jiazx0107@163.com
2023-06-08 08cea428e888b6fdd2a3c3783e87e4f828385783
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
package com.ld.igds.phone.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.gas.CoreGasService;
import com.ld.igds.gas.dto.GasData;
import com.ld.igds.gas.dto.GasParam;
import com.ld.igds.pest.CorePestService;
import com.ld.igds.pest.dto.PestData;
import com.ld.igds.pest.dto.PestParam;
import com.ld.igds.phone.constant.PhoneConstant;
import com.ld.igds.phone.dto.*;
import com.ld.igds.phone.mapper.PhoneCommonMapper;
import com.ld.igds.phone.param.ParamDepot;
import com.ld.igds.phone.param.PhoneRequest;
import com.ld.igds.phone.service.PhoneService;
import com.ld.igds.phone.util.PhoneRespUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
 
 
/**
 * 粮情展示-仓库列表接口实现
 *
 * @author chen
 */
@Service
public class ServiceImpl5301 implements PhoneService {
 
    @Autowired
    private PhoneCommonMapper phoneCommonMapper;
    @Autowired
    private CorePestService pestService;
    @Autowired
    private CoreGasService coreGasService;
 
    @Override
    public String getInterfaceId() {
        return PhoneConstant.API_PHONE_5301;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public PhoneResponse<Object> execute(PhoneRequest<JSONObject> req, AuthUser authUser)
            throws Exception {
 
        //转化为对象
        ParamDepot paramDepot = JSONObject.parseObject(req.getData().toString(), ParamDepot.class);
 
 
        //查看用户所属部门是否存在
        String deptId = authUser.getDeptId();
        if(StringUtils.isEmpty(deptId)){
            return PhoneRespUtil.error(RespCodeEnum.CODE_1111,"您的账号尚未分配部门/分库,无法查看!");
        }
 
        //判断登录用户部门是否是顶级部门,是的话默认分配到分库一
        if (deptId.equals(authUser.getCompanyId())) {
            deptId = authUser.getCompanyId() + "_001";
        }
 
        //获取仓库信息
        List<DtoDepot> depotList = phoneCommonMapper.phoneListDepot(authUser.getCompanyId(),deptId);
 
        for (int i = depotList.size()-1;i>=0;i--){
            if(StringUtils.isEmpty(depotList.get(i).getDepotType()) || "99".equals(depotList.get(i).getDepotType())){
                depotList.remove(depotList.get(i));
            }
        }
 
        //判断type类型,是虫害类型,则查询虫害信息
        if(paramDepot.getType().equals(PhoneConstant.PHONE_DEPOT_PEST)){
            //设置查询参数
            PestParam param = new PestParam();
            param.setCompanyId(authUser.getCompanyId());
            param.setLimit(1);
            List<PestData> pestList;
            //遍历仓库进行查询,每个仓库只查询一条虫害数据
            for (DtoDepot dtoDepot : depotList) {
                param.setDepotId(dtoDepot.getDepotId());
                pestList = pestService.pageQueryList(param);
                if (pestList != null && pestList.size()>0) {
                    dtoDepot.setIsPest(pestList.get(0).getRemark());
                    dtoDepot.setReceiveDate(pestList.get(0).getReceiveDate());
                }
            }
        }
 
        //判断type类型,是气体类型,则查询气体信息
        if(paramDepot.getType().equals(PhoneConstant.PHONE_DEPOT_GAS)){
            GasParam param = new GasParam();
            param.setCompanyId(authUser.getCompanyId());
            param.setLimit(1);
            List<GasData> gasList;
            for (DtoDepot dtoDepot : depotList) {
                param.setDepotId(dtoDepot.getDepotId());
                gasList = coreGasService.pageQueryList(param);
                if(gasList != null && gasList.size()>0){
                    dtoDepot.setPerCo2(gasList.get(0).getPerCo2());
                    dtoDepot.setPerN2(gasList.get(0).getPerN2());
                    dtoDepot.setPerO2(gasList.get(0).getPerO2());
                    dtoDepot.setPerPh3(gasList.get(0).getPerPh3());
                    dtoDepot.setReceiveDate(gasList.get(0).getReceiveDate());
                }
            }
        }
 
        return PhoneRespUtil.success(depotList, req);
    }
}