You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
525 lines
28 KiB
Java
525 lines
28 KiB
Java
package com.glxp.api.controller.purchase;
|
|
//领用单
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.glxp.api.annotation.AuthRuleAnnotation;
|
|
import com.glxp.api.common.enums.ResultEnum;
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
import com.glxp.api.constant.Constant;
|
|
import com.glxp.api.constant.ConstantStatus;
|
|
import com.glxp.api.constant.ConstantType;
|
|
import com.glxp.api.controller.BaseController;
|
|
import com.glxp.api.entity.auth.AuthAdmin;
|
|
import com.glxp.api.entity.auth.InvWarehouseEntity;
|
|
import com.glxp.api.entity.basic.BasicBusTypeChangeEntity;
|
|
import com.glxp.api.entity.basic.BasicProductsEntity;
|
|
import com.glxp.api.entity.basic.UdiProductEntity;
|
|
import com.glxp.api.entity.inout.IoOrderDetailBizEntity;
|
|
import com.glxp.api.entity.inout.IoOrderEntity;
|
|
import com.glxp.api.entity.inout.PurReceiveDetailEntity;
|
|
import com.glxp.api.entity.inout.PurReceiveEntity;
|
|
import com.glxp.api.entity.purchase.*;
|
|
import com.glxp.api.req.inout.AddReceiveDetailRequest;
|
|
import com.glxp.api.req.inout.FilterReceiveDetailRequest;
|
|
import com.glxp.api.req.inout.FilterReceiveRequest;
|
|
import com.glxp.api.req.inout.UpdateReceiveDetailRequest;
|
|
import com.glxp.api.req.purchase.*;
|
|
import com.glxp.api.res.PageSimpleResponse;
|
|
import com.glxp.api.res.inout.ReceiveDetailResponse;
|
|
import com.glxp.api.res.inout.ReceiveResponse;
|
|
import com.glxp.api.service.auth.CustomerService;
|
|
import com.glxp.api.service.auth.InvWarehouseService;
|
|
import com.glxp.api.service.basic.IBasicBusTypeChangeService;
|
|
import com.glxp.api.service.basic.UdiProductService;
|
|
import com.glxp.api.service.inout.IoOrderDetailBizService;
|
|
import com.glxp.api.service.inout.IoOrderService;
|
|
import com.glxp.api.service.inout.ReceiveService;
|
|
import com.glxp.api.service.inout.ReceivedetailService;
|
|
import com.glxp.api.service.purchase.*;
|
|
import com.glxp.api.util.CustomUtil;
|
|
import com.glxp.api.util.GennerOrderUtils;
|
|
import com.glxp.api.util.OrderNoTypeBean;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
@RestController
|
|
public class PurOrderReceiveController extends BaseController {
|
|
|
|
|
|
@Resource
|
|
ReceiveService receiveService;
|
|
@Resource
|
|
ReceivedetailService receivedetailService;
|
|
@Resource
|
|
CustomerService customerService;
|
|
@Resource
|
|
GennerOrderUtils gennerOrderUtils;
|
|
@Resource
|
|
PurApplyDetailService purApplyDetailService;
|
|
@Resource
|
|
UdiProductService udiProductService;
|
|
@Resource
|
|
IBasicBusTypeChangeService basicBusTypeChangeService;
|
|
@Resource
|
|
PurApplyService purApplyService;
|
|
@Resource
|
|
PurPlanService purPlanService;
|
|
@Resource
|
|
PurPlanDetailService purPlanDetailService;
|
|
@Resource
|
|
PurOrderService purOrderService;
|
|
@Resource
|
|
PurOrderDetailService purOrderDetailService;
|
|
@Resource
|
|
IoOrderService ioOrderService;
|
|
@Resource
|
|
IoOrderDetailBizService ioOrderDetailBizService;
|
|
@Resource
|
|
IoPurChangeService purChangeService;
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/udiwms/thrsys/order/insertWeb")
|
|
public BaseResponse addReceive(@RequestBody PurReceiveEntity purReceiveEntity, BindingResult bindingResult) {
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
Long userId = customerService.getUserId();
|
|
InvWarehouseEntity curWarehouseEntity = invWarehouseService.findByInvSubByCode(purReceiveEntity.getInvCode());
|
|
InvWarehouseEntity targetWarehouseEntity = invWarehouseService.findByInvSubByCode(purReceiveEntity.getTargetInvCode());
|
|
purReceiveEntity.setCreateUser(userId + "");
|
|
purReceiveEntity.setCreateTime(new Date());
|
|
purReceiveEntity.setUpdateTime(new Date());
|
|
String orderNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.LIN_YONG, "yyyyMMdd"));
|
|
purReceiveEntity.setBillNo(orderNo);
|
|
purReceiveEntity.setDeptCode(curWarehouseEntity.getParentId());
|
|
purReceiveEntity.setTargetDeptCode(targetWarehouseEntity.getParentId());
|
|
receiveService.insertOrder(purReceiveEntity);
|
|
return ResultVOUtils.success("成功");
|
|
}
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/udiwms/receive/order/update")
|
|
public BaseResponse updateReceive(@RequestBody PurReceiveEntity purReceiveEntity, BindingResult bindingResult) {
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
|
|
Long userId = customerService.getUserId();
|
|
purReceiveEntity.setStatus(purReceiveEntity.getStatus());
|
|
purReceiveEntity.setUpdateUser(userId + "");
|
|
purReceiveEntity.setUpdateTime(new Date());
|
|
receiveService.updateOrder(purReceiveEntity);
|
|
return ResultVOUtils.success("成功");
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@GetMapping("/udiwms/receive/order/filter")
|
|
public BaseResponse filterReceive(FilterReceiveRequest filterReceiveRequest) {
|
|
List<ReceiveResponse> data = receiveService.filterList(filterReceiveRequest);
|
|
PageInfo<ReceiveResponse> pageInfo;
|
|
pageInfo = new PageInfo<>(data);
|
|
PageSimpleResponse<ReceiveResponse> pageSimpleResponse = new PageSimpleResponse<>();
|
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
|
pageSimpleResponse.setList(data);
|
|
return ResultVOUtils.success(pageSimpleResponse);
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@GetMapping("/udiwms/receive/order/detail")
|
|
public BaseResponse filterReceiveDetail(FilterReceiveDetailRequest filterReceiveDetailRequest) {
|
|
List<ReceiveDetailResponse> data = receivedetailService.filterList(filterReceiveDetailRequest);
|
|
PageInfo<ReceiveDetailResponse> pageInfo;
|
|
pageInfo = new PageInfo<>(data);
|
|
PageSimpleResponse<ReceiveDetailResponse> pageSimpleResponse = new PageSimpleResponse<>();
|
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
|
pageSimpleResponse.setList(data);
|
|
return ResultVOUtils.success(pageSimpleResponse);
|
|
}
|
|
|
|
@Resource
|
|
InvWarehouseService invWarehouseService;
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/udiwms/receive/detail/add")
|
|
public BaseResponse updateReceive(@RequestBody AddReceiveDetailRequest addReceiveDetailRequest, BindingResult bindingResult) {
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
AuthAdmin authAdmin = getUser();
|
|
String orderNo = addReceiveDetailRequest.getPurReceiveEntity().getBillNo();
|
|
if (addReceiveDetailRequest.getPurReceiveEntity() == null)
|
|
return ResultVOUtils.error(500, "未指定订单");
|
|
|
|
if (CollUtil.isEmpty(addReceiveDetailRequest.getDatas())) {
|
|
return ResultVOUtils.error(500, "未选择产品信息");
|
|
}
|
|
PurReceiveEntity purReceiveEntity = addReceiveDetailRequest.getPurReceiveEntity();
|
|
if (StrUtil.isEmpty(purReceiveEntity.getBillNo())) {
|
|
InvWarehouseEntity curWarehouseEntity = invWarehouseService.findByInvSubByCode(purReceiveEntity.getInvCode());
|
|
InvWarehouseEntity targetWarehouseEntity = invWarehouseService.findByInvSubByCode(purReceiveEntity.getTargetInvCode());
|
|
orderNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.LIN_YONG, "yyyyMMdd"));
|
|
purReceiveEntity.setBillNo(orderNo);
|
|
purReceiveEntity.setCreateUser(authAdmin.getId() + "");
|
|
purReceiveEntity.setCreateTime(new Date());
|
|
purReceiveEntity.setStatus(1);
|
|
purReceiveEntity.setDeptCode(curWarehouseEntity.getParentId());
|
|
purReceiveEntity.setTargetDeptCode(targetWarehouseEntity.getParentId());
|
|
receiveService.insertOrder(purReceiveEntity);
|
|
}
|
|
for (AddReceiveDetailRequest.DetaiData detaiData : addReceiveDetailRequest.getDatas()) {
|
|
|
|
PurReceiveDetailEntity purReceiveDetailEntity = new PurReceiveDetailEntity();
|
|
purReceiveDetailEntity.setOrderIdFk(purReceiveEntity.getBillNo());
|
|
purReceiveDetailEntity.setNameCode(detaiData.getNameCode());
|
|
purReceiveDetailEntity.setExpireDate(detaiData.getExpireDate());
|
|
purReceiveDetailEntity.setProductDate(detaiData.getProductDate());
|
|
purReceiveDetailEntity.setRelIdFk(detaiData.getRelId());
|
|
purReceiveDetailEntity.setBatchNo(detaiData.getBatchNo());
|
|
purReceiveDetailEntity.setSupId(detaiData.getSupId());
|
|
receivedetailService.insert(purReceiveDetailEntity);
|
|
}
|
|
purReceiveEntity.setUpdateTime(new Date());
|
|
receiveService.updateOrder(purReceiveEntity);
|
|
return ResultVOUtils.success(orderNo);
|
|
}
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/udiwms/receive/detail/Update")
|
|
public BaseResponse updateReceiveDetail(@RequestBody UpdateReceiveDetailRequest updateReceiveDetailRequest, BindingResult bindingResult) {
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
boolean falg = receivedetailService.updateReceiveDetail(updateReceiveDetailRequest);
|
|
if (falg) {
|
|
return ResultVOUtils.success();
|
|
} else {
|
|
return ResultVOUtils.error(555, "更新失败!");
|
|
}
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@GetMapping("/udiwms/receive/order/del")
|
|
public BaseResponse del(String orderIdFk) {
|
|
boolean falg = receiveService.delReceive(orderIdFk);
|
|
if (falg) {
|
|
return ResultVOUtils.success();
|
|
} else {
|
|
return ResultVOUtils.error(555, "删除失败!");
|
|
}
|
|
}
|
|
|
|
@AuthRuleAnnotation("")
|
|
@GetMapping("/udiwms/receive/detail/delReceiveDetail")
|
|
public BaseResponse delReceiveDetail(Integer id) {
|
|
|
|
boolean falg = receivedetailService.delDetail(id + "");
|
|
if (falg) {
|
|
return ResultVOUtils.success();
|
|
} else {
|
|
return ResultVOUtils.error(555, "删除失败!");
|
|
}
|
|
}
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/udiwms/receive/order/audit")
|
|
public BaseResponse audit(@RequestBody PurReceiveEntity purReceiveEntity, BindingResult bindingResult) {
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
|
|
Long userId = customerService.getUserId();
|
|
purReceiveEntity.setStatus(purReceiveEntity.getStatus());
|
|
purReceiveEntity.setUpdateUser(userId + "");
|
|
purReceiveEntity.setAuditRemark(purReceiveEntity.getAuditRemark());
|
|
purReceiveEntity.setAuditTime(new Date());
|
|
purReceiveEntity.setAuditUser(userId + "");
|
|
purReceiveEntity.setUpdateTime(new Date());
|
|
receiveService.updateOrder(purReceiveEntity);
|
|
|
|
if (purReceiveEntity.getStatus() == 3) {
|
|
//进行单据流转
|
|
purChangeService.purReceiveChange(purReceiveEntity);
|
|
// generateDocument(purReceiveEntity);
|
|
}
|
|
return ResultVOUtils.success("成功");
|
|
}
|
|
|
|
//根据单据生成新单据
|
|
public Boolean generateDocument(PurReceiveEntity purReceiveEntity) {
|
|
//查询耗材表
|
|
purReceiveEntity = receiveService.selectById(purReceiveEntity.getId());
|
|
//查询耗材详情
|
|
List<PurReceiveDetailEntity> purReceiveDetailEntityList = receivedetailService.selectByOrderId(purReceiveEntity.getBillNo());
|
|
PurApplyEntity purApplyEntity = new PurApplyEntity();
|
|
//查询耗材要生成的业务单
|
|
BasicBusTypeChangeEntity basicBusTypeChangeEntity = new BasicBusTypeChangeEntity();
|
|
basicBusTypeChangeEntity = basicBusTypeChangeService.selectByOriginAction("HCLY");
|
|
if (basicBusTypeChangeEntity != null && StrUtil.isNotEmpty(basicBusTypeChangeEntity.getTargetBusAction()) && basicBusTypeChangeEntity.isEnable() == true) {
|
|
purApplyEntity.setBillNo(gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.SG_ORDER, "yyyyMMdd")));
|
|
purApplyEntity.setBillDate(purReceiveEntity.getBillDate());
|
|
purApplyEntity.setStatus(basicBusTypeChangeEntity.getBusAuditStatus());
|
|
purApplyEntity.setRemark(purReceiveEntity.getRemark());
|
|
purApplyEntity.setInvCode(purReceiveEntity.getTargetInvCode());
|
|
purApplyEntity.setDeptCode(purReceiveEntity.getTargetDeptCode());
|
|
purApplyEntity.setTargetInvCode(purReceiveEntity.getInvCode());
|
|
purApplyEntity.setTargetDeptCode(purReceiveEntity.getDeptCode());
|
|
purApplyEntity.setCreateUser(purReceiveEntity.getAuditUser());
|
|
purApplyEntity.setCreateTime(timeProcess(purReceiveEntity.getCreateTime(), basicBusTypeChangeEntity.getBusBeforeTime()));
|
|
purApplyEntity.setUpdateUser(purReceiveEntity.getAuditUser());
|
|
purApplyEntity.setUpdateTime(timeProcess(purReceiveEntity.getCreateTime(), basicBusTypeChangeEntity.getBusBeforeTime()));
|
|
if (purApplyEntity.getStatus() == 3) {
|
|
purApplyEntity.setAuditUser("");
|
|
purApplyEntity.setAuditTime(new Date());
|
|
}
|
|
//插入申购主表
|
|
purApplyService.insert(purApplyEntity);
|
|
//用stream流复制list
|
|
List<PurApplyDetailEntity> purApplyDetailEntityList = purReceiveDetailEntityList.stream().map(e -> {
|
|
PurApplyDetailEntity d = new PurApplyDetailEntity();
|
|
d.setOrderIdFk(purApplyEntity.getId() + "");
|
|
d.setProductId(e.getRelIdFk().intValue());
|
|
UdiProductEntity udiProductEntity = udiProductService.findByNameCode(e.getNameCode());
|
|
d.setProductName(udiProductEntity.getCpmctymc());
|
|
d.setCount(e.getCount());
|
|
d.setSupId(e.getSupId());
|
|
d.setZczbhhzbapzbh(udiProductEntity.getZczbhhzbapzbh());
|
|
return d;
|
|
})
|
|
.collect(Collectors.toList());
|
|
purApplyDetailService.insertPurApplyDetailEntity(purApplyDetailEntityList);
|
|
|
|
//---------------------------------判断申购为已审核就生成计划单-------------------------------------------//
|
|
PurPlanEntity purPlanEntity = new PurPlanEntity();
|
|
List<PurPlanDetailEntity> purPlanDetailEntityList = new ArrayList<>();
|
|
if (purApplyEntity.getStatus() == 3) {
|
|
basicBusTypeChangeEntity = basicBusTypeChangeService.selectByOriginAction("CPSG");
|
|
if (basicBusTypeChangeEntity != null && StrUtil.isNotEmpty(basicBusTypeChangeEntity.getTargetBusAction()) && basicBusTypeChangeEntity.isEnable() == true) {
|
|
purPlanEntity.setBillNo(gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.JH_ORDER, "yyyyMMdd")));
|
|
purPlanEntity.setBillDate(purReceiveEntity.getBillDate());
|
|
purPlanEntity.setStatus(basicBusTypeChangeEntity.getBusAuditStatus());
|
|
purPlanEntity.setRemark(purReceiveEntity.getRemark());
|
|
purPlanEntity.setInvCode(purReceiveEntity.getInvCode());
|
|
purPlanEntity.setDeptCode(purReceiveEntity.getDeptCode());
|
|
purPlanEntity.setCreateUser(purReceiveEntity.getAuditUser());
|
|
purPlanEntity.setCreateTime(timeProcess(purReceiveEntity.getCreateTime(), basicBusTypeChangeEntity.getBusBeforeTime()));
|
|
purPlanEntity.setUpdateUser(purReceiveEntity.getAuditUser());
|
|
purPlanEntity.setUpdateTime(timeProcess(purReceiveEntity.getCreateTime(), basicBusTypeChangeEntity.getBusBeforeTime()));
|
|
if (purPlanEntity.getStatus() == 3) {
|
|
purPlanEntity.setAuditUser("");
|
|
purPlanEntity.setAuditTime(new Date());
|
|
}
|
|
//插入计划主表
|
|
purPlanService.insert(purPlanEntity);
|
|
//用stream流复制list
|
|
purPlanDetailEntityList = purReceiveDetailEntityList.stream().map(e -> {
|
|
PurPlanDetailEntity d = new PurPlanDetailEntity();
|
|
d.setOrderIdFk(purPlanEntity.getId() + "");
|
|
d.setProductId(e.getRelIdFk().intValue());
|
|
UdiProductEntity udiProductEntity = udiProductService.findByNameCode(e.getNameCode());
|
|
d.setProductName(udiProductEntity.getCpmctymc());
|
|
d.setCount(e.getCount());
|
|
d.setSupId(e.getSupId());
|
|
d.setZczbhhzbapzbh(udiProductEntity.getZczbhhzbapzbh());
|
|
return d;
|
|
}).collect(Collectors.toList());
|
|
purPlanDetailService.insertPurPlanDetailEntity(purPlanDetailEntityList);
|
|
//更新申购表信息插入计划单号
|
|
PurApplyEntity purApplyEntity1 = new PurApplyEntity();
|
|
purApplyEntity1.setId(purApplyEntity.getId());
|
|
purApplyEntity1.setPlanBillNo(purPlanEntity.getBillNo());
|
|
purApplyEntity1.setGeneratePlan(true);
|
|
purApplyService.update(purApplyEntity1);
|
|
//---------------------------------判断计划为已审核就生成计划单-------------------------------------------//\
|
|
PurOrderEntity purOrderEntity = new PurOrderEntity();
|
|
if (purPlanEntity.getStatus() == 3) {
|
|
basicBusTypeChangeEntity = basicBusTypeChangeService.selectByOriginAction("CGJH");
|
|
if (basicBusTypeChangeEntity != null && StrUtil.isNotEmpty(basicBusTypeChangeEntity.getTargetBusAction()) && basicBusTypeChangeEntity.isEnable() == true) {
|
|
purOrderEntity.setBillNo(gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.CG_ORDER, "yyyyMMdd")));
|
|
purOrderEntity.setBillDate(purReceiveEntity.getBillDate());
|
|
purOrderEntity.setStatus(basicBusTypeChangeEntity.getBusAuditStatus());
|
|
purOrderEntity.setRemark(purReceiveEntity.getRemark());
|
|
purOrderEntity.setInvCode(purReceiveEntity.getInvCode());
|
|
purOrderEntity.setDeptCode(purReceiveEntity.getDeptCode());
|
|
purOrderEntity.setCreateUser(purReceiveEntity.getAuditUser());
|
|
purOrderEntity.setCreateTime(timeProcess(purReceiveEntity.getCreateTime(), basicBusTypeChangeEntity.getBusBeforeTime()));
|
|
purOrderEntity.setUpdateUser(purReceiveEntity.getAuditUser());
|
|
purOrderEntity.setUpdateTime(timeProcess(purReceiveEntity.getCreateTime(), basicBusTypeChangeEntity.getBusBeforeTime()));
|
|
if (purOrderEntity.getStatus() == 3) {
|
|
purOrderEntity.setAuditUser("");
|
|
purOrderEntity.setAuditTime(new Date());
|
|
}
|
|
//插入订单主表
|
|
purOrderService.insert(purOrderEntity);
|
|
//用stream流复制list
|
|
List<PurOrderDetailEntity> purOrderDetailEntityList = purReceiveDetailEntityList.stream().map(e -> {
|
|
PurOrderDetailEntity d = new PurOrderDetailEntity();
|
|
d.setOrderIdFk(purOrderEntity.getId() + "");
|
|
d.setProductId(e.getRelIdFk().intValue());
|
|
UdiProductEntity udiProductEntity = udiProductService.findByNameCode(e.getNameCode());
|
|
d.setProductName(udiProductEntity.getCpmctymc());
|
|
d.setCount(e.getCount());
|
|
d.setSupId(e.getSupId());
|
|
d.setZczbhhzbapzbh(udiProductEntity.getZczbhhzbapzbh());
|
|
return d;
|
|
}).collect(Collectors.toList());
|
|
purOrderDetailService.insertPurOrderDetailEntity(purOrderDetailEntityList);
|
|
// 更新计划表信息插入订单单号
|
|
PurPlanEntity purPlanEntity1 = new PurPlanEntity();
|
|
purPlanEntity1.setId(purPlanEntity.getId());
|
|
purPlanEntity1.setStockOrderNo(purOrderEntity.getBillNo());
|
|
// purPlanEntity.sets(true);
|
|
purPlanService.update(purPlanEntity1);
|
|
}
|
|
//---------------------------------判断计划为已审核就生成采购入库单-------------------------------------------//\
|
|
//查询申购单详情
|
|
List<PurPlanDetailEntity> purPlanDetailEntities = purPlanDetailService.findByOrderId(purPlanEntity.getId() + "");
|
|
//对计划单里面的供应商进行分组
|
|
Map<String, List<PurPlanDetailEntity>> map = purPlanDetailEntities.stream().collect(Collectors.groupingBy(PurPlanDetailEntity::getSupId));
|
|
String billNo = "";
|
|
if (basicBusTypeChangeEntity != null && StrUtil.isNotEmpty(basicBusTypeChangeEntity.getTargetAction()) && basicBusTypeChangeEntity.isEnable() == true) {
|
|
for (Map.Entry<String, List<PurPlanDetailEntity>> m : map.entrySet()) {
|
|
//生产单据表信息
|
|
IoOrderEntity ioOrderEntity = new IoOrderEntity();
|
|
ioOrderEntity.setBillNo(gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER, "yyyyMMdd")));
|
|
ioOrderEntity.setCorpOrderId(CustomUtil.getDate());
|
|
ioOrderEntity.setMainAction(ConstantType.TYPE_PUT);
|
|
ioOrderEntity.setAction(basicBusTypeChangeEntity.getTargetAction());
|
|
ioOrderEntity.setFromCorp(m.getKey());
|
|
ioOrderEntity.setFromType(ConstantStatus.FROM_PLAN);
|
|
ioOrderEntity.setStatus(1);
|
|
ioOrderEntity.setDealStatus(1);
|
|
ioOrderEntity.setOrderType(1);
|
|
ioOrderEntity.setCreateTime(new Date());
|
|
ioOrderEntity.setCreateUser(purReceiveEntity.getCreateUser());
|
|
ioOrderEntity.setUpdateTime(new Date());
|
|
ioOrderEntity.setUpdateUser(purReceiveEntity.getCreateUser());
|
|
ioOrderEntity.setCustomerId("110");
|
|
ioOrderEntity.setDeptCode(purReceiveEntity.getInvCode());
|
|
ioOrderEntity.setInvCode(purReceiveEntity.getDeptCode());
|
|
ioOrderService.insertOrder(ioOrderEntity);
|
|
billNo += ioOrderEntity.getBillNo() + ",";
|
|
//插入业务单表
|
|
for (PurPlanDetailEntity obj : m.getValue()) {
|
|
BasicProductsEntity basicProductsEntity = purPlanDetailService.selectIoOrderDetailBiz(obj.getId());
|
|
IoOrderDetailBizEntity ioOrderDetailBizEntity = new IoOrderDetailBizEntity();
|
|
ioOrderDetailBizEntity.setOrderIdFk(ioOrderEntity.getBillNo());
|
|
ioOrderDetailBizEntity.setBindRlFk(Long.valueOf(obj.getProductId()));
|
|
ioOrderDetailBizEntity.setCount(obj.getCount());
|
|
ioOrderDetailBizEntity.setUuidFk(basicProductsEntity.getUuid());
|
|
ioOrderDetailBizEntity.setNameCode(basicProductsEntity.getNameCode());
|
|
ioOrderDetailBizEntity.setCoName(basicProductsEntity.getCpmctymc());
|
|
ioOrderDetailBizEntity.setCertCode(basicProductsEntity.getZczbhhzbapzbh());
|
|
ioOrderDetailBizEntity.setYlqxzcrbarmc(basicProductsEntity.getYlqxzcrbarmc());
|
|
ioOrderDetailBizEntity.setManufacturer(basicProductsEntity.getManufactory());
|
|
ioOrderDetailBizEntity.setMeasname(basicProductsEntity.getMeasname());
|
|
ioOrderDetailBizEntity.setSpec(basicProductsEntity.getGgxh());
|
|
if (basicProductsEntity.getPrice() != null) {
|
|
ioOrderDetailBizEntity.setPrice(BigDecimal.valueOf(basicProductsEntity.getPrice()));
|
|
}
|
|
ioOrderDetailBizEntity.setSupId(obj.getSupId());
|
|
ioOrderDetailBizService.insert(ioOrderDetailBizEntity);
|
|
}
|
|
}
|
|
PurPlanEntity purPlanEntity1 = new PurPlanEntity();
|
|
purPlanEntity1.setId(purPlanEntity.getId());
|
|
purPlanEntity1.setStockOrderNo(billNo.substring(0, billNo.length() - 1));
|
|
purPlanService.update(purPlanEntity1);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* 添加申购单到采购单里面
|
|
*/
|
|
@PostMapping("/receive/order/addOrderDetailAndApply")
|
|
public BaseResponse addOrderDetailAndApply(@RequestBody purReceiveRequest purReceiveRequest) {
|
|
|
|
if (purReceiveRequest.getOrderId() == null || purReceiveRequest.getId() == null) {
|
|
return ResultVOUtils.error(999, "参数错误!");
|
|
}
|
|
|
|
//查询领用单详情
|
|
List<PurReceiveDetailEntity> purPlanDetailEntityList = receivedetailService.selectByOrderId(purReceiveRequest.getOrderId());
|
|
//使用stream拷贝list
|
|
List<PurApplyDetailEntity> purOrderDetailEntityList = purPlanDetailEntityList.stream()
|
|
.map(e -> {
|
|
PurApplyDetailEntity d = new PurApplyDetailEntity();
|
|
d.setProductId(e.getRelIdFk().intValue());
|
|
UdiProductEntity udiProductEntity = udiProductService.findByNameCode(e.getNameCode());
|
|
d.setProductName(udiProductEntity.getCpmctymc());
|
|
d.setCount(e.getCount());
|
|
d.setSupId(e.getSupId());
|
|
d.setZczbhhzbapzbh(udiProductEntity.getZczbhhzbapzbh());
|
|
return d;
|
|
})
|
|
.collect(Collectors.toList());
|
|
|
|
for (PurApplyDetailEntity obj : purOrderDetailEntityList) {
|
|
obj.setOrderIdFk(purReceiveRequest.getId() + "");
|
|
}
|
|
//获取详情表信息
|
|
List<PurApplyDetailEntity> purOrderDetailEntities = purApplyDetailService.findByOrderId(purReceiveRequest.getId());
|
|
|
|
|
|
List<Long> ids = new ArrayList<>();
|
|
for (PurApplyDetailEntity obj : purOrderDetailEntities) {
|
|
for (PurApplyDetailEntity obj1 : purOrderDetailEntityList) {
|
|
if (obj.getProductId().equals(obj1.getProductId())) {
|
|
//获取存在在详情表和申购单里面一样的产品
|
|
ids.add(obj.getId().longValue());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
//删除存在的产品
|
|
if (ids.size() > 0) {
|
|
purApplyDetailService.deleteByIds(ids);
|
|
}
|
|
|
|
boolean falg = purApplyDetailService.insertPurApplyDetailEntity(purOrderDetailEntityList);
|
|
if (falg) {
|
|
//查询申购单
|
|
return ResultVOUtils.success(purReceiveRequest.getId());
|
|
|
|
} else {
|
|
return ResultVOUtils.success("添加失败");
|
|
}
|
|
}
|
|
|
|
|
|
public Date timeProcess(Date date, Integer timeCount) {
|
|
Calendar rightNow = Calendar.getInstance();
|
|
rightNow.setTime(date);
|
|
rightNow.add(Calendar.HOUR, timeCount);
|
|
Date dt1 = rightNow.getTime();
|
|
return dt1;
|
|
}
|
|
|
|
|
|
}
|