commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_union_cadre;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分工会干部档案维护服务。
|
||||
*/
|
||||
public interface SysUnionCadreService extends BaseService<Sys_union_cadre> {
|
||||
|
||||
/**
|
||||
* 返回分工会干部页面可维护的角色范围,列表、历史届次和新增校验均使用同一范围。
|
||||
*
|
||||
* @return 可维护的角色编码
|
||||
*/
|
||||
List<String> getBranchUnionRoleCodes();
|
||||
|
||||
/**
|
||||
* 新增分工会干部;角色已存在而档案缺失时,仅补充档案,不重复写入角色。
|
||||
*
|
||||
* @param userId 人员ID
|
||||
* @param roleCode 角色编码
|
||||
* @param unionId 分工会ID
|
||||
* @param j 教代会届次
|
||||
* @return 保存结果和可直接展示的提示信息
|
||||
*/
|
||||
Result saveBranchUnionCadre(String userId, String roleCode, String unionId, String j);
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.flow.constant.FlowConst;
|
||||
import com.budwk.app.flow.engine.FlowEngine;
|
||||
import com.budwk.app.flow.entity.ProcessInstance;
|
||||
import com.budwk.app.flow.entity.ProcessTask;
|
||||
import com.budwk.app.flow.enums.ProcessSubmitTypeEnum;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_union;
|
||||
import com.budwk.app.sys.models.Sys_union_cadre;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUnionCadreService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysUnionCadreServiceImpl extends BaseServiceImpl<Sys_union_cadre> implements SysUnionCadreService {
|
||||
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private FlowEngine flowEngine;
|
||||
|
||||
public SysUnionCadreServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getBranchUnionRoleCodes() {
|
||||
List<String> roleCodes = new ArrayList<>(sysDictService.getSubListByCode("BRANCH_UNION_ROLES")
|
||||
.stream().map(Sys_dict::getCode).toList());
|
||||
roleCodes.add(RoleConstant.BRANCH_UNION_ADMIN.name());
|
||||
roleCodes.add(RoleConstant.UNIT_PARTY_SECRETARY.name());
|
||||
return roleCodes.stream().filter(StrUtil::isNotBlank).distinct().toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result saveBranchUnionCadre(String userId, String roleCode, String unionId, String j) {
|
||||
if (StrUtil.hasBlank(userId, roleCode, unionId, j)) {
|
||||
return Result.error("人员、角色和届数均不能为空");
|
||||
}
|
||||
if (!getBranchUnionRoleCodes().contains(roleCode)) {
|
||||
return Result.error("该角色不允许在分工会干部中维护");
|
||||
}
|
||||
|
||||
Sys_role role = sysRoleService.fetch(Cnd.where("code", "=", roleCode));
|
||||
if (Lang.isEmpty(role)) {
|
||||
return Result.error("未找到对应的角色");
|
||||
}
|
||||
Sys_union union = dao().fetch(Sys_union.class, unionId);
|
||||
if (union == null) {
|
||||
return Result.error("未找到对应分工会");
|
||||
}
|
||||
View_user user = dao().fetch(View_user.class, Cnd.where("id", "=", userId));
|
||||
if (user == null) {
|
||||
return Result.error("未找到人员信息");
|
||||
}
|
||||
|
||||
Cnd cadreCnd = Cnd.where("userId", "=", userId)
|
||||
.and("unionId", "=", unionId)
|
||||
.and("roleCode", "=", roleCode)
|
||||
.and("j", "=", j)
|
||||
.and("delFlag", "=", false);
|
||||
Sys_union_cadre existedCadre = dao().fetch(Sys_union_cadre.class, cadreCnd);
|
||||
boolean existedRole = dao().count(Sys_user_role.class, Cnd.where("roleId", "=", role.getId())
|
||||
.and("userId", "=", userId).and("unionId", "=", unionId)) > 0;
|
||||
if (existedCadre != null) {
|
||||
return Result.error("该人员已担任本分工会本届该职务,请勿重复添加");
|
||||
}
|
||||
|
||||
Sys_union_cadre unionCadre = buildUnionCadre(user, union, roleCode, j);
|
||||
dao().insert(unionCadre);
|
||||
if (existedRole) {
|
||||
// 历史迁移或人工维护可能先写入角色。此处只补齐档案,避免重复授权或再次发起审批。
|
||||
return Result.success("该人员已有该职务,已补充分工会干部档案");
|
||||
}
|
||||
|
||||
// 保留原有新增审批流程:新角色仍需发起“分工会干部”流程,管理员按既有规则直接写入角色。
|
||||
boolean isAdmin = AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name());
|
||||
Dict args = Dict.create();
|
||||
args.set("submit", isAdmin ? "admin" : "branch");
|
||||
args.set(FlowConst.SUBMIT_TYPE, ProcessSubmitTypeEnum.APPLY.getCode());
|
||||
args.set(FlowConst.FORM_DATA, unionCadre);
|
||||
ProcessInstance instance = flowEngine.startProcessInstanceByKey("JCGHWY", unionCadre.getId(), SecurityUtil.getUserId(), args);
|
||||
List<ProcessTask> doingTaskList = flowEngine.processTaskService().getDoingTaskList(instance.getId(), null);
|
||||
for (ProcessTask task : doingTaskList) {
|
||||
flowEngine.executeProcessTask(task.getId(), SecurityUtil.getUserId(), args);
|
||||
}
|
||||
if (isAdmin) {
|
||||
sysRoleService.clear("sys_user_role", Cnd.where("roleId", "=", role.getId())
|
||||
.and("userId", "=", userId).and("unionId", "=", unionId));
|
||||
sysRoleService.insert("sys_user_role", Chain.make("roleId", role.getId())
|
||||
.add("userId", userId).add("unionId", unionId));
|
||||
sysRoleService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
}
|
||||
return Result.success("添加成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从当前人员和分工会信息生成干部档案;只读取人员资料,不修改 sys_user 的任何字段。
|
||||
*/
|
||||
private Sys_union_cadre buildUnionCadre(View_user user, Sys_union union, String roleCode, String j) {
|
||||
Sys_union_cadre unionCadre = new Sys_union_cadre();
|
||||
unionCadre.setUserId(user.getId());
|
||||
unionCadre.setUnionId(union.getId());
|
||||
unionCadre.setMobile(user.getMobile());
|
||||
unionCadre.setUnionName(union.getName());
|
||||
unionCadre.setLoginName(user.getLoginname());
|
||||
unionCadre.setUserName(user.getUsername());
|
||||
unionCadre.setRoleCode(roleCode);
|
||||
unionCadre.setJ(j);
|
||||
unionCadre.setApplyDate(new Date());
|
||||
unionCadre.setIsServing(true);
|
||||
unionCadre.setIsJoin(true);
|
||||
return unionCadre;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.budwk.app.zhgh.democratic.proposal.service;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.democratic.proposal.models.ProposalUndertake;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
/**
|
||||
* 提案承办单位配置服务。
|
||||
*/
|
||||
public interface ProposalUndertakeConfigService extends BaseService<ProposalUndertake> {
|
||||
|
||||
/**
|
||||
* 将系统中有效的二级单位补充为提案承办单位。
|
||||
* 已存在相同单位编码的承办单位不会被修改或删除。
|
||||
*
|
||||
* @return 包含候选数、新增数和已存在数的同步结果
|
||||
*/
|
||||
NutMap syncSystemUnits();
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.budwk.app.zhgh.democratic.proposal.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.zhgh.democratic.proposal.models.ProposalUndertake;
|
||||
import com.budwk.app.zhgh.democratic.proposal.service.ProposalUndertakeConfigService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class ProposalUndertakeConfigServiceImpl extends BaseServiceImpl<ProposalUndertake> implements ProposalUndertakeConfigService {
|
||||
|
||||
public ProposalUndertakeConfigServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap syncSystemUnits() {
|
||||
// V3 承办单位初始化范围是有父节点的二级单位;V4 的 unitTypeCode 不再能代表这个业务范围。
|
||||
List<Sys_unit> systemUnits = dao().query(Sys_unit.class, Cnd.where(Sys_unit::getUnitLevel, "=", 2)
|
||||
.and(Sys_unit::getParentId, "is not", null)
|
||||
.and(Sys_unit::getParentId, "!=", "")
|
||||
.and(Sys_unit::getDelFlag, "=", false)
|
||||
.asc(Sys_unit::getUnitcode));
|
||||
Set<String> configuredCodes = dao().query(ProposalUndertake.class, Cnd.NEW()).stream()
|
||||
.map(ProposalUndertake::getCode)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
List<ProposalUndertake> newUndertakes = systemUnits.stream()
|
||||
.filter(unit -> StrUtil.isNotBlank(unit.getUnitcode()))
|
||||
.filter(unit -> !configuredCodes.contains(unit.getUnitcode()))
|
||||
.map(this::createUndertake)
|
||||
.toList();
|
||||
if (!newUndertakes.isEmpty()) {
|
||||
dao().fastInsert(newUndertakes);
|
||||
}
|
||||
return NutMap.NEW()
|
||||
.addv("candidateCount", systemUnits.size())
|
||||
.addv("insertedCount", newUndertakes.size())
|
||||
.addv("existingCount", systemUnits.size() - newUndertakes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 承办单位与系统单位只共享稳定的单位 ID、编码和名称;同步时默认启用,不处理负责人角色。
|
||||
*/
|
||||
private ProposalUndertake createUndertake(Sys_unit unit) {
|
||||
ProposalUndertake undertake = new ProposalUndertake();
|
||||
undertake.setId(unit.getId());
|
||||
undertake.setCode(unit.getUnitcode());
|
||||
undertake.setName(unit.getName());
|
||||
undertake.setEnable(true);
|
||||
return undertake;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user