package com.ld.igds.sh.service; import com.alibaba.fastjson.JSONObject; import com.ld.igds.inout.InoutConstant; import com.ld.igds.log.service.InteStatusLogService; import com.ld.igds.models.InoutNoticeIn; import com.ld.igds.models.InoutRecord; import com.ld.igds.models.InoutSettle; import com.ld.igds.models.InteStatusLog; import com.ld.igds.sh.dto.ApiResponse; import com.ld.igds.sh.dto.Dto1304; 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 com.ld.igds.util.RedisUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; 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 ApiShServiceImpl1304 implements ApiShService { @Autowired private HApiShServiceImpl hApiShServiceImpl; @Autowired private InteStatusLogService inteStatusLogService; @Autowired private RedisUtil redisUtil; @Override public String getInterfaceId() { return ApiShConst.API_SH_1304; } @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(); // String key = RedisConst.buildKey(companyId, ApiShConst.API_SH_1112); // Date startTime = (Date) redisUtil.get(key); // if(null == startTime){ // startTime = DateUtils.addDays(param.getEndTime(), -30); // } // redisUtil.set(key, param.getEndTime()); if(null == param.getStartTime()){ param.setStartTime(DateUtils.addDays(param.getEndTime(), -1)); } //查询数据 List settleList = hApiShServiceImpl.listInoutSettle(companyId, param.getDepotId(), param.getStartTime(), param.getEndTime(), InoutConstant.TYPE_IN); //响应数据为空则直接返回响应码2000 if (settleList == null || settleList.isEmpty()) { return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request); } List list = new ArrayList<>(); Dto1304 dto; InteStatusLog log; InteStatusLog addLog; InoutRecord inoutRecord; InoutNoticeIn noticeIn; //封装数据信息 for (InoutSettle settle : settleList) { dto = new Dto1304(); dto.setJsdbm(settle.getId()); inoutRecord = hApiShServiceImpl.getInoutRecord(companyId, settle.getId()); if(null != inoutRecord){ dto.setHwbm(ApiShUtil.getGbDepotId(inoutRecord.getDepotId()) + "01"); dto.setZznm(ApiShUtil.getGbDepotId(inoutRecord.getDepotId()).substring(0, 21)); }else { dto.setHwbm("0"); dto.setZznm("0"); } noticeIn = hApiShServiceImpl.getNoticeIn(companyId, settle.getId()); if(null != noticeIn){ dto.setHtbm(StringUtils.isEmpty(noticeIn.getContractId())?"0":noticeIn.getContractId()); }else { dto.setHtbm("0"); } dto.setJssl(String.valueOf(settle.getSettleWeight())); dto.setJsdj(String.valueOf(settle.getPayPrice())); dto.setJsje(String.valueOf(settle.getPayMoney())); dto.setJssj(DateFormatUtils.format(settle.getPayTime()==null?new Date():settle.getPayTime(),"yyyy-MM-dd HH:mm:ss")); dto.setJsfs(StringUtils.isEmpty(settle.getPayType())?"0":settle.getPayType()); dto.setSkr(StringUtils.isEmpty(settle.getPayee())?"0":settle.getPayee()); dto.setYhkh(StringUtils.isEmpty(settle.getBankNum())?"0":settle.getBankNum()); dto.setSgjsdnm(settle.getId()); dto.setJsyxm(StringUtils.isEmpty(settle.getPayUser())?"0":settle.getPayUser()); dto.setZhgxsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")); //查询日志状态表,设置操作标志 log = inteStatusLogService.getLogByBizId(companyId, ApiShConst.API_SH_1304 + "_" + settle.getId()); if(null == log){ addLog = new InteStatusLog(); addLog.setBizId(ApiShConst.API_SH_1304 + "_" + settle.getId()); addLog.setCompanyId(companyId); addLog.setBizType(ApiShConst.API_SH_TYPE_INOUT); addLog.setInterfaceId(ApiShConst.API_SH_1304); addLog.setInterfaceType(ApiShConst.API_SH_TYPE_INOUT); 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); } }