package com.fzzy.igds.sys.pr;
|
|
import com.bstek.dorado.annotation.DataProvider;
|
import com.bstek.dorado.annotation.DataResolver;
|
import com.bstek.dorado.annotation.Expose;
|
import com.bstek.dorado.data.provider.Page;
|
import com.fzzy.igds.dzhwk.constant.DepotStatus;
|
import com.fzzy.igds.dzhwk.domain.DepotStore;
|
import com.fzzy.igds.sys.DepotService;
|
import com.fzzy.igds.sys.DepotStoreService;
|
import com.fzzy.igds.util.ContextUtil;
|
import com.ruoyi.common.utils.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
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.Component;
|
import javax.annotation.Resource;
|
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Root;
|
import java.util.*;
|
|
|
/**
|
* @Description
|
* @Author CZT
|
* @Date 2024/11/23 15:29
|
*/
|
@Component
|
public class DepotStorePR {
|
|
@Resource
|
private DepotStoreService depotStoreService;
|
@Resource
|
private DepotService depotService;
|
|
/**
|
* JPA分页查询数据
|
* depotStorePR#pageList
|
* @param page
|
* @param param
|
*/
|
@DataProvider
|
public void pageList(Page<DepotStore> page, Map<String, Object> param) {
|
if (null == param) {
|
param = new HashMap<>();
|
}
|
Map<String, Object> finalParam = param;
|
|
//多参数分页查询
|
Pageable pageable = PageRequest.of(page.getPageNo() - 1, page.getPageSize(), Sort.Direction.ASC, DepotStore.SORT_PROP);
|
Specification<DepotStore> specification = new Specification<DepotStore>() {
|
private static final long serialVersionUID = 1L;
|
|
public Predicate toPredicate(Root<DepotStore> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
List<Predicate> predicates = new ArrayList<Predicate>(); //所有的断言
|
|
Predicate predicate1 = cb.equal(root.get("companyId"), ContextUtil.getCompanyId());
|
predicates.add(predicate1);
|
|
Predicate predicate2 = cb.equal(root.get("deptId"), ContextUtil.subDeptId(null));
|
predicates.add(predicate2);
|
|
String depotId = (String) finalParam.get("depotId");
|
if (StringUtils.isNotEmpty(depotId)) {
|
Predicate predicate3 = cb.equal(root.get("depotId"), depotId);
|
predicates.add(predicate3);
|
}
|
|
Date start = (Date) finalParam.get("start");
|
if (null != start) {
|
Predicate predicate4 = cb.greaterThan(root.get("fcrq"), start);
|
predicates.add(predicate4);
|
}
|
|
Date end = (Date) finalParam.get("end");
|
if (null != end) {
|
Predicate predicate5 = cb.lessThan(root.get("fcrq"), end);
|
predicates.add(predicate5);
|
}
|
return cb.and(predicates.toArray(new Predicate[0]));
|
}
|
};
|
org.springframework.data.domain.Page<DepotStore> japPage = depotStoreService.findAll(specification, pageable);
|
page.setEntityCount((int) japPage.getTotalElements());
|
page.setEntities(japPage.getContent());
|
}
|
|
/**
|
* depotStorePR#saveDepotStore
|
*
|
* @param data
|
*/
|
@DataResolver
|
public String saveDepotStore(DepotStore data) throws Exception {
|
|
//如果仓库状态=封仓/入库中/出库中
|
if (DepotStatus.STATUS_2.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_3.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_4.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_31.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_32.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_33.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_34.getCode().equals(data.getDepotStatus())) {
|
|
if (null == data.getFoodYear()) return "货位状态=封仓/入库中/出库中,收货年度不能为空";
|
|
if (null == data.getCountry()) return "货位状态=封仓/入库中/出库中,国别不能为空";
|
|
if (null == data.getFoodLocation()) return "货位状态=封仓/入库中/出库中,粮食产地不能为空";
|
|
if (null == data.getFoodLocation()) return "货位状态=封仓/入库中/出库中,粮食产地不能为空";
|
|
if (null == data.getStoreDate()) return "货位状态=封仓/入库中/出库中,入库时间不可为空";
|
}
|
|
//货位状态=封仓/出库中,必填
|
if (DepotStatus.STATUS_3.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_4.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_31.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_32.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_33.getCode().equals(data.getDepotStatus()) ||
|
DepotStatus.STATUS_34.getCode().equals(data.getDepotStatus())) {
|
if (null == data.getFullDate()) {
|
return "货位状态=封仓/出库中,封仓时间不可为空";
|
}
|
}
|
|
//货位状态=空仓,必填。最后一车粮食出仓时间
|
if (DepotStatus.STATUS_1.getCode().equals(data.getDepotStatus())) {
|
if (null == data.getOutDate()) {
|
return "货位状态=空仓,出仓完成时间不可为空";
|
}
|
}
|
DepotStore depotStore = new DepotStore();
|
BeanUtils.copyProperties(data, depotStore);
|
depotStoreService.saveDepotStore(depotStore);
|
|
//根据库存信息更新到仓库信息,仓库储粮信息以当前为准
|
depotService.updateByStore(depotStore);
|
|
//远程同步状态
|
|
return null;
|
}
|
|
/**
|
* depotStorePR#delDepotStore
|
*
|
* @param data
|
* @return
|
*/
|
@Expose
|
public String delDepotStore(DepotStore data) {
|
DepotStore depotStore = new DepotStore();
|
BeanUtils.copyProperties(data, depotStore);
|
return depotStoreService.delDepotStore(depotStore);
|
}
|
|
}
|