This commit is contained in:
jiang 2025-07-16 21:40:32 +08:00
parent f607dcacaa
commit 6a6e31001e
8 changed files with 332 additions and 65 deletions

View File

@ -178,6 +178,12 @@ public class PurchaseController {
}
@PostMapping("addUnplannedPurchaseData")
public ServerResponse addUnplannedPurchaseData(HttpServletRequest request, @RequestParam(value = "file[]", required = false) MultipartFile[] files) {
return service.addUnplannedPurchaseData(request, files);
}
/**
* 发货修改数据接口
*

View File

@ -89,4 +89,7 @@ public class OutPlanVoDetails {
private int hisNum;
}

View File

@ -1,12 +1,14 @@
package com.bonus.aqgqj.business.backstage.entity.plan;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.bonus.aqgqj.business.backstage.entity.OutPlanVoSupInfo;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @className:PlanDetailVo
@ -87,6 +89,39 @@ public class PlanDetailVo {
*/
private String projectName;
/**
* 出库数量
*/
private String cgNum;
/**
* 利库数量
*/
private String lkNum;
/**
*出厂日期
*/
private String ccDay;
/**
* 检验日期
*/
private String jyDay;
/**
* 出库厂家清单
*/
private List<OutPlanVoSupInfo> supList;
private List<String> ids;
private String param;
/**
* 历史数量
*/
private int hisNum;
/**
* 新增条件限制
*/

View File

@ -70,7 +70,9 @@ public interface PlanApplyMapper {
* @author cwchen
* @date 2024/11/27 10:50
*/
void addPlanDetail(@Param("list") List<PlanDetailVo> details, @Param("params") PlanApplyVo data);
// void addPlanDetail(@Param("list") List<PlanDetailVo> details, @Param("params") PlanApplyVo data);
int addPlanDetail(@Param("applyId") Integer applyId, @Param("list") List<PlanDetailVo> list);
/**
* 详情-安全工器具明细

View File

@ -55,6 +55,10 @@ public interface PurchaseService {
*/
ServerResponse addPurchaseData(HttpServletRequest request, MultipartFile[] files);
ServerResponse addUnplannedPurchaseData(HttpServletRequest request, MultipartFile[] files);
/**
* 采购详情查看
* @param data

View File

@ -3,15 +3,22 @@ package com.bonus.aqgqj.business.backstage.service;
import com.alibaba.fastjson.JSON;
import com.bonus.aqgqj.business.backstage.entity.*;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanApplyVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanAuditRecordVo;
import com.bonus.aqgqj.business.backstage.entity.plan.PlanDetailVo;
import com.bonus.aqgqj.business.backstage.mapper.MaTypeMapper;
import com.bonus.aqgqj.business.backstage.mapper.PurchaseMapper;
import com.bonus.aqgqj.business.backstage.mapper.SupplierMapper;
import com.bonus.aqgqj.business.backstage.mapper.plan.PlanApplyMapper;
import com.bonus.aqgqj.business.backstage.mapper.plan.PlanAuditMapper;
import com.bonus.aqgqj.business.backstage.service.plan.PlanApplyService;
import com.bonus.aqgqj.business.system.entity.FileUploadVo;
import com.bonus.aqgqj.business.system.service.FileUploadService;
import com.bonus.aqgqj.manager.common.util.DateTimeHelper;
import com.bonus.aqgqj.manager.common.util.StringHelper;
import com.bonus.aqgqj.manager.common.util.StringUtils;
import com.bonus.aqgqj.manager.common.util.UserUtil;
import com.bonus.aqgqj.manager.security.entity.SelfUserEntity;
import com.bonus.aqgqj.manager.webResult.AjaxResult;
import com.bonus.aqgqj.manager.webResult.ServerResponse;
import com.google.common.collect.Maps;
@ -20,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@ -49,6 +57,15 @@ public class PurchaseServiceImpl implements PurchaseService {
@Autowired
private MaTypeMapper maTypeMapper;
@Resource(name = "PlanAuditMapper")
private PlanAuditMapper planAuditMapper;
@Resource(name = "PlanApplyService")
private PlanApplyService service;
@Resource(name = "PlanApplyMapper")
private PlanApplyMapper planApplyMapper;
/**
* 发货统计
*
@ -200,6 +217,7 @@ public class PurchaseServiceImpl implements PurchaseService {
String userId = UserUtil.getLoginUser().getUserId() + "";
String userName = UserUtil.getLoginUser().getUsername();
OutPlanVo outPlanVo = JSON.parseObject(params, OutPlanVo.class);
outPlanVo.setUserName(userName);
outPlanVo.setUpdater(userId);
outPlanVo.setCreator(userId);
@ -330,6 +348,182 @@ public class PurchaseServiceImpl implements PurchaseService {
return ServerResponse.createErroe("新增失败");
}
@Override
public ServerResponse addUnplannedPurchaseData(HttpServletRequest request, MultipartFile[] files) {
try {
String params = request.getParameter("params");
if (StringHelper.isEmpty(params)) {
return ServerResponse.createErroe("请求参数缺失");
}
String userId = UserUtil.getLoginUser().getUserId() + "";
String userName = UserUtil.getLoginUser().getUsername();
OutPlanVo outPlanVo = JSON.parseObject(params, OutPlanVo.class);
outPlanVo.setUserName(userName);
outPlanVo.setUpdater(userId);
outPlanVo.setCreator(userId);
/*
{"projectId":"466","needTime":"2025-07-16","projectPart":"1","applyType":"safety-tool","remark":"1","jsonData":"[{\"modelId\":\"4\",\"type\":\"安全工器具\",\"name\":\"大挂钩\",\"model\":\"60mm\",\"unit\":\"\",\"needNum\":\"10\",\"backDate\":\"\",\"remark\":\"\"}]"}
*/
/* List<PlanDetailVo> details = JSON.parseArray(data.getJsonData(), PlanDetailVo.class);*/
PlanApplyVo planApplyVo = new PlanApplyVo();
planApplyVo.setCreator(userName);
planApplyVo.setUpdater(userName);
planApplyVo.setNeedTime(outPlanVo.getFhDay());
planApplyVo.setProjectId(outPlanVo.getProId());
planApplyVo.setProjectPart(outPlanVo.getRemark());
planApplyVo.setRemark(outPlanVo.getRemark());
String code = getCode(planApplyMapper.getTodayPlanNum(planApplyVo));
planApplyVo.setCode(code);
planApplyVo.setJsonData(JSON.toJSONString( outPlanVo.getDetailsList()));
service.addApplyPlan(planApplyVo);
outPlanVo.setPlanId(String.valueOf(planApplyVo.getId()));
if (StringHelper.isEmpty(outPlanVo.getJbUser())) {
return ServerResponse.createErroe("请填写经办人");
}
if (StringHelper.isEmpty(outPlanVo.getAddress())) {
outPlanVo.setAddress("");
// return ServerResponse.createErroe("请填写收获地址");
}
if (files == null || files.length < 1) {
return ServerResponse.createErroe("请上传附件");
}
List<OutPlanVoDetails> detailsList = outPlanVo.getDetailsList();
if (StringUtils.isEmpty(detailsList)) {
return ServerResponse.createErroe("发货明细不能为空");
}
int allCkNum = 0;
int allLkNum = 0;
SupplierVo supp = new SupplierVo();
for (OutPlanVoDetails details : detailsList) {
List<OutPlanVoSupInfo> supInfoList = details.getSupList();
if (StringUtils.isEmpty(detailsList)) {
return ServerResponse.createErroe("厂商数据不能为空");
}
boolean hasDuplicates = supInfoList.stream()
.collect(Collectors.groupingBy(OutPlanVoSupInfo::getSupId))
.entrySet()
.stream()
.anyMatch(e -> e.getValue().size() > 1);
if (hasDuplicates) {
return ServerResponse.createErroe("同一型号厂商不能一致");
}
details.setProId(outPlanVo.getProId());
details.setPlanId(details.getPlanId());
int ckNum = 0;
int lkNum = 0;
//三级
int applyNum = mapper.getJsData(outPlanVo.getPlanId());
if (applyNum > 0) {
return ServerResponse.createErroe("该单子已被结算、不允许再次发货");
}
String needNum = details.getNeedNum();
for (OutPlanVoSupInfo supInfo : supInfoList) {
ckNum += supInfo.getCgNum();
lkNum += supInfo.getLkNum();
supInfo.setPlanId(outPlanVo.getPlanId());
supInfo.setProId(outPlanVo.getProId());
supInfo.setModelId(details.getModelId());
//shu数据校验
supp.setContractId(supInfo.getContractId());
supp.setModelId(details.getModelId());
supp.setSupId(supInfo.getSupId());
//验证数据
int num = supplierMapper.supCheck(supp);
if (num < 1) {
return ServerResponse.createErroe(supInfo.getSupName() + "-厂家合同内无此-" + details.getModel() + "-型号设备");
}
}
// int needNums=Integer.parseInt(needNum);
// if(ckNum+lkNum>needNums){
// return ServerResponse.createErroe(details.getName()+"0"+details.getModel()+"发货量超过需求量");
// }
//数据校验
MaTypeVo maTypeVo = new MaTypeVo();
maTypeVo.setModelId(details.getModelId());
int num = maTypeMapper.maTypeCheck(maTypeVo);
if (lkNum > num) {
return ServerResponse.createErroe(details.getModel() + "-型号设备的利库量大于库存量,库存不足!");
}
details.setCgNum(Integer.toString(ckNum));
details.setLkNum(Integer.toString(lkNum));
allCkNum += ckNum;
allLkNum += lkNum;
}
outPlanVo.setCgNum(allCkNum);
outPlanVo.setLkNum(allLkNum);
int successNum = mapper.insertPurchaseData(outPlanVo);
if (successNum != 1) {
return ServerResponse.createErroe("新增数据异常,请稍后重试");
}
List<FileUploadVo> fileList = uploadService.uploadImage(files, outPlanVo.getId(), "st_plan_out", "采购发货附件");
if (fileList.size() != files.length) {
return ServerResponse.createErroe("文件上传失败!");
}
for (OutPlanVoDetails details : detailsList) {
details.setOutId(outPlanVo.getId());
details.setDetailId(String.valueOf(planApplyVo.getId()));
int num = mapper.insertPurchaseDetailsData(details);
if (num != 1) {
return ServerResponse.createErroe("新增失败数据异常,请稍后重试");
}
List<OutPlanVoSupInfo> supInfoList = details.getSupList();
int succ = mapper.insertPurchaseDetailsSupData(details, supInfoList);
if (succ != supInfoList.size()) {
return ServerResponse.createErroe("新增失败数据异常,请稍后重试");
}
//更新需求
mapper.updatePlanDetails(details);
//更新库存
MaTypeVo maTypeVo = new MaTypeVo();
maTypeVo.setModelId(details.getModelId());
int nowNum = maTypeMapper.maTypeCheck(maTypeVo);
if (nowNum - Integer.parseInt(details.getLkNum()) > 0) {
maTypeVo.setStorageNum(nowNum - Integer.parseInt(details.getLkNum()) + "");
} else {
maTypeVo.setStorageNum("0");
}
maTypeMapper.updateMatype(maTypeVo);
}
//跟新计划
mapper.updatePlanData(outPlanVo);
//修改成功后返回数据
outPlanVo.setResultData(outPlanVo.getDetailsList().size() + "");
outPlanVo.setResultData2(allCkNum + "");
PlanAuditRecordVo vo = new PlanAuditRecordVo();
vo.setApplyId(planApplyVo.getId());
vo.setAuditType("1");
vo.setAuditStatus("2");
//修改审核状态
planAuditMapper.updatePlanAudit(vo);
SelfUserEntity account = UserUtil.getLoginUser();
for (int i = 2; i < 5; i++) {
vo.setAuditType(String.valueOf(i));//审核节点
vo.setAuditor(Integer.parseInt(account.getUserId() + ""));
vo.setUpdater(Integer.parseInt(account.getUserId() + ""));
vo.setAuditName(account.getUsername());
vo.setAuditNum(planApplyVo.getAuditNum());
planApplyMapper.addPlanRecord(vo);
}
return ServerResponse.createSuccess("新增成功", outPlanVo);
} catch (Exception e) {
log.error(e.toString(), e);
}
return ServerResponse.createErroe("新增失败");
}
/**
* 修改合同接口
*
@ -617,4 +811,15 @@ public class PurchaseServiceImpl implements PurchaseService {
}
private static String getCode(int num) {
num++;
String year = DateTimeHelper.getNowYMD();
if (num < 10) {
return year + "00" + num;
} else if (num < 100) {
return year + "0" + num;
}
return year + num;
}
}

View File

@ -104,7 +104,8 @@ public class PlanApplyServiceImpl implements PlanApplyService {
// 添加计划申请数据
mapper.addPlanApply(data);
// 添加安全工器具数据
mapper.addPlanDetail(details, data);
mapper.addPlanDetail(data.getId(),details);
data.setJsonData(JSON.toJSONString(details));
// 添加需求计划申请节点
PlanAuditRecordVo vo = setPlanAuditRecordVoData(data, acount, "0");
vo.setAuditNum(1);

View File

@ -41,23 +41,13 @@
</trim>
</insert>
<!--添加安全工器具数据-->
<insert id="addPlanDetail">
<insert id="addPlanDetail" useGeneratedKeys="true" keyProperty="list.id">
INSERT INTO st_plan_details
<trim prefix="(" suffix=")" suffixOverrides=",">
apply_id,
model_id,
need_num,
need_day,
remark,
type,
name,
model,
unit,
back_date
</trim>
(apply_id, model_id, need_num, need_day, remark, type, name, model, unit, back_date)
VALUES
<foreach collection="list" item="item" separator=",">
(#{params.id},#{item.modelId},#{item.needNum},#{item.needDay},#{item.remark},#{item.type},#{item.name},#{item.model},#{item.unit},#{item.backDate})
(#{applyId}, #{item.modelId}, #{item.needNum}, #{item.needDay},
#{item.remark}, #{item.type}, #{item.name}, #{item.model}, #{item.unit}, #{item.backDate})
</foreach>
</insert>
<!--添加需求计划申请节点-->
@ -110,24 +100,39 @@
(#{params.id},#{item.modelId},#{item.needNum},#{item.backDate},#{item.remark},#{item.type},#{item.name},#{item.model},#{item.unit})
</if>
<if test="item.id !=null">
UPDATE st_plan_details SET need_num = #{item.needNum},back_date = #{item.backDate},remark = #{item.remark}
UPDATE st_plan_details SET need_num = #{item.needNum},back_date = #{item.backDate},remark =
#{item.remark}
WHERE id = #{item.id}
</if>
</foreach>
</insert>
<!--修改计划申请数据-->
<update id="editPlanApply">
UPDATE st_plan_apply SET project_id = #{projectId},project_part = #{projectPart},project_content = #{projectContent},
need_time = #{needTime},remark = #{remark},updater = #{updater},update_time = #{updateTime},
need_num = #{needNum},audit_num = (audit_num + 1) WHERE id = #{id}
UPDATE st_plan_apply
SET project_id = #{projectId},
project_part = #{projectPart},
project_content = #{projectContent},
need_time = #{needTime},
remark = #{remark},
updater = #{updater},
update_time = #{updateTime},
need_num = #{needNum},
audit_num = (audit_num + 1)
WHERE id = #{id}
</update>
<!--修改审核状态-->
<update id="editAuditStatus">
UPDATE st_plan_apply SET status = '1',status_type = '2' WHERE id = #{id}
UPDATE st_plan_apply
SET status = '1',
status_type = '2'
WHERE id = #{id}
</update>
<!--需求计划撤回-->
<update id="withdrawData">
UPDATE st_plan_apply SET status = '0',status_type = '0' WHERE id = #{id}
UPDATE st_plan_apply
SET status = '0',
status_type = '0'
WHERE id = #{id}
</update>
<!--删除安全工器具数据-->
<delete id="delPlanDetail">
@ -167,11 +172,14 @@
<!--工程下拉选-->
<select id="getProSelect" resultType="java.util.Map">
SELECT bid_id AS id, name AS `name`
FROM bm_project WHERE is_active = '1'
FROM bm_project
WHERE is_active = '1'
</select>
<!--获取今日添加的计划申请数量-->
<select id="getTodayPlanNum" resultType="java.lang.Integer">
SELECT COUNT(*) FROM st_plan_apply WHERE DATE_FORMAT(create_time, '%Y-%m-%d') = CURRENT_DATE
SELECT COUNT(*)
FROM st_plan_apply
WHERE DATE_FORMAT(create_time, '%Y-%m-%d') = CURRENT_DATE
</select>
<!--详情-安全工器具明细-->
<select id="getPlanDetailList" resultType="com.bonus.aqgqj.business.backstage.entity.plan.PlanDetailVo">
@ -201,58 +209,59 @@
<select id="getPlanDetails" resultType="com.bonus.aqgqj.business.backstage.entity.plan.PlanApplyVo">
SELECT spa.id,
spa.code,
tbp.name AS proName,
spa.project_part AS projectPart,
tbp.name AS proName,
spa.project_part AS projectPart,
spa.project_content AS projectContent,
spa.need_time AS needTime,
spa.need_time AS needTime,
spa.creator,
spa.create_time AS createTime,
spa.create_time AS createTime,
spa.remark,
spa.status,
spa.status_type AS statusType,
spa.project_id AS projectId
spa.status_type AS statusType,
spa.project_id AS projectId
FROM st_plan_apply spa
LEFT JOIN bm_project tbp ON spa.project_id = tbp.bid_id
LEFT JOIN bm_project tbp ON spa.project_id = tbp.bid_id
WHERE spa.id = #{id}
</select>
<!--需求计划申请-操作记录-->
<select id="getAuditList" resultType="com.bonus.aqgqj.business.backstage.entity.plan.PlanAuditRecordVo">
select spr.id,
spr.apply_id AS applyId,
spr.auditor AS auditor,
spr.audit_time AS auditTime,
spr.apply_id AS applyId,
spr.auditor AS auditor,
spr.audit_time AS auditTime,
spr.audit_status AS auditStatus,
spr.audit_remark AS auditRemark,
spr.updater AS updater,
spr.update_time AS updateTime,
spr.audit_type AS auditType,
spr.audit_name AS auditName,
spa.create_time AS statrtTime,
pu.TELPHONE AS phone
spr.updater AS updater,
spr.update_time AS updateTime,
spr.audit_type AS auditType,
spr.audit_name AS auditName,
spa.create_time AS statrtTime,
pu.TELPHONE AS phone
FROM st_plan_record spr
LEFT JOIN pm_user pu on spr.auditor=pu.id
LEFT JOIN st_plan_apply spa on spr.apply_id=spa.id
WHERE spr.apply_id=#{id}
ORDER BY spr.audit_time DESC
LEFT JOIN pm_user pu on spr.auditor = pu.id
LEFT JOIN st_plan_apply spa on spr.apply_id = spa.id
WHERE spr.apply_id = #{id}
ORDER BY spr.audit_time , spr.audit_type DESC
</select>
<!--获取安全工器具列表-->
<select id="getList" resultType="com.bonus.aqgqj.business.backstage.entity.MaTypeVo">
SELECT mt.id AS id,
mt.parent_id AS parentId,
mt.name AS title,
mt.unit_name AS unitName,
mt3.name AS type,
mt.remark,
mt.level,
mt2.name,
mt.name AS model
mt.parent_id AS parentId,
mt.name AS title,
mt.unit_name AS unitName,
mt3.name AS type,
mt.remark,
mt.level,
mt2.name,
mt.name AS model
FROM st_ma_type mt
LEFT JOIN st_ma_type mt2 ON mt.parent_id = mt2.id
LEFT JOIN st_ma_type mt3 ON mt2.parent_id = mt3.id
INNER JOIN (
SELECT DISTINCT sct.model_id AS modelId
FROM st_contract_type sct
INNER JOIN st_contract sc ON sct.contract_id = sc.id AND sc.is_active = '0' AND CURRENT_DATE BETWEEN sc.start_time AND sc.end_time
SELECT DISTINCT sct.model_id AS modelId
FROM st_contract_type sct
INNER JOIN st_contract sc ON sct.contract_id = sc.id AND sc.is_active = '0' AND CURRENT_DATE BETWEEN
sc.start_time AND sc.end_time
) a ON a.modelId = mt.id
WHERE mt.level = '3'
<if test="modelName!=null and modelName!=''">
@ -266,27 +275,29 @@
<select id="getPlanData" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM st_plan_apply spa
WHERE spa.id = #{id} AND spa.status_type = '2' AND spa.status = '1'
WHERE spa.id = #{id}
AND spa.status_type = '2'
AND spa.status = '1'
</select>
<select id="getExist" resultType="com.bonus.aqgqj.business.backstage.entity.MaTypeVo">
SELECT mt.id AS id,
SELECT mt.id AS id,
mt.parent_id AS parentId,
mt.name AS title,
mt.name AS title,
mt.unit_name AS unitName,
mt3.name AS type,
mt3.name AS type,
mt.remark,
mt.level,
mt2.name,
mt.name AS model
mt.name AS model
FROM st_ma_type mt
LEFT JOIN st_ma_type mt2 ON mt.parent_id = mt2.id
LEFT JOIN st_ma_type mt3 ON mt2.parent_id = mt3.id
INNER JOIN (
SELECT DISTINCT sct.model_id AS modelId
FROM st_contract_type sct
INNER JOIN st_contract sc ON sct.contract_id = sc.id AND sc.is_active = '0' AND CURRENT_DATE BETWEEN sc.start_time AND sc.end_time
) a ON a.modelId = mt.id
INNER JOIN (SELECT DISTINCT sct.model_id AS modelId
FROM st_contract_type sct
INNER JOIN st_contract sc ON sct.contract_id = sc.id AND sc.is_active = '0' AND
CURRENT_DATE BETWEEN sc.start_time AND sc.end_time) a
ON a.modelId = mt.id
WHERE mt.level = '3'
and mt3.name = #{param.type}
and mt2.name = #{param.name}