677 lines
28 KiB
XML
677 lines
28 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.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,
|
||
SUM( CASE WHEN mdi.is_active = '1' THEN 1 ELSE 0 END ) 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
|
||
ma_apply aaa
|
||
LEFT JOIN ma_apply_details 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>
|
||
<if test="createUser != null and createUser != ''">
|
||
and aaa.create_user like concat('%', #{createUser}, '%')
|
||
</if>
|
||
<if test="startCreateTime != null and endCreateTime != null ">
|
||
and aaa.create_time >= #{startCreateTime}
|
||
and aaa.create_time < DATE_ADD(#{endCreateTime}, INTERVAL 1 DAY)
|
||
</if>
|
||
<if test="companyId != null">
|
||
and mdi.on_company = #{companyId}
|
||
</if>
|
||
GROUP BY
|
||
aaa.id
|
||
ORDER BY FIELD(aaa.status, '3','0','1') ASC,aaa.create_time 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.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 ma_apply_details cdrd
|
||
LEFT JOIN ma_dev_info d ON cdrd.dev_id = d.ma_id AND d.is_active = '1'
|
||
LEFT JOIN ma_apply 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
|
||
INNER 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 ma_apply (create_user, order_number)
|
||
VALUES (#{createUser}, #{orderNumber})
|
||
</insert>
|
||
|
||
<insert id="insertOrderDevReal">
|
||
INSERT INTO ma_apply_details (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,
|
||
ma_status,
|
||
province_id,
|
||
on_company,
|
||
<!-- 非必填字段:有值才插入 -->
|
||
<if test="originalCode != null and originalCode != ''">identify_code,</if>
|
||
<if test="typeId != null">type_id,</if>
|
||
<if test="manufacturerId != null and manufacturerId != ''">supplier_id,</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>
|
||
<if test="unit != null">unit,</if>
|
||
<!-- 默认值字段:无值时插入默认值'1'(未删除) -->
|
||
is_active,
|
||
change_status,
|
||
up_down_status
|
||
)
|
||
VALUES (
|
||
#{name},
|
||
#{count},
|
||
#{specificationModel},
|
||
#{manageType},
|
||
#{code},
|
||
'0',
|
||
'340000000000',
|
||
#{propertyUnitId},
|
||
<!-- 非必填字段对应值 -->
|
||
<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>
|
||
<if test="unit != null">#{unit},</if>
|
||
<!-- 默认值:即使实体类无该属性,也插入'1' -->
|
||
'1',
|
||
'0',
|
||
'0'
|
||
)
|
||
</insert>
|
||
|
||
<insert id="interFile">
|
||
INSERT INTO ma_dev_file (ma_id,
|
||
file_type,
|
||
file_name,
|
||
file_url,
|
||
creator,
|
||
create_time,
|
||
is_active)
|
||
VALUES (#{maId},
|
||
#{fileType},
|
||
#{fileName},
|
||
#{fileUrl},
|
||
#{creator},
|
||
now(),
|
||
'1')
|
||
</insert>
|
||
<insert parameterType="com.bonus.material.devchange.domain.MaDevInfoXlsx" id="interDeviceXlsx" useGeneratedKeys="true"
|
||
keyProperty="maId">
|
||
INSERT INTO ma_dev_info (
|
||
<!-- 必选字段:若业务要求必须传值,可去掉if判断 -->
|
||
device_name,
|
||
device_count,
|
||
item_type_model,
|
||
manage_type,
|
||
code,
|
||
ma_status,
|
||
province_id,
|
||
on_company,
|
||
<!-- 非必填字段:有值才插入 -->
|
||
<if test="originalCode != null and originalCode != ''">identify_code,</if>
|
||
<if test="typeId != null">type_id,</if>
|
||
<if test="manufacturerId != null and manufacturerId != ''">supplier_id,</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>
|
||
<if test="unit != null">unit,</if>
|
||
<!-- 默认值字段:无值时插入默认值'1'(未删除) -->
|
||
is_active,
|
||
change_status,
|
||
up_down_status
|
||
)
|
||
VALUES (
|
||
#{name},
|
||
#{count},
|
||
#{specificationModel},
|
||
#{manageType},
|
||
#{code},
|
||
'0',
|
||
'340000000000',
|
||
#{propertyUnitId},
|
||
<!-- 非必填字段对应值 -->
|
||
<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>
|
||
<if test="unit != null">#{unit},</if>
|
||
<!-- 默认值:即使实体类无该属性,也插入'1' -->
|
||
'1',
|
||
'0',
|
||
'0'
|
||
)
|
||
</insert>
|
||
|
||
<update id="submitOrder">
|
||
UPDATE ma_apply
|
||
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 ma_apply_details
|
||
where cs_id = #{id})
|
||
</update>
|
||
|
||
<delete id="delOrder">
|
||
update ma_apply
|
||
set is_active = 0
|
||
where id = #{id}
|
||
</delete>
|
||
<delete id="delFile">
|
||
DELETE
|
||
FROM ma_dev_file
|
||
WHERE ma_id = #{maId}
|
||
</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>
|
||
|
||
<update id="updateChangeStatus">
|
||
<foreach collection="list" item="data" separator=";">
|
||
UPDATE ma_dev_info SET change_status ='1',ma_status = '1' WHERE ma_id = #{data.key}
|
||
</foreach>
|
||
</update>
|
||
|
||
<update id="updateDeviceByMaId">
|
||
UPDATE ma_dev_info
|
||
SET
|
||
device_name = #{name},
|
||
device_count = #{count},
|
||
item_type_model = #{specificationModel},
|
||
manage_type = #{manageType},
|
||
<!-- 非必填字段:有值才更新 -->
|
||
<if test="originalCode != null and originalCode != ''">
|
||
identify_code = #{originalCode},
|
||
</if>
|
||
<if test="typeId != null">
|
||
type_id = #{typeId},
|
||
</if>
|
||
<if test="manufacturerId != null and manufacturerId != ''">
|
||
supplier_id = #{manufacturerId},
|
||
</if>
|
||
<if test="productionDate != null">
|
||
production_date = #{productionDate},
|
||
</if>
|
||
<if test="maxServiceLifeYears != null">
|
||
max_working_hours = #{maxServiceLifeYears},
|
||
</if>
|
||
<if test="expirationTime != null">
|
||
expiration_time = #{expirationTime},
|
||
</if>
|
||
<if test="originalValue != null">
|
||
buy_price = #{originalValue},
|
||
</if>
|
||
<if test="purchaseDate != null">
|
||
purchase_date = #{purchaseDate},
|
||
</if>
|
||
<if test="unit != null">
|
||
unit = #{unit}
|
||
</if>
|
||
WHERE
|
||
<!-- 注意:此处需要替换为实际的主键字段,例如 id -->
|
||
ma_id = #{maId}
|
||
</update>
|
||
|
||
<select id="getDevNoCheck" resultType="int">
|
||
select count(1)
|
||
from ma_dev_info
|
||
where ma_id IN (select dev_id
|
||
from ma_apply_details
|
||
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 = '0'
|
||
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 = '0' -- 确保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 t1.type_id AS value,
|
||
t1.level,
|
||
t1.type_name AS label,
|
||
t1.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 t1.type_id = all_levels.type_id
|
||
WHERE t1.type_id = #{firstLevelId}
|
||
AND t1.parent_id = '0' -- 确保是一级类型
|
||
AND t1.del_flag = '0'
|
||
</select>
|
||
<select id="selectTodayOrderCount" resultType="java.lang.Integer">
|
||
SELECT COUNT(*)
|
||
FROM ma_apply
|
||
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,
|
||
mdi.unit AS unit,
|
||
TIMESTAMPDIFF(YEAR, mdi.production_date, CURDATE()) AS serviceLife,
|
||
jsp.pro_code AS usingProjectId,
|
||
jsp.pro_name AS usingProject,
|
||
mdi.identify_code AS originalCode,
|
||
mdi.supplier_id 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,
|
||
sc.name AS province
|
||
from ma_apply cds
|
||
LEFT JOIN ma_apply_details cdrd ON cdrd.cs_id = cds.id
|
||
LEFT JOIN ma_dev_info mdi ON cdrd.dev_id = mdi.ma_id
|
||
INNER 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 (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on
|
||
mdi.ma_id=mdq.ma_id
|
||
LEFT JOIN ma_supplier ms ON ms.supplier_id = mdi.supplier_id
|
||
LEFT JOIN sys_cnarea sc ON sc.area_code = mdi.province_id
|
||
<where>
|
||
mdi.is_active = '1'
|
||
<if test="name != null and name != ''">
|
||
and mdi.device_name like concat('%', #{name}, '%')
|
||
</if>
|
||
<if test="province != null and province != ''">
|
||
and sc.area_code = #{province}
|
||
</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="entryStatus != null and entryStatus != ''">
|
||
and mdi.entry_status = #{entryStatus}
|
||
</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 >= #{minOriginalValue} and mdi.buy_price <= #{maxOriginalValue}
|
||
</if>
|
||
<!-- 生产日期范围 -->
|
||
<if test="startProductionDate != null and endProductionDate != null ">
|
||
and mdi.production_date >= #{startProductionDate}
|
||
and mdi.production_date < DATE_ADD(#{endProductionDate}, INTERVAL 1 DAY)
|
||
</if>
|
||
<!-- 采购日期范围 -->
|
||
<if test="startPurchaseDate != null and endPurchaseDate != null">
|
||
and mdi.purchase_date >= #{startPurchaseDate}
|
||
and mdi.purchase_date < DATE_ADD(#{endPurchaseDate}, INTERVAL 1 DAY)
|
||
</if>
|
||
<!-- 订单创建时间范围 -->
|
||
<if test="startOrderCreateTime != null and endOrderCreateTime != null ">
|
||
and cds.create_time >= #{startOrderCreateTime}
|
||
and cds.create_time < DATE_ADD(#{endOrderCreateTime}, INTERVAL 1 DAY)
|
||
</if>
|
||
<if test="orderCreateUser != null and orderCreateUser != ''">
|
||
and cds.create_user like concat('%', #{orderCreateUser}, '%')
|
||
</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,
|
||
mdi.unit AS unit,
|
||
TIMESTAMPDIFF(YEAR, mdi.production_date, CURDATE()) AS serviceLife,
|
||
jsp.pro_code AS usingProjectId,
|
||
jsp.pro_name AS usingProject,
|
||
mdi.identify_code AS originalCode,
|
||
mdi.supplier_id 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,
|
||
mdi.entry_status AS entryStatus,
|
||
sc.name AS province
|
||
from ma_apply cds
|
||
LEFT JOIN ma_apply_details cdrd ON cdrd.cs_id = cds.id
|
||
LEFT JOIN ma_dev_info mdi ON cdrd.dev_id = mdi.ma_id
|
||
INNER 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 (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on
|
||
mdi.ma_id=mdq.ma_id
|
||
LEFT JOIN ma_supplier ms ON ms.supplier_id = mdi.supplier_id
|
||
LEFT JOIN sys_cnarea sc ON sc.area_code = mdi.province_id
|
||
<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="province != null and province != ''">
|
||
and sc.area_code = #{province}
|
||
</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.supplier_id = #{manufacturerId}
|
||
</if>
|
||
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue != null and maxOriginalValue != ''">
|
||
and mdi.buy_price >= #{minOriginalValue} and mdi.buy_price <= #{maxOriginalValue}
|
||
</if>
|
||
<!-- 生产日期范围 -->
|
||
<if test="startProductionDate != null and endProductionDate != null ">
|
||
and mdi.production_date >= #{startProductionDate}
|
||
and mdi.production_date < DATE_ADD(#{endProductionDate}, INTERVAL 1 DAY)
|
||
</if>
|
||
<!-- 采购日期范围 -->
|
||
<if test="startPurchaseDate != null and endPurchaseDate != null">
|
||
and mdi.purchase_date >= #{startPurchaseDate}
|
||
and mdi.purchase_date < DATE_ADD(#{endPurchaseDate}, INTERVAL 1 DAY)
|
||
</if>
|
||
<!-- 订单创建时间范围 -->
|
||
<if test="startOrderCreateTime != null and endOrderCreateTime != null ">
|
||
and cds.create_time >= #{startOrderCreateTime}
|
||
and cds.create_time < DATE_ADD(#{endOrderCreateTime}, INTERVAL 1 DAY)
|
||
</if>
|
||
<if test="orderCreateUser != null and orderCreateUser != ''">
|
||
and cds.create_user like concat('%', #{orderCreateUser}, '%')
|
||
</if>
|
||
<if test="status != null ">
|
||
and mdi.entry_status = #{status}
|
||
</if>
|
||
|
||
<if test="entryStatus != null and entryStatus != ''">
|
||
and mdi.entry_status = #{entryStatus}
|
||
</if>
|
||
</where>
|
||
</select>
|
||
<select id="listAllProfessionNames" resultType="java.lang.String">
|
||
SELECT CONCAT_WS('/', proType, mainGx, childGx, devCategory, devSubcategory) AS label
|
||
FROM ma_type_view
|
||
</select>
|
||
<select id="listAllManufacturerNames" resultType="java.lang.String">
|
||
SELECT supplier_name
|
||
FROM ma_supplier
|
||
WHERE status = 1
|
||
</select>
|
||
|
||
<select id="getManufacturer" resultType="java.lang.Integer">
|
||
SELECT supplier_id
|
||
FROM ma_supplier
|
||
WHERE supplier_name = #{manufacturer}
|
||
and status = '1'
|
||
</select>
|
||
<select id="getTypeId" resultType="java.lang.Integer">
|
||
SELECT typeId
|
||
FROM ma_type_view
|
||
WHERE CONCAT_WS('/', proType, mainGx, childGx, devCategory, devSubcategory) = #{profession}
|
||
LIMIT 1
|
||
</select>
|
||
<select id="getFileName" resultType="java.lang.String">
|
||
SELECT CONCAT_WS('-', 'Apply', mdi.ma_id, mdi.device_name, mdi.item_type_model)
|
||
from ma_apply cds
|
||
LEFT JOIN ma_apply_details cdrd ON cdrd.cs_id = cds.id
|
||
LEFT JOIN ma_dev_info mdi ON cdrd.dev_id = mdi.ma_id
|
||
INNER 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 (SELECT max(next_check_time) next_check_time, ma_id from ma_dev_qc GROUP BY ma_id) mdq on
|
||
mdi.ma_id = mdq.ma_id
|
||
LEFT JOIN ma_supplier ms ON ms.supplier_id = mdi.supplier_id
|
||
LEFT JOIN sys_cnarea sc ON sc.area_code = mdi.province_id
|
||
WHERE mdi.is_active = '1'
|
||
and cds.id = #{orderId}
|
||
</select>
|
||
<select id="getFileId" resultType="java.util.Map">
|
||
SELECT mdi.ma_id AS id,
|
||
CONCAT_WS('-', 'Apply', mdi.ma_id, mdi.device_name, mdi.item_type_model) AS fileName
|
||
from ma_apply cds
|
||
LEFT JOIN ma_apply_details cdrd ON cdrd.cs_id = cds.id
|
||
LEFT JOIN ma_dev_info mdi ON cdrd.dev_id = mdi.ma_id
|
||
INNER 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 (SELECT max(next_check_time) next_check_time, ma_id from ma_dev_qc GROUP BY ma_id) mdq on
|
||
mdi.ma_id = mdq.ma_id
|
||
LEFT JOIN ma_supplier ms ON ms.supplier_id = mdi.supplier_id
|
||
LEFT JOIN sys_cnarea sc ON sc.area_code = mdi.province_id
|
||
WHERE mdi.is_active = '1'
|
||
and cds.id = #{orderId}
|
||
</select>
|
||
<select id="selNum" resultType="java.lang.Integer">
|
||
SELECT COUNT(1)
|
||
FROM ma_dev_info
|
||
where entry_status = 3
|
||
and ma_id IN (select dev_id
|
||
from ma_apply_details
|
||
where cs_id = #{id})
|
||
AND is_active = '1'
|
||
</select>
|
||
|
||
</mapper>
|