Ver código fonte

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

‘linchangsheng’ 4 meses atrás
pai
commit
6d368f4a09

+ 70 - 14
mall-server-api/src/main/java/com/gree/mall/manager/logic/workorder/AppraiseRelaLogic.java

@@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -207,6 +208,17 @@ public class AppraiseRelaLogic {
     public void applySubmit(PgAppraiseApplyBean bean) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
         boolean isAdd = StringUtils.isBlank(bean.getId());
+
+        if (!isAdd) {
+            // 有id查询是否有记录
+            final PgAppraiseApply apply = pgAppraiseApplyService.getById(bean.getId());
+            if (Objects.isNull(apply)) {
+                // 没有记录置空新建
+                bean.setId(null);
+                isAdd = true;
+            }
+        }
+
         if (StringUtils.isBlank(bean.getOrderBaseId())) {
             throw new RemoteServiceException("工单编号不能为空");
         }
@@ -290,24 +302,30 @@ public class AppraiseRelaLogic {
             throw new RemoteServiceException("已有中差评申诉记录, 提交失败");
         }
 
-        waitCount = pgAppraiseApplyService.lambdaQuery()
-                .eq(PgAppraiseApply::getOrderBaseId, bean.getOrderBaseId())
-                .eq(PgAppraiseApply::getStatus, AppraiseApplyStatusEnum.OK.getKey())
-                .ne(!isAdd, PgAppraiseApply::getId, bean.getId())
-                .count();
-        if (waitCount > 0) {
-            throw new RemoteServiceException("已有中差评申诉“审核通过”记录, 提交失败");
-        }
+//        waitCount = pgAppraiseApplyService.lambdaQuery()
+//                .eq(PgAppraiseApply::getOrderBaseId, bean.getOrderBaseId())
+//                .eq(PgAppraiseApply::getStatus, AppraiseApplyStatusEnum.OK.getKey())
+//                .ne(!isAdd, PgAppraiseApply::getId, bean.getId())
+//                .count();
+//        if (waitCount > 0) {
+//            throw new RemoteServiceException("已有中差评申诉“审核通过”记录, 提交失败");
+//        }
 
         bean.setAppraiseStatus(orderBase.getAppraiseStatus());
         bean.setAppraiseSource(orderBase.getAppraiseSource());
+        bean.setAddress(orderBase.getAddress());
         bean.setStatus(AppraiseApplyStatusEnum.WAIT_CENTER.getKey());
         bean.setApplyTime(DateUtil.date());
         bean.setApplyBy(adminUser.getNickName());
         bean.setCompanyWechatId(orderBase.getCompanyWechatId());
         bean.setCompanyWechatName(orderBase.getCompanyWechatName());
+        bean.setOverTime(orderBase.getWebsitOverTime());
+
+        if (Objects.isNull(bean.getOverTime())) {
+            // 网点报完工时间为空取师傅报完工时间
+            bean.setOverTime(orderBase.getOverTime());
+        }
         if (isAdd) {
-            bean.setOverTime(Objects.isNull(orderBase.getOverTime()) ? orderBase.getOverTime() : orderBase.getWebsitOverTime());
             bean.insert();
             orderBaseLogic.dow(orderBase.getId());
         } else {
@@ -440,11 +458,20 @@ public class AppraiseRelaLogic {
 
         List<PgAppraiseApply> applyList = pgAppraiseApplyService.lambdaQuery()
                 .in(PgAppraiseApply::getId, ids)
-                .in(PgAppraiseApply::getStatus, AppraiseApplyStatusEnum.OK.getKey(), AppraiseApplyStatusEnum.WAIT_CENTER.getKey())
-                .isNull(PgAppraiseApply::getRejectTime)
-                .isNull(PgAppraiseApply::getCloseBy)
                 .list();
 
+        for (PgAppraiseApply apply : applyList) {
+            if (Objects.nonNull(apply.getRejectTime())) {
+                throw new RemoteServiceException(apply.getOrderBaseId() + "工单编号的申诉记录有“驳回可重申诉信息”,不能操作“驳回可再申诉”");
+            }
+            if (Objects.nonNull(apply.getCloseTime())) {
+                throw new RemoteServiceException(apply.getOrderBaseId() + "工单编号的申诉记录有“驳回不可再申诉信息”,不能操作“驳回可再申诉”");
+            }
+            if (!apply.getStatus().equals(AppraiseApplyStatusEnum.OK.getKey())) {
+                throw new RemoteServiceException(apply.getOrderBaseId() + "工单编号的申诉记录非“审核通过”,不能操作“驳回可再申诉”");
+            }
+        }
+
         final List<String> normIds = applyList.stream().map(PgAppraiseApply::getId).collect(Collectors.toList());
 
         pgAppraiseApplyService.lambdaUpdate()
@@ -504,12 +531,41 @@ public class AppraiseRelaLogic {
             throw new RemoteServiceException("请选择记录");
         }
         AdminUserCom adminUser = commonLogic.getAdminUser();
+
+        final List<PgAppraiseApply> applyList = pgAppraiseApplyService.lambdaQuery()
+                .in(PgAppraiseApply::getId, ids)
+                .eq(PgAppraiseApply::getStatus, AppraiseApplyStatusEnum.OK.getKey())
+                .orderByAsc(PgAppraiseApply::getApplyTime)
+                .list();
+
+        if (CollectionUtil.isNotEmpty(applyList)) {
+            final List<String> orderIds = applyList.stream().map(PgAppraiseApply::getOrderBaseId).collect(Collectors.toList());
+            final Map<String, PgAppraiseApply> applyMap = applyList.stream().collect(Collectors.toMap(PgAppraiseApply::getOrderBaseId, Function.identity(), (key1, key2) -> key2));
+            for (PgAppraiseApply apply : applyList) {
+                if (!apply.getStatus().equals(AppraiseApplyStatusEnum.OK.getKey())) {
+                    throw new RemoteServiceException(apply.getOrderBaseId() + "工单编号的申诉记录非“审核通过”,不能操作“驳回不可再申诉”");
+                }
+                apply.setExamineResult(apply.getAppraiseStatus());
+            }
+            pgAppraiseApplyService.saveBatch(applyList);
+
+            for (String orderId : orderIds) {
+                final PgAppraiseApply apply = applyMap.get(orderId);
+                if (Objects.nonNull(apply)) {
+                    pgOrderBaseService.lambdaUpdate()
+                            .set(PgOrderBase::getAppraiseApplyResult, apply.getAppraiseStatus())
+                            .eq(PgOrderBase::getId, orderId)
+                            .update();
+                }
+            }
+        }
+
+
         pgAppraiseApplyService.lambdaUpdate()
-                .set(PgAppraiseApply::getStatus, AppraiseApplyStatusEnum.OK.getKey())
                 .set(PgAppraiseApply::getCloseBy, adminUser.getNickName())
                 .set(PgAppraiseApply::getCloseTime, DateUtil.date())
                 .in(PgAppraiseApply::getId, ids)
-                .in(PgAppraiseApply::getStatus, AppraiseApplyStatusEnum.WAIT.getKey(), AppraiseApplyStatusEnum.WAIT_CENTER.getKey())
+                .eq(PgAppraiseApply::getStatus, AppraiseApplyStatusEnum.OK.getKey())
                 .update();
     }