Commit 23a63d0a by yubin

请假

parent 3ef0c218
package com.scpyun.platform.jilinsscgsdp.service.impl;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import com.scpyun.base.bean.Page;
import com.scpyun.base.core.annotation.Api;
import com.scpyun.base.core.annotation.ApiOperation;
import com.scpyun.base.core.exception.CustomException;
import com.scpyun.base.db.service.CommonService;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.xml.crypto.Data;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Api("日常请假管理")
@Service("keyDmLeave")
......@@ -20,13 +26,21 @@ public class KeyDmLeaveServiceImpl {
private static final String SUCCESS = "success";
private final String namespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmLeave.";
@ApiOperation(value = "分页查询请假申请列表", desc = "分页查询")
public Page<Map<String, Object>> selectList(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
return commonService.findPage(namespace + "selectList", map);
private final String leaveTypeNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmLeaveType.";
private final String approvalRecordNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmLeaveApprovalRecord.";
@ApiOperation(value = "部门分页查询请假申请列表", desc = "分页查询")
public Page<Map<String, Object>> selectList(Page<Map<String, Object>> map) {
if (map == null) map = new Page<>();
Page<Map<String, Object>> map1 = commonService.findPage(namespace + "selectList", map);
return map1;
}
@ApiOperation(value = "个人分页查询请假申请列表", desc = "分页查询")
public Page<Map<String, Object>> selectListByUserId(Page<Map<String, Object>> map) {
if (map == null) map = new Page<>();
Page<Map<String, Object>> map1 = commonService.findPage(namespace + "selectListByUserId", map);
return map1;
}
@ApiOperation(value = "待审核列表", desc = "查询待审核数据")
public Page<Map<String, Object>> selectPendingList(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
......@@ -36,12 +50,77 @@ public class KeyDmLeaveServiceImpl {
@ApiOperation(value = "保存请假申请", desc = "新增或修改,请假单保存")
public String save(Map<String, Object> map) {
if (map == null) throw new CustomException("参数不能为空");
Object id = map.get("id");
if (id == null || String.valueOf(id).trim().isEmpty()) {
if (commonService.insert(namespace + "insert", map) != 1) throw new CustomException("保存失败");
map.put("id", UUID.randomUUID().toString());
String typeId = map.get("leave_type_id").toString();
String typeName = commonService.getObject(leaveTypeNamespace + "selectLeaveTypeById", typeId);
map.put("leave_type_name", typeName);
map.put("status", 0); // 默认保存状态为0
Object startDateObj = map.get("start_time");
Object endDateObj = map.get("end_time");
double durationDays = 0; // 初始化天数为0
// 1. 非空判断 + 计算天数
if (startDateObj != null && endDateObj != null) {
try {
// 1. 解析字符串时间为DateTime
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime startDate = formatter.parseDateTime(startDateObj.toString());
DateTime endDate = formatter.parseDateTime(endDateObj.toString());
// 2. 计算时间差(毫秒),转成带小数的天数
Duration durationObj = new Duration(startDate, endDate);
long totalMillis = durationObj.getMillis();
// 关键:用86400000.0(浮点数)做除法,保留小数
durationDays = totalMillis / 86400000.0;
// 可选:保留1位小数(比如0.1天、4.5天),避免小数位数过多
durationDays = Math.round(durationDays * 10) / 10.0;
// 3. 存入map(小数天数)
map.put("duration", durationDays);
} catch (IllegalArgumentException e) {
throw new CustomException("时间格式错误,应为yyyy-MM-dd HH:mm:ss");
}
} else {
// 空值时默认存0.0,保持类型统一
map.put("duration", 0.0);
}
if (commonService.insert(namespace + "insert", map) != 1) {
throw new CustomException("保存失败");
}
// 如果请求中包含审批人信息,插入初始的审批记录到子表(jl_key_dm_leave_approval_record)
try {
Object approverId = map.get("approver_id");
Object approverName = map.get("approver_name");
if ((approverId != null && String.valueOf(approverId).trim().length() > 0) ||
(approverName != null && String.valueOf(approverName).trim().length() > 0)) {
Map<String, Object> approvalRecord = new HashMap<>();
approvalRecord.put("id", UUID.randomUUID().toString());
approvalRecord.put("leave_id", map.get("id"));
approvalRecord.put("node_index", 1);
approvalRecord.put("node_type", 1); // 1 = 流程节点
approvalRecord.put("approver_id", approverId == null ? null : String.valueOf(approverId));
approvalRecord.put("approver_name", approverName == null ? null : String.valueOf(approverName));
approvalRecord.put("approver_result", 0); // 0 未处理
approvalRecord.put("approver_time", null);
approvalRecord.put("status", 0); // 0 未操作
approvalRecord.put("comment", null);
approvalRecord.put("order_no", 1);
// 插入子表,mapper id 为 insert
commonService.insert(approvalRecordNamespace + "insert", approvalRecord);
}
} catch (Exception e) {
// 子表插入异常不影响主表保存,但记录日志以便排查
throw new CustomException("保存审批子表记录失败:" + e.getMessage());
}
} else {
int aff = commonService.update(namespace + "update", map);
if (aff < 0) throw new CustomException("保存失败");
if (aff < 0) {
throw new CustomException("保存失败");
}
}
return SUCCESS;
}
......@@ -50,6 +129,7 @@ public class KeyDmLeaveServiceImpl {
public String submit(Map<String, Object> map) {
if (map == null || map.get("id") == null) throw new CustomException("参数缺失");
int aff = commonService.update(namespace + "submit", map);
commonService.update(approvalRecordNamespace + "submit", map);
if (aff < 0) throw new CustomException("提交失败");
return SUCCESS;
}
......@@ -58,6 +138,7 @@ public class KeyDmLeaveServiceImpl {
public String revoke(Map<String, Object> map) {
if (map == null || map.get("id") == null) throw new CustomException("参数缺失");
int aff = commonService.update(namespace + "revoke", map);
commonService.update(approvalRecordNamespace + "revoke", map);
if (aff < 0) throw new CustomException("撤回失败");
return SUCCESS;
}
......@@ -66,6 +147,7 @@ public class KeyDmLeaveServiceImpl {
public String approve(Map<String, Object> map) {
if (map == null || map.get("id") == null) throw new CustomException("参数缺失");
int aff = commonService.update(namespace + "approve", map);
commonService.update(namespace + "approve", map);
if (aff < 0) throw new CustomException("审批失败");
return SUCCESS;
}
......@@ -84,15 +166,22 @@ public class KeyDmLeaveServiceImpl {
Map<String, Object> ret = new HashMap<>();
Map<String, Object> app = commonService.getObject(namespace + "getById", map);
ret.putAll(app == null ? new HashMap<>() : app);
List<Map<String, Object>> approvals = commonService.findList(namespace + "selectApprovalRecords", map);
ret.put("approvals", approvals == null ? new java.util.ArrayList<>() : approvals);
// 子表:审批记录
List<Map<String, Object>> approvals = commonService.findList(approvalRecordNamespace + "selectApprovalRecords", map);
approvals = approvals == null ? new java.util.ArrayList<>() : approvals;
ret.put("approvals", approvals);
// 将子表统一放入 subTables 集合,便于前端区分不同子表
Map<String, List<Map<String, Object>>> subTables = new HashMap<>();
subTables.put("approvalRecords", approvals);
ret.put("subTables", subTables);
return ret;
}
@ApiOperation(value = "审批历史查询", desc = "查询审批历史")
public Page<Map<String, Object>> selectApprovalHistory(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
return commonService.findPage(namespace + "selectApprovalHistory", map);
return commonService.findPage(approvalRecordNamespace + "selectApprovalHistory", map);
}
@ApiOperation(value = "请假统计", desc = "按人员统计已通过请假天数")
......
......@@ -5,7 +5,6 @@ import com.scpyun.base.core.annotation.Api;
import com.scpyun.base.core.annotation.ApiOperation;
import com.scpyun.base.core.exception.CustomException;
import com.scpyun.base.db.service.CommonService;
import com.scpyun.platform.jilinsscgsdp.utils.DataScopeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -28,6 +27,16 @@ public class KeyDmUserServiceImpl {
return commonService.findPage(namespace + "selectList", map);
}
@ApiOperation(value = "分页查询日常人员可选上级领导列表", desc = "分页")
public Page<Map<String, Object>> dmUserLeader(Page<Map<String, Object>> map) {
if (map == null) map = new Page<>();
return commonService.findPage(namespace + "selectUserLeaderById", map);
}
@ApiOperation(value = "分页查询日常人员可选上级部门列表", desc = "分页")
public Page<Map<String, Object>> dmUserOffice(Page<Map<String, Object>> map) {
if (map == null) map = new Page<>();
return commonService.findPage(namespace + "selectUserOfficeById", map);
}
@ApiOperation(value = "保存日常人员(编辑)", desc = "保存单条记录")
public String save(Map<String, Object> map) {
if (map == null || map.get("id") == null) {
......@@ -48,10 +57,6 @@ public class KeyDmUserServiceImpl {
@ApiOperation(value = "根据机构编码同步用户", desc = "同步本级及下属机构用户")
public String syncByOffice(Map<String, Object> map) {
if (map == null || map.get("office_code") == null) {
throw new CustomException("缺少机构编码");
}
// 查询 sys_user 列表(通过 office_code 匹配本级及下属机构)
List<Map<String, Object>> sysUsers = commonService.findList(namespace + "selectSysUserByOfficeCode", map);
if (sysUsers == null) return SUCCESS;
......@@ -65,12 +70,21 @@ public class KeyDmUserServiceImpl {
Map<String, Object> ins = new HashMap<>();
ins.put("id", u.get("id"));
ins.put("is_ext", 1);
ins.put("is_leave", 0);
ins.put("office_id", u.get("office_id"));
ins.put("name", u.get("name"));
ins.put("gh", u.get("no"));
ins.put("email", u.get("email"));
ins.put("phone", u.get("phone"));
ins.put("mobile", u.get("mobile"));
if (u.get("no")!= null|| !"".equals(u.get("no"))) {
ins.put("gh", u.get("no"));
}
if (u.get("email")!= null|| !"".equals(u.get("email"))) {
ins.put("email", u.get("email"));
}
if (u.get("phone")!= null|| !"".equals(u.get("phone"))) {
ins.put("phone", u.get("phone"));
}
if (u.get("mobile")!= null|| !"".equals(u.get("mobile"))) {
ins.put("mobile", u.get("mobile"));
}
ins.put("is_used", 1);
commonService.insert(namespace + "insert", ins);
} else {
......
......@@ -13,19 +13,44 @@
<if test="params.user_name != null and params.user_name != ''">
AND user_name LIKE CONCAT('%', #{params.user_name}, '%')
</if>
<if test="params._user.company_id != null and params._user.company_id != ''">
AND department_id LIKE CONCAT('%', #{params._user.parent_id}, '%')
</if>
</where>
ORDER BY submit_time DESC
</select>
<select id="selectPendingList" parameterType="page" resultType="map">
SELECT * FROM jl_key_dm_leave_application
<select id="selectListByUserId" parameterType="page" resultType="map">
SELECT
id,user_id,user_name,department_id,department_name,leave_type_id,leave_type_name,
start_time,end_time,duration_unit,duration,reason,emergency_contact,emergency_phone,
status,back_reason,submit_time,approval_complete_time,op_result,is_used,create_by,create_time,update_by,update_time,order_no
FROM jl_key_dm_leave_application
<where>
AND is_used = 1
AND status = 1
<if test="params.params.user_name != null and params.params.user_name != ''">
AND user_name LIKE CONCAT('%', #{params.user_name}, '%')
</if>
<if test="params._user.id != null and params._user.id != ''">
AND user_id LIKE CONCAT('%', #{params._user.id}, '%')
</if>
</where>
ORDER BY submit_time DESC
</select>
<select id="selectPendingList" parameterType="page" resultType="map">
SELECT * FROM jl_key_dm_leave_application a
left JOIN jl_key_dm_leave_approval_record r ON r.leave_id=a.id
<where>
AND a.is_used = 1
AND r.status = 1
<if test="params._user.id != null and params._user.id != ''">
AND r.approver_id = #{params._user.id}
</if>
</where>
ORDER BY a.submit_time DESC
</select>
<select id="getById" parameterType="map" resultType="map">
SELECT * FROM jl_key_dm_leave_application WHERE id = #{id} LIMIT 1
</select>
......@@ -36,7 +61,7 @@
start_time,end_time,duration_unit,duration,reason,emergency_contact,emergency_phone,
status,submit_time,is_used,create_by,create_time,order_no
) VALUES (
#{id},#{user_id},#{user_name},#{department_id},#{department_name},#{leave_type_id},#{leave_type_name},
#{id},#{_user.id},#{_user.name},#{_user.parent_id},#{_user.company_name},#{leave_type_id},#{leave_type_name},
#{start_time},#{end_time},#{duration_unit},#{duration},#{reason},#{emergency_contact},#{emergency_phone},
#{status},#{submit_time},1,#{_user.id},NOW(),#{order_no}
)
......@@ -76,14 +101,14 @@
<!-- 审批通过:设置 status=9, op_result=1, approval_complete_time -->
<update id="approve" parameterType="map">
UPDATE jl_key_dm_leave_application
SET status = 9, op_result = 1, approval_complete_time = NOW(), update_by = #{_user.id}, update_time = NOW()
SET status = 9, op_result = 1, approver_time = NOW(), update_by = #{_user.id}, update_time = NOW()
WHERE id = #{id}
</update>
<!-- 驳回:设置 status=-1, op_result=-1, back_reason -->
<update id="reject" parameterType="map">
UPDATE jl_key_dm_leave_application
SET status = -1, op_result = -1, back_reason = #{comment}, approval_complete_time = NOW(), update_by = #{_user.id}, update_time = NOW()
SET status = -1, op_result = -1, back_reason = #{comment}, approver_time = NOW(), update_by = #{_user.id}, update_time = NOW()
WHERE id = #{id}
</update>
......
......@@ -26,10 +26,39 @@
<if test="params.approver_name != null and params.approver_name != ''">
AND a.approver_name LIKE CONCAT('%', #{params.approver_name}, '%')
</if>
<if test="params._user.id != null and params._user.id != ''">
AND a.approver_id = #{params._user.id}
</if>
</where>
ORDER BY a.approver_time DESC
</select>
<update id="submit" parameterType="map">
UPDATE jl_key_dm_leave_approval_record
SET status = 1,update_by = #{_user.id}, update_time = NOW()
WHERE leave_id = #{id}
</update>
<!-- 撤回:仅限审核中状态撤回,设置 status=0 -->
<update id="revoke" parameterType="map">
UPDATE jl_key_dm_leave_approval_record
SET status = 0, update_by = #{_user.id}, update_time = NOW()
WHERE leave_id = #{id} AND status = 1
</update>
<!-- 审批通过:设置 status=9, op_result=1, approval_complete_time -->
<update id="approve" parameterType="map">
UPDATE jl_key_dm_leave_approval_record
SET status = 2, approval_complete_time = NOW(), update_by = #{_user.id}, update_time = NOW(),approver_result = 1
WHERE leave_id = #{id}
</update>
<!-- 驳回:设置 status=-1, op_result=-1, back_reason -->
<update id="reject" parameterType="map">
UPDATE jl_key_dm_leave_approval_record
SET status = 2, back_reason = #{comment}, approval_complete_time = NOW(), update_by = #{_user.id}, update_time = NOW(),approver_result = -1
WHERE leave_id = #{id}
</update>
</mapper>
......@@ -33,9 +33,86 @@
<if test="params.name != null and params.name != ''">
AND u.name LIKE CONCAT('%', #{params.name}, '%')
</if>
<if test="params._user.company_id != null and params._user.company_id != ''">
AND o.parent_ids LIKE CONCAT('%', #{params._user.company_id}, '%')
</if>
</where>
ORDER BY u.order_no ASC, u.create_time DESC
</select>
<select id="selectUserLeaderById" parameterType="page" resultType="map">
SELECT
u.id,
u.is_ext,
u.is_leave,
u.rc_role_id,
u.office_id,
o.name AS office_name,
u.name,
u.gh,
u.email,
u.phone,
u.mobile,
u.birthday,
u.in_work_time,
u.leader,
u.leader_name,
u.is_used,
u.create_by,
u.create_time,
u.update_by,
u.update_time,
u.order_no
FROM jl_key_dm_user u
LEFT JOIN sys_office o ON o.id = u.office_id
<where>
u.is_used = 1
<!-- 仅按前端当前格式(params.params)读取参数 -->
<if test="params != null and params.params != null and params.params.name != null and params.params.name != ''">
AND (u.name LIKE CONCAT('%', #{params.params.name}, '%') OR u.gh LIKE CONCAT('%', #{params.params.name}, '%'))
</if>
<!-- 查上级:params.params.parent_mode='up' 且提供 params.params.office_id -->
<if test="params != null and params.params != null and params.params.parent_mode != null and params.params.parent_mode == 'up' and params.params.office_id != null and params.params.office_id != ''">
AND o.id IN (
SELECT parent_id FROM sys_office WHERE id = #{params.params.office_id}
UNION
SELECT #{params.params.office_id} FROM DUAL
)
</if>
</where>
ORDER BY u.order_no ASC, u.create_time DESC
</select>
<select id="selectUserOfficeById" parameterType="page" resultType="map">
SELECT
o.*
FROM sys_office o
<where>
AND (o.del_flag = '0' OR o.useable = '1')
<!-- 仅按前端当前格式(params.params)读取机构查询条件 -->
<if test="params != null and params.params != null and params.params.name != null and params.params.name != ''">
AND (o.name LIKE CONCAT('%', #{params.params.name}, '%') OR o.code LIKE CONCAT('%', #{params.params.name}, '%'))
</if>
<!-- 查上级 parent_mode='up'(使用 params.params.office_id) -->
<if test="params != null and params.params != null and params.params.parent_mode != null and params.params.parent_mode == 'up' and params.params.office_id != null and params.params.office_id != ''">
AND o.id IN (
SELECT parent_id FROM sys_office WHERE id = #{params.params.office_id}
UNION
SELECT #{params.params.office_id} FROM DUAL
)
</if>
<!-- 默认按 params.params.company_id 或 params.params.office_id 过滤所属/子机构 -->
<if test="params != null and params.params != null and params.params.office_id != null and params.params.office_id != ''">
AND (o.parent_ids LIKE CONCAT('%', #{params.params.office_id}, '%'))
</if>
</where>
ORDER BY o.grade DESC
</select>
<!-- 从 sys_user 查询指定机构(及下属机构)的用户,office_code 为机构 code 字段 -->
<select id="selectSysUserByOfficeCode" parameterType="map" resultType="map">
......@@ -43,7 +120,7 @@
FROM sys_user su
WHERE su.office_id IN (
SELECT so.id FROM sys_office so
WHERE so.parent_ids LIKE CONCAT('%', #{office_code}, '%') OR so.code = #{office_code}
WHERE so.parent_ids LIKE CONCAT('%', #{_user.company_id}, '%') OR so.code = #{_user.company_id}
)
AND (su.del_flag IS NULL OR su.del_flag = '0')
</select>
......@@ -59,7 +136,7 @@
id, is_ext, is_leave, rc_role_id, office_id, name, gh, email, phone, mobile,
birthday, in_work_time, leader, leader_name, is_used, create_by, create_time, order_no
) VALUES (
#{id},
#{id},
#{is_ext},
#{is_leave},
#{rc_role_id},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论