jiazx0107
2025-11-30 87e5654c26476fabd1156023350d7726092af8c1
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
package com.fzzy.igds.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.data.NoticeDto;
import com.fzzy.igds.data.NoticeParam;
import com.fzzy.igds.mapper.InoutNoticeInMapper;
import com.fzzy.igds.mapper.InoutNoticeMapper;
import com.fzzy.igds.repository.InoutNoticeInRepository;
import com.fzzy.igds.repository.InoutNoticeOutRepository;
import com.fzzy.igds.domain.InoutNoticeIn;
import com.fzzy.igds.domain.InoutNoticeOut;
import com.fzzy.igds.utils.ContextUtil;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
 
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @Description 出入库通知单service层,包含入库通知单和出库通知单
 * @Author CZT
 * @Date 2025/11/29 16:33
 */
@Slf4j
@Service
public class InoutNoticeService {
 
    @Resource
    private InoutNoticeInRepository noticeInRepository;
    @Resource
    private InoutNoticeOutRepository noticeOutRepository;
    @Resource
    private InoutNoticeMapper noticeMapper;
 
    @Resource
    private InoutNoticeInMapper noticeInMapper;
 
 
/*    *//**
     * JPA分页查询数据
     *
     *//*
    public Page<InoutNoticeIn> queryAllNoticeIn(Specification<InoutNoticeIn> specification, Pageable pageable) {
        return noticeInRepository.findAll(specification, pageable);
    }*/
 
    public void pageQueryIn(Page<InoutNoticeIn> page, NoticeParam param) {
        QueryWrapper<InoutNoticeIn> queryWrapper = new QueryWrapper<>();
 
        if(null == param) param = new NoticeParam();
        param.setCompanyId(ContextUtil.getCompanyId());
 
        queryWrapper.eq("company_id", param.getCompanyId());
 
        noticeInMapper.selectPage(page, queryWrapper);
    }
 
    /**
     * JPA查询数据
     * @param companyId
     * @param deptId
     * @return
     */
    public List<InoutNoticeIn> listNoticeIn(String companyId, String deptId) {
        return noticeInRepository.listNoticeIn(companyId, deptId, Constant.COMPLETE_STATUS_NONE);
    }
 
    /**
     * jpa 获取信息
     * @param companyId
     * @return
     */
    public List<InoutNoticeIn> getUnComNoticeIn(String companyId) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        return noticeInRepository.listNoticeIn(companyId, Constant.COMPLETE_STATUS_NONE);
    }
 
    /**
     * JPA - 保存更新数据
     *
     * @param data
     * @return
     */
    public String saveOrUpdateIn(InoutNoticeIn data) {
        if (null == data.getUpdateBy()) {
            data.setUpdateBy(ContextUtil.getLoginUserName());
            data.setUpdateTime(new Date());
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setCreateTime(new Date());
            data.setAuditStatus(Constant.COMPLETE_STATUS_NONE);
            data.setCompleteStatus(Constant.COMPLETE_STATUS_NONE);
            noticeInRepository.save(data);
        } else {
            data.setUpdateBy(ContextUtil.getLoginUserName());
            data.setUpdateTime(new Date());
            noticeInRepository.save(data);
        }
 
        return null;
    }
 
    /**
     * JPA - 删除数据
     *
     * @param data
     * @return
     */
    public String delDataIn(InoutNoticeIn data) {
        noticeInRepository.delete(data);
        return null;
    }
 
    /**
     * JPA分页查询数据
     *
     * @param specification
     * @param pageable
     * @return
     */
    public Page<InoutNoticeOut> queryAllNoticeOut(Specification<InoutNoticeOut> specification, Pageable pageable) {
        //return noticeOutRepository.findAll(specification, pageable);
        return null;
    }
 
    /**
     * JPA查询数据
     * @param companyId
     * @param deptId
     * @return
     */
    public List<InoutNoticeOut> listNoticeOut(String companyId, String deptId) {
        return noticeOutRepository.listNoticeOut(companyId, deptId, Constant.COMPLETE_STATUS_NONE);
    }
 
    /**
     * Mybatis-plus 获取信息
     * @param companyId
     * @return
     */
    public List<InoutNoticeOut> getUnComNoticeOut(String companyId) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        return noticeOutRepository.listNoticeOut(companyId, Constant.COMPLETE_STATUS_NONE);
    }
 
    /**
     * JPA - 保存更新数据
     *
     * @param data
     * @return
     */
    public String saveOrUpdateOut(InoutNoticeOut data) {
        if (Constant.YN_Y.equals(data.getTag())) {
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setCreateTime(new Date());
            data.setAuditStatus(Constant.COMPLETE_STATUS_NONE);
            data.setCompleteStatus(Constant.COMPLETE_STATUS_NONE);
        }
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
        noticeOutRepository.save(data);
        return null;
    }
 
    /**
     * JPA - 删除数据
     *
     * @param data
     * @return
     */
    public String delDataOut(InoutNoticeOut data) {
        noticeOutRepository.delete(data);
        return null;
    }
 
    /**
     * JPA - 根据ID获取通知单信息
     * @param id
     * @param type
     * @return
     */
    public NoticeDto queryNoticeById(String id, String type) {
        if (StringUtils.isEmpty(id) || StringUtils.isEmpty(type)) {
            return null;
        }
        NoticeDto noticeDto = new NoticeDto();
        if (Constant.TYPE_IN.equals(type)) {
            InoutNoticeIn noticeIn = noticeInRepository.getDataById(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), id);
            BeanUtils.copyProperties(noticeIn, noticeDto);
        } else {
            InoutNoticeOut noticeOut = noticeOutRepository.getDataById(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), id);
            BeanUtils.copyProperties(noticeOut, noticeDto);
        }
        return noticeDto;
    }
 
    /**
     * Mybatis-plus 更新信息
     * @param noticeInList
     * @return
     */
    public void updateSumNoticeIn(List<InoutNoticeIn> noticeInList) {
 
        if (null == noticeInList || noticeInList.isEmpty()) {
            return;
        }
 
        //遍历通知单
        NoticeParam param;
        for (InoutNoticeIn noticeIn : noticeInList) {
 
            param = new NoticeParam(noticeIn.getCompanyId(), noticeIn.getDeptId(),
                    noticeIn.getCustomerName(), noticeIn.getFoodVariety(), noticeIn.getId());
 
            log.info("开始更新出库通知单={}", param.toString());
 
            String msg = this.reSumNoticeInComplete(param);
            if (msg != null) {
                log.info("入库通知单完成量统计失败={},失败原因={}", param.toString(), msg);
            }
        }
    }
 
    /**
     * Mybatis-plus 获取信息
     * @param param
     * @return
     */
    public String reSumNoticeInComplete(NoticeParam param) {
        if (StringUtils.isEmpty(param.getCustomerName())) {
            return "客户编码为空!";
        }
        if (StringUtils.isEmpty(param.getFoodVariety())) {
            return "粮食品种为空!";
        }
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(param.getDeptId())) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
        noticeMapper.reSumNoticeInComplete(param);
        return null;
    }
 
    /**
     * Mybatis-plus 更新信息
     * @param noticeOutList
     * @return
     */
    public void updateSumNoticeOut(List<InoutNoticeOut> noticeOutList) {
 
        if (null == noticeOutList || noticeOutList.isEmpty()) {
            return;
        }
 
        //遍历通知单
        NoticeParam param;
        for (InoutNoticeOut noticeOut : noticeOutList) {
 
            param = new NoticeParam(noticeOut.getCompanyId(), noticeOut.getDeptId(), noticeOut.getDepotId(),
                    noticeOut.getCustomerId(), noticeOut.getFoodVariety(), noticeOut.getId());
 
            log.info("开始更新出库通知单={}", param.toString());
 
            String msg = this.reSumNoticeOutComplete(param);
            if (msg != null) {
                log.info("出库通知单完成量统计失败={},失败原因={}", param.toString(), msg);
            }
        }
    }
 
    /**
     * Mybatis-plus 更新信息
     * @param param
     * @return
     */
    public String reSumNoticeOutComplete(NoticeParam param) {
        if (StringUtils.isEmpty(param.getCustomerName())) {
            return "客户编码为空!";
        }
        if (StringUtils.isEmpty(param.getFoodVariety())) {
            return "粮食品种为空!";
        }
        if (StringUtils.isEmpty(param.getDepotId())) {
            return "仓库编码为空!";
        }
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(param.getDeptId())) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
        noticeMapper.reSumNoticeOutComplete(param);
        return null;
    }
 
 
}