Bonus-Cloud-Material-Mall/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevMergeMapper.xml

428 lines
18 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.device.mapper.DevMergeMapper">
<select id="list" resultType="com.bonus.material.device.domain.vo.DevMergeVo">
SELECT
aaa.id AS id,
aaa.create_user AS createUser,
aaa.create_time AS createTime,
aaa.status AS status,
COUNT(bbb.dev_id) AS devCount,
aaa.order_number AS orderNumber,
SUM(CASE WHEN mdi.entry_status = 1 THEN 1 ELSE 0 END) AS agree,
SUM(CASE WHEN mdi.entry_status = 2 THEN 1 ELSE 0 END) AS reject
FROM
cs_device_status aaa
LEFT JOIN cs_device_real_dev bbb ON aaa.id = bbb.cs_id
LEFT JOIN ma_dev_info mdi ON bbb.dev_id = mdi.ma_id AND mdi.is_active = '1'
where aaa.is_active = 1
<if test="status != null and status != ''">
and aaa.status = #{status}
</if>
GROUP BY
aaa.id
ORDER BY aaa.status DESC
</select>
<select id="devList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
SELECT
cds.order_number AS orderNumber,
cds.create_user AS createUser,
cds.create_time AS createTime,
cds.status AS status,
mtv.proType,
mtv.mainGx,
mtv.childGx,
mtv.devCategory,
mtv.devSubcategory,
mtv.devName,
mtv.devModel,
mtv.unit_name,
d.ma_id as maId,
d.code as code,
d.identify_code as identifyCode,
d.device_name as deviceName,
d.device_count as deviceCount,
d.brand as brand,
d.production_date as productionDate,
d.working_hours as workingHours,
d.person as person,
d.person_phone as personPhone,
d.create_time as createTime,
d.update_time as updateTime,
d.on_company as companyId,
sd.dept_name as companyName,
c.operate_address as operateAddress,
d.entry_status AS entryStatus,
d.buy_price AS buyPrice
FROM cs_device_real_dev cdrd
LEFT JOIN ma_dev_info d ON cdrd.dev_id = d.ma_id AND d.is_active = '1'
LEFT JOIN cs_device_status cds ON cdrd.cs_id = cds.id
LEFT JOIN sys_dept sd ON d.on_company = sd.dept_id
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = d.type_id
<where>
<if test="orderId != null and orderId != ''">
and cdrd.cs_id = #{orderId}
</if>
</where>
</select>
<insert id="addOrder" useGeneratedKeys="true" keyProperty="id">
INSERT INTO cs_device_status (create_user, order_number)
VALUES (#{createUser}, #{orderNumber})
</insert>
<insert id="insertOrderDevReal">
INSERT INTO cs_device_real_dev (cs_id, dev_id)
VALUES (#{orderId}, #{maId})
</insert>
<insert parameterType="com.bonus.material.devchange.domain.MaDevInfo" id="interDevice" useGeneratedKeys="true" keyProperty="maId">
INSERT INTO ma_dev_info (
<!-- 必选字段若业务要求必须传值可去掉if判断 -->
device_name,
device_count,
item_type_model,
manage_type,
code,
<!-- 非必填字段:有值才插入 -->
<if test="originalCode != null and originalCode != ''">identify_code,</if>
<if test="typeId != null">type_id,</if>
<if test="manufacturerId != null and manufacturerId != ''">brand,</if>
<if test="productionDate != null">production_date,</if>
<if test="maxServiceLifeYears != null">max_working_hours,</if>
<if test="expirationTime != null">expiration_time,</if>
<if test="originalValue != null">buy_price,</if>
<if test="purchaseDate != null">purchase_date,</if>
<!-- 默认值字段:无值时插入默认值'1'(未删除) -->
is_active,
change_status,
up_down_status
)
VALUES (
#{name},
#{count},
#{specificationModel},
#{manageType},
#{code},
<!-- 非必填字段对应值 -->
<if test="originalCode != null and originalCode != ''">#{originalCode},</if>
<if test="typeId != null">#{typeId},</if>
<if test="manufacturerId != null and manufacturerId != ''">#{manufacturerId},</if>
<if test="productionDate != null">#{productionDate},</if>
<if test="maxServiceLifeYears != null">#{maxServiceLifeYears},</if>
<if test="expirationTime != null">#{expirationTime},</if>
<if test="originalValue != null">#{originalValue},</if>
<if test="purchaseDate != null">#{purchaseDate},</if>
<!-- 默认值:即使实体类无该属性,也插入'1' -->
'1',
'3',
'0'
)
</insert>
<update id="submitOrder">
UPDATE cs_device_status
SET status = #{status}
WHERE id = #{id}
</update>
<update id="updateDeviceStatus">
UPDATE ma_dev_info
SET entry_status = 0
WHERE ma_id IN (select dev_id
from cs_device_real_dev
where cs_id = #{id})
</update>
<delete id="delOrder">
update cs_device_status
set is_active = 0
where id = #{id}
</delete>
<update id="updateDevice">
<foreach collection="list" item="data" separator=";">
UPDATE ma_dev_info SET entry_status = #{data.value} WHERE ma_id = #{data.key}
</foreach>
</update>
<select id="getDevNoCheck" resultType="int">
select count(1)
from ma_dev_info
where ma_id IN (select dev_id
from cs_device_real_dev
where cs_id = #{id})
and is_active = 1
and entry_status = 0
</select>
<select id="findFirstLevelTypes" resultType="java.util.Map">
-- 查询一级类型(顶级类型)
SELECT type_id AS value,
level,
type_name AS label,
parent_id AS parentId
FROM ma_type
WHERE parent_id IS NULL
AND del_flag = '0'; -- 排除已删除的数据
</select>
<select id="findSecondAndThirdLevelTypes" resultType="java.util.Map">
-- 根据一级类型ID查询二、三级类型
-- 假设一级类型ID为100实际使用时替换为具体的一级类型ID
SELECT t2.type_id AS value,
t2.level,
t2.type_name AS label,
t2.parent_id AS parentId
FROM ma_type t1
JOIN ma_type t2 ON t1.type_id = t2.parent_id
OR t1.type_id = (SELECT parent_id FROM ma_type WHERE type_id = t2.parent_id)
WHERE t1.type_id = #{firstLevelId} -- 一级类型ID
AND t1.parent_id IS NULL -- 确保t1是一级类型
AND t2.del_flag = '0'
</select>
<select id="getFourthToSixthLevelTypes" resultType="java.util.Map">
-- 根据三级类型ID查询四、五、六级类型
-- 假设三级类型ID为300实际使用时替换为具体的三级类型ID
SELECT t.type_id AS value,
t.level,
t.type_name AS label,
t.parent_id AS parentId
FROM ma_type t3
JOIN ma_type t ON t3.type_id = t.parent_id
OR t3.type_id = (SELECT parent_id FROM ma_type WHERE type_id = t.parent_id)
OR t3.type_id = (SELECT parent_id
FROM ma_type
WHERE type_id = (SELECT parent_id FROM ma_type WHERE type_id = t.parent_id))
WHERE t3.type_id = #{thirdLevelId} -- 三级类型ID
AND t.del_flag = '0'
</select>
<select id="getSecondToFifthLevelTypes" resultType="java.util.Map">
-- MySQL 5.x兼容版本查询二至五级类型
SELECT t.type_id AS value,
t.level,
t.type_name AS label,
t.parent_id AS parentId
FROM ma_type t1
-- 二级:直接子节点
LEFT JOIN ma_type t2 ON t1.type_id = t2.parent_id AND t2.del_flag = '0'
-- 三级:二级的子节点
LEFT JOIN ma_type t3 ON t2.type_id = t3.parent_id AND t3.del_flag = '0'
-- 四级:三级的子节点
LEFT JOIN ma_type t4 ON t3.type_id = t4.parent_id AND t4.del_flag = '0'
-- 五级:四级的子节点
LEFT JOIN ma_type t5 ON t4.type_id = t5.parent_id AND t5.del_flag = '0'
-- 合并所有层级结果
JOIN (SELECT type_id
FROM ma_type
WHERE parent_id = #{firstLevelId}
AND del_flag = '0' -- 二级
UNION
SELECT t3.type_id
FROM ma_type t2
JOIN ma_type t3 ON t2.type_id = t3.parent_id
WHERE t2.parent_id = #{firstLevelId}
AND t3.del_flag = '0' -- 三级
UNION
SELECT t4.type_id
FROM ma_type t2
JOIN ma_type t3 ON t2.type_id = t3.parent_id
JOIN ma_type t4 ON t3.type_id = t4.parent_id
WHERE t2.parent_id = #{firstLevelId}
AND t4.del_flag = '0' -- 四级
UNION
SELECT t5.type_id
FROM ma_type t2
JOIN ma_type t3 ON t2.type_id = t3.parent_id
JOIN ma_type t4 ON t3.type_id = t4.parent_id
JOIN ma_type t5 ON t4.type_id = t5.parent_id
WHERE t2.parent_id = #{firstLevelId}
AND t5.del_flag = '0' -- 五级
) AS all_levels ON t.type_id = all_levels.type_id
WHERE t1.type_id = #{firstLevelId}
AND t1.parent_id IS NULL -- 确保是一级类型
AND t.del_flag = '0'
</select>
<select id="selectTodayOrderCount" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM cs_device_status
WHERE DATE(create_time) = CURDATE()
AND order_number IS NOT NULL
</select>
<select id="getDevice" resultType="com.bonus.material.devchange.domain.MaDevInfo">
select mdi.ma_id AS maId,
mdi.type_id AS typeId,
cds.id AS orderId,
cds.order_number AS orderNumber,
cds.create_user AS orderCreateUser,
cds.create_time AS orderCreateTime,
cds.status AS orderStatus,
mdi.manage_type AS manageType,
mdi.device_count AS count,
mtv.maxTypeId AS majorId,
mtv.proType AS major,
mtv.mainGxId AS mainProcessId,
mtv.mainGx AS mainProcess,
mtv.childGxId AS subProcessId,
mtv.childGx AS subProcess,
mtv.devCategoryId AS mainCategoryId,
mtv.devCategory AS mainCategory,
mtv.devSubcategory AS subCategory,
mtv.devSubcategoryId AS subCategoryId,
mtv.devNameId AS branchId,
mtv.devName AS branch,
mdi.device_name AS name,
mdi.item_type_model As specificationModel,
mdi.code AS code,
mdi.change_status AS status,
mdi.entry_status AS entryStatus,
TIMESTAMPDIFF(YEAR, mdi.production_date, CURDATE()) AS serviceLife,
jsp.pro_code AS usingProjectId,
jsp.pro_name AS usingProject,
mdi.identify_code AS originalCode,
mdi.brand AS manufacturerId,
ms.supplier_name AS manufacturer,
mdi.purchase_date AS purchaseDate,
mdi.production_date AS productionDate,
sd.dept_id AS propertyUnitId,
sd.dept_name AS propertyUnit,
mdi.buy_price AS originalValue,
mdq.next_check_time AS nextMaintenanceDate,
mdi.max_working_hours AS maxServiceLifeYears
from cs_device_status cds
LEFT JOIN cs_device_real_dev cdrd ON cdrd.cs_id = cds.id
LEFT JOIN ma_dev_info mdi ON cdrd.dev_id = mdi.ma_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
LEFT JOIN jj_sing_project jsp ON mdi.on_project = jsp.pro_code
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
LEFT JOIN ma_dev_qc mdq ON mdq.ma_id = mdi.ma_id
LEFT JOIN ma_supplier ms ON ms.supplier_id = mdi.brand
<where>
mdi.is_active = '1'
<if test="name != null and name != ''">
and mdi.device_name like concat('%', #{name}, '%')
</if>
<if test="specificationModel != null and specificationModel != ''">
and mdi.item_type_model like concat('%', #{specificationModel}, '%')
</if>
<if test="majorId != null and majorId != ''">
and mtv.maxTypeId = #{majorId}
</if>
<if test="subProcessId != null and subProcessId != ''">
and mtv.childGxId = #{subProcessId}
</if>
<if test="code != null and code != ''">
and mdi.code like concat('%', #{code}, '%')
</if>
<if test="originalCode != null and originalCode != ''">
and mdi.identify_code like concat('%', #{originalCode}, '%')
</if>
<if test="propertyUnitId != null and propertyUnitId != ''">
and sd.dept_id = #{propertyUnitId}
</if>
<if test="manufacturerId != null and manufacturerId != ''">
and mdi.brand = #{manufacturerId}
</if>
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue != null and maxOriginalValue != ''">
and mdi.buy_price &gt;= #{minOriginalValue} and mdi.buy_price &lt;= #{maxOriginalValue}
</if>
<if test="startProductionDate != null and startProductionDate != '' and endProductionDate != null and endProductionDate != ''">
and DATE_FORMAT(mdi.production_date,'%Y-%m-%d') between #{startProductionDate} and #{endProductionDate}
</if>
<if test="startPurchaseDate != null and startPurchaseDate != '' and endPurchaseDate != null and endPurchaseDate != ''">
and DATE_FORMAT(mdi.purchase_date,'%Y-%m-%d') between #{startPurchaseDate} and #{endPurchaseDate}
</if>
</where>
</select>
<select id="getDeviceByOrderId" resultType="com.bonus.material.devchange.domain.MaDevInfo">
select mdi.ma_id AS maId,
mdi.type_id AS typeId,
cds.order_number AS orderNumber,
cds.create_user AS orderCreateUser,
cds.create_time AS orderCreateTime,
cds.status AS orderStatus,
mdi.manage_type AS manageType,
mdi.device_count AS count,
mtv.maxTypeId AS majorId,
mtv.proType AS major,
mtv.mainGxId AS mainProcessId,
mtv.mainGx AS mainProcess,
mtv.childGxId AS subProcessId,
mtv.childGx AS subProcess,
mtv.devCategoryId AS mainCategoryId,
mtv.devCategory AS mainCategory,
mtv.devSubcategory AS subCategory,
mtv.devSubcategoryId AS subCategoryId,
mtv.devNameId AS branchId,
mtv.devName AS branch,
mdi.device_name AS name,
mdi.item_type_model As specificationModel,
mdi.code AS code,
mdi.change_status AS status,
TIMESTAMPDIFF(YEAR, mdi.production_date, CURDATE()) AS serviceLife,
jsp.pro_code AS usingProjectId,
jsp.pro_name AS usingProject,
mdi.identify_code AS originalCode,
mdi.brand AS manufacturerId,
ms.supplier_name AS manufacturer,
mdi.purchase_date AS purchaseDate,
mdi.production_date AS productionDate,
sd.dept_id AS propertyUnitId,
sd.dept_name AS propertyUnit,
mdi.buy_price AS originalValue,
mdq.next_check_time AS nextMaintenanceDate,
mdi.max_working_hours AS maxServiceLifeYears
from cs_device_status cds
LEFT JOIN cs_device_real_dev cdrd ON cdrd.cs_id = cds.id
LEFT JOIN ma_dev_info mdi ON cdrd.dev_id = mdi.ma_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
LEFT JOIN jj_sing_project jsp ON mdi.on_project = jsp.pro_code
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
LEFT JOIN ma_dev_qc mdq ON mdq.ma_id = mdi.ma_id
LEFT JOIN ma_supplier ms ON ms.supplier_id = mdi.brand
<where>
mdi.is_active = '1' and cds.id = #{orderId}
<if test="name != null and name != ''">
and mdi.device_name like concat('%', #{name}, '%')
</if>
<if test="specificationModel != null and specificationModel != ''">
and mdi.item_type_model like concat('%', #{specificationModel}, '%')
</if>
<if test="majorId != null and majorId != ''">
and mtv.maxTypeId = #{majorId}
</if>
<if test="subProcessId != null and subProcessId != ''">
and mtv.childGxId = #{subProcessId}
</if>
<if test="code != null and code != ''">
and mdi.code like concat('%', #{code}, '%')
</if>
<if test="originalCode != null and originalCode != ''">
and mdi.identify_code like concat('%', #{originalCode}, '%')
</if>
<if test="propertyUnitId != null and propertyUnitId != ''">
and sd.dept_id = #{propertyUnitId}
</if>
<if test="manufacturerId != null and manufacturerId != ''">
and mdi.brand = #{manufacturerId}
</if>
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue != null and maxOriginalValue != ''">
and mdi.buy_price &gt;= #{minOriginalValue} and mdi.buy_price &lt;= #{maxOriginalValue}
</if>
<if test="startProductionDate != null and startProductionDate != '' and endProductionDate != null and endProductionDate != ''">
and DATE_FORMAT(mdi.production_date,'%Y-%m-%d') between #{startProductionDate} and #{endProductionDate}
</if>
<if test="startPurchaseDate != null and startPurchaseDate != '' and endPurchaseDate != null and endPurchaseDate != ''">
and DATE_FORMAT(mdi.purchase_date,'%Y-%m-%d') between #{startPurchaseDate} and #{endPurchaseDate}
</if>
</where>
</select>
</mapper>