package com.ld.igds.sh.service; import com.ld.igds.constant.DepotStatus; import com.ld.igds.constant.DepotType; import com.ld.igds.log.service.InteStatusLogService; import com.ld.igds.models.Building; import com.ld.igds.models.Depot; import com.ld.igds.models.InteStatusLog; import com.ld.igds.sh.dto.ApiResponse; import com.ld.igds.sh.dto.Dto1106; import com.ld.igds.sh.param.ApiRequest; 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 com.ld.igds.util.NumberUtil; import lombok.extern.slf4j.Slf4j; 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.ArrayList; import java.util.Date; import java.util.List; /** * 廒间信息数据接口 * * @author chen */ @Slf4j @Service public class ApiShServiceImpl1106 implements ApiShService { @Autowired private HApiShServiceImpl hApiShServiceImpl; @Autowired private InteStatusLogService inteStatusLogService; @Override public String getInterfaceId() { return ApiShConst.API_SH_1106; } @SuppressWarnings("unchecked") @Override public ApiResponse execute(ApiRequest request) { //获取参数信息 String deptId = request.getDeptId(); if(StringUtils.isEmpty(deptId)){ deptId = ContextUtil.subDeptId(null); } //获取单位信息 String companyId = ContextUtil.getDefaultCompanyId(); List depotList = hApiShServiceImpl.listDepot(companyId, deptId); //响应数据为空则直接返回响应码2000 if (depotList == null || depotList.isEmpty()) { return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request); } //封装数据 List list = new ArrayList<>(); Dto1106 dto; Building building; InteStatusLog log; InteStatusLog addLog; for (Depot depot : depotList) { if (DepotType.TYPE_03.getCode().equals(depot.getDepotType())) { continue; } dto = new Dto1106(); dto.setAjdh(ApiShUtil.getGbDepotId(depot.getId())); dto.setAjmc(depot.getName()); dto.setCfbh(ApiShUtil.getGbDepotId(depot.getId()).substring(0, 25)); building = hApiShServiceImpl.getBuilding(companyId, depot.getBuildingId()); if (null != building) { dto.setAjcd(building.getLength() == null ? "0.0" : building.getLength() / 2 + ""); dto.setAjkd(building.getWidth() == null ? "0.0" : building.getWidth() + ""); dto.setAjgd(building.getHeight() == null ? "0.0" : building.getHeight() + ""); } dto.setSjcr(depot.getStorageMax() == null ? "0.0" : NumberUtil.keepPrecision(depot.getStorageMax()/1000, 1) + ""); dto.setQyrq(DateFormatUtils.format((depot.getStoreDate() == null ? new Date() : depot.getStoreDate()), "yyyy-MM-dd")); if(DepotStatus.STATUS_9.getCode().equals(depot.getDepotStatus())){ dto.setAjzt("3"); //需大修 }else { dto.setAjzt("1"); //玩好 } dto.setZhgxsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")); //查询日志状态表,设置操作标志 log = inteStatusLogService.getLogByBizId(companyId, ApiShConst.API_SH_1106 + "_" + ApiShUtil.getGbDepotId(depot.getId())); if(null == log){ addLog = new InteStatusLog(); addLog.setBizId(ApiShConst.API_SH_1106 + "_" + ApiShUtil.getGbDepotId(depot.getId())); addLog.setCompanyId(companyId); addLog.setBizType(ApiShConst.API_SH_TYPE_BASIC); addLog.setInterfaceId(ApiShConst.API_SH_1106); addLog.setInterfaceType(ApiShConst.API_SH_TYPE_BASIC); addLog.setStatus(ApiShConst.API_SH_STATUS_SUCCESS); inteStatusLogService.addInteStatusLog(addLog); }else { dto.setCzbz(ApiShConst.API_SH_U); } list.add(dto); } //响应数据为空则直接返回响应码2000 if (list.isEmpty()) { return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request); } return RespUtil.success(list, request); } }