Преглед на файлове

Merge branch '20200918' of http://114.135.61.188:53000/ZONIOT/water-iot into 20200918

oppadmin преди 4 години
родител
ревизия
36ac6fa10a
променени са 13 файла, в които са добавени 162 реда и са изтрити 6 реда
  1. 10 0
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/archives/PayBaseCustomerandmeterrelaController.java
  2. 2 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayPayReceivableMapper.java
  3. 5 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/archives/PayBaseCustomerandmeterrelaMapper.java
  4. 26 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayControlValve.java
  5. 2 2
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimateMsgSendServiceImpl.java
  6. 2 1
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimatedDayServiceImpl.java
  7. 29 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java
  8. 28 3
      smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java
  9. 8 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/pay/archives/impl/PayBaseCustomerandmeterrelaServiceImpl.java
  10. BIN
      smart-city-platform/src/main/resources/excel/batchOpenAccountTemplate.xlsx
  11. 32 0
      smart-city-platform/src/main/resources/mapper/PayBaseCustomerandmeterrelaMapper.xml
  12. 1 0
      smart-city-platform/src/main/resources/mapper/pay/PayChargeSurveyMapper.xml
  13. 17 0
      smart-city-platform/src/main/resources/mapper/pay/PayPayReceivableMapper.xml

+ 10 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/archives/PayBaseCustomerandmeterrelaController.java

@@ -11,6 +11,7 @@ import com.bz.smart_city.dto.pay.PayCustomerDto;
 import com.bz.smart_city.dto.pay.PaySaveCustomerDto;
 import com.bz.smart_city.entity.pay.archives.CustomerListInfo;
 import com.bz.smart_city.entity.pay.archives.PayAccountInfo;
+import com.bz.smart_city.quartz.service.EstimatedDayService;
 import com.bz.smart_city.service.impl.ImportServiceImpl;
 import com.bz.smart_city.service.pay.archives.PayBaseCustomerandmeterrelaService;
 import io.swagger.annotations.Api;
@@ -46,6 +47,9 @@ public class PayBaseCustomerandmeterrelaController {
     @Autowired
     private RedisUtil redisUtil;
 
+    @Autowired
+    private EstimatedDayService estimatedDayService;
+
     @ResponseBody
     @GetMapping("/pageOpenList")
     @ApiOperation(value = "计费系统-获取开户分页")
@@ -226,4 +230,10 @@ public class PayBaseCustomerandmeterrelaController {
 
         payBaseCustomerandmeterrelaService.getCustomerListExcel(condition,waterPropertyId,businessstate,calculateway,httpServletResponse);
     }
+
+    @GetMapping("/estimatedTest")
+    @ApiOperation(value = "计费系统-预计费测试")
+    public void estimatedTest(Integer siteId,Integer customerId){
+        estimatedDayService.start(siteId,customerId);
+    }
 }

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

@@ -84,4 +84,6 @@ public interface PayPayReceivableMapper {
 
     BigDecimal querySumTransamount(@Param("siteId")Integer siteId,@Param("customerId")Integer customerId,
                                    @Param("year")Integer year,@Param("month")Integer month,@Param("accountnumber") String accountnumber);
+
+    BigDecimal getHistoryDebt(@Param("siteId")Integer siteId,@Param("customerId")Integer customerId,@Param("accountid")BigInteger accountid);
 }

+ 5 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/archives/PayBaseCustomerandmeterrelaMapper.java

@@ -5,6 +5,7 @@ import com.bz.smart_city.dto.pay.PayCustomerDto;
 import com.bz.smart_city.entity.Organization;
 import com.bz.smart_city.entity.pay.PayBaseAccount;
 import com.bz.smart_city.entity.pay.PayControlRule;
+import com.bz.smart_city.entity.pay.PayControlValve;
 import com.bz.smart_city.entity.pay.PayPayRechargeaccount;
 import com.bz.smart_city.entity.pay.archives.*;
 import org.apache.ibatis.annotations.Mapper;
@@ -31,6 +32,8 @@ public interface PayBaseCustomerandmeterrelaMapper {
     public PayBaseCustomerandmeterrela getWaterPropertyId(@Param("siteId")Integer siteId, @Param("customerId")Integer customerId,@Param("name")String name);
     public int insertList(@Param("customers") List<PayBaseCustomerandmeterrela> customers);
 
+    public int insertValveList(@Param("valve") List<PayControlValve> valve);
+
     public Organization getOfficeId(@Param("siteId")Integer siteId, @Param("name")String name);
 
     public List<PayBaseCustomerandmeterrela> findList(PayBaseCustomerandmeterrela customer);
@@ -101,4 +104,6 @@ public interface PayBaseCustomerandmeterrelaMapper {
     void updateMeterInstallOpen(@Param("isAccepted")Integer isAccepted, @Param("updateBy")String updateBy,@Param("date") LocalDateTime date, @Param("id") BigInteger id);
 
     public List<PayControlRule> getRuleNames(@Param("siteId")Integer siteId,@Param("customerId")Integer customerId,@Param("list")List<String> list);
+
+    void insertValve(@Param("deviceId")BigInteger deviceId,@Param("date")LocalDateTime date,@Param("controlState")int controlState);
 }

+ 26 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayControlValve.java

@@ -0,0 +1,26 @@
+package com.bz.smart_city.entity.pay;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+
+/**
+ * @author xjh
+ * @version 计费
+ * @date 2021/1/30 10:07
+ */
+@Data
+@ApiModel("阀控记录表")
+public class PayControlValve {
+    @ApiModelProperty(value = "设备ID")
+    private BigInteger deviceId;//设备id
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "下发时间")
+    private LocalDateTime controlTime;//下发时间
+    @ApiModelProperty(value = "操作类型")
+    private Integer controlState;//操作类型 0关 1开
+}

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimateMsgSendServiceImpl.java

@@ -77,8 +77,8 @@ public class EstimateMsgSendServiceImpl implements EstimateMsgSendService, Initi
                 minute = sp[1];
                 //String cron = "0 */3 * * * ?";
                 //String cron ="0 40 14 * * ?";
-                String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ?";
-                //String cron = "0 20 11 * * ?";
+                //String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ?";
+                String cron = "0 2 15 * * ?";
                 log.info("预计费每天推送:" + cron);
                 log.info("预计费每天推送:" + "站点ID:"+siteId+"水司ID:"+customerId);
                 entity.setCronExpression(cron);

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimatedDayServiceImpl.java

@@ -59,7 +59,8 @@ public class EstimatedDayServiceImpl implements EstimatedDayService, Initializin
         boolean exists = jobAndTriggerService.isExists(entity);
         if(!exists) {
             //String cron = "0 */2 * * * ?";
-            String cron = "0 0 0 * * ?";
+            //String cron = "0 0 0 * * ?";
+            String cron = "0 0 15 * * ?";
             log.info("预计费每天统计:" + cron);
             log.info("预计费每天统计:" + "站点ID:"+siteId+"水司ID:"+customerId);
             entity.setCronExpression(cron);

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

@@ -794,6 +794,10 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
             List<EstimatedDayDto>  list = amountWaterUsedAmountMapper.getEstimatedDay(beforDate,baseClosingAccountInfoDto.getYear(),baseClosingAccountInfoDto.getMonth(),siteId,customerId);
             if(list != null && list.size() > 0){
                 for(EstimatedDayDto dto:list){
+
+                    PayBaseCustomerandmeterrela customerInfo = payBaseCustomerandmeterrelaMapper.get(dto.getId());
+                    Integer calculateway = customerInfo.getCalculateway();//结算方式
+
                     BigDecimal dayReading = dto.getDayReading();
                     BigDecimal mReading = dto.getMReading();
                     String readdate = dto.getReaddate();
@@ -806,6 +810,14 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
                     if(dayReading != null && mReading != null){
                         BigDecimal amount = dayReading.subtract(mReading);
 
+                        // 0水量 不计费但计量
+                        if(amount.intValue()<=0|| calculateway == 3){
+                            amount = new BigDecimal(0);
+                        }
+                        if(calculateway ==2){
+                            amount = customerInfo.getFixedamount();
+                        }
+
                         Integer isEnable = this.isEnable(baseClosingAccountInfoDto.getYear(),baseClosingAccountInfoDto.getMonth(),watermeterId,waterPropertyId,siteId,customerId);
                         //isEnable 0非阶梯  1阶梯  2异常(不做处理)
                         if(isEnable ==0){
@@ -835,6 +847,18 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
                                 if (objAmount != null) {
                                     availableAmount = new BigDecimal(objAmount.toString());
                                 }
+                                if(availableAmount.compareTo(BigDecimal.ZERO) == 0){
+                                    Object objlableL = new Object();
+                                    if(i > 1){
+                                        Object objlableL1 = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + i);
+                                        objlableL = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + (i-1));
+                                        //减去前一阶的阶梯量
+                                        availableAmount = new BigDecimal(objlableL1.toString()).subtract(new BigDecimal(objlableL.toString()));
+                                    }else{
+                                        objlableL = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + i);
+                                        availableAmount = new BigDecimal(objlableL.toString());
+                                    }
+                                }
                                 //阶梯结算水量
                                 BigDecimal calAmount = BigDecimal.ZERO;
                                 if (availableAmount.intValue() > 0) {
@@ -863,6 +887,11 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
                             balance = remaining.subtract(fee);
                         }
                     }
+                    //查询该户是否有历史欠费
+                    BigDecimal historyDebt = payPayReceivableMapper.getHistoryDebt(siteId,customerId,accountId);
+                    historyDebt = historyDebt != null ? historyDebt : BigDecimal.ZERO;
+                    //如果有欠费必须加上之前欠费
+                    balance = balance.add(historyDebt.negate());
                     payRechargeaccountMapper.updateBalance(balance,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()),payRechargeaccountDto.getId());
                     //修改账户用水余额字段跟预计费日期
                     log.info("【"+payRechargeaccountDto.getAccountnumber()+"】户:用水余额:"+balance+",预计费日期:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

+ 28 - 3
smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java

@@ -5,6 +5,7 @@ import com.bz.smart_city.commom.util.FileUtil;
 import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.commom.util.Util;
 import com.bz.smart_city.dao.pay.PayBaseAccountMapper;
+import com.bz.smart_city.dao.pay.PayControlRuleMapper;
 import com.bz.smart_city.dao.pay.PayRechargeaccountMapper;
 import com.bz.smart_city.dao.pay.archives.PayBaseCustomerandmeterrelaMapper;
 import com.bz.smart_city.dto.LoginUser;
@@ -13,6 +14,8 @@ import com.bz.smart_city.entity.Import;
 import com.bz.smart_city.entity.Message;
 import com.bz.smart_city.entity.Organization;
 import com.bz.smart_city.entity.pay.PayBaseAccount;
+import com.bz.smart_city.entity.pay.PayControlRule;
+import com.bz.smart_city.entity.pay.PayControlValve;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
 import com.bz.smart_city.excel.resolver.InstallPlanResolverExcelTemplate;
 import com.bz.smart_city.service.ImportService;
@@ -67,6 +70,8 @@ public class AsyncTaskImportService {
     private PayBaseAccountService payBaseAccountService;
     @Autowired
     private InstallPlanResolverExcelTemplate installPlanResolverExcelTemplate;
+    @Resource
+    private PayControlRuleMapper payControlRuleMapper;
 
     @Value("${files.path}")
     private String filesPath;
@@ -107,6 +112,7 @@ public class AsyncTaskImportService {
 
                 FormulaEvaluator evaluator = hssfWorkbook.getCreationHelper().createFormulaEvaluator();
                 List<PayBaseCustomerandmeterrela> customerList = newArrayList();
+                List<PayControlValve> valveList = newArrayList();//阀控记录
                 // 循环工作表Sheet
                 for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
 
@@ -131,8 +137,9 @@ public class AsyncTaskImportService {
                                Cell officeNameCell = row.getCell(14);//机构名称
                                Cell housetypeCell = row.getCell(16);//住房类型
                                Cell customergroupCell = row.getCell(18);//开户分组
-                               Cell vatnoCell = row.getCell(20);//公司税号
-                               Cell emailCell = row.getCell(21);//电子邮箱
+                               Cell vatnoCell = row.getCell(19);//公司税号
+                               Cell emailCell = row.getCell(20);//电子邮箱
+                               Cell controlCell = row.getCell(21);//阀控规则
                                Cell c_remark = row.getCell(22);//备注
 
                                if (accountnumberCell == null || StringUtils.equals("",accountnumberCell.getStringCellValue())) {
@@ -183,6 +190,7 @@ public class AsyncTaskImportService {
                                String email = emailCell.getStringCellValue().trim();
                                String housetype = housetypeCell.getStringCellValue().trim();
                                String customerGroup = customergroupCell.getStringCellValue().trim();
+                               String contollName = controlCell.getStringCellValue().trim();
 
                                //去重
                                if(!number_maps.containsKey(accountnumber)){
@@ -234,12 +242,15 @@ public class AsyncTaskImportService {
                                }
 
                                PayBaseCustomerandmeterrela customer =  new PayBaseCustomerandmeterrela();//实例化开户实体
+                               PayControlValve valve = new PayControlValve();//实例化阀控实体
                                //根据客户编码寻找客户id
                                PayBaseAccount accounts = payBaseCustomerandmeterrelaMapper.getAccountId(loginUser.getSiteId(),loginUser.getCustomerId(),accountnumber);
                                //根据水表电子号寻找水表id
                                PayBaseCustomerandmeterrela device = payBaseCustomerandmeterrelaMapper.getDeviceId(loginUser.getSiteId(),loginUser.getCustomerId(),metercode);
                                //根据用水性质名称寻找用水性质id
                                PayBaseCustomerandmeterrela property = payBaseCustomerandmeterrelaMapper.getWaterPropertyId(loginUser.getSiteId(),loginUser.getCustomerId(),propertyName);
+                               //根据阀控规则名称寻找阀控ID
+                               List<PayControlRule> contollList = payControlRuleMapper.findList(null,contollName,customerId);
                                //根据机构名称寻找机构id
                                Organization office =  null;
                                if(StringUtils.isNotBlank(officeName)){
@@ -329,7 +340,9 @@ public class AsyncTaskImportService {
                                    customer.setHousetype(value);//住房类型
                                    value = paySysDictService.getDictValue("开户分组",customerGroup,siteId,customerId);
                                    customer.setCustomergroup(value);//开户分组
-
+                                   customer.setValveRuleName(contollName);
+                                   customer.setValveRuleName(contollName);
+                                   customer.setValveRuleId(contollList != null && contollList.size() >0 ? String.valueOf(contollList.get(0).getId()) : "");
                                    customer.setOpendate(LocalDateTime.now());
                                    customer.setWaterPropertyId(property.getWaterPropertyId());
                                    payBaseCustomerandmeterrelaMapper.update(customer);
@@ -378,9 +391,17 @@ public class AsyncTaskImportService {
                                    customer.setCustomergroup(value);//开户分组
                                    customer.setOpendate(LocalDateTime.now());
                                    customer.setWaterPropertyId(property.getWaterPropertyId());
+                                   customer.setValveRuleName(contollName);
+                                   customer.setValveRuleId(contollList != null && contollList.size() >0 ? String.valueOf(contollList.get(0).getId()) : "");
                                    customerList.add(customer);
                                }
 
+                               //插入阀控记录
+                               valve.setDeviceId(device.getId());
+                               valve.setControlState(1);
+                               valve.setControlTime(LocalDateTime.now());
+                               valveList.add(valve);
+
                                //计算可用水量
                                if(property.getWaterPropertyId() != null){
                                    Boolean  flag = payBaseCustomerandmeterrelaService.UpdateAccountInfo(property.getWaterPropertyId(),accounts.getId(),null,loginUser.getSiteId(),loginUser.getCustomerId());
@@ -433,6 +454,10 @@ public class AsyncTaskImportService {
                     int reslut = payBaseCustomerandmeterrelaMapper.insertList(customerList);
                     log.info("insert reslut:" + reslut);
                 }
+                if(valveList.size() >0){
+                    int reslut = payBaseCustomerandmeterrelaMapper.insertValveList(valveList);
+                    log.info("insert valveResult:" + reslut);
+                }
                 log.info("结束循环为空的行上移");
                 messageContent.append("导入完成,");
                 messageContent.append("导入成功");

+ 8 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/pay/archives/impl/PayBaseCustomerandmeterrelaServiceImpl.java

@@ -87,6 +87,9 @@ public class PayBaseCustomerandmeterrelaServiceImpl implements PayBaseCustomeran
     @Resource
     private BaseClosingAccountInfoMapper baseClosingAccountInfoMapper;
 
+    @Resource
+    private PayControlRuleMapper payControlRuleMapper;
+
 
     @Value("${files.path}")
     private String filesPath;
@@ -486,6 +489,8 @@ public class PayBaseCustomerandmeterrelaServiceImpl implements PayBaseCustomeran
         //修改水表安装信息为已开户
         payBaseCustomerandmeterrelaMapper.updateMeterInstallOpen(2,loginUser.getUpdateBy(),LocalDateTime.now(),device.getId());
 
+        //往阀控表插入开阀记录
+        payBaseCustomerandmeterrelaMapper.insertValve(device.getId(),LocalDateTime.now(),1);
         if (customerList.size() > 0) {
             int reslut = payBaseCustomerandmeterrelaMapper.insertList(customerList);
 
@@ -875,6 +880,8 @@ public class PayBaseCustomerandmeterrelaServiceImpl implements PayBaseCustomeran
             List<PaySysDictSelectDto> houseList  = paySysDictMapper.getAll(null,null,"住房类型",siteId,customerId);
             //7.查找开户分组集合
             List<PaySysDictSelectDto> customerList  = paySysDictMapper.getAll(null,null,"开户分组",siteId,customerId);
+            //8.阀控规则集合
+            List<PayControlRule> controList = payControlRuleMapper.findList(null,null,customerId);
             //列表数据将存储到指定的excel文件路径
             FileOutputStream out = new FileOutputStream(filePath);
             //这里的context是jxls框架上的context内容
@@ -887,6 +894,7 @@ public class PayBaseCustomerandmeterrelaServiceImpl implements PayBaseCustomeran
             context.putVar("organizationList", organizationList);
             context.putVar("houseList", houseList);
             context.putVar("customerList", customerList);
+            context.putVar("controList",controList);
             //将List<Exam>列表数据按照模板文件中的格式生成到scoreOutput.xls文件中
             JxlsHelper.getInstance().processTemplate(in, out, context);
             log.info("save file success");

BIN
smart-city-platform/src/main/resources/excel/batchOpenAccountTemplate.xlsx


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

@@ -112,6 +112,23 @@
         </where>
     </select>
 
+    <insert id="insertValveList">
+        INSERT INTO pay_control_valve
+        (
+            device_id,
+            control_time,
+            control_state
+        )
+        values
+        <foreach collection="valve" item="valve" index="index" separator=",">
+            (
+                #{valve.deviceId,jdbcType=BIGINT},
+                #{valve.controlTime,jdbcType=TIMESTAMP},
+                #{valve.controlState,jdbcType=INTEGER}
+            )
+        </foreach>
+    </insert>
+
     <insert id="insertList">
         INSERT INTO pay_base_customerandmeterrela
         (
@@ -697,4 +714,19 @@
             </if>
         </where>
     </select>
+
+    <insert id="insertValve">
+        insert into pay_control_valve
+        (
+            device_id,
+            control_time,
+            control_state
+        )
+        values
+        (
+            #{deviceId},
+            #{date},
+            #{controlState}
+        )
+    </insert>
 </mapper>

+ 1 - 0
smart-city-platform/src/main/resources/mapper/pay/PayChargeSurveyMapper.xml

@@ -72,6 +72,7 @@
         AS c WHERE a.watermeter_id=c.watermeter_id AND a.read_date = c.read_date)  rd on rd.watermeter_id = scd.id
         <where>
             scd.customer_id =#{customerId} and scd.account_id is not null
+            and (scd.curr_status =1 or scd.curr_status =2)
             <if test="startDate != null">
                 and scd.date_create &gt;=#{startDate}
             </if>

+ 17 - 0
smart-city-platform/src/main/resources/mapper/pay/PayPayReceivableMapper.xml

@@ -506,4 +506,21 @@
         and cancelperson is null
         ) and site_id =#{siteId} and customer_id =#{customerId}
     </delete>
+
+    <select id="getHistoryDebt" resultType="java.math.BigDecimal">
+        select
+            sum(r.debt) as "debt"
+        from pay_pay_receivable r
+        <where>
+            <if test="siteId != null">
+                and  r.site_id =#{siteId}
+            </if>
+            <if test="customerId != null">
+                and r.customer_id =#{customerId}
+            </if>
+            <if test="accountid != null">
+                and r.account_id =#{accountid}
+            </if>
+        </where>
+    </select>
 </mapper>