jiazx0107@163.com
2023-05-17 a87eff704037284e46568c7c7b8a60caaae884c2
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
package com.ld.igds.sh.service;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.log.service.InteStatusLogService;
import com.ld.igds.models.InoutNoticeIn;
import com.ld.igds.models.InoutRecord;
import com.ld.igds.models.InoutSettle;
import com.ld.igds.models.InteStatusLog;
import com.ld.igds.sh.dto.ApiResponse;
import com.ld.igds.sh.dto.Dto1302;
import com.ld.igds.sh.param.ApiRequest;
import com.ld.igds.sh.param.BaseParam;
import com.ld.igds.sh.service.impl.HApiShServiceImpl;
import com.ld.igds.sh.util.ApiShConst;
import com.ld.igds.sh.util.RespCodeEnum;
import com.ld.igds.sh.util.RespUtil;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
 
/**
 * 粮食入库信息数据接口
 *
 * @author chen
 */
@Slf4j
@Service
public class ApiShServiceImpl1302 implements ApiShService {
 
    @Autowired
    private HApiShServiceImpl hApiShServiceImpl;
    @Autowired
    private InteStatusLogService inteStatusLogService;
    @Autowired
    private RedisUtil redisUtil;
    @Override
    public String getInterfaceId() {
        return ApiShConst.API_SH_1302;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public ApiResponse<Object> execute(ApiRequest<Object> request){
        //获取参数信息
        String deptId = request.getDeptId();
        BaseParam param = JSONObject.parseObject(JSONObject.toJSONString(request.getData()), BaseParam.class);
 
        String companyId = ContextUtil.getDefaultCompanyId();
 
        String key = RedisConst.buildKey(companyId, ApiShConst.API_SH_1302);
        Date startTime = (Date) redisUtil.get(key);
        if(null == startTime){
            startTime = DateUtils.addDays(param.getEndTime(), -30);
        }
        redisUtil.set(key, param.getEndTime());
 
        //查询数据
        List<InoutRecord> inoutRecords = hApiShServiceImpl.listInoutRecord(companyId, param.getDepotId(), startTime, param.getEndTime(), InoutConstant.TYPE_IN);
 
        //响应数据为空则直接返回响应码2000
        if (inoutRecords == null || inoutRecords.isEmpty()) {
            return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request);
        }
 
        List<Dto1302> list = new ArrayList<>();
        Dto1302 dto;
        InoutNoticeIn inoutNoticeIn;
        InoutSettle inoutSettle;
        InteStatusLog log;
        InteStatusLog addLog;
        //封装数据信息
        for (InoutRecord inoutRecord : inoutRecords) {
            dto = new Dto1302();
            dto.setYwdh("14" + inoutRecord.getId().substring(4, 14));
            dto.setHwbm(inoutRecord.getDepotId());
            dto.setYwrq(DateFormatUtils.format(inoutRecord.getCompleteTime(),"yyyy-MM-dd HH:mm:ss"));
 
            dto.setCyr(StringUtils.isEmpty(inoutRecord.getUserName())?"0":inoutRecord.getUserName());
            dto.setLxdh(StringUtils.isEmpty(inoutRecord.getUserContact())?"0":inoutRecord.getUserContact());
            dto.setSfzh(inoutRecord.getUserId());
            dto.setXxdz(StringUtils.isEmpty(inoutRecord.getUserAddress())?"0":inoutRecord.getUserAddress());
            dto.setYsgj(inoutRecord.getTransType());
            dto.setCch(inoutRecord.getPlateNum());
            dto.setDjsj(DateFormatUtils.format(inoutRecord.getRegisterTime(),"yyyy-MM-dd HH:mm:ss"));
            dto.setPzbm(StringUtils.isEmpty(inoutRecord.getFoodVariety())?"0":inoutRecord.getFoodVariety());
            dto.setLqxzbm(StringUtils.isEmpty(inoutRecord.getFoodType())?"0":inoutRecord.getFoodType());
            dto.setShnd(DateFormatUtils.format(inoutRecord.getCompleteTime(),"yyyy"));
            dto.setCddm("310000");
            dto.setMz(inoutRecord.getFullWeight() + "");
            dto.setMzjlsj(DateFormatUtils.format(inoutRecord.getFullWeightTime(),"yyyy-MM-dd HH:mm:ss"));
            dto.setPz(inoutRecord.getEmptyWeight() + "");
            dto.setPzjlsj(DateFormatUtils.format(inoutRecord.getEmptyWeightTime(),"yyyy-MM-dd HH:mm:ss"));
            dto.setZjkl(inoutRecord.getDeSum() + "");
            dto.setJz(inoutRecord.getSettleWeight() + "");
            dto.setCmsj(DateFormatUtils.format(inoutRecord.getCompleteTime(),"yyyy-MM-dd HH:mm:ss"));
            dto.setCmqrmgryxm(StringUtils.isEmpty(inoutRecord.getCompleteUser())?"0":inoutRecord.getCompleteUser());
            dto.setJsdbm(inoutRecord.getId());
            dto.setBz(StringUtils.isEmpty(inoutRecord.getRemarks())?"0":inoutRecord.getRemarks());
            //获取通知单信息,设置合同号和计划号
            inoutNoticeIn = hApiShServiceImpl.getNoticeIn(companyId, inoutRecord.getNoticeId());
            if(null != inoutNoticeIn){
                dto.setHtbm(StringUtils.isEmpty(inoutNoticeIn.getContractId())?"0":inoutNoticeIn.getContractId());
                dto.setJhbh(StringUtils.isEmpty(inoutNoticeIn.getPlanId())?"0":inoutNoticeIn.getPlanId());
            }else {
                dto.setHtbm("0");
                dto.setJhbh("0");
            }
            dto.setDjmgryxm(StringUtils.isEmpty(inoutRecord.getRegisterUser())?"0":inoutRecord.getRegisterUser());
            dto.setRkdnm(StringUtils.isEmpty(inoutRecord.getNoticeId())?"0":inoutRecord.getNoticeId());
            dto.setZznm(inoutRecord.getDepotId().substring(0, 21));
            dto.setSxh(inoutRecord.getId().substring(10));
            if(InoutConstant.RECORD_STATUS_DEL.equals(inoutRecord.getRecordStatus()) ||
                    InoutConstant.RECORD_STATUS_ERROR.equals(inoutRecord.getRecordStatus())){
                dto.setDjzt("4"); //已作废
            }else {
                dto.setDjzt("2"); //入库完成
            }
            inoutSettle = hApiShServiceImpl.getInoutSettle(companyId, inoutRecord.getId());
            if(inoutSettle != null){
                dto.setJssj(DateFormatUtils.format((inoutSettle.getPayTime() == null?new Date():inoutSettle.getPayTime()),"yyyy-MM-dd HH:mm:ss"));
                dto.setJsjz(inoutSettle.getSettleWeight() + "");
                dto.setJsdj(inoutSettle.getPayPrice() + "");
                dto.setJsje(inoutSettle.getPaySum() + "");
            }else {
                dto.setJssj(DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
                dto.setJsjz("0.0");
                dto.setJsdj("0.0");
                dto.setJsje("0.0");
            }
            dto.setJydbh(inoutRecord.getId());
            dto.setLhnd(DateFormatUtils.format(inoutRecord.getCompleteTime(),"yyyy"));
 
            dto.setZhgxsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            //查询日志状态表,设置操作标志
            log = inteStatusLogService.getLogByBizId(companyId, ApiShConst.API_SH_1302 + "_" + inoutRecord.getId());
            if(null == log){
                addLog = new InteStatusLog();
                addLog.setBizId(ApiShConst.API_SH_1302 + "_" + inoutRecord.getId());
                addLog.setCompanyId(companyId);
                addLog.setBizType(ApiShConst.API_SH_TYPE_INOUT);
                addLog.setInterfaceId(ApiShConst.API_SH_1302);
                addLog.setInterfaceType(ApiShConst.API_SH_TYPE_INOUT);
                addLog.setStatus(ApiShConst.API_SH_STATUS_SUCCESS);
 
                inteStatusLogService.addInteStatusLog(addLog);
            }else {
                dto.setCzbz(ApiShConst.API_SH_U);
            }
            list.add(dto);
        }
 
        //响应数据为空则直接返回响应码2000
        if (list.isEmpty()) {
            return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request);
        }
 
        return RespUtil.success(list, request);
    }
}