Commit 7e503a633f6a6bcbac14152495ad6aa00d6f1a60

Authored by 房远帅
1 parent 390fdf0d

采购计划:快速变更

... ... @@ -116,6 +116,28 @@ public class ProcurementPlanController extends DefaultBaseController {
116 116 }
117 117
118 118 /**
  119 + * 查询可快速变更列表
  120 + */
  121 + @ApiOperation("查询可快速变更列表")
  122 + @HasPermission({"plan-manage:domestic-plan:query"})
  123 + @GetMapping("/queryCanFastChange")
  124 + public InvokeResult<PageResult<GetProcurementPlanBo>> queryCanFastChange(@Valid QueryProcurementPlanVo vo) {
  125 +
  126 + PageResult<ProcurementPlan> pageResult = procurementPlanService.queryCanFastChangeList(getPageIndex(vo),
  127 + getPageSize(vo), vo);
  128 +
  129 + List<ProcurementPlan> datas = pageResult.getDatas();
  130 + List<GetProcurementPlanBo> results = null;
  131 +
  132 + if (!CollectionUtil.isEmpty(datas)) {
  133 + results = datas.stream().map(GetProcurementPlanBo::new).collect(Collectors.toList());
  134 + fillBuyoutButtons(results, datas);
  135 + }
  136 +
  137 + return InvokeResultBuilder.success(PageResultUtil.rebuild(pageResult, results));
  138 + }
  139 +
  140 + /**
119 141 * 根据ID查询
120 142 */
121 143 @ApiOperation("根据ID查询")
... ...
... ... @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.annotation.TableField;
5 5 import com.baomidou.mybatisplus.annotation.TableName;
6 6 import com.lframework.starter.web.core.dto.BaseDto;
7 7 import com.lframework.starter.web.core.entity.BaseEntity;
8   -import io.swagger.annotations.ApiModelProperty;
9 8 import lombok.Data;
10 9 import java.math.BigDecimal;
11 10 import java.time.LocalDate;
... ...
... ... @@ -57,6 +57,10 @@ public class ProcurementBuyoutApplyServiceImpl extends
57 57 if (plan == null) {
58 58 throw new DefaultClientException("采购计划不存在!");
59 59 }
  60 + //判断是否有 通货买断、质量买断、数量买断
  61 + if (!(plan.getCommodityBuyout() || plan.getQualityBuyout() || plan.getQuantityBuyout())) {
  62 + return null;
  63 + }
60 64
61 65 List<ProcurementPlanLine> planLines = procurementPlanLineService.getByProcurementPlanId(plan.getId());
62 66 if (CollectionUtil.isEmpty(planLines)) {
... ... @@ -177,7 +181,7 @@ public class ProcurementBuyoutApplyServiceImpl extends
177 181 }
178 182 ProcurementBuyoutApply apply = this.getById(id);
179 183 if (apply == null) {
180   - throw new DefaultClientException("买断操作申请单不存在!");
  184 + return;
181 185 }
182 186
183 187 buyoutApplyLineService.remove(Wrappers.lambdaQuery(ProcurementBuyoutApplyLine.class)
... ... @@ -197,7 +201,7 @@ public class ProcurementBuyoutApplyServiceImpl extends
197 201 .eq(ProcurementBuyoutApply::getProcurementPlanId, planId);
198 202 ProcurementBuyoutApply apply = this.getOne(queryWrapper);
199 203 if (apply == null) {
200   - throw new DefaultClientException("买断操作申请单不存在!");
  204 + return;
201 205 }
202 206
203 207 buyoutApplyLineService.remove(Wrappers.lambdaQuery(ProcurementBuyoutApplyLine.class)
... ...
... ... @@ -26,11 +26,15 @@ import com.lframework.xingyun.sc.bo.procurement.GetProcurementPlanChangeLineBo;
26 26 import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
27 27 import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanChange;
28 28 import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanChangeLine;
  29 +import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanLine;
29 30 import com.lframework.xingyun.sc.procurement.mappers.change.ProcurementPlanChangeLineMapper;
30 31 import com.lframework.xingyun.sc.procurement.mappers.change.ProcurementPlanChangeMapper;
  32 +import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyService;
31 33 import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChangeLineService;
32 34 import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChangeService;
  35 +import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService;
33 36 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  37 +import com.lframework.xingyun.sc.procurement.vo.buyout.CreateProcurementBuyoutApplyVo;
34 38 import com.lframework.xingyun.sc.procurement.vo.change.CreateProcurementPlanChangeLineVo;
35 39 import com.lframework.xingyun.sc.procurement.vo.change.CreateProcurementPlanChangeVo;
36 40 import com.lframework.xingyun.sc.procurement.vo.change.QueryProcurementPlanChangeVo;
... ... @@ -59,6 +63,10 @@ public class ProcurementPlanChangeServiceImpl extends
59 63 private SysRoleService sysRoleService;
60 64 @Resource
61 65 private FlowInstanceWrapperService flowInstanceWrapperService;
  66 + @Resource
  67 + private ProcurementPlanLineService procurementPlanLineService;
  68 + @Resource
  69 + private ProcurementBuyoutApplyService procurementBuyoutApplyService;
62 70
63 71
64 72 private static final List<String> PROCESS_STATUSES = Arrays.asList(
... ... @@ -81,54 +89,155 @@ public class ProcurementPlanChangeServiceImpl extends
81 89 throw new DefaultClientException("原采购计划不存在!");
82 90 }
83 91
84   - if (StringUtil.isNotBlank(plan.getParentId())) {
85   - throw new DefaultClientException("只能选择主计划进行变更!");
86   - }
87   -
88 92 if (StringUtil.isBlank(plan.getProcessStatus())
89 93 || !PROCESS_STATUSES.contains(plan.getProcessStatus())) {
90 94 throw new DefaultClientException("原采购计划状态不允许变更,请确认计划已中止/完成");
91 95 }
92   - String currentUserId = SecurityUtil.getCurrentUser().getId();
93   - List<SysRole> roles = sysRoleService.getByUserId(currentUserId);
94   - List<String> roleCodes = CollectionUtil.isEmpty(roles) ? new java.util.ArrayList<>()
95   - : roles.stream().map(SysRole::getCode).collect(Collectors.toList());
96   - ProcurementPlanChange planChange = new ProcurementPlanChange();
97   - BeanUtil.copyProperties(vo, planChange);
98   - planChange.setId(IdUtil.getId());
99   - if (roleCodes.contains("ltcgczg") || roleCodes.contains("ztcgczg")
100   - || roleCodes.contains("htcgeczg") || roleCodes.contains("htcgyczg")) {
101   - planChange.setProcessNode("CGCZG");
102   - } else if (roleCodes.contains("qyjl")) {
103   - planChange.setProcessNode("QYJL");
104   - } else if (roleCodes.contains("nmcgkywy")) {
105   - planChange.setProcessNode("YWY");
106   - }
  96 + if ("FAST".equals(vo.getChangeType())) {
  97 + ProcurementPlanChange planChange = new ProcurementPlanChange();
  98 + BeanUtil.copyProperties(vo, planChange);
  99 + planChange.setId(IdUtil.getId());
  100 + planChange.setCode("K" + vo.getCode());
  101 + this.save(planChange);
  102 +
  103 + List<ProcurementPlanChangeLine> lines = new ArrayList<>();
  104 + if (!CollectionUtil.isEmpty(vo.getLines())) {
  105 + for (CreateProcurementPlanChangeLineVo lineVo : vo.getLines()) {
  106 + ProcurementPlanChangeLine line = new ProcurementPlanChangeLine();
  107 + BeanUtil.copyProperties(lineVo, line);
  108 + line.setId(IdUtil.getId());
  109 + line.setProcurementPlanChangeId(planChange.getId());
  110 + lines.add(line);
  111 + }
  112 + }
107 113
  114 + if (!CollectionUtil.isEmpty(lines)) {
  115 + procurementPlanChangeLineService.saveBatch(lines);
  116 + }
108 117
109   - this.save(planChange);
  118 + //变更的是子计划 直接修改(开票品名 公司名称 另付运费 分厂)子计划的数据(无需修改主计划、合同数据),需重新生成买断操作申请单(如有买断)
  119 + if (StringUtil.isNotEmpty(plan.getParentId())) {
  120 + //修改 开票品名 公司名称 另付运费
  121 + Wrapper<ProcurementPlan> parentWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
  122 + .set(ProcurementPlan::getInvoiceProductName, vo.getInvoiceProductName())
  123 + .set(ProcurementPlan::getCompanyShortId, vo.getCompanyShortId())
  124 + .set(ProcurementPlan::getShippingCost, vo.getShippingCost())
  125 + .set(ProcurementPlan::getWorkshopId, vo.getLines().get(0).getWorkshopId())
  126 + .set(ProcurementPlan::getProcessStatus, "COMPLETED")
  127 + .set(ProcurementPlan::getProcessNode, null)
  128 + .eq(ProcurementPlan::getId, vo.getProcurementPlanId());
  129 + procurementPlanService.update(parentWrapper);
  130 + //修改分厂
  131 + Wrapper<ProcurementPlanLine> lineWrapper = Wrappers.lambdaUpdate(ProcurementPlanLine.class)
  132 + .set(ProcurementPlanLine::getWorkshopId, vo.getLines().get(0).getWorkshopId())
  133 + .eq(ProcurementPlanLine::getProcurementPlanId, vo.getProcurementPlanId());
  134 + procurementPlanLineService.update(lineWrapper);
  135 + //先删除买断操作申请单
  136 + procurementBuyoutApplyService.deleteByPlanId(vo.getProcurementPlanId());
  137 + //重新生成买断操作申请单
  138 + CreateProcurementBuyoutApplyVo vo1 = new CreateProcurementBuyoutApplyVo();
  139 + vo1.setProcurementPlanId(vo.getProcurementPlanId());
  140 + procurementBuyoutApplyService.create(vo1);
  141 + } else {
  142 + //变更的是主计划(开票品名 公司名称 另付运费) 直接修改主计划的数据、合同数据、子计划数据,子计划买断操作申请单(如果只有主计划就只生成主计划的买断操作申请单)
  143 + Wrapper<ProcurementPlan> queryWrapper = Wrappers.lambdaQuery(ProcurementPlan.class)
  144 + .eq(ProcurementPlan::getFrozen, false)
  145 + .eq(ProcurementPlan::getParentId, vo.getProcurementPlanId());
  146 + List<ProcurementPlan> list = procurementPlanService.list(queryWrapper);
  147 + //有子计划
  148 + if (CollectionUtil.isNotEmpty(list)) {
  149 + //修改主计划 开票品名 公司名称 另付运费
  150 + Wrapper<ProcurementPlan> parentWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
  151 + .set(ProcurementPlan::getInvoiceProductName, vo.getInvoiceProductName())
  152 + .set(ProcurementPlan::getCompanyShortId, vo.getCompanyShortId())
  153 + .set(ProcurementPlan::getShippingCost, vo.getShippingCost())
  154 + .set(ProcurementPlan::getProcessStatus, "COMPLETED")
  155 + .set(ProcurementPlan::getProcessNode, null)
  156 + .eq(ProcurementPlan::getId, vo.getProcurementPlanId());
  157 + procurementPlanService.update(parentWrapper);
  158 +
  159 + //修改子计划 开票品名 公司名称 另付运费
  160 + Wrapper<ProcurementPlan> sonWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
  161 + .set(ProcurementPlan::getInvoiceProductName, vo.getInvoiceProductName())
  162 + .set(ProcurementPlan::getCompanyShortId, vo.getCompanyShortId())
  163 + .set(ProcurementPlan::getShippingCost, vo.getShippingCost())
  164 + .set(ProcurementPlan::getProcessStatus, "COMPLETED")
  165 + .set(ProcurementPlan::getProcessNode, null)
  166 + .eq(ProcurementPlan::getParentId, vo.getProcurementPlanId());
  167 + procurementPlanService.update(sonWrapper);
  168 +
  169 + for (ProcurementPlan procurementPlan : list) {
  170 + //先删除子计划买断操作申请单
  171 + procurementBuyoutApplyService.deleteByPlanId(procurementPlan.getId());
  172 + //重新生成子计划买断操作申请单
  173 + CreateProcurementBuyoutApplyVo vo1 = new CreateProcurementBuyoutApplyVo();
  174 + vo1.setProcurementPlanId(procurementPlan.getId());
  175 + procurementBuyoutApplyService.create(vo1);
  176 + }
  177 + //todo 作废合同,生成新合同
  178 + } else {
  179 + //没有子计划
  180 + //修改 开票品名 公司名称 另付运费
  181 + Wrapper<ProcurementPlan> parentWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
  182 + .set(ProcurementPlan::getInvoiceProductName, vo.getInvoiceProductName())
  183 + .set(ProcurementPlan::getCompanyShortId, vo.getCompanyShortId())
  184 + .set(ProcurementPlan::getShippingCost, vo.getShippingCost())
  185 + .set(ProcurementPlan::getWorkshopId, vo.getLines().get(0).getWorkshopId())
  186 + .set(ProcurementPlan::getProcessStatus, "COMPLETED")
  187 + .set(ProcurementPlan::getProcessNode, null)
  188 + .eq(ProcurementPlan::getId, vo.getProcurementPlanId());
  189 + procurementPlanService.update(parentWrapper);
  190 + //先删除买断操作申请单
  191 + procurementBuyoutApplyService.deleteByPlanId(vo.getProcurementPlanId());
  192 + //重新生成买断操作申请单
  193 + CreateProcurementBuyoutApplyVo vo1 = new CreateProcurementBuyoutApplyVo();
  194 + vo1.setProcurementPlanId(vo.getProcurementPlanId());
  195 + procurementBuyoutApplyService.create(vo1);
  196 + }
  197 + }
  198 + return planChange.getId();
  199 + } else {
  200 + String currentUserId = SecurityUtil.getCurrentUser().getId();
  201 + List<SysRole> roles = sysRoleService.getByUserId(currentUserId);
  202 + List<String> roleCodes = CollectionUtil.isEmpty(roles) ? new java.util.ArrayList<>()
  203 + : roles.stream().map(SysRole::getCode).collect(Collectors.toList());
  204 + ProcurementPlanChange planChange = new ProcurementPlanChange();
  205 + BeanUtil.copyProperties(vo, planChange);
  206 + planChange.setId(IdUtil.getId());
  207 + if (roleCodes.contains("ltcgczg") || roleCodes.contains("ztcgczg")
  208 + || roleCodes.contains("htcgeczg") || roleCodes.contains("htcgyczg")) {
  209 + planChange.setProcessNode("CGCZG");
  210 + } else if (roleCodes.contains("qyjl")) {
  211 + planChange.setProcessNode("QYJL");
  212 + } else if (roleCodes.contains("nmcgkywy")) {
  213 + planChange.setProcessNode("YWY");
  214 + }
  215 +
  216 +
  217 + this.save(planChange);
  218 +
  219 + List<ProcurementPlanChangeLine> lines = new ArrayList<>();
  220 + if (!CollectionUtil.isEmpty(vo.getLines())) {
  221 + for (CreateProcurementPlanChangeLineVo lineVo : vo.getLines()) {
  222 + ProcurementPlanChangeLine line = new ProcurementPlanChangeLine();
  223 + BeanUtil.copyProperties(lineVo, line);
  224 + line.setId(IdUtil.getId());
  225 + line.setProcurementPlanChangeId(planChange.getId());
  226 + lines.add(line);
  227 + }
  228 + }
110 229
111   - List<ProcurementPlanChangeLine> lines = new ArrayList<>();
112   - if (!CollectionUtil.isEmpty(vo.getLines())) {
113   - for (CreateProcurementPlanChangeLineVo lineVo : vo.getLines()) {
114   - ProcurementPlanChangeLine line = new ProcurementPlanChangeLine();
115   - BeanUtil.copyProperties(lineVo, line);
116   - line.setId(IdUtil.getId());
117   - line.setProcurementPlanChangeId(planChange.getId());
118   - lines.add(line);
  230 + if (!CollectionUtil.isEmpty(lines)) {
  231 + procurementPlanChangeLineService.saveBatch(lines);
119 232 }
120   - }
  233 + //更新采购计划变更状态为 变更中
  234 + Wrapper<ProcurementPlan> parentWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
  235 + .set(ProcurementPlan::getChangeStatus, "CHANGING")
  236 + .eq(ProcurementPlan::getId, vo.getProcurementPlanId());
  237 + procurementPlanService.update(parentWrapper);
121 238
122   - if (!CollectionUtil.isEmpty(lines)) {
123   - procurementPlanChangeLineService.saveBatch(lines);
  239 + return planChange.getId();
124 240 }
125   - //更新采购计划变更状态为 变更中
126   - Wrapper<ProcurementPlan> parentWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
127   - .set(ProcurementPlan::getChangeStatus, "CHANGING")
128   - .eq(ProcurementPlan::getId, vo.getProcurementPlanId());
129   - procurementPlanService.update(parentWrapper);
130   -
131   - return planChange.getId();
132 241 }
133 242
134 243 @Override
... ...
... ... @@ -116,6 +116,25 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla
116 116 }
117 117
118 118 @Override
  119 + public PageResult<ProcurementPlan> queryCanFastChangeList(Integer pageIndex, Integer pageSize,
  120 + QueryProcurementPlanVo vo) {
  121 +
  122 + Assert.greaterThanZero(pageIndex);
  123 + Assert.greaterThanZero(pageSize);
  124 +
  125 + PageHelperUtil.startPage(pageIndex, pageSize);
  126 + List<ProcurementPlan> datas = this.queryCanFastChangeList(vo);
  127 +
  128 + return PageResultUtil.convert(new PageInfo<>(datas));
  129 + }
  130 +
  131 + @Override
  132 + public List<ProcurementPlan> queryCanFastChangeList(QueryProcurementPlanVo vo) {
  133 +
  134 + return getBaseMapper().queryCanFastChangeList(vo);
  135 + }
  136 +
  137 + @Override
119 138 public GetProcurementPlanBo getDetail(String id) {
120 139 if (StringUtil.isBlank(id)) {
121 140 throw new InputErrorException("ID不能为空!");
... ...
... ... @@ -24,5 +24,13 @@ public interface ProcurementPlanMapper extends BaseMapper<ProcurementPlan> {
24 24 */
25 25 List<ProcurementPlan> queryCanChangeOrReplenishmentList(@Param("vo") QueryProcurementPlanVo vo);
26 26
  27 + /**
  28 + * 查询可快速变更列表
  29 + *
  30 + * @param vo
  31 + * @return
  32 + */
  33 + List<ProcurementPlan> queryCanFastChangeList(@Param("vo") QueryProcurementPlanVo vo);
  34 +
27 35 ProcurementPlan findById(@Param("id") String id);
28 36 }
... ...
... ... @@ -47,6 +47,20 @@ public interface ProcurementPlanService extends BaseMpService<ProcurementPlan> {
47 47 */
48 48 List<ProcurementPlan> queryCanChangeOrReplenishmentList(QueryProcurementPlanVo vo);
49 49
  50 +
  51 + /**
  52 + * 查询可快速变更列表
  53 + *
  54 + * @param vo
  55 + * @return
  56 + */
  57 + List<ProcurementPlan> queryCanFastChangeList(QueryProcurementPlanVo vo);
  58 +
  59 + /**
  60 + * 查询可快速变更列表
  61 + */
  62 + PageResult<ProcurementPlan> queryCanFastChangeList(Integer pageIndex, Integer pageSize, QueryProcurementPlanVo vo);
  63 +
50 64 /**
51 65 * 根据ID查询详情
52 66 *
... ...
... ... @@ -210,6 +210,11 @@
210 210 <include refid="ProcurementPlan_sql"/>
211 211 <where>
212 212 pp.parent_id IS NULL
  213 + AND NOT EXISTS (
  214 + SELECT 1 FROM procurement_plan p
  215 + WHERE p.id = pp.parent_id
  216 + AND (p.change_status = 'CHANGING' OR p.replenishment_status = 'REPLENISHING')
  217 + )
213 218 <if test="vo != null">
214 219 <if test="vo.code != null and vo.code != ''">
215 220 AND pp.code LIKE CONCAT('%', #{vo.code}, '%')
... ... @@ -264,4 +269,54 @@
264 269 </where>
265 270 ORDER BY pp.create_time DESC
266 271 </select>
  272 +
  273 + <select id="queryCanFastChangeList" resultMap="ProcurementPlan">
  274 + <include refid="ProcurementPlan_sql"/>
  275 + <where>
  276 + pp.process_status IN ('COMPLETED', 'ABORTED')
  277 + AND (pp.change_status = '' OR pp.change_status IS NULL OR pp.change_status = 'CHANGED')
  278 + AND (pp.replenishment_status = '' OR pp.replenishment_status IS NULL OR pp.replenishment_status
  279 + = 'REPLENISHED')
  280 + AND NOT EXISTS (
  281 + SELECT 1 FROM procurement_plan p
  282 + WHERE p.id = pp.parent_id
  283 + AND (p.change_status = 'CHANGING' OR p.replenishment_status = 'REPLENISHING')
  284 + )
  285 + <if test="vo != null">
  286 + <if test="vo.code != null and vo.code != ''">
  287 + AND pp.code LIKE CONCAT('%', #{vo.code}, '%')
  288 + </if>
  289 + <if test="vo.companyShortId != null and vo.companyShortId != ''">
  290 + AND pp.company_short_id = #{vo.companyShortId}
  291 + </if>
  292 + <if test="vo.companyName != null and vo.companyName != ''">
  293 + AND (
  294 + bdcs.company_name LIKE CONCAT('%', #{vo.companyName}, '%')
  295 + OR bdcs.short_name LIKE CONCAT('%', #{vo.companyName}, '%')
  296 + )
  297 + </if>
  298 + <if test="vo.purchaseDepartment != null and vo.purchaseDepartment != ''">
  299 + AND pp.purchase_department = #{vo.purchaseDepartment}
  300 + </if>
  301 + <if test="vo.startDate != null">
  302 + AND pp.date >= #{vo.startDate}
  303 + </if>
  304 + <if test="vo.endDate != null">
  305 + <![CDATA[
  306 + AND pp.date <= #{vo.endDate}
  307 + ]]>
  308 + </if>
  309 + <if test="vo.supplierId != null and vo.supplierId != ''">
  310 + AND pp.supplier_id = #{vo.supplierId}
  311 + </if>
  312 + <if test="vo.supplierName != null and vo.supplierName != ''">
  313 + AND pdc.unit_name LIKE CONCAT('%', #{vo.supplierName}, '%')
  314 + </if>
  315 + <if test="vo.workshopId != null and vo.workshopId != ''">
  316 + AND pp.workshop_id = #{vo.workshopId}
  317 + </if>
  318 + </if>
  319 + </where>
  320 + ORDER BY pp.create_time DESC
  321 + </select>
267 322 </mapper>
... ...