发货 流程

This commit is contained in:
haozq 2024-11-08 13:23:53 +08:00
parent 8c0baa7280
commit 580e4d573d
10 changed files with 492 additions and 88 deletions

View File

@ -0,0 +1,45 @@
package com.bonus.gzgqj.business.plan.entity;
import lombok.Data;
@Data
public class FileUploadVo {
/**
* id
*/
private String id;
/**
* 文件名称
*/
private String fileName;
/**
* 文件路径
*/
private String fileUrl;
/**
* 业务id
*/
private String ownId;
private String createTime;
/**
* 创建人
*/
private String creator;
/**
* 文件类型
*/
private String fileType;
/**
* 业务表名称
*/
private String modelTable;
/**
* 业务表名称
*/
private String suffix;
}

View File

@ -0,0 +1,13 @@
package com.bonus.gzgqj.business.plan.mapper;
import com.bonus.gzgqj.business.plan.entity.FileUploadVo;
import org.springframework.stereotype.Repository;
@Repository
public interface FileUploadMapper {
/**
* 文件上传
* @param vo
*/
void insertFileUpload(FileUploadVo vo);
}

View File

@ -5,10 +5,10 @@ import cn.hutool.core.collection.ListUtil;
import com.alibaba.fastjson.JSON;
import com.bonus.gzgqj.business.plan.entity.*;
import com.bonus.gzgqj.business.plan.mapper.PlanOutMapper;
import com.bonus.gzgqj.manager.common.util.R;
import com.bonus.gzgqj.manager.common.util.SecurityUtils;
import com.bonus.gzgqj.manager.common.util.StringHelper;
import com.bonus.gzgqj.manager.common.util.StringUtils;
import com.bonus.gzgqj.business.utils.FileUploadService;
import com.bonus.gzgqj.business.utils.IDUtils;
import com.bonus.gzgqj.business.utils.SystemUtils;
import com.bonus.gzgqj.manager.common.util.*;
import com.bonus.gzgqj.manager.webResult.ServerResponse;
import com.github.pagehelper.PageInfo;
import lombok.Data;
@ -16,21 +16,28 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.omg.CORBA.INTERNAL;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
public class PlanOutServiceImpl implements PlanOutService{
@Autowired
private PlanOutMapper mapper;
@Autowired
private FileUploadService uploadService;
/**
* 查询工程需要的系那个
* @param data
@ -117,100 +124,166 @@ public class PlanOutServiceImpl implements PlanOutService{
//出库记录单存储
vo.setCreater(userId+"");
int num=mapper.insertProOutInfo(vo);
//存储文件
List<FileUploadVo> fileList=uploadService.uploadImage(files,vo.getId(),"t_plan_out");
if(StringUtils.isEmpty(fileList) || fileList.size()!=files.length){
return ServerResponse.createErroe("发货失败");
}
if(num>0){
//计算 本次全部发货数量及整改数量 最后同步到 工程 -计划-发货统计表中
int allFhNum=0;
int allTzNum=0;
for (ProOutDetail details:list){
allFhNum=allFhNum+details.getFhNum();
allTzNum=allTzNum+details.getTzNum();
//获取 计划数据
ProNeedInfo data=mapper.getProNeedInfo(details);
if(data==null){
mapper.deleteProOut(vo);
return ServerResponse.createErroe("未找到发货内容,发货失败");
}else{
ProNeedInfo insertObj=new ProNeedInfo();
BeanUtils.copyProperties(insertObj,data);
insertObj.setOutId(vo.getId());
insertObj.setDataType("1");
insertObj.setFhNum(details.getFhNum());
insertObj.setTzNum(details.getTzNum());
insertObj.setRemarks(details.getRemarks());
int num2=mapper.insertProNeedDetails(insertObj);
if(num2>=0){
//更新 工程-计划-发货 清单表
int fhNum=data.getFhNum();
int tzNum=data.getFhNum();
data.setRemarks(details.getRemarks());
int fhNum2=details.getFhNum();
int tzNum2=details.getFhNum();
data.setFhNum(fhNum+fhNum2);
data.setTzNum(tzNum+tzNum2);
mapper.updateNeedInfo(data);
}else {
return ServerResponse.createErroe("发货失败");
}
}
}
//是否有 新增
if(StringUtils.isNotEmpty(addList)){
//全部新增发货清单
for (ProAddInfoDetails details:addList){
allFhNum=allFhNum+details.getFhNum();
ProNeedInfo insertObj=new ProNeedInfo();
insertObj.setOutId(vo.getId());
insertObj.setDataType("1");
insertObj.setFhNum(details.getFhNum());
insertObj.setTzNum(0);
insertObj.setType(details.getType());
insertObj.setName(details.getName());
insertObj.setModule(details.getModule());
insertObj.setModuleId(details.getModuleId());
insertObj.setUnit(details.getUnit());
insertObj.setRemarks(details.getRemark());
insertObj.setDataType("2");
insertObj.setProId(vo.getProId());
//添加 记录清单
int num2=mapper.insertProNeedDetails(insertObj);
if(num2>=0){
//新增 工程-计划-发货 清单表
mapper.addNeedInfo(insertObj);
}else {
return ServerResponse.createErroe("发货失败");
}
}
}
//更新工程 总数据信息
ProPlanInfoVo data= mapper.getProPlanInfo(vo);
int recordNum=data.getRecordNum();
int outNum= data.getOutNum();
int needNum= data.getNeedNum();
recordNum=recordNum+1;
outNum=outNum+allFhNum;
data.setRecordNum(recordNum);
//发货数量
data.setOutNum(outNum);
//调整数量
data.setTzNum(allTzNum);
//更新 发货状态
if(needNum>outNum+allTzNum){
data.setStatus(1);
}else {
data.setStatus(2);
//处理 发货单
boolean a= planOutInfo(list,vo,allFhNum,allTzNum);
if(!a){
return ServerResponse.createErroe("发货失败");
}
data.setLastDay(vo.getCreateDay());
//更新 工程-计划 -统计表
mapper.updatePriPlanInfo(data);
//处理新增发货单
boolean b=addOutPlanInfo(addList,vo,allFhNum);
if(!b){
return ServerResponse.createErroe("发货失败");
}
//处理 发货后 统计及 详情数据
boolean c= updateProPlan(vo,allFhNum,allTzNum);
if(!c){
return ServerResponse.createErroe("发货失败");
}
return ServerResponse.createBySuccessMsg("发货成功");
}else {
return ServerResponse.createErroe("发货失败");
}
} catch (Exception e) {
log.error(e.toString(),e);
}
return ServerResponse.createSuccess();
}
public boolean planOutInfo(List<ProOutDetail> list,ProOutInfoVo vo,int allFhNum, int allTzNum){
try {
for (ProOutDetail details:list){
allFhNum=allFhNum+details.getFhNum();
allTzNum=allTzNum+details.getTzNum();
//获取 计划数据
ProNeedInfo data=mapper.getProNeedInfo(details);
if(data==null){
mapper.deleteProOut(vo);
return false;
}else{
ProNeedInfo insertObj=new ProNeedInfo();
BeanUtils.copyProperties(insertObj,data);
insertObj.setOutId(vo.getId());
insertObj.setDataType("1");
insertObj.setFhNum(details.getFhNum());
insertObj.setTzNum(details.getTzNum());
insertObj.setRemarks(details.getRemarks());
int num2=mapper.insertProNeedDetails(insertObj);
if(num2>=0){
//更新 工程-计划-发货 清单表
int fhNum=data.getFhNum();
int tzNum=data.getFhNum();
data.setRemarks(details.getRemarks());
int fhNum2=details.getFhNum();
int tzNum2=details.getFhNum();
data.setFhNum(fhNum+fhNum2);
data.setTzNum(tzNum+tzNum2);
mapper.updateNeedInfo(data);
return true;
}else {
return false;
}
}
}
}catch (Exception e){
log.error(e.toString(),e);
}
return true;
}
/**
* 更新工程 -统计数据
* @param allTzNum
* @param vo
* @param allFhNum
* @return
*/
public Boolean updateProPlan( ProOutInfoVo vo,int allFhNum, int allTzNum){
try {
//更新工程 总数据信息
ProPlanInfoVo data= mapper.getProPlanInfo(vo);
int recordNum=data.getRecordNum();
int outNum= data.getOutNum();
int needNum= data.getNeedNum();
recordNum=recordNum+1;
outNum=outNum+allFhNum;
data.setRecordNum(recordNum);
//发货数量
data.setOutNum(outNum);
//调整数量
data.setTzNum(allTzNum);
//更新 发货状态
if(needNum>outNum+allTzNum){
data.setStatus(1);
}else {
data.setStatus(2);
}
data.setLastDay(vo.getCreateDay());
//更新 工程-计划 -统计表
mapper.updatePriPlanInfo(data);
return true;
}catch (Exception e){
log.error(e.toString(),e);
}
return false;
}
/**
* 处理 新增 需求 及发货单
* 传入
* 新增集合发货单发货数量
*/
public Boolean addOutPlanInfo(List<ProAddInfoDetails> addList, ProOutInfoVo vo,int allFhNum){
try {
//是否有 新增
if(StringUtils.isNotEmpty(addList)){
//全部新增发货清单
for (ProAddInfoDetails details:addList){
allFhNum=allFhNum+details.getFhNum();
ProNeedInfo insertObj=new ProNeedInfo();
insertObj.setOutId(vo.getId());
insertObj.setDataType("1");
insertObj.setFhNum(details.getFhNum());
insertObj.setTzNum(0);
insertObj.setType(details.getType());
insertObj.setName(details.getName());
insertObj.setModule(details.getModule());
insertObj.setModuleId(details.getModuleId());
insertObj.setUnit(details.getUnit());
insertObj.setRemarks(details.getRemark());
insertObj.setDataType("2");
insertObj.setProId(vo.getProId());
//添加 记录清单
int num2=mapper.insertProNeedDetails(insertObj);
if(num2>=0){
//新增 工程-计划-发货 清单表
mapper.addNeedInfo(insertObj);
return true;
}else {
return false;
}
}
}
}catch (Exception e){
log.error(e.toString(),e);
}
return false;
}
public static void main(String[] args) {
String suffx= IDUtils.getSuffix("/C/SSSK4555.PNG");
System.err.println(suffx);
}
}

View File

@ -0,0 +1,74 @@
package com.bonus.gzgqj.business.utils;
import com.bonus.gzgqj.business.plan.entity.FileUploadVo;
import com.bonus.gzgqj.business.plan.mapper.FileUploadMapper;
import com.bonus.gzgqj.manager.common.util.DateTimeHelper;
import com.bonus.gzgqj.manager.common.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static com.bonus.gzgqj.business.utils.IDUtils.getSuffix;
import static com.bonus.gzgqj.business.utils.IDUtils.isImageFileExtension;
/**
* 文件上传业务
*/
@Service
@Slf4j
public class FileUploadService {
@Autowired
private FileUploadMapper mapper;
/**
* 上传文件
*/
public List<FileUploadVo> uploadImage(MultipartFile[] files , String outId, String table){
List<FileUploadVo> list=new ArrayList<>();
try {
for (MultipartFile file : files) {
String fileName = file.getOriginalFilename();
String suffix=IDUtils.getSuffix(fileName);
String newPath= SystemUtils.getUploadPath()+ DateTimeHelper.getNowYMD()+"/"+ IDUtils.createID()+suffix;
File uploadFile = new File(newPath);
//生成文件夹
if (!uploadFile.getParentFile().exists()) {
uploadFile.getParentFile().mkdirs();
}
String fileType=isImageFileExtension(fileName);
// 存入临时文件
file.transferTo(uploadFile);
FileUploadVo vo=new FileUploadVo();
vo.setFileName(fileName);
vo.setFileUrl(newPath);
vo.setOwnId(outId);
vo.setModelTable(table);
vo.setSuffix(suffix);
vo.setFileType(fileType);
String userId= SecurityUtils.getUserId()+"";
vo.setCreator(userId);
list.add(vo);
mapper.insertFileUpload(vo);
}
}catch (Exception e){
log.error(e.toString(),e);
}
return list;
}
}

View File

@ -0,0 +1,52 @@
package com.bonus.gzgqj.business.utils;
public class IDUtils {
private static byte[] lock = new byte[0];
// 位数默认是8位
private final static long w = 100000000;
/**
* 传入文件 名称
* @param fileName
* @return
*/
public static String getSuffix(String fileName){
return fileName.substring(fileName.lastIndexOf('.'));
}
public static void main(String[] args) {
System.err.println(createID());
}
/**
* 获取id
* @return
*/
public static String createID() {
long r = 0;
synchronized (lock) {
r = (long) ((Math.random() + 1) * w);
}
return System.currentTimeMillis() + String.valueOf(r).substring(1);
}
/**
* 是否是文件/图片
* @param name
* @return
*/
public static String isImageFileExtension(String name) {
name=name.toLowerCase();
String[] imageFormats = {"jpg", "jpeg", "png", "gif", "bmp", "tiff"};
for (String format : imageFormats) {
if (format.equals(name)) { // 判断扩展名
return "1";
}
}
return "2"; // 不是支持的图片格式
}
}

View File

@ -0,0 +1,74 @@
package com.bonus.gzgqj.business.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class SystemUtils {
public static String windowsPath;
public static String linuxPath;
/**
* 自动注入
*
* @param windowsPath
*/
@Value("${file.upload_path.windows}")
public void setWindowsPath(String windowsPath) {
SystemUtils.windowsPath = windowsPath;
}
/**
* 自动注入
*
* @param linuxPath
*/
@Value("${file.upload_path.linux}")
public void setLinuxPath(String linuxPath) {
SystemUtils.linuxPath = linuxPath;
}
/**
* 返回系统
*
* @return
*/
public static String getSystem() {
String os = System.getProperty("os.name");
//Windows操作系统
if (os != null && os.toLowerCase().startsWith("windows")) {
return "windows";
} else if (os != null && os.toLowerCase().startsWith("linux")) {//Linux操作系统
return "linux";
} else { //其它操作系统
return "other";
}
}
/**
* 获取文件上传路径
*
* @return
*/
public static String getUploadPath() {
String os = getSystem();
System.err.println("当前系统是=" + os);
if ("windows".equals(os)) {
return windowsPath;
} else if ("linux".equals(os)) {
return linuxPath;
} else {
return windowsPath;
}
}
}

View File

@ -0,0 +1,47 @@
package com.bonus.gzgqj.manager.common.config;
import com.bonus.gzgqj.business.utils.SystemUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
/**
* 跨域支持
* @return
* @return
*/
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*");
// registry.addMapping("/**")
// .allowedOrigins("http://example.com")
// .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
// .allowedHeaders("*")
// .allowCredentials(true);
}
};
}
/**
* 外部文件访问
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String filePath= SystemUtils.getUploadPath();//获取文件上传路径
/** 本地文件上传路径 */
registry.addResourceHandler("/statics/**")
.addResourceLocations("file:" + filePath);
registry.addResourceHandler("/files/**")
.addResourceLocations("file:"+filePath);
}
}

View File

@ -38,6 +38,12 @@ zhly:
aq:
enable: false
file:
upload_path:
windows: D://files//zg_gqj//
linux: /home/zg_gqj/files//
jwt:
secret: your_secret_key

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.gzgqj.business.plan.mapper.FileUploadMapper">
<insert id="insertFileUpload" useGeneratedKeys="true" keyProperty="id">
insert into bm_file_upload(
file_name,
file_url,
create_time,
creator,
model_table,
own_id,
suffix,
file_type
)values(#{fileName},#{fileUrl},now(),#{creator},#{modelTable},#{ownId},#{suffix},#{fileType})
</insert>
</mapper>

View File

@ -50,7 +50,7 @@
</select>
<select id="getPorInfoDetail" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select pni.id,pni.pro_id proId,pni.type,pni.name,pni.module,pni.module_id,pni.need_type needType,
IFNULL(pni.unit,'-') unit ,pni.need_num needNum ,pni.fh_num fhNum ,pro.`NAME` proName ,IF(pni.need_num-pni.fh_num<0,0,pni.need_num-pni.fh_num) diff
IFNULL(pni.unit,'-') unit ,pni.need_num needNum ,pni.fh_num fhNum ,pro.`NAME` proName ,IF(pni.need_num-pni.fh_num &lt;0,0,pni.need_num-pni.fh_num) diff
from t_pro_need_info pni
LEFT JOIN bm_project pro on pni.pro_id=pro.id
<where>