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-spms-java/src/main/java/com/glxp/api/controller/purchase/PurOrderController.java

476 lines
21 KiB
Java

package com.glxp.api.controller.purchase;
import cn.hutool.core.bean.BeanUtil;
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.Log;
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.BusinessType;
import com.glxp.api.constant.Constant;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.constant.ConstantType;
import com.glxp.api.entity.auth.InvWarehouseEntity;
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.*;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.purchase.PurOrderDetailResponse;
import com.glxp.api.res.purchase.PurOrderResponse;
import com.glxp.api.res.purchase.PurPlanResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.auth.InvWarehouseService;
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 PurOrderController {
@Resource
PurOrderService purOrderService;
@Resource
PurPlanDetailService purPlanDetailService;
@Resource
PurOrderDetailService purOrderDetailService;
@Resource
CustomerService customerService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
IoOrderService ioOrderService;
@Resource
IoOrderDetailBizService ioOrderDetailBizService;
@Resource
InvWarehouseService invWarehouseService;
/**
* 新增采购计划
*/
@RepeatSubmit()
@AuthRuleAnnotation("")
@PostMapping("/purchase/order/postOrder")
@Log(title = "采购计划", businessType = BusinessType.INSERT)
public BaseResponse postOrder(@RequestBody PostPurOrderRequest postPurOrderRequest) {
Long userId = customerService.getUserId();
PurOrderEntity purOrderEntity = postPurOrderRequest.getPurOrderEntity();
purOrderEntity.setCreateUser(userId + "");
purOrderEntity.setCreateTime(new Date());
purOrderEntity.setUpdateTime(new Date());
purOrderEntity.setUpdateUser(userId + "");
purOrderEntity.setStatus(postPurOrderRequest.getEditStatus()); //草稿状态
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(purOrderEntity.getInvCode());
purOrderEntity.setDeptCode(invWarehouseEntity.getParentId());
if (postPurOrderRequest.getType() != null) {
String billNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.CG_ORDER, "yyyyMMdd"));
purOrderEntity.setBillNo(billNo);
}
if (purOrderEntity.getId() == null) {
purOrderService.insert(purOrderEntity);
} else {
purOrderService.update(purOrderEntity);
}
return ResultVOUtils.success("提交成功!");
}
/**
* 查询采购计划列表
*/
@GetMapping("/purchase/order/list")
public BaseResponse list(PurOrderRequest purOrderRequest) {
if (purOrderRequest.getStatus() == null) {
purOrderRequest.setStatus(11); //查询未审核和草稿状态
}
String customerId = customerService.getCustomerId();
if (!customerId.equals("110")) {
purOrderRequest.setSupId(customerId);
}
List<PurOrderResponse> purApplyEntities = purOrderService.queryPageList(purOrderRequest);
PageInfo<PurOrderResponse> pageInfo;
pageInfo = new PageInfo<>(purApplyEntities);
PageSimpleResponse<PurOrderResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(purApplyEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
/**
* 查询采购订单列表
*/
@GetMapping("/purchase/order/auditList")
public BaseResponse auditList(PurOrderRequest purOrderRequest) {
if (purOrderRequest.getStatus() == null) {
purOrderRequest.setStatus(10); //查询未审核和已审核状态
}
List<PurOrderResponse> purApplyEntities = purOrderService.queryPageList(purOrderRequest);
PageInfo<PurOrderResponse> pageInfo;
pageInfo = new PageInfo<>(purApplyEntities);
PageSimpleResponse<PurOrderResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(purApplyEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@RepeatSubmit()
@PostMapping("/purchase/order/dealOrder")
@Log(title = "送货单", businessType = BusinessType.INSERT)
public BaseResponse dealOrder(@RequestBody PostPurOrderRequest postPurOrderRequest) {
PurOrderEntity purOrderEntity = postPurOrderRequest.getPurOrderEntity();
purOrderEntity.setUpdateTime(new Date());
purOrderService.update(purOrderEntity);
if (postPurOrderRequest.isAutoPurchase() && StrUtil.isNotEmpty(postPurOrderRequest.getTargetBillAction())) {
String billNo = "";
List<PurOrderDetailEntity> purOrderDetailEntities = purOrderDetailService.findByOrderId(purOrderEntity.getId() + "");
//对计划单里面的供应商进行分组
Map<String, List<PurOrderDetailEntity>> map = purOrderDetailEntities.stream().collect(Collectors.groupingBy(PurOrderDetailEntity::getSupId));
if (CollUtil.isNotEmpty(purOrderDetailEntities) && postPurOrderRequest.isAutoPurchase() == true
&& StrUtil.isNotEmpty(postPurOrderRequest.getTargetBillAction())) {
for (Map.Entry<String, List<PurOrderDetailEntity>> 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(postPurOrderRequest.getTargetBillAction());
ioOrderEntity.setFromCorp(m.getKey());
ioOrderEntity.setFromType(ConstantStatus.FROM_Order);
ioOrderEntity.setStatus(1);
ioOrderEntity.setDealStatus(1);
ioOrderEntity.setOrderType(1);
ioOrderEntity.setCreateTime(new Date());
ioOrderEntity.setCreateUser(postPurOrderRequest.getPurOrderEntity().getAuditUser());
ioOrderEntity.setUpdateTime(new Date());
ioOrderEntity.setUpdateUser(postPurOrderRequest.getPurOrderEntity().getAuditUser());
ioOrderEntity.setCustomerId("110");
ioOrderEntity.setDeptCode(purOrderEntity.getDeptCode());
ioOrderEntity.setInvCode(purOrderEntity.getInvCode());
ioOrderEntity.setProductType(purOrderEntity.getProductType());
ioOrderService.insertOrder(ioOrderEntity);
billNo += ioOrderEntity.getBillNo() + ",";
//插入业务单表
for (PurOrderDetailEntity obj : m.getValue()) {
BasicProductsEntity basicProductsEntity = purOrderDetailService.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.setPrice(obj.getPrice());
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);
}
}
purOrderEntity.setStockOrderNo(billNo.substring(0, billNo.length() - 1));
purOrderService.update(purOrderEntity);
}
}
return ResultVOUtils.success("更新成功!");
}
/**
* 审核采购订单
*/
@RepeatSubmit()
@PostMapping("/purchase/order/auditOrder")
@Log(title = "采购订单", businessType = BusinessType.INSERT)
public BaseResponse auditOrder(@RequestBody PostPurOrderRequest postPurOrderRequest) {
Long userId = customerService.getUserId();
PurOrderEntity purOrderEntity = postPurOrderRequest.getPurOrderEntity();
purOrderEntity.setUpdateTime(new Date());
purOrderEntity.setAuditUser(userId + "");
purOrderEntity.setStatus(postPurOrderRequest.getEditStatus());
purOrderService.update(purOrderEntity);
String billNo = "";
List<PurOrderDetailEntity> purOrderDetailEntities = purOrderDetailService.findByOrderId(purOrderEntity.getId() + "");
//对计划单里面的供应商进行分组
Map<String, List<PurOrderDetailEntity>> map = purOrderDetailEntities.stream().collect(Collectors.groupingBy(PurOrderDetailEntity::getSupId));
if (postPurOrderRequest.getEditStatus() == ConstantStatus.APPLY_AUDIT_ED) {
if (CollUtil.isNotEmpty(purOrderDetailEntities) && postPurOrderRequest.isAutoPurchase() == true
&& StrUtil.isNotEmpty(postPurOrderRequest.getTargetSubInv()) && StrUtil.isNotEmpty(postPurOrderRequest.getTargetBillAction())) {
for (Map.Entry<String, List<PurOrderDetailEntity>> 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(postPurOrderRequest.getTargetBillAction());
ioOrderEntity.setFromCorp(m.getKey());
ioOrderEntity.setFromType(ConstantStatus.FROM_Order);
ioOrderEntity.setStatus(1);
ioOrderEntity.setDealStatus(1);
ioOrderEntity.setOrderType(1);
ioOrderEntity.setCreateTime(new Date());
ioOrderEntity.setCreateUser(postPurOrderRequest.getPurOrderEntity().getAuditUser());
ioOrderEntity.setUpdateTime(new Date());
ioOrderEntity.setUpdateUser(postPurOrderRequest.getPurOrderEntity().getAuditUser());
ioOrderEntity.setCustomerId("110");
ioOrderEntity.setDeptCode(postPurOrderRequest.getTargetDeptCode());
ioOrderEntity.setInvCode(postPurOrderRequest.getTargetSubInv());
ioOrderService.insertOrder(ioOrderEntity);
billNo += ioOrderEntity.getBillNo() + ",";
//插入业务单表
for (PurOrderDetailEntity obj : m.getValue()) {
BasicProductsEntity basicProductsEntity = purOrderDetailService.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(basicProductsEntity.getPrice());
}
ioOrderDetailBizEntity.setSupId(obj.getSupId());
ioOrderDetailBizService.insert(ioOrderDetailBizEntity);
}
}
purOrderEntity.setStockOrderNo(billNo.substring(0, billNo.length() - 1));
purOrderService.update(purOrderEntity);
}
}
return ResultVOUtils.success("更新成功!");
}
/**
* 查询采购订单列表
*/
@GetMapping("/purchase/order/list/detail")
public BaseResponse detailList(PurOrderDetailRequest purApplyDetailRequest) {
List<PurOrderDetailResponse> purOrderDetailResponseList = purOrderDetailService.joinQueryList(purApplyDetailRequest);
PageInfo<PurOrderDetailResponse> pageInfo;
pageInfo = new PageInfo<>(purOrderDetailResponseList);
PageSimpleResponse<PurOrderDetailResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(purOrderDetailResponseList);
return ResultVOUtils.success(pageSimpleResponse);
}
/**
* 查询药品采购订单列表
*/
@GetMapping("/purchase/order/drug/list/detail")
public BaseResponse drugDetailList(PurOrderDetailRequest purApplyDetailRequest) {
List<PurOrderDetailResponse> purOrderDetailResponseList = purOrderDetailService.joinQueryDrugList(purApplyDetailRequest);
PageInfo<PurOrderDetailResponse> pageInfo;
pageInfo = new PageInfo<>(purOrderDetailResponseList);
PageSimpleResponse<PurOrderDetailResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(purOrderDetailResponseList);
return ResultVOUtils.success(pageSimpleResponse);
}
/**
* pageSimpleResponse
* 添加申购单到采购单里面
*/
@PostMapping("/purchase/order/addPlanDetailAndOrder")
@Log(title = "采购订单", businessType = BusinessType.INSERT)
public BaseResponse addPlanDetailAndOrder(@RequestBody PurOrderRequest purOrderRequest) {
if (purOrderRequest.getApplyId() == null || purOrderRequest.getId() == null) {
return ResultVOUtils.error(999, "参数错误!");
}
//查询申购单详情
PurPlanDetailRequest purPlanDetailRequest = new PurPlanDetailRequest();
purPlanDetailRequest.setOrderIdFk(purOrderRequest.getApplyId() + "");
List<PurPlanDetailEntity> purApplyDetailEntityList = purPlanDetailService.getPurPlanDetailEntityList(purPlanDetailRequest);
//使用stream拷贝list
List<PurOrderDetailEntity> purOrderDetailEntityList = purApplyDetailEntityList.stream()
.map(e -> {
PurOrderDetailEntity d = new PurOrderDetailEntity();
BeanUtil.copyProperties(e, d);
return d;
})
.collect(Collectors.toList());
for (PurOrderDetailEntity obj : purOrderDetailEntityList) {
obj.setOrderIdFk(purOrderRequest.getId() + "");
}
//获取详情表信息
PurOrderDetailRequest PurOrderDetailRequest = new PurOrderDetailRequest();
PurOrderDetailRequest.setOrderIdFk(purOrderRequest.getId() + "");
List<PurOrderDetailEntity> purOrderDetailEntities = purOrderDetailService.getPurOrderDetailEntityList(PurOrderDetailRequest);
List<Long> ids = new ArrayList<>();
for (PurOrderDetailEntity obj : purOrderDetailEntities) {
for (PurOrderDetailEntity obj1 : purOrderDetailEntityList) {
if (obj.getProductId().equals(obj1.getProductId())) {
//获取存在在详情表和申购单里面一样的产品
ids.add(obj.getId().longValue());
break;
}
}
}
//删除存在的产品
if (ids.size() > 0) {
purOrderDetailService.deleteByIds(ids);
}
boolean falg = purOrderDetailService.insertPurOrderDetailEntity(purOrderDetailEntityList);
if (falg) {
//查询申购单
return ResultVOUtils.success("添加成功");
} else {
return ResultVOUtils.success("添加失败");
}
}
/**
* 添加产品到采购单里面
*/
@PostMapping("/purchase/order/addOrderDetail")
@Log(title = "采购订单", businessType = BusinessType.INSERT)
public BaseResponse addOrderDetail(@RequestBody PurOrderDetailEntity purOrderDetailEntity) {
boolean falg = purOrderDetailService.insert(purOrderDetailEntity);
if (falg) {
return ResultVOUtils.success("添加成功");
} else {
return ResultVOUtils.success("添加失败");
}
}
/**
* 新增计划单
*/
@AuthRuleAnnotation("")
@PostMapping("/purchase/order/add")
@Log(title = "计划单", businessType = BusinessType.INSERT)
public BaseResponse add() {
Long userId = customerService.getUserId();
PurOrderEntity purOrderEntity = new PurOrderEntity();
purOrderEntity.setCreateUser(userId + "");
purOrderEntity.setCreateTime(new Date());
purOrderEntity.setUpdateTime(new Date());
purOrderEntity.setUpdateUser(userId + "");
purOrderService.insert(purOrderEntity);
Long id = purOrderEntity.getId();
return ResultVOUtils.success(id);
}
/**
* 删除申购单和详情
*/
@AuthRuleAnnotation("")
@PostMapping("/purchase/order/delOrderDetailAll")
@Log(title = "申购单", businessType = BusinessType.DELETE)
public BaseResponse delApplyDetailAll(@RequestBody PurApplyEntity purApplyEntity) {
if (purApplyEntity.getId() != null) {
purOrderService.deleteById(purApplyEntity.getId());
purOrderDetailService.deleteByOrderId(purApplyEntity.getId() + "");
} else {
return ResultVOUtils.error(999, "参数有误!");
}
return ResultVOUtils.success();
}
/**
* 修改计划详情单
*/
@RepeatSubmit()
@PostMapping("/purchase/order/updateDetail")
@Log(title = "计划详情单", businessType = BusinessType.UPDATE)
public BaseResponse detailEdit(@RequestBody PurOrderDetailEntity purOrderDetailEntity) {
purOrderDetailService.update(purOrderDetailEntity);
return ResultVOUtils.success("修改成功");
}
/**
* 删除采购订单
*
* @param ids 主键串
*/
@DeleteMapping("/purchase/order/detail/{ids}")
@Log(title = "采购订单", businessType = BusinessType.DELETE)
public BaseResponse detailRemove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) {
purOrderDetailService.deleteByIds(Arrays.asList(ids));
return ResultVOUtils.success("删除成功");
}
}