组织架构考勤规则修改初次提交

This commit is contained in:
fl 2024-12-02 17:01:20 +08:00
parent 4b0497270d
commit c8f167dc50
6 changed files with 715 additions and 0 deletions

View File

@ -0,0 +1,123 @@
package com.bonus.system.att.controller;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.Log;
import com.bonus.common.log.enums.BusinessType;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.system.att.entity.AttGroupBean;
import com.bonus.system.att.entity.OrgChangeBean;
import com.bonus.system.att.service.OrgChangeService;
import com.bonus.system.basic.domain.SysTree;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* 组织架构变更
*
* @author fly
*/
@RestController
@RequestMapping("/orgChange")
@Slf4j
public class OrgChangeController extends BaseController {
@Resource(name = "OrgChangeService")
private OrgChangeService orgChangeService;
/**
* 获取组织架构列表
*/
@RequiresPermissions("att:org:change:list")
@GetMapping("/list")
@Log(title = "考勤设置->组织架构变更->列表查询", businessType = BusinessType.QUERY)
public TableDataInfo list(OrgChangeBean bean) {
try{
startPage();
return getDataTable(orgChangeService.selectOrgChangeList(bean));
}catch (Exception e){
log.error(e.toString(),e);
}
return getDataTableError(new ArrayList<>());
}
/**
* 新增组织架构变更单
*/
@RequiresPermissions("att:org:change:add")
@PostMapping
@Log(title = "考勤设置->组织架构变更->组织架构新增", businessType = BusinessType.INSERT)
public AjaxResult add(@RequestBody OrgChangeBean bean) {
try{
return toAjax(orgChangeService.insertOrgChange(bean));
}catch (Exception e){
log.error(e.toString(),e);
}
return error("系统异常");
}
/**
* 根据组织架构编号获取详细信息
*/
@RequiresPermissions("att:org:change:query")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable Long id) {
try{
return success(orgChangeService.selectOrgChangeById(id));
}catch (Exception e){
log.error(e.toString(),e);
}
return error("系统异常");
}
/**
* 修改组织架构
*/
@RequiresPermissions("att:org:change:edit")
@PutMapping
@Log(title = "考勤设置->组织架构变更->组织架构修改", businessType = BusinessType.UPDATE)
public AjaxResult edit(@RequestBody OrgChangeBean bean) {
try{
return toAjax(orgChangeService.updateOrgChange(bean));
}catch (Exception e){
log.error(e.toString(),e);
}
return error("系统异常");
}
/**
* 删除组织架构
*/
@RequiresPermissions("att:group:remove")
@DeleteMapping("/{groupId}")
@Log(title = "考勤设置->组织架构变更->组织架构删除", businessType = BusinessType.DELETE)
public AjaxResult remove(@PathVariable("groupId") Long groupId) {
try{
return toAjax(orgChangeService.deleteAttGroup(groupId));
}catch (Exception e){
log.error(e.toString(),e);
}
return error("系统异常");
}
/**
* 查询组织选择列表
*/
@PostMapping("/selectOrgList")
@Log(title = "考勤设置->查询组织选择列表", businessType = BusinessType.QUERY)
public AjaxResult selectOrgList() {
try{
List<SysTree> sysTrees = orgChangeService.selectOrgList();
return success(sysTrees);
}catch (Exception e){
log.error(e.toString(),e);
}
return error("系统异常");
}
}

View File

@ -0,0 +1,116 @@
package com.bonus.system.att.dao;
import com.bonus.system.att.entity.AttGroupBean;
import com.bonus.system.att.entity.AttGroupCheckOrgBean;
import com.bonus.system.att.entity.OrgChangeBean;
import com.bonus.system.basic.domain.SysTree;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
/**
* 考勤组-数据访问层
* @author zys
*/
@Repository("OrgChangeDao")
public interface OrgChangeDao {
/**
* 获取考勤组列表
* @param bean 参数
* @return list bean
*/
List<OrgChangeBean> selectOrgChangeList(OrgChangeBean bean);
/**
* 查询组织选择列表
* @return list bean
*/
List<AttGroupCheckOrgBean> selectOrgList();
/**
* 删除考勤组
* @param groupId 考勤组编号
* @return 1|0
*/
int deleteAttGroup(Long groupId);
/**
* 上传考勤组表
* @param bean 参数
* @return 1|0
*/
int insertOrgChange(OrgChangeBean bean);
/**
* 上传考勤组设置表
* @param bean 参数
* @return 1|0
*/
int insertAttGroupSetting(AttGroupBean bean);
/**
* 上传考勤人员绑定表
* @param checkOrgList 参数
* @return 1|0
*/
int insertAttGroupPerson(List<AttGroupCheckOrgBean> checkOrgList);
/**
* 根据考勤组编号获取详细信息
* @param groupId 考勤组编号
* @return bean
*/
AttGroupBean selectAttGroupById(Long groupId);
/**
* 根据考勤组编号获取人员绑定情况
* @param groupId 考勤组编号
* @return list bean
*/
OrgChangeBean selectOrgChangeById(Long id);
/**
* 删除考勤组绑定人员
* @param groupId 考勤组编号
*/
void deleteAttGroupRelationPerson(Long groupId);
/**
* 修改考勤组
* @param bean 参数
* @return 1|0
*/
int updateOrgChange(OrgChangeBean bean);
/**
* 修改考勤组设置表
* @param bean 参数
* @return 1|0
*/
int updateAttGroupSetting(AttGroupBean bean);
/**
* 查询人员是否绑定考勤组
* @param id 用户编号
* @return 1|0
*/
String getAttGroupPersonIsBind(long id);
/**
* 查询出可选中人员
* @return list bean
*/
List<SysTree> getAttGroupCheckPerson();
/**
*
* 根据组织编号获取人员
* @param idList 组织编号
* @param groupId 考勤组当前考情组
* @return list bean
*/
List<AttGroupCheckOrgBean> getUserByOrg(@Param("idList")ArrayList<String> idList, @Param("groupId")Long groupId);
}

View File

@ -0,0 +1,98 @@
package com.bonus.system.att.entity;
import com.bonus.system.basic.domain.SysTree;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 组织架构变更实体类
* @author fly
*/
@Data
@NoArgsConstructor
public class OrgChangeBean {
/**
* 编号
*/
private Long id;
/**
* 申请人编号
*/
private Long userId;
/**
* 申请人
*/
private String userName;
/**
* 变更前部门编号
*/
private Long oldOrgId;
/**
* 变更前部门
*/
private String oldOrgName;
/**
* 变更后部门编号
*/
private Long newOrgId;
/**
* 变更后部门
*/
private String newOrgName;
/**
* 是否变更考勤组 0 不变 1
*/
private String isChangeAttGroup;
/**
* 变更前考勤组编号
*/
private Long oldAttGroup;
/**
* 变更后考勤组编号
*/
private String newAttGroup;
/**
* 生效日期
*/
private Long changeEffectiveDate;
/**
* 是否审核通过 0 未审核 1 已通过 2 未通过
*/
private Long isCheck;
/**
* 审核人编号
*/
private Long checkUserId;
/**
* 审核时间
*/
private Long checkTime;
/**
* 备注
*/
private String remark;
/**
* 是否有效
*/
private Integer isActive;
}

View File

@ -0,0 +1,55 @@
package com.bonus.system.att.service;
import com.bonus.system.att.entity.AttGroupBean;
import com.bonus.system.att.entity.OrgChangeBean;
import com.bonus.system.basic.domain.SysTree;
import java.util.List;
/**
* 考勤组-业务层
* @author zys
*/
public interface OrgChangeService {
/**
* 获取考勤组列表
* @param bean 参数
* @return list bean
*/
List<OrgChangeBean> selectOrgChangeList(OrgChangeBean bean);
/**
* 查询组织选择列表
* @return map
*/
List<SysTree> selectOrgList();
/**
* 删除考勤组
* @param groupId 考勤组编号
* @return 1|0
*/
int deleteAttGroup(Long groupId);
/**
* 新增考勤组
* @param bean 参数
* @return 1|0
*/
int insertOrgChange(OrgChangeBean bean);
/**
* 根据考勤组编号获取详细信息
* @param groupId 考勤组编号
* @return bean
*/
OrgChangeBean selectOrgChangeById(Long groupId);
/**
* 修改考勤组
* @param bean 参数
* @return 1|0
*/
int updateOrgChange(OrgChangeBean bean);
}

View File

@ -0,0 +1,111 @@
package com.bonus.system.att.service;
import com.bonus.common.core.constant.Constants;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.system.att.dao.OrgChangeDao;
import com.bonus.system.att.entity.AttGroupBean;
import com.bonus.system.att.entity.AttGroupCheckOrgBean;
import com.bonus.system.att.entity.OrgChangeBean;
import com.bonus.system.att.utils.TreeUtils;
import com.bonus.system.basic.domain.SysTree;
import com.bonus.system.dept.dao.ProDeptRoleDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* 考勤组-业务层
*
* @author zys
*/
@Service("OrgChangeService")
public class OrgChangeServiceImpl implements OrgChangeService {
@Resource(name = "OrgChangeDao")
private OrgChangeDao orgChangeDao;
@Resource(name = "ProDeptRoleDao")
private ProDeptRoleDao proDeptRoleDao;
@Override
public List<OrgChangeBean> selectOrgChangeList(OrgChangeBean bean) {
return orgChangeDao.selectOrgChangeList(bean);
}
@Override
public List<SysTree> selectOrgList() {
List<SysTree> listTree = orgChangeDao.getAttGroupCheckPerson();
// 返回处理后的树形结构
return listTree.stream()
.filter(m -> m.getParentId() == null)
.peek(m -> m.setChildren(TreeUtils.getOrgTreeChild(m, listTree, 0)))
.collect(Collectors.toList());
}
@Override
public int deleteAttGroup(Long groupId) {
return orgChangeDao.deleteAttGroup(groupId);
}
@Transactional(rollbackFor = Exception.class)
@Override
public int insertOrgChange(OrgChangeBean bean) {
//新增考勤组表
return orgChangeDao.insertOrgChange(bean);
}
@Override
public OrgChangeBean selectOrgChangeById(Long id) {
return orgChangeDao.selectOrgChangeById(id);
}
@Transactional(rollbackFor = Exception.class)
@Override
public int updateOrgChange(OrgChangeBean bean) {
return orgChangeDao.updateOrgChange(bean);
}
private List<AttGroupCheckOrgBean> dealWithOrgUser(AttGroupBean bean, Long bean1) {
//只有部门的将部门变成部门下所有人(去除掉其他考勤组选的人)
List<AttGroupCheckOrgBean> checkOrgAllList = bean.getCheckOrgList();
List<AttGroupCheckOrgBean> checkOrgList = new ArrayList<>();
checkOrgAllList.forEach(c -> {
if (!"".equals(c.getOrgId()) && "".equals(c.getUserId())) {
String id = proDeptRoleDao.getOrgChildById(Long.valueOf(c.getOrgId()));
// 使用 Arrays.asList() 将数组转换为 ArrayList
ArrayList<String> idList = new ArrayList<>(Arrays.asList(id.split(",")));
List<AttGroupCheckOrgBean> userList = orgChangeDao.getUserByOrg(idList, bean1);
checkOrgList.addAll(userList);
}
}
);
checkOrgAllList.addAll(checkOrgList);
// 使用 Iterator 来安全地遍历并移除元素
Iterator<AttGroupCheckOrgBean> iterator = checkOrgAllList.iterator();
while (iterator.hasNext()) {
AttGroupCheckOrgBean person = iterator.next();
if (person.getUserId().isEmpty()) {
// 如果 userId 为空或空字符串则移除该元素
iterator.remove();
} else {
// 否则设置 groupId
person.setGroupId(bean.getGroupId());
}
}
return checkOrgAllList;
}
private List<SysTree> getOrgCheckList(List<SysTree> orgList, List<AttGroupCheckOrgBean> checkList) {
// 使用forEach结合stream进行比对
checkList.forEach(c -> orgList.stream().filter(v -> (c.getUserId() + Constants.VERTICAL +
c.getOrgId()).equals(v.getId())).forEach(x -> x.setIsChecked(true)));
return orgList;
}
}

View File

@ -0,0 +1,212 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.system.att.dao.OrgChangeDao">
<select id="selectOrgChangeList" resultType="com.bonus.system.att.entity.OrgChangeBean">
SELECT
su.user_name,
so.org_name AS oldOrgName,
so2.org_name AS newOrgName,
oc.*
FROM
org_change oc
LEFT JOIN sys_user su ON oc.user_id = su.user_id
AND su.is_active = '1'
LEFT JOIN sys_organization so ON oc.old_org_id = so.id
AND so.is_active = '1'
LEFT JOIN sys_organization so2 ON oc.new_org_id = so2.id
AND so2.is_active = '1'
WHERE
oc.is_active = '1'
<if test="startTime != null and startTime != '' ">
and oc.create_time between #{startTime} and #{endTime}
</if>
<if test="isCheck != null and isCheck != '' ">
and oc.is_check = #{isCheck}
</if>
</select>
<select id="selectOrgList" resultType="com.bonus.system.att.entity.AttGroupCheckOrgBean">
select org.id as orgId,
org.org_name as orgName,
su.user_id,
su.user_name,
IF(agpr.is_active is null, 0, 1) as isBind
from sys_organization org
left join sys_user_org suo on suo.org_id = org.id and org.is_active = 1
left join sys_user su on su.user_id = suo.user_id and su.is_active = 1
left join att_group_person_relation agpr on agpr.user_id = su.user_id and agpr.is_active = 1
where org.is_active = 1
GROUP BY org.id, su.user_id
</select>
<select id="selectAttGroupById" resultType="com.bonus.system.att.entity.AttGroupBean">
select ag.id as groupId, ag.*, ags.*
from att_group ag
left join att_group_setting ags on ags.group_id = ag.id and ags.is_active = 1
where ag.is_active = 1
and ag.id = #{groupId}
</select>
<select id="selectOrgChangeById" resultType="com.bonus.system.att.entity.OrgChangeBean">
SELECT
su.user_name,
so.org_name AS oldOrgName,
so2.org_name AS newOrgName,
oc.*
FROM
org_change oc
LEFT JOIN sys_user su ON oc.user_id = su.user_id
AND su.is_active = '1'
LEFT JOIN sys_organization so ON oc.old_org_id = so.id
AND so.is_active = '1'
LEFT JOIN sys_organization so2 ON oc.new_org_id = so2.id
AND so2.is_active = '1'
WHERE
oc.is_active = '1'
and oc.id = #{id}
</select>
<select id="getAttGroupPersonIsBind" resultType="java.lang.String">
SELECT IFNULL((SELECT is_active
FROM att_group_person_relation
WHERE user_id = #{id}
AND is_active = 1), 0) as idBind
FROM DUAL
</select>
<select id="getAttGroupCheckPerson" resultType="com.bonus.system.basic.domain.SysTree">
select id, org_name as name, parent_id, false as disabled, '' as userId, id as orgId
from sys_organization
where is_active = 1
union
select CONCAT(su.user_id, '|', suo.org_id) as id,
user_name as name,
suo.org_id as parnet_id,
if(agpr.is_active is null, false, true) as disabled,
su.user_id,
suo.org_id
from sys_user su
left join sys_user_org suo on suo.user_id = su.user_id and suo.is_active = 1
left join att_group_person_relation agpr on agpr.user_id = su.user_id and agpr.is_active = 1
where su.is_active = 1
</select>
<select id="getUserByOrg" resultType="com.bonus.system.att.entity.AttGroupCheckOrgBean">
SELECT
su.user_id,
suo.org_id
FROM
sys_user su
LEFT JOIN sys_user_org suo ON suo.user_id = su.user_id
AND suo.is_active = 1
LEFT JOIN att_group_person_relation agpr ON agpr.user_id = su.user_id
<if test="groupId != null and groupId != ''">
and agpr.group_id != #{groupId}
</if>
AND agpr.is_active = 1
WHERE
su.is_active = 1
<if test="idList != null and idList.size() > 0">
AND suo.org_id IN
<foreach item="id" collection="idList" separator="," open="(" close=")" index="">
#{id}
</foreach>
</if>
AND agpr.user_id IS NULL
</select>
<delete id="deleteAttGroup">
update att_group
set is_active = 0
where id = #{groupId};
update att_group_setting
set is_active = 0
where group_id = #{groupId};
update att_group_person_relation
set is_active = 0
where group_id = #{groupId};
</delete>
<delete id="deleteAttGroupRelationPerson">
update att_group_person_relation
set is_active = 0
where group_id = #{groupId};
</delete>
<insert id="insertOrgChange" useGeneratedKeys="true" keyColumn="id" keyProperty="groupId">
insert into org_change(user_id, old_org_id, new_org_id,is_change_att_group, change_effective_date, is_check
remark)
values (#{userId},#{oldOrgId},#{newOrgId},#{isChangeAttGroup},#{changeTime},#{createUserId},#{remark})
<if test="oldAttGroup != null and oldAttGroup != ''">,old_att_group</if>
<if test="newAttGroup != null and newAttGroup != ''">,new_att_group</if>
) values (#{userId},#{oldOrgId},#{newOrgId},#{isChangeAttGroup},#{changeEffectiveDate},#{isCheck}
<if test="oldAttGroup != null and oldAttGroup != ''">,#{oldAttGroup}</if>
<if test="newAttGroup != null and newAttGroup != ''">,#{newAttGroup}</if>
)
</insert>
<insert id="insertAttGroupSetting">
insert into att_group_setting(group_id, att_day
<if test="toWorkTime != null and toWorkTime != ''">,to_work_time</if>
<if test="offWorkTime != null and offWorkTime != ''">,off_work_time</if>
<if test="lateMinute != null and lateMinute != ''">,late_minute</if>
<if test="leaveMinute != null and leaveMinute != ''">,leave_minute</if>
<if test="absenteeismLateMinute != null and absenteeismLateMinute != ''">,absenteeism_late_minute</if>
<if test="absenteeismLeaveMinute != null and absenteeismLeaveMinute != ''">,absenteeism_leave_minute</if>
<if test="entryAbnormalMinute != null and entryAbnormalMinute != ''">,entry_abnormal_minute</if>
<if test="todayClockNum != null and todayClockNum != ''">,today_clock_num</if>
<if test="attendanceDuration != null and attendanceDuration != ''">,attendance_duration</if>
)values( #{groupId}, #{attDay}
<if test="toWorkTime != null and toWorkTime != ''">,#{toWorkTime}</if>
<if test="offWorkTime != null and offWorkTime != ''">,#{offWorkTime}</if>
<if test="lateMinute != null and lateMinute != ''">,#{lateMinute}</if>
<if test="leaveMinute != null and leaveMinute != ''">,#{leaveMinute}</if>
<if test="absenteeismLateMinute != null and absenteeismLateMinute != ''">,#{absenteeismLateMinute}</if>
<if test="absenteeismLeaveMinute != null and absenteeismLeaveMinute != ''">,#{absenteeismLeaveMinute}</if>
<if test="entryAbnormalMinute != null and entryAbnormalMinute != ''">,#{entryAbnormalMinute}</if>
<if test="todayClockNum != null and todayClockNum != ''">,#{todayClockNum}</if>
<if test="attendanceDuration != null and attendanceDuration != ''">,#{attendanceDuration}</if>
)
</insert>
<insert id="insertAttGroupPerson">
insert into att_group_person_relation(group_id, org_id, user_id)
values
<foreach item="params" collection="list" separator=",">
(#{params.groupId}, #{params.orgId}, #{params.userId})
</foreach>
</insert>
<update id="updateOrgChange">
update att_group
set group_name = #{groupName},
att_type = #{attType},
update_user_id = #{updateUserId}
where id = #{groupId}
</update>
<update id="updateAttGroupSetting">
update att_group_setting set att_day = #{attDay}
<if test="toWorkTime != null and toWorkTime != ''">,to_work_time = #{toWorkTime}</if>
<if test="offWorkTime != null and offWorkTime != ''">,off_work_time = #{offWorkTime}</if>
<if test="lateMinute != null and lateMinute != ''">,late_minute = #{lateMinute}</if>
<if test="leaveMinute != null and leaveMinute != ''">,leave_minute = #{leaveMinute}</if>
<if test="absenteeismLateMinute != null and absenteeismLateMinute != ''">,absenteeism_late_minute =
#{absenteeismLateMinute}
</if>
<if test="absenteeismLeaveMinute != null and absenteeismLeaveMinute != ''">,absenteeism_leave_minute =
#{absenteeismLeaveMinute}
</if>
<if test="entryAbnormalMinute != null and entryAbnormalMinute != ''">,entry_abnormal_minute =
#{entryAbnormalMinute}
</if>
<if test="todayClockNum != null and todayClockNum != ''">,today_clock_num = #{todayClockNum}</if>
<if test="attendanceDuration != null and attendanceDuration != ''">,attendance_duration =
#{attendanceDuration}
</if>
where group_id = #{groupId}
</update>
</mapper>