|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|