package com.ld.igds.m.service.impl;
|
|
import com.ld.igds.constant.RedisConst;
|
import com.ld.igds.inout.InoutConstant;
|
import com.ld.igds.inout.dto.InoutParam;
|
import com.ld.igds.m.dto.NoticeInData;
|
import com.ld.igds.m.dto.NoticeParam;
|
import com.ld.igds.m.service.InoutCommonService;
|
import com.ld.igds.m.mapper.InoutCommonMapper;
|
import com.ld.igds.models.*;
|
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.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Repository;
|
|
import java.util.*;
|
|
/**
|
* 出入库开始前的各种配置 --- 包含流程配置、出入库设备配置、通知单等
|
*
|
* @author chen
|
*/
|
@Slf4j
|
@Repository(InoutCommonService.BEAN_ID)
|
public class InoutCommonServiceImpl implements InoutCommonService {
|
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private InoutCommonMapper inoutManagerMapper;
|
|
@Override
|
public void flushInoutSysConfCache(InoutSysConf data) {
|
|
String key = RedisConst.buildKey(data.getCompanyId(), InoutConstant.CACHE_INOUT_SYS_CONF, data.getDeptId());
|
|
redisUtil.set(key, data);
|
}
|
|
@Override
|
public InoutSysConf getCacheInoutSysConf(String companyId, String deptId) {
|
if (null == companyId || null == deptId) {
|
return null;
|
}
|
// 从缓存中获取已有的组织编码
|
String key = RedisConst.buildKey(companyId, InoutConstant.CACHE_INOUT_SYS_CONF, deptId);
|
|
return (InoutSysConf) redisUtil.get(key);
|
}
|
|
@Override
|
public List<InoutSysConf> getCacheInoutSysConf(String companyId) {
|
if (StringUtils.isEmpty(companyId)) {
|
return null;
|
}
|
|
String pattern = RedisConst.buildKey(companyId, InoutConstant.CACHE_INOUT_SYS_CONF);
|
|
Set<String> keys = redisUtil.keys(pattern);
|
if (null == keys || keys.isEmpty()) {
|
return null;
|
}
|
|
List<InoutSysConf> list = new ArrayList<>();
|
for (String key : keys) {
|
list.add((InoutSysConf) redisUtil.get(key));
|
}
|
return list;
|
}
|
|
@Override
|
public void flushInoutConfCache(String companyId, String deptId) {
|
List<InoutConf> list = inoutManagerMapper.listInoutConf(companyId, deptId);
|
|
String key = RedisConst.buildKey(companyId, InoutConstant.CACHE_INOUT_CONF_LIST, deptId);
|
|
redisUtil.set(key, list);
|
|
log.debug("---更新出入库配置信息缓存----");
|
}
|
|
|
@Override
|
@SuppressWarnings("unchecked")
|
public List<InoutConf> getCacheInoutConf(String companyId, String deptId) {
|
if (null == companyId || null == deptId) {
|
return null;
|
}
|
String key = RedisConst.buildKey(companyId,
|
InoutConstant.CACHE_INOUT_CONF_LIST, deptId);
|
|
return (List<InoutConf>) redisUtil.get(key);
|
}
|
|
@Override
|
public InoutConf getCacheInoutConf(String companyId, String deptId, String confId) {
|
|
if (null == companyId || null == deptId || null == confId) {
|
return null;
|
}
|
|
List<InoutConf> list = getCacheInoutConf(companyId, deptId);
|
|
if (list != null && list.size() > 0) {
|
for (InoutConf inoutConf : list) {
|
if (inoutConf.getId().equals(confId)) {
|
return inoutConf;
|
}
|
}
|
}
|
return null;
|
}
|
|
@Override
|
public void updateInoutConfStatus(String ip, Integer port, String status) {
|
inoutManagerMapper.updateInoutConfStatus(ip, port, status);
|
}
|
|
@Override
|
public List<InoutCustomer> listCustomer(InoutParam param) {
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isNotEmpty(param.getKey())) {
|
param.setKey("%" + param.getKey() + "%");
|
}
|
return inoutManagerMapper.listCustomer(param);
|
}
|
|
// @Override
|
// public List<InoutCustomer> listCustomerByNoticeIn(InoutParam param) {
|
// if (StringUtils.isEmpty(param.getCompanyId())) {
|
// param.setCompanyId(ContextUtil.getCompanyId());
|
// }
|
// //设置当前年份
|
// Date date = new Date();
|
// if (null != param.getStart()) {
|
// date = param.getStart();
|
// }
|
// param.setYear(DateFormatUtils.format(date, "yyyy"));
|
//
|
// if (StringUtils.isNotEmpty(param.getKey())) {
|
// param.setKey("%" + param.getKey() + "%");
|
// }
|
// //设置通知单完成状态
|
// param.setType(InoutConstant.COMPLETE_STATUS_NONE);
|
// return inoutManagerMapper.listCustomerByNoticeIn(param);
|
// }
|
|
// @Override
|
// public List<InoutCustomer> listCustomerByNoticeOut(InoutParam param) {
|
// if (StringUtils.isEmpty(param.getCompanyId())) {
|
// param.setCompanyId(ContextUtil.getCompanyId());
|
// }
|
//
|
// //设置当前年份
|
// Date date = new Date();
|
// if (null != param.getStart()) {
|
// date = param.getStart();
|
// }
|
// param.setYear(DateFormatUtils.format(date, "yyyy"));
|
//
|
// if (StringUtils.isNotEmpty(param.getKey())) {
|
// param.setKey("%" + param.getKey() + "%");
|
// }
|
// //设置通知单完成状态
|
// param.setType(InoutConstant.COMPLETE_STATUS_NONE);
|
// return inoutManagerMapper.listCustomerByNoticeOut(param);
|
// }
|
|
@Override
|
public int updateCustomer(NoticeInData data) {
|
return inoutManagerMapper.updateCustomer(data);
|
}
|
|
@Override
|
public String getMaxCustomerId(String companyId) {
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
|
return inoutManagerMapper.getMaxCustomerId(companyId);
|
}
|
|
// @Override
|
// public InoutNoticeIn getInoutNoticeIn(NoticeInParam param) {
|
// List<InoutNoticeIn> list = inoutManagerMapper.listNoticeIn(param);
|
// if (null == list || list.isEmpty()) {
|
// return null;
|
// }
|
// return list.get(0);
|
// }
|
|
|
@Override
|
public int updateNoticeIn(NoticeInData data) {
|
int i = inoutManagerMapper.updateNoticeIn(data);
|
if (i == 0) {
|
log.info("系统中没有更新到当前用户任务信息,新增一个客户任务!");
|
|
InoutNoticeIn param = new InoutNoticeIn();
|
param.setCompanyId(data.getCompanyId());
|
param.setCustomerId(data.getCustomerId());
|
param.setCustomerName(data.getCustomerName());
|
param.setDeptId(data.getDeptId());
|
param.setFoodVariety(data.getFoodVariety());
|
param.setTargetNumber(data.getTargetNumber());
|
param.setCompleteStatus(InoutConstant.COMPLETE_STATUS_NONE);
|
param.setYear(data.getYear());
|
param.setName("入库通知单");
|
param.setCreateUser(data.getCreateUser());
|
param.setId(data.getId());
|
inoutManagerMapper.addNoticeIn(param);
|
}
|
return i;
|
}
|
|
@Override
|
public List<InoutNoticeIn> getUnComNoticeIn(String companyId) {
|
return inoutManagerMapper.getUnComNoticeIn(companyId);
|
}
|
|
@Override
|
public String reSumNoticeInComplete(NoticeParam param) {
|
if (StringUtils.isEmpty(param.getCustomerId())) {
|
return "客户编码为空!";
|
}
|
if (StringUtils.isEmpty(param.getFoodVariety())) {
|
return "粮食品种为空!";
|
}
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
inoutManagerMapper.reSumNoticeInComplete(param);
|
return null;
|
}
|
|
@Override
|
public Integer queryNoticeOut(NoticeParam param) {
|
return inoutManagerMapper.queryNoticeOut(param);
|
}
|
|
@Override
|
public Integer queryNoticeIn(NoticeParam param) {
|
return inoutManagerMapper.queryNoticeIn(param);
|
}
|
|
// @Override
|
// public InoutNoticeOut getInoutNoticeOut(NoticeOutParam param) {
|
// List<InoutNoticeOut> list = inoutManagerMapper.getNoticeOut(param);
|
// if (null == list || list.isEmpty()) {
|
// return null;
|
// }
|
// return list.get(0);
|
// }
|
|
@Override
|
public List<InoutNoticeOut> getUnComNoticeOut(String companyId) {
|
return inoutManagerMapper.getUnComNoticeOut(companyId);
|
}
|
|
|
@Override
|
public String reSumNoticeOutComplete(NoticeParam param) {
|
if (StringUtils.isEmpty(param.getCustomerId())) {
|
return "客户编码为空!";
|
}
|
if (StringUtils.isEmpty(param.getFoodVariety())) {
|
return "粮食品种为空!";
|
}
|
if (StringUtils.isEmpty(param.getDepotId())) {
|
return "仓库编码为空!";
|
}
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
inoutManagerMapper.reSumNoticeOutComplete(param);
|
return null;
|
}
|
|
@Override
|
public void updateSumNoticeIn(String deptId, List<InoutNoticeIn> noticeInList) {
|
|
if (null == noticeInList || noticeInList.isEmpty()) {
|
return;
|
}
|
|
//遍历通知单
|
NoticeParam param;
|
for (InoutNoticeIn noticeIn : noticeInList) {
|
|
if (!deptId.equals(noticeIn.getDeptId())) {
|
continue;
|
}
|
|
param = new NoticeParam(noticeIn.getCompanyId(), noticeIn.getDeptId(),
|
noticeIn.getCustomerId(), noticeIn.getFoodVariety(), noticeIn.getId());
|
|
log.info("开始更新出库通知单={}", param.toString());
|
|
String msg = this.reSumNoticeInComplete(param);
|
if (msg != null) {
|
log.info("入库通知单完成量统计失败={},失败原因={}", param.toString(), msg);
|
}
|
}
|
}
|
|
@Override
|
public void updateSumNoticeOut(String deptId, List<InoutNoticeOut> noticeOutList) {
|
|
if (null == noticeOutList || noticeOutList.isEmpty()) {
|
return;
|
}
|
|
//遍历通知单
|
NoticeParam param;
|
for (InoutNoticeOut noticeOut : noticeOutList) {
|
|
if (!deptId.equals(noticeOut.getDeptId())) {
|
continue;
|
}
|
|
param = new NoticeParam(noticeOut.getCompanyId(), noticeOut.getDeptId(), noticeOut.getDepotId(),
|
noticeOut.getCustomerId(), noticeOut.getFoodVariety(), noticeOut.getId());
|
|
log.info("开始更新出库通知单={}", param.toString());
|
|
String msg = this.reSumNoticeOutComplete(param);
|
if (msg != null) {
|
log.info("出库通知单完成量统计失败={},失败原因={}", param.toString(), msg);
|
}
|
}
|
}
|
|
@Override
|
public List<InoutNoticeIn> listNoticeIn(NoticeParam param) {
|
return inoutManagerMapper.listNoticeIn(param);
|
}
|
|
@Override
|
public List<InoutNoticeOut> listNoticeOut(NoticeParam param) {
|
return inoutManagerMapper.listNoticeOut(param);
|
}
|
|
|
}
|