Commit 90977d67 by wangchunyang

合并代码,减少文件

parent 89407ea7
package com.scpyun.platform.jilinsscgsdp.service.impl;
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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Api("统计服务")
@Service("keyDmStats")
public class KeyDmStatsServiceImpl {
@Autowired
private CommonService commonService;
private final String namespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmStats.";
@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);
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<>();
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<>();
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<>();
return commonService.findList(namespace + "selectWorkloadDetails", map);
}
}
......@@ -370,4 +370,31 @@ public class KeyDmUserCategoryServiceImpl {
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);
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<>();
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<>();
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<>();
return commonService.findList(namespace + "selectWorkloadDetails", map);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.keyDmStats" name="统计">
<!-- 使用统计:按部门、物料统计领用数量 -->
<select id="selectUsageStats" parameterType="map" resultType="map">
SELECT
ba.department_id,
ba.department_name,
ad.material_id,
ad.material_name,
sum(ad.apply_quantity)-sum(ad.returned_quantity) as total_quantity
from jl_key_dm_borrow_application_detail ad
LEFT JOIN jl_key_dm_borrow_application ba on ad.application_id = ba.id
LEFT JOIN jl_key_dm_material m on ad.material_id = m.id
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
<if test="start != null and start != ''">
AND ba.create_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND ba.create_time &lt; #{end}
</if>
<if test="material != null and material != ''">
AND (ad.material_name LIKE CONCAT('%', #{material}, '%') OR ad.material_code LIKE CONCAT('%', #{material}, '%'))
</if>
<if test="dep != null and dep != ''">
AND ad.department_name LIKE CONCAT('%', #{dep}, '%')
</if>
</where>
GROUP BY ba.department_id, ba.department_name, ad.material_id,ad.material_name
ORDER BY total_quantity DESC
</select>
<!-- 使用明细 -->
<select id="selectUsageDetails" parameterType="map" resultType="map">
SELECT
ba.applicant_name user_name,
ba.department_id,
ba.department_name,
ad.material_id,
ad.material_name,
ad.apply_quantity,
ad.returned_quantity
from jl_key_dm_borrow_application_detail ad
LEFT JOIN jl_key_dm_borrow_application ba on ad.application_id = ba.id
LEFT JOIN jl_key_dm_material m on ad.material_id = m.id
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
<if test="start != null and start != ''">
AND ba.create_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND ba.create_time &lt; #{end}
</if>
<if test="material != null and material != ''">
AND ad.material_id = #{material}
</if>
<if test="department != null and department != ''">
AND ba.department_id = #{department}
</if>
</where>
GROUP BY ba.department_id, ba.department_name, ad.material_id,ad.material_name
ORDER BY apply_quantity DESC
</select>
<!-- 工作量统计:合并多表数据后按人员统计 -->
<select id="selectWorkloadStats" parameterType="map" resultType="map">
SELECT uid AS user_id, uname AS user_name,
SUM(leave_app) AS leave_applications,
SUM(leave_approve) AS leave_approvals,
SUM(borrow_app) AS borrow_applications,
SUM(inbound_cnt) AS inbound_count,
SUM(leave_duration) AS leave_duration
FROM (
SELECT l.user_id AS uid, l.user_name AS uname, 1 AS leave_app, 0 AS leave_approve, 0 AS borrow_app, 0 AS inbound_cnt, COALESCE(l.duration,0) AS leave_duration
FROM jl_key_dm_leave_application l
<where>
AND l.is_used = 1 AND l.STATUS != 0
<if test="start != null and start != ''">
AND l.start_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND l.start_time &lt; #{end}
</if>
</where>
UNION ALL
SELECT r.approver_id AS uid, r.approver_name AS uname, 0, CASE WHEN r.approver_result = 1 THEN 1 ELSE 0 END, 0, 0, 0
FROM jl_key_dm_leave_approval_record r
<where>
AND r.is_used = 1 AND r.STATUS = 2
<if test="start != null and start != ''">
AND r.approver_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND r.approver_time &lt; #{end}
</if>
</where>
UNION ALL
SELECT b.applicant_id AS uid, b.applicant_name AS uname, 0, 0, 1, 0, 0
FROM jl_key_dm_borrow_application b
<where>
AND b.is_used = 1 AND b.approval_status != 0
<if test="start != null and start != ''">
AND b.submit_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND b.submit_time &lt; #{end}
</if>
</where>
UNION ALL
SELECT ir.create_by AS uid, du.`name` AS uname, 0, 0, 0, 1, 0
FROM jl_key_dm_inbound_record ir LEFT JOIN jl_key_dm_user du on ir.create_by = du.id
<where>
AND ir.is_used = 1
<if test="start != null and start != ''">
AND ir.create_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND ir.create_time &lt; #{end}
</if>
</where>
) t
GROUP BY uid, uname
ORDER BY leave_applications DESC, borrow_applications DESC
</select>
<!-- 工作量明细:按类型返回对应明细 -->
<select id="selectWorkloadDetails" parameterType="map" resultType="map">
<choose>
<when test="type == 'leave'">
SELECT id, user_id, user_name, start_time, end_time, duration, reason, `status` FROM jl_key_dm_leave_application
<where>
AND user_id = #{user_id} AND STATUS != 0
<if test="start != null and start != ''">
AND create_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND create_time &lt; #{end}
</if>
</where>
ORDER BY create_time DESC
</when>
<when test="type == 'inventory'">
SELECT b.application_no, b.applicant_id, b.applicant_name, d.material_name, b.approval_status, d.apply_quantity, d.returned_quantity,b.submit_time
FROM jl_key_dm_borrow_application_detail d
LEFT JOIN jl_key_dm_borrow_application b ON b.id = d.application_id
<where>
AND b.is_used = 1 AND b.approval_status != 0 AND b.applicant_id = #{user_id}
<if test="start != null and start != ''">
AND b.submit_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND b.submit_time &lt; #{end}
</if>
</where>
ORDER BY b.submit_time DESC
</when>
<otherwise>
SELECT 1 AS dummy
</otherwise>
</choose>
</select>
</mapper>
......@@ -723,5 +723,169 @@
<select id="findLeader" parameterType="String" resultType="String">
select leader from jl_key_dm_user where id = #{param}
</select>
<!-- //统计部分 -->
<!-- 使用统计:按部门、物料统计领用数量 -->
<select id="selectUsageStats" parameterType="map" resultType="map">
SELECT
ba.department_id,
ba.department_name,
ad.material_id,
ad.material_name,
sum(ad.apply_quantity)-sum(ad.returned_quantity) as total_quantity
from jl_key_dm_borrow_application_detail ad
LEFT JOIN jl_key_dm_borrow_application ba on ad.application_id = ba.id
LEFT JOIN jl_key_dm_material m on ad.material_id = m.id
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
<if test="start != null and start != ''">
AND ba.create_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND ba.create_time &lt; #{end}
</if>
<if test="material != null and material != ''">
AND (ad.material_name LIKE CONCAT('%', #{material}, '%') OR ad.material_code LIKE CONCAT('%', #{material}, '%'))
</if>
<if test="dep != null and dep != ''">
AND ad.department_name LIKE CONCAT('%', #{dep}, '%')
</if>
</where>
GROUP BY ba.department_id, ba.department_name, ad.material_id,ad.material_name
ORDER BY total_quantity DESC
</select>
<!-- 使用明细 -->
<select id="selectUsageDetails" parameterType="map" resultType="map">
SELECT
ba.applicant_name user_name,
ba.department_id,
ba.department_name,
ad.material_id,
ad.material_name,
ad.apply_quantity,
ad.returned_quantity
from jl_key_dm_borrow_application_detail ad
LEFT JOIN jl_key_dm_borrow_application ba on ad.application_id = ba.id
LEFT JOIN jl_key_dm_material m on ad.material_id = m.id
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
<if test="start != null and start != ''">
AND ba.create_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND ba.create_time &lt; #{end}
</if>
<if test="material != null and material != ''">
AND ad.material_id = #{material}
</if>
<if test="department != null and department != ''">
AND ba.department_id = #{department}
</if>
</where>
GROUP BY ba.department_id, ba.department_name, ad.material_id,ad.material_name
ORDER BY apply_quantity DESC
</select>
<!-- 工作量统计:合并多表数据后按人员统计 -->
<select id="selectWorkloadStats" parameterType="map" resultType="map">
SELECT uid AS user_id, uname AS user_name,
SUM(leave_app) AS leave_applications,
SUM(leave_approve) AS leave_approvals,
SUM(borrow_app) AS borrow_applications,
SUM(inbound_cnt) AS inbound_count,
SUM(leave_duration) AS leave_duration
FROM (
SELECT l.user_id AS uid, l.user_name AS uname, 1 AS leave_app, 0 AS leave_approve, 0 AS borrow_app, 0 AS inbound_cnt, COALESCE(l.duration,0) AS leave_duration
FROM jl_key_dm_leave_application l
<where>
AND l.is_used = 1 AND l.STATUS != 0
<if test="start != null and start != ''">
AND l.start_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND l.start_time &lt; #{end}
</if>
</where>
UNION ALL
SELECT r.approver_id AS uid, r.approver_name AS uname, 0, CASE WHEN r.approver_result = 1 THEN 1 ELSE 0 END, 0, 0, 0
FROM jl_key_dm_leave_approval_record r
<where>
AND r.is_used = 1 AND r.STATUS = 2
<if test="start != null and start != ''">
AND r.approver_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND r.approver_time &lt; #{end}
</if>
</where>
UNION ALL
SELECT b.applicant_id AS uid, b.applicant_name AS uname, 0, 0, 1, 0, 0
FROM jl_key_dm_borrow_application b
<where>
AND b.is_used = 1 AND b.approval_status != 0
<if test="start != null and start != ''">
AND b.submit_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND b.submit_time &lt; #{end}
</if>
</where>
UNION ALL
SELECT ir.create_by AS uid, du.`name` AS uname, 0, 0, 0, 1, 0
FROM jl_key_dm_inbound_record ir LEFT JOIN jl_key_dm_user du on ir.create_by = du.id
<where>
AND ir.is_used = 1
<if test="start != null and start != ''">
AND ir.create_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND ir.create_time &lt; #{end}
</if>
</where>
) t
GROUP BY uid, uname
ORDER BY leave_applications DESC, borrow_applications DESC
</select>
<!-- 工作量明细:按类型返回对应明细 -->
<select id="selectWorkloadDetails" parameterType="map" resultType="map">
<choose>
<when test="type == 'leave'">
SELECT id, user_id, user_name, start_time, end_time, duration, reason, `status` FROM jl_key_dm_leave_application
<where>
AND user_id = #{user_id} AND STATUS != 0
<if test="start != null and start != ''">
AND create_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND create_time &lt; #{end}
</if>
</where>
ORDER BY create_time DESC
</when>
<when test="type == 'inventory'">
SELECT b.application_no, b.applicant_id, b.applicant_name, d.material_name, b.approval_status, d.apply_quantity, d.returned_quantity,b.submit_time
FROM jl_key_dm_borrow_application_detail d
LEFT JOIN jl_key_dm_borrow_application b ON b.id = d.application_id
<where>
AND b.is_used = 1 AND b.approval_status != 0 AND b.applicant_id = #{user_id}
<if test="start != null and start != ''">
AND b.submit_time &gt; #{start}
</if>
<if test="end != null and end != ''">
AND b.submit_time &lt; #{end}
</if>
</where>
ORDER BY b.submit_time DESC
</when>
<otherwise>
SELECT 1 AS dummy
</otherwise>
</choose>
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论