package com.fzzy.sys.manager.inout;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.fzzy.igds.constant.Constant;
|
import com.fzzy.igds.constant.RespCodeEnum;
|
import com.fzzy.igds.data.*;
|
import com.fzzy.igds.domain.*;
|
import com.fzzy.igds.service.DicAreaService;
|
import com.fzzy.igds.service.InoutConfService;
|
import com.fzzy.igds.service.InoutNoticeService;
|
import com.fzzy.igds.service.InoutRecordService;
|
import com.fzzy.igds.utils.ContextUtil;
|
import com.fzzy.igds.utils.SystemUtil;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.redis.RedisCache;
|
import lombok.extern.slf4j.Slf4j;
|
import com.ruoyi.common.utils.StringUtils;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.*;
|
|
/**
|
* @Description 出入库业务处理
|
* @Author CZT
|
* @Date 2025/11/29 11:02
|
*/
|
@Slf4j
|
@Component
|
public class InoutManager {
|
|
@Resource
|
private RedisCache redisCache;
|
@Resource
|
private InoutConfService inoutConfService;
|
@Resource
|
private InoutRecordService inoutRecordService;
|
@Resource
|
private DicAreaService dicAreaService;
|
@Resource
|
private InoutNoticeService inoutNoticeService;
|
|
/**
|
* 根据用户请求信息,根据当前客户电脑IP,获取出入库称重上次选择的地磅
|
*
|
* @param httpRequest
|
* @return
|
*/
|
public String getInoutWeightByClient(HttpServletRequest httpRequest) {
|
String userIp = SystemUtil.getIP(httpRequest);
|
log.debug("----------------根据用户IP获取选择-地磅----{}", userIp);
|
|
String key = "INOUT:WEIGHT:" + userIp;
|
String sort = (String) redisCache.getCacheObject(key);
|
if (com.ruoyi.common.utils.StringUtils.isEmpty(sort)) sort = "1";
|
return sort;
|
}
|
|
/**
|
* 获取出入库的整个流程信息
|
*
|
* @param companyId
|
* @param deptId
|
* @param inoutType
|
* @return
|
*/
|
public String getInoutProgressConf(String companyId, String deptId, String inoutType) {
|
// 从缓存中获取出入库系统配置信息
|
InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(companyId, deptId);
|
String progressConf = null;
|
if (inoutSysConf != null) {
|
if (Constant.TYPE_IN.equals(inoutType)) {
|
progressConf = inoutSysConf.getProgressIn();
|
}
|
if (Constant.TYPE_OUT.equals(inoutType)) {
|
progressConf = inoutSysConf.getProgressOut();
|
}
|
}
|
return progressConf;
|
}
|
|
/**
|
* 获取出入库设备配置信息
|
*
|
* @param companyId
|
* @param deptId
|
* @return
|
*/
|
public List<InoutConf> getListInoutConf(String companyId, String deptId) {
|
return inoutConfService.getCacheInoutConf(companyId, deptId);
|
}
|
|
/**
|
* 根据配置获取出入库的配置参数
|
*
|
* @param listInoutConf 配置列表
|
* @param sort 方案序号
|
* @param type 设备类型
|
* @param inoutProgress 出入库流程
|
* @return 车牌设备配置,没有则返回NULL
|
*/
|
public InoutConf getInoutConf(List<InoutConf> listInoutConf, String sort, String type, String inoutProgress, int inOrder) {
|
if (null == listInoutConf) {
|
return new InoutConf(sort);
|
}
|
if (StringUtils.isEmpty(sort)) sort = "1";
|
|
InoutConf result = null;
|
for (InoutConf conf : listInoutConf) {
|
if (sort.equals(conf.getSort()) && type.equals(conf.getType()) && inoutProgress.equals(conf.getInoutProgress())) {
|
if (conf.getInOrder() == inOrder) {
|
result = conf;
|
break;
|
}
|
}
|
}
|
|
if (null == result) return new InoutConf(sort);
|
|
return result;
|
}
|
|
/**
|
* 根据配置获取出入库的配置参数
|
*
|
* @param listInoutConf
|
* @param type
|
* @return
|
*/
|
public List<InoutConf> getInoutConf(List<InoutConf> listInoutConf, String type) {
|
List<InoutConf> result = new ArrayList<>();
|
if (null == listInoutConf) return result;
|
for (InoutConf conf : listInoutConf) {
|
if (type.equals(conf.getType())) {
|
result.add(conf);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* 根据配置获取出入库的配置参数
|
*
|
* @param listInoutConf
|
* @param sort
|
* @param type
|
* @return
|
*/
|
public InoutConf getInoutConf(List<InoutConf> listInoutConf, String sort, String type) {
|
if (null == listInoutConf) return new InoutConf(sort);
|
if (StringUtils.isEmpty(sort)) sort = "1";
|
|
for (InoutConf conf : listInoutConf) {
|
if (sort.equals(conf.getSort()) && type.equals(conf.getType())) {
|
return conf;
|
}
|
}
|
return new InoutConf(sort);
|
}
|
|
/**
|
* 获取地磅重量编辑标签
|
*
|
* @param companyId
|
* @param deptId
|
* @return
|
*/
|
public String getWeightEditTag(String companyId, String deptId) {
|
// 从缓存中获取出入库系统配置信息
|
InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(companyId, deptId);
|
String weightEditTag = Constant.YN_N;
|
if (inoutSysConf != null) {
|
weightEditTag = inoutSysConf.getWeightEditTag();
|
}
|
if (null == weightEditTag) weightEditTag = Constant.YN_N;
|
|
return weightEditTag;
|
}
|
|
/**
|
* 出入库注册数据提交,出入库登记使用同一个方法,包含称重时直接登记
|
*
|
* @param data
|
* @return
|
*/
|
public PageResponse<InoutData> submitRegister(InoutData data) {
|
if (StringUtils.isEmpty(data.getCompanyId())) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(data.getDeptId())) {
|
data.setDeptId(ContextUtil.subDeptId(null));
|
}
|
|
int num = inoutRecordService.checkExist(data.getCompanyId(), data.getPlateNum());
|
if (num > 0) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "当前车牌号正在执行流程未结束,请核查车牌或联系管理员", data);
|
}
|
|
// 获取系统参数配置
|
InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
|
if (null == inoutSysConf) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提示:当前库区未配置出入库流程信息,请联系管理员", data);
|
}
|
|
// 获取下一个流程状态
|
String curProgress = data.getProgress();
|
String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
|
data.setProgress(nextProgress);
|
|
//去除身份证号中的空格
|
if (StringUtils.isNotEmpty(data.getUserId())) {
|
data.setUserId(data.getUserId().trim());
|
}
|
//去除姓名中的空格
|
if (StringUtils.isNotEmpty(data.getUserName())) {
|
data.setUserName(data.getUserName().trim());
|
}
|
//登记人及登记时间
|
data.setRegisterUser(ContextUtil.getLoginUserName());
|
data.setRegisterTime(new Date());
|
|
num = inoutRecordService.addInoutRecord(data);
|
|
if (num == 0) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "登记失败!", data);
|
}
|
|
//附件处理
|
saveInoutFiles(data.getFiles(), data.getId(), curProgress);
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "登记成功!", data);
|
}
|
|
/**
|
* 化验信息提交
|
*
|
* @param data
|
* @return
|
*/
|
public PageResponse<InoutData> submitCheck(InoutData data) {
|
SysUser user = ContextUtil.getLoginUser();
|
if (StringUtils.isEmpty(data.getCompanyId())) {
|
data.setCompanyId(user.getCompanyId());
|
}
|
if (StringUtils.isEmpty(data.getDeptId())) {
|
data.setDeptId(ContextUtil.subDeptId(user));
|
}
|
|
//化验人及时间
|
data.setCheckUser(user.getUserName());
|
data.setCheckTime(new Date());
|
data.setCheckStatus(Constant.STATUS_CHECK);
|
|
int num = inoutRecordService.updateInoutRecord(data);
|
|
if (num == 0) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提交失败!", data);
|
}
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "提交成功!", data);
|
}
|
|
/**
|
* 称重提交,包含称重登记提交及单独称重提交
|
*
|
* @param data
|
* @return
|
*/
|
public PageResponse<InoutData> submitWeight(InoutData data) {
|
if (Constant.PROGRESS_WEIGHT_EMPTY.equals(data.getProgress())) {
|
data.setEmptyWeightTime(new Date());
|
data.setEmptyWeightUser(ContextUtil.getLoginUserName());
|
}
|
if (Constant.PROGRESS_WEIGHT_FULL.equals(data.getProgress())) {
|
data.setFullWeightTime(new Date());
|
data.setFullWeightUser(ContextUtil.getLoginUserName());
|
}
|
if (StringUtils.isBlank(data.getId())) {
|
//表示称重时直接登记
|
return submitRegister(data);
|
}
|
|
//获取系统参数配置
|
InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
|
if (null == inoutSysConf) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提示:当前系统中流程配置异常,请联系管理员", data);
|
}
|
|
// 获取下一个流程状态
|
String curProgress = data.getProgress();
|
String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
|
data.setProgress(nextProgress);
|
|
//称重数据更新
|
int num = inoutRecordService.updateInoutRecord(data);
|
|
if (num == 0) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提交失败!", data);
|
}
|
|
//附件处理
|
saveInoutFiles(data.getFiles(), data.getId(), curProgress);
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
|
}
|
|
/**
|
* 值仓信息提交
|
*
|
* @param data
|
* @return
|
*/
|
public PageResponse<InoutData> submitHandle(InoutData data) {
|
|
// 获取系统参数配置
|
InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
|
if (null == inoutSysConf) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提示:当前系统中流程配置异常,请联系管理员", data);
|
}
|
|
// 获取下一个流程状态
|
String curProgress = data.getProgress();
|
String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
|
data.setProgress(nextProgress);
|
|
data.setHandleEnd(new Date());
|
data.setHandleUser(ContextUtil.getLoginUserName());
|
// 执行数据更新
|
int num = inoutRecordService.updateInoutRecord(data);
|
|
if (num == 0) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提交失败!", data);
|
}
|
|
//附件处理
|
saveInoutFiles(data.getFiles(), data.getId(), curProgress);
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "提交成功", data);
|
}
|
|
/**
|
* 异步执行附件保存
|
* @param files 附件信息
|
* @param bizId 业务id
|
* @param progress 流程节点
|
*/
|
@Async
|
public void saveInoutFiles(List<FileInfo> files, String bizId, String progress) {
|
|
if (null == files || files.isEmpty()) {
|
return;
|
}
|
|
//TODO 附件逻辑待处理
|
|
|
|
}
|
|
/**
|
* 获取下一流程
|
*
|
* @param curProgress
|
* @param type
|
* @param sysConf
|
* @return
|
*/
|
private String getNextProgress(String curProgress, String type, InoutSysConf sysConf) {
|
String nextProgress = null;
|
List<String> list = null;
|
if (Constant.TYPE_IN.equals(type)) {
|
list = Arrays.asList(sysConf.getProgressIn().split("-"));
|
}
|
if (Constant.TYPE_OUT.equals(type)) {
|
list = Arrays.asList(sysConf.getProgressOut().split("-"));
|
}
|
if (list != null) {
|
for (int i = 0; i < list.size() - 1; i++) {
|
if (curProgress.equals(list.get(i))) {
|
nextProgress = list.get(i + 1);
|
break;
|
}
|
}
|
}
|
return nextProgress;
|
}
|
|
/**
|
* 分页查询数据
|
*
|
* @param param
|
* @return
|
*/
|
public PageResponse<Page<InoutRecord>> pageInoutData(InoutParam param) {
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
|
param.setProgressTag(Constant.PROGRESS_RECORD);
|
|
Page<InoutRecord> corePage = new Page<>(param.getPage(), param.getLimit());
|
inoutRecordService.listPageInout(corePage, param);
|
|
if (null == corePage.getRecords() || corePage.getRecords().isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取到数据信息为空");
|
}
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000, corePage);
|
}
|
|
/**
|
* 查询待称重的数据
|
*
|
* @param param
|
* @return
|
*/
|
public PageResponse<List<InoutRecord>> listWeightData(InoutParam param) {
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
|
//设置称重流程标记
|
param.setWeightTag("WEIGHT");
|
|
List<InoutRecord> inoutRecords = inoutRecordService.listInout(param);
|
|
if (null == inoutRecords || inoutRecords.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取到数据信息为空");
|
}
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000, inoutRecords);
|
}
|
|
/**
|
* 查询待值仓的数据
|
*
|
* @param param
|
* @return
|
*/
|
public PageResponse<List<InoutRecord>> listHandleData(InoutParam param) {
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
|
List<InoutRecord> inoutRecords = inoutRecordService.listInout(param);
|
|
if (null == inoutRecords || inoutRecords.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取到数据信息为空");
|
}
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000, inoutRecords);
|
}
|
|
/**
|
* 查询数据
|
*
|
* @param param
|
* @return
|
*/
|
public PageResponse<InoutRecord> inoutQuery(InoutParam param) {
|
|
if (StringUtils.isEmpty(param.getId()) && StringUtils.isEmpty(param.getPlateNum())) {
|
return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(), "查询参数不完整,查询失败!");
|
}
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
|
if(Constant.PROGRESS_WEIGHT_EMPTY.equals(param.getProgress()) || Constant.PROGRESS_WEIGHT_FULL.equals(param.getProgress())){
|
//设置查询待称重的
|
param.setProgress(null);
|
//设置称重流程标记
|
param.setWeightTag("WEIGHT");
|
}
|
|
InoutRecord result = inoutRecordService.selectOne(param);
|
if (null == result) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
|
"系统未查询到执行中的单据信息", null);
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000, result);
|
}
|
|
/**
|
* 分页获取区划信息
|
*
|
* @param param
|
* @return
|
*/
|
public PageResponse<Page<DicArea>> pageDicArea(IgdsBaseParam param) {
|
|
Page<DicArea> corePage = new Page<>(param.getPage(), param.getLimit());
|
|
dicAreaService.listPageData(corePage, param.getKey());
|
|
if (null == corePage.getRecords() || corePage.getRecords().isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取到数据信息为空");
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000, corePage);
|
}
|
|
/**
|
* @param param
|
* @return
|
*/
|
public PageResponse<List<InoutNoticeIn>> listNoticeIn(NoticeParam param) {
|
|
SysUser user = ContextUtil.getLoginUser();
|
if (org.apache.commons.lang3.StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(user.getCompanyId());
|
}
|
param.setDeptId(ContextUtil.subDeptId(user));
|
|
List<InoutNoticeIn> list = inoutNoticeService.getNoticeIn(param.getCompanyId(), param.getDeptId(), Constant.COMPLETE_STATUS_NONE);
|
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "查询结果为空!");
|
}
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000, list);
|
}
|
|
/**
|
* @param param
|
* @return
|
*/
|
public PageResponse<List<InoutNoticeOut>> listNoticeOut(NoticeParam param) {
|
SysUser user = ContextUtil.getLoginUser();
|
if (org.apache.commons.lang3.StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(user.getCompanyId());
|
}
|
param.setDeptId(ContextUtil.subDeptId(user));
|
|
List<InoutNoticeOut> list = inoutNoticeService.getNoticeOut(param.getCompanyId(), param.getDeptId(), Constant.COMPLETE_STATUS_NONE);
|
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "查询结果为空!");
|
}
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000, list);
|
}
|
}
|