352 lines
15 KiB
XML
352 lines
15 KiB
XML
<?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.material.equipment.mapper.SysDeptMapper">
|
|
|
|
<sql id="selectDeptVo">
|
|
select d.dept_id,
|
|
d.parent_id,
|
|
d.dept_name,
|
|
d.order_num,
|
|
d.leader,
|
|
d.dept_abbreviation,
|
|
d.dept_type,
|
|
d.location,
|
|
d.phone,
|
|
d.status,
|
|
d.del_flag,
|
|
d.city
|
|
from sys_dept d
|
|
</sql>
|
|
|
|
<resultMap type="com.bonus.system.api.domain.SysDept" id="SysDeptResult">
|
|
<id property="deptId" column="dept_id" />
|
|
<result property="parentId" column="parent_id" />
|
|
<result property="ancestors" column="ancestors" />
|
|
<result property="deptName" column="dept_name" />
|
|
<result property="orderNum" column="order_num" />
|
|
<result property="leader" column="leader" />
|
|
<result property="phone" column="phone" />
|
|
<result property="email" column="email" />
|
|
<result property="status" column="status" />
|
|
<result property="delFlag" column="del_flag" />
|
|
<result property="parentName" column="parent_name" />
|
|
<result property="createBy" column="create_by" />
|
|
<result property="createTime" column="create_time" />
|
|
<result property="updateBy" column="update_by" />
|
|
<result property="updateTime" column="update_time" />
|
|
<result property="menuTemplateId" column="menu_template_id" />
|
|
<result property="province" column="province" />
|
|
<result property="city" column="city" />
|
|
<result property="district" column="district" />
|
|
<result property="address" column="address" />
|
|
<result property="deptAbbreviation" column="dept_abbreviation" />
|
|
<result property="remark" column="remark" />
|
|
<result property="logo" column="logo" />
|
|
<result property="adminUserId" column="admin_user_id" />
|
|
<result property="initPassword" column="init_password" />
|
|
</resultMap>
|
|
|
|
<resultMap type="com.bonus.material.basic.domain.SysDeptVO" id="SysDeptVOResult">
|
|
<id property="deptId" column="dept_id" />
|
|
<result property="parentId" column="parent_id" />
|
|
<result property="ancestors" column="ancestors" />
|
|
<result property="deptName" column="dept_name" />
|
|
<result property="orderNum" column="order_num" />
|
|
<result property="leader" column="leader" />
|
|
<result property="phone" column="phone" />
|
|
<result property="email" column="email" />
|
|
<result property="status" column="status" />
|
|
<result property="delFlag" column="del_flag" />
|
|
<result property="parentName" column="parent_name" />
|
|
<result property="createBy" column="create_by" />
|
|
<result property="createTime" column="create_time" />
|
|
<result property="updateBy" column="update_by" />
|
|
<result property="updateTime" column="update_time" />
|
|
<result property="menuTemplateId" column="menu_template_id" />
|
|
<result property="province" column="province" />
|
|
<result property="city" column="city" />
|
|
<result property="district" column="district" />
|
|
<result property="address" column="address" />
|
|
<result property="deptAbbreviation" column="dept_abbreviation" />
|
|
<result property="remark" column="remark" />
|
|
<result property="logo" column="logo" />
|
|
<result property="adminUserId" column="admin_user_id" />
|
|
<result property="initPassword" column="init_password" />
|
|
</resultMap>
|
|
|
|
<select id="selectDeptTree" resultType="com.bonus.material.equipment.domain.SysDept">
|
|
SELECT * FROM sys_dept WHERE del_flag = '0' ORDER BY parent_id, order_num
|
|
</select>
|
|
|
|
<select id="selectDeptList" parameterType="com.bonus.system.api.domain.SysDept" resultMap="SysDeptResult">
|
|
<include refid="selectDeptVo"/>
|
|
where d.del_flag = '0'
|
|
<if test="deptName != null and deptName != ''">
|
|
AND dept_name like concat('%', #{deptName}, '%')
|
|
</if>
|
|
</select>
|
|
|
|
<select id="selectDeptVOList" resultMap="SysDeptVOResult">
|
|
<include refid="selectDeptVo"/>
|
|
where d.del_flag = '0'
|
|
<if test="deptName != null and deptName != ''">
|
|
AND dept_name like concat('%', #{deptName}, '%')
|
|
</if>
|
|
</select>
|
|
|
|
<select id="selectUserList" resultType="com.bonus.material.equipment.domain.DeptEquipmentConfig">
|
|
SELECT
|
|
mt.type_id AS equipmentId,
|
|
mt2.type_name AS equipmentName,
|
|
mt.type_name AS equipmenttype,
|
|
mt.jiju_type as jijuType,
|
|
CASE
|
|
|
|
WHEN MAX( mdc.config_value ) IS NOT NULL
|
|
AND MAX( mdc.config_value ) != '' THEN
|
|
'已配置' ELSE '未配置'
|
|
END AS configStatus
|
|
FROM
|
|
ma_type mt
|
|
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
|
|
LEFT JOIN ma_dept_config mdc ON mdc.type_id = mt.type_id
|
|
AND mdc.dept_id = #{deptId}
|
|
WHERE
|
|
mt.LEVEL =5
|
|
GROUP BY
|
|
mt.type_id,
|
|
mt2.type_name,
|
|
mt.type_name
|
|
UNION
|
|
|
|
SELECT
|
|
mt.type_id AS equipmentId,
|
|
mt2.type_name AS equipmentName,
|
|
mt.type_name AS equipmenttype,
|
|
mt.jiju_type as jijuType,
|
|
CASE
|
|
|
|
WHEN MAX( mdc.config_value ) IS NOT NULL
|
|
AND MAX( mdc.config_value ) != '' THEN
|
|
'已配置' ELSE '未配置'
|
|
END AS configStatus
|
|
FROM
|
|
tool_type mt
|
|
LEFT JOIN tool_type mt2 ON mt.parent_id = mt2.type_id
|
|
LEFT JOIN ma_dept_config mdc ON mdc.type_id = mt.type_id
|
|
AND mdc.dept_id = #{deptId}
|
|
WHERE
|
|
mt.LEVEL =4
|
|
<if test="equipmentName != null and equipmentName != ''">
|
|
AND mt.type_name LIKE CONCAT('%', #{equipmentName}, '%')
|
|
</if>
|
|
<if test="equipmenttype != null and equipmenttype != ''">
|
|
AND mt2.type_name LIKE CONCAT('%', #{equipmenttype}, '%')
|
|
</if>
|
|
GROUP BY mt.type_id, mt2.type_name, mt.type_name
|
|
</select>
|
|
|
|
<select id="selectConfigList" resultType="com.bonus.material.equipment.domain.ConfigEntity">
|
|
SELECT
|
|
config_value AS basicConfig,
|
|
config_type AS configurationType,
|
|
config_rate AS configurationRate,
|
|
config_description AS configurationDescription
|
|
FROM ma_dept_config
|
|
WHERE dept_id = #{deptId}
|
|
AND type_id = #{typeId}
|
|
</select>
|
|
|
|
<select id="getTree" resultType="com.bonus.material.equipment.domain.DeptTreeSelect">
|
|
SELECT
|
|
mt.type_id AS id,
|
|
mt.type_name AS name
|
|
FROM ma_type mt
|
|
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
|
|
LEFT JOIN ma_dept_config mdc ON mdc.type_id = mt.type_id
|
|
WHERE mt.level = 3
|
|
GROUP BY mt.type_id, mt2.type_name, mt.type_name
|
|
</select>
|
|
|
|
<select id="selectDeptConfigRatePivot" resultType="com.bonus.material.equipment.domain.DeptConfigRateSummary">
|
|
SELECT
|
|
my.type_name AS deptName,
|
|
my.type_id AS typeId,
|
|
sd.dept_name AS companyName,
|
|
grouped.dept_id AS companyId,
|
|
grouped.config_type AS configType,
|
|
grouped.config_value AS configValue,
|
|
if(grouped.config_rate='/',0,grouped.config_rate) AS configRate,
|
|
IFNULL(order_stat.order_count, 0) AS orderCount
|
|
FROM
|
|
(
|
|
SELECT
|
|
dept_id,
|
|
type_id,
|
|
config_type,
|
|
SUM(config_value) AS config_value,
|
|
SUM(if(config_rate='/',0,config_rate)) AS config_rate
|
|
FROM ma_dept_config
|
|
where jiju_type =1
|
|
GROUP BY dept_id, type_id, config_type
|
|
) grouped
|
|
LEFT JOIN sys_dept sd ON sd.dept_id = grouped.dept_id
|
|
LEFT JOIN ma_type my ON my.type_id = grouped.type_id
|
|
|
|
-- 设备订单数量子查询
|
|
LEFT JOIN (
|
|
SELECT
|
|
sd.dept_id AS dept_id,
|
|
mt.type_id AS parent_type_id,
|
|
COUNT(md.num) AS order_count
|
|
FROM
|
|
ma_order_details md
|
|
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
|
|
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
|
|
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
|
|
LEFT JOIN sys_dept sd ON moi.buyer_company = sd.dept_id
|
|
where devType =0
|
|
GROUP BY sd.dept_id, mt.type_id
|
|
) order_stat
|
|
ON order_stat.dept_id = grouped.dept_id
|
|
AND order_stat.parent_type_id = grouped.type_id
|
|
|
|
UNION
|
|
|
|
SELECT
|
|
my.type_name AS deptName,
|
|
my.type_id AS typeId,
|
|
sd.dept_name AS companyName,
|
|
grouped.dept_id AS companyId,
|
|
grouped.config_type AS configType,
|
|
grouped.config_value AS configValue,
|
|
if(grouped.config_rate='/',0,grouped.config_rate) AS configRate,
|
|
IFNULL(order_stat.order_count, 0) AS orderCount
|
|
FROM
|
|
(
|
|
SELECT
|
|
dept_id,
|
|
type_id,
|
|
config_type,
|
|
SUM(config_value) AS config_value,
|
|
SUM(if(config_rate='/',0,config_rate)) AS config_rate
|
|
FROM ma_dept_config
|
|
where jiju_type =2
|
|
GROUP BY dept_id, type_id, config_type
|
|
) grouped
|
|
LEFT JOIN sys_dept sd ON sd.dept_id = grouped.dept_id
|
|
LEFT JOIN tool_type my ON my.type_id = grouped.type_id
|
|
|
|
-- 设备订单数量子查询
|
|
LEFT JOIN (
|
|
SELECT
|
|
sd.dept_id AS dept_id,
|
|
mt.type_id AS parent_type_id,
|
|
COUNT(md.num) AS order_count
|
|
FROM
|
|
ma_order_details md
|
|
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
|
|
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
|
|
LEFT JOIN tool_type mt ON mdi.type_id = mt.type_id
|
|
LEFT JOIN tool_type mt2 ON mt.parent_id = mt2.type_id
|
|
LEFT JOIN sys_dept sd ON moi.buyer_company = sd.dept_id
|
|
where devType =1
|
|
GROUP BY sd.dept_id, mt.type_id
|
|
) order_stat
|
|
ON order_stat.dept_id = grouped.dept_id
|
|
AND order_stat.parent_type_id = grouped.type_id;
|
|
</select>
|
|
|
|
<select id="selectDeptConfigTypeSummary" resultType="com.bonus.material.equipment.domain.DeptConfigTypeSummary">
|
|
SELECT mt1.type_name AS typeName,
|
|
mt2.type_name AS parentTypeName,
|
|
CAST(mdc.config_rate AS DECIMAL(10, 2)) AS configRate,
|
|
mdc.config_description AS configDescription
|
|
FROM ma_dept_config mdc
|
|
LEFT JOIN ma_type mt1 ON mt1.type_id = mdc.type_id
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
|
WHERE mdc.dept_id = #{deptId}
|
|
</select>
|
|
|
|
<select id="detailsInfo" resultType="com.bonus.material.equipment.domain.EquipmentDetail">
|
|
SELECT
|
|
d.dept_id AS companyId,
|
|
d.vol as labelVol,
|
|
mt3.type_id as typeId,
|
|
mt3.type_name AS NAME,-- 使用层级表当前类型作为名称
|
|
d.config_description AS `desc`,
|
|
d.config_rate AS `value`,
|
|
d.config_type AS configType,
|
|
CONCAT_WS( '>', NULLIF( mt1.type_name, '' ), NULLIF( mt2.type_name, '' ), NULLIF( mt3.type_name, '' ) ) AS combinedName,
|
|
(
|
|
SELECT
|
|
COUNT( md.ma_id )
|
|
FROM
|
|
ma_order_details md
|
|
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
|
|
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
|
|
LEFT JOIN ma_type mto1 ON mdi.type_id = mto1.type_id
|
|
LEFT JOIN ma_type mto2 ON mto1.parent_id = mto2.type_id
|
|
WHERE
|
|
moi.buyer_company = d.dept_id
|
|
AND mto2.type_id = d.type_id
|
|
) AS orderCount,
|
|
SUM(
|
|
CAST(
|
|
d.config_value AS DECIMAL ( 10, 2 ))) AS standard,
|
|
MAX( own_count ) AS own,
|
|
MAX( rent_count ) AS rent
|
|
FROM
|
|
ma_dept_config d -- 层级关系连接(当前类型 → 父级 → 祖父级)
|
|
LEFT JOIN ma_type mt3 ON mt3.type_id = d.type_id
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id
|
|
LEFT JOIN ma_type mt1 ON mt1.type_id = mt2.parent_id -- 自有设备统计子查询(完整语句)
|
|
LEFT JOIN ( SELECT ma_name, SUM( ma_num ) AS own_count FROM ma_own_manage WHERE type = '2' AND is_active = '0' AND company_id = #{companyId} GROUP BY ma_name ) own ON CAST( d.type_id AS CHAR ) = own.ma_name -- 租赁设备统计子查询(完整语句)
|
|
LEFT JOIN ( SELECT ma_name, SUM( ma_num ) AS rent_count FROM ma_own_manage WHERE type = '1' AND is_active = '0' AND company_id = #{companyId} GROUP BY ma_name ) rent ON CAST( d.type_id AS CHAR ) = rent.ma_name
|
|
WHERE
|
|
d.dept_id = #{companyId}
|
|
<choose>
|
|
<when test="configType == 0">
|
|
AND d.config_type IN (0, 3)
|
|
</when>
|
|
<when test="configType == 1">
|
|
AND d.config_type IN (1, 4)
|
|
</when>
|
|
<when test="configType == 2">
|
|
AND d.config_type IN (2, 5)
|
|
</when>
|
|
<otherwise>
|
|
<if test="configType != null">
|
|
AND d.config_type = #{configType}
|
|
</if>
|
|
</otherwise>
|
|
</choose>
|
|
GROUP BY
|
|
d.dept_id,
|
|
d.config_type,
|
|
d.type_id
|
|
</select>
|
|
|
|
<select id="listFromDevInfo" resultType="com.bonus.material.equipment.domain.NewmydevInfo">
|
|
SELECT
|
|
md.on_company AS companyId,
|
|
mt2.type_id AS typeId, mt2.type_name as typeName,
|
|
SUM( 1 ) AS ownCount
|
|
FROM
|
|
ma_dev_info md
|
|
LEFT JOIN ma_type mt ON mt.type_id = md.type_id
|
|
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
|
|
WHERE
|
|
md.is_active = '1' AND md.on_company = #{companyId}
|
|
GROUP BY
|
|
mt2.type_id
|
|
</select>
|
|
|
|
<select id="getCityName" resultType="java.lang.String">
|
|
select name
|
|
from base_address where code = #{city}
|
|
</select>
|
|
|
|
</mapper>
|