|
|
|
package com.jiashi.dao;
|
|
|
|
|
|
|
|
import com.jiashi.service.CardInfo;
|
|
|
|
import com.jiashi.service.Picture;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
@Repository
|
|
|
|
public class DataQuery {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private CardInfoRepository cardInfoRepository;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private PictureRepository pictureRepository;
|
|
|
|
|
|
|
|
public List<CardInfo> dateQuery(){
|
|
|
|
Specification<CardInfo> specification = (root, query, cb) -> {
|
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
|
predicates.add(cb.equal(root.<String>get("state"), 0));
|
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
};
|
|
|
|
|
|
|
|
Sort.Order sortCreateTime = Sort.Order.asc("outdate");
|
|
|
|
Sort sort = Sort.by(sortCreateTime);
|
|
|
|
Pageable pageable = PageRequest.of(0, 1000, sort);
|
|
|
|
Page<CardInfo> all = cardInfoRepository.findAll(specification, pageable);
|
|
|
|
return all.toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<CardInfo> dateQuery(int state){
|
|
|
|
Specification<CardInfo> specification = (root, query, cb) -> {
|
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
|
predicates.add(cb.equal(root.<String>get("state"), state));
|
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
};
|
|
|
|
|
|
|
|
List<CardInfo> all = cardInfoRepository.findAll(specification);
|
|
|
|
return all;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<CardInfo> dateQueryByInpNo(String inpNo){
|
|
|
|
Specification<CardInfo> specification = (root, query, cb) -> {
|
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
|
predicates.add(cb.equal(root.<String>get("patno"), inpNo));
|
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
};
|
|
|
|
|
|
|
|
Sort.Order sortCreateTime = Sort.Order.asc("outdate");
|
|
|
|
Sort sort = Sort.by(sortCreateTime);
|
|
|
|
Pageable pageable = PageRequest.of(0, 1000, sort);
|
|
|
|
Page<CardInfo> all = cardInfoRepository.findAll(specification, pageable);
|
|
|
|
return all.toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateBatch(List<CardInfo> cardInfos){
|
|
|
|
for(CardInfo cardInfo:cardInfos){
|
|
|
|
cardInfo.setState(1);
|
|
|
|
}
|
|
|
|
cardInfoRepository.saveAll(cardInfos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateBatchState(List<CardInfo> cardInfos,Integer state){
|
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
|
for(CardInfo cardInfo:cardInfos){
|
|
|
|
String id = cardInfo.getId();
|
|
|
|
ids.add(id);
|
|
|
|
}
|
|
|
|
cardInfoRepository.updateState(ids,state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateBatchState(CardInfo cardInfo,Integer state){
|
|
|
|
|
|
|
|
cardInfoRepository.updateState(cardInfo.getId(),state);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Picture> getPictures(String FileId){
|
|
|
|
|
|
|
|
Specification<Picture> specification = (root, query, cb) -> {
|
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
|
predicates.add(cb.equal(root.<String>get("fileid"), FileId));
|
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
};
|
|
|
|
List<Picture> all = pictureRepository.findAll(specification);
|
|
|
|
return all;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|