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 execute(PhoneRequest 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 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); } }