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.InoutNoticeOut; 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.Dto1308; 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 ApiShServiceImpl1308 implements ApiShService { @Autowired private HApiShServiceImpl hApiShServiceImpl; @Autowired private InteStatusLogService inteStatusLogService; @Autowired private RedisUtil redisUtil; @Override public String getInterfaceId() { return ApiShConst.API_SH_1308; } @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_OUT); //响应数据为空则直接返回响应码2000 if (settleList == null || settleList.isEmpty()) { return RespUtil.error(RespCodeEnum.CODE_2000.getCode(), request); } List list = new ArrayList<>(); Dto1308 dto; InteStatusLog log; InteStatusLog addLog; InoutRecord inoutRecord; InoutNoticeOut noticeOut; //封装数据信息 for (InoutSettle settle : settleList) { dto = new Dto1308(); dto.setJsdbm(settle.getId()); noticeOut = hApiShServiceImpl.getNoticeOut(companyId, settle.getId()); if(null != noticeOut){ dto.setHtbm(StringUtils.isEmpty(noticeOut.getContractId())?"0":noticeOut.getContractId()); }else { dto.setHtbm("0"); } dto.setJssl(String.valueOf(settle.getSettleWeight())); dto.setJsdj(settle.getPayPrice() + ""); dto.setJsje(settle.getPayMoney() + ""); if(null == settle.getPayTime()){ settle.setPayTime(new Date()); } dto.setJssj(DateFormatUtils.format(settle.getPayTime(),"yyyy-MM-dd HH:mm:ss")); dto.setJsfs(StringUtils.isEmpty(settle.getPayType())?"0":settle.getPayType()); dto.setFkr(settle.getPayUser()); inoutRecord = hApiShServiceImpl.getInoutRecord(companyId, settle.getId()); if(null != inoutRecord){ dto.setZznm(ApiShUtil.getGbDepotId(inoutRecord.getDepotId()).substring(0, 21)); }else { dto.setZznm("0"); } dto.setYhkh(StringUtils.isEmpty(settle.getBankNum())?"0":settle.getBankNum()); dto.setSgjsdnm(settle.getId()); dto.setSgjsdbh(settle.getId()); dto.setJsyxm(StringUtils.isEmpty(settle.getPayUser())?"0":settle.getPayUser()); dto.setShrxm(StringUtils.isEmpty(settle.getPayUser())?"0":settle.getPayUser()); dto.setShsj(DateFormatUtils.format(settle.getPayTime(),"yyyy-MM-dd HH:mm:ss")); dto.setKhmc(StringUtils.isEmpty(settle.getPayee())?"0":settle.getPayee()); dto.setZdrxm(StringUtils.isEmpty(settle.getPayUser())?"0":settle.getPayUser()); dto.setZdsj(DateFormatUtils.format(settle.getPayTime(),"yyyy-MM-dd HH:mm:ss")); dto.setJsfsmc(StringUtils.isEmpty(settle.getPayType())?"0":settle.getPayType()); dto.setSjjssl(settle.getSettleWeight() + ""); dto.setSjjsje(settle.getPayMoney() + ""); dto.setHjsl(settle.getSettleWeight() + ""); dto.setSkfsbh(StringUtils.isEmpty(settle.getPayType())?"0":settle.getPayType()); dto.setZhgxsj(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")); //查询日志状态表,设置操作标志 log = inteStatusLogService.getLogByBizId(companyId, ApiShConst.API_SH_1308 + "_" + settle.getId()); if(null == log){ addLog = new InteStatusLog(); addLog.setBizId(ApiShConst.API_SH_1308 + "_" + settle.getId()); addLog.setCompanyId(companyId); addLog.setBizType(ApiShConst.API_SH_TYPE_INOUT); addLog.setInterfaceId(ApiShConst.API_SH_1308); 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); } }