package com.fzzy.igds.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.fzzy.igds.bill.InoutBill;
|
import com.fzzy.igds.constant.Constant;
|
import com.fzzy.igds.constant.FoodVariety;
|
import com.fzzy.igds.constant.RedisConst;
|
import com.fzzy.igds.data.IgdsBaseParam;
|
import com.fzzy.igds.data.InoutData;
|
import com.fzzy.igds.data.InoutParam;
|
import com.fzzy.igds.data.InoutPrintBill;
|
import com.fzzy.igds.domain.Depot;
|
import com.fzzy.igds.domain.InoutRecord;
|
import com.fzzy.igds.mapper.InoutRecordMapper;
|
import com.fzzy.igds.utils.ContextUtil;
|
import com.fzzy.igds.utils.DateUtil;
|
import com.fzzy.igds.utils.MoneyUtil;
|
import com.fzzy.igds.utils.NumberUtil;
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
import com.ruoyi.common.core.redis.RedisCache;
|
import com.ruoyi.common.utils.StringUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.text.DecimalFormat;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @Description
|
* @Author CZT
|
* @Date 2025/12/2 10:36
|
*/
|
@Slf4j
|
@Service
|
public class InoutRecordService {
|
|
@Resource
|
private InoutRecordMapper inoutRecordMapper;
|
@Resource
|
private FileService fileService;
|
@Resource
|
private SysDeptService sysDeptService;
|
@Resource
|
private DepotService depotService;
|
@Resource
|
private RedisCache redisCache;
|
|
/**
|
* 分页查询数据
|
*
|
* @param page
|
* @param param
|
*/
|
public void listPageInout(Page<InoutRecord> page, InoutParam param) {
|
if (StringUtils.isBlank(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isBlank(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
QueryWrapper<InoutRecord> queryWrapper = getQueryWrapper(param);
|
inoutRecordMapper.selectPage(page, queryWrapper);
|
}
|
|
/**
|
* 查询数据集合
|
*
|
* @param param
|
*/
|
public List<InoutRecord> listInout(InoutParam param) {
|
if (StringUtils.isBlank(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isBlank(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
QueryWrapper<InoutRecord> queryWrapper = getQueryWrapper(param);
|
|
return inoutRecordMapper.selectList(queryWrapper);
|
}
|
|
/**
|
* 封装查询条件
|
*
|
* @param param
|
*/
|
public QueryWrapper<InoutRecord> getQueryWrapper(InoutParam param) {
|
QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
|
if (StringUtils.isNotBlank(param.getCompanyId())) {
|
queryWrapper.eq("company_id", param.getCompanyId());
|
}
|
if (StringUtils.isNotBlank(param.getDeptId())) {
|
queryWrapper.likeRight("dept_id", param.getDeptId());
|
}
|
if (StringUtils.isNotBlank(param.getCustomerName())) {
|
queryWrapper.like("customer_name", param.getCustomerName());
|
}
|
|
if (StringUtils.isNotBlank(param.getId())) {
|
queryWrapper.eq("id", param.getId());
|
}
|
if (StringUtils.isNotBlank(param.getPlateNum())) {
|
queryWrapper.like("plate_num", param.getPlateNum());
|
}
|
if (StringUtils.isNotBlank(param.getWeightTag())) {
|
//查询待称重的
|
queryWrapper.likeRight("progress", param.getWeightTag());
|
}
|
if (StringUtils.isNotBlank(param.getProgressTag())) {
|
//未完成的
|
queryWrapper.ne("progress", param.getProgressTag());
|
}
|
if (StringUtils.isNotBlank(param.getProgress())) {
|
queryWrapper.eq("progress", param.getProgress());
|
}
|
if (StringUtils.isNotBlank(param.getFoodVariety())) {
|
queryWrapper.eq("food_variety", param.getFoodVariety());
|
}
|
if (StringUtils.isNotBlank(param.getCheckStatus())) {
|
queryWrapper.eq("check_status", param.getCheckStatus());
|
}
|
if (StringUtils.isNotBlank(param.getDepotId())) {
|
queryWrapper.eq("depot_id", param.getDepotId());
|
}
|
if (StringUtils.isNotBlank(param.getType())) {
|
queryWrapper.eq("type", param.getType());
|
}
|
if (StringUtils.isNotBlank(param.getSettleTag())) {
|
queryWrapper.eq("settle_tag", param.getSettleTag());
|
}
|
if (null != param.getStart()) {
|
queryWrapper.ge("create_time", DateUtil.getCurZero(param.getStart()));
|
}
|
if (null != param.getEnd()) {
|
queryWrapper.le("create_time", DateUtil.getNextZero(param.getEnd()));
|
}
|
queryWrapper.ne("record_status", Constant.RECORD_STATUS_DEL); //不是删除的单子,即正常的单子
|
queryWrapper.orderByDesc("create_time");
|
|
return queryWrapper;
|
}
|
|
/**
|
* 根据时间类型,获取已完成的正常单据
|
* @param timeType
|
* @param param
|
* @return
|
*/
|
public List<InoutRecord> getCompleteInoutByTime(String timeType, IgdsBaseParam param) {
|
if(StringUtils.isBlank(timeType)){
|
return null;
|
}
|
|
QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.likeRight("dept_id", param.getDeptId());
|
queryWrapper.likeRight("progress", Constant.PROGRESS_RECORD); //已完成的单据
|
queryWrapper.ne("record_status", Constant.RECORD_STATUS_DEL); //不是删除的单子,即正常的单子
|
queryWrapper.ge(timeType, param.getStart());
|
queryWrapper.le(timeType, param.getEnd());
|
queryWrapper.orderByAsc("complete_time");
|
|
return inoutRecordMapper.selectList(queryWrapper);
|
}
|
|
/**
|
* 查询数据
|
*
|
* @param param
|
* @return
|
*/
|
public InoutRecord selectOne(InoutParam param) {
|
if (StringUtils.isBlank(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
QueryWrapper<InoutRecord> queryWrapper = getQueryWrapper(param);
|
|
return inoutRecordMapper.selectOne(queryWrapper);
|
}
|
|
/**
|
* 验证车牌号是否在流程中
|
*
|
* @param companyId
|
* @param plateNum
|
* @return
|
*/
|
public int checkExist(String companyId, String plateNum) {
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("company_id", companyId);
|
queryWrapper.eq("plate_num", plateNum);
|
queryWrapper.ne("progress", Constant.PROGRESS_RECORD);
|
|
return inoutRecordMapper.selectCount(queryWrapper);
|
}
|
|
/**
|
* 手动补单
|
*
|
* @param data
|
* @return
|
*/
|
public String handAddInoutRecord(InoutData data) {
|
|
//补单数据直接到结果状态
|
data.setRecordStatus(Constant.RECORD_STATUS_ADD);
|
data.setProgress(Constant.PROGRESS_RECORD);
|
if (null != data.getPerWet() && data.getPerWet() > 0) {
|
data.setCheckStatus(Constant.STATUS_CHECK);
|
}
|
String loginUser = ContextUtil.getLoginUserName();
|
if (StringUtils.isEmpty(data.getRegisterUser())) {
|
data.setRegisterUser(loginUser);
|
}
|
if (StringUtils.isEmpty(data.getFullWeightUser())) {
|
data.setFullWeightUser(loginUser);
|
}
|
if (StringUtils.isEmpty(data.getEmptyWeightUser())) {
|
data.setEmptyWeightUser(loginUser);
|
}
|
if (StringUtils.isEmpty(data.getHandleUser())) {
|
data.setHandleUser(loginUser);
|
}
|
if (StringUtils.isEmpty(data.getCompleteUser())) {
|
data.setCompleteUser(loginUser);
|
}
|
|
if (null == data.getCompleteTime()) {
|
data.setCompleteTime(new Date());
|
}
|
|
InoutRecord record = new InoutRecord();
|
BeanUtils.copyProperties(data, record);
|
//保存
|
int num = this.addInoutRecord(record);
|
|
//附件处理
|
fileService.saveInoutFiles(data.getFiles(), record.getId(), null, "INOUT");
|
|
if (num > 0) {
|
return null;
|
} else {
|
return "保存失败!";
|
}
|
}
|
|
/**
|
* 新增出入库记录
|
*
|
* @param list
|
* @return
|
*/
|
public String addInoutRecordList(List<InoutRecord> list) {
|
if(null == list || list.isEmpty()){
|
return "新增失败";
|
}
|
|
for (InoutRecord inoutRecord : list) {
|
addInoutRecord(inoutRecord);
|
}
|
|
return null;
|
}
|
|
/**
|
* 新增出入库记录
|
*
|
* @param data
|
* @return
|
*/
|
public int addInoutRecord(InoutRecord data) {
|
|
if (StringUtils.isBlank(data.getId())) {
|
String id = this.createId(data.getRegisterTime(), data.getCompanyId());
|
if (Constant.TYPE_IN.equals(data.getType())) {
|
data.setId("R_" + id);
|
} else if (Constant.TYPE_OUT.equals(data.getType())) {
|
data.setId("C_" + id);
|
} else {
|
data.setId("M_" + id);
|
}
|
}
|
data.setCreateBy(ContextUtil.getLoginUserName());
|
data.setCreateTime(new Date());
|
data.setUpdateBy(ContextUtil.getLoginUserName());
|
data.setUpdateTime(new Date());
|
|
int num = inoutRecordMapper.insert(data);
|
//TODO 更新缓存
|
|
return num;
|
|
}
|
|
/**
|
* 新增出入库记录
|
*
|
* @param data
|
* @return
|
*/
|
public int updateInoutRecord(InoutRecord data) {
|
|
data.setUpdateBy(ContextUtil.getLoginUserName());
|
data.setUpdateTime(new Date());
|
|
int num = inoutRecordMapper.updateById(data);
|
//TODO 更新缓存
|
//updateInoutCache(data);
|
return num;
|
|
}
|
|
/**
|
* 数据修改,保留修改记录
|
* @param updateData
|
* @return
|
*/
|
public int checkAndUpdate(InoutRecord updateData) {
|
|
//获取原来的数据
|
InoutParam param = new InoutParam();
|
param.setId(updateData.getId());
|
InoutRecord record = this.selectOne(param);
|
|
String remarks = checkRemarks(updateData, record);
|
updateData.setRemarks(remarks);
|
|
return updateInoutRecord(updateData);
|
}
|
|
/**
|
* 校验修改信息
|
* @param updateData 修改数据
|
* @param record 原始数据
|
* @return
|
*/
|
public String checkRemarks(InoutRecord updateData, InoutRecord record) {
|
|
String remarks = "【" + ContextUtil.getLoginUserName() + "】于["+DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss")+"]修改数据:";
|
|
boolean updateTag = false;
|
//校验仓库信息
|
if(null != updateData.getDepotId() && null != record.getDepotId()){
|
updateTag = !updateData.getDepotId().equals(record.getDepotId());
|
if(updateTag){
|
remarks += "[仓库编码](" + record.getDepotId() + ")修改为(" + updateData.getDepotId() + "),";
|
}
|
}
|
|
//校验品种信息
|
if(null != updateData.getFoodVariety() && null != record.getFoodVariety()){
|
updateTag = !updateData.getFoodVariety().equals(record.getFoodVariety());
|
if(updateTag){
|
remarks += "[品种](" + record.getFoodVariety() + ")修改为(" + updateData.getFoodVariety() + "),";
|
}
|
}
|
|
//粮食产地
|
if(null != updateData.getFoodLocation() && null != record.getFoodLocation()){
|
updateTag = !updateData.getFoodLocation().equals(record.getFoodLocation());
|
if(updateTag){
|
remarks += "[粮食产地](" + record.getFoodLocation() + ")修改为(" + updateData.getFoodLocation() + "),";
|
}
|
}
|
|
//粮食等级
|
if(null != updateData.getFoodLevel() && null != record.getFoodLevel()){
|
updateTag = !updateData.getFoodLevel().equals(record.getFoodLevel());
|
if(updateTag){
|
remarks += "[粮食等级](" + record.getFoodLevel() + ")修改为(" + updateData.getFoodLevel() + "),";
|
}
|
}
|
|
//粮食年份
|
if(null != updateData.getFoodYear() && null != record.getFoodYear()){
|
updateTag = !updateData.getFoodYear().equals(record.getFoodYear());
|
if(updateTag){
|
remarks += "[粮食年份](" + record.getFoodYear() + ")修改为(" + updateData.getFoodYear() + "),";
|
}
|
}
|
|
//承运人
|
if(null != updateData.getUserName() && null != record.getUserName()){
|
updateTag = !updateData.getUserName().equals(record.getUserName());
|
if(updateTag){
|
remarks += "[承运人](" + record.getUserName() + ")修改为(" + updateData.getUserName() + "),";
|
}
|
}
|
|
//校验通知单信息
|
if(null != updateData.getNoticeId() && null != record.getNoticeId()){
|
updateTag = !updateData.getNoticeId().equals(record.getNoticeId());
|
if(updateTag){
|
remarks += "[通知单编码](" + record.getNoticeId() + ")修改为(" + updateData.getNoticeId() + "),";
|
}
|
}
|
|
//校验往来单位信息
|
if(null != updateData.getCustomerName() && null != record.getCustomerName()){
|
updateTag = !updateData.getCustomerName().equals(record.getCustomerName());
|
if(updateTag){
|
remarks += "[往来单位](" + record.getCustomerName() + ")修改为(" + updateData.getCustomerName() + "),";
|
}
|
}
|
|
//单价
|
if(null != updateData.getPrice() && null != record.getPrice()){
|
updateTag = !updateData.getPrice().equals(record.getPrice());
|
if(updateTag){
|
remarks += "[单价](" + record.getPrice() + ")修改为(" + updateData.getPrice() + "),";
|
}
|
}
|
|
//结算金额
|
if(null != updateData.getSettleMoney() && null != record.getSettleMoney()){
|
updateTag = !updateData.getSettleMoney().equals(record.getSettleMoney());
|
if(updateTag){
|
remarks += "[结算金额](" + record.getSettleMoney() + ")修改为(" + updateData.getSettleMoney() + "),";
|
}
|
}
|
|
//水分
|
if(null != updateData.getPerWet() && null != record.getPerWet()){
|
updateTag = !updateData.getPerWet().equals(record.getPerWet());
|
if(updateTag){
|
remarks += "[水分](" + record.getPerWet() + ")修改为(" + updateData.getPerWet() + "),";
|
}
|
}
|
|
//杂质
|
if(null != updateData.getPerImpurity() && null != record.getPerImpurity()){
|
updateTag = !updateData.getPerImpurity().equals(record.getPerImpurity());
|
if(updateTag){
|
remarks += "[杂质](" + record.getPerImpurity() + ")修改为(" + updateData.getPerImpurity() + "),";
|
}
|
}
|
|
//毛重
|
if(null != updateData.getFullWeight() && null != record.getFullWeight()){
|
updateTag = !updateData.getFullWeight().equals(record.getFullWeight());
|
if(updateTag){
|
remarks += "[毛重](" + record.getFullWeight() + ")修改为(" + updateData.getFullWeight() + "),";
|
}
|
}
|
|
//皮重
|
if(null != updateData.getEmptyWeight() && null != record.getEmptyWeight()){
|
updateTag = !updateData.getEmptyWeight().equals(record.getEmptyWeight());
|
if(updateTag){
|
remarks += "[皮重](" + record.getEmptyWeight() + ")修改为(" + updateData.getEmptyWeight() + "),";
|
}
|
}
|
|
//扣重
|
if(null != updateData.getDeOther() && null != record.getDeOther()){
|
updateTag = !updateData.getDeOther().equals(record.getDeOther());
|
if(updateTag){
|
remarks += "[扣重](" + record.getDeOther() + ")修改为(" + updateData.getDeOther() + "),";
|
}
|
}
|
|
//结算重量
|
if(null != updateData.getSettleWeight() && null != record.getSettleWeight()){
|
updateTag = !updateData.getSettleWeight().equals(record.getSettleWeight());
|
if(updateTag){
|
remarks += "[结算重量](" + record.getSettleWeight() + ")修改为(" + updateData.getSettleWeight() + "),";
|
}
|
}
|
|
//出入库重量
|
if(null != updateData.getRecordWeight() && null != record.getRecordWeight()){
|
updateTag = !updateData.getRecordWeight().equals(record.getRecordWeight());
|
if(updateTag){
|
remarks += "[出入库重量](" + record.getRecordWeight() + ")修改为(" + updateData.getRecordWeight() + "),";
|
}
|
}
|
|
//登记时间
|
if(null != updateData.getRegisterTime() && null != record.getRegisterTime()){
|
updateTag = !updateData.getRegisterTime().equals(record.getRegisterTime());
|
if(updateTag){
|
remarks += "[登记时间](" + DateFormatUtils.format(record.getRegisterTime(),"yyyy-MM-dd HH:mm:ss") + ")修改为(" + DateFormatUtils.format(updateData.getRegisterTime(),"yyyy-MM-dd HH:mm:ss") + "),";
|
}
|
}
|
|
//满车时间
|
if(null != updateData.getFullWeightTime() && null != record.getFullWeightTime()){
|
updateTag = !updateData.getFullWeightTime().equals(record.getFullWeightTime());
|
if(updateTag){
|
remarks += "[满车时间](" + DateFormatUtils.format(record.getFullWeightTime(),"yyyy-MM-dd HH:mm:ss") + ")修改为(" + DateFormatUtils.format(updateData.getFullWeightTime(),"yyyy-MM-dd HH:mm:ss") + "),";
|
}
|
}
|
|
//空车时间
|
if(null != updateData.getEmptyWeightTime() && null != record.getEmptyWeightTime()){
|
updateTag = !updateData.getEmptyWeightTime().equals(record.getEmptyWeightTime());
|
if(updateTag){
|
remarks += "[空车时间](" + DateFormatUtils.format(record.getEmptyWeightTime(),"yyyy-MM-dd HH:mm:ss") + ")修改为(" + DateFormatUtils.format(updateData.getEmptyWeightTime(),"yyyy-MM-dd HH:mm:ss") + "),";
|
}
|
}
|
|
//完成时间
|
if(null != updateData.getCompleteTime() && null != record.getCompleteTime()){
|
updateTag = !updateData.getCompleteTime().equals(record.getCompleteTime());
|
if(updateTag){
|
remarks += "[完成时间](" + DateFormatUtils.format(record.getCompleteTime(),"yyyy-MM-dd HH:mm:ss") + ")修改为(" + DateFormatUtils.format(updateData.getCompleteTime(),"yyyy-MM-dd HH:mm:ss") + "),";
|
}
|
}
|
|
//满车称重人
|
if(null != updateData.getFullWeightUser() && null != record.getFullWeightUser()){
|
updateTag = !updateData.getFullWeightUser().equals(record.getFullWeightUser());
|
if(updateTag){
|
remarks += "[满车称重人](" + record.getFullWeightUser() + ")修改为(" + updateData.getFullWeightUser() + "),";
|
}
|
}
|
|
//空车称重人
|
if(null != updateData.getEmptyWeightUser() && null != record.getEmptyWeightUser()){
|
updateTag = !updateData.getEmptyWeightUser().equals(record.getEmptyWeightUser());
|
if(updateTag){
|
remarks += "[空车称重人](" + record.getEmptyWeightUser() + ")修改为(" + updateData.getEmptyWeightUser() + "),";
|
}
|
}
|
|
//备注说明
|
if(null != updateData.getRemarks() && null != record.getRemarks()){
|
updateTag = !updateData.getRemarks().equals(record.getRemarks());
|
if(updateTag){
|
remarks += "[备注说明](" + record.getRemarks() + ")修改为(" + updateData.getRemarks() + "),";
|
}
|
}
|
|
if(StringUtils.isNotBlank(record.getRemarks())){
|
remarks = record.getRemarks() + ";" + remarks;
|
}
|
|
return remarks;
|
}
|
|
/**
|
* 异常终止
|
*
|
* @param data
|
* @return
|
*/
|
public String errorInoutData(InoutRecord data) {
|
|
InoutParam param = new InoutParam();
|
param.setId(data.getId());
|
data = this.selectOne(param);
|
if (Constant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) {
|
return "当前信息已做异常处理,不支持重复执行!";
|
}
|
|
String msg = " 于" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm") + " 被 " + ContextUtil.getLoginUserName() + " 执行终止,原因:" + data.getRemarks();
|
|
data.setRemarks(msg);
|
data.setProgress(Constant.PROGRESS_RECORD);
|
data.setRecordStatus(Constant.RECORD_STATUS_DEL);
|
data.setCompleteTime(new Date());
|
|
int i = this.updateInoutRecord(data);
|
|
//TODO 删除缓存
|
|
if (i > 0) {
|
return null;
|
} else {
|
return "操作失败!";
|
}
|
}
|
|
/**
|
* 出入库流程ID创建 202001030001 202001030001
|
*
|
* @param registerTime
|
* @param companyId
|
* @return
|
*/
|
public String createId(Date registerTime, String companyId) {
|
|
// 时间戳标签
|
String timeKey = DateFormatUtils.format(registerTime, "yyyyMMdd");
|
|
// 从缓存中获取已有的组织编码
|
String cacheKey = RedisConst.buildKey(companyId, Constant.CACHE_RECORD_ID);
|
|
String cacheId = (String) redisCache.getCacheObject(cacheKey);
|
|
if (null != cacheId && cacheId.indexOf(timeKey) >= 0) {
|
String temp = cacheId.substring(cacheId.length() - 4);
|
Integer i = Integer.valueOf(temp);
|
i++;
|
temp = String.valueOf(i);
|
if (temp.length() == 1) {
|
cacheId = timeKey + "000" + temp;
|
}
|
if (temp.length() == 2) {
|
cacheId = timeKey + "00" + temp;
|
}
|
if (temp.length() == 3) {
|
cacheId = timeKey + "0" + temp;
|
}
|
if (temp.length() == 4) {
|
cacheId = timeKey + temp;
|
}
|
} else {
|
String result = this.getMaxId(companyId, timeKey);
|
if (null == result) {
|
cacheId = timeKey + "0001";
|
} else {
|
// 获取最后四位
|
int i = Integer.valueOf(result.substring(result.length() - 4));
|
i++;
|
String temp = String.valueOf(i);
|
if (temp.length() == 1) {
|
cacheId = timeKey + "000" + temp;
|
}
|
if (temp.length() == 2) {
|
cacheId = timeKey + "00" + temp;
|
}
|
if (temp.length() == 3) {
|
cacheId = timeKey + "0" + temp;
|
}
|
if (temp.length() == 4) {
|
cacheId = timeKey + temp;
|
}
|
}
|
}
|
|
// 更新缓存
|
redisCache.setCacheObject(cacheKey, cacheId);
|
|
return cacheId;
|
}
|
|
/**
|
* 查询最大id号,为空则返回null
|
*
|
* @param companyId
|
* @param timeKey
|
* @return
|
*/
|
public String getMaxId(String companyId, String timeKey) {
|
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("company_id", companyId);
|
queryWrapper.like("id", timeKey);
|
queryWrapper.orderByDesc("create_time");
|
|
List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper);
|
if (null == inoutRecords || inoutRecords.isEmpty()) {
|
return null;
|
} else {
|
return inoutRecords.get(0).getId();
|
}
|
}
|
|
/**
|
* 获取入库过磅单数据信息
|
*
|
* @param data
|
* @return
|
*/
|
public String inWeightBill(InoutRecord data) {
|
|
// 获取表单数据
|
InoutPrintBill bill = this.createBillData(data, "入库划码单");
|
|
// 调整模版数据并返回
|
String htmlStr = InoutBill.IN_WEIGHT_DEFAULT;
|
|
htmlStr = htmlStr.replace("billTitle", bill.getBillTitle());
|
|
htmlStr = htmlStr.replace("registerTime", bill.getRegisterTime());
|
htmlStr = htmlStr.replace("completeTime", bill.getCompleteTime());
|
htmlStr = htmlStr.replace("fullTime", bill.getFullTime());
|
htmlStr = htmlStr.replace("emptyTime", bill.getEmptyTime());
|
htmlStr = htmlStr.replace("serId", bill.getSerId());
|
|
htmlStr = htmlStr.replace("customerName", bill.getCustomerName());
|
htmlStr = htmlStr.replace("deptName", bill.getUnitName());
|
|
htmlStr = htmlStr.replace("driverName", bill.getDriverName());
|
htmlStr = htmlStr.replace("userNumberId", bill.getUserId());
|
htmlStr = htmlStr.replace("userContact", bill.getUserContact());
|
htmlStr = htmlStr.replace("userAddress", bill.getUserAddress());
|
htmlStr = htmlStr.replace("foodVariety", bill.getFoodVariety());
|
htmlStr = htmlStr.replace("depotName", bill.getDepotName());
|
htmlStr = htmlStr.replace("foodLocation", bill.getFoodLocation());
|
|
htmlStr = htmlStr.replace("plateNum", bill.getPlateNum());
|
htmlStr = htmlStr.replace("fullWeight",
|
new DecimalFormat("0.00").format(bill.getFullWeight()));
|
htmlStr = htmlStr.replace("emptyWeight",
|
new DecimalFormat("0.00").format(bill.getEmptyWeight()));
|
htmlStr = htmlStr.replace("netWeight",
|
new DecimalFormat("0.00").format(bill.getNetWeight()));
|
|
htmlStr = htmlStr.replace("deImpurity", bill.getDeImpurity() + "");
|
htmlStr = htmlStr.replace("deWet", bill.getDeWet() + "");
|
|
htmlStr = htmlStr.replace("recordWeight", new DecimalFormat("0.00").format(bill.getRecordWeight()));
|
htmlStr = htmlStr.replace("deCheck", bill.getDeCheck() + "");
|
htmlStr = htmlStr.replace("addCheck", bill.getAddCheck() + "");
|
|
htmlStr = htmlStr.replace("deSum", bill.getDeSum() + "");
|
htmlStr = htmlStr.replace("settleWeight",
|
new DecimalFormat("0.00").format(bill.getSettleWeight()));
|
|
htmlStr = htmlStr.replace("dePackage", bill.getDePackage() + "");
|
htmlStr = htmlStr.replace("deHandle", bill.getDeHandle() + "");
|
htmlStr = htmlStr.replace("deOther", bill.getDeOther() + "");
|
htmlStr = htmlStr.replace("price", bill.getPrice());
|
htmlStr = htmlStr.replace("settleMoney", bill.getSettleMoney() + "");
|
htmlStr = htmlStr.replace("wet", bill.getWet() + "");
|
htmlStr = htmlStr.replace("impurity", bill.getImpurity() + "");
|
|
htmlStr = htmlStr.replace("checkStatus", bill.getCheckStatus());
|
htmlStr = htmlStr.replace("remark", "");
|
htmlStr = htmlStr.replace("moneyName", bill.getMoneyName());
|
|
htmlStr = htmlStr.replace("unitName", bill.getUnitName());
|
htmlStr = htmlStr.replace("time", bill.getRegisterTime());
|
htmlStr = htmlStr.replace("handleStart", "");
|
htmlStr = htmlStr.replace("handleEnd", "");
|
htmlStr = htmlStr.replace("noticeId", bill.getNoticeId() == null ? "" : bill.getNoticeId());
|
htmlStr = htmlStr.replace("phone", data.getUserContact() == null ? "" : data.getUserContact() + "");
|
htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm"));
|
|
htmlStr = htmlStr.replaceAll("weightUser",
|
bill.getWeightUser() == null ? "" : bill.getWeightUser());
|
htmlStr = htmlStr.replaceAll("handleUser",
|
bill.getHandleUser() == null ? "" : bill.getHandleUser());
|
htmlStr = htmlStr.replaceAll("keeperName",
|
bill.getKeeperUser() == null ? "" : bill.getKeeperUser());
|
|
|
return htmlStr;
|
}
|
|
/**
|
* 获取出库过磅单
|
*
|
* @param data
|
* @return
|
*/
|
public String outWeightBill(InoutRecord data) {
|
// 获取表单数据
|
InoutPrintBill bill = this.createBillData(data, "出库划码单");
|
|
//默认模版
|
String htmlStr = InoutBill.OUT_WEIGHT_DEFAULT;
|
|
htmlStr = htmlStr.replace("billTitle", bill.getBillTitle());
|
|
htmlStr = htmlStr.replace("registerTime", bill.getRegisterTime());
|
htmlStr = htmlStr.replace("completeTime", bill.getCompleteTime());
|
htmlStr = htmlStr.replace("fullTime", bill.getFullTime());
|
htmlStr = htmlStr.replace("emptyTime", bill.getEmptyTime());
|
htmlStr = htmlStr.replace("serId", bill.getSerId());
|
|
htmlStr = htmlStr.replace("customerName", bill.getCustomerName());
|
htmlStr = htmlStr.replace("deptName", bill.getUnitName());
|
|
htmlStr = htmlStr.replace("driverName", bill.getDriverName());
|
htmlStr = htmlStr.replace("userNumberId", bill.getUserId());
|
htmlStr = htmlStr.replace("userContact", bill.getUserContact());
|
htmlStr = htmlStr.replace("userAddress", bill.getUserAddress());
|
htmlStr = htmlStr.replace("foodVariety", bill.getFoodVariety());
|
htmlStr = htmlStr.replace("depotName", bill.getDepotName());
|
htmlStr = htmlStr.replace("foodLocation", bill.getFoodLocation());
|
|
htmlStr = htmlStr.replace("plateNum", bill.getPlateNum());
|
htmlStr = htmlStr.replace("fullWeight",
|
new DecimalFormat("0.00").format(bill.getFullWeight()));
|
htmlStr = htmlStr.replace("emptyWeight",
|
new DecimalFormat("0.00").format(bill.getEmptyWeight()));
|
htmlStr = htmlStr.replace("netWeight",
|
new DecimalFormat("0.00").format(bill.getNetWeight()));
|
htmlStr = htmlStr.replace("dePackage",
|
new DecimalFormat("0.00").format(bill.getDePackage()));
|
htmlStr = htmlStr.replace("remark", "");
|
|
htmlStr = htmlStr.replace("settleWeight",
|
new DecimalFormat("0.00").format(bill.getSettleWeight()));
|
htmlStr = htmlStr.replace("deHandle", bill.getDeHandle() + "");
|
htmlStr = htmlStr.replace("recordWeight", new DecimalFormat("0.00").format(bill.getRecordWeight()));
|
htmlStr = htmlStr.replace("deSum", bill.getDeSum() + "");
|
htmlStr = htmlStr.replace("deOther", bill.getDeOther() + "");
|
htmlStr = htmlStr.replace("price", bill.getPrice());
|
htmlStr = htmlStr.replace("settleMoney", bill.getSettleMoney() + "");
|
htmlStr = htmlStr.replace("wet", bill.getWet() + "");
|
htmlStr = htmlStr.replace("impurity", bill.getImpurity() + "");
|
|
htmlStr = htmlStr.replace("unitName", getValue(bill.getUnitName()));
|
htmlStr = htmlStr.replace("time", bill.getRegisterTime());
|
htmlStr = htmlStr.replace("handleStart", "");
|
htmlStr = htmlStr.replace("handleEnd", "");
|
htmlStr = htmlStr.replace("noticeId", bill.getNoticeId() == null ? "" : bill.getNoticeId());
|
htmlStr = htmlStr.replace("phone", data.getUserContact() == null ? "" : data.getUserContact() + "");
|
htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm"));
|
|
htmlStr = htmlStr.replaceAll("weightUser", getValue(bill.getWeightUser()));
|
htmlStr = htmlStr.replace("handleUser", getValue(bill.getHandleUser()));
|
htmlStr = htmlStr.replaceAll("keeperName", getValue(bill.getKeeperUser()));
|
return htmlStr;
|
}
|
|
|
public String getValue(String value) {
|
if (null == value) return "";
|
return value;
|
}
|
|
/**
|
* 封装过磅单数据
|
*
|
* @param data
|
* @param billTitle
|
* @return
|
*/
|
private InoutPrintBill createBillData(InoutRecord data, String billTitle) {
|
InoutPrintBill bill = new InoutPrintBill();
|
|
bill.setBillTitle(billTitle);
|
|
SysDept dept = sysDeptService.getCacheDept(data.getCompanyId(), data.getDeptId());
|
if (null != dept && StringUtils.isNotEmpty(dept.getDeptName())) {
|
bill.setBillTitle(dept.getDeptName() + billTitle);
|
bill.setDeptId(dept.getDeptId() + "");
|
bill.setDeptName(dept.getDeptName() + "");
|
bill.setUnitName(dept.getDeptName());
|
}
|
|
bill.setCompanyId(data.getCompanyId() == null ? "" : data
|
.getCompanyId());
|
if (null == data.getRegisterTime()) {
|
data.setRegisterTime(new Date());
|
}
|
bill.setRegisterTime(DateFormatUtils.format(data.getRegisterTime(),
|
"yyyy-MM-dd HH:mm"));
|
|
if (null == data.getCompleteTime()) {
|
data.setCompleteTime(new Date());
|
}
|
bill.setCompleteTime(DateFormatUtils.format(data.getCompleteTime(),
|
"yyyy-MM-dd HH:mm"));
|
|
bill.setEmptyTime(DateFormatUtils.format(data.getEmptyWeightTime(),
|
"yyyy-MM-dd HH:mm:ss"));
|
bill.setFullTime(DateFormatUtils.format(data.getFullWeightTime(),
|
"yyyy-MM-dd HH:mm:ss"));
|
bill.setSerId(data.getId());
|
if ("5016".equals(data.getCompanyId()) || "5347".equals(data.getCompanyId()) || "5352".equals(data.getCompanyId())) {
|
bill.setCompleteTime(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
|
bill.setSerId(data.getId().substring(2));
|
|
}
|
|
//客户信息
|
bill.setCustomerName(data.getCustomerName() == null ? "" : data.getCustomerName());
|
bill.setUserId(data.getUserId() == null ? "" : data.getUserId());
|
bill.setUserAddress(data.getUserAddress() == null ? "" : data.getUserAddress());
|
bill.setUserContact(data.getUserContact() == null ? "" : data.getUserContact());
|
|
|
bill.setNoticeId(data.getNoticeId());
|
|
|
bill.setDriverName(data.getUserName() == null ? "" : data.getUserName());
|
|
// 获取仓库信息
|
Depot depot = depotService.getCacheDepot(data.getCompanyId(),
|
data.getDepotId());
|
if (depot != null) {
|
bill.setDepotName(depot.getName() == null ? "" : depot.getName());
|
bill.setHandleUser(depot.getStoreKeeperName() == null ? "" : depot
|
.getStoreKeeperName());
|
}
|
|
bill.setFoodVariety(FoodVariety.getMsg(data.getFoodVariety()));
|
bill.setFoodLocation(data.getFoodLocation() == null ? "" : data
|
.getFoodLocation());
|
bill.setPlateNum(data.getPlateNum());
|
|
bill.setFullWeight(data.getFullWeight());
|
bill.setEmptyWeight(data.getEmptyWeight());
|
bill.setNetWeight(data.getNetWeight());
|
bill.setRecordWeight(data.getRecordWeight());
|
bill.setCheckStatus(data.getCheckStatus().equals(Constant.STATUS_CHECK) ? "合格" : "不合格");
|
|
bill.setDeOther(data.getDeOther());
|
bill.setSettleWeight(data.getSettleWeight());
|
|
bill.setPrice(data.getPrice() == null ? "" : data.getPrice() + "");
|
if (data.getSettleMoney() <= 0) {
|
if (null != data.getPrice() && null != data.getRecordWeight()) {
|
data.setSettleMoney(NumberUtil.keepPrecision(data.getPrice() * data.getRecordWeight(), 2));
|
}
|
}
|
bill.setSettleMoney(data.getSettleMoney() == null ? "" : data.getSettleMoney() + "");
|
bill.setRemark(data.getRemarks() == null ? "" : data.getRemarks());
|
|
if (Constant.TYPE_IN.equals(data.getType())) {
|
bill.setWeightUser(data.getFullWeightUser());
|
}
|
if (Constant.TYPE_OUT.equals(data.getType())) {
|
bill.setWeightUser(data.getEmptyWeightUser());
|
}
|
bill.setHandleUser(data.getHandleUser());
|
bill.setKeeperUser(depot.getStoreKeeperName());
|
return bill;
|
}
|
|
/**
|
* 获取结算单
|
*
|
* @param
|
* @return
|
*/
|
public String printPay(InoutRecord data) {
|
|
// 调整模版数据并返回
|
String htmlStr = InoutBill.IN_SETTLE_DEFAULT;
|
//标题
|
//清远出发货单位及标题,使用公司名
|
String billTitle = data.getType().equals("IN") ? "入库结算单" : "出库结算单";
|
|
htmlStr = htmlStr.replace("[billTitle]", billTitle);
|
//库区名称
|
SysDept dept = sysDeptService.getCacheDept(data.getCompanyId(), data.getDeptId());
|
if (dept != null) {
|
htmlStr = htmlStr.replace("[deptId]", null == data.getDeptId() ? "" : dept.getDeptName());
|
} else {
|
htmlStr = htmlStr.replace("[deptId]", "");
|
}
|
|
//业务单号
|
htmlStr = htmlStr.replace("[id]", data.getId());
|
//打印时间
|
htmlStr = htmlStr.replace("[payTime]", null == data.getSettleTime() ? "" : DateFormatUtils.format(data.getSettleTime(), "yyyy年MM月dd日"));
|
//客户名称
|
htmlStr = htmlStr.replace("[customerName]", null == data.getCustomerName() ? "" : data.getCustomerName());
|
//承运人
|
htmlStr = htmlStr.replace("[userName]", null == data.getUserName() ? "" : data.getUserName());
|
//承运人联系电话
|
htmlStr = htmlStr.replace("[userContact]", null == data.getUserContact() ? "" : data.getUserContact());
|
//承运人身份证号
|
htmlStr = htmlStr.replace("[userId]", null == data.getUserId() ? "" : data.getUserId());
|
//承运人车牌号
|
htmlStr = htmlStr.replace("[plateNum]", null == data.getPlateNum() ? "" : data.getPlateNum());
|
//获取仓库信息
|
Depot depot = depotService.getCacheDepot(data.getCompanyId(), data.getDepotId());
|
if (null != depot) {
|
//货位信息
|
htmlStr = htmlStr.replace("[depotId]", depot.getName());
|
}
|
//粮食名称
|
htmlStr = htmlStr.replace("[foodVariety]", null == data.getFoodVariety() ? "" : FoodVariety.getMsg(data.getFoodVariety()));
|
|
//备注
|
htmlStr = htmlStr.replace("[remark]", null == data.getRemarks() ? "" : data.getRemarks());
|
//毛重
|
htmlStr = htmlStr.replace("[fullWeight]", null == data.getFullWeight() ? "" : String.format("%.2f", data.getFullWeight()));
|
//皮重
|
htmlStr = htmlStr.replace("[emptyWeight]", null == data.getEmptyWeight() ? "" : String.format("%.2f", data.getEmptyWeight()));
|
//扣重
|
htmlStr = htmlStr.replace("[deOther]", null == data.getDeOther() ? "" : String.format("%.2f", data.getDeOther()));
|
//粮油价格
|
htmlStr = htmlStr.replace("[payPrice]", null == data.getPrice() ? "" : String.format("%.3f", data.getPrice()));
|
//结算重量
|
htmlStr = htmlStr.replace("[settleWeight]", String.format("%.2f", data.getSettleWeight()));
|
//结算金额
|
htmlStr = htmlStr.replace("[payMoney]", null == data.getSettleMoney() ? "" : String.format("%.3f", data.getSettleMoney()));
|
|
//结算重量名称
|
htmlStr = htmlStr.replace("[payMoneyName]", MoneyUtil.formatToCN(new BigDecimal(String.format("%.2f", data.getSettleMoney()))));
|
|
return htmlStr;
|
}
|
|
}
|