package com.ld.igds.sh.service; import com.alibaba.fastjson.JSONObject; import com.ld.igds.log.service.InteStatusLogService; import com.ld.igds.models.DepotConf; import com.ld.igds.models.InteStatusLog; import com.ld.igds.sh.dto.ApiResponse; import com.ld.igds.sh.dto.Dto1402; 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 lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.time.DateFormatUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 粮情参数配置接口 * * @author chen */ @Slf4j @Service public class ApiShServiceImpl1402 implements ApiShService { @Autowired private HApiShServiceImpl hApiShServiceImpl; @Autowired private InteStatusLogService inteStatusLogService; @Override public String getInterfaceId() { return ApiShConst.API_SH_1402; } @SuppressWarnings("unchecked") @Override public ApiResponse execute(ApiRequest request) { //获取参数信息 String deptId = request.getDeptId(); BaseParam param = JSONObject.parseObject(JSONObject.toJSONString(request.getData()), BaseParam.class); String companyId = ContextUtil.getDefaultCompanyId(); //查询温湿度信息,即粮情信息 List dataList = hApiShServiceImpl.listDepotConf(companyId, param.getDepotId()); //响应数据为空则直接返回响应码2000 if (dataList == null || dataList.isEmpty()) { return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request); } List list = new ArrayList<>(); Dto1402 dto1402; InteStatusLog log; InteStatusLog addLog; //封装数据信息 for (DepotConf depotConf : dataList) { dto1402 = new Dto1402(); dto1402.setNm(ApiShUtil.getGbDepotId(depotConf.getDepotId()).substring(0, 21)); dto1402.setZznm(ApiShUtil.getGbDepotId(depotConf.getDepotId()).substring(0, 21)); dto1402.setCfnm(ApiShUtil.getGbDepotId(depotConf.getDepotId()).substring(0, 25)); dto1402.setCfbh(ApiShUtil.getGbDepotId(depotConf.getDepotId())); String cableRule = depotConf.getCableRule(); String[] split = cableRule.split("-"); dto1402.setDlcs(split[0]); dto1402.setDlhs(split[1]); dto1402.setDlls(split[2]); if(null!= depotConf.getCableCir()){ String cableCir = depotConf.getCableCir(); String[] cir = cableCir.split(","); dto1402.setDlqs(cir.length+""); dto1402.setDlqplxq(cableCir); } dto1402.setScqd("0"); dto1402.setSczd((Integer.valueOf(split[1])*Integer.valueOf(split[2])-1)+""); dto1402.setZcqd("0"); dto1402.setZczd((Integer.valueOf(split[1])*Integer.valueOf(split[2])-1)+""); dto1402.setXcqd("0"); dto1402.setXczd((Integer.valueOf(split[1])*Integer.valueOf(split[2])-1)+""); dto1402.setYxfwqsc("1"); dto1402.setYxfwjsc(split[0]); dto1402.setZhgxsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")); //查询日志状态表,设置操作标志 log = inteStatusLogService.getLogByBizId(companyId, ApiShConst.API_SH_1402 + "_" + depotConf.getCompanyId() + depotConf.getDepotId()); if(null == log){ addLog = new InteStatusLog(); addLog.setBizId(ApiShConst.API_SH_1402 + "_" + depotConf.getCompanyId() + ApiShUtil.getGbDepotId(depotConf.getDepotId())); addLog.setCompanyId(companyId); addLog.setBizType(ApiShConst.API_SH_TYPE_TASK); addLog.setInterfaceId(ApiShConst.API_SH_1402); addLog.setInterfaceType(ApiShConst.API_SH_TYPE_TASK); addLog.setStatus(ApiShConst.API_SH_STATUS_SUCCESS); inteStatusLogService.addInteStatusLog(addLog); }else { dto1402.setCzbz(ApiShConst.API_SH_U); } list.add(dto1402); } //响应数据为空则直接返回响应码2000 if (list.isEmpty()) { return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request); } return RespUtil.success(list, request); } }