申购单据根据单据生成功能代码提交

master
郑明梁 2 years ago
parent 8907c32a99
commit 4bed6fcddc

@ -9,10 +9,15 @@ 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.entity.purchase.PurApplyDetailEntity;
import com.glxp.api.entity.purchase.PurApplyEntity;
import com.glxp.api.entity.purchase.PurPlanDetailEntity;
import com.glxp.api.entity.purchase.PurPlanEntity;
import com.glxp.api.constant.ConstantType;
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.purchase.PostPurApplyRequest;
import com.glxp.api.req.purchase.PurApplyDetailRequest;
import com.glxp.api.req.purchase.PurApplyRequest;
@ -20,13 +25,11 @@ import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.purchase.PurApplyResponse;
import com.glxp.api.res.purchase.PurOrderDetailResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.basic.IBasicBussinessTypeService;
import com.glxp.api.service.basic.UdiRelevanceService;
import com.glxp.api.service.basic.UdiRlSupService;
import com.glxp.api.service.purchase.PurApplyDetailService;
import com.glxp.api.service.purchase.PurApplyService;
import com.glxp.api.service.purchase.PurPlanDetailService;
import com.glxp.api.service.purchase.PurPlanService;
import com.glxp.api.service.basic.*;
import com.glxp.api.service.inout.IoOrderDetailBizService;
import com.glxp.api.service.inout.IoOrderService;
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 lombok.RequiredArgsConstructor;
@ -36,9 +39,9 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* pur
@ -60,18 +63,22 @@ public class PurApplyController {
@Resource
PurPlanDetailService purPlanDetailService;
@Resource
UdiProductService udiProductService;
@Resource
IBasicBusTypeChangeService basicBusTypeChangeService;
@Resource
CustomerService customerService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
UdiRelevanceService udiRelevanceService;
PurOrderService purOrderService;
@Resource
UdiRlSupService udiRlSupService;
PurOrderDetailService purOrderDetailService;
@Resource
IBasicBussinessTypeService basicBussinessTypeService;
IoOrderService ioOrderService;
@Resource
IoOrderDetailBizService ioOrderDetailBizService;
/**
*
*/
@ -158,43 +165,210 @@ public class PurApplyController {
purApplyEntity.setAuditUser(userId + "");
purApplyService.update(purApplyEntity);
//审核通过后转换成采购计划单
if (purApplyEntity.getStatus() == ConstantStatus.APPLY_AUDIT_ED && purApplyRequest.isAudtoPlan()) {
PurPlanEntity purPlanEntity = new PurPlanEntity();
String billNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.JH_ORDER, "yyyyMMdd"));
purPlanEntity.setBillNo(billNo);
purPlanEntity.setBillDate(new Date());
if(purApplyRequest.getStatus()==3){
generateDocument(purApplyEntity);
}
// //审核通过后转换成采购计划单
// if (purApplyEntity.getStatus() == ConstantStatus.APPLY_AUDIT_ED && purApplyRequest.isAudtoPlan()) {
// PurPlanEntity purPlanEntity = new PurPlanEntity();
// String billNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.JH_ORDER, "yyyyMMdd"));
// purPlanEntity.setBillNo(billNo);
// purPlanEntity.setBillDate(new Date());
// purPlanEntity.setInvCode(purApplyEntity.getInvCode());
// purPlanEntity.setDeptCode(purApplyEntity.getDeptCode());
// purApplyEntity.setCreateUser(customerService.getUserId()+"");
// purPlanEntity.setUpdateUser(purApplyEntity.getUpdateUser());
// purPlanEntity.setStatus(ConstantStatus.APPLY_DRAFT);
// purPlanEntity.setBillType("purPlan");
// purPlanEntity.setCreateTime(new Date());
// purPlanEntity.setUpdateTime(new Date());
// purPlanEntity.setApplyBillNo(purApplyEntity.getBillNo());
// purPlanEntity.setApplyCreateUser(purApplyEntity.getCreateUser());
// purPlanEntity.setApplyRemark(purApplyEntity.getRemark());
// purPlanEntity.setApplyAuditUser(purApplyEntity.getAuditUser());
// purPlanEntity.setRemark("申购科室:" + purApplyRequest.getTargetInvCode() +
// ";申购人:" + purApplyRequest.getCreateByName() + ";申购原因:" + purApplyRequest.getRemark());
// purApplyEntity.setPlanBillNo(purPlanEntity.getBillNo());
// purApplyEntity.setGeneratePlan(true);
// purApplyService.update(purApplyEntity);
// purPlanService.insert(purPlanEntity);
// List<PurApplyDetailEntity> purApplyDetailEntities = purApplyDetailService.findByOrderId(purApplyEntity.getId() + "");
// if (CollUtil.isNotEmpty(purApplyDetailEntities)) {
// for (PurApplyDetailEntity purApplyDetailEntity : purApplyDetailEntities) {
// PurPlanDetailEntity purPlanDetailEntity = new PurPlanDetailEntity();
// BeanUtils.copyProperties(purApplyDetailEntity, purPlanDetailEntity);
// purPlanDetailEntity.setOrderIdFk(purPlanEntity.getId() + "");
// purPlanDetailService.insert(purPlanDetailEntity);
// }
// }
// }
return ResultVOUtils.success("更新成功!");
}
//根据单据生成新单据
public Boolean generateDocument(PurApplyEntity purApplyEntity){
BasicBusTypeChangeEntity basicBusTypeChangeEntity=new BasicBusTypeChangeEntity();
//查询申购详情
List<PurApplyDetailEntity> purApplyDetailEntityList=purApplyDetailService.findByOrderId(purApplyEntity.getId()+"");
//---------------------------------判断申购为已审核就生成计划单-------------------------------------------//
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(purApplyEntity.getBillDate());
purPlanEntity.setStatus(basicBusTypeChangeEntity.getBusAuditStatus());
purPlanEntity.setRemark(purApplyEntity.getRemark());
purPlanEntity.setEmergency(purApplyEntity.getEmergency());
purPlanEntity.setArrivalTime(purApplyEntity.getArrivalTime());
purPlanEntity.setInvCode(purApplyEntity.getInvCode());
purPlanEntity.setDeptCode(purApplyEntity.getDeptCode());
purApplyEntity.setCreateUser(customerService.getUserId()+"");
purPlanEntity.setUpdateUser(purApplyEntity.getUpdateUser());
purPlanEntity.setStatus(ConstantStatus.APPLY_DRAFT);
purPlanEntity.setBillType("purPlan");
purPlanEntity.setCreateTime(new Date());
purPlanEntity.setUpdateTime(new Date());
purPlanEntity.setApplyBillNo(purApplyEntity.getBillNo());
purPlanEntity.setApplyCreateUser(purApplyEntity.getCreateUser());
purPlanEntity.setApplyRemark(purApplyEntity.getRemark());
purPlanEntity.setApplyAuditUser(purApplyEntity.getAuditUser());
purPlanEntity.setRemark("申购科室:" + purApplyRequest.getTargetInvCode() +
";申购人:" + purApplyRequest.getCreateByName() + ";申购原因:" + purApplyRequest.getRemark());
purApplyEntity.setPlanBillNo(purPlanEntity.getBillNo());
purApplyEntity.setGeneratePlan(true);
purApplyService.update(purApplyEntity);
purPlanEntity.setCreateUser(purApplyEntity.getAuditUser());
purPlanEntity.setCreateTime(timeProcess(purApplyEntity.getCreateTime(),basicBusTypeChangeEntity.getBusBeforeTime()));
purPlanEntity.setUpdateUser(purApplyEntity.getAuditUser());
purPlanEntity.setUpdateTime(timeProcess(purApplyEntity.getCreateTime(),basicBusTypeChangeEntity.getBusBeforeTime()));
if(purPlanEntity.getStatus()==3){
purPlanEntity.setAuditUser("");
purPlanEntity.setAuditTime(new Date());
}
//插入计划主表
purPlanService.insert(purPlanEntity);
List<PurApplyDetailEntity> purApplyDetailEntities = purApplyDetailService.findByOrderId(purApplyEntity.getId() + "");
if (CollUtil.isNotEmpty(purApplyDetailEntities)) {
for (PurApplyDetailEntity purApplyDetailEntity : purApplyDetailEntities) {
PurPlanDetailEntity purPlanDetailEntity = new PurPlanDetailEntity();
BeanUtils.copyProperties(purApplyDetailEntity, purPlanDetailEntity);
purPlanDetailEntity.setOrderIdFk(purPlanEntity.getId() + "");
purPlanDetailService.insert(purPlanDetailEntity);
//用stream流复制list
purPlanDetailEntityList = purApplyDetailEntityList.stream().map(e -> {
PurPlanDetailEntity d = new PurPlanDetailEntity();
d.setOrderIdFk(purPlanEntity.getId()+"");
d.setProductId(e.getProductId());
d.setProductName(e.getProductName());
d.setCount(e.getCount());
d.setSupId(e.getSupId());
d.setZczbhhzbapzbh(e.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(purApplyEntity.getBillDate());
purOrderEntity.setStatus(basicBusTypeChangeEntity.getBusAuditStatus());
purOrderEntity.setRemark(purApplyEntity.getRemark());
purOrderEntity.setEmergency(purApplyEntity.getEmergency());
purOrderEntity.setArrivalTime(purApplyEntity.getArrivalTime());
purOrderEntity.setInvCode(purApplyEntity.getInvCode());
purOrderEntity.setDeptCode(purApplyEntity.getDeptCode());
purOrderEntity.setCreateUser(purApplyEntity.getAuditUser());
purOrderEntity.setCreateTime(timeProcess(purApplyEntity.getCreateTime(),basicBusTypeChangeEntity.getBusBeforeTime()));
purOrderEntity.setUpdateUser(purApplyEntity.getAuditUser());
purOrderEntity.setUpdateTime(timeProcess(purApplyEntity.getCreateTime(),basicBusTypeChangeEntity.getBusBeforeTime()));
if(purOrderEntity.getStatus()==3){
purOrderEntity.setAuditUser("");
purOrderEntity.setAuditTime(new Date());
}
//插入订单主表
purOrderService.insert(purOrderEntity);
//用stream流复制list
List<PurOrderDetailEntity> purOrderDetailEntityList = purApplyDetailEntityList.stream().map(e -> {
PurOrderDetailEntity d = new PurOrderDetailEntity();
d.setOrderIdFk(purOrderEntity.getId()+"");
d.setProductId(e.getProductId());
d.setProductName(e.getProductName());
d.setCount(e.getCount());
d.setSupId(e.getSupId());
d.setZczbhhzbapzbh(e.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(purApplyEntity.getCreateUser());
ioOrderEntity.setUpdateTime(new Date());
ioOrderEntity.setUpdateUser(purApplyEntity.getCreateUser());
ioOrderEntity.setCustomerId("110");
ioOrderEntity.setDeptCode(purApplyEntity.getInvCode());
ioOrderEntity.setInvCode(purApplyEntity.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);
}
return ResultVOUtils.success("更新成功!");
}
PurPlanEntity purPlanEntity1=new PurPlanEntity();
purPlanEntity1.setId(purPlanEntity.getId());
purPlanEntity1.setStockOrderNo(billNo.substring(0,billNo.length()-1));
purPlanService.update(purPlanEntity1);
}
}
}
}
return true;
}
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;
}
/**
*

@ -242,14 +242,14 @@ public class PurOrderReceiveController extends BaseController {
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);
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){
generateDocument(purReceiveEntity);

Loading…
Cancel
Save