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.
udi-wms-java/src/main/java/com/glxp/api/controller/purchase/PurPlanController.java

522 lines
24 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.annotation.RepeatSubmit;
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.entity.basic.BasicBusTypeChangeEntity;
import com.glxp.api.entity.basic.BasicCorpEntity;
import com.glxp.api.entity.basic.BasicProductsEntity;
import com.glxp.api.entity.inout.IoOrderDetailBizEntity;
import com.glxp.api.entity.inout.IoOrderEntity;
import com.glxp.api.entity.purchase.*;
import com.glxp.api.req.purchase.PostPurPlanRequest;
import com.glxp.api.req.purchase.PurApplyDetailRequest;
import com.glxp.api.req.purchase.PurPlanDetailRequest;
import com.glxp.api.req.purchase.PurPlanRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.basic.UdiRelevanceResponse;
import com.glxp.api.res.purchase.PurOrderDetailResponse;
import com.glxp.api.res.purchase.PurPlanResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.basic.BasicCorpService;
import com.glxp.api.service.basic.IBasicBusTypeChangeService;
import com.glxp.api.service.basic.UdiRelevanceService;
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;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* pur
*
* @author anthony.ywj
* @date 2022-10-12
*/
@Validated
@RequiredArgsConstructor
@RestController
public class PurPlanController {
@Resource
PurPlanService purPlanService;
@Resource
PurApplyService purApplyService;
@Resource
PurApplyDetailService purApplyDetailService;
@Resource
PurPlanDetailService purPlanDetailService;
@Resource
IBasicBusTypeChangeService basicBusTypeChangeService;
@Resource
CustomerService customerService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
IoOrderService ioOrderService;
@Resource
IoOrderDetailBizService ioOrderDetailBizService;
@Resource
PurOrderService purOrderService;
@Resource
PurOrderDetailService purOrderDetailService;
@Resource
IoPurChangeService purChangeService;
/**
* 新增采购计划
*/
@RepeatSubmit()
@AuthRuleAnnotation("")
@PostMapping("/purchase/plan/postOrder")
public BaseResponse postOrder(@RequestBody PostPurPlanRequest postPurPlanRequest) {
Long userId = customerService.getUserId();
PurPlanEntity purPlanEntity = postPurPlanRequest.getPurPlanEntity();
purPlanEntity.setCreateUser(userId + "");
purPlanEntity.setCreateTime(new Date());
purPlanEntity.setUpdateTime(new Date());
purPlanEntity.setUpdateUser(userId + "");
purPlanEntity.setStatus(postPurPlanRequest.getEditStatus()); //草稿状态
if (postPurPlanRequest.getType() != null) {
String billNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.SG_ORDER, "yyyyMMdd"));
purPlanEntity.setBillNo(billNo);
}
if (purPlanEntity.getId() == null) {
purPlanService.insert(purPlanEntity);
} else {
purPlanService.update(purPlanEntity);
}
return ResultVOUtils.success("提交成功!");
}
/**
* 查询采购计划列表
*/
@GetMapping("/purchase/plan/list")
public BaseResponse list(PurPlanRequest purApplyRequest) {
if (purApplyRequest.getStatus() == null) {
purApplyRequest.setStatus(11); //查询未审核和草稿状态
}
List<PurPlanResponse> purApplyEntities = purPlanService.queryPageList(purApplyRequest);
PageInfo<PurPlanResponse> pageInfo;
pageInfo = new PageInfo<>(purApplyEntities);
PageSimpleResponse<PurPlanResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(purApplyEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
/**
* 查询采购计划列表
*/
@GetMapping("/purchase/plan/auditList")
public BaseResponse auditList(PurPlanRequest purApplyRequest) {
if (purApplyRequest.getStatus() == null) {
purApplyRequest.setStatus(10); //查询未审核和已审核状态
}
List<PurPlanResponse> purApplyEntities = purPlanService.queryPageList(purApplyRequest);
PageInfo<PurPlanResponse> pageInfo;
pageInfo = new PageInfo<>(purApplyEntities);
PageSimpleResponse<PurPlanResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(purApplyEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
/**
* 查询采购计划列表
*/
@GetMapping("/purchase/plan/selectApprovedList")
public BaseResponse selectApprovedList(PurPlanRequest purApplyRequest) {
if (purApplyRequest.getStatus() == null) {
purApplyRequest.setStatus(12); //查询已审核状态
}
List<PurPlanResponse> purApplyEntities = purPlanService.queryPageList(purApplyRequest);
PageInfo<PurPlanResponse> pageInfo;
pageInfo = new PageInfo<>(purApplyEntities);
PageSimpleResponse<PurPlanResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(purApplyEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
/**
* 审核采购计划
*/
@RepeatSubmit()
@PostMapping("/purchase/plan/auditOrder")
public BaseResponse auditOrder(@RequestBody PostPurPlanRequest postPurPlanRequest) {
Long userId = customerService.getUserId();
PurPlanEntity purPlanEntity = postPurPlanRequest.getPurPlanEntity();
purPlanEntity.setUpdateTime(new Date());
purPlanEntity.setUpdateUser(userId + "");
purPlanEntity.setAuditUser(userId + "");
purPlanEntity.setAuditUser(userId + "");
purPlanEntity.setStatus(postPurPlanRequest.getEditStatus());
// purPlanService.update(purApplyEntity);
if (purPlanEntity.getStatus() == 3) {
purChangeService.purPlanChange(purPlanEntity);
// generateDocument(purPlanEntity);
}
// String billNo="";
// List<PurPlanDetailEntity> purPlanDetailEntities = purPlanDetailService.findByOrderId(purApplyEntity.getId() + "");
//
// //对计划单里面的供应商进行分组
// Map<String, List<PurPlanDetailEntity>> map = purPlanDetailEntities.stream().collect(Collectors.groupingBy(PurPlanDetailEntity::getSupId));
//
// if (postPurPlanRequest.getEditStatus() == ConstantStatus.APPLY_AUDIT_ED) {
//
// if (CollUtil.isNotEmpty(purPlanDetailEntities) && postPurPlanRequest.isAutoPurchase()==true
// && StrUtil.isNotEmpty(postPurPlanRequest.getTargetSubInv()) && StrUtil.isNotEmpty(postPurPlanRequest.getTargetBillAction()) ) {
//
// 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(postPurPlanRequest.getTargetBillAction());
// ioOrderEntity.setFromCorp(m.getKey());
// ioOrderEntity.setFromType(ConstantStatus.FROM_PLAN);
// ioOrderEntity.setStatus(1);
// ioOrderEntity.setDealStatus(1);
// ioOrderEntity.setOrderType(1);
// ioOrderEntity.setCreateTime(new Date());
// ioOrderEntity.setCreateUser(postPurPlanRequest.getPurPlanEntity().getAuditUser());
// ioOrderEntity.setUpdateTime(new Date());
// ioOrderEntity.setUpdateUser(postPurPlanRequest.getPurPlanEntity().getAuditUser());
// ioOrderEntity.setCustomerId("110");
// ioOrderEntity.setDeptCode(postPurPlanRequest.getTargetDeptCode());
// ioOrderEntity.setInvCode(postPurPlanRequest.getTargetSubInv());
// 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);
// }
// }
// purApplyEntity.setStockOrderNo(billNo.substring(0,billNo.length()-1));
// purPlanService.update(purApplyEntity);
// }
// }
return ResultVOUtils.success("更新成功!");
}
//根据单据生成新单据
public Boolean generateDocument(PurPlanEntity purPlanEntity) {
BasicBusTypeChangeEntity basicBusTypeChangeEntity = new BasicBusTypeChangeEntity();
//查询计划详情
List<PurPlanDetailEntity> purPlanDetailEntityList = purPlanDetailService.findByOrderId(purPlanEntity.getId() + "");
//---------------------------------判断计划为已审核就生成计划单-------------------------------------------//\
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(purPlanEntity.getBillDate());
purOrderEntity.setStatus(basicBusTypeChangeEntity.getBusAuditStatus());
purOrderEntity.setRemark(purPlanEntity.getRemark());
purOrderEntity.setEmergency(purPlanEntity.getEmergency());
purOrderEntity.setArrivalTime(purPlanEntity.getArrivalTime());
purOrderEntity.setInvCode(purPlanEntity.getInvCode());
purOrderEntity.setDeptCode(purPlanEntity.getDeptCode());
purOrderEntity.setCreateUser(purPlanEntity.getAuditUser());
purOrderEntity.setCreateTime(timeProcess(purPlanEntity.getCreateTime(), basicBusTypeChangeEntity.getBusBeforeTime()));
purOrderEntity.setUpdateUser(purPlanEntity.getAuditUser());
purOrderEntity.setUpdateTime(timeProcess(purPlanEntity.getCreateTime(), basicBusTypeChangeEntity.getBusBeforeTime()));
if (purOrderEntity.getStatus() == 3) {
purOrderEntity.setAuditUser("");
purOrderEntity.setAuditTime(new Date());
}
//插入订单主表
purOrderService.insert(purOrderEntity);
//用stream流复制list
List<PurOrderDetailEntity> purOrderDetailEntityList = purPlanDetailEntityList.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(purPlanEntity.getCreateUser());
ioOrderEntity.setUpdateTime(new Date());
ioOrderEntity.setUpdateUser(purPlanEntity.getCreateUser());
ioOrderEntity.setCustomerId("110");
ioOrderEntity.setDeptCode(purPlanEntity.getInvCode());
ioOrderEntity.setInvCode(purPlanEntity.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;
}
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;
}
/**
* 查询采购计划列表
*/
@GetMapping("/purchase/plan/list/detail")
public BaseResponse detailList(PurPlanDetailRequest purApplyDetailRequest) {
List<PurOrderDetailResponse> purApplyDetailEntities = purPlanDetailService.joinQueryList(purApplyDetailRequest);
PageInfo<PurOrderDetailResponse> pageInfo;
pageInfo = new PageInfo<>(purApplyDetailEntities);
PageSimpleResponse<PurOrderDetailResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(purApplyDetailEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
/**
* 添加申购单到采购单里面
*/
@PostMapping("/purchase/plan/addPlanDetailAndApply")
public BaseResponse addPlanDetailAndApply(@RequestBody PurPlanRequest purPlanRequest) {
if (purPlanRequest.getApplyId() == null || purPlanRequest.getId() == null) {
return ResultVOUtils.error(999, "参数错误!");
}
//查询申购单详情
PurApplyDetailRequest purApplyDetailRequest = new PurApplyDetailRequest();
purApplyDetailRequest.setOrderIdFk(purPlanRequest.getApplyId() + "");
List<PurApplyDetailEntity> purApplyDetailEntityList = purApplyDetailService.selectPurApplyDetailList(purApplyDetailRequest);
//使用stream拷贝list
List<PurPlanDetailEntity> purPlanDetailEntityList = purApplyDetailEntityList.stream()
.map(e -> {
PurPlanDetailEntity d = new PurPlanDetailEntity();
BeanUtils.copyProperties(e, d);
return d;
})
.collect(Collectors.toList());
for (PurPlanDetailEntity obj : purPlanDetailEntityList) {
obj.setOrderIdFk(purPlanRequest.getId() + "");
}
//获取详情表信息
PurPlanDetailRequest purPlanDetailRequest = new PurPlanDetailRequest();
purPlanDetailRequest.setOrderIdFk(purPlanRequest.getId() + "");
List<PurPlanDetailEntity> purApplyDetailEntities = purPlanDetailService.getPurPlanDetailEntityList(purPlanDetailRequest);
List<Long> ids = new ArrayList<>();
for (PurPlanDetailEntity obj : purApplyDetailEntities) {
for (PurPlanDetailEntity obj1 : purPlanDetailEntityList) {
if (obj.getProductId().equals(obj1.getProductId())) {
//获取存在在详情表和申购单里面一样的产品
ids.add(obj.getId().longValue());
break;
}
}
}
//删除存在的产品
if (ids.size() > 0) {
purPlanDetailService.deleteByIds(ids);
}
boolean falg = purPlanDetailService.insertPurPlanDetailEntity(purPlanDetailEntityList);
if (falg) {
//查询申购单
return ResultVOUtils.success("添加成功");
} else {
return ResultVOUtils.success("添加失败");
}
}
/**
* 添加产品到采购单里面
*/
@PostMapping("/purchase/plan/addPlanDetail")
public BaseResponse addPlanDetail(@RequestBody PurPlanDetailEntity purPlanDetailEntity) {
boolean falg = purPlanDetailService.insert(purPlanDetailEntity);
if (falg) {
return ResultVOUtils.success("添加成功");
} else {
return ResultVOUtils.success("添加失败");
}
}
/**
* 新增计划单
*/
@AuthRuleAnnotation("")
@PostMapping("/purchase/plan/add")
public BaseResponse add() {
Long userId = customerService.getUserId();
PurPlanEntity purPlanEntity = new PurPlanEntity();
purPlanEntity.setCreateUser(userId + "");
purPlanEntity.setCreateTime(new Date());
purPlanEntity.setUpdateTime(new Date());
purPlanEntity.setUpdateUser(userId + "");
purPlanService.insert(purPlanEntity);
Long id = purPlanEntity.getId();
return ResultVOUtils.success(id);
}
/**
* 删除申购单和详情
*/
@AuthRuleAnnotation("")
@PostMapping("/purchase/plan/delPlanDetailAll")
public BaseResponse delApplyDetailAll(@RequestBody PurApplyEntity purApplyEntity) {
if (purApplyEntity.getId() != null) {
purPlanService.deleteById(purApplyEntity.getId());
purPlanDetailService.deleteByOrderId(purApplyEntity.getId() + "");
} else {
return ResultVOUtils.error(999, "参数有误!");
}
return ResultVOUtils.success();
}
/**
* 修改计划详情单
*/
@RepeatSubmit()
@PostMapping("/purchase/plan/updateDetail")
public BaseResponse detailEdit(@RequestBody PurPlanDetailEntity purPlanDetailEntity) {
purPlanDetailService.update(purPlanDetailEntity);
return ResultVOUtils.success("修改成功");
}
/**
* 删除采购计划
*
* @param ids 主键串
*/
@DeleteMapping("/purchase/plan/detail/{ids}")
public BaseResponse detailRemove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) {
purPlanDetailService.deleteByIds(Arrays.asList(ids));
return ResultVOUtils.success("删除成功");
}
}