|
|
@@ -1,8 +1,26 @@
|
|
|
package com.xjrsoft.module.material.service.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
+import com.xjrsoft.common.enums.MaterialCategoryEnum;
|
|
|
+import com.xjrsoft.common.model.result.RT;
|
|
|
+import com.xjrsoft.common.page.ConventPage;
|
|
|
+import com.xjrsoft.common.utils.LocalDateTimeUtil;
|
|
|
+import com.xjrsoft.common.utils.RedisUtil;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
+import com.xjrsoft.config.CommonPropertiesConfig;
|
|
|
import com.xjrsoft.module.material.dto.AddMaterialTaskAppendixDto;
|
|
|
import com.xjrsoft.module.material.dto.AddMaterialTaskDto;
|
|
|
import com.xjrsoft.module.material.dto.MaterialAssignUserDto;
|
|
|
@@ -10,16 +28,35 @@ import com.xjrsoft.module.material.dto.MaterialTaskAssignAppendixDto;
|
|
|
import com.xjrsoft.module.material.entity.MaterialTask;
|
|
|
import com.xjrsoft.module.material.entity.MaterialTaskAppendix;
|
|
|
import com.xjrsoft.module.material.entity.MaterialTaskAssign;
|
|
|
+import com.xjrsoft.module.material.entity.MaterialType;
|
|
|
import com.xjrsoft.module.material.mapper.MaterialTaskAppendixMapper;
|
|
|
import com.xjrsoft.module.material.mapper.MaterialTaskAssignMapper;
|
|
|
import com.xjrsoft.module.material.mapper.MaterialTaskMapper;
|
|
|
import com.xjrsoft.module.material.service.IMaterialTaskService;
|
|
|
+import com.xjrsoft.module.material.service.IMaterialTypeService;
|
|
|
+import com.xjrsoft.module.material.vo.MaterialTaskAppendixVo;
|
|
|
+import com.xjrsoft.module.material.vo.MaterialTaskPageVo;
|
|
|
+import com.xjrsoft.module.material.vo.MaterialTaskVo;
|
|
|
+import com.xjrsoft.module.material.vo.MaterialTypeVo;
|
|
|
+import com.xjrsoft.module.oa.entity.News;
|
|
|
+import com.xjrsoft.module.oa.entity.NewsRelation;
|
|
|
+import com.xjrsoft.module.oa.vo.NewsRelationVo;
|
|
|
+import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
|
|
|
+import com.xjrsoft.module.organization.entity.Department;
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
+import com.xjrsoft.module.organization.service.IUserService;
|
|
|
+import com.xjrsoft.module.organization.service.IWeChatService;
|
|
|
+import com.xjrsoft.module.system.entity.DictionaryDetail;
|
|
|
+import com.xjrsoft.module.system.entity.File;
|
|
|
+import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -36,17 +73,21 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
|
|
|
private final MaterialTaskAssignMapper materialTaskMaterialTaskAssignMapper;
|
|
|
private final MaterialTaskAppendixMapper materialTaskMaterialTaskAppendixMapper;
|
|
|
|
|
|
+ private final IMaterialTypeService materialTypeService;
|
|
|
+ private final IWeChatService weChatService;
|
|
|
|
|
|
+ private final CommonPropertiesConfig commonPropertiesConfig;
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Long add(AddMaterialTaskDto dto) {
|
|
|
MaterialTask materialTask = BeanUtil.toBean(dto, MaterialTask.class);
|
|
|
+ //新增任务
|
|
|
materialTask.setStatus(2);
|
|
|
if(dto.getUserList() == null && !dto.getUserList().isEmpty()){
|
|
|
materialTask.setSubmitedPerson(dto.getUserList().size());
|
|
|
}
|
|
|
materialTaskMaterialTaskMapper.insert(materialTask);
|
|
|
-
|
|
|
+ //新增任务人
|
|
|
for (MaterialAssignUserDto materialAssignUserDto : dto.getUserList()){
|
|
|
materialTaskMaterialTaskAssignMapper.insert(new MaterialTaskAssign(){{
|
|
|
setMaterialTaskId(materialTask.getId());
|
|
|
@@ -55,7 +96,7 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
|
|
|
setUserNumber(materialAssignUserDto.getUserNumber());
|
|
|
setStatus(1);
|
|
|
setExecutiveStatus(1);
|
|
|
- setSendMessage(dto.getSendMessageStatus());
|
|
|
+ setSendMessage(dto.getSendMessage());
|
|
|
}});
|
|
|
}
|
|
|
|
|
|
@@ -180,4 +221,135 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MaterialTaskVo getInfoById(Long id) {
|
|
|
+ MPJLambdaWrapper<MaterialTask> queryWrapper = new MPJLambdaWrapper<>();
|
|
|
+ queryWrapper
|
|
|
+ .orderByDesc(MaterialTask::getId)
|
|
|
+ .eq(MaterialTask::getId, id)
|
|
|
+ .select(MaterialTask::getId)
|
|
|
+ .selectAs(MaterialType::getName, MaterialTaskVo::getMaterialTypeIdCn)
|
|
|
+ .selectAs(MaterialType::getCreateDate, MaterialTaskVo::getCreateDate)
|
|
|
+ .selectAs(DictionaryDetail::getName, MaterialTaskVo::getMaterialCategoryCn)
|
|
|
+ .select(MaterialTask.class, x -> VoToColumnUtil.fieldsToColumns(MaterialTaskVo.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, MaterialTask::getMaterialCategory)
|
|
|
+ .leftJoin(MaterialType.class, MaterialType::getId, MaterialTask::getMaterialTypeId);
|
|
|
+ MaterialTaskVo materialTaskVo = this.selectJoinOne(MaterialTaskVo.class, queryWrapper);
|
|
|
+
|
|
|
+ if (materialTaskVo == null) {
|
|
|
+ return materialTaskVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ MaterialTypeVo materialTypeVo = materialTypeService.getInfoById(materialTaskVo.getMaterialTypeId());
|
|
|
+ if(materialTypeVo == null){
|
|
|
+ return materialTaskVo;
|
|
|
+ }
|
|
|
+ if(materialTaskVo.getMaterialCategory().equals(MaterialCategoryEnum.MT0001.getCode())){
|
|
|
+ materialTaskVo.setFolderId(materialTypeVo.getFolderId());
|
|
|
+ materialTaskVo.setFolderIdCn(materialTypeVo.getFolderIdCn());
|
|
|
+ materialTaskVo.setFiles(materialTypeVo.getFiles());
|
|
|
+ }
|
|
|
+ if(materialTaskVo.getMaterialCategory().equals(MaterialCategoryEnum.MT0002.getCode())){
|
|
|
+ materialTaskVo.setFormReleaseId(materialTypeVo.getFormReleaseId());
|
|
|
+ materialTaskVo.setFormReleaseIdCn(materialTypeVo.getFormReleaseIdCn());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// MPJLambdaWrapper<MaterialTaskAssign> materialTaskAssignMPJLambdaWrapper = new MPJLambdaWrapper<>();
|
|
|
+// materialTaskAssignMPJLambdaWrapper
|
|
|
+// .orderByDesc(MaterialTaskAssign::getCreateDate)
|
|
|
+// .eq(MaterialTaskAssign::getMaterialTaskId, id)
|
|
|
+// .select(MaterialTask::getId)
|
|
|
+// .selectAs(MaterialType::getName, MaterialTaskVo::getMaterialTypeIdCn)
|
|
|
+// .selectAs(MaterialType::getCreateDate, MaterialTaskVo::getCreateDate)
|
|
|
+// .selectAs(DictionaryDetail::getName, MaterialTaskVo::getMaterialCategoryCn)
|
|
|
+// .select(MaterialTask.class, x -> VoToColumnUtil.fieldsToColumns(MaterialTaskVo.class).contains(x.getProperty()))
|
|
|
+// .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, MaterialTask::getMaterialCategory)
|
|
|
+// .leftJoin(MaterialType.class, MaterialType::getId, MaterialTask::getMaterialTypeId);
|
|
|
+// MaterialTaskVo materialTaskVo = materialTaskMaterialTaskAssignMapper.selectJoinOne(MaterialTaskVo.class, queryWrapper);
|
|
|
+
|
|
|
+// List<MaterialTaskAppendixVo> newsAppendixVoList = materialTaskAppendixService.selectJoinList(MaterialTaskAppendixVo.class,
|
|
|
+// new MPJLambdaWrapper<MaterialTaskAppendix>().eq(MaterialTaskAppendix::getMaterialTaskId, id)
|
|
|
+// .select(MaterialTaskAppendix::getId)
|
|
|
+// .select(MaterialTaskAppendix.class, x -> VoToColumnUtil.fieldsToColumns(MaterialTaskAppendixVo.class).contains(x.getProperty()))
|
|
|
+// .leftJoin(File.class, File::getId, MaterialTaskAppendix::getFileId, ext -> ext.selectAs(File::getFileName, MaterialTaskAppendixVo::getFileName)
|
|
|
+// .selectAs(File::getFolderId, MaterialTaskAppendixVo::getFolderId)
|
|
|
+// .selectAs(File::getFileUrl, MaterialTaskAppendixVo::getFileUrl))
|
|
|
+// );
|
|
|
+//
|
|
|
+// if (newsAppendixVoList.size() > 0) {
|
|
|
+// materialTaskVo.setMaterialTaskAppendixList(newsAppendixVoList);
|
|
|
+// }
|
|
|
+ return materialTaskVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sendMessage(Long materialTaskId) {
|
|
|
+ MaterialTask materialTask = this.getById(materialTaskId);
|
|
|
+ if(materialTask == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<MaterialTaskAssign> materialTaskAssignLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ materialTaskAssignLambdaQueryWrapper
|
|
|
+ .orderByDesc(MaterialTaskAssign::getCreateDate)
|
|
|
+ .eq(MaterialTaskAssign::getMaterialTaskId, materialTaskId)
|
|
|
+ .select(MaterialTaskAssign::getId)
|
|
|
+ .select(MaterialTaskAssign.class, x -> VoToColumnUtil.fieldsToColumns(MaterialTaskAssign.class).contains(x.getProperty()));
|
|
|
+ List<MaterialTaskAssign> materialTaskAssignList = materialTaskMaterialTaskAssignMapper.selectList(materialTaskAssignLambdaQueryWrapper);
|
|
|
+
|
|
|
+ if(!materialTaskAssignList.isEmpty()){
|
|
|
+ materialTask.setMaterialTaskAssignList(materialTaskAssignList);
|
|
|
+ }
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ this.sendMessageUtil(materialTask);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean sendMessageUtil(MaterialTask materialTask ) {
|
|
|
+ IUserService userService = SpringUtil.getBean(IUserService.class);
|
|
|
+ RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
|
|
|
+ List<User> userList = redisUtil.get(GlobalConstant.USER_CACHE_KEY, new TypeReference<List<User>>() {
|
|
|
+ });
|
|
|
+ //如果缓存中不存在用户信息,就直接去数据库查询,并保存到缓存中去
|
|
|
+ if (userList.size() == 0) {
|
|
|
+ userList = userService.list();
|
|
|
+ redisUtil.set(GlobalConstant.USER_CACHE_KEY, userList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(materialTask.getCreateUserId() == null){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ User createUser = userList.stream().filter(u -> materialTask.getCreateUserId().equals(u.getId())).findFirst().orElse(new User());
|
|
|
+
|
|
|
+ for (MaterialTaskAssign materialTaskAssign : materialTask.getMaterialTaskAssignList()) {
|
|
|
+
|
|
|
+ User materialTaskAssignUser = userList.stream().filter(u -> materialTaskAssign.getUserId().equals(u.getId())).findFirst().orElse(new User());
|
|
|
+
|
|
|
+ WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
|
|
|
+ weChatSendMessageDto.setUserId(materialTaskAssignUser.getOpenId());
|
|
|
+ weChatSendMessageDto.setTemplateId("qmpXORPM1Cocqn503Qa4OkNNQ0uxlj2-ed9m6uWO-v4");
|
|
|
+ //weChatSendMessageDto.setUrl(StrUtil.format("{}/pages/message/notice/detail?id={}", commonPropertiesConfig.getDomainApp(), id));
|
|
|
+ weChatSendMessageDto.setMsgId(materialTask.getId().toString());
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject data1 = new JSONObject();
|
|
|
+ data1.put("value", materialTask.getName());
|
|
|
+ data.put("thing23", data1);
|
|
|
+
|
|
|
+ JSONObject data2 = new JSONObject();
|
|
|
+ data2.put("value", createUser.getName());
|
|
|
+ data.put("thing18", data2);
|
|
|
+
|
|
|
+ JSONObject data3 = new JSONObject();
|
|
|
+ data3.put("value", materialTask.getRequiredCompleteTime());
|
|
|
+ data.put("time17", data3);
|
|
|
+ weChatSendMessageDto.setContent(data);
|
|
|
+ weChatService.sendTemplateMessage(weChatSendMessageDto);
|
|
|
+ };
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|