czt
2025-06-03 4901f0cf60ecc6484d149ca5e9a0083e4b21db21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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);
    }
 
}