فهرست منبع

#MOD 设备故障 转售后

tanbin 1 سال پیش
والد
کامیت
89bb79acf4

+ 3 - 0
device-api-service/src/main/java/com/xy/entity/DeviceFaultInfo.java

@@ -68,5 +68,8 @@ public class DeviceFaultInfo implements Serializable {
     @ApiModelProperty(value = "故障级别-字典:device_fault_level")
     private Integer faultLevel;
 
+    @ApiModelProperty(value = "是否转售后")
+    private Boolean toAfterSale;
+
 
 }

+ 6 - 1
device-api-service/src/main/java/com/xy/service/DeviceFaultInfoFlowServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.system.SystemUtil;
 import com.xy.dto.SysWorkUser.ListDto;
 import com.xy.dto.SysWorkUser.SysWorkVo;
 import com.xy.entity.DeviceFaultInfoFlow;
+import com.xy.error.CommRuntimeException;
 import com.xy.mapper.DeviceFaultInfoFlowMapper;
 import com.xy.service.DeviceFaultInfoFlowService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -79,12 +80,16 @@ public class DeviceFaultInfoFlowServiceImpl extends ServiceImpl<DeviceFaultInfoF
     @PostMapping("save")
     @ApiOperation("添加")
     public R save(@RequestBody @Validated DeviceFaultInfoFlowDto.Save save) {
+        String content = save.getContent();
+        if(StrUtil.isEmpty(content)){
+            throw new CommRuntimeException("回复内容不可为空");
+        }
         DeviceFaultInfoFlow saveInfo = copy(DeviceFaultInfoFlow.class, save);
         Long operatorId = AuthorizeUtils.getLoginId(Long.class);
         Long sysId = AuthorizeUtils.getSysId();
         List<String> roleCodes = AuthorizeUtils.getRoleCodes(sysId);
 //        List<Long> roleIds = AuthorizeUtils.getRoleIds(sysId);
-        R<List<SysWorkVo>> listR = R.feignCheck(sysWorkUserService.list(new ListDto().setId(CollUtil.newArrayList(operatorId))));
+        R<List<SysWorkVo>> listR = R.feignCheck(sysWorkUserService.list(new ListDto().setId(CollUtil.newArrayList(operatorId)).setSysId(sysId)));
         List<SysWorkVo> data = listR.getData();
         SysWorkVo sysWorkVo = data.get(0);
         String roleNames = CollUtil.join(sysWorkVo.getRoleNames(), StrUtil.COMMA);

+ 29 - 6
device-api-service/src/main/java/com/xy/service/DeviceFaultInfoServiceImpl.java

@@ -1,13 +1,18 @@
 package com.xy.service;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xy.collections.list.JArrayList;
 import com.xy.collections.map.JMap;
+import com.xy.consts.CommConsts;
 import com.xy.dto.DeviceFaultInfoDto;
+import com.xy.dto.DeviceFaultInfoFlowDto;
+import com.xy.dto.SysWorkUser.ListDto;
+import com.xy.dto.SysWorkUser.SysWorkVo;
 import com.xy.dto.be.MercDto;
 import com.xy.entity.DeviceFaultInfo;
 import com.xy.entity.DeviceFaultLog;
@@ -15,14 +20,12 @@ import com.xy.entity.DeviceInfo;
 import com.xy.error.CommRuntimeException;
 import com.xy.mapper.DeviceFaultInfoMapper;
 import com.xy.service.be.MercService;
-import com.xy.utils.Emptys;
-import com.xy.utils.MybatisPlusQuery;
-import com.xy.utils.PageBean;
-import com.xy.utils.R;
+import com.xy.utils.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -52,6 +55,8 @@ public class DeviceFaultInfoServiceImpl extends ServiceImpl<DeviceFaultInfoMappe
     private final DeviceFaultLogServiceImpl deviceFaultLogService;
     private final MercService mercService;
     private final DeviceInfoServiceImpl deviceInfoService;
+    private final DeviceFaultInfoFlowServiceImpl deviceFaultInfoFlowService;
+    private final SysWorkUserService sysWorkUserService;
 
     @PostMapping("obj")
     @ApiOperation("对象查询")
@@ -82,6 +87,14 @@ public class DeviceFaultInfoServiceImpl extends ServiceImpl<DeviceFaultInfoMappe
                 .eqWrapper(page, DeviceFaultInfo.class).build()
                 .ge(beginTime != null, DeviceFaultInfo::getCreateTime, beginTime)
                 .le(endTime != null, DeviceFaultInfo::getCreateTime, endTime);
+
+        Long sysId = AuthorizeUtils.getSysId();
+        List<String> roleCodes = AuthorizeUtils.getRoleCodes(sysId);
+        //售后角色只看转售后的,其他角色看所有
+        if(roleCodes.contains(CommConsts.MERC_SH_ADMIN)){
+            lambdaQueryWrapper.eq(DeviceFaultInfo::getToAfterSale,true);
+        }
+
         IPage<DeviceFaultInfo> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
         PageBean<DeviceFaultInfoDto.Vo> data = toPageBean(DeviceFaultInfoDto.Vo.class, iPage);
         List<DeviceFaultInfoDto.Vo> records = data.getRecords();
@@ -120,20 +133,30 @@ public class DeviceFaultInfoServiceImpl extends ServiceImpl<DeviceFaultInfoMappe
     @PostMapping("resolve")
     @ApiOperation("标记已解决")
     public R resolve(@RequestBody @Validated DeviceFaultInfoDto.Update update) {
-        DeviceFaultInfo deviceFaultInfo = this.getById(update.getFaultId());
+        resolveDone(update);
+        return R.ok();
+    }
+    @Transactional(rollbackFor = Exception.class)
+    public void resolveDone( DeviceFaultInfoDto.Update update){
+        Long faultId = update.getFaultId();
+        DeviceFaultInfo deviceFaultInfo = this.getById(faultId);
         if (deviceFaultInfo == null) {
             throw new CommRuntimeException("操作对象不存在!");
         }
         DeviceFaultInfo updateInfo = copy(DeviceFaultInfo.class, update);
         updateInfo.setState(true);
+        updateInfo.setResolveTime(LocalDateTime.now());
         updateInfo.setFaultLevel(-1);
         boolean b = updateById(updateInfo);
         if (b) {
+            DeviceFaultInfoFlowDto.Save save = new DeviceFaultInfoFlowDto.Save();
+            save.setFaultId(faultId);
+            save.setContent("故障已解决");
+            deviceFaultInfoFlowService.save(save);
             //清理日志 故障信息表标记已解决,清除日志表中对应设备事件在标记已解决时间之前所有事件。
             deviceFaultLogService.remove(Wrappers.<DeviceFaultLog>lambdaUpdate().le(DeviceFaultLog::getEventTime, LocalDateTime.now()));
             //更新故障等级为正常
             deviceInfoService.updateById(new DeviceInfo().setDeviceId(deviceFaultInfo.getDeviceId()).setFaultLevel(-1));
         }
-        return R.ok();
     }
 }

+ 6 - 1
device-api-service/src/main/java/com/xy/service/DeviceMqttConsumerImpl.java

@@ -232,7 +232,7 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
                 Long minuteNum = config.getMinuteNum();
                 Integer faultLevel = config.getFaultLevel();
                 Long monitorId = config.getMonitorId();
-
+                Boolean toAfterSale = config.getToAfterSale();
                 // 获取当前时间
                 Date now = DateUtil.date();
 
@@ -261,6 +261,10 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
                         if (faultLevel1.intValue() < faultLevel) {
                             //小于,当前故障级别,更新
                             deviceFaultInfo.setFaultLevel(faultLevel);
+                            if(toAfterSale){
+                                //如果配置了自动转售后,则更新
+                                deviceFaultInfo.setToAfterSale(toAfterSale);
+                            }
                             deviceInfoService.updateById(new DeviceInfo().setDeviceId(deviceId).setFaultLevel(faultLevel));
                         }
                         //累加次数
@@ -276,6 +280,7 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
                                 .setEventCode(code)
                                 .setEventNum(count.intValue())
                                 .setMonitorId(monitorId)
+                                .setToAfterSale(toAfterSale)
                         );
                         deviceInfoService.updateById(new DeviceInfo().setDeviceId(deviceId).setFaultLevel(faultLevel));
                     }

+ 2 - 0
device-api/src/main/java/com/xy/dto/DeviceFaultInfoDto.java

@@ -99,6 +99,8 @@ public class DeviceFaultInfoDto {
         @ApiModelProperty(value = "监控ID")
         private Long monitorId;
 
+        @ApiModelProperty(value = "是否转售后")
+        private Boolean toAfterSale;
 
     }