|
@@ -1,20 +1,42 @@
|
|
package com.platform.service.preparation.impl;
|
|
package com.platform.service.preparation.impl;
|
|
|
|
+
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
import com.platform.common.bean.AbstractPageResultBean;
|
|
import com.platform.common.bean.AbstractPageResultBean;
|
|
|
|
+import com.platform.common.cache.ConfigCache;
|
|
|
|
+import com.platform.common.exception.DeniedException;
|
|
|
|
+import com.platform.common.util.IdGeneratorUtils;
|
|
|
|
+import com.platform.common.util.ListUtils;
|
|
|
|
+import com.platform.common.util.SecurityUtils;
|
|
|
|
+import com.platform.common.util.SpringContextHolder;
|
|
import com.platform.dao.bean.MyPage;
|
|
import com.platform.dao.bean.MyPage;
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
|
-import com.platform.dao.vo.query.preparation.PreparationVO;
|
|
|
|
import com.platform.dao.dto.preparation.PreparationDTO;
|
|
import com.platform.dao.dto.preparation.PreparationDTO;
|
|
|
|
+import com.platform.dao.dto.upms.SysUserDTO;
|
|
import com.platform.dao.entity.preparation.Preparation;
|
|
import com.platform.dao.entity.preparation.Preparation;
|
|
|
|
+import com.platform.dao.entity.sb.SbPosition;
|
|
|
|
+import com.platform.dao.enums.SysConfigEnum;
|
|
|
|
+import com.platform.dao.enums.SysRoleCodeEnum;
|
|
|
|
+import com.platform.dao.enums.WorkplaceBacklogDetailTypeEnum;
|
|
|
|
+import com.platform.dao.enums.WorkplaceBacklogTypeEnum;
|
|
import com.platform.dao.mapper.preparation.PreparationMapper;
|
|
import com.platform.dao.mapper.preparation.PreparationMapper;
|
|
|
|
+import com.platform.dao.mapper.sb.SbPositionMapper;
|
|
|
|
+import com.platform.dao.mapper.upms.SysUserDeptMapper;
|
|
|
|
+import com.platform.dao.mapper.upms.SysUserMapper;
|
|
|
|
+import com.platform.dao.util.MessageTemplateUtil;
|
|
|
|
+import com.platform.dao.vo.SysUserVO;
|
|
|
|
+import com.platform.dao.vo.query.preparation.PreparationVO;
|
|
|
|
+import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
|
+import com.platform.service.event.WorkplaceBacklogEvent;
|
|
import com.platform.service.preparation.PreparationService;
|
|
import com.platform.service.preparation.PreparationService;
|
|
|
|
+import com.platform.service.util.SendMessageUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
-import lombok.AllArgsConstructor;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description 筹建管理 service 实现类
|
|
* @Description 筹建管理 service 实现类
|
|
@@ -22,10 +44,16 @@ import java.util.List;
|
|
* @Date 2022-12-28 20:00:26
|
|
* @Date 2022-12-28 20:00:26
|
|
* @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
|
|
* @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
|
|
*/
|
|
*/
|
|
-@AllArgsConstructor
|
|
|
|
@Service("preparationService")
|
|
@Service("preparationService")
|
|
public class PreparationServiceImpl extends BaseServiceImpl<PreparationMapper, Preparation, PreparationDTO> implements PreparationService {
|
|
public class PreparationServiceImpl extends BaseServiceImpl<PreparationMapper, Preparation, PreparationDTO> implements PreparationService {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private SbPositionMapper sbPositionMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private SysUserDeptMapper sysUserDeptMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public int batchDelete(List<String> ids) {
|
|
public int batchDelete(List<String> ids) {
|
|
Weekend<Preparation> weekend = new Weekend<>(Preparation.class);
|
|
Weekend<Preparation> weekend = new Weekend<>(Preparation.class);
|
|
@@ -41,10 +69,92 @@ public class PreparationServiceImpl extends BaseServiceImpl<PreparationMapper, P
|
|
return new MyPage(mapper.selectList(record));
|
|
return new MyPage(mapper.selectList(record));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Preparation saveByDTO(PreparationDTO model) {
|
|
|
|
+ // 获取公司ID
|
|
|
|
+ model.setParentPositionId(getParentPositionId(model.getPositionId()));
|
|
|
|
+ // 获取筹建主管角色,当一人时,直接赋值,多人时,接单派单
|
|
|
|
+ SysUserDTO queryUserDTO = new SysUserDTO();
|
|
|
|
+ queryUserDTO.setRoleCode(SysRoleCodeEnum.PREPARATION_MANAGER.name());
|
|
|
|
+ List<SysUserVO> userVOS = sysUserMapper.selectDeptRoleUser(queryUserDTO);
|
|
|
|
+ if(userVOS == null || userVOS.size() == 0){
|
|
|
|
+ throw new DeniedException("报修失败,筹建部门,尚无派送主管。");
|
|
|
|
+ }
|
|
|
|
+ if(userVOS.size() == 1){
|
|
|
|
+ model.setDispatchUserId(userVOS.get(0).getUserId());
|
|
|
|
+ }
|
|
|
|
+ // 获取申请人部门
|
|
|
|
+ String userId = SecurityUtils.getUserInfo().getUserId();
|
|
|
|
+ model.setDepartId(sysUserDeptMapper.selectDeptIdByUserId(userId));
|
|
|
|
+ model.setUserId(userId);
|
|
|
|
+ // 单据号
|
|
|
|
+ Weekend<Preparation> weekend = new Weekend<>(Preparation.class);
|
|
|
|
+ weekend.weekendCriteria().andIsNotNull(Preparation::getId);
|
|
|
|
+ Integer count = mapper.selectCountByExample(weekend);
|
|
|
|
+ model.setNo(IdGeneratorUtils.getPreparationNo(++count));
|
|
|
|
+ Preparation preparation = this.saveModelByDTO(model);
|
|
|
|
+ // 给主管发送消息
|
|
|
|
+ sendMessageToManger(userVOS,preparation);
|
|
|
|
+ return preparation;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getParentPositionId(String positionId){
|
|
|
|
+ SbPosition sbPosition = sbPositionMapper.selectByPrimaryKey(positionId);
|
|
|
|
+ while(!StringUtils.isEmpty(sbPosition.getParentId())){
|
|
|
|
+ sbPosition = sbPositionMapper.selectByPrimaryKey(sbPosition.getParentId());
|
|
|
|
+ }
|
|
|
|
+ return sbPosition.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public AbstractPageResultBean<Preparation> selectPageInfo(PreparationDTO record, int pageNum, int pageSize) {
|
|
public AbstractPageResultBean<Preparation> selectPageInfo(PreparationDTO record, int pageNum, int pageSize) {
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
return new MyPage(mapper.selectList(record));
|
|
return new MyPage(mapper.selectList(record));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 给筹建主管发送消息
|
|
|
|
+ * @param userVOS
|
|
|
|
+ * @param preparation
|
|
|
|
+ */
|
|
|
|
+ private void sendMessageToManger(List<SysUserVO> userVOS,Preparation preparation){
|
|
|
|
+ String info = MessageTemplateUtil.getPreparationSuccess(preparation.getNo());
|
|
|
|
+ Integer detailType = WorkplaceBacklogDetailTypeEnum.PREPARATION_REPAIR.getValue();
|
|
|
|
+ String[] values = new String[]{"有一条新的筹建消息!",preparation.getNo(),"无",preparation.getContent(),sbPositionMapper.selectNameById(preparation.getPositionId()),"请尽快派工"};
|
|
|
|
+ String wechatTemplateId = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_SEND_SUCCESS_WECHAT_TEMPLATE_ID.name());;
|
|
|
|
+ String detailUrl = "pages/service-detail/service-detail?id=" + preparation.getId();
|
|
|
|
+ Map<String,List<String>> maps = getPushReceivers(userVOS);
|
|
|
|
+ // 1、站内信
|
|
|
|
+ sendWorkplaceAndEmailNew(maps.get("mails"),maps.get("userIds"),preparation.getId(),info, detailType);
|
|
|
|
+ // 2、微信
|
|
|
|
+ SendMessageUtils.sendWechatNew(maps.get("openIds"),detailUrl,values,wechatTemplateId);
|
|
|
|
+ // 3、短信
|
|
|
|
+ SendMessageUtils.sendCommonSms(maps.get("phones"),info);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Map<String,List<String>> getPushReceivers(List<SysUserVO> userVOS){
|
|
|
|
+ Map<String,List<String>> retInfos = new HashMap<>();
|
|
|
|
+ List<String> mails = ListUtils.newArrayList();
|
|
|
|
+ List<String> userIds = ListUtils.newArrayList();
|
|
|
|
+ List<String> openIds = ListUtils.newArrayList();
|
|
|
|
+ List<String> phones = ListUtils.newArrayList();
|
|
|
|
+ userVOS.forEach(item -> {
|
|
|
|
+ mails.add(item.getEmail());
|
|
|
|
+ userIds.add(item.getUserId());
|
|
|
|
+ openIds.add(item.getWxOpenId());
|
|
|
|
+ phones.add(item.getPhone());
|
|
|
|
+ });
|
|
|
|
+ retInfos.put("mails",mails);
|
|
|
|
+ retInfos.put("userIds",userIds);
|
|
|
|
+ retInfos.put("openIds",openIds);
|
|
|
|
+ retInfos.put("phones",phones);
|
|
|
|
+ return retInfos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void sendWorkplaceAndEmailNew(List<String> mails,List<String> userIds,String repairId,String content,Integer detailType){
|
|
|
|
+ // 通过给当天值班维修人员
|
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.PREPARATION_REPAIR.getValue(), detailType,
|
|
|
|
+ repairId, content, repairId, userIds, mails));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|