|
@@ -2,12 +2,14 @@ package com.rongwei.sfcommon.sys.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.rongwe.scentity.domian.*;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysUserDo;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysConfigFeignService;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysUserService;
|
|
|
+import com.rongwei.rwcommon.base.BaseDo;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommon.vo.MailDo;
|
|
@@ -21,10 +23,10 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.lang.reflect.Array;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service("themeCheckService")
|
|
|
public class ThemeCheckServiceImpl extends ServiceImpl<ThemeCheckDao, ThemeCheckDo> implements ThemeCheckService {
|
|
@@ -48,14 +50,17 @@ public class ThemeCheckServiceImpl extends ServiceImpl<ThemeCheckDao, ThemeCheck
|
|
|
@Autowired
|
|
|
private SafetyObservationDao safetyObservationDao;
|
|
|
|
|
|
+ public static final String INSPECTION_TEAM = "%s,%s";
|
|
|
+
|
|
|
/**
|
|
|
* 日常检查保存时拆分任务
|
|
|
+ *
|
|
|
* @param map
|
|
|
*/
|
|
|
- public void themeCheckSplit(Map<String,Object> map){
|
|
|
+ public void themeCheckSplit(Map<String, Object> map) {
|
|
|
// 日常检查实体类封装
|
|
|
- GeneralApiParameter generalApiParameter = BeanUtil.mapToBeanIgnoreCase(map, GeneralApiParameter.class,true);
|
|
|
- ThemeCheckDo themeCheckDo = BeanUtil.mapToBeanIgnoreCase(generalApiParameter.getMasterPar(), ThemeCheckDo.class,true);
|
|
|
+ GeneralApiParameter generalApiParameter = BeanUtil.mapToBeanIgnoreCase(map, GeneralApiParameter.class, true);
|
|
|
+ ThemeCheckDo themeCheckDo = BeanUtil.mapToBeanIgnoreCase(generalApiParameter.getMasterPar(), ThemeCheckDo.class, true);
|
|
|
List<SlaveDMLVo> slaveDMLVos = generalApiParameter.getSlaveDMLVos();
|
|
|
List<ThemeCheckWorkparkDo> themeCheckWorkparks = new ArrayList<>();
|
|
|
if(slaveDMLVos != null && slaveDMLVos.size()>0){
|
|
@@ -140,42 +145,144 @@ public class ThemeCheckServiceImpl extends ServiceImpl<ThemeCheckDao, ThemeCheck
|
|
|
|
|
|
/**
|
|
|
* 根据日常检查ID,发送邮件内容
|
|
|
+ *
|
|
|
* @param themeCheckId
|
|
|
*/
|
|
|
- public void sendMailByCheckId(String themeCheckId){
|
|
|
- if(StringUtils.isNotEmpty(themeCheckId)){
|
|
|
- ThemeCheckDo themeCheckDo = this.getById(themeCheckId);
|
|
|
- Map<String,Object> queryMap = new HashMap<>();
|
|
|
- queryMap.put("THEMECHECKID",themeCheckId);
|
|
|
- List<ThemeCheckWorkparkDo> themeCheckWorkparks = (List<ThemeCheckWorkparkDo>)themeCheckWorkparkService.listByMap(queryMap);
|
|
|
- Map<String,Object> parmap = new HashMap<>();
|
|
|
- parmap.put("CHECKTEMPLATEID",themeCheckDo.getChecktemplateid());
|
|
|
- parmap.put("DELETED","0");
|
|
|
-// List<CheckTemplateItemsDo> checkTemplateItemss = (List<CheckTemplateItemsDo>)checkTemplateItemsService.listByMap(parmap);
|
|
|
- CheckTemplateItemsDo queryItemDo = new CheckTemplateItemsDo();
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void sendMailByCheckId(String themeCheckId) {
|
|
|
+ if (StringUtils.isBlank(themeCheckId)) {
|
|
|
+ logger.error("检查计划ID 为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ThemeCheckDo themeCheckDo = this.getById(themeCheckId);
|
|
|
+ if (themeCheckDo.getCreatetask() == 1) {
|
|
|
+ logger.debug("此检查计划已生成检查任务");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Object> queryMap = new HashMap<>();
|
|
|
+ queryMap.put("THEMECHECKID", themeCheckId);
|
|
|
+ // 获取检查小组人员
|
|
|
+ List<ThemeCheckWorkparkDo> themeCheckWorkparks = (List<ThemeCheckWorkparkDo>) themeCheckWorkparkService.listByMap(queryMap);
|
|
|
+ if (themeCheckWorkparks.isEmpty()) {
|
|
|
+ log.error("该检查计划没有检查小组");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 获取所有检查小组的人员信息
|
|
|
+ List<String> userIds = themeCheckWorkparks.stream().map(info -> {
|
|
|
+ String groupLeader = "";
|
|
|
+ if (StringUtils.isNotBlank(info.getGroupleader())) {
|
|
|
+ groupLeader = info.getGroupleader();
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(info.getGroupusers())) {
|
|
|
+ groupLeader = String.format(INSPECTION_TEAM, groupLeader, info.getGroupusers());
|
|
|
+ }
|
|
|
+ return groupLeader.split(",");
|
|
|
+ }).flatMap(Arrays::stream).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
|
|
|
+ List<SysUserDo> userList = sysUserService.list(new LambdaQueryWrapper<SysUserDo>().in(SysUserDo::getId, userIds));
|
|
|
+ // 当前检查小组的人员信息
|
|
|
+ HashSet<String> currentCheckUserIds = new HashSet<>();
|
|
|
+ List<ThemeCheckItemDo> saveCheckItemList = new ArrayList<ThemeCheckItemDo>();
|
|
|
+ List<ThemeCheckContentDo> saveCheckContentList = new ArrayList<ThemeCheckContentDo>();
|
|
|
+ // 获取检查小组中的所有检查主题
|
|
|
+ List<String> checkTemplateIds = themeCheckWorkparks.stream().map(ThemeCheckWorkparkDo::getChecktemplateid).distinct().filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
|
|
+ // 检查主题明细
|
|
|
+ List<CheckTemplateItemsDo> checkTemplateItemsDos = checkTemplateItemsService.list(new LambdaQueryWrapper<CheckTemplateItemsDo>()
|
|
|
+ .eq(BaseDo::getDeleted, "0")
|
|
|
+ .in(CheckTemplateItemsDo::getChecktemplateid, checkTemplateIds)
|
|
|
+ );
|
|
|
+ // 生成检查任务
|
|
|
+ themeCheckWorkparks.forEach(info -> {
|
|
|
+ String groupleader = info.getGroupleader();
|
|
|
+ String groupusers = info.getGroupusers();
|
|
|
+ currentCheckUserIds.clear();
|
|
|
+ if (StringUtils.isNotBlank(groupleader)) {
|
|
|
+ currentCheckUserIds.add(groupleader);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(groupusers)) {
|
|
|
+ currentCheckUserIds.addAll(new HashSet<>(Arrays.asList(groupusers.split(","))));
|
|
|
+ }
|
|
|
+ currentCheckUserIds.forEach(userId -> {
|
|
|
+ SysUserDo userDo = userList.stream().filter(userInfo -> userId.equals(userInfo.getId())).findFirst().orElse(null);
|
|
|
+ ThemeCheckItemDo themeCheckItemDo = generateThemeCheckItem(userDo, info, themeCheckDo);
|
|
|
+ saveCheckItemList.add(themeCheckItemDo);
|
|
|
+ checkTemplateItemsDos.forEach(checkTemplate -> {
|
|
|
+ saveCheckContentList.add(generateThemeCheckContent(userDo, themeCheckItemDo, checkTemplate));
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ this.update(new LambdaUpdateWrapper<ThemeCheckDo>().set(ThemeCheckDo::getCreatetask, 1).eq(ThemeCheckDo::getId, themeCheckId));
|
|
|
+ themeCheckItemService.saveBatch(saveCheckItemList);
|
|
|
+ themeCheckContentService.saveBatch(saveCheckContentList);
|
|
|
+ // 邮件发送代码注释
|
|
|
+ /*CheckTemplateItemsDo queryItemDo = new CheckTemplateItemsDo();
|
|
|
queryItemDo.setChecktemplateid(themeCheckDo.getChecktemplateid());
|
|
|
queryItemDo.setDeleted("0");
|
|
|
Wrapper<CheckTemplateItemsDo> entity = (Wrapper<CheckTemplateItemsDo>)new QueryWrapper(queryItemDo).orderByAsc("ITEMSORT");
|
|
|
List<CheckTemplateItemsDo> checkTemplateItemss = checkTemplateItemsService.list(entity);
|
|
|
- // 邮件发送
|
|
|
- this.sendMail(themeCheckDo,themeCheckWorkparks,checkTemplateItemss);
|
|
|
- }
|
|
|
+ this.sendMail(themeCheckDo,themeCheckWorkparks,checkTemplateItemss);*/
|
|
|
+ }
|
|
|
+
|
|
|
+ private ThemeCheckContentDo generateThemeCheckContent(SysUserDo sysUser, ThemeCheckItemDo themeCheckItemDo, CheckTemplateItemsDo checkTemplateItemsDo) {
|
|
|
+ ThemeCheckContentDo themeCheckContentDo = new ThemeCheckContentDo();
|
|
|
+ themeCheckContentDo.setId(SecurityUtil.getUUID());
|
|
|
+ themeCheckContentDo.setCreateusername(sysUser.getName());
|
|
|
+ themeCheckContentDo.setCreateuserid(sysUser.getId());
|
|
|
+ themeCheckContentDo.setModifydate(new Date());
|
|
|
+ themeCheckContentDo.setModifyuserid(sysUser.getId());
|
|
|
+ themeCheckContentDo.setModifyusername(sysUser.getName());
|
|
|
+ themeCheckContentDo.setCreatedate(new Date());
|
|
|
+ themeCheckContentDo.setThemecheckitemid(themeCheckItemDo.getId());
|
|
|
+ themeCheckContentDo.setCheckposition(checkTemplateItemsDo.getCheckposition());
|
|
|
+ themeCheckContentDo.setCheckcontent(checkTemplateItemsDo.getCheckcontent());
|
|
|
+ return themeCheckContentDo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生产检查任务信息
|
|
|
+ *
|
|
|
+ * @param sysUser 检查人信息
|
|
|
+ * @param themeCheckWorkpark 检查小组信息
|
|
|
+ * @param themeCheckId 检查任务ID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ThemeCheckItemDo generateThemeCheckItem(SysUserDo sysUser, ThemeCheckWorkparkDo themeCheckWorkPark, ThemeCheckDo themeCheck) {
|
|
|
+ ThemeCheckItemDo themeCheckItemDo = new ThemeCheckItemDo();
|
|
|
+ themeCheckItemDo.setId(SecurityUtil.getUUID());
|
|
|
+ themeCheckItemDo.setThemecheckid(themeCheck.getId());
|
|
|
+ themeCheckItemDo.setCreateusername(sysUser.getName());
|
|
|
+ themeCheckItemDo.setCreateuserid(sysUser.getId());
|
|
|
+ themeCheckItemDo.setModifydate(new Date());
|
|
|
+ themeCheckItemDo.setModifyuserid(sysUser.getId());
|
|
|
+ themeCheckItemDo.setModifyusername(sysUser.getName());
|
|
|
+ themeCheckItemDo.setCreatedate(new Date());
|
|
|
+ themeCheckItemDo.setThemecheckname(themeCheckWorkPark.getChecktheme());
|
|
|
+ themeCheckItemDo.setPlanstarttime(themeCheck.getPlanstarttime());
|
|
|
+ themeCheckItemDo.setThemecheckworkspartid(themeCheckWorkPark.getChargeorgid());
|
|
|
+ themeCheckItemDo.setCheckworkspart(themeCheckWorkPark.getChargeorgname());
|
|
|
+ themeCheckItemDo.setCheckerid(sysUser.getId());
|
|
|
+ themeCheckItemDo.setChecker(sysUser.getName());
|
|
|
+ themeCheckItemDo.setGroupleader(themeCheckWorkPark.getGroupleader());
|
|
|
+ themeCheckItemDo.setGroupleadername(themeCheckWorkPark.getGroupleadername());
|
|
|
+ themeCheckItemDo.setGroupusers(themeCheckWorkPark.getGroupusernames());
|
|
|
+ themeCheckItemDo.setGroupusernames(themeCheckWorkPark.getGroupleadername());
|
|
|
+ return themeCheckItemDo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 日常检查完成时邮件发送
|
|
|
+ *
|
|
|
* @param themeCheckDo
|
|
|
* @param themeCheckWorkparks
|
|
|
* @param checkTemplateItemss
|
|
|
*/
|
|
|
- private void sendMail(ThemeCheckDo themeCheckDo,List<ThemeCheckWorkparkDo> themeCheckWorkparks,List<CheckTemplateItemsDo> checkTemplateItemss){
|
|
|
- if(themeCheckWorkparks != null && themeCheckWorkparks.size()>0){
|
|
|
- for(ThemeCheckWorkparkDo themeCheckWorkpark:themeCheckWorkparks){
|
|
|
+ private void sendMail(ThemeCheckDo themeCheckDo, List<ThemeCheckWorkparkDo> themeCheckWorkparks, List<CheckTemplateItemsDo> checkTemplateItemss) {
|
|
|
+ if (themeCheckWorkparks != null && themeCheckWorkparks.size() > 0) {
|
|
|
+ for (ThemeCheckWorkparkDo themeCheckWorkpark : themeCheckWorkparks) {
|
|
|
// 邮件发送
|
|
|
MailDo mail = new MailDo();
|
|
|
- if(MlConstants.THEMECHECK_TYPE_SPECIALCHECK.equals(themeCheckDo.getChecktype())){
|
|
|
+ if (MlConstants.THEMECHECK_TYPE_SPECIALCHECK.equals(themeCheckDo.getChecktype())) {
|
|
|
mail.setSubject("周五专项检查");
|
|
|
- }else if(MlConstants.THEMECHECK_TYPE_DAYCHECK.equals(themeCheckDo.getChecktype())){
|
|
|
+ } else if (MlConstants.THEMECHECK_TYPE_DAYCHECK.equals(themeCheckDo.getChecktype())) {
|
|
|
mail.setSubject("全厂检查");
|
|
|
}
|
|
|
|