Просмотр исходного кода

优化账户预存定时任务

java110 лет назад: 4
Родитель
Сommit
eddea331e6

+ 9 - 0
java110-bean/src/main/java/com/java110/dto/account/AccountDto.java

@@ -38,6 +38,7 @@ public class AccountDto extends PageDto implements Serializable {
     private String acctName;
     private String objType;
     private String partId;
+    private String hasMoney; // 1 标识有
 
 
     private Date createTime;
@@ -125,4 +126,12 @@ public class AccountDto extends PageDto implements Serializable {
     public void setPartId(String partId) {
         this.partId = partId;
     }
+
+    public String getHasMoney() {
+        return hasMoney;
+    }
+
+    public void setHasMoney(String hasMoney) {
+        this.hasMoney = hasMoney;
+    }
 }

+ 1 - 0
java110-bean/src/main/java/com/java110/dto/app/AppDto.java

@@ -22,6 +22,7 @@ public class AppDto extends PageDto implements Serializable {
     public static final String WECHAT_MALL_APP_ID = "992021030901240071";
     public static final String OWNER_WECHAT_PAY = "992020011134400001"; // 微信支付
     public static final String OWNER_APP_PAY = "992020061440050003"; // app微信支付
+    public static final String JOB_APP_ID = "992021061746360004"; // 定时任务应用
 
 
     private String appId;

+ 1 - 0
java110-bean/src/main/java/com/java110/dto/logSystemError/LogSystemErrorDto.java

@@ -17,6 +17,7 @@ public class LogSystemErrorDto extends PageDto implements Serializable {
 
 
     public static final String ERR_TYPE_JOB = "JOB";
+    public static final String ERR_TYPE_ACCOUNT = "ACCOUNT";
 
     private String msg;
     private String errType;

+ 7 - 0
java110-db/src/main/resources/mapper/acct/AccountServiceDaoImplMapper.xml

@@ -104,6 +104,9 @@
         <if test="amount !=null and amount != ''">
             and t.amount= #{amount}
         </if>
+        <if test="hasMoney !=null and hasMoney != ''">
+            and t.amount > 0
+        </if>
         <if test="acctType !=null and acctType != ''">
             and t.acct_type= #{acctType}
         </if>
@@ -178,6 +181,10 @@
         <if test="amount !=null and amount != ''">
             and t.amount= #{amount}
         </if>
+        <if test="hasMoney !=null and hasMoney != ''">
+            and t.amount > 0
+        </if>
+
         <if test="acctType !=null and acctType != ''">
             and t.acct_type= #{acctType}
         </if>

+ 1 - 1
service-api/src/main/java/com/java110/api/listener/fee/PayOweFeeListener.java

@@ -37,7 +37,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * @ClassName PayFeeListener
+ * @ClassName payOweFeeListener
  * @Description TODO 缴费侦听
  * @Author wuxw
  * @Date 2019/6/3 13:46

+ 1 - 0
service-job/src/main/java/com/java110/job/JobServiceApplication.java

@@ -39,6 +39,7 @@ import java.nio.charset.Charset;
         "com.java110.intf.order",
         "com.java110.intf.store",
         "com.java110.intf.report",
+        "com.java110.intf.acct",
         "com.java110.intf.goods"
 })
 @EnableScheduling

+ 195 - 0
service-job/src/main/java/com/java110/job/task/fee/AccountDeductionPayFeeTemplate.java

@@ -0,0 +1,195 @@
+package com.java110.job.task.fee;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.client.RestTemplate;
+import com.java110.core.factory.CallApiServiceFactory;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.smo.IComputeFeeSMO;
+import com.java110.dto.account.AccountDto;
+import com.java110.dto.app.AppDto;
+import com.java110.dto.community.CommunityDto;
+import com.java110.dto.fee.FeeDto;
+import com.java110.dto.logSystemError.LogSystemErrorDto;
+import com.java110.dto.task.TaskDto;
+import com.java110.intf.acct.IAccountInnerServiceSMO;
+import com.java110.intf.common.ILogSystemErrorInnerServiceSMO;
+import com.java110.intf.fee.IFeeInnerServiceSMO;
+import com.java110.job.quartz.TaskSystemQuartz;
+import com.java110.po.accountDetail.AccountDetailPo;
+import com.java110.po.logSystemError.LogSystemErrorPo;
+import com.java110.service.smo.ISaveSystemErrorSMO;
+import com.java110.utils.constant.ServiceCodeConstant;
+import com.java110.utils.exception.SMOException;
+import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.ExceptionUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @ClassName GenerateOwnerBillTemplate
+ * @Description TODO  预存账户扣款缴费
+ * @Author wuxw
+ * @Date 2020/6/4 8:33
+ * @Version 1.0
+ * add by wuxw 2020/6/4
+ **/
+@Component
+public class AccountDeductionPayFeeTemplate extends TaskSystemQuartz {
+
+
+    @Autowired
+    private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
+
+    @Autowired
+    private IComputeFeeSMO computeFeeSMOImpl;
+
+    @Autowired
+    private ILogSystemErrorInnerServiceSMO logSystemErrorInnerServiceSMOImpl;
+
+    @Autowired
+    private ISaveSystemErrorSMO saveSystemErrorSMOImpl;
+
+    @Autowired
+    private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
+
+    @Autowired
+    RestTemplate restTemplate;
+
+    @Override
+    protected void process(TaskDto taskDto) throws Exception {
+
+        // 获取小区
+        List<CommunityDto> communityDtos = getAllCommunity();
+
+        for (CommunityDto communityDto : communityDtos) {
+            doDeductionPayFeeFee(taskDto, communityDto);
+        }
+
+    }
+
+    /**
+     * 根据小区生成账单
+     *
+     * @param communityDto
+     */
+    private void doDeductionPayFeeFee(TaskDto taskDto, CommunityDto communityDto) {
+
+        //查询费用项
+        AccountDto accountDto = new AccountDto();
+        accountDto.setPartId(communityDto.getCommunityId());
+        accountDto.setHasMoney("1");
+        accountDto.setAcctType(AccountDto.ACCT_TYPE_CASH);
+        List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
+
+        if (accountDtos == null || accountDtos.size() < 1) {
+            return;
+        }
+
+        for (AccountDto tmpAccountDto : accountDtos) {
+            try {
+                doPayFee(tmpAccountDto);
+            } catch (Exception e) {
+                LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo();
+                logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId));
+                logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_JOB);
+                logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e));
+                saveSystemErrorSMOImpl.saveLog(logSystemErrorPo);
+                logger.error("生成费用失败", e);
+            }
+        }
+
+    }
+
+    private void doPayFee(AccountDto tmpAccountDto) {
+
+        // 查询业主的费用
+        FeeDto feeDto = new FeeDto();
+        feeDto.setCommunityId(tmpAccountDto.getPartId());
+        feeDto.setOwnerId(tmpAccountDto.getObjId());
+        feeDto.setState(FeeDto.STATE_DOING);
+        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
+        if (feeDtos == null || feeDtos.size() < 1) {
+            return;
+        }
+        List<FeeDto> tmpFeeDtos = new ArrayList<>();
+        for (FeeDto tmpFeeDto : feeDtos) {
+            computeFeeSMOImpl.computeEveryOweFee(tmpFeeDto);//计算欠费金额
+            //如果金额为0 就排除
+            if (tmpFeeDto.getFeePrice() > 0 && tmpFeeDto.getEndTime().getTime() <= DateUtil.getCurrentDate().getTime()) {
+                tmpFeeDtos.add(tmpFeeDto);
+            }
+        }
+
+        if (tmpFeeDtos.size() < 1) {
+            return;
+        }
+        int flag = 0;
+        for (FeeDto tmpFeeDto : tmpFeeDtos) {
+            try {
+                if (tmpFeeDto.getFeePrice() > Double.parseDouble(tmpAccountDto.getAmount())) {
+                    continue; // 余额不足
+                }
+                //先做扣款
+                AccountDetailPo accountDetailPo = new AccountDetailPo();
+                accountDetailPo.setAcctId(tmpAccountDto.getAcctId());
+                accountDetailPo.setAmount(tmpFeeDto.getFeePrice() + "");
+                accountDetailPo.setObjId(tmpAccountDto.getObjId());
+                accountDetailPo.setObjType(tmpAccountDto.getObjType());
+                accountDetailPo.setRemark("缴费扣款");
+                flag = accountInnerServiceSMOImpl.withholdAccount(accountDetailPo);
+                if (flag < 1) {
+                    continue;//扣款失败
+                }
+                JSONObject param = new JSONObject();
+                param.put("communityId", tmpAccountDto.getPartId());
+                JSONArray fees = new JSONArray();
+                JSONObject fee = new JSONObject();
+                fee.put("feeId", tmpFeeDto.getFeeId());
+                fee.put("startTime", tmpFeeDto.getEndTime());
+                fee.put("endTime", tmpFeeDto.getDeadlineTime());
+                fee.put("receivedAmount", tmpFeeDto.getFeePrice());
+                fee.put("primeRate", "1");
+                fee.put("remark", "定时账户扣款缴费");
+                fees.add(fee);
+                param.put("fees", fees);
+                param.put("remark", "定时账户扣款缴费");
+                try {
+                    CallApiServiceFactory.postForApi(AppDto.JOB_APP_ID, param, ServiceCodeConstant.SERVICE_CODE_PAY_OWE_FEE, JSONObject.class);
+                } catch (SMOException e) {
+                    logger.error("缴费失败", e);
+                    accountDetailPo = new AccountDetailPo();
+                    accountDetailPo.setAcctId(tmpAccountDto.getAcctId());
+                    accountDetailPo.setAmount(tmpFeeDto.getFeePrice() + "");
+                    accountDetailPo.setObjId(tmpAccountDto.getObjId());
+                    accountDetailPo.setObjType(tmpAccountDto.getObjType());
+                    accountDetailPo.setRemark("缴费失败,费用预存");
+                    flag = accountInnerServiceSMOImpl.prestoreAccount(accountDetailPo);
+                    if (flag < 1) {
+                        throw new IllegalArgumentException("费用回退失败,严重,请手工处理 " + tmpAccountDto.getAcctId() + "金额:" + tmpFeeDto.getFeePrice());
+                    }
+                }
+            } catch (Exception e) {
+                logger.error("缴费失败", e);
+                LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo();
+                logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId));
+                logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_ACCOUNT);
+                logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e));
+                saveSystemErrorSMOImpl.saveLog(logSystemErrorPo);
+                logger.error("生成费用失败", e);
+            }
+        }
+
+
+        //feeId: _item,
+        //                                startTime: _oweFeeItem.endTime,
+        //                                endTime: _oweFeeItem.deadlineTime,
+        //                                receivedAmount: _oweFeeItem.feePrice,
+        //                                primeRate:$that.owePayFeeOrderInfo.primeRate
+
+    }
+
+}