|
|
|
package com.glxp.api.controller.purchase;
|
|
|
|
|
|
|
|
import com.glxp.api.req.purchase.*;
|
|
|
|
import com.glxp.api.service.basic.SysApprovalFlowService;
|
|
|
|
import com.glxp.api.service.purchase.impl.PurApplyDetailService;
|
|
|
|
import com.glxp.api.service.purchase.impl.PurApplyService;
|
|
|
|
import com.glxp.api.service.purchase.impl.PurOrderDetailService;
|
|
|
|
import com.glxp.api.service.purchase.impl.PurPlanDetailService;
|
|
|
|
import com.glxp.api.service.system.SystemParamConfigService;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
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.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.res.PageSimpleResponse;
|
|
|
|
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.IBasicBusTypeChangeService;
|
|
|
|
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.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;
|
|
|
|
@Resource
|
|
|
|
SysApprovalFlowService sysApprovalFlowService;
|
|
|
|
@Resource
|
|
|
|
SystemParamConfigService systemParamConfigService;
|
|
|
|
|
|
|
|
final String type = "cgjh";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 新增采购计划
|
|
|
|
*/
|
|
|
|
@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()); //草稿状态
|
|
|
|
purPlanEntity.setBillType(ConstantStatus.BUS_ORDER_CGJH);
|
|
|
|
if (postPurPlanRequest.getType() != null) {
|
|
|
|
String billNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.SG_ORDER, "yyyyMMdd"));
|
|
|
|
purPlanEntity.setBillNo(billNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean sys_approval_flow = "1".equals(systemParamConfigService.selectValueByParamKey("sys_approval_flow"));
|
|
|
|
Integer editStatus = postPurPlanRequest.getEditStatus();
|
|
|
|
if (editStatus == 2 && sys_approval_flow){//提交审核
|
|
|
|
String approvalFlowId = sysApprovalFlowService.getApprovalFlowId();
|
|
|
|
purPlanEntity.setApprovalFlowId(approvalFlowId);
|
|
|
|
sysApprovalFlowService.generateFlow(approvalFlowId,purPlanEntity.getBillNo(),type);
|
|
|
|
}
|
|
|
|
|
|
|
|
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); //查询未审核和草稿状态
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean sys_approval_flow = "1".equals(systemParamConfigService.selectValueByParamKey("sys_approval_flow"));
|
|
|
|
purApplyRequest.setSysApprovalFlow(sys_approval_flow);
|
|
|
|
|
|
|
|
List<PurPlanResponse> purApplyEntities = purPlanService.queryPageList(purApplyRequest);
|
|
|
|
PageInfo<PurPlanResponse> 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); //查询待审核
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean sys_approval_flow = "1".equals(systemParamConfigService.selectValueByParamKey("sys_approval_flow"));
|
|
|
|
purApplyRequest.setSysApprovalFlow(sys_approval_flow);
|
|
|
|
|
|
|
|
List<PurPlanResponse> purApplyEntities = purPlanService.queryPageList(purApplyRequest);
|
|
|
|
PageInfo<PurPlanResponse> 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); //查询已审核状态
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean sys_approval_flow = "1".equals(systemParamConfigService.selectValueByParamKey("sys_approval_flow"));
|
|
|
|
purApplyRequest.setSysApprovalFlow(sys_approval_flow);
|
|
|
|
|
|
|
|
List<PurPlanResponse> purApplyEntities = purPlanService.queryPageList(purApplyRequest);
|
|
|
|
PageInfo<PurPlanResponse> 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.setAuditTime(new Date());
|
|
|
|
purPlanEntity.setStatus(postPurPlanRequest.getEditStatus());
|
|
|
|
purPlanService.update(purPlanEntity);
|
|
|
|
if (purPlanEntity.getStatus() == 3) {
|
|
|
|
purPlanEntity = purPlanService.selectById(purPlanEntity.getId());
|
|
|
|
purChangeService.purPlanChange(purPlanEntity);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success("更新成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询采购计划列表
|
|
|
|
*/
|
|
|
|
@GetMapping("/purchase/plan/list/detail")
|
|
|
|
public BaseResponse detailList(PurPlanDetailRequest purApplyDetailRequest) {
|
|
|
|
|
|
|
|
List<PurOrderDetailResponse> purApplyDetailEntities = purPlanDetailService.joinQueryList(purApplyDetailRequest);
|
|
|
|
PageInfo<PurOrderDetailResponse> pageInfo = new PageInfo<>(purApplyDetailEntities);
|
|
|
|
PageSimpleResponse<PurOrderDetailResponse> pageSimpleResponse = new PageSimpleResponse<>();
|
|
|
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
|
|
|
pageSimpleResponse.setList(purApplyDetailEntities);
|
|
|
|
return ResultVOUtils.success(pageSimpleResponse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询采购计划列表
|
|
|
|
*/
|
|
|
|
@GetMapping("/purchase/plan/drug/list/detail")
|
|
|
|
public BaseResponse drugDetailList(PurPlanDetailRequest purApplyDetailRequest) {
|
|
|
|
|
|
|
|
List<PurOrderDetailResponse> purApplyDetailEntities = purPlanDetailService.joinDrugQueryList(purApplyDetailRequest);
|
|
|
|
PageInfo<PurOrderDetailResponse> pageInfo = new PageInfo<>(purApplyDetailEntities);
|
|
|
|
PageSimpleResponse<PurOrderDetailResponse> pageSimpleResponse = new PageSimpleResponse<>();
|
|
|
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
|
|
|
pageSimpleResponse.setList(purApplyDetailEntities);
|
|
|
|
return ResultVOUtils.success(pageSimpleResponse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询采购计划详情列表
|
|
|
|
*
|
|
|
|
* @param purPlanDetailRequest
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@GetMapping("/purchase/plan/list/getDetailList")
|
|
|
|
public BaseResponse getDetailList(PurPlanDetailRequest purPlanDetailRequest) {
|
|
|
|
List<PurOrderDetailResponse> list = purPlanDetailService.getDetailList(purPlanDetailRequest);
|
|
|
|
PageInfo<PurOrderDetailResponse> pageInfo = new PageInfo<>(list);
|
|
|
|
return ResultVOUtils.page(pageInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加申购单到采购单里面
|
|
|
|
*/
|
|
|
|
@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) {
|
|
|
|
|
|
|
|
int falg = purPlanDetailService.insert(purPlanDetailEntity);
|
|
|
|
if (falg > 0) {
|
|
|
|
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/addDetailByWarlockBag")
|
|
|
|
public BaseResponse addDetailByWarlockBag(@RequestBody AddDetailByWarlockBagRequest addDetailByWarlockBagRequest) {
|
|
|
|
purPlanDetailService.addDetailByWarlockBag(addDetailByWarlockBagRequest);
|
|
|
|
return ResultVOUtils.success(addDetailByWarlockBagRequest.getOrderIdFk());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除申购单和详情
|
|
|
|
*/
|
|
|
|
@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("删除成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|