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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.ld.igds.phone.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.common.CoreDicService;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.models.DicTrigger;
import com.ld.igds.phone.constant.PhoneConstant;
import com.ld.igds.phone.util.PhoneRespUtil;
import com.ld.igds.phone.dto.*;
import com.ld.igds.phone.mapper.PhoneCommonMapper;
import com.ld.igds.phone.param.PhoneRequest;
import com.ld.igds.phone.service.PhoneService;
import com.ld.igds.sys.service.DicTriggerService;
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.*;
 
/**
 * 综合展示接口实现
 * @author chen
 */
@Service
public class ServiceImpl5101 implements PhoneService {
 
    @Autowired
    private DicTriggerService triggerService;
    @Autowired
    private PhoneCommonMapper phoneCommonMapper;
 
    @Override
    public String getInterfaceId() {
        return PhoneConstant.API_PHONE_5101;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public PhoneResponse<Object> execute(PhoneRequest<JSONObject> req, AuthUser authUser)
            throws Exception {
 
        //查看用户所属部门是否存在
        String deptId = authUser.getDeptId();
        if(StringUtils.isEmpty(deptId)){
            return PhoneRespUtil.error(RespCodeEnum.CODE_1111,"您的账号尚未分配部门/分库,无法查看!");
        }
 
        //判断登录用户部门是否是顶级部门,是的话默认分配到分库一
        if (deptId.equals(authUser.getCompanyId())) {
            deptId = authUser.getCompanyId() + "_001";
        }
 
        //获取粮食性质字典集合信息
        List<DicTrigger> foodTypeList = triggerService.getCacheDicByParent(
                authUser.getCompanyId(),"FOOD_TYPE_");
 
        //获取粮食品种字典集合信息
        List<DicTrigger> foodVarietyList = triggerService.getCacheDicByParent(
                authUser.getCompanyId(),"FOOD_VARIETY_");
 
        //获取粮食等级字典集合信息
        List<DicTrigger> foodLevelList = triggerService.getCacheDicByParent(
                authUser.getCompanyId(),"FOOD_LEVEL_");
 
        //获取仓库实时信息
        List<DtoDepot> depotList = phoneCommonMapper.phoneListDepot(authUser.getCompanyId(),deptId);
 
        //数量临时变量
        Double tempNum;
 
        //统计粮食性质信息
        List<Map<String ,String>> listFoodType = new ArrayList<>();
        Map<String,String> map;
        for (DicTrigger dicTrigger : foodTypeList) {
            tempNum = 0.0;
            for (DtoDepot depot : depotList) {
                if(dicTrigger.getCode().equals(depot.getFoodType())){
                    tempNum += depot.getStorageReal();
                }
            }
            if(tempNum > 0){
                map = new HashMap<>();
                map.put("typeName",dicTrigger.getName());
                map.put("typeNum",String.valueOf(tempNum.longValue()));
                listFoodType.add(map);
            }
        }
 
        //统计粮食品种信息
        List<Map<String ,String>> listFoodVariety = new ArrayList<>();
        for (DicTrigger dicTrigger : foodVarietyList) {
            tempNum = 0.0;
            for (DtoDepot depot : depotList) {
                if(dicTrigger.getCode().equals(depot.getFoodVariety())){
                    tempNum += depot.getStorageReal();
                }
            }
            if(tempNum > 0) {
                map = new HashMap<>();
                map.put("varietyName",dicTrigger.getName());
                map.put("varietyNum",String.valueOf(tempNum.longValue()));
                listFoodVariety.add(map);
            }
        }
 
        //统计粮食等级信息
        List<Map<String ,String>> listFoodLevel = new ArrayList<>();
        for (DicTrigger dicTrigger : foodLevelList) {
            tempNum = 0.0;
            for (DtoDepot depot : depotList) {
                if(dicTrigger.getCode().equals(depot.getFoodLevel())){
                    tempNum += depot.getStorageReal();
                }
            }
            if(tempNum > 0) {
                map = new HashMap<>();
                map.put("levelName",dicTrigger.getName());
                map.put("levelNum",String.valueOf(tempNum.longValue()));
                listFoodLevel.add(map);
            }
        }
 
        //设置返回信息
        Dto5101 dto = new Dto5101();
        dto.setTime(DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
        dto.setDepotNum(depotList.size());
        dto.setDeptName(authUser.getDeptName());
        dto.setListFoodType(listFoodType);
        dto.setListFoodVariety(listFoodVariety);
        dto.setListFoodLevel(listFoodLevel);
 
        return PhoneRespUtil.success(dto,req);
    }
}