Commit 62184577 by wangchunyang

根据现场需求,各功能查询调整为区县使用范围,包括对应横向部门,使用sys_office中的area_id来确认范围

parent aab9db7e
......@@ -6,6 +6,7 @@ import com.scpyun.base.core.annotation.ApiOperation;
import com.scpyun.base.core.exception.CustomException;
import com.scpyun.base.db.service.CommonService;
import com.scpyun.base.utils.UUID;
import com.scpyun.platform.jilinsscgsdp.utils.DataScopeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -67,6 +68,13 @@ public class KeyDmBorrowServiceImpl {
@ApiOperation(value = "历史申请列表", desc = "分页查询历史申请")
public Page<Map<String, Object>> selectHistoryList(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
Map<String, Object> user = (Map<String, Object>) map.get("_user");
if (user != null) {
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.put("areaId", pos.get("area_id"));
map.put("parentId", user.get("parent_id"));
map.put("parentIds", user.get("parent_ids")+","+pos.get("area_id"));
}
return commonService.findPage(namespace + "selectHistoryList", map);
}
......
package com.scpyun.platform.jilinsscgsdp.service.impl;
import com.scpyun.platform.jilinsscgsdp.utils.DataScopeUtil;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import com.scpyun.base.bean.Page;
......@@ -34,6 +35,9 @@ public class KeyDmLeaveServiceImpl {
@ApiOperation(value = "请假申请查询", desc = "分页查询")
public Page<Map<String, Object>> selectList(Page<Map<String, Object>> map) {
if (map == null) map = new Page<>();
Map<String, Object> user = (Map<String, Object>) map.getParams().get("_user");
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.getParams().put("area_id", pos.get("area_id"));
Page<Map<String, Object>> map1 = commonService.findPage(namespace + "selectList", map);
return map1;
}
......@@ -236,12 +240,18 @@ public class KeyDmLeaveServiceImpl {
@ApiOperation(value = "审批历史查询", desc = "查询审批历史")
public Page<Map<String, Object>> selectApprovalHistory(Page<Map<String, Object>> map) {
if (map == null) map = new Page<>();
Map<String, Object> user = (Map<String, Object>) map.getParams().get("_user");
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.getParams().put("area_id", pos.get("area_id"));
return commonService.findPage(approvalRecordNamespace + "selectApprovalHistory", map);
}
@ApiOperation(value = "请假统计", desc = "按人员统计已通过请假天数")
public List<Map<String, Object>> selectStats(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
Map<String, Object> user = (Map<String, Object>) map.get("_user");
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.put("area_id", pos.get("area_id"));
return commonService.findList(namespace + "selectStats", map);
}
}
......
......@@ -294,107 +294,129 @@ public class KeyDmUserCategoryServiceImpl {
return commonService.findList(namespace + "getStockWarningList", null);
}
// ===== 部门管理 =====
@ApiOperation(value = "查询部门列表", desc = "分页查询部门")
public Page<Map<String, Object>> selectOrgList(Page<Map<String, Object>> map) {
if (map == null) map = new Page<>();
Map<String, Object> user = (Map<String, Object>) map.getParams().get("_user");
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.getParams().put("area_id", pos.get("area_id"));
return commonService.findPage(namespace + "selectOrgList", map);
}
@ApiOperation(value = "保存部门", desc = "新增或修改部门")
public String saveOrg(Map<String, Object> map) {
if (map == null) {
throw new CustomException("参数不能为空");
}
Object id = map.get("id");
if (id == null || String.valueOf(id).trim().isEmpty()) {
Map<String, Object> user = (Map<String, Object>) map.get("_user");
Map<String, String> pos = DataScopeUtil.getPosition(user);
// 新增
map.put("id", UUIDUtil.getUUID());
map.put("source_org", pos.get("area_id"));
map.put("org_code", map.get("id"));
if (commonService.insert(namespace + "insertOrg", map) != 1) {
throw new CustomException("保存失败");
}
} else {
// 修改
int affected = commonService.update(namespace + "updateOrg", map);
if (affected < 0) throw new CustomException("保存失败");
}
return SUCCESS;
}
@ApiOperation(value = "删除部门", desc = "逻辑删除部门")
public String deleteOrg(Map<String, Object> map) {
if (map == null || map.get("id") == null) {
throw new CustomException("参数不能为空");
}
int affected = commonService.update(namespace + "deleteOrg", map);
if (affected < 0) throw new CustomException("删除失败");
return SUCCESS;
}
@ApiOperation(value = "分配用户到部门", desc = "将用户分配到指定部门")
public String assignUsersToOrg(Map<String, Object> map) {
if (map == null || map.get("org_id") == null) {
throw new CustomException("参数缺失");
}
String orgId = map.get("org_id").toString();
List<String> userIds = (List<String>) map.get("user_ids");
Map<String, Object> user = (Map<String, Object>) map.get("_user");
Map<String, String> pos = DataScopeUtil.getPosition(user);
// 先清除该部门的所有用户分配
Map<String, Object> clearParam = new HashMap<>();
clearParam.put("belong_org_id", orgId);
clearParam.put("area_id", pos.get("area_id"));
clearParam.put("parent_ids", user.get("parent_ids")+","+pos.get("area_id"));
commonService.update(namespace + "clearOrgUsers", clearParam);
// 再分配新用户
if (userIds != null && !userIds.isEmpty()) {
for (String userId : userIds) {
Map<String, Object> assignParam = new HashMap<>();
assignParam.put("user_id", userId);
assignParam.put("belong_org_id", orgId);
// 这里需要根据实际的部门信息设置其他字段
// 暂时只更新 belong_org_id,后续可以扩展
commonService.update(namespace + "assignUserToOrg", assignParam);
}
}
return SUCCESS;
}
// // ===== 部门管理 =====
// @ApiOperation(value = "查询部门列表", desc = "分页查询部门")
// public Page<Map<String, Object>> selectOrgList(Page<Map<String, Object>> map) {
// if (map == null) map = new Page<>();
// Map<String, Object> user = (Map<String, Object>) map.getParams().get("_user");
// Map<String, String> pos = DataScopeUtil.getPosition(user);
// map.getParams().put("area_id", pos.get("area_id"));
// return commonService.findPage(namespace + "selectOrgList", map);
// }
//
// @ApiOperation(value = "保存部门", desc = "新增或修改部门")
// public String saveOrg(Map<String, Object> map) {
// if (map == null) {
// throw new CustomException("参数不能为空");
// }
// Object id = map.get("id");
// if (id == null || String.valueOf(id).trim().isEmpty()) {
// Map<String, Object> user = (Map<String, Object>) map.get("_user");
// Map<String, String> pos = DataScopeUtil.getPosition(user);
// // 新增
// map.put("id", UUIDUtil.getUUID());
// map.put("source_org", pos.get("area_id"));
// map.put("org_code", map.get("id"));
// if (commonService.insert(namespace + "insertOrg", map) != 1) {
// throw new CustomException("保存失败");
// }
// } else {
// // 修改
// int affected = commonService.update(namespace + "updateOrg", map);
// if (affected < 0) throw new CustomException("保存失败");
// }
// return SUCCESS;
// }
//
// @ApiOperation(value = "删除部门", desc = "逻辑删除部门")
// public String deleteOrg(Map<String, Object> map) {
// if (map == null || map.get("id") == null) {
// throw new CustomException("参数不能为空");
// }
// int affected = commonService.update(namespace + "deleteOrg", map);
// if (affected < 0) throw new CustomException("删除失败");
// return SUCCESS;
// }
//
// @ApiOperation(value = "分配用户到部门", desc = "将用户分配到指定部门")
// public String assignUsersToOrg(Map<String, Object> map) {
// if (map == null || map.get("org_id") == null) {
// throw new CustomException("参数缺失");
// }
//
// String orgId = map.get("org_id").toString();
// List<String> userIds = (List<String>) map.get("user_ids");
// Map<String, Object> user = (Map<String, Object>) map.get("_user");
// Map<String, String> pos = DataScopeUtil.getPosition(user);
//
// // 先清除该部门的所有用户分配
// Map<String, Object> clearParam = new HashMap<>();
// clearParam.put("belong_org_id", orgId);
// clearParam.put("area_id", pos.get("area_id"));
// clearParam.put("parent_ids", user.get("parent_ids")+","+pos.get("area_id"));
// commonService.update(namespace + "clearOrgUsers", clearParam);
//
// // 再分配新用户
// if (userIds != null && !userIds.isEmpty()) {
// for (String userId : userIds) {
// Map<String, Object> assignParam = new HashMap<>();
// assignParam.put("user_id", userId);
// assignParam.put("belong_org_id", orgId);
// // 这里需要根据实际的部门信息设置其他字段
// // 暂时只更新 belong_org_id,后续可以扩展
// commonService.update(namespace + "assignUserToOrg", assignParam);
// }
// }
//
// return SUCCESS;
// }
// ===== 统计服务 =====
@ApiOperation(value = "使用统计", desc = "统计各部门领用量")
public List<Map<String, Object>> selectUsageStats(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
// Map<String, Object> user = (Map<String, Object>) map.get("_user");
// Map<String, String> pos = DataScopeUtil.getPosition(user);
Map<String, Object> user = (Map<String, Object>) map.get("_user");
if (user != null) {
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.put("areaId", pos.get("area_id"));
map.put("parentId", user.get("parent_id"));
}
return commonService.findList(namespace + "selectUsageStats", map);
}
@ApiOperation(value = "使用明细", desc = "查询使用明细")
public List<Map<String, Object>> selectUsageDetails(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
Map<String, Object> user = (Map<String, Object>) map.get("_user");
if (user != null) {
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.put("areaId", pos.get("area_id"));
map.put("parentId", user.get("parent_id"));
}
return commonService.findList(namespace + "selectUsageDetails", map);
}
@ApiOperation(value = "工作量统计", desc = "统计人员工作量")
public List<Map<String, Object>> selectWorkloadStats(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
Map<String, Object> user = (Map<String, Object>) map.get("_user");
if (user != null) {
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.put("areaId", pos.get("area_id"));
map.put("parentId", user.get("parent_id"));
}
return commonService.findList(namespace + "selectWorkloadStats", map);
}
@ApiOperation(value = "工作量明细", desc = "工作量明细")
public List<Map<String, Object>> selectWorkloadDetails(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
Map<String, Object> user = (Map<String, Object>) map.get("_user");
if (user != null) {
Map<String, String> pos = DataScopeUtil.getPosition(user);
map.put("areaId", pos.get("area_id"));
map.put("parentId", user.get("parent_id"));
}
return commonService.findList(namespace + "selectWorkloadDetails", map);
}
}
......@@ -102,7 +102,7 @@ public class KeyDmUserServiceImpl {
// prepare insert map: only copy available fields
Map<String, Object> ins = new HashMap<>();
ins.put("id", u.get("id"));
ins.put("is_ext", 1);
ins.put("is_ext", 0);
ins.put("is_leave", 0);
ins.put("office_id", u.get("office_id"));
ins.put("name", u.get("name"));
......
......@@ -37,26 +37,28 @@
</select>
<select id="selectHistoryList" parameterType="map" resultType="map">
SELECT * FROM jl_key_dm_borrow_application
SELECT ba.* FROM jl_key_dm_borrow_application ba
left join jl_key_dm_user u on ba.applicant_id=u.id
left join sys_office so on u.office_id=so.id
<where>
is_used = 1
ba.is_used = 1 and so.area_id = #{params.areaId}
<if test="params.params.applicant_name != null and params.params.applicant_name != ''">
AND applicant_name LIKE CONCAT('%', #{params.params.applicant_name}, '%')
AND ba.applicant_name LIKE CONCAT('%', #{params.params.applicant_name}, '%')
</if>
<if test="params.params.department_name != null and params.params.department_name != ''">
AND department_name LIKE CONCAT('%', #{params.params.department_name}, '%')
AND u.department_name LIKE CONCAT('%', #{params.params.department_name}, '%')
</if>
<if test="params.params.approval_status != null">
AND approval_status = #{params.params.approval_status}
AND ba.approval_status = #{params.params.approval_status}
</if>
<if test="params.params.startDate != null">
AND submit_time &gt;= #{params.params.startDate}
AND ba.submit_time &gt;= #{params.params.startDate}
</if>
<if test="params.params.endDate != null">
AND submit_time &lt;= #{params.params.endDate}
AND ba.submit_time &lt;= #{params.params.endDate}
</if>
</where>
ORDER BY create_time DESC
ORDER BY ba.create_time DESC
</select>
<select id="getById" parameterType="map" resultType="map">
......
......@@ -4,32 +4,36 @@
<select id="selectList" 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
la.id,la.user_id,la.user_name,la.department_id,la.department_name,la.leave_type_id,la.leave_type_name,
la.start_time,la.end_time,la.duration_unit,la.duration,la.reason,la.emergency_contact,la.emergency_phone,
la.status,la.back_reason,la.submit_time,la.approval_complete_time,la.op_result,la.is_used,la.create_by,la.create_time,la.update_by,la.update_time,la.order_no
FROM jl_key_dm_leave_application la
LEFT JOIN jl_key_dm_user u ON la.user_id = u.id
LEFT JOIN sys_office so on u.office_id = so.id
<where>
AND is_used = 1
AND status !=0
AND la.is_used = 1
AND la.status !=0
AND so.area_id = #{params.area_id}
<!-- AND (u.office_id = #{params._user.company_id} OR so.parent_ids like CONCAT(#{params._user.parent_ids}, ',', #{params._user.company_id}, '%'))-->
<if test="params.user_name != null and params.user_name != ''">
AND user_name LIKE CONCAT('%', #{params.user_name}, '%')
AND la.user_name LIKE CONCAT('%', #{params.user_name}, '%')
</if>
<!-- 支持按起止时间区间查询(来自 params.params.start_time / params.params.end_time):返回与区间有交集的请假记录 -->
<if test="params.params != null and params.params.start_time != null and params.params.start_time != ''">
AND submit_time &gt;= #{params.params.start_time}
AND la.submit_time &gt;= #{params.params.start_time}
</if>
<if test="params.params != null and params.params.end_time != null and params.params.end_time != ''">
AND submit_time &lt; #{params.params.end_time}
AND la.submit_time &lt; #{params.params.end_time}
</if>
<!-- 支持按状态过滤(来自 params.params.status,例如: 0,1,2,9,-1) -->
<if test="params.params != null and params.params.status != null and params.params.status != ''">
AND status = #{params.params.status}
AND la.status = #{params.params.status}
</if>
<if test="params._user.company_id != null and params._user.company_id != ''">
AND department_id LIKE CONCAT('%', #{params._user.parent_id}, '%')
AND la.department_id LIKE CONCAT('%', #{params._user.parent_id}, '%')
</if>
</where>
ORDER BY submit_time DESC
ORDER BY so.grade,la.submit_time DESC
</select>
<select id="selectListByUserId" parameterType="page" resultType="map">
......@@ -282,19 +286,22 @@
<!-- 统计:按人员统计已通过请假时长(按天数汇总),params.start, params.end, params.department -->
<select id="selectStats" parameterType="map" resultType="map">
SELECT user_id, user_name, department_id, department_name, SUM(duration) AS passed_days
FROM jl_key_dm_leave_application
SELECT la.user_id, la.user_name, la.department_id, la.department_name, SUM(la.duration) AS passed_days
FROM jl_key_dm_leave_application la
LEFT JOIN jl_key_dm_user u ON la.user_id = u.id
LEFT JOIN sys_office so on u.office_id = so.id
<where>
AND is_used = 1
AND status = 9
AND la.is_used = 1
AND la.status = 9
AND so.area_id = #{area_id}
<if test="start != null and start != ''">
AND end_time >= #{start}
AND la.end_time >= #{start}
</if>
<if test="end != null and end != ''">
And start_time &lt; #{end}
And la.start_time &lt; #{end}
</if>
</where>
GROUP BY user_id, user_name, department_id, department_name
GROUP BY la.user_id, la.user_name, la.department_id, la.department_name
ORDER BY passed_days DESC
</select>
......
......@@ -30,10 +30,12 @@
FROM jl_key_dm_leave_application a
LEFT JOIN jl_key_dm_leave_approval_record r ON a.id = r.leave_id
LEFT JOIN jl_key_dm_user u ON r.approver_id = u.id
LEFT JOIN sys_office so on u.office_id = so.id
<where>
a.is_used = 1
AND a.status != 0
AND u.office_id = #{params._user.company_id}
AND so.area_id = #{params.area_id}
<!-- AND (u.office_id = #{params._user.company_id} OR so.parent_ids like CONCAT(#{params._user.parent_ids}, ',', #{params._user.company_id}, '%'))-->
AND r.node_type = 1
<!-- 支持按起止时间查询:可单独填写一个时间进行查询 -->
<if test="params.params != null and params.params.start_time != null and params.params.start_time != ''">
......
......@@ -553,13 +553,12 @@
u.name as user_name,
COUNT(la.id) as leave_count
FROM jl_key_dm_user u
LEFT JOIN jl_key_dm_leave_application la ON la.applicant_id = u.id AND la.is_used = 1
LEFT JOIN jl_key_dm_leave_application la ON la.user_id = u.id AND la.is_used = 1
AND DATE_FORMAT(la.create_time, '%Y-%m') = DATE_FORMAT(NOW(), '%Y-%m')
WHERE u.is_used = 1 AND u.is_leave = 0
GROUP BY u.id, u.name
HAVING leave_count > 0
ORDER BY leave_count DESC
LIMIT 20
</select>
<!-- 用品领用统计(月度) -->
......@@ -739,6 +738,7 @@
LEFT JOIN sys_office so on so.id = ba.department_id
<where>
AND ba.is_used=1 and ad.is_used=1 and ba.approval_status = 9
AND so.area_id = #{areaId}
<if test="start != null and start != ''">
AND ba.create_time &gt;= #{start}
</if>
......@@ -764,6 +764,7 @@
ba.department_name,
ad.material_id,
ad.material_name,
DATE_FORMAT(ba.submit_time, '%Y-%m-%d') as apply_time,
ad.apply_quantity,
ad.returned_quantity
from jl_key_dm_borrow_application_detail ad
......@@ -858,6 +859,7 @@
</if>
</where>
) t LEFT JOIN jl_key_dm_user u on t.uid=u.id LEFT JOIN sys_office o on u.office_id=o.id
WHERE o.area_id = #{areaId}
GROUP BY t.uid, t.uname, o.name, o.grade, o.sort
ORDER BY o.grade, o.sort, leave_applications DESC, borrow_applications DESC
</select>
......
......@@ -115,13 +115,9 @@
<!-- 从 sys_user 查询指定机构(及下属机构)的用户,office_code 为机构 code 字段, 注:内部控制只有长春市由此功能,功能只覆盖长春市范围 -->
<select id="selectSysUserByOfficeCode" parameterType="map" resultType="map">
SELECT su.*
FROM sys_user su
WHERE su.office_id IN (
SELECT so.id FROM sys_office so
WHERE del_flag=0 AND so.parent_ids LIKE CONCAT(#{parentIds}, '%') OR so.id = #{_user.company_id}
AND (id='220100000000' OR parent_ids like '0,220000000000,220100000000%')
)
AND (su.del_flag IS NULL OR su.del_flag = '0')
FROM sys_user su LEFT JOIN sys_office so on su.office_id=so.id
WHERE su.del_flag=0 AND so.del_flag=0 AND so.area_id = #{areaId}
AND (so.id='220100000000' OR so.parent_ids like '0,220000000000,220100000000%')
</select>
<!-- 根据 id 获取日常人员 -->
......@@ -250,10 +246,9 @@
<select id="selectDmUserByOfficeCode" parameterType="map" resultType="map">
SELECT du.*
FROM jl_key_dm_user du
WHERE du.office_id IN (
SELECT so.id FROM sys_office so
WHERE so.parent_ids LIKE CONCAT(#{parentIds}, '%') OR so.id = #{_user.company_id}
)
<!-- LEFT JOIN sys_office so on du.office_id=so.id-->
<!-- WHERE du.is_used=1 AND so.del_flag=0 AND so.area_id = #{areaId}-->
<!-- AND (so.id='220100000000' OR so.parent_ids like '0,220000000000,220100000000%')-->
</select></mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论