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
package com.ld.igds.phone.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.es.dto.EsData;
import com.ld.igds.es.dto.EsParam;
import com.ld.igds.es.mapper.EsServiceMapper;
import com.ld.igds.phone.constant.PhoneConstant;
import com.ld.igds.phone.dto.AuthUser;
import com.ld.igds.phone.dto.DtoEnergy;
import com.ld.igds.phone.dto.PhoneResponse;
import com.ld.igds.phone.param.ParamEnergy;
import com.ld.igds.phone.param.PhoneRequest;
import com.ld.igds.phone.service.PhoneService;
import com.ld.igds.phone.util.PhoneRespUtil;
import com.ld.igds.phone.util.PhoneUtil;
import com.ld.igds.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
 
/**
 * 能耗管理-查询仓库能耗信息接口实现
 *
 * @author chen
 */
@Service
public class ServiceImpl5502 implements PhoneService {
 
    @Autowired
    private EsServiceMapper esServiceMapper;
    @Autowired
    private PhoneUtil phoneUtil;
 
    @Override
    public String getInterfaceId() {
        return PhoneConstant.API_PHONE_5502;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public PhoneResponse<Object> execute(PhoneRequest<JSONObject> req, AuthUser authUser)
            throws Exception {
 
        //转化对象
        ParamEnergy paramEnergy = JSONObject.parseObject(req.getData().toString(), ParamEnergy.class);
 
        EsParam param = new EsParam();
        param.setDepotId(paramEnergy.getDepotId());
        //设置开始时间的为当前天的零点零分
        if(paramEnergy.getStart()!=null){
            param.setStart(paramEnergy.getStart());
        }
        //设置截止时间的为下一天的零点零分
        if(paramEnergy.getEnd() != null){
            param.setEnd(DateUtil.getNextZero(paramEnergy.getEnd()));
        }
        param.setCompanyId(authUser.getCompanyId());
        List<EsData> list = esServiceMapper.listDetailChartData(param);
 
 
        if (null == list || list.isEmpty()) {
            return PhoneRespUtil.error(RespCodeEnum.CODE_2000, "根据条件获取数据为空!");
        }
 
        DtoEnergy dtoEnergy = new DtoEnergy();
        dtoEnergy.setDepotId(param.getDepotId());
        dtoEnergy.setDepotName(phoneUtil.getDepotName(param.getCompanyId(),param.getDepotId()));
        for (EsData esData : list) {
            dtoEnergy.setEpSum(dtoEnergy.getEpSum() + esData.getEpInc());
            dtoEnergy.setEqSum(dtoEnergy.getEqSum() + esData.getEqInc());
            dtoEnergy.setEsSum(dtoEnergy.getEsSum() + esData.getEsInc());
        }
        return PhoneRespUtil.success(dtoEnergy, req);
    }
}