jiazx0107@163.com
2023-05-27 ff212e3d6cc57220133aff1d68b6bed02ba8a77b
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
package com.ld.igds.sh.service;
 
import com.alibaba.fastjson.JSONObject;
import com.bstek.bdf2.core.model.DefaultDept;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.file.CoreFileService;
import com.ld.igds.log.service.InteStatusLogService;
import com.ld.igds.models.FileInfo;
import com.ld.igds.models.InteStatusLog;
import com.ld.igds.sh.dto.ApiResponse;
import com.ld.igds.sh.dto.Dto1112;
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.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.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.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 文件信息数据接口
 *
 * @author chen
 */
@Slf4j
@Service
public class ApiShServiceImpl1112 implements ApiShService {
 
    @Autowired
    private HApiShServiceImpl hApiShServiceImpl;
    @Autowired
    private InteStatusLogService inteStatusLogService;
    @Autowired
    private CoreFileService fileService;
    @Autowired
    private ApiShUtil apiShUtil;
    @Autowired
    private RedisUtil redisUtil;
    @Override
    public String getInterfaceId() {
        return ApiShConst.API_SH_1112;
    }
 
    @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_1112);
        Date startTime = (Date) redisUtil.get(key);
        if(null == startTime){
            startTime = DateUtils.addDays(param.getEndTime(), -30);
        }
        redisUtil.set(key, param.getEndTime());
        List<FileInfo> listFiles = hApiShServiceImpl.listFiles(companyId, startTime, param.getEndTime());
 
        //响应数据为空则直接返回响应码2000
        if (listFiles == null || listFiles.isEmpty()) {
            return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request);
        }
        //查询库区信息
        List<DefaultDept> deptList = hApiShServiceImpl.listDept(companyId, companyId);
        DefaultDept dept = deptList.get(0);
        List<Dto1112> list = new ArrayList<>();
        Dto1112 dto;
        String bathPath;
        InteStatusLog log;
        InteStatusLog addLog;
        File fil;
        for (FileInfo file : listFiles) {
            //判断文件是否存在
            bathPath = fileService.getInoutFilePath(file.getCreateTime()) + file.getFileName();
            fil = new File(bathPath);
            if(!fil.exists()){
                continue;
            }
            dto = new Dto1112();
            dto.setWjmc(file.getFileName());
            dto.setKqbh(dept.getCode());
            if(file.getBizId().startsWith("C")){
                //出库图片
                dto.setWjlx("3");
            }else if(file.getBizId().startsWith("R")){
                //入库图片
                dto.setWjlx("2");
            }else {
                dto.setWjlx("9");
            }
 
            dto.setWjl(apiShUtil.imgToIo(bathPath));
 
            dto.setZhgxsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            //查询日志状态表,设置操作标志
            log = inteStatusLogService.getLogByBizId(companyId, ApiShConst.API_SH_1112 + "_" + file.getFileId());
            if(null == log){
                addLog = new InteStatusLog();
                addLog.setBizId(ApiShConst.API_SH_1112 + "_" + file.getFileId());
                addLog.setCompanyId(companyId);
                addLog.setBizType(ApiShConst.API_SH_TYPE_BASIC);
                addLog.setInterfaceId(ApiShConst.API_SH_1112);
                addLog.setInterfaceType(ApiShConst.API_SH_TYPE_BASIC);
                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);
    }
}