Commit 6e8027e6 by ice

提交采购申请下推采购订单的备用字段1填充库存现有量,采购订单审核数量与库存现有量判断功能

parent cdcb3990
...@@ -18,6 +18,7 @@ import orthopedics.vo.PurOrderHeaderPage; ...@@ -18,6 +18,7 @@ import orthopedics.vo.PurOrderHeaderPage;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/*采购订单模块*/ /*采购订单模块*/
@RestController @RestController
...@@ -44,6 +45,8 @@ public class PurOrderHeaderController { ...@@ -44,6 +45,8 @@ public class PurOrderHeaderController {
@Autowired @Autowired
private RcvReceiptHeaderService rcvReceiptHeaderService; private RcvReceiptHeaderService rcvReceiptHeaderService;
@Autowired
private TransactionServer transactionServer;
/** /**
*描述:下推生成采购订单 *描述:下推生成采购订单
...@@ -79,6 +82,11 @@ public class PurOrderHeaderController { ...@@ -79,6 +82,11 @@ public class PurOrderHeaderController {
} }
String excutor = hrPerson.getId(); String excutor = hrPerson.getId();
purOrderHeaderPage.setBuyerId(hrPerson.getId()); purOrderHeaderPage.setBuyerId(hrPerson.getId());
//插入库存现有量
for(PurOrderLine purOrderLine:purOrderHeaderPage.getPurOrderLineList()){
Integer sumItemIdQuantity = transactionServer.findByOrgIdAndItemId(purOrderHeaderPage.getOrgId(),purOrderLine.getItemId());
purOrderLine.setAttribute1(String.valueOf(sumItemIdQuantity));
}
PurOrderHeader purOrderHeader = new PurOrderHeader(); PurOrderHeader purOrderHeader = new PurOrderHeader();
BeanUtils.copyProperties(purOrderHeaderPage, purOrderHeader); BeanUtils.copyProperties(purOrderHeaderPage, purOrderHeader);
purOrderHeaderService.saveMain(purOrderHeader, purOrderHeaderPage.getPurOrderLineList()); purOrderHeaderService.saveMain(purOrderHeader, purOrderHeaderPage.getPurOrderLineList());
...@@ -100,69 +108,78 @@ public class PurOrderHeaderController { ...@@ -100,69 +108,78 @@ public class PurOrderHeaderController {
public Result editOrderHeaderStatus(@RequestBody List<PurOrderHeaderPage> purOrderHeaderPageList, public Result editOrderHeaderStatus(@RequestBody List<PurOrderHeaderPage> purOrderHeaderPageList,
@RequestParam(value = "status",required = true)String status, @RequestParam(value = "status",required = true)String status,
@RequestParam(value = "access_token",required = true)String accessToken){ @RequestParam(value = "access_token",required = true)String accessToken){
//检查accesstoken的有效性
SysAccessToken sysAccessToken = userServer.checkAccessToken(accessToken);
//查询用户
SysUser sysUser = userServer.getSysUserById(sysAccessToken.getUserId());
if(sysUser == null){
return new Result(false,StatusCode.ERROR,ErrorEnum.UserNotExist.getErrorMsg());
}
String updateBy = sysUser.getRealname();
//创建一个集合存放状态不匹配的采购单号,用于返回错误信息 //创建一个集合存放状态不匹配的采购单号,用于返回错误信息
List<String> errorIds = new ArrayList<>(); List<String> errorList = new ArrayList<>();
//判断要审核或强制完成的订单是否存在以及状态 //判断要审核或强制完成的订单是否存在以及状态
for(PurOrderHeaderPage purOr : purOrderHeaderPageList){ label:for(PurOrderHeaderPage purOrderHeaderPage : purOrderHeaderPageList){
PurOrderHeader purOrderHeader = purOrderHeaderService.selectPurOrderById(purOr.getId()); PurOrderHeader purOrderHeader = purOrderHeaderService.selectPurOrderById(purOrderHeaderPage.getId());
//判断实体类是否存在 //判断实体类是否存在
if(purOrderHeader == null){ if(purOrderHeader == null){
return new Result(false,20001,ErrorEnum.NotExistModel.getErrorMsg()); errorList.add("选中的采购订单号为"+purOrderHeaderPage.getOrderNumber()+"不存在,请刷新!");
} continue label;
if(!purOrderHeader.getHeaderStatus().equals(purOr.getHeaderStatus())){
return new Result(false,20001,ErrorEnum.DataTransmitError.getErrorMsg());
} }
//调用审核接口 //调用审核接口
if("approval".equals(status)){ if("approval".equals(status)){
//审核时状态必须为新建new //审核时状态必须为新建new
if(!"new".equals(purOr.getHeaderStatus())){ if(!"new".equals(purOrderHeader.getHeaderStatus())){
errorIds.add(purOr.getOrderNumber()); errorList.add("采购单号为:"+purOrderHeader.getOrderNumber()+"的状态不为新建,审核失败!");
continue label;
}
if("000000006c60dba1016c60f588e00002".equals(purOrderHeader.getOrderType())) {
List<PurOrderLine> purOrderLineList = purOrderLineService.findOrderLineByHeaderId(purOrderHeader.getId());
for (PurOrderLine purOrderLine : purOrderLineList) {
Integer quantity = Integer.valueOf(purOrderLine.getQuantity());
Integer newSumQuantity = transactionServer.findByOrgIdAndItemId(purOrderHeader.getOrgId(),purOrderLine.getItemId());
if(null == purOrderLine.getAttribute1() || "".equals(purOrderLine.getAttribute1())){
purOrderLineService.updateOrderLineSumQuantity(String.valueOf(newSumQuantity),purOrderLine.getId());
}else {
Integer sumQuantity = Integer.valueOf(purOrderLine.getAttribute1());
if (sumQuantity != newSumQuantity) {
purOrderLineService.updateOrderLineSumQuantity(String.valueOf(newSumQuantity), purOrderLine.getId());
}
}
if(quantity > newSumQuantity){
errorList.add("采购订单号为:"+purOrderHeader.getOrderNumber()+"库存现有量不足,审核失败!");
continue label;
}
}
} }
} }
//调用强制完成接口 //调用强制完成接口
if("completed".equals(status)){ if("completed".equals(status)){
//强制完成时状态必须为已审批approval //强制完成时状态必须为已审批approval
if(!"approval".equals(purOr.getHeaderStatus())){ if(!"approval".equals(purOrderHeader.getHeaderStatus())){
errorIds.add(purOr.getOrderNumber()); errorList.add("采购订单号为:"+purOrderHeader.getOrderNumber()+"的状态不为已审批,强制完成失败!");
continue label;
} }
} RcvReceiptHeader rcvReceiptHeader = rcvReceiptHeaderService.findBySourceHeaderId(purOrderHeader.getId());
} if(rcvReceiptHeader != null){
//有状态不匹配则返回出错信息 if(!"ACCEPTED".equals(rcvReceiptHeader.getHeaderStatus())){
if(errorIds.size() != 0){ errorList.add("接收单号为:"+rcvReceiptHeader.getReceiptNumber()+"强制完成失败!采购订单未完成接收入库,请处理后重试!");
throw ErrorEnum.NotAllowStatusERROR.createException(errorIds); continue label;
}else{
//全部状态正确则继续
//强制完成判断
if("completed".equals(status)){
//查找出与采购订单关联的接收单
for(PurOrderHeaderPage purOrderHeaderPage:purOrderHeaderPageList){
RcvReceiptHeader rcvReceiptHeader = rcvReceiptHeaderService.findBySourceHeaderId(purOrderHeaderPage.getId());
if(rcvReceiptHeader != null){
if(!"ACCEPTED".equals(rcvReceiptHeader.getHeaderStatus())){
return new Result(false,20001,("接收单号为:"+rcvReceiptHeader.getReceiptNumber()+"强制完成失败!采购订单未完成接收入库,请处理后重试!"));
}
} }
} }
} }
//检查accesstoken的有效性 //获取当前时间
SysAccessToken sysAccessToken = userServer.checkAccessToken(accessToken); LocalDateTime updateTime = LocalDateTime.now();
//查询用户 //修改附表的订单状态,审核人,修改人,修改时间
SysUser sysUser = userServer.getSysUserById(sysAccessToken.getUserId()); this.purOrderLineService.updateStatus(status,updateBy,updateTime,purOrderHeader.getId());
if(sysUser == null){ //修改主表的订单状态、修改人、修改时间
return new Result(false,20001,ErrorEnum.UserNotExist.getErrorMsg()); this.purOrderHeaderService.updateHeaderStatus(status,updateBy,updateTime,purOrderHeader.getId());
} }
String updateBy = sysUser.getRealname(); if(errorList.size() == 0) {
//修改对应信息
for(PurOrderHeaderPage purOrderHeaderPage:purOrderHeaderPageList){
//获取当前时间
LocalDateTime updateTime = LocalDateTime.now();
//修改附表的订单状态,审核人,修改人,修改时间
this.purOrderLineService.updateStatus(status,updateBy,updateTime,purOrderHeaderPage.getId());
//修改主表的订单状态、修改人、修改时间
this.purOrderHeaderService.updateHeaderStatus(status,updateBy,updateTime,purOrderHeaderPage.getId());
}
//修改成功返回成功信息 //修改成功返回成功信息
return new Result(true,20000,ErrorEnum.SUCCESS.getErrorMsg()); return new Result(true, StatusCode.OK, "操作成功!");
}else{
return new Result(false, StatusCode.ERROR, "操作失败!",errorList);
} }
} }
...@@ -419,4 +436,5 @@ public class PurOrderHeaderController { ...@@ -419,4 +436,5 @@ public class PurOrderHeaderController {
map.put("label",label); map.put("label",label);
return map; return map;
} }
} }
...@@ -107,4 +107,15 @@ public interface InvTransactionMapper{ ...@@ -107,4 +107,15 @@ public interface InvTransactionMapper{
@ResultMap("invtransaction") @ResultMap("invtransaction")
List<InvTransaction> findInInvTran(@Param("headerId")String headerId,@Param("lineId")String lineId); List<InvTransaction> findInInvTran(@Param("headerId")String headerId,@Param("lineId")String lineId);
//查询该组织下的商品库存现有量
@Select("SELECT ifnull(sum(i.tx_quantity),0) FROM inv_transaction i ," +
"(SELECT inv_id,default_shipping_subinv_id,default_shipping_locator_id " +
"FROM wsh_parameter " +
"WHERE org_id = (" +
"SELECT org_code FROM hr_organization " +
"WHERE id = #{orgId} )) w " +
"WHERE " +
"i.inv_id = w.inv_id AND i.subinv_id = w.default_shipping_subinv_id AND i.locator_id = w.default_shipping_locator_id " +
"and item_id = #{itemId}")
Integer selectByOrgIdAndItemId(@Param("orgId")String orgId,@Param("itemId")String itemId);
} }
\ No newline at end of file
...@@ -147,4 +147,7 @@ public interface PurOrderLineMapper{ ...@@ -147,4 +147,7 @@ public interface PurOrderLineMapper{
@Select("select * from pur_order_line where order_id = #{OrderId}") @Select("select * from pur_order_line where order_id = #{OrderId}")
@ResultMap("purorderline") @ResultMap("purorderline")
List<PurOrderLine> selectOrderLineByOrderId(@Param("OrderId")String OrderId); List<PurOrderLine> selectOrderLineByOrderId(@Param("OrderId")String OrderId);
@Update("update pur_order_line set attribute1 = #{attribute1} where id = #{id}")
Integer updateOrderLineSumQuantity(@Param("attribute1")String attribute1,@Param("id")String id);
} }
\ No newline at end of file
...@@ -29,4 +29,13 @@ public class PurOrderLineService { ...@@ -29,4 +29,13 @@ public class PurOrderLineService {
return purOrderLineMapper.selectOrderLineById(id); return purOrderLineMapper.selectOrderLineById(id);
} }
//根据主表id查询附表
public List<PurOrderLine> findOrderLineByHeaderId(String headerId){
return purOrderLineMapper.selectOrderLineByOrderId(headerId);
}
//更新采购订单行的库存现有量
public Integer updateOrderLineSumQuantity(String attribute,String id){
return purOrderLineMapper.updateOrderLineSumQuantity(attribute, id);
}
} }
...@@ -320,4 +320,7 @@ public class TransactionServer { ...@@ -320,4 +320,7 @@ public class TransactionServer {
return invTransactionMapper.selectQuantity(source_header_id, source_line_id); return invTransactionMapper.selectQuantity(source_header_id, source_line_id);
} }
public Integer findByOrgIdAndItemId(String orgId,String itemId){
return invTransactionMapper.selectByOrgIdAndItemId(orgId, itemId);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment