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
package com.ld.igds.sh.service;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.log.service.InteStatusLogService;
import com.ld.igds.models.Gas;
import com.ld.igds.models.InteStatusLog;
import com.ld.igds.sh.dto.ApiResponse;
import com.ld.igds.sh.dto.Dto1408;
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.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
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 ApiShServiceImpl1408 implements ApiShService {
 
    @Autowired
    private HApiShServiceImpl hApiShServiceImpl;
    @Autowired
    private InteStatusLogService inteStatusLogService;
    @Autowired
    private RedisUtil redisUtil;
    @Override
    public String getInterfaceId() {
        return ApiShConst.API_SH_1408;
    }
 
    @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_1408);
        Date startTime = (Date) redisUtil.get(key);
        if(null == startTime){
            startTime = DateUtils.addDays(param.getEndTime(), -100);
        }
        redisUtil.set(key, param.getEndTime());
 
        //查询气体信息
        List<Gas> dataList = hApiShServiceImpl.listGas(companyId,
                param.getDepotId(), startTime, param.getEndTime());
 
        //响应数据为空则直接返回响应码2000
        if (dataList == null || dataList.isEmpty()) {
            return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request);
        }
 
        List<Dto1408> list = new ArrayList<>();
        Dto1408 dto;
        InteStatusLog log;
        InteStatusLog addLog;
        //封装数据信息
        for (Gas data : dataList) {
            dto = new Dto1408();
            dto.setQtndjcdh(data.getBatchId());
            dto.setJcsj(DateFormatUtils.format(data.getReceiveDate(), "yyyy-MM-dd HH:mm:ss"));
            dto.setHwdm(data.getDepotId());
            dto.setYqhlzjh(getPointByType(data.getPoints(), 2));
            dto.setLhqndzjh(getPointByType(data.getPoints(), 3));
 
            dto.setZhgxsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            //查询日志状态表,设置操作标志
            log = inteStatusLogService.getLogByBizId(companyId, ApiShConst.API_SH_1408 + "_" + data.getCompanyId() + data.getBatchId());
            if(null == log){
                addLog = new InteStatusLog();
                addLog.setBizId(ApiShConst.API_SH_1408 + "_" + data.getCompanyId() + data.getBatchId());
                addLog.setCompanyId(companyId);
                addLog.setBizType(ApiShConst.API_SH_TYPE_TASK);
                addLog.setInterfaceId(ApiShConst.API_SH_1408);
                addLog.setInterfaceType(ApiShConst.API_SH_TYPE_TASK);
                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);
    }
 
    /**
     * 获取对应气体浓度集合:passCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2;
     *
     * @return
     */
    private String getPointByType(String points, int num) {
        String[] arr = points.split(";");
        String point = "";
        String[] split;
        for (String s : arr) {
            split = s.split(",");
            point += split[num] + ",";
        }
        return point;
    }
}