Browse Source

阀门规则判断

oppadmin 4 years ago
parent
commit
c4edf468fc

+ 13 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayControlRuleMapper.java

@@ -1,9 +1,11 @@
 package com.bz.smart_city.dao.pay;
 
+import com.bz.smart_city.dto.pay.PayPayReceivableDto;
 import com.bz.smart_city.entity.pay.PayControlRule;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.List;
 
@@ -24,5 +26,16 @@ public interface PayControlRuleMapper {
     //数据是否存在
     List<PayControlRule>ExitsData(@Param("id") String id,@Param("name") String name,@Param("customerId") BigInteger customerId);
 
+    //用户欠费金额
+    BigDecimal findDebtMoney(@Param("accountId") String accountId);
+
+    //用户欠户天数
+    Integer findDebtDay(@Param("accountId") String accountId);
+
+    //用水余额
+    BigDecimal findUseMoeny(@Param("accountId") String accountId);
+
+    //开户状态
+    Integer findOpenUse(@Param("accountId") String accountId);
 
 }

+ 280 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayControlRuleServiceImpl.java

@@ -4,13 +4,16 @@ import com.bz.smart_city.commom.exception.ServiceException;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.dao.pay.PayControlRuleMapper;
+import com.bz.smart_city.dao.pay.PayRechargeaccountMapper;
 import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.dto.pay.PayRechargeaccountDto;
 import com.bz.smart_city.entity.pay.PayControlRule;
 import com.bz.smart_city.service.pay.PayControlRuleService;
 import com.github.pagehelper.PageHelper;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.time.LocalDateTime;
 import java.util.List;
@@ -23,6 +26,10 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
 
     @Resource
     PayControlRuleMapper payControlRuleMapper;
+    @Resource
+    PayRechargeaccountMapper payRechargeaccountMapper;
+
+
     @Override
     public Integer add(PayControlRule payControlRule){
         LoginUser loginUser = UserUtil.getCurrentUser();
@@ -97,4 +104,277 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
     }
 
 
+    /**
+     * 欠费天数
+     * @param accountId 用户编号
+     * @param condition 条件
+     * @param value 判断值
+     * @return 符合条件返回true
+     */
+    public boolean ConditionDebtDay(String accountId,String condition,String value){
+        Integer day = payControlRuleMapper.findDebtDay(accountId);
+        int paramDay = Integer.valueOf(value).intValue();
+        if(day != null){
+            switch (condition){
+                case ">":{
+                    if(day > paramDay)
+                        return true;
+                    break;
+                }
+                case "<":{
+                    if(day < paramDay)
+                        return true;
+                    break;
+                }
+                case "<>":{
+                    if(day != paramDay)
+                        return true;
+                    break;
+                }
+                case "=":{
+                    if(day == paramDay)
+                        return true;
+                    break;
+                }
+                case ">=":{
+                    if(day >= paramDay)
+                        return true;
+                    break;
+                }
+                case "<=":{
+                    if(day <= paramDay)
+                        return true;
+                    break;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * 欠费金额
+     * @param accountId 用户编号
+     * @param condition 条件
+     * @param value 判断值
+     * @return 符合条件返回true
+     */
+    public boolean ConditionDebtMoney(String accountId,String condition,String value){
+        BigDecimal money = payControlRuleMapper.findDebtMoney(accountId);
+        if(money != null){
+            switch (condition){
+                case ">":{
+                    if(money.compareTo(new BigDecimal(value))  > 0)
+                        return true;
+                    break;
+                }
+                case "<":{
+                    if(money.compareTo(new BigDecimal(value)) < 0)
+                        return true;
+                    break;
+                }
+                case "<>":{
+                    if(money.compareTo(new BigDecimal(value))  != 0)
+                        return true;
+                    break;
+                }
+                case "=":{
+                    if(money.compareTo(new BigDecimal(value))  == 0)
+                        return true;
+                    break;
+                }
+                case ">=":{
+                    if(money.compareTo(new BigDecimal(value))  >= 0)
+                        return true;
+                    break;
+                }
+                case "<=":{
+                    if(money.compareTo(new BigDecimal(value))  <= 0)
+                        return true;
+                    break;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 预存余额
+     * @param accountId 用户编号
+     * @param condition 条件
+     * @param value 判断值
+     * @return 符合条件返回true
+     */
+    public boolean ConditionRecharge(String accountId,String condition,String value){
+        PayRechargeaccountDto payRechargeaccountDto = payRechargeaccountMapper.findById(null,new BigInteger(accountId));
+
+        if(payRechargeaccountDto != null){
+            BigDecimal money = payRechargeaccountDto.getRemaining();
+            switch (condition){
+                case ">":{
+                    if(money.compareTo(new BigDecimal(value))  > 0)
+                        return true;
+                    break;
+                }
+                case "<":{
+                    if(money.compareTo(new BigDecimal(value)) < 0)
+                        return true;
+                    break;
+                }
+                case "<>":{
+                    if(money.compareTo(new BigDecimal(value))  != 0)
+                        return true;
+                    break;
+                }
+                case "=":{
+                    if(money.compareTo(new BigDecimal(value))  == 0)
+                        return true;
+                    break;
+                }
+                case ">=":{
+                    if(money.compareTo(new BigDecimal(value))  >= 0)
+                        return true;
+                    break;
+                }
+                case "<=":{
+                    if(money.compareTo(new BigDecimal(value))  <= 0)
+                        return true;
+                    break;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * 用水余额
+     * @param accountId 用户编号
+     * @param condition 条件
+     * @param value 判断值
+     * @return 符合条件返回true
+     */
+    public  boolean ConditionUsedMoney(String accountId,String condition,String value){
+        BigDecimal money = payControlRuleMapper.findUseMoeny(accountId);
+        if(money != null){
+            switch (condition){
+                case ">":{
+                    if(money.compareTo(new BigDecimal(value))  > 0)
+                        return true;
+                    break;
+                }
+                case "<":{
+                    if(money.compareTo(new BigDecimal(value)) < 0)
+                        return true;
+                    break;
+                }
+                case "<>":{
+                    if(money.compareTo(new BigDecimal(value))  != 0)
+                        return true;
+                    break;
+                }
+                case "=":{
+                    if(money.compareTo(new BigDecimal(value))  == 0)
+                        return true;
+                    break;
+                }
+                case ">=":{
+                    if(money.compareTo(new BigDecimal(value))  >= 0)
+                        return true;
+                    break;
+                }
+                case "<=":{
+                    if(money.compareTo(new BigDecimal(value))  <= 0)
+                        return true;
+                    break;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 开户状态
+     * @param accountId 用户编号
+     * @param condition 条件
+     * @param value 判断值
+     * @return 符合条件返回true
+     */
+    public boolean ConditionOpenUsed(String accountId,String condition,String value){
+        Integer state = payControlRuleMapper.findDebtDay(accountId);
+        int paramValue = Integer.valueOf(value).intValue();
+        if(state != null){
+            switch (condition){
+                case "=":
+                {
+                    if(paramValue == state)
+                        return true;
+                    break;
+                }
+                case "<>":
+                {
+                    if(paramValue != state)
+                        return true;
+                    break;
+                }
+            }
+
+        }
+        return false;
+    }
+
+    /**
+     * 预存与欠费差额
+     * @param accountId 用户编号
+     * @param condition 条件
+     * @param value 判断值
+     * @return 符合条件返回true
+     */
+    public boolean ConditionRechargeAndDebt(String accountId,String condition,String value){
+        BigDecimal Recharge = payControlRuleMapper.findUseMoeny(accountId);
+        if(Recharge == null)
+            Recharge = new BigDecimal("0");
+
+        BigDecimal Debt = payControlRuleMapper.findDebtMoney(accountId);
+        if(Debt == null)
+            Debt = new BigDecimal("0");
+
+        BigDecimal DiffValue = null;
+        DiffValue = Recharge.subtract(Debt);
+        switch (condition) {
+                case ">": {
+                    if (DiffValue.compareTo(new BigDecimal(value)) > 0)
+                        return true;
+                    break;
+                }
+                case "<": {
+                    if (DiffValue.compareTo(new BigDecimal(value)) < 0)
+                        return true;
+                    break;
+                }
+                case "<>": {
+                    if (DiffValue.compareTo(new BigDecimal(value)) != 0)
+                        return true;
+                    break;
+                }
+                case "=": {
+                    if (DiffValue.compareTo(new BigDecimal(value)) == 0)
+                        return true;
+                    break;
+                }
+                case ">=": {
+                    if (DiffValue.compareTo(new BigDecimal(value)) >= 0)
+                        return true;
+                    break;
+                }
+                case "<=": {
+                    if (DiffValue.compareTo(new BigDecimal(value)) <= 0)
+                        return true;
+                    break;
+                }
+            }
+
+        return false;
+    }
+
 }

+ 32 - 0
smart-city-platform/src/main/resources/mapper/pay/PayControlRuleMapper.xml

@@ -113,4 +113,36 @@
 
         where id = #{payControlRule.id}
     </update>
+
+    <select id="findDebtMoney" resultType="Decimal">
+       select
+            sum( CASE WHEN pprb.debt IS NULL THEN 0 ELSE pprb.debt END ) sumDebt
+        from pay_pay_receivable rece
+        where rece.debt > 0  and rece.account_id = #{accountId}
+    </select>
+
+    <select id="findDebtDay" resultType="integer">
+       select
+            to_days(now()) - to_days(create_date) days
+        from pay_pay_receivable rece
+        where rece.debt > 0  and rece.account_id = #{accountId}
+    </select>
+
+    <select id="findUseMoeny" resultType="decimal">
+        select
+            (
+            SELECT remaining remaining from pay_pay_rechargeaccount
+            where  account_id=#{accountId})
+         -
+            (select IFNULL(SUM(debt),0) debt  from pay_pay_receivable where
+            account_id=#{accountId} and debt > 0 )
+         as remaining
+    </select>
+
+    <select id="findOpenUse" resultType="integer">
+        select
+        scd.curr_status state
+        from  sc_device scd
+        where scd.account_id = #{accountId}
+    </select>
 </mapper>