2025-07-04 16:37:48 +08:00
|
|
|
<?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.ancestors,
|
|
|
|
|
d.dept_name,
|
|
|
|
|
d.order_num,
|
|
|
|
|
d.leader,
|
|
|
|
|
d.phone,
|
|
|
|
|
d.email,
|
|
|
|
|
d.status,
|
|
|
|
|
d.del_flag,
|
|
|
|
|
d.create_by,
|
|
|
|
|
d.create_time
|
|
|
|
|
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>
|
|
|
|
|
<select id="selectDeptTree">
|
|
|
|
|
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="selectUserList" resultType="com.bonus.material.equipment.domain.DeptEquipmentConfig">
|
|
|
|
|
SELECT
|
|
|
|
|
mt.type_id AS equipmentId,
|
|
|
|
|
mt2.type_name AS equipmentName,
|
|
|
|
|
mt.type_name AS equipmenttype,
|
|
|
|
|
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 = 3
|
|
|
|
|
<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,
|
|
|
|
|
sd.dept_name AS companyName,
|
|
|
|
|
mdc.dept_id AS companyId,
|
|
|
|
|
mdc.config_type AS configType,
|
|
|
|
|
mdc.config_value AS configValue,
|
|
|
|
|
mdc.config_rate AS configRate,
|
|
|
|
|
IFNULL(order_stat.order_count, 0) AS orderCount
|
|
|
|
|
FROM
|
|
|
|
|
ma_dept_config mdc
|
|
|
|
|
LEFT JOIN sys_dept sd ON sd.dept_id = mdc.dept_id
|
|
|
|
|
LEFT JOIN ma_type my ON my.type_id = mdc.type_id
|
|
|
|
|
|
|
|
|
|
-- 设备订单数量子查询
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
sd.dept_id AS dept_id,
|
|
|
|
|
mt2.type_id AS parent_type_id,
|
|
|
|
|
COUNT(md.ma_id) 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
|
|
|
|
|
GROUP BY sd.dept_id, mt2.type_id
|
|
|
|
|
) order_stat
|
|
|
|
|
ON order_stat.dept_id = mdc.dept_id
|
|
|
|
|
AND order_stat.parent_type_id = mdc.type_id
|
|
|
|
|
|
|
|
|
|
WHERE 1 = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</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,
|
|
|
|
|
mt.type_name AS NAME,
|
|
|
|
|
d.config_description as `desc`,
|
|
|
|
|
SUM(CAST(d.config_rate AS DECIMAL(10, 2))) AS `value`,
|
|
|
|
|
(
|
|
|
|
|
SELECT
|
|
|
|
|
CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END
|
|
|
|
|
FROM ma_dept_config d2
|
|
|
|
|
WHERE d2.dept_id = d.dept_id AND d2.config_type = '3'
|
|
|
|
|
) AS ifExist,
|
|
|
|
|
|
|
|
|
|
(
|
|
|
|
|
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 mt1 ON mdi.type_id = mt1.type_id
|
|
|
|
|
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
|
|
|
|
|
WHERE
|
|
|
|
|
moi.buyer_company = d.dept_id AND
|
|
|
|
|
mt2.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 (
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
LEFT JOIN ma_type mt ON mt.type_id = d.type_id
|
|
|
|
|
WHERE
|
|
|
|
|
1=1
|
|
|
|
|
<if test="companyId != null">
|
|
|
|
|
AND d.dept_id = #{companyId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="configType != null">
|
|
|
|
|
AND d.config_type = #{configType}
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
GROUP BY
|
|
|
|
|
d.dept_id,
|
|
|
|
|
d.config_type,
|
|
|
|
|
d.type_id;
|
|
|
|
|
</select>
|
|
|
|
|
<select id="listFromDevInfo" resultType="com.bonus.material.equipment.domain.NewmydevInfo">
|
|
|
|
|
SELECT
|
|
|
|
|
md.own_co 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'
|
2025-07-07 08:52:02 +08:00
|
|
|
AND md.own_co = #{companyId}
|
2025-07-04 16:37:48 +08:00
|
|
|
|
|
|
|
|
GROUP BY
|
|
|
|
|
mt.type_id
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</mapper>
|