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.
398 lines
17 KiB
Java
398 lines
17 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.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.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.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.UdiRelevanceService;
|
|
import com.glxp.api.service.inout.IoOrderDetailBizService;
|
|
import com.glxp.api.service.inout.IoOrderService;
|
|
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.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
|
|
CustomerService customerService;
|
|
@Resource
|
|
GennerOrderUtils gennerOrderUtils;
|
|
@Resource
|
|
IoOrderService ioOrderService;
|
|
@Resource
|
|
IoOrderDetailBizService ioOrderDetailBizService;
|
|
|
|
|
|
/**
|
|
* 新增采购计划
|
|
*/
|
|
@RepeatSubmit()
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/purchase/plan/postOrder")
|
|
@Log(title = "采购计划", businessType = BusinessType.INSERT)
|
|
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")
|
|
@Log(title = "采购计划", businessType = BusinessType.INSERT)
|
|
public BaseResponse auditOrder(@RequestBody PostPurPlanRequest postPurPlanRequest) {
|
|
Long userId = customerService.getUserId();
|
|
PurPlanEntity purApplyEntity = postPurPlanRequest.getPurPlanEntity();
|
|
purApplyEntity.setUpdateTime(new Date());
|
|
purApplyEntity.setAuditUser(userId + "");
|
|
purApplyEntity.setStatus(postPurPlanRequest.getEditStatus());
|
|
purPlanService.update(purApplyEntity);
|
|
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(basicProductsEntity.getPrice());
|
|
}
|
|
ioOrderDetailBizEntity.setSupId(obj.getSupId());
|
|
ioOrderDetailBizService.insert(ioOrderDetailBizEntity);
|
|
}
|
|
}
|
|
purApplyEntity.setStockOrderNo(billNo.substring(0,billNo.length()-1));
|
|
purPlanService.update(purApplyEntity);
|
|
}
|
|
}
|
|
return ResultVOUtils.success("更新成功!");
|
|
}
|
|
|
|
|
|
/**
|
|
* 查询采购计划列表
|
|
*/
|
|
@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")
|
|
@Log(title = "采购单", businessType = BusinessType.INSERT)
|
|
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();
|
|
BeanUtil.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")
|
|
@Log(title = "采购单", businessType = BusinessType.INSERT)
|
|
public BaseResponse addPlanDetail(@RequestBody PurPlanDetailEntity purPlanDetailEntity) {
|
|
|
|
int falg =purPlanDetailService.insert(purPlanDetailEntity);
|
|
if(falg > 0){
|
|
return ResultVOUtils.success("添加成功");
|
|
}else {
|
|
return ResultVOUtils.success("添加失败");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 新增计划单
|
|
*/
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/purchase/plan/add")
|
|
@Log(title = "计划单", businessType = BusinessType.INSERT)
|
|
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")
|
|
@Log(title = "申购单", businessType = BusinessType.DELETE)
|
|
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")
|
|
@Log(title = "计划详情单", businessType = BusinessType.UPDATE)
|
|
public BaseResponse detailEdit(@RequestBody PurPlanDetailEntity purPlanDetailEntity) {
|
|
purPlanDetailService.update(purPlanDetailEntity);
|
|
return ResultVOUtils.success("修改成功");
|
|
}
|
|
/**
|
|
* 删除采购计划
|
|
*
|
|
* @param ids 主键串
|
|
*/
|
|
@DeleteMapping("/purchase/plan/detail/{ids}")
|
|
@Log(title = "采购计划", businessType = BusinessType.DELETE)
|
|
public BaseResponse detailRemove(@NotEmpty(message = "主键不能为空")
|
|
@PathVariable Long[] ids) {
|
|
purPlanDetailService.deleteByIds(Arrays.asList(ids));
|
|
return ResultVOUtils.success("删除成功");
|
|
}
|
|
|
|
}
|