diff --git a/src/main/java/com/qs/serve/common/model/enums/BudgetLogOptFlag.java b/src/main/java/com/qs/serve/common/model/enums/BudgetLogOptFlag.java index 215932c8..5327fc29 100644 --- a/src/main/java/com/qs/serve/common/model/enums/BudgetLogOptFlag.java +++ b/src/main/java/com/qs/serve/common/model/enums/BudgetLogOptFlag.java @@ -6,20 +6,11 @@ import lombok.Getter; /** * @author YenHex * @since 2023/1/30 - * @apiNote - * 0-预算新增;1-费用申请;2-预算调增;3-预算调减;4-费用释放;5-费用申请调增;6-费用申请调减 - 7-销售区域迁移调增,8-销售区域迁移调减 - 9-行政区域迁移调增,10-行政区域迁移调减 - 11-政策申请 - 12-政策申请调增 - 13-政策申请调减 - 14-政策释放(被拒绝后) */ @Getter @AllArgsConstructor public enum BudgetLogOptFlag { - /** 0-预算新增 */ State_0(0,true), @@ -56,20 +47,19 @@ public enum BudgetLogOptFlag { /** 11-政策申请 */ State_11(11,false), - /** 12-政策申请调增 */ - State_12(12,false), + /** 12-政策申请调增(政策申请,预算调增) */ + State_12(12,true), - /** 13-政策申请调减 */ + /** 13-政策申请调减(政策申请,预算调减) */ State_13(13,false), - /** 14-政策释放(被拒绝后) */ + /** 14-政策释放(被拒绝后,政策释放) */ State_14(14,true), /** 15-费用申请释放(被拒绝后,预算增加) */ State_15(15,true); - /** * 编码 */ diff --git a/src/main/java/com/qs/serve/modules/bms/service/impl/BmsRegion2ServiceImpl.java b/src/main/java/com/qs/serve/modules/bms/service/impl/BmsRegion2ServiceImpl.java index 53679ac5..d00012ea 100644 --- a/src/main/java/com/qs/serve/modules/bms/service/impl/BmsRegion2ServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/bms/service/impl/BmsRegion2ServiceImpl.java @@ -54,8 +54,11 @@ public class BmsRegion2ServiceImpl extends ServiceImpl public boolean updateBmsRegionById(BmsRegion param){ BmsRegion ori = this.getById(param.getId()); param = this.flushSetLevel(param); - boolean b = this.updateById(param); boolean changePid = !ori.getPid().equals(param.getPid()); + if(changePid){ + Assert.throwEx("当前版本限制上下级变更"); + } + boolean b = this.updateById(param); if(!ori.getName().equals(param.getName())||changePid) { BmsRegion parentRegion = this.updatePathByPid(param.getId()); if(changePid){ diff --git a/src/main/java/com/qs/serve/modules/seeyon/service/SeeYonOperationService.java b/src/main/java/com/qs/serve/modules/seeyon/service/SeeYonOperationService.java index b7efeea2..cefcb706 100644 --- a/src/main/java/com/qs/serve/modules/seeyon/service/SeeYonOperationService.java +++ b/src/main/java/com/qs/serve/modules/seeyon/service/SeeYonOperationService.java @@ -38,7 +38,7 @@ public interface SeeYonOperationService extends SeeYonBaseService{ * @param affairCommit * @return */ - String commitGetSyFormId(TbsAffairCommitBo affairCommit); + String getSyFormIdByTargetInfo(TbsAffairCommitBo affairCommit); /** * 审批退回 @@ -186,7 +186,7 @@ public interface SeeYonOperationService extends SeeYonBaseService{ */ default R commitAffair(TbsAffairCommitBo affairCommit){ getRequestService().testConnection(); - String syFormId = this.commitGetSyFormId(affairCommit); + String syFormId = this.getSyFormIdByTargetInfo(affairCommit); R result = getRequestService().commonCommit(affairCommit, getTemplateCode(),syFormId); boolean isBackCommit = affairCommit.getState()==2; if(result.getStatus()==200){ diff --git a/src/main/java/com/qs/serve/modules/tbs/mapper/TbsScheduleItemBudgetMapper.java b/src/main/java/com/qs/serve/modules/tbs/mapper/TbsScheduleItemBudgetMapper.java index 9de54e29..5b4dc604 100644 --- a/src/main/java/com/qs/serve/modules/tbs/mapper/TbsScheduleItemBudgetMapper.java +++ b/src/main/java/com/qs/serve/modules/tbs/mapper/TbsScheduleItemBudgetMapper.java @@ -49,6 +49,7 @@ public interface TbsScheduleItemBudgetMapper extends BaseMapper logLqw = new LambdaQueryWrapper<>(); logLqw.eq(TbsBudgetLog::getCostApplyId,costApplyId); + logLqw.eq(TbsBudgetLog::getRollbackFlag,BudgetLogRollbackFlag.State_0); List oldLogList = tbsBudgetLogService.list(logLqw); List oldLogList4Upd = oldLogList.stream().map(a->{ TbsBudgetLog budgetLog = new TbsBudgetLog(); @@ -145,8 +145,9 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService budgetLog.setUpdateBy(null); budgetLog.setUpdateTime(null); budgetLog.setId(null); - budgetLog.setOptType(BudgetLogOptFlag.State_15.getCode()); - budgetLog.setAmount(TbsBudgetLogBuildUtil.buildAmount(budgetLog.getAmount(),BudgetLogOptFlag.State_15)); + BudgetLogOptFlag optFlag = BudgetLogOptFlag.State_15; + budgetLog.setOptType(optFlag.getCode()); + budgetLog.setAmount(TbsBudgetLogBuildUtil.buildAmount(budgetLog.getAmount(),optFlag)); } tbsBudgetLogService.saveBatch(oldLogList); return null; @@ -184,7 +185,7 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService } @Override - public String commitGetSyFormId(TbsAffairCommitBo affairCommit) { + public String getSyFormIdByTargetInfo(TbsAffairCommitBo affairCommit) { TbsCostApply costApply = costApplyService.getById(affairCommit.getCostApplyId()); if(!costApply.getChargeState().equals(TbsCostApplyState.State_1_apply.getCode())){ Assert.throwEx("费用申请处于未非审批状态"); diff --git a/src/main/java/com/qs/serve/modules/tzc/controller/TzcPolicyController.java b/src/main/java/com/qs/serve/modules/tzc/controller/TzcPolicyController.java index 084ab2c6..2d631085 100644 --- a/src/main/java/com/qs/serve/modules/tzc/controller/TzcPolicyController.java +++ b/src/main/java/com/qs/serve/modules/tzc/controller/TzcPolicyController.java @@ -29,6 +29,7 @@ import com.qs.serve.modules.tzc.common.TzcPolicyStatus; import com.qs.serve.modules.tzc.entity.TzcPolicyItem; import com.qs.serve.modules.tzc.service.TzcPolicyApplicationService; import com.qs.serve.modules.tzc.service.TzcPolicyItemService; +import com.qs.serve.modules.tzc.service.impl.TzcPolicyOperationServiceImpl; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; @@ -58,6 +59,7 @@ public class TzcPolicyController { private TzcPolicyService tzcPolicyService; private TzcPolicyItemService tzcPolicyItemService; private TzcPolicyApplicationService policyApplicationService; + private TzcPolicyOperationServiceImpl tzcPolicyOperationService; private TbsBudgetLogService tbsBudgetLogService; private SysUserService sysUserService; private SeeYonRequestService seeYonService; @@ -205,31 +207,32 @@ public class TzcPolicyController { * @return */ @GetMapping("/ListAffairs") - public R> pageMemberAffair(Long policyId){ - TzcPolicy tzcPolicy = tzcPolicyService.getById(policyId); - if(tzcPolicy.getSyFormId()==null){ - return R.ok(); - } - String templateCode = TbsSeeYonConst.PolicyConf.Code(); - R> syResult = seeYonService.commonListAffairs(policyId+"",null,templateCode); - List ctpAffairs = syResult.getData(); - if(ctpAffairs.size()>0){ - List oaUserIds = ctpAffairs.stream().map(CtpAffair::getMemberId).collect(Collectors.toList()); - List userList = sysUserService.listByOaMemberIds(oaUserIds); - List result = new ArrayList<>(); - for (CtpAffair ctpAffair : ctpAffairs) { - CtpAffairVo ctpAffairVo = new CtpAffairVo(); - ctpAffairVo.setAffairInfo(ctpAffair); - for (SysUser user : userList) { - if(ctpAffair.getMemberId().equals(user.getSyUserId())){ - ctpAffairVo.setUserInfo(user.toSysUserVo()); - } - } - result.add(ctpAffairVo); - } - return R.ok(result); - } - return R.ok(); + public R> pageMemberAffair(String policyId){ + return tzcPolicyOperationService.pageAffair(policyId); +// TzcPolicy tzcPolicy = tzcPolicyService.getById(policyId); +// if(tzcPolicy.getSyFormId()==null){ +// return R.ok(); +// } +// String templateCode = TbsSeeYonConst.PolicyConf.Code(); +// R> syResult = seeYonService.commonListAffairs(policyId+"",null,templateCode); +// List ctpAffairs = syResult.getData(); +// if(ctpAffairs.size()>0){ +// List oaUserIds = ctpAffairs.stream().map(CtpAffair::getMemberId).collect(Collectors.toList()); +// List userList = sysUserService.listByOaMemberIds(oaUserIds); +// List result = new ArrayList<>(); +// for (CtpAffair ctpAffair : ctpAffairs) { +// CtpAffairVo ctpAffairVo = new CtpAffairVo(); +// ctpAffairVo.setAffairInfo(ctpAffair); +// for (SysUser user : userList) { +// if(ctpAffair.getMemberId().equals(user.getSyUserId())){ +// ctpAffairVo.setUserInfo(user.toSysUserVo()); +// } +// } +// result.add(ctpAffairVo); +// } +// return R.ok(result); +// } +// return R.ok(); } /** @@ -239,43 +242,44 @@ public class TzcPolicyController { */ @GetMapping("/pageMemberAffair") public R> pageMemberAffair(CtpAffairQo param){ - param.setTitle(param.getChargeTheme()); - param.setApplyUserName(param.getUserName()); - SysUser sysUser = sysUserService.getById(AuthContextUtils.getSysUserId()); - if(!StringUtils.hasText(sysUser.getSyUserId())||!StringUtils.hasText(sysUser.getSyAccount())){ - return R.error("当前账号未绑定致远用户信息"); - } - param.setMemberId(sysUser.getSyUserId()); - param.setTemplateCode(TbsSeeYonConst.PolicyConf.Code()); - R> syResult = seeYonService.pageMemberAffair(param); - PageVo pageVo = syResult.getData(); - List ctpAffairs = pageVo.getList(); - if(ctpAffairs.size()>0){ - List oaUserIds = ctpAffairs.stream().map(CtpAffair::getMemberId).collect(Collectors.toList()); - List userList = sysUserService.listByOaMemberIds(oaUserIds); - List policyIds = ctpAffairs.stream().map(CtpAffair::getCostApplyId).collect(Collectors.toList()); - List policyList = tzcPolicyService.listByIds(policyIds); - List result = new ArrayList<>(); - for (CtpAffair ctpAffair : ctpAffairs) { - CtpAffairVo ctpAffairVo = new CtpAffairVo(); - for (TzcPolicy policy : policyList) { - if(policy.getId().toString().equals(ctpAffair.getCostApplyId())){ - ctpAffairVo.setPolicyInfo(policy); - break; - } - } - for (SysUser user : userList) { - if(ctpAffair.getMemberId().equals(user.getSyUserId())){ - ctpAffairVo.setUserInfo(user.toSysUserVo()); - } - } - ctpAffairVo.setAffairInfo(ctpAffair); - result.add(ctpAffairVo); - } - PageVo costApplyPageVo = PageVo.initNewList(pageVo,result); - return R.ok(costApplyPageVo); - } - return R.byEmptyList(); + return tzcPolicyOperationService.pageMemberAffair(param); +// param.setTitle(param.getChargeTheme()); +// param.setApplyUserName(param.getUserName()); +// SysUser sysUser = sysUserService.getById(AuthContextUtils.getSysUserId()); +// if(!StringUtils.hasText(sysUser.getSyUserId())||!StringUtils.hasText(sysUser.getSyAccount())){ +// return R.error("当前账号未绑定致远用户信息"); +// } +// param.setMemberId(sysUser.getSyUserId()); +// param.setTemplateCode(TbsSeeYonConst.PolicyConf.Code()); +// R> syResult = seeYonService.pageMemberAffair(param); +// PageVo pageVo = syResult.getData(); +// List ctpAffairs = pageVo.getList(); +// if(ctpAffairs.size()>0){ +// List oaUserIds = ctpAffairs.stream().map(CtpAffair::getMemberId).collect(Collectors.toList()); +// List userList = sysUserService.listByOaMemberIds(oaUserIds); +// List policyIds = ctpAffairs.stream().map(CtpAffair::getCostApplyId).collect(Collectors.toList()); +// List policyList = tzcPolicyService.listByIds(policyIds); +// List result = new ArrayList<>(); +// for (CtpAffair ctpAffair : ctpAffairs) { +// CtpAffairVo ctpAffairVo = new CtpAffairVo(); +// for (TzcPolicy policy : policyList) { +// if(policy.getId().toString().equals(ctpAffair.getCostApplyId())){ +// ctpAffairVo.setPolicyInfo(policy); +// break; +// } +// } +// for (SysUser user : userList) { +// if(ctpAffair.getMemberId().equals(user.getSyUserId())){ +// ctpAffairVo.setUserInfo(user.toSysUserVo()); +// } +// } +// ctpAffairVo.setAffairInfo(ctpAffair); +// result.add(ctpAffairVo); +// } +// PageVo costApplyPageVo = PageVo.initNewList(pageVo,result); +// return R.ok(costApplyPageVo); +// } +// return R.byEmptyList(); } /** @@ -286,82 +290,83 @@ public class TzcPolicyController { @SysLog(module = SystemModule.Budget, title = "费用申请", biz = BizType.DELETE) @PreAuthorize("hasRole('tbs:costApply:commit')") public R commitAffair(@RequestBody @Valid TbsAffairCommitBo affairCommit){ - seeYonService.testConnection(); - Long policyId = affairCommit.getPolicyId(); - TzcPolicy tzcPolicy = tzcPolicyService.getById(policyId); - if(!tzcPolicy.getPolicyStatus().equals(TzcPolicyStatus.Status_1_Checking)){ - return R.error("费用申请处于未非审批状态!"); - } - R result = seeYonService.commonCommit(affairCommit,TbsSeeYonConst.PolicyConf.Code(),tzcPolicy.getSyFormId()); - boolean isBackCommit = affairCommit.getState()==2; - if(result.getStatus()==200){ - // 判断是否含有下个节点 - String flag = result.getData(); - //审批中(next)、完成(finish)、拒绝(refused) - if("finish".equals(flag)){ - TzcPolicy policy = new TzcPolicy(); - policy.setId(tzcPolicy.getId()); - policy.setPolicyStatus(TzcPolicyStatus.Status_2_PassSuccess); - policy.setPassTime(LocalDateTime.now()); - tzcPolicyService.updateById(policy); - //更新活动通过时间 - TzcPolicyItem policyItem = new TzcPolicyItem(); - policyItem.setPolicyItemStatus(TzPolicyItemStatus.Status_1_PassSuccess); - LambdaQueryWrapper itemLqw = new LambdaQueryWrapper<>(); - itemLqw.eq(TzcPolicyItem::getPolicyId,tzcPolicy.getId()); - tzcPolicyItemService.update(policyItem,itemLqw); - return R.ok(); - }else if ("stop".equals(flag)){ - if(isBackCommit){ - TzcPolicy policy = new TzcPolicy(); - policy.setId(tzcPolicy.getId()); - policy.setPolicyStatus(TzcPolicyStatus.Status_4_RollBack); - tzcPolicyService.updateById(policy); - LambdaQueryWrapper logLqw = new LambdaQueryWrapper<>(); - logLqw.select(TbsBudgetLog::getId); - logLqw.eq(TbsBudgetLog::getPolicyId,tzcPolicy.getId()); - logLqw.eq(TbsBudgetLog::getRollbackFlag, BudgetLogRollbackFlag.State_0); - List budgetLogList = tbsBudgetLogService.list(logLqw); - budgetLogList.forEach(a->a.setRollbackFlag(BudgetLogRollbackFlag.State_1)); - tbsBudgetLogService.updateBatchById(budgetLogList); - return R.ok(); - }else { - TzcPolicy policy = new TzcPolicy(); - policy.setId(tzcPolicy.getId()); - policy.setPolicyStatus(TzcPolicyStatus.Status_3_Refuse); - tzcPolicyService.updateById(policy); - tzcPolicyService.releaseCost(policy.getId(), 1); - //移除日志 - LambdaQueryWrapper logLqw = new LambdaQueryWrapper<>(); - logLqw.eq(TbsBudgetLog::getPolicyId,tzcPolicy.getId()); - List oldLogList = tbsBudgetLogService.list(logLqw); - List oldLogList4Upd = oldLogList.stream().map(a->{ - TbsBudgetLog budgetLog = new TbsBudgetLog(); - budgetLog.setId(a.getId()); - budgetLog.setRollbackFlag(BudgetLogRollbackFlag.State_3); - return budgetLog; - }).collect(Collectors.toList()); - tbsBudgetLogService.updateBatchById(oldLogList4Upd); - for (TbsBudgetLog budgetLog : oldLogList) { - budgetLog.setCreateBy(null); - budgetLog.setCreateTime(null); - budgetLog.setUpdateBy(null); - budgetLog.setUpdateTime(null); - budgetLog.setId(null); - BudgetLogOptFlag optFlag = BudgetLogOptFlag.State_12; - budgetLog.setAmount(TbsBudgetLogBuildUtil.buildAmount(budgetLog.getAmount(),optFlag)); - budgetLog.setOptType(optFlag.getCode()); - } - tbsBudgetLogService.saveBatch(oldLogList); - return R.ok(); - } - }else if ("next".equals(flag)){ - return R.ok(); - } - }else if (result.getStatus()==500){ - return result; - } - return R.error("远程调用失败"); + return tzcPolicyOperationService.commitAffair(affairCommit); +// seeYonService.testConnection(); +// Long policyId = affairCommit.getPolicyId(); +// TzcPolicy tzcPolicy = tzcPolicyService.getById(policyId); +// if(!tzcPolicy.getPolicyStatus().equals(TzcPolicyStatus.Status_1_Checking)){ +// return R.error("费用申请处于未非审批状态!"); +// } +// R result = seeYonService.commonCommit(affairCommit,TbsSeeYonConst.PolicyConf.Code(),tzcPolicy.getSyFormId()); +// boolean isBackCommit = affairCommit.getState()==2; +// if(result.getStatus()==200){ +// // 判断是否含有下个节点 +// String flag = result.getData(); +// //审批中(next)、完成(finish)、拒绝(refused) +// if("finish".equals(flag)){ +// TzcPolicy policy = new TzcPolicy(); +// policy.setId(tzcPolicy.getId()); +// policy.setPolicyStatus(TzcPolicyStatus.Status_2_PassSuccess); +// policy.setPassTime(LocalDateTime.now()); +// tzcPolicyService.updateById(policy); +// //更新活动通过时间 +// TzcPolicyItem policyItem = new TzcPolicyItem(); +// policyItem.setPolicyItemStatus(TzPolicyItemStatus.Status_1_PassSuccess); +// LambdaQueryWrapper itemLqw = new LambdaQueryWrapper<>(); +// itemLqw.eq(TzcPolicyItem::getPolicyId,tzcPolicy.getId()); +// tzcPolicyItemService.update(policyItem,itemLqw); +// return R.ok(); +// }else if ("stop".equals(flag)){ +// if(isBackCommit){ +// TzcPolicy policy = new TzcPolicy(); +// policy.setId(tzcPolicy.getId()); +// policy.setPolicyStatus(TzcPolicyStatus.Status_4_RollBack); +// tzcPolicyService.updateById(policy); +// LambdaQueryWrapper logLqw = new LambdaQueryWrapper<>(); +// logLqw.select(TbsBudgetLog::getId); +// logLqw.eq(TbsBudgetLog::getPolicyId,tzcPolicy.getId()); +// logLqw.eq(TbsBudgetLog::getRollbackFlag, BudgetLogRollbackFlag.State_0); +// List budgetLogList = tbsBudgetLogService.list(logLqw); +// budgetLogList.forEach(a->a.setRollbackFlag(BudgetLogRollbackFlag.State_1)); +// tbsBudgetLogService.updateBatchById(budgetLogList); +// return R.ok(); +// }else { +// TzcPolicy policy = new TzcPolicy(); +// policy.setId(tzcPolicy.getId()); +// policy.setPolicyStatus(TzcPolicyStatus.Status_3_Refuse); +// tzcPolicyService.updateById(policy); +// tzcPolicyService.releaseCost(policy.getId(), 1); +// //移除日志 +// LambdaQueryWrapper logLqw = new LambdaQueryWrapper<>(); +// logLqw.eq(TbsBudgetLog::getPolicyId,tzcPolicy.getId()); +// List oldLogList = tbsBudgetLogService.list(logLqw); +// List oldLogList4Upd = oldLogList.stream().map(a->{ +// TbsBudgetLog budgetLog = new TbsBudgetLog(); +// budgetLog.setId(a.getId()); +// budgetLog.setRollbackFlag(BudgetLogRollbackFlag.State_3); +// return budgetLog; +// }).collect(Collectors.toList()); +// tbsBudgetLogService.updateBatchById(oldLogList4Upd); +// for (TbsBudgetLog budgetLog : oldLogList) { +// budgetLog.setCreateBy(null); +// budgetLog.setCreateTime(null); +// budgetLog.setUpdateBy(null); +// budgetLog.setUpdateTime(null); +// budgetLog.setId(null); +// BudgetLogOptFlag optFlag = BudgetLogOptFlag.State_12; +// budgetLog.setAmount(TbsBudgetLogBuildUtil.buildAmount(budgetLog.getAmount(),optFlag)); +// budgetLog.setOptType(optFlag.getCode()); +// } +// tbsBudgetLogService.saveBatch(oldLogList); +// return R.ok(); +// } +// }else if ("next".equals(flag)){ +// return R.ok(); +// } +// }else if (result.getStatus()==500){ +// return result; +// } +// return R.error("远程调用失败"); } diff --git a/src/main/java/com/qs/serve/modules/tzc/service/impl/TzcPolicyApplicationServiceImpl.java b/src/main/java/com/qs/serve/modules/tzc/service/impl/TzcPolicyApplicationServiceImpl.java index afb9ce95..3fda6a91 100644 --- a/src/main/java/com/qs/serve/modules/tzc/service/impl/TzcPolicyApplicationServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tzc/service/impl/TzcPolicyApplicationServiceImpl.java @@ -197,14 +197,13 @@ public class TzcPolicyApplicationServiceImpl implements TzcPolicyApplicationServ List allBudgetItem = result.getPolicyBudgetMatchList(); tbsBudgetCostItemPolicyService.saveBatch(allBudgetItem); //保存预算使用日志 + List budgetLogList = saveBudgetLog(result, sysUser, tzcPolicy, result.getPolicyBudgetMatchList(),result.getPolicyItemList()); if(tzcPolicy.getPolicyStatus().equals(TzcPolicyStatus.Status_0_UnCommit)){ - List budgetLogList = saveBudgetLog(result, sysUser, tzcPolicy, result.getPolicyBudgetMatchList(),result.getPolicyItemList()); if(CollectionUtil.isNotEmpty(budgetLogList)){ budgetLogService.saveBatch(budgetLogList); } }else { //排除历史记录 - List budgetLogList = saveBudgetLog(result, sysUser, tzcPolicy, result.getPolicyBudgetMatchList(),result.getPolicyItemList()); LambdaQueryWrapper logLqw = new LambdaQueryWrapper<>(); logLqw.eq(TbsBudgetLog::getPolicyId,policyId); logLqw.eq(TbsBudgetLog::getRollbackFlag, BudgetLogRollbackFlag.State_1); diff --git a/src/main/java/com/qs/serve/modules/tzc/service/impl/TzcPolicyOperationServiceImpl.java b/src/main/java/com/qs/serve/modules/tzc/service/impl/TzcPolicyOperationServiceImpl.java new file mode 100644 index 00000000..af74ef2b --- /dev/null +++ b/src/main/java/com/qs/serve/modules/tzc/service/impl/TzcPolicyOperationServiceImpl.java @@ -0,0 +1,134 @@ +package com.qs.serve.modules.tzc.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.qs.serve.common.model.consts.BudgetLogRollbackFlag; +import com.qs.serve.common.model.dto.R; +import com.qs.serve.common.model.enums.BudgetLogOptFlag; +import com.qs.serve.common.util.Assert; +import com.qs.serve.modules.seeyon.service.SeeYonOperationService; +import com.qs.serve.modules.tbs.common.TbsSeeYonConst; +import com.qs.serve.modules.tbs.common.util.TbsBudgetLogBuildUtil; +import com.qs.serve.modules.tbs.entity.TbsBudgetLog; +import com.qs.serve.modules.tbs.entity.bo.TbsAffairCommitBo; +import com.qs.serve.modules.tbs.service.TbsBudgetLogService; +import com.qs.serve.modules.tzc.common.TzPolicyItemStatus; +import com.qs.serve.modules.tzc.common.TzcPolicyStatus; +import com.qs.serve.modules.tzc.entity.TzcPolicy; +import com.qs.serve.modules.tzc.entity.TzcPolicyItem; +import com.qs.serve.modules.tzc.service.TzcPolicyItemService; +import com.qs.serve.modules.tzc.service.TzcPolicyService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author YenHex + * @since 2023/5/25 + */ +@Slf4j +@Service +@AllArgsConstructor +public class TzcPolicyOperationServiceImpl implements SeeYonOperationService { + + private final TzcPolicyService tzcPolicyService; + private final TzcPolicyItemService tzcPolicyItemService; + private final TbsBudgetLogService tbsBudgetLogService; + + @Override + public String getTargetId(TbsAffairCommitBo affairCommit) { + return affairCommit.getPolicyId()+""; + } + + @Override + public String getSyFormIdByTargetInfo(TbsAffairCommitBo affairCommit) { + TzcPolicy tzcPolicy = tzcPolicyService.getById(affairCommit.getPolicyId()); + if(tzcPolicy.getPolicyStatus().equals(TzcPolicyStatus.Status_1_Checking)){ + Assert.throwEx("当前政策状态不可审批"); + } + return tzcPolicy.getSyFormId(); + } + + @Override + public Object doBacked(TbsAffairCommitBo param) { + Long policyId = param.getPolicyId(); + TzcPolicy policy = new TzcPolicy(); + policy.setId(policyId); + policy.setPolicyStatus(TzcPolicyStatus.Status_4_RollBack); + tzcPolicyService.updateById(policy); + LambdaQueryWrapper logLqw = new LambdaQueryWrapper<>(); + logLqw.select(TbsBudgetLog::getId); + logLqw.eq(TbsBudgetLog::getPolicyId,policyId); + logLqw.eq(TbsBudgetLog::getRollbackFlag, BudgetLogRollbackFlag.State_0); + List budgetLogList = tbsBudgetLogService.list(logLqw); + budgetLogList.forEach(a->a.setRollbackFlag(BudgetLogRollbackFlag.State_1)); + tbsBudgetLogService.updateBatchById(budgetLogList); + return R.ok(); + } + + @Override + public Object doFinished(TbsAffairCommitBo param) { + String policyId = this.getTargetId(param); + TzcPolicy tzcPolicy = tzcPolicyService.getById(policyId); + TzcPolicy policy = new TzcPolicy(); + policy.setId(tzcPolicy.getId()); + policy.setPolicyStatus(TzcPolicyStatus.Status_2_PassSuccess); + policy.setPassTime(LocalDateTime.now()); + tzcPolicyService.updateById(policy); + //更新活动通过时间 + TzcPolicyItem policyItem = new TzcPolicyItem(); + policyItem.setPolicyItemStatus(TzPolicyItemStatus.Status_1_PassSuccess); + LambdaQueryWrapper itemLqw = new LambdaQueryWrapper<>(); + itemLqw.eq(TzcPolicyItem::getPolicyId,tzcPolicy.getId()); + tzcPolicyItemService.update(policyItem,itemLqw); + return R.ok(); + } + + @Override + public Object doRefuse(TbsAffairCommitBo param) { + Long policyId = param.getPolicyId(); + TzcPolicy policy = new TzcPolicy(); + policy.setId(policyId); + policy.setPolicyStatus(TzcPolicyStatus.Status_3_Refuse); + tzcPolicyService.updateById(policy); + tzcPolicyService.releaseCost(policy.getId(), 1); + //移除日志 + LambdaQueryWrapper logLqw = new LambdaQueryWrapper<>(); + logLqw.eq(TbsBudgetLog::getPolicyId,policyId); + logLqw.eq(TbsBudgetLog::getRollbackFlag,BudgetLogRollbackFlag.State_0); + List oldLogList = tbsBudgetLogService.list(logLqw); + List oldLogList4Upd = oldLogList.stream().map(a->{ + TbsBudgetLog budgetLog = new TbsBudgetLog(); + budgetLog.setId(a.getId()); + budgetLog.setRollbackFlag(BudgetLogRollbackFlag.State_3); + return budgetLog; + }).collect(Collectors.toList()); + tbsBudgetLogService.updateBatchById(oldLogList4Upd); + for (TbsBudgetLog budgetLog : oldLogList) { + budgetLog.setCreateBy(null); + budgetLog.setCreateTime(null); + budgetLog.setUpdateBy(null); + budgetLog.setUpdateTime(null); + budgetLog.setId(null); + BudgetLogOptFlag optFlag = BudgetLogOptFlag.State_14; + budgetLog.setAmount(TbsBudgetLogBuildUtil.buildAmount(budgetLog.getAmount(),optFlag)); + budgetLog.setOptType(optFlag.getCode()); + } + tbsBudgetLogService.saveBatch(oldLogList); + return null; + } + + @Override + public Object doNext(TbsAffairCommitBo param) { + return null; + } + + @Override + public String getTemplateCode() { + return TbsSeeYonConst.PolicyConf.Code(); + } + +}