|
@@ -1,13 +1,11 @@
|
|
|
package com.tofly.feesapi.bjgl.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.tofly.feesapi.bjgl.entity.dto.*;
|
|
|
import com.tofly.feesapi.common.constant.JfztEnum;
|
|
|
import com.tofly.feesapi.common.constant.JtjslxEnum;
|
|
|
import com.tofly.feesapi.bjgl.entity.YhCbkxx;
|
|
|
import com.tofly.feesapi.bjgl.entity.YhCbkxxLog;
|
|
|
-import com.tofly.feesapi.bjgl.entity.dto.YhCbkxxCbxhUpdate;
|
|
|
-import com.tofly.feesapi.bjgl.entity.dto.YhCbkxxFilter;
|
|
|
-import com.tofly.feesapi.bjgl.entity.dto.YhCbkxxSjUpdate;
|
|
|
import com.tofly.feesapi.bjgl.entity.vo.*;
|
|
|
import com.tofly.feesapi.bjgl.mapper.YhCbkxxMapper;
|
|
|
import com.tofly.feesapi.bjgl.service.YhCbkxxLogService;
|
|
@@ -34,10 +32,7 @@ import java.math.BigDecimal;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -153,35 +148,69 @@ public class YhCbkxxServiceImpl extends ServiceImpl<YhCbkxxMapper, YhCbkxx> impl
|
|
|
public boolean updateCbxh(YhCbkxxCbxhUpdate update, CzyUserDetails czyUserDetails) {
|
|
|
List<String> yhbhs = update.getYhbhs();
|
|
|
if (yhbhs == null || yhbhs.size() == 0) return false;
|
|
|
- for (String yhbh : yhbhs) {
|
|
|
- YhCbkxx yhCbkxx = this.getById(yhbh);
|
|
|
- if (yhCbkxx == null) throw new FeesException("水表档案不存在", FeesErrorCode.BUSINESS_ERROR);
|
|
|
- }
|
|
|
+ Set<String> cbbs = new HashSet<>();
|
|
|
+ Set<String> qbyhbhs = new HashSet<>();
|
|
|
+ qbyhbhs.addAll(yhbhs);
|
|
|
String crdzhYhbh = update.getCrdzhYhbh();
|
|
|
- YhCbkxx insertAfter = this.getById(crdzhYhbh);
|
|
|
- if (insertAfter == null) throw new FeesException("水表档案不存在", FeesErrorCode.BUSINESS_ERROR);
|
|
|
- int cbxh = insertAfter.getCbxh();
|
|
|
- if (cbxh == 0) throw new FeesException("水表档案未分配序号", FeesErrorCode.BUSINESS_ERROR);
|
|
|
- List<String> cbbYhbhs = getCbbYhbhs(crdzhYhbh);
|
|
|
- boolean b = cbbYhbhs.containsAll(yhbhs);
|
|
|
- if (!b) throw new FeesException("不在同一个抄表本(册)", FeesErrorCode.BUSINESS_ERROR);
|
|
|
- YhCbkxx next = getNext(cbbYhbhs, cbxh);
|
|
|
- if (next != null) {
|
|
|
- this.lambdaUpdate()
|
|
|
- .ge(YhCbkxx::getCbxh, next.getCbxh())
|
|
|
- .in(YhCbkxx::getYhbh, cbbYhbhs)
|
|
|
- .setSql("cbxh = cbxh + " + yhbhs.size())
|
|
|
- .update();
|
|
|
- }
|
|
|
- int cbxhStart = cbxh;
|
|
|
- for (String yhbh : yhbhs) {
|
|
|
- this.lambdaUpdate()
|
|
|
- .eq(YhCbkxx::getYhbh, yhbh)
|
|
|
- .set(YhCbkxx::getCbxh, ++cbxhStart).update();
|
|
|
+ if (crdzhYhbh != null) qbyhbhs.add(crdzhYhbh);
|
|
|
+
|
|
|
+ qbyhbhs.forEach(yhbh -> {
|
|
|
+ YhKhjbxx yhKhjbxx = yhKhjbxxService.getById(yhbh);
|
|
|
+ if (yhKhjbxx == null)
|
|
|
+ throw new FeesException(String.format("用户档案不存在:%s", yhbh), FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ String sscbb = yhKhjbxx.getSscbb();
|
|
|
+ if (sscbb == null)
|
|
|
+ throw new FeesException(String.format("用户档案未分配抄表册:%s", yhbh), FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ cbbs.add(sscbb);
|
|
|
+
|
|
|
+ });
|
|
|
+ if (cbbs.size() > 1) throw new FeesException("用户档案不在同一个抄表本(册)", FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ String sscbb = cbbs.stream().findFirst().get();
|
|
|
+
|
|
|
+ if (crdzhYhbh == null) {
|
|
|
+ List<String> cbbYhbhs = getCbbYhbhs(sscbb);
|
|
|
+ int cbxhStart = getMaxCbxh(cbbYhbhs);
|
|
|
+ for (String yhbh : yhbhs) {
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, yhbh)
|
|
|
+ .set(YhCbkxx::getCbxh, ++cbxhStart).update();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ YhCbkxx insertAfter = this.getById(crdzhYhbh);
|
|
|
+ if (insertAfter == null)
|
|
|
+ throw new FeesException(String.format("水表档案不存在:%s", crdzhYhbh), FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ int cbxh = insertAfter.getCbxh();
|
|
|
+ if (cbxh == 0) throw new FeesException("水表档案未分配序号", FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ List<String> cbbYhbhs = getCbbYhbhs(sscbb);
|
|
|
+ YhCbkxx next = getNext(cbbYhbhs, cbxh);
|
|
|
+ if (next != null) {
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .ge(YhCbkxx::getCbxh, next.getCbxh())
|
|
|
+ .in(YhCbkxx::getYhbh, cbbYhbhs)
|
|
|
+ .setSql("cbxh = cbxh + " + yhbhs.size())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+ int cbxhStart = cbxh;
|
|
|
+ for (String yhbh : yhbhs) {
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, yhbh)
|
|
|
+ .set(YhCbkxx::getCbxh, ++cbxhStart).update();
|
|
|
+ }
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 获取抄表本最大抄表序号
|
|
|
+ *
|
|
|
+ * @param cbbYhbhs 抄表本用户编号
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private int getMaxCbxh(List<String> cbbYhbhs) {
|
|
|
+ if (cbbYhbhs == null || cbbYhbhs.isEmpty()) return 0;
|
|
|
+ return this.baseMapper.getMaxCbxh(cbbYhbhs);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public PageResult<YhCbkxxSelect2> getPage(PageDto pageDto, YhCbkxxFilter filter) {
|
|
|
PageDto<YhCbkxxSelect2> page = this.baseMapper.getPage(pageDto, filter);
|
|
@@ -262,15 +291,81 @@ public class YhCbkxxServiceImpl extends ServiceImpl<YhCbkxxMapper, YhCbkxx> impl
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean cancelCbxh(YhCbkxxCbxhCancel cancel, CzyUserDetails czyUserDetails) {
|
|
|
+ List<String> yhbhs = cancel.getYhbhs();
|
|
|
+ yhbhs.forEach(yhbh -> {
|
|
|
+ YhKhjbxx yhKhjbxx = yhKhjbxxService.getById(yhbh);
|
|
|
+ if (yhKhjbxx == null)
|
|
|
+ throw new FeesException(String.format("用户档案不存在:%s", yhbh), FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ YhCbkxx yhCbkxx = this.getById(yhbh);
|
|
|
+ if (yhCbkxx == null)
|
|
|
+ throw new FeesException(String.format("水表档案不存在:%s", yhbh), FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ });
|
|
|
+ for (String yhbh : yhbhs) {
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, yhbh)
|
|
|
+ .set(YhCbkxx::getCbxh, 0).update();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean sxydCbxh(YhCbkxxCbxhSxyd sxyd, CzyUserDetails czyUserDetails) {
|
|
|
+ String yhbh = sxyd.getYhbh();
|
|
|
+ if (yhbh == null) return false;
|
|
|
+ YhKhjbxx yhKhjbxx = yhKhjbxxService.getById(yhbh);
|
|
|
+ if (yhKhjbxx == null)
|
|
|
+ throw new FeesException(String.format("用户档案不存在:%s", yhbh), FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ Boolean ydfx = sxyd.getYdfx();
|
|
|
+ String sscbb = yhKhjbxx.getSscbb();
|
|
|
+ if (sscbb == null)
|
|
|
+ throw new FeesException(String.format("用户档案未分配抄表册:%s", yhbh), FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ YhCbkxx yhCbkxx = this.getById(yhbh);
|
|
|
+ if (yhCbkxx == null)
|
|
|
+ throw new FeesException(String.format("水表档案不存在:%s", yhbh), FeesErrorCode.BUSINESS_ERROR);
|
|
|
+ if (ydfx) {
|
|
|
+ int cbxh = yhCbkxx.getCbxh();
|
|
|
+ YhCbkxx up = this.baseMapper.getUp(sscbb, cbxh);
|
|
|
+ if (up != null) {
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, yhCbkxx.getYhbh())
|
|
|
+ .set(YhCbkxx::getCbxh, up.getCbxh()).update();
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, up.getYhbh())
|
|
|
+ .set(YhCbkxx::getCbxh, cbxh).update();
|
|
|
+ } else {
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, yhCbkxx.getYhbh())
|
|
|
+ .set(YhCbkxx::getCbxh, cbxh - 1).update();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ int cbxh = yhCbkxx.getCbxh();
|
|
|
+ YhCbkxx down = this.baseMapper.getDown(sscbb, cbxh);
|
|
|
+ if (down != null) {
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, yhCbkxx.getYhbh())
|
|
|
+ .set(YhCbkxx::getCbxh, down.getCbxh()).update();
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, down.getYhbh())
|
|
|
+ .set(YhCbkxx::getCbxh, cbxh).update();
|
|
|
+ } else {
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(YhCbkxx::getYhbh, yhCbkxx.getYhbh())
|
|
|
+ .set(YhCbkxx::getCbxh, cbxh + 1).update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 获取用户编号所在抄表本(册)的所有用户编号
|
|
|
*
|
|
|
- * @param yhbh 用户编号
|
|
|
+ * @param sscbb 用户编号
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<String> getCbbYhbhs(String yhbh) {
|
|
|
- YhKhjbxx yhKhjbxx = yhKhjbxxService.getById(yhbh);
|
|
|
- String sscbb = yhKhjbxx.getSscbb();
|
|
|
+ private List<String> getCbbYhbhs(String sscbb) {
|
|
|
+
|
|
|
if (sscbb == null) return new ArrayList<>();
|
|
|
List<YhKhjbxx> list = yhKhjbxxService.lambdaQuery()
|
|
|
.eq(YhKhjbxx::getSscbb, sscbb)
|
|
@@ -301,6 +396,7 @@ public class YhCbkxxServiceImpl extends ServiceImpl<YhCbkxxMapper, YhCbkxx> impl
|
|
|
|
|
|
|
|
|
* 检查基本参数
|
|
|
+ *
|
|
|
* @param cbkxx
|
|
|
*/
|
|
|
private void checkJbcs(YhCbkxx cbkxx) {
|