|
@@ -1,9 +1,12 @@
|
|
|
package cn.com.ty.lift.business.maintenance.service;
|
|
|
|
|
|
+import cn.com.ty.lift.business.capital.dao.mapper.CommonMapper;
|
|
|
import cn.com.ty.lift.business.framework.util.MessageUtils;
|
|
|
+import cn.com.ty.lift.business.library.dao.entity.Lift;
|
|
|
import cn.com.ty.lift.business.library.service.LiftService;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.MaintenancePlan;
|
|
|
-import cn.com.ty.lift.business.maintenance.dao.entity.model.request.*;
|
|
|
+import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenancePlanRequest;
|
|
|
+import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtPlanRequest;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.response.LiftPrintResponse;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenancePlanPrintResponse;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenancePlanResponse;
|
|
@@ -11,10 +14,16 @@ import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MtPlanRespo
|
|
|
import cn.com.ty.lift.business.maintenance.dao.mapper.MaintenancePlanMapper;
|
|
|
import cn.com.ty.lift.business.project.dao.entity.Project;
|
|
|
import cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance;
|
|
|
+import cn.com.ty.lift.business.project.dao.entity.Region;
|
|
|
+import cn.com.ty.lift.business.project.dao.entity.model.response.ProjectDetailResponse;
|
|
|
+import cn.com.ty.lift.business.project.service.ProjectAppService;
|
|
|
import cn.com.ty.lift.business.project.service.ProjectLiftRelevanceService;
|
|
|
import cn.com.ty.lift.business.project.service.ProjectService;
|
|
|
+import cn.com.ty.lift.business.push.service.PushUserService;
|
|
|
import cn.com.ty.lift.common.base.ExportRequest;
|
|
|
import cn.com.ty.lift.common.export.ExportUtils;
|
|
|
+import cn.com.ty.lift.common.model.PushMessage;
|
|
|
+import cn.com.ty.lift.common.model.PushUserInfo;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -24,6 +33,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.jms.core.JmsMessagingTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -49,9 +59,21 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
@Resource
|
|
|
private LiftService liftService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private CommonMapper commonMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private ProjectLiftRelevanceService projectLiftRelevanceService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ProjectAppService projectAppService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private JmsMessagingTemplate jmsMessagingTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PushUserService pushUserService;
|
|
|
+
|
|
|
private Map<String, String> paramMap = new HashMap<String, String>() {{
|
|
|
put("projectCode", "项目编号");
|
|
|
put("projectName", "项目名称");
|
|
@@ -119,6 +141,78 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
return Optional.ofNullable(getOne(lambdaQueryWrapper)).orElse(null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param liftId 电梯ID
|
|
|
+ * @param projectId 项目ID
|
|
|
+ * @param mtCompanyId 公司ID
|
|
|
+ * @param interval 保养间隔
|
|
|
+ * @param planDate 保养时间
|
|
|
+ * @param type 保养类型
|
|
|
+ * @param liftCharge 电梯负责人
|
|
|
+ * @param operator 操作人
|
|
|
+ * @return
|
|
|
+ * @description 生成保养计划消息推送
|
|
|
+ * @date 2020/5/5 9:26 下午
|
|
|
+ */
|
|
|
+ public void sendCreateMessage(Long liftId, Long projectId, Long mtCompanyId, int interval, LocalDate planDate, int type, String liftCharge, String operator, Long workerId) {
|
|
|
+ //消息推送
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ Region region = pushUserService.findRegionByProject(projectId, mtCompanyId);
|
|
|
+ if (Objects.nonNull(region)) {
|
|
|
+ userIds.addAll(region.members());
|
|
|
+ }
|
|
|
+ userIds.add(workerId);
|
|
|
+ List<PushUserInfo> pushUserInfos = new ArrayList<>();
|
|
|
+ if (!userIds.isEmpty()) {
|
|
|
+ List<PushUserInfo> userInfos = pushUserService.listByUserIds(mtCompanyId, userIds);
|
|
|
+ pushUserInfos.addAll(userInfos);
|
|
|
+ }
|
|
|
+ if (!pushUserInfos.isEmpty()) {
|
|
|
+ ProjectDetailResponse detail = projectAppService.detail(projectId);
|
|
|
+ Optional<Lift> lift = liftService.getOne(null, liftId);
|
|
|
+ lift.ifPresent(l ->
|
|
|
+ PushMessage.maintainCreatePlan(detail.getAreaName(), detail.getProjectName(), l.getDevicePosition(),
|
|
|
+ l.getRegistrationCode(), interval, planDate, type, liftCharge, operator).sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfos));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param liftId 电梯ID
|
|
|
+ * @param projectId 项目ID
|
|
|
+ * @param mtCompanyId 公司ID
|
|
|
+ * @param interval 保养间隔
|
|
|
+ * @param planDate 保养时间
|
|
|
+ * @param type 保养类型
|
|
|
+ * @param liftCharge 电梯负责人
|
|
|
+ * @param operator 操作人
|
|
|
+ * @param workerId 维保工
|
|
|
+ * @return
|
|
|
+ * @description 修改保养计划消息推送
|
|
|
+ * @date 2020/5/8 10:25 上午
|
|
|
+ */
|
|
|
+ public void sendModifyMessage(Long liftId, Long projectId, Long mtCompanyId, int interval, LocalDate planDate, int type, String liftCharge, String operator, Long workerId) {
|
|
|
+ //消息推送
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ Region region = pushUserService.findRegionByProject(projectId, mtCompanyId);
|
|
|
+ if (Objects.nonNull(region)) {
|
|
|
+ userIds.addAll(region.members());
|
|
|
+ }
|
|
|
+ userIds.add(workerId);
|
|
|
+ List<PushUserInfo> pushUserInfos = new ArrayList<>();
|
|
|
+ if (!userIds.isEmpty()) {
|
|
|
+ List<PushUserInfo> userInfos = pushUserService.listByUserIds(mtCompanyId, userIds);
|
|
|
+ pushUserInfos.addAll(userInfos);
|
|
|
+ }
|
|
|
+ if (!pushUserInfos.isEmpty()) {
|
|
|
+ ProjectDetailResponse detail = projectAppService.detail(projectId);
|
|
|
+ Optional<Lift> lift = liftService.getOne(null, liftId);
|
|
|
+ lift.ifPresent(l ->
|
|
|
+ PushMessage.maintainModifyPlan(detail.getAreaName(), detail.getProjectName(), l.getDevicePosition(),
|
|
|
+ l.getRegistrationCode(), interval, planDate, type, liftCharge, operator).sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfos));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @param request 电梯列表
|
|
|
* @return 是否成功
|
|
@@ -126,13 +220,27 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
* @date 2019/12/16 2:14 PM
|
|
|
*/
|
|
|
public RestResponse insertBatch(MaintenancePlanRequest request) {
|
|
|
- boolean result = preJudgment(request.getPlanList(), request.getFirstTime());
|
|
|
- if (!result){
|
|
|
+ List<MaintenancePlan> planList = request.getPlanList();
|
|
|
+ boolean result = preJudgment(planList, request.getFirstTime());
|
|
|
+ if (!result) {
|
|
|
return RestResponse.fail(MessageUtils.get("msg.error.time"));
|
|
|
}
|
|
|
List<MaintenancePlan> resultList = addPlan(request);
|
|
|
boolean ret = saveBatch(resultList, resultList.size());
|
|
|
if (ret) {
|
|
|
+ List<MaintenancePlan> messageList = new ArrayList<>();
|
|
|
+ Map<Long, List<MaintenancePlan>> collectMap = resultList.stream().collect(Collectors.groupingBy(MaintenancePlan::getId));
|
|
|
+ for (Map.Entry<Long, List<MaintenancePlan>> entry : collectMap.entrySet()) {
|
|
|
+ MaintenancePlan plan = entry.getValue().get(0);
|
|
|
+ messageList.add(plan);
|
|
|
+ }
|
|
|
+ //生成维保计划发送推送消息
|
|
|
+ for (MaintenancePlan plan : messageList) {
|
|
|
+ String workerName = commonMapper.queryUserNameById(plan.getWorkerId());
|
|
|
+ String creatorName = commonMapper.queryUserNameById(plan.getCreatorId());
|
|
|
+ sendCreateMessage(plan.getLiftId(), plan.getProjectId(),
|
|
|
+ plan.getMtCompanyId(), request.getInterval(), request.getFirstTime(), plan.getType(), workerName, creatorName, plan.getWorkerId());
|
|
|
+ }
|
|
|
return RestResponse.success(null, MessageUtils.get("msg.add.success"));
|
|
|
} else {
|
|
|
return RestResponse.fail(MessageUtils.get("msg.add.fail"));
|
|
@@ -278,12 +386,16 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
Long mtCompanyId = request.getMtCompanyId();
|
|
|
//获取电梯id
|
|
|
Long liftId = request.getLiftId();
|
|
|
+ //获取项目id
|
|
|
+ Long projectId = request.getProjectId();
|
|
|
+ //获取维保工id
|
|
|
+ Long workerId = request.getWorkerId();
|
|
|
MaintenancePlan plan = new MaintenancePlan();
|
|
|
- plan.setProjectId(request.getProjectId());
|
|
|
+ plan.setProjectId(projectId);
|
|
|
plan.setMtCompanyId(mtCompanyId);
|
|
|
plan.setLiftId(liftId);
|
|
|
- plan.setWorkerId(request.getWorkerId());
|
|
|
- Optional<Project> optional = projectService.getOne(request.getProjectId());
|
|
|
+ plan.setWorkerId(workerId);
|
|
|
+ Optional<Project> optional = projectService.getOne(projectId);
|
|
|
Project project = new Project();
|
|
|
if (optional.isPresent()) project = optional.get();
|
|
|
if (ObjectUtil.isEmpty(project)) return false;
|
|
@@ -336,6 +448,11 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
//按照修改时间重新生成计划
|
|
|
plans = generatePlan(plan, periods, updateInterval, updateTime, endDate);
|
|
|
}
|
|
|
+ MaintenancePlan newPlan = plans.get(0);
|
|
|
+ String workerName = commonMapper.queryUserNameById(workerId);
|
|
|
+ String creatorName = commonMapper.queryUserNameById(plan.getCreatorId());
|
|
|
+ //发送修改计划消息推送
|
|
|
+ sendModifyMessage(liftId, projectId, mtCompanyId, interval, newPlan.getPlanDate(), newPlan.getType(), workerName, creatorName, workerId);
|
|
|
return saveBatch(plans, plans.size());
|
|
|
}
|
|
|
|