CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
package com.ld.igds.sh.service;
 
import com.ld.igds.constant.FoodVariety;
import com.ld.igds.log.service.InteStatusLogService;
import com.ld.igds.models.Building;
import com.ld.igds.models.Depot;
import com.ld.igds.models.DicArea;
import com.ld.igds.models.InteStatusLog;
import com.ld.igds.sh.dto.ApiResponse;
import com.ld.igds.sh.dto.Dto1310;
import com.ld.igds.sh.param.ApiRequest;
import com.ld.igds.sh.service.impl.HApiShServiceImpl;
import com.ld.igds.sh.util.ApiShConst;
import com.ld.igds.sh.util.ApiShUtil;
import com.ld.igds.sh.util.RespCodeEnum;
import com.ld.igds.sh.util.RespUtil;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.view.service.HDicAreaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 粮食库存数据接口
 *
 * @author chen
 */
@Slf4j
@Service
public class ApiShServiceImpl1310 implements ApiShService {
 
    @Autowired
    private HApiShServiceImpl hApiShServiceImpl;
    @Autowired
    private InteStatusLogService inteStatusLogService;
    @Autowired
    private HDicAreaService areaService;
    @Override
    public String getInterfaceId() {
        return ApiShConst.API_SH_1310;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public ApiResponse<Object> execute(ApiRequest<Object> request) {
        //获取参数信息
        String deptId = request.getDeptId();
        if(StringUtils.isEmpty(deptId)){
            deptId = ContextUtil.subDeptId(null);
        }
        //获取单位信息
        String companyId = ContextUtil.getDefaultCompanyId();
        List<Depot> depotList = hApiShServiceImpl.listDepot(companyId, deptId);
 
        //响应数据为空则直接返回响应码2000
        if (depotList == null || depotList.isEmpty()) {
            return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request);
        }
 
        //封装数据
        List<Dto1310> list = new ArrayList<>();
        Dto1310 dto;
        InteStatusLog log;
        InteStatusLog addLog;
        Building building;
        DicArea dicArea;
        for (Depot depot : depotList) {
            dto = new Dto1310();
            dto.setHwbm(ApiShUtil.getGbDepotId(depot.getId()) + "01");
            dto.setLspzbm(StringUtils.isEmpty(depot.getFoodVariety())?"0":depot.getFoodVariety());
            dto.setLsxzbm(StringUtils.isEmpty(depot.getFoodType())?"0":depot.getFoodType());
            dto.setDjbm(StringUtils.isEmpty(depot.getFoodLevel())?"0":depot.getFoodLevel());
            dto.setShnd(StringUtils.isEmpty(depot.getFoodYear())?"0":depot.getFoodYear());
            dto.setGb("156");
            dicArea = areaService.listDicAreaByName(depot.getFoodLocation());
            dto.setCd(dicArea == null ? "310114": dicArea.getCode());
            dto.setGoodscode(dicArea == null ? "310114": dicArea.getCode());
            dto.setLqgsdwbm(ApiShUtil.getGbDepotId(depot.getId()).substring(0,18));
            dto.setGlfs("01");
            dto.setScdd("1");
            dto.setClfs(StringUtils.isEmpty(depot.getStoreType())?"1":depot.getStoreType());
            dto.setFczt(depot.getDepotStatus());
            if(null != depot.getStoreDate()){
                dto.setRcsj(DateFormatUtils.format(depot.getStoreDate(), "yyyy-MM-dd HH:mm:ss"));
                dto.setFcsj(DateFormatUtils.format(depot.getStoreDate(), "yyyy-MM-dd HH:mm:ss"));
                dto.setYf(DateFormatUtils.format(new Date(), "MM"));
            }else {
                dto.setRcsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
                dto.setFcsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
                dto.setYf(DateFormatUtils.format(new Date(), "MM"));
            }
 
            dto.setKcjcsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            dto.setQmkc(depot.getStorageReal()==null?"0.0":depot.getStorageReal()+"");
            dto.setScnd(StringUtils.isEmpty(depot.getFoodYear())?"0":depot.getFoodYear());
 
            dto.setSjsl(depot.getStorageReal()==null?"0.0":depot.getStorageReal() + "");
            dto.setJjsl(depot.getStorageReal()==null?"0.0":depot.getStorageReal() + "");
 
            dto.setNm(ApiShUtil.getGbDepotId(depot.getId()).substring(0, 21));
            dto.setZznm(ApiShUtil.getGbDepotId(depot.getId()).substring(0, 21));
            dto.setPzmc(StringUtils.isEmpty(depot.getFoodVariety())?"0": FoodVariety.getMsg(depot.getFoodVariety()));
            dto.setPznm(StringUtils.isEmpty(depot.getFoodVariety())?"0":depot.getFoodVariety());
            building = hApiShServiceImpl.getBuilding(companyId, depot.getId());
            if(building != null){
                dto.setCfnm(building.getId());
            }
 
            dto.setZhgxsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            //查询日志状态表,设置操作标志
            log = inteStatusLogService.getLogByBizId(companyId, ApiShConst.API_SH_1310 + "_" + ApiShUtil.getGbDepotId(depot.getId()));
            if(null == log){
                addLog = new InteStatusLog();
                addLog.setBizId(ApiShConst.API_SH_1310 + "_" + ApiShUtil.getGbDepotId(depot.getId()));
                addLog.setCompanyId(companyId);
                addLog.setBizType(ApiShConst.API_SH_TYPE_INOUT);
                addLog.setInterfaceId(ApiShConst.API_SH_1310);
                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);
    }
}