Browse Source

Merge remote-tracking branch 'origin/20210716' into 20210716

lin 3 năm trước cách đây
mục cha
commit
5e81c41070

+ 126 - 9
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/BigDecimalUtils.java

@@ -12,12 +12,65 @@ import java.math.RoundingMode;
 public class BigDecimalUtils {
 
 
+    /**
+    * 转换BigDecimal,如value==null,直接返回null
+    * @author Andy
+    * @date 17:20 2021/9/9
+    * @param value:
+    * @return java.math.BigDecimal
+    **/
+    public static BigDecimal convert(Object value){
+        if (value == null) {
+            return null;
+        }
+        if (value instanceof BigDecimal) {
+            return (BigDecimal) value;
+        }
+        return new BigDecimal(value.toString());
+    }
+
+    /**
+    * 转换BigDecimal,如value==null,返回初始值0
+    * @author Andy
+    * @date 17:21 2021/9/9
+    * @param value:
+    * @return java.math.BigDecimal
+    **/
+    public static BigDecimal convertDefault(Object value){
+        if (value == null) {
+            return new BigDecimal("0");
+        }
+        if (value instanceof BigDecimal) {
+            return (BigDecimal) value;
+        }
+        return new BigDecimal(value.toString());
+    }
+
+
+    /**
+    * 百分比计算,不进行四舍五入
+    * @author Andy
+    * @date 17:00 2021/9/9
+    * @param value:
+    * @param value2:
+    * @param scale:
+    * @return java.lang.String
+    **/
     public static String percentDivideDown(Object value, Object value2, int scale){
-        return divideDown(value, value2, scale).multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%";
+        return divideDown(value, value2, scale).multiply(convert("100")).stripTrailingZeros().toPlainString() + "%";
     }
 
+    /**
+    * 百分比计算,进行四舍五入
+    * @author Andy
+    * @date 17:01 2021/9/9
+    * @param value:
+    * @param value2:
+    * @param scale:
+    * @return java.lang.String
+    **/
     public static String percentDivide(Object value, Object value2, int scale){
-        return divide(value, value2, scale).multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%";
+        return divide(value, value2, scale).multiply(convert("100")).stripTrailingZeros().toPlainString() + "%";
     }
 
     /**
@@ -28,7 +81,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal divideDown(Object value, Object value2, int scale){
-        return new BigDecimal(value.toString()).divide(new BigDecimal(value2.toString()), scale, RoundingMode.DOWN);
+        return convertDefault(value).divide(convertDefault(value2), scale, RoundingMode.DOWN);
     }
 
     /**
@@ -39,7 +92,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal divide(Object value, Object value2, int scale){
-        return new BigDecimal(value.toString()).divide(new BigDecimal(value2.toString()), scale, RoundingMode.HALF_UP);
+        return convertDefault(value).divide(convertDefault(value2), scale, RoundingMode.HALF_UP);
     }
 
     public static double divideToDouble(Object value, Object value2, int scale){
@@ -47,7 +100,7 @@ public class BigDecimalUtils {
     }
 
     public static BigDecimal setScale(Object value, int scale){
-        return new BigDecimal(value.toString()).setScale(scale, BigDecimal.ROUND_HALF_UP);
+        return convertDefault(value).setScale(scale, BigDecimal.ROUND_HALF_UP);
     }
 
 
@@ -63,7 +116,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal multiply(Object value, Object value2){
-        return multiply(new BigDecimal(value.toString()), new BigDecimal(value2.toString()), 2);
+        return multiply(convertDefault(value), convertDefault(value2), 2);
     }
 
     /**
@@ -75,7 +128,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal subtract(Object value, Object value2){
-        return subtract(new BigDecimal(value.toString()), new BigDecimal(value2.toString()));
+        return subtract(convert(value), convert(value2));
     }
 
     /**
@@ -107,7 +160,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal add(Object value, Object value2){
-        return new BigDecimal(value.toString()).add(new BigDecimal(value2.toString()));
+        return convertDefault(value).add(convertDefault(value2));
     }
 
     /**
@@ -125,7 +178,71 @@ public class BigDecimalUtils {
         if (value == null || value2 == null) {
             return false;
         }
-        return new BigDecimal(value.toString()).compareTo(new BigDecimal(value2.toString())) == 0;
+        return convert(value).compareTo(convert(value2)) == 0;
+    }
+
+    /**
+    * 大于等于
+    * @author Andy
+    * @date 17:04 2021/9/9
+    * @param value:
+    * @param value2:
+    * @return boolean
+    **/
+    public static boolean gte(Object value, Object value2) {
+        if (value == null || value2 == null) {
+            return false;
+        }
+        return convert(value).compareTo(convert(value2)) > -1;
+    }
+
+    /**
+    * 大于
+    * @author Andy
+    * @date 17:04 2021/9/9
+    * @param value:
+    * @param value2:
+    * @return boolean
+    **/
+    public static boolean gt(Object value, Object value2) {
+        if (value == null || value2 == null) {
+            return false;
+        }
+        return convert(value).compareTo(convert(value2)) == 1;
     }
 
+    /**
+    * 小于等于
+    * @author Andy
+    * @date 17:04 2021/9/9
+    * @param value:
+    * @param value2:
+    * @return boolean
+    **/
+    public static boolean lte(Object value, Object value2) {
+        if (value == null || value2 == null) {
+            return false;
+        }
+        return convert(value).compareTo(convert(value2)) < 1;
+    }
+
+    /**
+    * 小于
+    * @author Andy
+    * @date 17:04 2021/9/9
+    * @param value:
+    * @param value2:
+    * @return boolean
+    **/
+    public static boolean lt(Object value, Object value2) {
+        if (value == null || value2 == null) {
+            return false;
+        }
+        return convert(value).compareTo(convert(value2)) == -1;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(new BigDecimal("12.150"));
+        System.out.println(convert(12.150 + ""));
+    }
 }

+ 9 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/DeviceMapper.java

@@ -190,4 +190,13 @@ public interface DeviceMapper {
     List<DeviceVo> queryDeviceInfoList(@Param("deviceNo") String deviceNo, @Param("meterNo") String meterNo, @Param("userCondition") UserCondition userCondition);
 
     List<MeterSyncDto> meterSync(@Param("meterSync") MeterSyncInputDto meterSync);
+
+    /**
+    * 统计小区下有多少个设备数
+    * @author Andy
+    * @date 16:04 2021/9/10
+    * @param communityId:
+    * @return int
+    **/
+    int countDeviceByCommunityId(int communityId);
 }

+ 0 - 3
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/CommunityMapper.xml

@@ -259,10 +259,7 @@
     left join rmcp_org org2 on org2.id = sc.dept_org_id
     where
     sc.status = 1
-    <if test="dto.tenantId != null"> and sc.tenant_id = #{dto.tenantId} </if>
     <if test="dto.name != null and dto.name != ''"> and sc.name like concat('%',#{dto.name} ,'%')</if>
-    <if test="dto.companyOrgId != null"> and sc.company_org_id = #{dto.companyOrgId}</if>
-    <if test="dto.deptOrgId != null"> and sc.dept_org_id = #{dto.deptOrgId}</if>
     <include refid="permissionCondition"/>
     order by sc.create_date desc
   </select>

+ 4 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/DeviceMapper.xml

@@ -835,4 +835,8 @@
     and rd.file_no in
     <foreach collection="meterSync.fileNo" item="item" open="(" separator="," close=")">#{item}</foreach>
   </select>
+
+  <select id="countDeviceByCommunityId" resultType="java.lang.Integer">
+    select count(1) from rmcp_device where community_id = #{communityId} and status = 1
+  </select>
 </mapper>

+ 8 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/CommunityServiceImpl.java

@@ -13,6 +13,7 @@ import com.zcxk.rmcp.api.dto.community.CommunityPageDto;
 import com.zcxk.rmcp.api.enums.RmcpErrorEnum;
 import com.zcxk.rmcp.api.vo.CommunityVo;
 import com.zcxk.rmcp.core.dao.CommunityMapper;
+import com.zcxk.rmcp.core.dao.DeviceMapper;
 import com.zcxk.rmcp.core.entity.Community;
 import com.zcxk.rmcp.web.service.CommunityService;
 import lombok.extern.slf4j.Slf4j;
@@ -38,6 +39,9 @@ public class CommunityServiceImpl implements CommunityService {
     @Resource
     private CommunityMapper communityMapper;
 
+    @Resource
+    private DeviceMapper deviceMapper;
+
     @Override
     public int updateByPrimaryKeySelective(CommunityAddDto communityDto) {
         Community community = new Community();
@@ -86,6 +90,10 @@ public class CommunityServiceImpl implements CommunityService {
         community.setUpdateDate(LocalDateTime.now());
         community.setId(id);
         community.setStatus(StatusEnum.DELETE.getCode());
+        // 小区有绑定设备就不能删除
+        if (deviceMapper.countDeviceByCommunityId(id) > 0 ){
+            throw BusinessException.builder(RmcpErrorEnum.RMCP_UPDATE_FAIL.getStatus(), "删除失败,该小区已绑定设备!");
+        }
         communityMapper.updateByPrimaryKeySelective(community);
     }
 

+ 4 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/DeviceServiceImpl.java

@@ -50,6 +50,8 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.text.NumberFormat;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -434,7 +436,7 @@ public class DeviceServiceImpl implements DeviceService{
      **/
     private void ratioDevice(List<DeviceStatisticsVo.DeviceRatio> ratioList, int total){
         for (DeviceStatisticsVo.DeviceRatio ratio : ratioList) {
-            ratio.setRatio(BigDecimalUtils.percentDivide(ratio.getTotal(), total, 2));
+            ratio.setRatio(BigDecimalUtils.percentDivide(ratio.getTotal(), total, 4));
         }
     }
 
@@ -568,4 +570,5 @@ public class DeviceServiceImpl implements DeviceService{
     public List<DeviceVo> queryDeviceInfoList(String deviceNo, String meterNo) {
         return deviceMapper.queryDeviceInfoList(deviceNo,meterNo,UserUtil.getCurrentUser().getUserCondition());
     }
+
 }

+ 1 - 1
zoniot-rmcp/zoniot-xxljob-client/src/main/java/com/zcxk/xxljob/jobs/MeasurementSettlementRecordHander.java

@@ -137,7 +137,7 @@ public class MeasurementSettlementRecordHander {
         Integer clearingPeriod = measurementSettlement.getBillingCycle();
         Date clearingEndDate = getClearingEndDate(clearingDate);
         Date clearingStartDate = getClearingStartDate(clearingEndDate,clearingPeriod);
-        List<MeterReadRecordVo> recordList =meterReadRecordDao.querySettlementWaterConsumption(device, clearingStartDate, clearingEndDate);//
+        List<MeterReadRecordVo> recordList =meterReadRecordDao.querySettlementWaterConsumption(device.getId(), clearingStartDate, clearingEndDate);
 
         // 3,获取结算周期内开始数据
         MeterReadRecordDTO clearingStartMeterRecord = getClearingStartMeterRecord(device,clearingStartDate,lastClearingRecordItem,recordList);

+ 1 - 0
zoniot-water/zoniot-water-web/pom.xml

@@ -68,6 +68,7 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-amqp</artifactId>
         </dependency>
+
     </dependencies>
 
     <build>

+ 1 - 1
zoniot-water/zoniot-water-web/src/main/java/com/zcxk/water/web/ZoniotWaterApplication.java

@@ -21,7 +21,7 @@ import java.net.UnknownHostException;
 @SpringBootApplication(scanBasePackages="com.zcxk")
 @EnableSwagger2
 @MapperScan("com.zcxk.water.core.dao")
-@EnableFeignClients
+@EnableFeignClients("com.zcxk")
 @Slf4j
 public class ZoniotWaterApplication {
 

+ 4 - 0
zoniot-water/zoniot-water-web/src/main/java/com/zcxk/water/web/config/FeignConfig.java

@@ -16,6 +16,8 @@ import javax.servlet.http.HttpServletRequest;
  */
 @Configuration
 public class FeignConfig implements RequestInterceptor {
+
+
     @Override
     public void apply(RequestTemplate requestTemplate) {
         ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
@@ -26,4 +28,6 @@ public class FeignConfig implements RequestInterceptor {
             }
         }
     }
+
+
 }

+ 5 - 0
zoniot-water/zoniot-water-web/src/main/java/com/zcxk/water/web/controller/WaterPropertyController.java

@@ -1,6 +1,8 @@
 package com.zcxk.water.web.controller;
 
 
+import com.zcxk.rmcp.api.dto.meterreadrecord.MeterReadRecordSyncDto;
+import com.zcxk.rmcp.api.feign.MeterReadRecordClient;
 import com.zcxk.water.core.entity.WaterPropertyEntity;
 import com.zcxk.water.web.service.WaterPropertyService;
 import com.zcxk.core.common.pojo.AjaxMessage;
@@ -12,6 +14,8 @@ import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -72,4 +76,5 @@ public class WaterPropertyController {
         }
         return AjaxMessage.success( waterPropertyService.save(waterPropertyList));
     }
+
 }