|
@@ -1,5 +1,6 @@
|
|
|
package com.fdkankan.site.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -9,21 +10,31 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.site.common.PageInfo;
|
|
|
import com.fdkankan.site.common.ResultCode;
|
|
|
+import com.fdkankan.site.common.ResultData;
|
|
|
import com.fdkankan.site.common.util.VUtils;
|
|
|
import com.fdkankan.site.entity.*;
|
|
|
import com.fdkankan.site.entity.dto.MarkingDTO;
|
|
|
import com.fdkankan.site.entity.dto.UserDTO;
|
|
|
import com.fdkankan.site.mapper.IMarkingMapper;
|
|
|
+import com.fdkankan.site.request.MarkingParam;
|
|
|
import com.fdkankan.site.request.MarkingSearchParam;
|
|
|
+import com.fdkankan.site.response.SceneVo;
|
|
|
import com.fdkankan.site.service.*;
|
|
|
+import com.fdkankan.sms.SmsService;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static java.util.stream.Collectors.toList;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class MarkingServiceImpl extends ServiceImpl<IMarkingMapper, Marking> implements IMarkingService {
|
|
|
@Autowired
|
|
|
IProjectLogService projectLogService;
|
|
@@ -33,26 +44,31 @@ public class MarkingServiceImpl extends ServiceImpl<IMarkingMapper, Marking> imp
|
|
|
IProjectTeamService projectTeamService;
|
|
|
@Autowired
|
|
|
IProjectService projectService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ SmsService smsService;
|
|
|
+ @Autowired
|
|
|
+ IProjectNumService projectNumService;
|
|
|
+ @Autowired
|
|
|
+ ISceneService sceneService;
|
|
|
+ @Value("${phone.code.cn}")
|
|
|
+ private String cnCode;
|
|
|
@Override
|
|
|
public Object pageList(MarkingSearchParam param) {
|
|
|
-// VUtils.isTure(param.getProjectId() == null).throwMessage(ResultCode.PARAM_MISS);
|
|
|
-// MPJLambdaWrapper<Marking> wrapper = new MPJLambdaWrapper<Marking>()
|
|
|
-// .selectAll(Marking.class)
|
|
|
-// .selectCollection(ProjectTeam.class, MarkingDTO::getUsers)
|
|
|
-// .leftJoin(MarkingUser.class, MarkingUser::getMarkingId, Marking::getMarkingId)
|
|
|
-// .leftJoin(ProjectTeam.class, ProjectTeam::getUserId, MarkingUser::getUserId)
|
|
|
-// .eq(Marking::getProjectId,param.getProjectId())
|
|
|
-// .eq(ProjectTeam::getProjectId,param.getProjectId());
|
|
|
-// if (Optional.ofNullable(param.getMarkingStatus()).isPresent()) {
|
|
|
-// wrapper.eq(Marking::getMarkingStatus,param.getMarkingStatus());
|
|
|
-// }
|
|
|
-// if (Optional.ofNullable(param.getMarkingTitle()).isPresent()&& StrUtil.isNotEmpty(param.getMarkingTitle())) {
|
|
|
-// wrapper.like(Marking::getMarkingTitle,param.getMarkingTitle());
|
|
|
-// }
|
|
|
-// IPage<MarkingDTO> page = baseMapper.selectJoinPage(new Page<>(param.getPageNum(), param.getPageSize()), MarkingDTO.class, wrapper);
|
|
|
-
|
|
|
VUtils.isTure(param.getProjectId() == null).throwMessage(ResultCode.PARAM_MISS);
|
|
|
+
|
|
|
+ List<Marking> byProjectId = findByProjectId(param.getProjectId());
|
|
|
+ Set<Integer> projectIds = new HashSet<>(Arrays.asList(param.getProjectId()));
|
|
|
+ List<ProjectNum> projectNum = projectNumService.getListByProjectIds(projectIds);
|
|
|
+ HashMap<Integer,List<String>> typeMap = projectNumService.getTypeMap(projectNum);
|
|
|
+ List<SceneVo> list = sceneService.getListByNumMap(typeMap);
|
|
|
+
|
|
|
+ List<Marking> difference = byProjectId.stream()
|
|
|
+ .filter(obj1 -> list.stream()
|
|
|
+ .noneMatch(obj2 -> obj2.getNum().equals(obj1.getNum())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (Marking marking : difference) {
|
|
|
+ delMarking(marking.getMarkingId());
|
|
|
+ }
|
|
|
MPJLambdaWrapper<Marking> wrapper = new MPJLambdaWrapper<Marking>()
|
|
|
.selectAll(Marking.class)
|
|
|
.eq(Marking::getProjectId,param.getProjectId());
|
|
@@ -66,6 +82,9 @@ public class MarkingServiceImpl extends ServiceImpl<IMarkingMapper, Marking> imp
|
|
|
wrapper.like(Marking::getMarkingTitle,param.getMarkingTitle());
|
|
|
}
|
|
|
IPage<MarkingDTO> page = baseMapper.selectJoinPage(new Page<>(param.getPageNum(), param.getPageSize()), MarkingDTO.class, wrapper);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
for (MarkingDTO record : page.getRecords()) {
|
|
|
List<UserDTO> users = markingUserService.findByProjectIdAndMarkingId(record.getProjectId(), record.getMarkingId());
|
|
|
record.setUsers(users);
|
|
@@ -100,6 +119,13 @@ public class MarkingServiceImpl extends ServiceImpl<IMarkingMapper, Marking> imp
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void delMarking(Integer markingId) {
|
|
|
+ LambdaUpdateWrapper<Marking> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(Marking::getMarkingId, markingId);
|
|
|
+ this.baseMapper.delete(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<Marking> findByProjectId(Integer projectId) {
|
|
|
LambdaQueryWrapper<Marking> wrapper=new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(Marking::getProjectId,projectId);
|
|
@@ -107,10 +133,59 @@ public class MarkingServiceImpl extends ServiceImpl<IMarkingMapper, Marking> imp
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Marking findByProjectIdAndNum(Integer projectId, String num) {
|
|
|
+ public List<Marking> findByProjectIdAndNum(Integer projectId, String num) {
|
|
|
LambdaQueryWrapper<Marking> wrapper=new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(Marking::getProjectId,projectId);
|
|
|
wrapper.eq(Marking::getNum,num);
|
|
|
- return getOne(wrapper);
|
|
|
+ return list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData addOrUpdate(MarkingParam param,String token) {
|
|
|
+
|
|
|
+ VUtils.isTure(param.getNum() == null).throwMessage(ResultCode.PARAM_MISS);
|
|
|
+ projectService.checkTokenPer(token, param.getProjectId());
|
|
|
+ if (Optional.ofNullable(param.getMarkingId()).isPresent()){
|
|
|
+ // 写不为空的逻辑
|
|
|
+ log.info("不为空修改");
|
|
|
+// ProjectTeam byUserIdAndProjectId = projectTeamService.findByUserIdAndProjectId(getUserId(), param.getProjectId());
|
|
|
+// param.setLastUpdateBy(byUserIdAndProjectId.getNickName());
|
|
|
+ updateById(param);
|
|
|
+ } else {
|
|
|
+ // 写为空的逻辑
|
|
|
+ log.info("为空");
|
|
|
+// ProjectTeam byUserIdAndProjectId = projectTeamService.findByUserIdAndProjectId(getUserId(), param.getProjectId());
|
|
|
+// param.setLastCreateBy(byUserIdAndProjectId.getNickName());
|
|
|
+ boolean save = save(param);
|
|
|
+ if (save){
|
|
|
+ Project project = projectService.getById(param.getProjectId());
|
|
|
+ if (ObjectUtil.isNotNull(project)){
|
|
|
+ if (CollectionUtil.isNotEmpty(param.getUserIds())) {
|
|
|
+ for (Integer userId : param.getUserIds()) {
|
|
|
+ ProjectTeam projectTeam = projectTeamService.findByUserIdAndProjectId(userId, param.getProjectId());
|
|
|
+ if (Optional.ofNullable(projectTeam).isPresent()&&Optional.ofNullable(projectTeam.getBindAccount()).isPresent()) {
|
|
|
+ try {
|
|
|
+ smsService.sendSms(projectTeam.getBindAccount(), "{\"projectname\":\"" + project.getProjectName() + "\"}", cnCode);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(param.getUserIds())) {
|
|
|
+ markingUserService.delByMarkingId(param.getMarkingId());
|
|
|
+ for (Integer userId : param.getUserIds()) {
|
|
|
+ MarkingUser markingUser=new MarkingUser();
|
|
|
+ markingUser.setUserId(userId);
|
|
|
+ markingUser.setMarkingId(param.getMarkingId());
|
|
|
+ markingUserService.save(markingUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultData.ok(param);
|
|
|
}
|
|
|
}
|