|
@@ -1,28 +1,40 @@
|
|
|
package cn.com.ty.lift.business.project.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.dao.entity.model.request.LiftExtensionRequest;
|
|
|
import cn.com.ty.lift.business.library.dao.entity.model.request.LiftRequest;
|
|
|
+import cn.com.ty.lift.business.library.service.LiftService;
|
|
|
import cn.com.ty.lift.business.library.service.PlatformCompanyLiftRelevanceService;
|
|
|
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.request.ProjectRequest;
|
|
|
+import cn.com.ty.lift.business.project.dao.entity.model.response.ProjectDetailResponse;
|
|
|
import cn.com.ty.lift.business.project.dao.entity.model.response.ProjectRelevanceResponse;
|
|
|
import cn.com.ty.lift.business.project.dao.entity.model.response.ProjectUserResponse;
|
|
|
import cn.com.ty.lift.business.project.dao.mapper.ProjectLiftRelevanceMapper;
|
|
|
+import cn.com.ty.lift.business.push.service.PushUserService;
|
|
|
import cn.com.ty.lift.common.constants.CommonEnum;
|
|
|
+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.xwy.boot.web.dto.RestResponse;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.jms.core.JmsMessagingTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -39,6 +51,21 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
|
|
|
@Resource
|
|
|
private PlatformCompanyLiftRelevanceService platformService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ProjectAppService projectAppService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private JmsMessagingTemplate jmsMessagingTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PushUserService pushUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private LiftService liftService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CommonMapper commonMapper;
|
|
|
+
|
|
|
/**
|
|
|
* @param request 项目关联数据
|
|
|
* @return RestResponse 状态码和返回消息
|
|
@@ -186,6 +213,68 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
|
|
|
return updateById(entry);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param projectId 项目ID
|
|
|
+ * @param mtCompanyId 公司ID
|
|
|
+ * @param liftId 电梯ID
|
|
|
+ * @param workerId 原有维保负责人
|
|
|
+ * @param newWorkerId 新维保负责人
|
|
|
+ * @return
|
|
|
+ * @description 电梯更换主要负责人消息推送
|
|
|
+ * @date 2020/5/8 6:35 下午
|
|
|
+ */
|
|
|
+ public void sendMessage(Long projectId, Long mtCompanyId, Long liftId, Long workerId, Long newWorkerId) {
|
|
|
+ //消息推送
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ Region region = pushUserService.findRegionByProject(projectId, mtCompanyId);
|
|
|
+ if (Objects.nonNull(region)) {
|
|
|
+ userIds.addAll(region.members());
|
|
|
+ }
|
|
|
+ userIds.add(workerId);
|
|
|
+ userIds.add(newWorkerId);
|
|
|
+ List<PushUserInfo> director = pushUserService.listEnterpriseAdmin(mtCompanyId);
|
|
|
+ List<PushUserInfo> pushUserInfos = new ArrayList<>(director);
|
|
|
+ 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 -> {
|
|
|
+ String workerName = commonMapper.queryUserNameById(workerId);
|
|
|
+ String newworkerName = commonMapper.queryUserNameById(newWorkerId);
|
|
|
+ PushMessage pushMessage = PushMessage.workReplaceLiftCharger(detail.getAreaName(), detail.getProjectName(),
|
|
|
+ l.getDevicePosition(), l.getRegistrationCode(), workerName, newworkerName);
|
|
|
+ pushMessage.sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfos);
|
|
|
+ List<Long> sendToUserIdList = pushUserInfos.stream().map(PushUserInfo::getUserId).collect(Collectors.toList());
|
|
|
+ //推送pc端
|
|
|
+ SendMessageUtil.sendMessageToPC(jmsMessagingTemplate, sendToUserIdList, pushMessage.getContent());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param request 项目电梯id列表
|
|
|
+ * @return 是否成功
|
|
|
+ * @description 批量更新
|
|
|
+ * @date 2020/5/8 4:15 下午
|
|
|
+ */
|
|
|
+ public RestResponse batchModify(ProjectRequest request){
|
|
|
+ Long newWorkerId = request.getWorkerId();
|
|
|
+ List<ProjectLiftRelevance> list = request.getList();
|
|
|
+ list.forEach(entry -> entry.setWorkerId(request.getWorkerId()));
|
|
|
+ boolean result = updateBatchById(list);
|
|
|
+ if (!result) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
|
|
|
+ }
|
|
|
+ for (ProjectLiftRelevance entry : list){
|
|
|
+ sendMessage(entry.getProjectId(), entry.getMtCompanyId(), entry.getLiftId(), entry.getWorkerId(), newWorkerId);
|
|
|
+ }
|
|
|
+ return RestResponse.success(MessageUtils.get("msg.modify.success"));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param id 项目关联主键id
|
|
|
* @return 是否成功
|