|
@@ -0,0 +1,278 @@
|
|
|
+package com.factory.wx.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.factory.base.entity.aggregates.PageBean;
|
|
|
+import com.factory.base.entity.aggregates.ResponseBean;
|
|
|
+import com.factory.base.entity.po.benteler.BentelerPlan;
|
|
|
+import com.factory.base.entity.po.remote.UserInfo;
|
|
|
+import com.factory.base.util.res.ResponseBeanBuilder;
|
|
|
+import com.factory.user.mapper.UserInfoMapper;
|
|
|
+import com.factory.web.entity.pm.*;
|
|
|
+import com.factory.web.entity.pm.res.ApprovalUserRes;
|
|
|
+import com.factory.web.mapper.BentelerPlanMapper;
|
|
|
+import com.factory.web.mapper.pm.*;
|
|
|
+import com.factory.web.service.pm.PreventMistakeService;
|
|
|
+import com.factory.wx.entity.req.PassListReq;
|
|
|
+import com.factory.wx.entity.req.PlanApprovalReq;
|
|
|
+import com.factory.wx.entity.req.PlanInfoReq;
|
|
|
+import com.factory.wx.entity.req.PlanListReq;
|
|
|
+import com.factory.wx.entity.res.PlanApprovalDetailRes;
|
|
|
+import com.factory.wx.entity.res.PlanApprovalRes;
|
|
|
+import com.factory.wx.entity.res.PlanPassDetailRes;
|
|
|
+import com.factory.wx.mapper.PlanMapper;
|
|
|
+import com.factory.wx.service.PlanService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author sMArT
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2021-07-13 12:42 下午
|
|
|
+ */
|
|
|
+@Service("planService")
|
|
|
+public class PlanServiceImpl implements PlanService {
|
|
|
+
|
|
|
+ private final static Logger LOGGER = LoggerFactory.getLogger(PlanServiceImpl.class);
|
|
|
+ /**
|
|
|
+ * 审批规则类型为:1新建计划审批
|
|
|
+ */
|
|
|
+ private static int APPROVAL_TYPE_NEW = 1;
|
|
|
+ @Autowired
|
|
|
+ private PlanMapper planMapper;
|
|
|
+ @Autowired
|
|
|
+ private BentelerPlanMapper bentelerPlanMapper;
|
|
|
+ @Autowired
|
|
|
+ private OnsiteCalendarMapper onsiteCalendarMapper;
|
|
|
+ @Autowired
|
|
|
+ private OnsiteWorkshopMapper onsiteWorkshopMapper;
|
|
|
+ @Autowired
|
|
|
+ private OnsiteItemMapper onsiteItemMapper;
|
|
|
+ @Autowired
|
|
|
+ private OnsiteApprovalPlanMapper onsiteApprovalPlanMapper;
|
|
|
+ @Autowired
|
|
|
+ private ApprovalRuleMapper approvalRuleMapper;
|
|
|
+ @Autowired
|
|
|
+ private UserInfoMapper userInfoMapper;
|
|
|
+ @Autowired
|
|
|
+ private PreventMistakeService preventMistakeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OnsiteApprovalTaskMapper onsiteApprovalTaskMapper;
|
|
|
+ @Autowired
|
|
|
+ private OnsiteTaskMapper onsiteTaskMapper;
|
|
|
+
|
|
|
+ private static IPage<BentelerPlan> getBentelerPlanIPage(PassListReq passListReq, List<OnsiteCalendar> onsiteCalendarList, BentelerPlanMapper bentelerPlanMapper) {
|
|
|
+ IPage<BentelerPlan> bentelerPlanIPage;
|
|
|
+ List<Long> planIds = onsiteCalendarList.stream().map(OnsiteCalendar::getBentelerPlanId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BentelerPlan> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.in(BentelerPlan::getId, planIds);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(passListReq.getName())) {
|
|
|
+ wrapper.like(BentelerPlan::getName, passListReq.getName());
|
|
|
+ }
|
|
|
+ IPage<BentelerPlan> page = new Page<>(passListReq.getPage(), passListReq.getSize());
|
|
|
+ bentelerPlanIPage = bentelerPlanMapper.selectPage(page, wrapper);
|
|
|
+ return bentelerPlanIPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取计划审批列表
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<PlanApprovalRes> getApprovalList(Long userId) {
|
|
|
+ return planMapper.getApprovalList(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页显示计划列表
|
|
|
+ *
|
|
|
+ * @param planListReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageBean<BentelerPlan> getApprovalListByPage(PlanListReq planListReq) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<OnsiteApprovalPlan> approvalPlanWrapper = new LambdaQueryWrapper<>();
|
|
|
+ approvalPlanWrapper.eq(OnsiteApprovalPlan::getApprovalUserId, planListReq.getUserId());
|
|
|
+ approvalPlanWrapper.eq(OnsiteApprovalPlan::getStatus, 0);//获取未处理过的计划
|
|
|
+ List<OnsiteApprovalPlan> onsiteApprovalPlanList = onsiteApprovalPlanMapper.selectList(approvalPlanWrapper);
|
|
|
+
|
|
|
+ IPage<BentelerPlan> bentelerPlanIPage = new Page<>();
|
|
|
+ if (CollUtil.isNotEmpty(onsiteApprovalPlanList)) {
|
|
|
+ LambdaQueryWrapper<BentelerPlan> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ List<Long> planIds = onsiteApprovalPlanList.stream().map(OnsiteApprovalPlan::getBentelerPlanId).collect(Collectors.toList());
|
|
|
+ wrapper.in(BentelerPlan::getId, planIds);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(planListReq.getName())) {
|
|
|
+ wrapper.like(BentelerPlan::getName, planListReq.getName());
|
|
|
+ }
|
|
|
+ IPage<BentelerPlan> page = new Page<>(planListReq.getPage(), planListReq.getSize());
|
|
|
+ bentelerPlanIPage = bentelerPlanMapper.selectPage(page, wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ return PageBean.<BentelerPlan>builder().row(bentelerPlanIPage.getRecords()).total(bentelerPlanIPage.getTotal()).page(bentelerPlanIPage.getPages()).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取审批计划详情-防错
|
|
|
+ *
|
|
|
+ * @param planInfoReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PlanApprovalDetailRes getApprovalDetail(PlanInfoReq planInfoReq) {
|
|
|
+ BentelerPlan bentelerPlan = bentelerPlanMapper.selectById(planInfoReq.getPlanId());
|
|
|
+ List<OnsiteCalendar> onsiteCalendarList = onsiteCalendarMapper.selectList(Wrappers.<OnsiteCalendar>lambdaQuery()
|
|
|
+ .eq(OnsiteCalendar::getBentelerPlanId, planInfoReq.getPlanId()));
|
|
|
+
|
|
|
+ List<String> usersName = new ArrayList<>();
|
|
|
+ onsiteCalendarList.forEach(onsiteCalendar -> {
|
|
|
+ UserInfo userInfo = userInfoMapper.selectById(onsiteCalendar.getUserId());
|
|
|
+ usersName.add(userInfo.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+ //获取title
|
|
|
+ OnsiteTitle title = preventMistakeService.getTitle(planInfoReq.getPlanId());
|
|
|
+
|
|
|
+ List<OnsiteWorkshop> onsiteWorkshopList = onsiteWorkshopMapper.selectList(Wrappers.<OnsiteWorkshop>lambdaQuery()
|
|
|
+ .eq(OnsiteWorkshop::getBentelerPlanId, planInfoReq.getPlanId()));
|
|
|
+ onsiteWorkshopList.forEach(onsiteWorkshop -> {
|
|
|
+ onsiteWorkshop.setOnsiteItemList(onsiteItemMapper.selectList(Wrappers.<OnsiteItem>lambdaQuery()
|
|
|
+ .eq(OnsiteItem::getWorkshopId, onsiteWorkshop.getId())));
|
|
|
+ });
|
|
|
+
|
|
|
+ PlanApprovalDetailRes planApprovalDetailRes = PlanApprovalDetailRes.builder()
|
|
|
+ .planId(bentelerPlan.getId())
|
|
|
+ .planName(bentelerPlan.getName())
|
|
|
+ .effectiveDate(bentelerPlan.getEffectiveDate())
|
|
|
+ .usersName(usersName)
|
|
|
+ .titleInfo(title)
|
|
|
+ .onsiteCalendars(onsiteCalendarList)
|
|
|
+ .onsiteWorkshops(onsiteWorkshopList)
|
|
|
+ .build();
|
|
|
+ return planApprovalDetailRes;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计划审批
|
|
|
+ *
|
|
|
+ * @param planApprovalReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseBean approvalOperate(PlanApprovalReq planApprovalReq) {
|
|
|
+
|
|
|
+ OnsiteApprovalPlan onsiteApprovalPlan = new OnsiteApprovalPlan();
|
|
|
+ onsiteApprovalPlan.setStatus(planApprovalReq.getStatus());
|
|
|
+ int updateStatus = onsiteApprovalPlanMapper.update(onsiteApprovalPlan, Wrappers.<OnsiteApprovalPlan>lambdaQuery()
|
|
|
+ .eq(OnsiteApprovalPlan::getBentelerPlanId, planApprovalReq.getPlanId())
|
|
|
+ .eq(OnsiteApprovalPlan::getApprovalUserId, planApprovalReq.getUserId()));
|
|
|
+ if (updateStatus > 0) {
|
|
|
+ //审批通过触发下一级别
|
|
|
+ if (planApprovalReq.getStatus() == 1) {
|
|
|
+ ApprovalRule approvalRuleMaxLevel = approvalRuleMapper.selectOne(Wrappers.<ApprovalRule>lambdaQuery()
|
|
|
+ .eq(ApprovalRule::getType, APPROVAL_TYPE_NEW)
|
|
|
+ .orderByDesc(ApprovalRule::getApprovalLevel)
|
|
|
+ .last("limit 1"));
|
|
|
+ //获取当前审批级别
|
|
|
+ OnsiteApprovalPlan userApprovalInfo = onsiteApprovalPlanMapper.selectOne(Wrappers.<OnsiteApprovalPlan>lambdaQuery()
|
|
|
+ .eq(OnsiteApprovalPlan::getBentelerPlanId, planApprovalReq.getPlanId())
|
|
|
+ .eq(OnsiteApprovalPlan::getApprovalUserId, planApprovalReq.getUserId()).last("limit 1"));
|
|
|
+ int userLevel = userApprovalInfo.getApprovalLevel();
|
|
|
+ if (userLevel < approvalRuleMaxLevel.getApprovalLevel()) {
|
|
|
+ ApprovalUserRes approvalUserRes = preventMistakeService.getApprovalUserInfo(userLevel + 1, APPROVAL_TYPE_NEW);
|
|
|
+ onsiteApprovalPlanMapper.insert(OnsiteApprovalPlan.builder()
|
|
|
+ .bentelerPlanId(planApprovalReq.getPlanId())
|
|
|
+ .approvalLevel(approvalUserRes.getApprovalLevel())
|
|
|
+ .approvalUserId(approvalUserRes.getUserId())
|
|
|
+ .status(0)
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //审批不通过
|
|
|
+ if (planApprovalReq.getStatus() == 2) {
|
|
|
+ //审批不通过,保存审批历史
|
|
|
+// preventMistakeService.setOnsitePlanHis(planApprovalReq.getPlanId());
|
|
|
+ preventMistakeService.getApprovalUserInfo(1, APPROVAL_TYPE_NEW);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseBeanBuilder.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计划放行列表
|
|
|
+ *
|
|
|
+ * @param passListReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageBean<BentelerPlan> getPassListByPage(PassListReq passListReq) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<OnsiteApprovalTask> approvalTaskWrapper = new LambdaQueryWrapper<>();
|
|
|
+ approvalTaskWrapper.eq(OnsiteApprovalTask::getApprovalUserId, passListReq.getUserId());
|
|
|
+ approvalTaskWrapper.eq(OnsiteApprovalTask::getStatus, 0);//获取未处理过的计划
|
|
|
+
|
|
|
+ List<OnsiteApprovalTask> onsiteApprovalTaskList = onsiteApprovalTaskMapper.selectList(approvalTaskWrapper);
|
|
|
+ IPage<BentelerPlan> bentelerPlanIPage = new Page<>();
|
|
|
+ if (CollUtil.isNotEmpty(onsiteApprovalTaskList)) {
|
|
|
+ List<Long> taskIds = onsiteApprovalTaskList.stream().map(OnsiteApprovalTask::getOnsiteTaskId).collect(Collectors.toList());
|
|
|
+ List<OnsiteTask> onsiteTaskList = onsiteTaskMapper.selectBatchIds(taskIds);
|
|
|
+ if (CollUtil.isNotEmpty(onsiteTaskList)) {
|
|
|
+ List<Long> calendarIds = onsiteTaskList.stream().map(OnsiteTask::getOnsiteCalendarId).collect(Collectors.toList());
|
|
|
+ List<OnsiteCalendar> onsiteCalendarList = onsiteCalendarMapper.selectBatchIds(calendarIds);
|
|
|
+ if (CollUtil.isNotEmpty(onsiteCalendarList)) {
|
|
|
+ bentelerPlanIPage = getBentelerPlanIPage(passListReq, onsiteCalendarList, bentelerPlanMapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return PageBean.<BentelerPlan>builder().row(bentelerPlanIPage.getRecords()).total(bentelerPlanIPage.getTotal()).page(bentelerPlanIPage.getPages()).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计划放行详情
|
|
|
+ *
|
|
|
+ * @param planInfoReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PlanPassDetailRes getPassDetail(PlanInfoReq planInfoReq) {
|
|
|
+ BentelerPlan bentelerPlan = bentelerPlanMapper.selectById(planInfoReq.getPlanId());
|
|
|
+ List<OnsiteCalendar> onsiteCalendarList = onsiteCalendarMapper.selectList(Wrappers.<OnsiteCalendar>lambdaQuery()
|
|
|
+ .eq(OnsiteCalendar::getBentelerPlanId, planInfoReq.getPlanId()));
|
|
|
+
|
|
|
+ List<String> usersName = new ArrayList<>();
|
|
|
+ onsiteCalendarList.forEach(onsiteCalendar -> {
|
|
|
+ UserInfo userInfo = userInfoMapper.selectById(onsiteCalendar.getUserId());
|
|
|
+ usersName.add(userInfo.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+ //获取title
|
|
|
+ OnsiteTitle title = preventMistakeService.getTitle(planInfoReq.getPlanId());
|
|
|
+
|
|
|
+ PlanPassDetailRes planPassDetailRes = PlanPassDetailRes.builder()
|
|
|
+ .planId(bentelerPlan.getId())
|
|
|
+ .planName(bentelerPlan.getName())
|
|
|
+ .effectiveDate(bentelerPlan.getEffectiveDate())
|
|
|
+ .usersName(usersName)
|
|
|
+ .titleInfo(title)
|
|
|
+ .onsiteCalendars(onsiteCalendarList)
|
|
|
+ .build();
|
|
|
+ return planPassDetailRes;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|