24282 2 жил өмнө
parent
commit
0b2fe19f52

+ 52 - 43
hx-account/src/main/java/com/fjhx/account/flow/AccountRequestFundsFlow.java

@@ -1,6 +1,5 @@
 package com.fjhx.account.flow;
 
-import cn.hutool.extra.spring.SpringUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -9,7 +8,6 @@ import com.fjhx.account.entity.account.dto.AccountPaymentDto;
 import com.fjhx.account.entity.account.dto.AccountRequestFundsDto;
 import com.fjhx.account.entity.account.enums.AccountRequestFundsStatusEnum;
 import com.fjhx.account.entity.account.enums.PaymentStatusEnum;
-import com.fjhx.account.entity.account.enums.PaymentTypeEnum;
 import com.fjhx.account.entity.account.po.AccountRequestFunds;
 import com.fjhx.account.entity.account.po.AccountRequestFundsDetail;
 import com.fjhx.account.service.account.AccountPaymentService;
@@ -35,9 +33,16 @@ import java.util.List;
 @DS(SourceConstant.ACCOUNT)
 @Component
 public class AccountRequestFundsFlow extends FlowDelegate {
+
     @Autowired
     private AccountPaymentService accountPaymentService;
 
+    @Autowired
+    private AccountRequestFundsService accountRequestFundsService;
+
+    @Autowired
+    private AccountRequestFundsDetailService accountRequestFundsDetailService;
+
     @Override
     public String getFlowKey() {
         return "account_request_funds_flow";
@@ -53,24 +58,24 @@ public class AccountRequestFundsFlow extends FlowDelegate {
      */
     @Override
     public Long start(Long flowId, JSONObject submitData) {
-//        DynamicDataSourceContextHolder.push(SourceConstant.ACCOUNT);
-        AccountRequestFundsService accountRequestFundsService = SpringUtil.getBean(AccountRequestFundsService.class);
-        AccountRequestFundsDetailService accountRequestFundsDetailService = SpringUtil.getBean(AccountRequestFundsDetailService.class);
+
+        // 获取提交数据
         AccountRequestFundsDto accountRequestFundsDto = submitData.toJavaObject(AccountRequestFundsDto.class);
+
+        // 添加请款表的信息
         accountRequestFundsDto.setStatus(AccountRequestFundsStatusEnum.UNDER_REVIEW.getKey());
-        //添加请款表的信息
         accountRequestFundsService.save(accountRequestFundsDto);
 
-        //获取请款详情表的详细信息
+        // 添加请款详情表的信息
         List<AccountRequestFundsDetail> accountRequestFundsDetailList = accountRequestFundsDto.getAccountRequestFundsDetailList();
         if (CollectionUtils.isNotEmpty(accountRequestFundsDetailList)) {
-            accountRequestFundsDetailList.forEach(accountRequestFundsDetail -> accountRequestFundsDetail
-                    .setAccountRequestFundsId(accountRequestFundsDto.getId()));
-            //添加请款详情表的信息
+            accountRequestFundsDetailList.forEach(item -> item.setAccountRequestFundsId(accountRequestFundsDto.getId()));
             accountRequestFundsDetailService.saveBatch(accountRequestFundsDetailList);
         }
-        //添加附件信息
+
+        // 添加附件信息
         ObsFileUtil.saveFile(accountRequestFundsDto.getFileList(), accountRequestFundsDto.getId());
+
         return accountRequestFundsDto.getId();
     }
 
@@ -83,59 +88,63 @@ public class AccountRequestFundsFlow extends FlowDelegate {
      */
     @Override
     public void end(Long flowId, Long businessId, JSONObject submitData) {
-        AccountRequestFundsService accountRequestFundsService = SpringUtil.getBean(AccountRequestFundsService.class);
-        //通过业务ID查询申购数据
+        // 通过业务ID查询申购数据
         AccountRequestFunds accountRequestFunds = accountRequestFundsService.getById(businessId);
-        AccountRequestFundsDto accountRequestFundsDto = submitData.toJavaObject(AccountRequestFundsDto.class);
         if (ObjectUtils.isEmpty(accountRequestFunds)) {
             throw new ServiceException("请款表的数据不存在");
         }
-        //修改申购状态为审批通过
+
+        // 修改申购状态为审批通过
         accountRequestFunds.setStatus(AccountRequestFundsStatusEnum.PASS.getKey());
-        //修改核销状态以及预支单核销状态为已核销
-        if ("3".equals(accountRequestFundsDto.getType())) {
+
+        // 修改核销状态以及预支单核销状态为已核销
+        if ("3".equals(accountRequestFunds.getType())) {
             accountRequestFunds.setWriteOffStatus(1);
-            //修改预支单核销状态
+            // 修改预支单核销状态
             AccountRequestFunds advance = accountRequestFundsService.getById(accountRequestFunds.getAdvanceId());
-            Assert.notEmpty(advance,"查询不到关联预支单信息");
+            Assert.notEmpty(advance, "查询不到关联预支单信息");
             advance.setWriteOffStatus(1);
             accountRequestFundsService.updateById(advance);
         }
+
         accountRequestFundsService.updateById(accountRequestFunds);
-        //添加打款的数据
-        addPayment(accountRequestFundsDto);
+
+        // 添加打款的数据
+        addPayment(accountRequestFunds);
+
     }
 
     /**
      * 添加打款表的数据
      */
-    private void addPayment(AccountRequestFundsDto accountRequestFundsDto) {
+    private void addPayment(AccountRequestFunds accountRequestFunds) {
         AccountPaymentDto accountPayment = new AccountPaymentDto();
-        accountPayment.setBusinessId(accountRequestFundsDto.getId());
-        accountPayment.setType(PaymentTypeEnum.UNDER_REVIEW.getKey());
+
+        accountPayment.setDepartmentId(accountRequestFunds.getDepartmentId());
+        accountPayment.setCorporationId(accountRequestFunds.getCorporationId());
+        accountPayment.setBusinessId(accountRequestFunds.getId());
+        accountPayment.setPaymentTime(accountRequestFunds.getPaymentTime());
+        accountPayment.setCurrency(accountRequestFunds.getCurrency());
         accountPayment.setStatus(PaymentStatusEnum.UNDER_REVIEW.getKey());
-        accountPayment.setPaymentTime(accountPayment.getPaymentTime());
-        accountPayment.setPaymentRemark(accountRequestFundsDto.getPaymentRemarks());
-
-        accountPayment.setDepartmentId(accountRequestFundsDto.getDepartmentId());
-        accountPayment.setCorporationId(accountRequestFundsDto.getCorporationId());
-        accountPayment.setBusinessId(accountPayment.getId());
-        accountPayment.setPaymentMethod(accountRequestFundsDto.getPaymentMethod());
-        accountPayment.setIncomeAmount(accountRequestFundsDto.getTotal());
-        accountPayment.setAmount(accountRequestFundsDto.getTotal());
-        accountPayment.setName(accountRequestFundsDto.getName());
-        accountPayment.setBusinessManagementId(accountRequestFundsDto.getAccountManagementId());
-        accountPayment.setOpeningBank(accountRequestFundsDto.getOpeningBank());
-        accountPayment.setCurrency(accountPayment.getCurrency());
-        accountPayment.setAccountOpening(accountRequestFundsDto.getAccountOpening());
-        accountPayment.setInterbankNumber(accountPayment.getInterbankNumber());
-
-        //如果是核销 核销数据审批通过后,根据“核销总额 - 预支总额”生成“待打款”数据
-        if ("3".equals(accountRequestFundsDto.getType())) {
-            BigDecimal subtract = accountRequestFundsDto.getTotal().subtract(accountRequestFundsDto.getAdvanceAmounts());
+        accountPayment.setType(accountRequestFunds.getType());
+        accountPayment.setPaymentRemark(accountRequestFunds.getPaymentRemarks());
+        accountPayment.setPaymentMethod(accountRequestFunds.getPaymentMethod());
+        accountPayment.setIncomeAmount(accountRequestFunds.getTotal());
+        accountPayment.setName(accountRequestFunds.getName());
+        accountPayment.setBusinessManagementId(accountRequestFunds.getAccountManagementId());
+        accountPayment.setOpeningBank(accountRequestFunds.getOpeningBank());
+        accountPayment.setAccountOpening(accountRequestFunds.getAccountOpening());
+        accountPayment.setInterbankNumber(accountRequestFunds.getInterbankNumber());
+
+        // 如果是核销 核销数据审批通过后,根据“核销总额 - 预支总额”生成“待打款”数据
+        if ("3".equals(accountRequestFunds.getType())) {
+            BigDecimal subtract = accountRequestFunds.getTotal().subtract(accountRequestFunds.getAdvanceAmounts());
             accountPayment.setAmount(subtract);
+        } else {
+            accountPayment.setAmount(accountRequestFunds.getTotal());
         }
 
         accountPaymentService.save(accountPayment);
     }
+
 }

+ 46 - 50
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountPaymentServiceImpl.java

@@ -22,7 +22,6 @@ import com.fjhx.account.service.account.AccountPaymentService;
 import com.fjhx.account.service.account.AccountRemainderService;
 import com.fjhx.account.service.account.AccountRunningWaterService;
 import com.fjhx.common.constant.SourceConstant;
-import com.fjhx.common.entity.corporation.po.Corporation;
 import com.fjhx.common.service.corporation.CorporationService;
 import com.fjhx.file.utils.ObsFileUtil;
 import com.ruoyi.common.core.domain.BasePo;
@@ -35,6 +34,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 
@@ -65,43 +65,37 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
 
     @Override
     public Page<AccountPaymentVo> getPage(AccountRequestFundsSelectDto dto) {
-        QueryWrapper<Object> wrapper = Wrappers.query();
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getPaymentStatus()),"ap.status",dto.getPaymentStatus());
-        wrapper.like(ObjectUtil.isNotEmpty(dto.getKeyword()),"ap.payment_remark",dto.getKeyword());
-        wrapper.orderByDesc("ap.status","ap.payment_time","ap.create_time");
-        Page<AccountPaymentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
-
-        //切换数据源
-        DynamicDataSourceContextHolder.push(SourceConstant.COMMON);
-        //查询公司名称信息
-        List<Corporation> corporationList = corporationService.list();
-        Map<Long, List<Corporation>> corporationMap = corporationList.stream().collect(Collectors.groupingBy(Corporation::getId));
-        DynamicDataSourceContextHolder.poll();
-
-
-        //切换数据源
-        DynamicDataSourceContextHolder.push(SourceConstant.BASE);
-        //查询部门信息
-        List<SysDept> sysDeptList = sysDeptService.list();
-        Map<Long, List<SysDept>> sysDeptMap = sysDeptList.stream().collect(Collectors.groupingBy(SysDept::getDeptId));
 
+        QueryWrapper<Object> wrapper = Wrappers.query();
+        wrapper.eq(ObjectUtil.isNotEmpty(dto.getPaymentStatus()), "ap.status", dto.getPaymentStatus());
+        wrapper.like(ObjectUtil.isNotEmpty(dto.getKeyword()), "ap.payment_remark", dto.getKeyword());
+        wrapper.orderByDesc("ap.status", "ap.create_time");
 
-        //赋值部门名称、归属公司名称
+        Page<AccountPaymentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         List<AccountPaymentVo> records = page.getRecords();
-        for (AccountPaymentVo record : records) {
-            List<SysDept> sysDepts = sysDeptMap.get(record.getDepartmentId());
-            if (ObjectUtil.isNotEmpty(sysDepts)){
-                record.setDeptName(sysDepts.get(0).getDeptName());
-            }
-            List<Corporation> corporations = corporationMap.get(record.getCorporationId());
-            if (ObjectUtil.isNotEmpty(corporations)){
-                record.setCorporationName(corporations.get(0).getName());
-            }
-
+        if (records.size() == 0) {
+            return page;
         }
 
+        // 赋值公司名称信息
+        corporationService.attributeAssign(records, AccountPaymentVo::getCorporationId, (item, corporation) -> {
+            item.setCorporationName(corporation.getName());
+        });
+
         // 赋值用户名称
-        UserUtil.assignmentNickName(records, BasePo::getCreateUser,AccountPaymentVo::setUserName);
+        UserUtil.assignmentNickName(records, BasePo::getCreateUser, AccountPaymentVo::setUserName);
+
+        // 赋值部门名称
+        DynamicDataSourceContextHolder.push(SourceConstant.BASE);
+        List<Long> deptIdList = records.stream()
+                .map(AccountPaymentVo::getDepartmentId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+        List<SysDept> sysDeptList = sysDeptService.listByIds(deptIdList);
+        Map<Long, String> deptMap = sysDeptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
+        records.forEach(item -> item.setDeptName(deptMap.get(item.getDepartmentId())));
+        DynamicDataSourceContextHolder.poll();
 
         return page;
     }
@@ -141,35 +135,37 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
     @Override
     @DSTransactional
     public void add(AccountPaymentDto accountPaymentDto) {
+
         AccountRemainder accountRemainder = accountRemainderService.getOne(Wrappers.<AccountRemainder>lambdaQuery()
                 .eq(AccountRemainder::getAccountManagementId, accountPaymentDto.getAccountManagementId())
                 .eq(AccountRemainder::getCurrency, accountPaymentDto.getCurrency()));
-        //如果不存在这条数据则返回账户余额不足
-        if (ObjectUtil.isEmpty(accountRemainder)){
+
+        // 如果不存在这条数据则返回账户余额不足
+        if (ObjectUtil.isEmpty(accountRemainder)) {
             throw new ServiceException("账户余额不足");
         }
-        //如果余额小于付款金额则返回账户余额不足
-        if (accountRemainder.getRemainder().compareTo(accountPaymentDto.getAmount()) == -1){
+
+        // 如果余额小于付款金额则返回账户余额不足
+        if (accountRemainder.getRemainder().compareTo(accountPaymentDto.getAmount()) < 0) {
             throw new ServiceException("账户余额不足");
         }
-        //TODO 只要发起就是已打款(后期可能要修改)
-        accountRemainder.setStatus(PaymentStatusEnum.REJECT.getKey());
-        if (ObjectUtil.isEmpty(accountPaymentDto.getId())){
-            this.save(accountPaymentDto);
-        }else {
-            this.updateById(accountPaymentDto);
-        }
 
-        //添加附件信息
-        ObsFileUtil.saveFile(accountPaymentDto.getFileList(),accountPaymentDto.getId());
+        // TODO 只要发起就是已打款(后期可能要修改)
+        accountPaymentDto.setStatus(PaymentStatusEnum.REJECT.getKey());
+        updateById(accountPaymentDto);
+
+        // 赋值变更金额
         accountRemainder.setChangeRemainder(accountPaymentDto.getAmount());
-        //修改账户-余额表的中余额
-        accountRemainder.setRemainder( accountRemainder.getRemainder().subtract(accountPaymentDto.getAmount()));
-        //打款的交易状态都是支出
+        // 修改账户-余额表的中余额
+        accountRemainder.setRemainder(accountRemainder.getRemainder().subtract(accountPaymentDto.getAmount()));
+        // 打款的交易状态都是支出
         accountRemainder.setStatus("20");
-        accountRemainderService.add(accountRemainder);
+        accountRemainderService.updateById(accountRemainder);
+
+        // 添加附件信息
+        ObsFileUtil.saveFile(accountPaymentDto.getFileList(), accountPaymentDto.getId());
 
-        //添加资金流水表的数据
+        // 添加资金流水表的数据
         addAccountRunningWater(accountPaymentDto);
     }
 

+ 5 - 4
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountRequestFundsServiceImpl.java

@@ -71,7 +71,10 @@ public class AccountRequestFundsServiceImpl extends ServiceImpl<AccountRequestFu
         wrapper.eq(ObjectUtil.isNotEmpty(dto.getPaymentStatus()), "ap.status", dto.getPaymentStatus());
         wrapper.like(ObjectUtil.isNotEmpty(dto.getKeyword()), "arf.payment_remarks", dto.getKeyword());
         wrapper.eq(ObjectUtil.isNotEmpty(dto.getWriteOffStatus()), "arf.write_off_status", dto.getWriteOffStatus());
-        wrapper.orderByDesc("ap.status", "arf.payment_time", "arf.create_time");
+        // 请款审批状态 按 审批中、已通过、未通过 排序
+        wrapper.orderByAsc("case arf.status when 10 then 1 when 30 then 2 else 3 END");
+        // 同状态按发起时间倒序排序
+        wrapper.orderByDesc("arf.create_time");
         Page<AccountRequestFundsVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
 
         List<AccountRequestFundsVo> records = page.getRecords();
@@ -96,9 +99,7 @@ public class AccountRequestFundsServiceImpl extends ServiceImpl<AccountRequestFu
         if (ObjectUtil.isNotEmpty(accountRequestFundsIds)) {
             Map<Long, Long> arfMap = flowExampleService.mapKV(FlowExample::getBusinessId, FlowExample::getId,
                     q -> q.in(FlowExample::getBusinessId, accountRequestFundsIds));
-            for (AccountRequestFundsVo record : records) {
-                record.setFlowInfoId(arfMap.get(record.getId()));
-            }
+            records.forEach(item -> item.setFlowInfoId(arfMap.get(item.getId())));
         }
 
         // 查询部门id列表

+ 2 - 1
hx-item/src/main/resources/mapper/product/ProductInfoMapper.xml

@@ -21,7 +21,8 @@
             pi.victoriatourist_json,
             pi.bar_code,
             IF(DATEDIFF(now(),pi.create_time)> json_unquote( victoriatourist_json -> '$.growUpDay' ),3,IF( DATEDIFF(now(),pi.create_time)> json_unquote( victoriatourist_json -> '$.newProductsDay' ), 2, 1 )) AS lifeCycle,
-            pi.unit_price
+            pi.unit_price,
+            pi.standard_json
         FROM
             product_info pi
             ${ew.customSqlSegment}