|
@@ -1,27 +1,62 @@
|
|
|
package cn.com.ty.lift.business.maintenance.service;
|
|
|
|
|
|
+import cn.com.ty.lift.business.emergency.dto.RepairRequest;
|
|
|
+import cn.com.ty.lift.business.emergency.entity.EmergencyRepair;
|
|
|
+import cn.com.ty.lift.business.emergency.entity.LiftFault;
|
|
|
+import cn.com.ty.lift.business.emergency.service.EmergencyRepairService;
|
|
|
+import cn.com.ty.lift.business.emergency.service.ErRecordCostService;
|
|
|
+import cn.com.ty.lift.business.emergency.service.ErRecordImgService;
|
|
|
+import cn.com.ty.lift.business.emergency.service.LiftFaultService;
|
|
|
+import cn.com.ty.lift.business.evaluation.dao.entity.Evaluation;
|
|
|
+import cn.com.ty.lift.business.evaluation.service.EvaluationService;
|
|
|
+import cn.com.ty.lift.business.library.dao.entity.PlatformCompanyLiftRelevance;
|
|
|
+import cn.com.ty.lift.business.library.service.PlatformCompanyLiftRelevanceService;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.dto.MaintenancePlanMonthTaskNum;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.request.PropertyMaintenanceVO;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.request.PropertyVo;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.response.DynamicMessageResponse;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.response.PropertyCalendarResponse;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.response.PropertyMtResponse;
|
|
|
+import cn.com.ty.lift.business.maintenance.dao.entity.model.response.RepairResponse;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.mapper.PropertyMaintenanceMapper;
|
|
|
+import cn.com.ty.lift.business.project.dao.entity.Region;
|
|
|
+import cn.com.ty.lift.business.push.service.PushUserService;
|
|
|
import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
+import cn.com.ty.lift.common.constants.CommonEnum;
|
|
|
+import cn.com.ty.lift.common.constants.WebSocketConstants;
|
|
|
+import cn.com.ty.lift.common.model.PushMessage;
|
|
|
+import cn.com.ty.lift.common.model.PushUserInfo;
|
|
|
+import cn.com.ty.lift.common.utils.SendMessageUtil;
|
|
|
+import cn.com.ty.lift.common.utils.ValuePool;
|
|
|
+import cn.com.ty.lift.common.verify.Validate;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import cn.hutool.core.collection.IterUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.jms.core.JmsMessagingTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@Slf4j
|
|
|
public class PropertyService {
|
|
|
private final PropertyMaintenanceMapper propertyMaintenanceMapper;
|
|
|
+ private final EmergencyRepairService emergencyRepairService;
|
|
|
+ private final PlatformCompanyLiftRelevanceService platformCompanyLiftRelevanceService;
|
|
|
+ private final JmsMessagingTemplate jmsMessagingTemplate;
|
|
|
+ private final PushUserService pushUserService;
|
|
|
+ private final EvaluationService evaluationService;
|
|
|
+ private final ErRecordCostService erRecordCostService;
|
|
|
+ private final ErRecordImgService erRecordImgService;
|
|
|
+ private final LiftFaultService liftFaultService;
|
|
|
|
|
|
/**
|
|
|
* @param propertyMaintenanceVO userId用户id,yearMonth年月 例202005即2020年5月
|
|
@@ -182,7 +217,124 @@ public class PropertyService {
|
|
|
* @param propertyVo userId
|
|
|
* @return 急修列表
|
|
|
*/
|
|
|
- public RestResponse<?> queryRepairList(PropertyVo propertyVo) {
|
|
|
- return RestResponse.success(propertyMaintenanceMapper.queryRepairList(propertyVo.getUserId()));
|
|
|
+ public RestResponse<?> queryRepairList(@RequestBody PropertyVo propertyVo) {
|
|
|
+ IPage<RepairResponse> page = new Page<>(propertyVo.getPageNum(), propertyVo.getPageSize());
|
|
|
+ return RestResponse.success(propertyMaintenanceMapper.queryRepairList(page, propertyVo.getStatus(), propertyVo.getUserId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起急修
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public RestResponse<Boolean> repairAdd(EmergencyRepair entity) {
|
|
|
+ Long mtCompanyId = entity.getMtCompanyId();
|
|
|
+ Long liftId = entity.getLiftId();
|
|
|
+ int repairing = emergencyRepairService.countRepairing(mtCompanyId, liftId);
|
|
|
+ Validate.notTrue(repairing > 0, ValuePool.EMERGENCY_HAVE_REPAIRING);
|
|
|
+ PlatformCompanyLiftRelevance relevance = platformCompanyLiftRelevanceService.findByMtCompanyAndLift(entity.getMtCompanyId(), entity.getLiftId());
|
|
|
+ if (Objects.nonNull(relevance)) {
|
|
|
+ Validate.notTrue(CommonEnum.LiftStatus.ANNUAL_INSPECTION.getCode().equals(relevance.getLiftCompanyStatus()), ValuePool.EMERGENCY_LIFT_IS_IN_INSPECTION);
|
|
|
+ }
|
|
|
+ //派单时间 急修单创建时间
|
|
|
+ entity.setHasEvaluate(0);
|
|
|
+ entity.setAssignTime(LocalDateTime.now());
|
|
|
+ entity.setStatus(ValuePool.EMERGENCY_STATE_TO_DO);
|
|
|
+ entity.setCreateDate(LocalDateTime.now());
|
|
|
+ boolean result = emergencyRepairService.save(entity);
|
|
|
+ if (result) {
|
|
|
+ //消息推送
|
|
|
+ Long id = entity.getId();
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ Region region = pushUserService.findRegionByEmergencyRepair(id, mtCompanyId);
|
|
|
+ if (Objects.nonNull(region)) {
|
|
|
+ userIds.add(region.getUserId());
|
|
|
+ }
|
|
|
+ List<PushUserInfo> director = pushUserService.listHighDirector(mtCompanyId);
|
|
|
+ List<PushUserInfo> pushUserInfos = new ArrayList<>(director);
|
|
|
+ if (!userIds.isEmpty()) {
|
|
|
+ List<PushUserInfo> userInfos = pushUserService.listByUserIds(mtCompanyId, userIds);
|
|
|
+ pushUserInfos.addAll(userInfos);
|
|
|
+ }
|
|
|
+ if (!pushUserInfos.isEmpty()) {
|
|
|
+ cn.com.ty.lift.business.emergency.dto.RepairResponse info = emergencyRepairService.infoById(id);
|
|
|
+ PushMessage pushMessage = PushMessage.emergencyAssign(info.getAreaName(), info.getProjectName(), info.getDevicePosition(),
|
|
|
+ info.getRegistrationCode(), info.getCallerDate(), info.getIsTrapped(),
|
|
|
+ info.getCallerFaultDescription(), info.getWorkerName());
|
|
|
+ if (ApiConstants.ACCESS_TYPE_PUBLIC == entity.getMobileType()) {
|
|
|
+ pushMessage = PushMessage.emergencyAssignByProperty(info.getAreaName(), info.getProjectName(), info.getDevicePosition(),
|
|
|
+ info.getRegistrationCode(), info.getCallerDate(), info.getIsTrapped(),
|
|
|
+ info.getCallerFaultDescription(), info.getWorkerName());
|
|
|
+ //物业端发起的急修要将消息推送到pc端
|
|
|
+ List<Long> pushUserIds = pushUserInfos.stream().map(PushUserInfo::getUserId).collect(Collectors.toList());
|
|
|
+ SendMessageUtil.sendMessageToPC(jmsMessagingTemplate, pushUserIds, pushMessage.getContent(),
|
|
|
+ WebSocketConstants.MessageType.EMERGENCY_MSG);
|
|
|
+ }
|
|
|
+ pushMessage.sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return RestResponse.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param request
|
|
|
+ * @return 急修详情
|
|
|
+ */
|
|
|
+ public RestResponse<?> repairBill(RepairRequest request) {
|
|
|
+ Long id = request.getId();
|
|
|
+ cn.com.ty.lift.business.emergency.dto.RepairResponse result = emergencyRepairService.infoById(request.getId());
|
|
|
+ if (null != result) {
|
|
|
+ //急修费用
|
|
|
+ result.setErRecordCosts(erRecordCostService.listByErRecordId(id));
|
|
|
+ //急修图片
|
|
|
+ result.setErRecordImgs(erRecordImgService.listByErRecordId(id));
|
|
|
+ //评价
|
|
|
+ Evaluation byRecord = evaluationService.findByRecord(id, ValuePool.EVALUATE_SOURCE_EMERGENCY);
|
|
|
+ if (Objects.nonNull(byRecord)) result.setEvaluation(byRecord);
|
|
|
+ //故障信息
|
|
|
+ fillFault(result);
|
|
|
+ }
|
|
|
+ return RestResponse.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析故障项id字符串,查询出相关的故障项
|
|
|
+ *
|
|
|
+ * @param result RepairResponse
|
|
|
+ */
|
|
|
+ private void fillFault(cn.com.ty.lift.business.emergency.dto.RepairResponse result) {
|
|
|
+ List<Long> partIds = splitIds(result.getFaultPart());
|
|
|
+ List<Long> reasonIds = splitIds(result.getFaultReason());
|
|
|
+ List<Long> natureIds = splitIds(result.getFaultNature());
|
|
|
+ List<Long> handleIds = splitIds(result.getFaultHandle());
|
|
|
+ List<Long> dutyIds = splitIds(result.getFaultDuty());
|
|
|
+
|
|
|
+ Set<Long> faultIds = new HashSet<>();
|
|
|
+ faultIds.addAll(partIds);
|
|
|
+ faultIds.addAll(reasonIds);
|
|
|
+ faultIds.addAll(natureIds);
|
|
|
+ faultIds.addAll(handleIds);
|
|
|
+ faultIds.addAll(dutyIds);
|
|
|
+ if (faultIds.isEmpty()) return;
|
|
|
+ Collection<LiftFault> liftFaults = liftFaultService.listByIds(faultIds);
|
|
|
+ if (IterUtil.isEmpty(liftFaults)) return;
|
|
|
+ result.setFaultParts(liftFaults.stream().filter(fault -> (partIds.contains(fault.getId()))).collect(Collectors.toList()));
|
|
|
+ result.setFaultReasons(liftFaults.stream().filter(fault -> (reasonIds.contains(fault.getId()))).collect(Collectors.toList()));
|
|
|
+ result.setFaultNatures(liftFaults.stream().filter(fault -> (natureIds.contains(fault.getId()))).collect(Collectors.toList()));
|
|
|
+ result.setFaultHandles(liftFaults.stream().filter(fault -> (handleIds.contains(fault.getId()))).collect(Collectors.toList()));
|
|
|
+ result.setFaultDuties(liftFaults.stream().filter(fault -> (dutyIds.contains(fault.getId()))).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拆分故障项id字符串,组装成List<Long>
|
|
|
+ *
|
|
|
+ * @param idStr ids
|
|
|
+ * @return List<Long>
|
|
|
+ */
|
|
|
+ private List<Long> splitIds(String idStr) {
|
|
|
+ if (StrUtil.isEmpty(idStr)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return Arrays.stream(idStr.split(ValuePool.COMMA)).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
}
|
|
|
}
|