Browse Source

[feat]

添加采购订单前端页面实现:本次占用共享库存数新增 条件,如果共享库存占用数为0,则其的结果为0,且不可编辑;否则可编辑;设置本次采购数不能小于等于0;提交的时候去掉本次占用共享库存数不能为0的情况
采购计划前端页面,采购计划添加采购订单方法实现:遍历选择的数据,如果含有除了待申请和部分申请的数据提示:”所选采购计划单中包含状态不符合要求的采购计划单,只能选择状态为'待申请'或'部分申请'的采购计划单“;
采购计划子表新增 通过采购计划子表ID集合查询采购计划子表数据方法
修改采购计划 添加采购订单第二步展示选物料列表后端方法实现:合并采购计划添加采购订单后,料号相等的数据;合并setPurchaseNum、setSharedAvailableInventoryNum、setLatestQuoteRmb、setMaterialNoRmbSum、setMaterialRmbSum;处理合并后的数据:字段(本次占用共享库存数):必填;默认为0,若共享可用库存数>0,则默认=共享可用库存数,可修改;需0<=本次占用共享库存数<=共享可用库存数;过滤掉待采购数量 <= 0的数据;过滤掉采购计划状态为全部申请和全部作废的数据 2为全部申请、3为全部作废
修改采购订单 添加保存采购计划后端方法:前端传入的本次采购数都要先进行判空操作;
新增处理采购计划子表后端方法实现:收集前端传入的所有的物料号、得到本次采购的所有采购计划单号、过滤 allPurchasePlanChildList,只保留和前端 collectMaterialNo 相等的数据、将旧数据按物料编号分组、获取当前时间、通过遍历前端传入的数据 ,获取旧数据中相同物料编号的数据、 按照 订单创建时间 远离当前时间排序、计算 本次采购数也是实际采购数、计算待采购数、并且判断 本次采购数量不能大于待采购数量;部分申请:0<(实际采购数+共享库存占用数+作废数)<计划采购数;可添加采购订单、全部申请:0<(实际采购数+共享库存占用数+作废数)=计划采购数,作废数<计划采购数;不可添加采购订单、收集更新后的子表数据、更新采购计划子表;
新增 处理采购计划主表后端方法,实现:本次出货的所有采购计划子表的数据,把purchasePlanChildList按照物料采购计划单号进行分组、得到本次采购的所有采购计划单号、得到本次出货的所有采购计划单数据库中的数据、创建一个 map 用于快速查找主表数据、遍历更新主表数据、通过采购单号获取主表数据、初始化 actualPurchaseSum、累加 actualPurchaseSum、更新 purchaseSum、更新采购计划状态:如果实际采购数小于计划采购数,状态为待申请;如果实际采购数等于计划采购数,状态为全部申请、更新主表数据到数据库
dev
liuxiaoxu 6 days ago
parent
commit
5500865af9
  1. 2
      ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchasePlan.java
  2. 6
      ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java
  3. 192
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java
  4. 59
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java
  5. 8
      ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml
  6. 18
      ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html
  7. 50
      ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html

2
ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchasePlan.java

@ -51,7 +51,7 @@ public class PurchasePlan extends BaseEntity
@Excel(name = "含税总价(RMB)")
private BigDecimal rmbSum;
/** 计划采购总数 */
/** 计划采购总数为之前的数量合计 */
@Excel(name = "计划采购总数")
private Integer planPurchaseSum;

6
ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java

@ -101,4 +101,10 @@ public interface PurchasePlanChildMapper
* 通过采购计划单号集合查询采购计划子表数据
* */
List<PurchasePlanChild> selectPurchasePlanChildPlanCodeList(List<String> purchasePlanCodeList);
/*
*
* 通过采购计划子表ID集合查询采购计划子表数据
* */
List<PurchasePlanChild> selectBatchPurchasePlanChildByIdList(List<Long> collectPurchasePlanChildId);
}

192
ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java

@ -38,6 +38,7 @@ import com.ruoyi.purchase.mapper.PurchasePlanMapper;
import com.ruoyi.purchase.service.IPurchaseOrderService;
import com.ruoyi.system.domain.SysAttachFile;
import com.ruoyi.system.domain.SysCompanyInformation;
import com.ruoyi.system.domain.SysSalesOrderChild;
import com.ruoyi.system.domain.SysSupplier;
import com.ruoyi.system.mapper.SysCompanyInformationMapper;
import com.ruoyi.system.mapper.SysUserMapper;
@ -69,6 +70,7 @@ import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -92,6 +94,9 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
@Autowired
private PurchasePlanChildMapper purchasePlanChildMapper;
@Autowired
private PurchasePlanMapper purchasePlanMapper;
@Autowired
private RedisCache redisCache;
@ -249,6 +254,13 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
List<PurchasePlanSelectSupplierVo> purchasePlanSelectSupplierVoList = addPurchaseOrder.getPurchasePlanSelectSupplierVoList();
List<PurchasePlanSelectMaterialVo> purchasePlanSelectMaterialVoList = addPurchaseOrder.getPurchasePlanSelectMaterialVoList();
//先不判断处理本次占用库存数
//判断本次采购数
boolean anyNullThisPurchaseNum = purchasePlanSelectMaterialVoList.stream().anyMatch(item -> item.getThisPurchaseNum() == null);
if (anyNullThisPurchaseNum) {
throw new BusinessException("请填写本次采购数量");
}
PurchaseOrder purchaseOrder = new PurchaseOrder();
purchaseOrder.setPurchaseOrderCode(redisCache.generateBillNo("CG"));
purchaseOrder.setPurchasePlanCode(purchasePlanOne.getPurchasePlanCodes());
@ -270,6 +282,11 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
purchaseOrder.setCreateTime(new Date());
purchaseOrder.setCreateBy(loginName);
//处理采购计划子表
List<PurchasePlanChild> purchasePlanChildList = updatePurchasePlanChildByAddPurchaseOrder(addPurchaseOrder);
//处理采购计划主表
updatePurchasePlanByAddPurchaseOrder(addPurchaseOrder,purchasePlanChildList);
buildPurchaseChild(purchasePlanSelectMaterialVoList, purchaseOrder);
int result = purchaseOrderMapper.insertPurchaseOrder(purchaseOrder);
@ -279,6 +296,181 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
return result;
}
//处理采购计划子表
private List<PurchasePlanChild> updatePurchasePlanChildByAddPurchaseOrder(AddPurchaseOrder addPurchaseOrder) {
List<PurchasePlanChild> purchasePlanChildren = new ArrayList<>();
//暂时不处理共享库存占用总数和作废数
List<PurchasePlanSelectMaterialVo> purchasePlanSelectMaterialVoList = addPurchaseOrder.getPurchasePlanSelectMaterialVoList();
//收集前端传入的所有的物料号
List<String> collectMaterialNo = purchasePlanSelectMaterialVoList.stream().map(PurchasePlanSelectMaterialVo::getMaterialNo).collect(Collectors.toList());
PurchasePlanOne purchasePlanOne = addPurchaseOrder.getPurchasePlanOne();
String purchasePlanCodes = purchasePlanOne.getPurchasePlanCodes();
//得到本次采购的所有采购计划单号
List<String> purchasePlanCodeList = new ArrayList<>();
if (StringUtils.isNotEmpty(purchasePlanCodes)){
String[] splitSalesOrderCode = purchasePlanCodes.split(",");
purchasePlanCodeList = Arrays.asList(splitSalesOrderCode);
}
for (String purchasePlanCode : purchasePlanCodeList) {
PurchasePlanChild purchasePlanChild = new PurchasePlanChild();
purchasePlanChild.setPurchasePlanCode(purchasePlanCode);
}
List<PurchasePlanChild> allPurchasePlanChildList = purchasePlanChildMapper.selectPurchasePlanChildPlanCodeList(purchasePlanCodeList);
// 过滤 allPurchasePlanChildList,只保留和前端 collectMaterialNo 相等的数据
List<PurchasePlanChild> oldPurchasePlanChildList = allPurchasePlanChildList.stream()
.filter(child -> collectMaterialNo.contains(child.getMaterialNo()))
.collect(Collectors.toList());
// List<Long> collectPurchasePlanChildId = purchasePlanSelectMaterialVoList.stream().map(PurchasePlanSelectMaterialVo::getPurchasePlanChildId).collect(Collectors.toList());
//List<PurchasePlanChild> oldPurchasePlanChildList = purchasePlanChildMapper.selectBatchPurchasePlanChildByIdList(collectPurchasePlanChildId);
// 将旧数据按物料编号分组
Map<String, List<PurchasePlanChild>> oldDataGroupedByMaterialNo = oldPurchasePlanChildList.stream()
.collect(Collectors.groupingBy(PurchasePlanChild ::getMaterialNo));
// 当前时间
Date now = new Date();
for (PurchasePlanSelectMaterialVo purchasePlanSelectMaterialVo : purchasePlanSelectMaterialVoList) {
String materialNo = purchasePlanSelectMaterialVo.getMaterialNo();
// Integer thisPurchaseNum = purchasePlanSelectMaterialVo.getThisPurchaseNum();
// 获取旧数据中相同物料编号的数据
List<PurchasePlanChild> oldChildren = oldDataGroupedByMaterialNo.get(materialNo);
if (oldChildren != null && !oldChildren.isEmpty()) {
// 按照 订单创建时间 远离当前时间排序
oldChildren.sort(Comparator.comparing(oldChild -> -Math.abs(now.getTime() - oldChild.getCreateTime().getTime())));
for (PurchasePlanChild oldChild : oldChildren) {
Integer thisPurchaseNum = purchasePlanSelectMaterialVo.getThisPurchaseNum();
//本次采购数也是实际采购数
oldChild.setActualPurchaseNum(thisPurchaseNum);
//待采购数
Integer purchaseNum = oldChild.getPurchaseNum();
if (purchaseNum >= thisPurchaseNum){
purchaseNum = purchaseNum - thisPurchaseNum;
oldChild.setPurchaseNum(purchaseNum);
}else {
throw new BusinessException("本次采购数量不能大于待采购数量");
}
/*
* 部分申请:0<(实际采购数+共享库存占用数+作废数)<计划采购数;可添加采购订单
* 全部申请:0<(实际采购数+共享库存占用数+作废数)=计划采购数作废数<计划采购数;不可添加采购订单
* */
//计划采购数
Integer planPurchaseNum = oldChild.getPlanPurchaseNum();
if (thisPurchaseNum < planPurchaseNum){
oldChild.setPurchasePlanStatus("1");//部分申请
}
if (thisPurchaseNum.equals(planPurchaseNum)){
oldChild.setPurchasePlanStatus("2");//全部申请
}
oldChild.setUpdateTime(new Date());
oldChild.setUpdateBy(ShiroUtils.getLoginName());
oldChild.setThisPurchaseNum(thisPurchaseNum);
//收集更新后的子表数据
purchasePlanChildren.add(oldChild);
int result = purchasePlanChildMapper.updatePurchasePlanChild(oldChild);
if (result <= 0){
throw new BusinessException("更新采购计划子表数据失败");
}
// 更新完成后,跳出循环
break;
}
}
}
return purchasePlanChildren;
}
//处理采购计划主表
private void updatePurchasePlanByAddPurchaseOrder(AddPurchaseOrder addPurchaseOrder,List<PurchasePlanChild> purchasePlanChildList) {
//本次出货的所有采购计划子表的数据,把purchasePlanChildList按照物料采购计划单号进行分组
Map<String, List<PurchasePlanChild>> groupedByPurchasePlanCode = purchasePlanChildList.stream()
.collect(Collectors.groupingBy(PurchasePlanChild::getPurchasePlanCode));
PurchasePlanOne purchasePlanOne = addPurchaseOrder.getPurchasePlanOne();
String purchasePlanCodes = purchasePlanOne.getPurchasePlanCodes();
//得到本次采购的所有采购计划单号
List<String> purchasePlanCodeList = new ArrayList<>();
if (StringUtils.isNotEmpty(purchasePlanCodes)){
String[] splitSalesOrderCode = purchasePlanCodes.split(",");
purchasePlanCodeList = Arrays.asList(splitSalesOrderCode);
}
//本次出货的所有采购计划单数据库中的数据
List<PurchasePlan> purchasePlans = purchasePlanMapper.selectPurchaseOrderByPlanCodeList(purchasePlanCodeList);
// 创建一个 map 用于快速查找主表数据
Map<String, PurchasePlan> purchasePlanMap = purchasePlans.stream()
.collect(Collectors.toMap(PurchasePlan::getPurchasePlanCode, Function.identity()));
// 更新主表数据
for (Map.Entry<String, List<PurchasePlanChild>> entry : groupedByPurchasePlanCode.entrySet()) {
String purchasePlanCode = entry.getKey();
List<PurchasePlanChild> children = entry.getValue();
// 获取主表数据
PurchasePlan purchasePlan = purchasePlanMap.get(purchasePlanCode);
if (purchasePlan != null) {
// 初始化 actualPurchaseSum
if (purchasePlan.getActualPurchaseSum() == null) {
purchasePlan.setActualPurchaseSum(0);
}
// 累加 actualPurchaseSum
int thisPurchaseSum = children.stream()
.mapToInt(PurchasePlanChild::getThisPurchaseNum)
.sum();
purchasePlan.setActualPurchaseSum(purchasePlan.getActualPurchaseSum() + thisPurchaseSum);
// 更新 purchaseSum
int currentPurchaseSum = purchasePlan.getPurchaseSum();
purchasePlan.setPurchaseSum(currentPurchaseSum - thisPurchaseSum);
// 更新采购计划状态
if (purchasePlan.getActualPurchaseSum() < purchasePlan.getPlanPurchaseSum()) {
purchasePlan.setPurchasePlanStatus("1");
} else if (purchasePlan.getActualPurchaseSum().equals(purchasePlan.getPlanPurchaseSum())) {
purchasePlan.setPurchasePlanStatus("2");
}
// 更新其他字段
purchasePlan.setUpdateTime(new Date());
purchasePlan.setUpdateBy(ShiroUtils.getLoginName());
// 更新主表数据到数据库
int result = purchasePlanMapper.updatePurchasePlan(purchasePlan);
if (result <= 0) {
throw new BusinessException("更新采购计划主表数据失败");
}
}
}
}
//新增采购订单子表
private void buildPurchaseChild(List<PurchasePlanSelectMaterialVo> purchasePlanSelectMaterialVoList, PurchaseOrder purchaseOrder) {
List<PurchaseOrderChild> purchaseOrderChildren = new ArrayList<>();

59
ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java

@ -23,10 +23,7 @@ import com.ruoyi.purchase.domain.Vo.PurchasePlanSelectSupplierVo;
import com.ruoyi.purchase.mapper.PurchasePlanChildMapper;
import com.ruoyi.purchase.mapper.PurchaseQuoteChildMapper;
import com.ruoyi.purchase.mapper.PurchaseQuoteMapper;
import com.ruoyi.system.domain.SysMakeOrder;
import com.ruoyi.system.domain.SysMakeorderBom;
import com.ruoyi.system.domain.SysSalesOrderChild;
import com.ruoyi.system.domain.SysSupplier;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.Vo.SysSupplierVo;
import com.ruoyi.system.mapper.SysMakeOrderMapper;
import com.ruoyi.system.mapper.SysSalesOrderChildMapper;
@ -199,7 +196,59 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
//采购计划子表数据
List<PurchasePlanChild> purchasePlanChildList = purchasePlanChildMapper.selectPurchasePlanChildPlanCodeList(purchasePlanCodeList);
return purchasePlanChildList;
// 合并相同物料料号的数据
Map<String, PurchasePlanChild> mergedMap = purchasePlanChildList.stream()
.collect(Collectors.toMap(
PurchasePlanChild::getMaterialNo,
item -> item,
(existingItem, newItem) -> {
existingItem.setPurchaseNum(
(existingItem.getPurchaseNum() != null ? existingItem.getPurchaseNum() : 0) +
(newItem.getPurchaseNum() != null ? newItem.getPurchaseNum() : 0)
);
existingItem.setSharedAvailableInventoryNum(
(existingItem.getSharedAvailableInventoryNum() != null ? existingItem.getSharedAvailableInventoryNum() : 0) +
(newItem.getSharedAvailableInventoryNum() != null ? newItem.getSharedAvailableInventoryNum() : 0)
);
existingItem.setLatestQuoteRmb(
(existingItem.getLatestQuoteRmb() != null ? existingItem.getLatestQuoteRmb() : BigDecimal.ZERO)
.add(newItem.getLatestQuoteRmb() != null ? newItem.getLatestQuoteRmb() : BigDecimal.ZERO)
);
existingItem.setMaterialNoRmbSum(
(existingItem.getMaterialNoRmbSum() != null ? existingItem.getMaterialNoRmbSum() : BigDecimal.ZERO)
.add(newItem.getMaterialNoRmbSum() != null ? newItem.getMaterialNoRmbSum() : BigDecimal.ZERO)
);
existingItem.setMaterialRmbSum(
(existingItem.getMaterialRmbSum() != null ? existingItem.getMaterialRmbSum() : BigDecimal.ZERO)
.add(newItem.getMaterialRmbSum() != null ? newItem.getMaterialRmbSum() : BigDecimal.ZERO)
);
return existingItem;
}
));
// 将合并后的数据转换为列表
List<PurchasePlanChild> mergedList = new ArrayList<>(mergedMap.values());
mergedList.forEach(item->{
//字段(本次占用共享库存数):必填;默认为0,若共享可用库存数>0,则默认=共享可用库存数,可修改;需0<=本次占用共享库存数<=共享可用库存数
if (item.getSharedAvailableInventoryNum() > 0){
item.setSharedInventoryOccupancyNum(item.getSharedAvailableInventoryNum());
}else {
item.setSharedInventoryOccupancyNum(0);
}
});
//过滤掉待采购数量 <= 0的数据
mergedList = mergedList.stream().filter(item->item.getPurchaseNum() > 0).collect(Collectors.toList());
//过滤掉采购计划状态为全部申请和全部作废的数据 2为全部申请、3为全部作废
mergedList = mergedList.stream().filter(item->!item.getPurchasePlanStatus().equals("2") || !item.getPurchasePlanStatus().equals("3")).collect(Collectors.toList());
return mergedList;
}
/**

8
ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml

@ -64,6 +64,14 @@
</foreach>
</select>
<select id="selectBatchPurchasePlanChildByIdList" parameterType="Long" resultMap="PurchasePlanChildResult">
<include refid="selectPurchasePlanChildVo"/>
where purchase_plan_child_id in
<foreach collection="list" item="purchasePlanChildId" open="(" separator="," close=")">
#{purchasePlanChildId}
</foreach>
</select>
<insert id="insertPurchasePlanChild" parameterType="PurchasePlanChild" useGeneratedKeys="true" keyProperty="purchasePlanChildId">
insert into purchase_plan_child
<trim prefix="(" suffix=")" suffixOverrides=",">

18
ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html

@ -558,6 +558,16 @@ animation-fill-mode: none;
title: '本次占用共享库存数',
field: 'sharedAvailableInventoryNum',
editable: {
//动态禁用行内编辑
noEditFormatter: function(value, row, index){
if (row.sharedInventoryOccupancyNum === 0){
return "0";
}else {
return false;
}
},
validate: function(value) {
if ($.trim(value) === '') {
return '本次占用共享库存数不能为空';
@ -604,8 +614,8 @@ animation-fill-mode: none;
if (isNaN(value)) {
return '请输入有效的数字';
}
if (value < 0) {
return '本次采购数不能小于0';
if (value <= 0) {
return '本次采购数不能小于等于0';
}
//不能为小数
if (value % 1 !== 0) {
@ -670,8 +680,8 @@ animation-fill-mode: none;
//遍历选择的行,如果选择的行中sharedAvailableInventoryNum和thisPurchaseNum数据为空就进行提示
for (var i = 0; i < selectedRows.length; i++) {
var row = selectedRows[i];
if (!row.sharedAvailableInventoryNum || !row.thisPurchaseNum) {
$.modal.alertWarning('选择数据前请填写共享库存占用数和本次采购数进行合计');
if (!row.thisPurchaseNum) {
$.modal.alertWarning('选择数据前请填写本次采购数进行合计');
return;
}
}

50
ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html

@ -164,37 +164,51 @@
]
});
};
function addPurchaseOrder(){
//采购计划添加采购订单
function addPurchaseOrder() {
// 采购计划状态为待申请
const apply = "0";
// 采购计划状态为部分申请
const partApply = "1";
var purchasePlanCodes = "";
var selections = $("#bootstrap-table").bootstrapTable("getSelections");
if(selections.length === 0){
if (selections.length === 0) {
$.modal.alertWarning("请选择采购计划单");
return;
}else{
if(selections.length > 1 ){
//·拼接采购计划单号
for(let i=0;i<selections.length;i++){
if(i === selections.length - 1){
purchasePlanCodes += selections[i].purchasePlanCode ;
}else{
purchasePlanCodes += selections[i].purchasePlanCode + ",";
}
}
}else if(selections.length === 1){
purchasePlanCodes = selections[0].purchasePlanCode;
}
// 检查选中的采购计划单的状态
var invalidSelections = selections.filter(function(selection) {
return selection.purchasePlanStatus !== apply && selection.purchasePlanStatus !== partApply;
});
if (invalidSelections.length > 0) {
$.modal.alertWarning("所选采购计划单中包含状态不符合要求的采购计划单,只能选择状态为'待申请'或'部分申请'的采购计划单");
return;
}
// 拼接采购计划单号
for (let i = 0; i < selections.length; i++) {
if (i === selections.length - 1) {
purchasePlanCodes += selections[i].purchasePlanCode;
} else {
purchasePlanCodes += selections[i].purchasePlanCode + ",";
}
}
var url = prefix + "/addPurchaseOrder/" + purchasePlanCodes;
$.modal.openOptions({
title : "新增采购订单",
title: "新增采购订单",
url: url,
howButtonPanel: false,
btn: ['关闭'],
yes: function(index, layero){
$.modal.close(index);//使用layer.close(index);无效
yes: function (index, layero) {
$.modal.close(index); // 使用layer.close(index);无效
},
cancel: function(index, layero){
cancel: function (index, layero) {
$.modal.close(index);
}
});

Loading…
Cancel
Save