Browse Source

feature 代码提交

xiahan 3 months ago
parent
commit
9f70cd9594

+ 13 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/MobileService.java

@@ -0,0 +1,13 @@
+package com.rongwei.zhsw.system.service;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * MobileService class
+ *
+ * @author XH
+ * @date 2025/04/10
+ */
+@Service
+public interface MobileService {
+}

+ 15 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/WaterUsageService.java

@@ -0,0 +1,15 @@
+package com.rongwei.zhsw.system.service;
+
+import com.rongwe.zhsw.system.domain.SwWaterUsageEntryDo;
+import com.rongwe.zhsw.system.vo.ManualMeterReadingVo;
+import com.rongwei.rwcommon.base.R;
+
+/**
+ * WaterUsageServiceImpl class
+ *
+ * @author XH
+ * @date 2025/04/14
+ */
+public interface WaterUsageService {
+    R meterReading(ManualMeterReadingVo manualMeterReadingVo);
+}

+ 1 - 1
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/BillGenerationServiceImpl.java

@@ -77,7 +77,7 @@ public class BillGenerationServiceImpl {
 
     public void generateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList) {
         String dsKey = ContextHolder.getValue("dsKey");
-        log.info("上下文信息为:{},dsKey:{}", RequestContextHolder.getRequestAttributes(), dsKey);
+        log.info("dsKey:{}",  dsKey);
         log.debug("需要生成账单的抄表记录为:{}", swWaterUsageEntryDoList);
         // 对数据按照抄表日期排序
         List<SwWaterUsageEntryDo> collect = swWaterUsageEntryDoList.stream()

+ 12 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/MobileServiceImppl.java

@@ -0,0 +1,12 @@
+package com.rongwei.zhsw.system.service.impl;
+
+import com.rongwei.zhsw.system.service.MobileService;
+
+/**
+ * MobileServiceImppl class
+ *
+ * @author XH
+ * @date 2025/04/10
+ */
+public class MobileServiceImppl implements MobileService {
+}

+ 89 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/WaterUsageServiceImpl.java

@@ -0,0 +1,89 @@
+package com.rongwei.zhsw.system.service.impl;
+
+import com.rongwe.zhsw.system.domain.SwUserManagementDo;
+import com.rongwe.zhsw.system.domain.SwWaterUsageEntryDo;
+import com.rongwe.zhsw.system.vo.ManualMeterReadingVo;
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommon.base.exception.CustomException;
+import com.rongwei.rwcommon.utils.SecurityUtil;
+import com.rongwei.zhsw.system.config.ContextHolder;
+import com.rongwei.zhsw.system.service.WaterUsageService;
+import com.rongwei.zhsw.system.utils.ZHSWCommonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+
+/**
+ * WaterUsageServiceImpl class
+ *
+ * @author XH
+ * @date 2025/04/14
+ */
+@Service
+public class WaterUsageServiceImpl implements WaterUsageService {
+    private static final Logger log = LoggerFactory.getLogger(WaterUsageServiceImpl.class);
+    @Autowired
+    private SwWaterUsageEntryServiceImpl swWaterUsageEntryService;
+    @Autowired
+    private SwUserManagementServiceImpl swUserManagementService;
+    @Autowired
+    private BillGenerationServiceImpl billGenerationService;
+
+    @Transactional
+    @Override
+    public R meterReading(ManualMeterReadingVo manualMeterReadingVo) {
+        log.error("开始生成移动端抄表记录:{}", manualMeterReadingVo);
+
+        SwUserManagementDo swUserManagementDo = swUserManagementService.getById(manualMeterReadingVo.getUserId());
+        if (swUserManagementDo == null) {
+            throw new CustomException("无法获取用户信息");
+        }
+        if (manualMeterReadingVo.getThisReading().compareTo(BigDecimal.ZERO) < 0) {
+            throw new CustomException("本次抄表度数小于0");
+        }
+        // 上次抄表数
+        BigDecimal lastReading = swUserManagementDo.getLastmeterreading() == null ? BigDecimal.ZERO : swUserManagementDo.getLastmeterreading();
+        SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
+        LocalDate date = LocalDate.now();
+        SwWaterUsageEntryDo swWaterUsageEntryDo = new SwWaterUsageEntryDo();
+        ZHSWCommonUtils.initModelGeneralParameters(swWaterUsageEntryDo, currentUser);
+        swWaterUsageEntryDo.setId(SecurityUtil.getUUID());
+        swWaterUsageEntryDo.setUsernumber(swUserManagementDo.getUsernumber());
+        swWaterUsageEntryDo.setUsername(swUserManagementDo.getUsername());
+        swWaterUsageEntryDo.setThisreading(manualMeterReadingVo.getThisReading());
+        swWaterUsageEntryDo.setCommunityname(swUserManagementDo.getVillagename());
+        swWaterUsageEntryDo.setAddress(swUserManagementDo.getAddress());
+        swWaterUsageEntryDo.setCurrentreadingdate(new Date());
+        swWaterUsageEntryDo.setReadingsource("3");
+        swWaterUsageEntryDo.setUserid(swUserManagementDo.getId());
+        swWaterUsageEntryDo.setCommunitycode(swUserManagementDo.getVolumeno());
+        swWaterUsageEntryDo.setYear(date.getYear());
+        swWaterUsageEntryDo.setMonth(date.getMonthValue());
+        swWaterUsageEntryDo.setLastreading(lastReading);
+        swWaterUsageEntryDo.setLastreadingdate(swUserManagementDo.getLastmeterreaddate());
+        swWaterUsageEntryDo.setState("0");
+        //当前用水
+        BigDecimal waterConsumption;
+        // 本次大于上次
+        if (manualMeterReadingVo.getThisReading().compareTo(lastReading) >= 0) {
+            waterConsumption = manualMeterReadingVo.getThisReading().subtract(lastReading);
+        } else {
+            // 本次抄表数小于上次抄表数 用表具的最大值-上次抄表数+本次抄表数
+            waterConsumption = swUserManagementDo.getMetermaxvalue().subtract(lastReading).add(manualMeterReadingVo.getThisReading()).add(BigDecimal.ONE);
+        }
+        swWaterUsageEntryDo.setWaterusage(waterConsumption);
+        swWaterUsageEntryService.save(swWaterUsageEntryDo);
+        billGenerationService.generateBill(Collections.singletonList(swWaterUsageEntryDo));
+        return R.ok();
+    }
+
+}

+ 1 - 1
zhsw-entity/src/main/java/com/rongwe/zhsw/system/domain/SwWaterUsageEntryDo.java

@@ -145,7 +145,7 @@ public class SwWaterUsageEntryDo extends BaseDo implements Serializable {
      * 用水量
      */
     @JsonProperty("WATERUSAGE")
-    private Decimal waterusage;
+    private BigDecimal waterusage;
 
 }
 

+ 17 - 0
zhsw-entity/src/main/java/com/rongwe/zhsw/system/vo/ManualMeterReadingVo.java

@@ -0,0 +1,17 @@
+package com.rongwe.zhsw.system.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * ManualMeterReadingVo class
+ *
+ * @author XH
+ * @date 2025/04/14
+ */
+@Data
+public class ManualMeterReadingVo {
+    private String userId;
+    private BigDecimal thisReading;
+}

+ 17 - 0
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/MobileController.java

@@ -0,0 +1,17 @@
+package com.rongwei.zhsw.system.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * MobileController class
+ *
+ * @author XH
+ * @date 2025/04/10
+ */
+@RestController
+@RequestMapping("/mobile")
+public class MobileController {
+
+
+}

+ 34 - 0
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/weChat/WaterUsageController.java

@@ -0,0 +1,34 @@
+package com.rongwei.zhsw.system.controller.weChat;
+
+import com.rongwe.zhsw.system.domain.SwWaterUsageEntryDo;
+import com.rongwe.zhsw.system.vo.ManualMeterReadingVo;
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.zhsw.system.service.impl.WaterUsageServiceImpl;
+import org.checkerframework.checker.units.qual.A;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * WaterUsageController class
+ *
+ * @author XH
+ * @date 2025/04/14
+ */
+
+@RestController
+@RequestMapping("/water")
+public class WaterUsageController {
+
+    @Autowired
+    private WaterUsageServiceImpl waterUsageService;
+
+    @PostMapping("/meter/reading")
+    private R meterReading(@RequestBody ManualMeterReadingVo manualMeterReadingVo) {
+     return  waterUsageService.meterReading(manualMeterReadingVo);
+    }
+}