|
@@ -0,0 +1,92 @@
|
|
|
+package com.rongwei.zhsw.system.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.rongwe.zhsw.system.domain.SwBillManagementPaidDo;
|
|
|
+import com.rongwe.zhsw.system.domain.SwBillManagementUnpaidDo;
|
|
|
+import com.rongwe.zhsw.system.domain.SwUserManagementDo;
|
|
|
+import com.rongwe.zhsw.system.domain.SwWaterUsageEntryDo;
|
|
|
+import com.rongwei.rwcommon.base.BaseDo;
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.UtilsChecks;
|
|
|
+import com.rongwei.zhsw.system.service.MeterReadingService;
|
|
|
+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.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * MeterReadingServiceImpl class
|
|
|
+ *
|
|
|
+ * @author XH
|
|
|
+ * @date 2025/03/28
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MeterReadingServiceImpl implements MeterReadingService {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(MeterReadingServiceImpl.class);
|
|
|
+ @Autowired
|
|
|
+ private SwWaterUsageEntryServiceImpl swWaterUsageEntryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SwUserManagementServiceImpl swUserManagementService;
|
|
|
+ @Autowired
|
|
|
+ private SwBillManagementUnpaidServiceImpl swBillManagementUnpaidService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SwBillManagementPaidServiceImpl swBillManagementPaidService;
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R removeRecord(String id) {
|
|
|
+ log.info("开始删除抄表记录:{}",id);
|
|
|
+ // 获取抄表记录
|
|
|
+ SwWaterUsageEntryDo swWaterUsageEntryDo = swWaterUsageEntryService.getById(id);
|
|
|
+ // 本次记录由换表生成无法删除
|
|
|
+ UtilsChecks.parameterCheck(()->"9".equals(swWaterUsageEntryDo.getReadingsource()),"本次抄表记录由换表生成无法删除","本次抄表记录由换表生成无法删除");
|
|
|
+ // 户号信息
|
|
|
+ String userNumber = swWaterUsageEntryDo.getUsernumber();
|
|
|
+ // 判断改抄表记录是否是最新的抄表
|
|
|
+ List<SwWaterUsageEntryDo> swWaterUsageEntryDoList = swWaterUsageEntryService.list(new LambdaQueryWrapper<SwWaterUsageEntryDo>()
|
|
|
+ .eq(SwWaterUsageEntryDo::getUsernumber, userNumber)
|
|
|
+ .gt(SwWaterUsageEntryDo::getCurrentreadingdate, swWaterUsageEntryDo.getCurrentreadingdate())
|
|
|
+ );
|
|
|
+ if(!swWaterUsageEntryDoList.isEmpty()){
|
|
|
+ log.error("当前抄表记录不是改户号下最新的一条记录,最新的记录为:{}",swWaterUsageEntryDoList.get(0).getId());
|
|
|
+ throw new CustomException("该抄表记录不是该户号最新的抄表记录,不允许删除!");
|
|
|
+ }
|
|
|
+ // 如果未生成直接删除并更新用户表信息
|
|
|
+ if(1!=swWaterUsageEntryDo.getState()){
|
|
|
+ swUserManagementService.update(new LambdaUpdateWrapper<SwUserManagementDo>()
|
|
|
+ .eq(SwUserManagementDo::getUsernumber,userNumber)
|
|
|
+ .set(SwUserManagementDo::getLastmeterreaddate,swWaterUsageEntryDo.getLastreadingdate())
|
|
|
+ .set(SwUserManagementDo::getLastmeterreading,swWaterUsageEntryDo.getLastreading()));
|
|
|
+ return R.ok("该抄表记录已删除");
|
|
|
+ }
|
|
|
+ // 未缴账单
|
|
|
+ SwBillManagementUnpaidDo unpaidDo = swBillManagementUnpaidService.getOne(new LambdaQueryWrapper<SwBillManagementUnpaidDo>()
|
|
|
+ .eq(SwBillManagementUnpaidDo::getUsernumber, userNumber)
|
|
|
+ .eq(SwBillManagementUnpaidDo::getYear, swWaterUsageEntryDo.getYear())
|
|
|
+ .eq(SwBillManagementUnpaidDo::getPaymentrecordid, id));
|
|
|
+ // 已缴账单
|
|
|
+ SwBillManagementPaidDo paidDo = swBillManagementPaidService.getOne(new LambdaQueryWrapper<SwBillManagementPaidDo>()
|
|
|
+ .eq(SwBillManagementPaidDo::getUsernumber, userNumber)
|
|
|
+ .eq(SwBillManagementPaidDo::getYear, swWaterUsageEntryDo.getYear())
|
|
|
+ .eq(SwBillManagementPaidDo::getPaymentrecordid, id));
|
|
|
+ if(paidDo!=null){
|
|
|
+ log.error("该账单已缴费");
|
|
|
+ return R.ok("该抄表记录已存在已缴账单,不允许删除");
|
|
|
+ }
|
|
|
+ if(unpaidDo!=null){
|
|
|
+ swBillManagementUnpaidService.removeById(unpaidDo.getId());
|
|
|
+ }
|
|
|
+ swWaterUsageEntryService.removeById(id);
|
|
|
+ swUserManagementService.update(new LambdaUpdateWrapper<SwUserManagementDo>()
|
|
|
+ .eq(SwUserManagementDo::getUsernumber,userNumber)
|
|
|
+ .set(SwUserManagementDo::getLastmeterreaddate,swWaterUsageEntryDo.getLastreadingdate())
|
|
|
+ .set(SwUserManagementDo::getLastmeterreading,swWaterUsageEntryDo.getLastreading()));
|
|
|
+ return R.ok("该抄表记录已删除,且对应预收或待缴账单也已删除");
|
|
|
+ }
|
|
|
+}
|