huangpeng пре 4 месеци
родитељ
комит
c89c50e1dd
15 измењених фајлова са 393 додато и 51 уклоњено
  1. 3 0
      zhsw-common/src/main/java/com/rongwei/zhsw/system/dao/SwBillManagementUnpaidDao.java
  2. 4 0
      zhsw-common/src/main/java/com/rongwei/zhsw/system/dao/SwUserManagementDao.java
  3. 10 0
      zhsw-common/src/main/java/com/rongwei/zhsw/system/service/SwBillManagementUnpaidService.java
  4. 5 0
      zhsw-common/src/main/java/com/rongwei/zhsw/system/service/SwBillingRecordService.java
  5. 5 0
      zhsw-common/src/main/java/com/rongwei/zhsw/system/service/SwUserManagementService.java
  6. 219 9
      zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwBillManagementUnpaidServiceImpl.java
  7. 20 11
      zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwBillingRecordServiceImpl.java
  8. 15 8
      zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwRefundRequestRecordServiceImpl.java
  9. 7 0
      zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwUserManagementServiceImpl.java
  10. 14 2
      zhsw-common/src/main/java/com/rongwei/zhsw/system/utils/SaveConstans.java
  11. 7 10
      zhsw-common/src/main/resources/mybatis/zhsw/SwBillManagementUnpaidDao.xml
  12. 10 0
      zhsw-common/src/main/resources/mybatis/zhsw/SwUserManagementDao.xml
  13. 7 7
      zhsw-entity/src/main/java/com/rongwe/zhsw/system/domain/SwBillManagementUnpaidDo.java
  14. 49 0
      zhsw-entity/src/main/java/com/rongwe/zhsw/system/dto/TransferAccountDo.java
  15. 18 4
      zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/SwBillManagementUnpaidController.java

+ 3 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/dao/SwBillManagementUnpaidDao.java

@@ -3,6 +3,7 @@ package com.rongwei.zhsw.system.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.rongwe.zhsw.system.domain.SwBillManagementUnpaidDo;
+import com.rongwe.zhsw.system.dto.TransferAccountDo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -21,5 +22,7 @@ public interface SwBillManagementUnpaidDao extends BaseMapper<SwBillManagementUn
 
 
     int deleteByIds(@Param("idList") List<String> idList);
+
+
 }
 

+ 4 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/dao/SwUserManagementDao.java

@@ -3,6 +3,7 @@ package com.rongwei.zhsw.system.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.rongwe.zhsw.system.domain.SwUserManagementDo;
+import com.rongwe.zhsw.system.dto.TransferAccountDo;
 import com.rongwe.zhsw.system.vo.SwUserManagementVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -33,6 +34,9 @@ public interface SwUserManagementDao extends BaseMapper<SwUserManagementDo> {
     void setDefaultAccount1(@Param("dsKey") String dsKey,@Param("openId") String openId);
 
     void setDefaultAccount0(@Param("dsKey") String dsKey,@Param("openId") String openId,@Param("userAccount") String userAccount);
+
+    void batchUpdateUserBalances(@Param("list") List<TransferAccountDo.UpdateUserBalance> list);
+
 }
 
 

+ 10 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/SwBillManagementUnpaidService.java

@@ -3,8 +3,13 @@ package com.rongwei.zhsw.system.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.rongwe.zhsw.system.domain.SwBillManagementUnpaidDo;
 import com.rongwe.zhsw.system.dto.MeterReadingCorrectionDTO;
+import com.rongwe.zhsw.system.dto.TransferAccountDo;
 import com.rongwei.rwcommon.base.R;
 
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
 /**
  * 账单管理(按年分表)(预收,未缴)(SwBillManagementUnpaid)表服务接口
  *
@@ -14,4 +19,9 @@ import com.rongwei.rwcommon.base.R;
 public interface SwBillManagementUnpaidService extends IService<SwBillManagementUnpaidDo> {
 
     R meterReadingCorrection(MeterReadingCorrectionDTO dto);
+
+    R transferAccount(Map<String, Object> map) throws Exception;
+
+
+    void saveProcessedData(TransferAccountDo transferAccountDo);
 }

+ 5 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/SwBillingRecordService.java

@@ -2,10 +2,14 @@ package com.rongwei.zhsw.system.service;
 
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.rongwe.zhsw.system.domain.SwBillManagementPaidDo;
 import com.rongwe.zhsw.system.domain.SwBillingRecordDo;
+import com.rongwe.zhsw.system.domain.SwUserManagementDo;
 import com.rongwe.zhsw.system.dto.PaymentRequestDTO;
 import com.rongwei.rwcommon.base.R;
 
+import java.util.List;
+
 /**
  * 缴费记录(SwBillingRecord)表服务接口
  *
@@ -17,4 +21,5 @@ public interface SwBillingRecordService extends IService<SwBillingRecordDo> {
 
     R windowPayment(PaymentRequestDTO paymentRequestDTO) throws Exception;
 
+    void saveProcessedData(SwBillingRecordDo add, SwUserManagementDo user, List<SwBillManagementPaidDo> bills, List<String> ids);
 }

+ 5 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/SwUserManagementService.java

@@ -3,8 +3,10 @@ package com.rongwei.zhsw.system.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.rongwe.zhsw.system.domain.SwUserManagementDo;
+import com.rongwe.zhsw.system.dto.TransferAccountDo;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
 * @author libai
@@ -14,4 +16,7 @@ import java.math.BigDecimal;
 public interface SwUserManagementService extends IService<SwUserManagementDo> {
 
     void balanceAdd(String id, BigDecimal balanceAdd);
+
+    void batchUpdateUserBalances(List<TransferAccountDo.UpdateUserBalance> list);
+
 }

+ 219 - 9
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwBillManagementUnpaidServiceImpl.java

@@ -3,29 +3,32 @@ package com.rongwei.zhsw.system.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.rongwe.zhsw.system.domain.SwBillManagementUnpaidDo;
-import com.rongwe.zhsw.system.domain.SwMeterReadingCorrectionDo;
-import com.rongwe.zhsw.system.domain.SwUserManagementDo;
-import com.rongwe.zhsw.system.domain.SwWaterUsageEntryDo;
+import com.rongwe.zhsw.system.domain.*;
 import com.rongwe.zhsw.system.dto.MeterReadingCorrectionDTO;
+import com.rongwe.zhsw.system.dto.TransferAccountDo;
 import com.rongwei.rwadmincommon.system.vo.SysUserVo;
 import com.rongwei.rwcommon.base.BaseDo;
 import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.zhsw.system.dao.SwBillManagementUnpaidDao;
-import com.rongwei.zhsw.system.service.SwBillManagementUnpaidService;
-import com.rongwei.zhsw.system.service.SwUserManagementService;
-import com.rongwei.zhsw.system.service.SwMeterReadingCorrectionService;
-import com.rongwei.zhsw.system.service.SwWaterUsageEntryService;
+import com.rongwei.zhsw.system.service.*;
 import com.rongwei.zhsw.system.utils.ZHSWCommonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
-import java.util.Date;
+import java.util.*;
+import java.util.stream.Collectors;
 
+import static com.rongwei.zhsw.system.utils.SaveConstans.billInfo.*;
+import static com.rongwei.zhsw.system.utils.SaveConstans.billReccord.DATASOURCEBALANCEDEDUCTION;
 import static com.rongwei.zhsw.system.utils.SaveConstans.billReccord.HAVEREVISEDSTATUS;
+import static sun.security.krb5.internal.KDCOptions.with;
 
 /**
  * 账单管理(按年分表)(预收,未缴)(SwBillManagementUnpaid)表服务实现类
@@ -48,9 +51,19 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
     @Autowired
     SwBillManagementUnpaidService swBillManagementUnpaidService;
 
+    @Autowired
+    SwBillManagementPaidService swBillManagementPaidService;
+
     @Autowired
     SwMeterReadingCorrectionService swMeterReadingCorrectionService;
 
+    @Autowired
+    private SwBillingRecordServiceImpl swBillingRecordService;
+
+
+    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
+
+
     /**
      * 抄表修正
      * 1、将 对应抄表记录更新,本次抄表数 更新
@@ -126,5 +139,202 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
         return R.ok();
     }
 
+    /**
+     * 转正式账单
+     * @param map
+     * @return
+     */
+    @Override
+    public R transferAccount(Map<String, Object> map) throws Exception {
+
+        //获取账单数据 已根据户号 分组 创建时间正序
+        Map<String, List<SwBillManagementUnpaidDo>> billGroups = getGroupedBills(map);
+
+        // 获取用户信息映射(按户号分组)
+        Map<String, List<SwUserManagementDo>> userGroups = getUserGroups(billGroups.keySet());
+
+        TransferAccountDo transferAccountDo = new TransferAccountDo();
+
+        // 处理每个户号的账单数据
+        billGroups.keySet().forEach(key -> processUserBills(billGroups.get(key), userGroups.get(key).get(0), transferAccountDo));
+
+        // 保存处理结果
+        try {
+            swBillManagementUnpaidService.saveProcessedData(transferAccountDo);
+        }catch (Exception e){
+            log.error("转正式账单数据保存失败 {}",e.getMessage());
+            throw new Exception(e.getMessage());
+        }
+
+        return R.ok();
+    }
+
+    private Map<String, List<SwUserManagementDo>> getUserGroups(Set<String> usernumbers) {
+        return  swUserManagementService.list(new LambdaQueryWrapper<SwUserManagementDo>()
+                .eq(SwUserManagementDo::getDeleted, "0")
+                .in(SwUserManagementDo::getUsernumber, usernumbers)).stream().collect(Collectors.groupingBy(SwUserManagementDo::getUsernumber));
+    }
+
+
+    private Map<String, List<SwBillManagementUnpaidDo>> getGroupedBills(Map<String, Object> map) {
+
+        List<SwBillManagementUnpaidDo> unpaidDoList = Collections.emptyList();
+
+        String type = map.getOrDefault("type", "").toString();
+        //全选
+        if ("all".equals(type)) {
+
+            // 全选 预收且未 删除 的账单
+            unpaidDoList = swBillManagementUnpaidService.list(new LambdaQueryWrapper<SwBillManagementUnpaidDo>()
+                    .eq(SwBillManagementUnpaidDo::getDeleted, "0")
+                    .eq(SwBillManagementUnpaidDo::getStatus, PRERECEIVEDSTATE));
+
+        }else if ("select".equals(type)) {
+            //根据ids 选择
+            List<String> ids = (List<String>) map.get("ids");
+            if (ids.isEmpty()){
+                throw new CustomException("参数 ids 异常");
+            }
+            unpaidDoList = (List<SwBillManagementUnpaidDo>) swBillManagementUnpaidService.listByIds(ids);
+
+        }else {
+            throw new CustomException("无效的查询类型");
+        }
+
+        if (unpaidDoList.isEmpty()){
+            throw new CustomException("预收账单数量为空!");
+        }
+
+        //1. 预收账单根据户号分组 创建时间正序
+        return unpaidDoList.stream()
+                .collect(Collectors.groupingBy(SwBillManagementUnpaidDo::getUsernumber,
+                        Collectors.collectingAndThen(
+                                Collectors.toList(), list -> list.stream()
+                                        .sorted(Comparator.comparing(SwBillManagementUnpaidDo::getCreatedate))
+                                        .collect(Collectors.toList())
+                        )
+                ));
+
+    }
+
+
+    /**
+
+
 
+    /**
+     * //计算用户余额是否充足 直接生成缴费记录
+     *
+     * @param swBillManagementUnpaidDos
+     * @param user
+
+     */
+    private void processUserBills(List<SwBillManagementUnpaidDo> swBillManagementUnpaidDos, SwUserManagementDo user,
+                                  TransferAccountDo transferAccountDo ) {
+
+        BigDecimal billAmount =BigDecimal.ZERO;
+        List<SwBillManagementUnpaidDo> unpaidDos  = new ArrayList<>();
+        SwBillManagementPaidDo paid;
+        String paymentBatchId = SecurityUtil.getUUID(); // 批次唯一ID
+        SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
+        HashMap<String, BigDecimal> map = new HashMap<>();
+        //是否累加值超出余额
+        Boolean excessBalance =false;
+
+
+        for (SwBillManagementUnpaidDo unpaidDo:swBillManagementUnpaidDos){
+            //当累计的账单的 【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 <= 账户余额,生成计费记录
+            billAmount = billAmount.add(unpaidDo.getOughttohavepaid()).subtract(unpaidDo.getFeewaiver()).add(unpaidDo.getLatefees());
+
+            if (excessBalance){
+                transferAccountDo.getOfficeIds().add(unpaidDo.getId());
+                break;
+            }
+
+            if (billAmount.compareTo(user.getAccountbalance()) <= 0){
+                //转正式账单后 生成缴费记录,生成 已缴费账单,删除待缴费记录,更新用户余额
+
+                // 记录待删除ID
+                transferAccountDo.getDelUnpaidIds().add(unpaidDo.getId());
+
+                //2.生成已缴费记录
+                paid = new SwBillManagementPaidDo();
+                BeanUtils.copyProperties(unpaidDo, paid);
+                paid.setStatus(PAIDINSTATUS);
+                paid .setPaymentrecordid(paymentBatchId);
+                ZHSWCommonUtils.initModelGeneralParameters(paid,null);
+                transferAccountDo.getPaidDoList().add(paid);
+
+                //整合要生成缴费记录的预收账单
+                unpaidDos.add(unpaidDo);
+
+
+            }else{
+                excessBalance =true;
+                // 超出余额部分标记为正式账单
+                transferAccountDo.getOfficeIds().add(unpaidDo.getId());
+            }
+        }
+
+        if (!unpaidDos.isEmpty()){
+            //生成缴费记录
+            SwBillingRecordDo record = swBillingRecordService.buildBaseBillingRecord(currentUser, user);
+            record.setId(paymentBatchId);
+            record.setDatasource(DATASOURCEBALANCEDEDUCTION);
+            record.setPaidin(BigDecimal.ZERO);
+
+            // 计算费用
+            swBillingRecordService.calculateFees(unpaidDos, record, user);
+            transferAccountDo.getRecordDoList().add(record);
+
+            //更新 用户余额记录
+            TransferAccountDo.UpdateUserBalance updateUserBalance = new TransferAccountDo.UpdateUserBalance();
+            updateUserBalance.setId(user.getId());
+            updateUserBalance.setBalanceAdd(record.getAfterpaymentbalance().subtract(user.getAccountbalance()));
+            transferAccountDo.getUserBalanceList().add(updateUserBalance);
+
+        }
+
+    }
+
+    /**
+     * 保存数据
+     * @param transferAccountDo
+     */
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void saveProcessedData(TransferAccountDo transferAccountDo) {
+
+        //转正式账单生成
+        if(!transferAccountDo.getOfficeIds().isEmpty()){
+            swBillManagementUnpaidService.update(new LambdaUpdateWrapper<SwBillManagementUnpaidDo>()
+                    .in(SwBillManagementUnpaidDo::getId,transferAccountDo.getOfficeIds())
+                    .set(SwBillManagementUnpaidDo::getStatus,PENDINGSTATUS)
+            );
+        }
+
+
+        //删除 待收账单数据
+        if (!transferAccountDo.getDelUnpaidIds().isEmpty()) {
+            swBillingRecordService.deleteUnpaidBills(transferAccountDo.getDelUnpaidIds());
+
+        }
+
+        //生成已缴费账单
+        if (!transferAccountDo.getPaidDoList().isEmpty()){
+            swBillManagementPaidService.saveBatch(transferAccountDo.getPaidDoList(),200);
+        }
+
+        // 更新 用户余额
+        if (!transferAccountDo.getUserBalanceList().isEmpty()) {
+            swUserManagementService.batchUpdateUserBalances(transferAccountDo.getUserBalanceList());
+        }
+
+        //生成缴费
+        if (!transferAccountDo.getRecordDoList().isEmpty()){
+            swBillingRecordService.saveBatch(transferAccountDo.getRecordDoList(),200);
+        }
+
+
+    }
 }

+ 20 - 11
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwBillingRecordServiceImpl.java

@@ -68,7 +68,6 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
      * @throws Exception
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public R windowPayment(PaymentRequestDTO paymentRequestDTO) throws Exception {
 
         log.info("窗口缴费开始");
@@ -96,7 +95,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
      * 删除 待收账单数据
      * @param ids
      */
-    private void deleteUnpaidBills(List<String> ids) {
+    public void deleteUnpaidBills(List<String> ids) {
         swBillManagementUnpaidDao.deleteByIds(ids);
     }
 
@@ -116,14 +115,13 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
     }
 
     // 提取公共字段设置
-    private SwBillingRecordDo buildBaseBillingRecord( SysUserVo currentUser, SwUserManagementDo user) {
+    public SwBillingRecordDo buildBaseBillingRecord( SysUserVo currentUser, SwUserManagementDo user) {
         SwBillingRecordDo record = new SwBillingRecordDo();
 
         //缴费编号
         generateBillingNumber(record);
 
-        return record.setId(SecurityUtil.getUUID())
-                .setChargedate(new Date())
+        return record.setChargedate(new Date())
                 .setPayfeesstatus(PAIDSTATUS)
                 .setYear(Calendar.getInstance().get(Calendar.YEAR))
                 .setUsername(user.getUsername())
@@ -153,7 +151,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
      * @param paymentRequestDTO
      * @param unpaidBills
      */
-    private void addNewBillRecord(PaymentRequestDTO paymentRequestDTO, List<SwBillManagementUnpaidDo> list) {
+    private void addNewBillRecord(PaymentRequestDTO paymentRequestDTO, List<SwBillManagementUnpaidDo> list) throws Exception {
 
         SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
 
@@ -167,8 +165,10 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
             throw new CustomException("户号不存在");
         }
 
-        SwBillingRecordDo add = buildBaseBillingRecord(currentUser,user);
+        String id = SecurityUtil.getUUID(); // 批次唯一ID
 
+        SwBillingRecordDo add = buildBaseBillingRecord(currentUser,user);
+        add.setId(id);
         add.setDatasource(paymentRequestDTO.getDatasource());
         add.setPaidin(paymentRequestDTO.getPaidin());
 
@@ -181,7 +181,15 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
 
         }
 
-        this.updateOrSaveData(add,user,bills,paymentRequestDTO.getIds());
+        // 保存处理结果
+        try {
+            swBillingRecordService.saveProcessedData(add,user,bills,paymentRequestDTO.getIds());
+        }catch (Exception e){
+            log.error("生成缴费记录 失败 {}",e.getMessage());
+            throw new Exception(e.getMessage());
+        }
+
+
 
     }
 
@@ -192,8 +200,9 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
      * @param bills
      * @param ids
      */
-
-    public void updateOrSaveData(SwBillingRecordDo add, SwUserManagementDo user, List<SwBillManagementPaidDo> bills, List<String> ids){
+     @Override
+     @Transactional(rollbackFor = Exception.class)
+    public void saveProcessedData(SwBillingRecordDo add, SwUserManagementDo user, List<SwBillManagementPaidDo> bills, List<String> ids){
         //账单缴费记录生成
         this.baseMapper.insert(add);
         //已缴费账单生成
@@ -241,7 +250,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
 
 
 
-    private void calculateFees(List<SwBillManagementUnpaidDo> list, SwBillingRecordDo add, SwUserManagementDo user) {
+    public void calculateFees(List<SwBillManagementUnpaidDo> list, SwBillingRecordDo add, SwUserManagementDo user) {
 
 
         // 用户 账户余额

+ 15 - 8
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwRefundRequestRecordServiceImpl.java

@@ -73,17 +73,24 @@ public class SwRefundRequestRecordServiceImpl extends ServiceImpl<SwRefundReques
             //校验 退款金额
             validateRefundAmount(refundRequestRecordDO,user);
 
-            // 1.缴费记录表更新:
-            updateBillRecord(refundRequestRecordDO,currentUser);
+            try {
+                // 1.缴费记录表更新:
+                updateBillRecord(refundRequestRecordDO,currentUser);
 
-            //2. 更新退款记录
-            processRefund(refundRequestRecordDO, currentUser);
+                //2. 更新退款记录
+                processRefund(refundRequestRecordDO, currentUser);
 
-            // 已缴账单记录表更新
-            migratePaidBillsToUnpaid(refundRequestRecordDO);
+                // 已缴账单记录表更新
+                migratePaidBillsToUnpaid(refundRequestRecordDO);
 
-            // 更新用户余额
-            updateUserBalance(refundRequestRecordDO,user);
+                // 更新用户余额
+                updateUserBalance(refundRequestRecordDO,user);
+
+            }catch (Exception e){
+
+                log.error("退款申请失败 {}",e.getMessage());
+                throw new Exception(e.getMessage());
+            }
 
         return R.ok();
     }

+ 7 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwUserManagementServiceImpl.java

@@ -2,11 +2,13 @@ package com.rongwei.zhsw.system.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.rongwe.zhsw.system.domain.SwUserManagementDo;
+import com.rongwe.zhsw.system.dto.TransferAccountDo;
 import com.rongwei.zhsw.system.dao.SwUserManagementDao;
 import com.rongwei.zhsw.system.service.SwUserManagementService;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * @author libai
@@ -27,6 +29,11 @@ public class SwUserManagementServiceImpl extends ServiceImpl<SwUserManagementDao
     public void balanceAdd(String id, BigDecimal balanceAdd) {
         this.getBaseMapper().balanceAdd(id, balanceAdd);
     }
+
+    @Override
+    public void batchUpdateUserBalances(List<TransferAccountDo.UpdateUserBalance> list) {
+        this.getBaseMapper().batchUpdateUserBalances(list);
+    }
 }
 
 

+ 14 - 2
zhsw-common/src/main/java/com/rongwei/zhsw/system/utils/SaveConstans.java

@@ -12,15 +12,22 @@ public class SaveConstans {
     public static class billInfo {
 
         /**
-         * 账单待缴费状态  ----------代缴
+         * 账单状态  ----------待缴费
          */
         public static final String PENDINGSTATUS = "2";
 
         /**
-         * 账单待缴费状态  ----------实缴
+         * 账单状态  ----------已缴费
          */
         public static final String PAIDINSTATUS = "3";
 
+        /**
+         * 账单状态  ----------预收账单
+         */
+        public static final String PRERECEIVEDSTATE = "1";
+
+
+
 
 
     }
@@ -47,6 +54,11 @@ public class SaveConstans {
          */
         public static final String DATASOURCEWINSOW = "1";
 
+        /**
+         * 数据来源  ---余额抵扣
+         */
+        public static final String DATASOURCEBALANCEDEDUCTION = "2";
+
 
         /**
          * 账单报表修正   --已修正状态

+ 7 - 10
zhsw-common/src/main/resources/mybatis/zhsw/SwBillManagementUnpaidDao.xml

@@ -5,16 +5,13 @@
 <mapper namespace="com.rongwei.zhsw.system.dao.SwBillManagementUnpaidDao">
 
     <delete id="deleteByIds">
+        <if test="idList != null and idList.size() > 0">
+            <foreach collection="idList" item="id" separator=";" >
+        delete from sw_bill_management_unpaid where ID = #{id}
 
-        delete from sw_bill_management_unpaid
-        <where>
-            <if test="idList != null and idList.size() > 0">
-                ID in
-                <foreach collection="idList" item="id" separator="," open="(" close=")">
-                    #{id}
-                </foreach>
-            </if>
-        </where>
-
+        </foreach>
+    </if>
     </delete>
+
+
 </mapper>

+ 10 - 0
zhsw-common/src/main/resources/mybatis/zhsw/SwUserManagementDao.xml

@@ -9,6 +9,16 @@
         set ACCOUNTBALANCE = ACCOUNTBALANCE + #{balanceAdd}
         where ID = #{id}
     </update>
+
+
+    <update id="batchUpdateUserBalances">
+        <foreach collection="list" item="item" separator=";">
+            UPDATE sw_user_management
+            SET ACCOUNTBALANCE = ACCOUNTBALANCE + #{item.balanceAdd}
+            WHERE ID = #{item.id}
+        </foreach>
+    </update>
+
     <select id="getUserByDsKey" resultType="com.rongwe.zhsw.system.vo.SwUserManagementVo">
         select * from
         <foreach collection="para" index="key" item="value" separator="union all" open="(" close=") A">

+ 7 - 7
zhsw-entity/src/main/java/com/rongwe/zhsw/system/domain/SwBillManagementUnpaidDo.java

@@ -121,37 +121,37 @@ public class SwBillManagementUnpaidDo extends BaseDo implements Serializable {
     /**
      * 缴费记录ID
      */
-    @Deprecated
+
     private String paymentrecordid;
     /**
      * 开票状态
      */
-    @Deprecated
+
     private String invoicestatus;
     /**
      * 票据状态
      */
-    @Deprecated
+
     private String billstatus;
     /**
      * 发票附件
      */
-    @Deprecated
+
     private String invoicefiles;
     /**
      * 滞纳金
      */
-    @Deprecated
+
     private BigDecimal latefees;
     /**
      * 退款金额
      */
-    @Deprecated
+
     private BigDecimal refundamount;
     /**
      * 余额划扣金额
      */
-    @Deprecated
+
     private BigDecimal balancedebitamount;
     /**
      * 抄表修正状态

+ 49 - 0
zhsw-entity/src/main/java/com/rongwe/zhsw/system/dto/TransferAccountDo.java

@@ -0,0 +1,49 @@
+package com.rongwe.zhsw.system.dto;
+
+import com.rongwe.zhsw.system.domain.SwBillManagementPaidDo;
+import com.rongwe.zhsw.system.domain.SwBillingRecordDo;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class TransferAccountDo {
+
+    /**
+     * 转 正式账单的 ids
+     */
+    private List<String> officeIds  = new ArrayList<>();
+
+    /**
+     * 需要生成的 缴费记录
+     */
+    private List<SwBillingRecordDo> recordDoList   = new ArrayList<>();
+
+
+    /**
+     * 需要生成的已缴张账单 记录
+     */
+    private List<SwBillManagementPaidDo> paidDoList   = new ArrayList<>();
+
+    /**
+     * 需要删除的 待缴账单 ids
+     */
+    private List<String> delUnpaidIds   = new ArrayList<>();
+
+    /**
+     * 记录需要更新的用户余额
+     */
+    private List<UpdateUserBalance> userBalanceList  = new ArrayList<>();
+
+
+    @Data
+    public static class UpdateUserBalance {
+
+        private String id;
+
+        private BigDecimal balanceAdd;
+    }
+}

+ 18 - 4
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/SwBillManagementUnpaidController.java

@@ -6,6 +6,8 @@ import com.rongwei.zhsw.system.service.SwBillManagementUnpaidService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Map;
+
 /**
  * 账单管理(按年分表)(预收,未缴)(SwBillManagementUnpaid)表控制层
  *
@@ -20,10 +22,7 @@ public class SwBillManagementUnpaidController {
     private SwBillManagementUnpaidService swBillManagementUnpaidService;
 
     /**
-     *
-     * @param meterReadId 抄表id
-     * @param billId   账单 iD
-     * @param thisMeterReading  本次抄表数
+     *抄表修正
      * @return
      */
     @PostMapping("/meterReadingCorrection")
@@ -36,5 +35,20 @@ public class SwBillManagementUnpaidController {
         }
     }
 
+
+    /**
+     * 转正式账单
+     * @return
+     */
+    @PostMapping("/transferAccount")
+    @ResponseBody
+    public R transferAccount(@RequestBody Map<String,Object> map){
+        try {
+            return  swBillManagementUnpaidService.transferAccount(map);
+        }catch (Exception e){
+            return R.error(e.getMessage());
+        }
+    }
+
 }