|
|
@@ -1,33 +1,47 @@
|
|
|
package com.xunmei.core.edu.service.impl;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.R;
|
|
|
+import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlanToExecOrg;
|
|
|
+import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlanToRole;
|
|
|
import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanInsertDto;
|
|
|
import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanPageDto;
|
|
|
import com.xunmei.common.core.domain.edu.vo.CoreEduTrainingPlanPageVo;
|
|
|
import com.xunmei.common.core.domain.edu.vo.CoreEduTrainingPlanRoleVo;
|
|
|
+import com.xunmei.common.core.exception.SystemException;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.core.edu.mapper.CoreEduTrainingPlanMapper;
|
|
|
+import com.xunmei.core.edu.mapper.CoreEduTrainingPlanToExecOrgMapper;
|
|
|
+import com.xunmei.core.edu.mapper.CoreEduTrainingPlanToRoleMapper;
|
|
|
import com.xunmei.core.edu.service.ICoreEduTrainingPlanService;
|
|
|
+import com.xunmei.core.edu.service.ICoreEduTrainingPlanToExecOrgService;
|
|
|
+import com.xunmei.core.edu.service.ICoreEduTrainingPlanToRoleService;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.BooleanUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlan;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
/**
|
|
|
* 教育培训计划Service业务层处理
|
|
|
@@ -41,6 +55,14 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
@Autowired
|
|
|
private CoreEduTrainingPlanMapper coreEduTrainingPlanMapper;
|
|
|
@Autowired
|
|
|
+ private ICoreEduTrainingPlanToRoleService coreEduTrainingPlanToRoleService;
|
|
|
+ @Autowired
|
|
|
+ private CoreEduTrainingPlanToRoleMapper coreEduTrainingPlanToRoleMapper;
|
|
|
+ @Autowired
|
|
|
+ private ICoreEduTrainingPlanToExecOrgService coreEduTrainingPlanToExecOrgService;
|
|
|
+ @Autowired
|
|
|
+ private CoreEduTrainingPlanToExecOrgMapper coreEduTrainingPlanToExecOrgMapper;
|
|
|
+ @Autowired
|
|
|
private RemoteOrgService orgService;
|
|
|
|
|
|
@Override
|
|
|
@@ -54,18 +76,28 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
}
|
|
|
//下穿
|
|
|
if (request.getCheckSub()) {
|
|
|
- R<SysOrg> r;
|
|
|
+ SysOrg r;
|
|
|
try {
|
|
|
- r = orgService.selectSysOrgById(request.getBelongOrgId(), SecurityConstants.INNER);
|
|
|
+ r = orgService.selectOrgById(request.getBelongOrgId(), SecurityConstants.INNER);
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException("远程调用错误:获取机构信息失败!");
|
|
|
}
|
|
|
- request.setBelongOrgPath(r.getData().getPath());
|
|
|
+ request.setBelongOrgPath(r.getPath());
|
|
|
}
|
|
|
//获取数据
|
|
|
page = coreEduTrainingPlanMapper.selectPageData(page, request);
|
|
|
+ SysOrg sysOrg;
|
|
|
+ try {
|
|
|
+ sysOrg = orgService.selectTopOrg(SecurityConstants.INNER);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("远程调用错误:获取机构信息失败!");
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
for (CoreEduTrainingPlanPageVo record : page.getRecords()) {
|
|
|
record.setNo(page.getRecords().indexOf(record) + 1);
|
|
|
+ if (ObjectUtil.equal(record.getCreateOrgId(), sysOrg.getId())) {
|
|
|
+ record.setCreateByTopOrg(1);
|
|
|
+ }
|
|
|
}
|
|
|
//抓换为TableDataInfo适配前端
|
|
|
TableDataInfo tableDataInfo = new TableDataInfo();
|
|
|
@@ -110,26 +142,56 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int insertCoreEduTrainingPlan(CoreEduTrainingPlanInsertDto request) {
|
|
|
+ if (ObjectUtil.isAllEmpty(request.getExecOrgType(), request.getPlanExecOrgIdList())) {
|
|
|
+ throw new RuntimeException("培训机构类型和执行机构不能同时为空!");
|
|
|
+ }
|
|
|
CoreEduTrainingPlan plan = new CoreEduTrainingPlan();
|
|
|
BeanUtils.copyProperties(request, plan);
|
|
|
+ plan.setId(IdWorker.getId());
|
|
|
plan.setCreateTime(new Date());
|
|
|
plan.setUpdateTime(new Date());
|
|
|
plan.setCreateBy(SecurityUtils.getUserId().toString());
|
|
|
plan.setUpdateBy(SecurityUtils.getUserId().toString());
|
|
|
- plan.setBuildTaskNow(request.getBuildTaskNow() ? 1 : 0);
|
|
|
+ plan.setBuildTaskNow(Boolean.TRUE.equals(request.getBuildTaskNow()) ? 1 : 0);
|
|
|
final Long orgId = SecurityUtils.getLoginUser().getSysUser().getOrgId();
|
|
|
SysOrg r;
|
|
|
+ SysOrg topOrg;
|
|
|
try {
|
|
|
r = orgService.selectOrgById(orgId, SecurityConstants.INNER);
|
|
|
+ topOrg = orgService.selectTopOrg(SecurityConstants.INNER);
|
|
|
} catch (Exception e) {
|
|
|
log.error("远程调用错误:获取机构信息失败!");
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- plan.setCreateOrgId(SecurityUtils.getLoginUser().getSysUser().getOrgId());
|
|
|
+ plan.setCreateOrgId(orgId);
|
|
|
plan.setCreateOrgName(r.getName());
|
|
|
plan.setCreateOrgPath(r.getPath());
|
|
|
+ plan.setBelongOrgId(orgId);
|
|
|
+ plan.setBelongOrgName(r.getName());
|
|
|
+ plan.setBelongOrgPath(r.getPath());
|
|
|
+ if (ObjectUtil.equal(orgId, topOrg.getId())) {
|
|
|
+ plan.setStandard(1);
|
|
|
+ plan.setIssue(0);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ List<CoreEduTrainingPlanToRole> planRoleList = new ArrayList<>();
|
|
|
+ for (Long roleId : request.getPlanRoleId()) {
|
|
|
+ CoreEduTrainingPlanToRole role = new CoreEduTrainingPlanToRole();
|
|
|
+ role.setRoleId(roleId);
|
|
|
+ role.setPlanId(plan.getId());
|
|
|
+ planRoleList.add(role);
|
|
|
+ }
|
|
|
+ coreEduTrainingPlanToRoleService.saveBatch(planRoleList);
|
|
|
+ if (ObjectUtil.isNotEmpty(request.getPlanExecOrgIdList())) {
|
|
|
+ List<CoreEduTrainingPlanToExecOrg> planOrgList = new ArrayList<CoreEduTrainingPlanToExecOrg>();
|
|
|
+ for (Long orgId1 : request.getPlanExecOrgIdList()) {
|
|
|
+ CoreEduTrainingPlanToExecOrg org = new CoreEduTrainingPlanToExecOrg();
|
|
|
+ org.setOrgId(orgId1);
|
|
|
+ org.setPlanId(plan.getId());
|
|
|
+ planOrgList.add(org);
|
|
|
+ }
|
|
|
+ coreEduTrainingPlanToExecOrgService.saveBatch(planOrgList);
|
|
|
+ }
|
|
|
return coreEduTrainingPlanMapper.insert(plan);
|
|
|
}
|
|
|
|
|
|
@@ -140,8 +202,10 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public int updateCoreEduTrainingPlan(CoreEduTrainingPlan coreEduTrainingPlan) {
|
|
|
coreEduTrainingPlan.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ coreEduTrainingPlan.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
|
|
|
return coreEduTrainingPlanMapper.updateById(coreEduTrainingPlan);
|
|
|
}
|
|
|
|
|
|
@@ -152,6 +216,7 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public int deleteCoreEduTrainingPlanByIds(Long[] ids) {
|
|
|
return coreEduTrainingPlanMapper.deleteBatchIds(Arrays.asList((ids)));
|
|
|
}
|
|
|
@@ -163,22 +228,57 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public int deleteCoreEduTrainingPlanById(Long id) {
|
|
|
return coreEduTrainingPlanMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+
|
|
|
public List<CoreEduTrainingPlanRoleVo> listPlanRole(Long orgId) {
|
|
|
if (orgId == null) {
|
|
|
- SysOrg r;
|
|
|
+ SysOrg r = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectTopOrg(SecurityConstants.INNER), "获取机构信息失败!");
|
|
|
+ orgId = r.getId();
|
|
|
+ }
|
|
|
+ return coreEduTrainingPlanMapper.selectPlanRole(orgId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void publishPlan(Long planId) {
|
|
|
+ final CoreEduTrainingPlan plan = coreEduTrainingPlanMapper.selectById(planId);
|
|
|
+ if (plan == null) {
|
|
|
+ throw new SystemException("计划不存在!");
|
|
|
+ }
|
|
|
+ // 下发 按钮显示逻辑:仅省联社安全保卫管理人员进入且由省联社管理安全保卫人员创建的计划才显示
|
|
|
+ //todo 判断当前人的角色信息
|
|
|
+
|
|
|
+
|
|
|
+ //获取执行角色
|
|
|
+ QueryWrapper<CoreEduTrainingPlanToRole> ros = new QueryWrapper<>();
|
|
|
+ ros.lambda().eq(CoreEduTrainingPlanToRole::getPlanId, plan.getId());
|
|
|
+ List<CoreEduTrainingPlanToRole> planRoleList = coreEduTrainingPlanToRoleMapper.selectList(ros);
|
|
|
+
|
|
|
+
|
|
|
+ final Integer execOrgType = plan.getExecOrgType();
|
|
|
+ List<SysOrg> orgList;
|
|
|
+ if (execOrgType != null) {
|
|
|
+ //获取具体执行检查的机构
|
|
|
try {
|
|
|
- r = orgService.selectTopOrg(SecurityConstants.INNER);
|
|
|
- orgId = r.getId();
|
|
|
+ orgList = orgService.selectByOrgType(execOrgType, SecurityConstants.INNER);
|
|
|
} catch (Exception e) {
|
|
|
log.error("远程调用错误:获取机构信息失败!,{}", e.getMessage());
|
|
|
- throw new RuntimeException("远程调用错误:获取机构信息失败!");
|
|
|
+ throw new SystemException("远程调用错误:获取机构信息失败!");
|
|
|
}
|
|
|
+ Assert.notEmpty(orgList, "无法根据培训机构类型找到具体机构,请修改计划内容!");
|
|
|
+ } else {
|
|
|
+ QueryWrapper<CoreEduTrainingPlanToExecOrg> eos = new QueryWrapper<>();
|
|
|
+ eos.lambda().eq(CoreEduTrainingPlanToExecOrg::getPlanId, plan.getId());
|
|
|
+ List<CoreEduTrainingPlanToExecOrg> execOrg = coreEduTrainingPlanToExecOrgMapper.selectList(eos);
|
|
|
+ Assert.notEmpty(execOrg, "未能查找到具体的培训机构,请联系管理员!");
|
|
|
+ final List<Long> list = execOrg.stream().map(CoreEduTrainingPlanToExecOrg::getOrgId).collect(Collectors.toList());
|
|
|
+ orgList = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectOrgByIdList(list, SecurityConstants.INNER), "未能查找到具体的培训机构,请联系管理员!");
|
|
|
}
|
|
|
- return coreEduTrainingPlanMapper.selectPlanRole(orgId);
|
|
|
+
|
|
|
}
|
|
|
}
|