495 lines
20 KiB
XML
495 lines
20 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.devchange.mapper.MaDevInfoMapper">
|
||
<resultMap id="BaseResultMap" type="com.bonus.material.devchange.domain.MaDevInfo">
|
||
<id column="ma_id" property="maId"/>
|
||
<result column="device_name" property="deviceName"/>
|
||
<result column="device_count" property="deviceCount"/>
|
||
<result column="code" property="code"/>
|
||
<result column="identify_code" property="identifyCode"/>
|
||
<result column="type_id" property="typeId"/>
|
||
<result column="ma_status" property="maStatus"/>
|
||
<result column="lease_scope" property="leaseScope"/>
|
||
<result column="location" property="location"/>
|
||
<result column="brand" property="brand"/>
|
||
<result column="item_type_model" property="modelName"/>
|
||
<result column="production_date" property="productionDate"/>
|
||
<result column="working_hours" property="workingHours"/>
|
||
<result column="pic_url" property="picUrl"/>
|
||
<result column="js_month_price" property="jsMonthPrice"/>
|
||
<result column="js_day_price" property="jsDayPrice"/>
|
||
<result column="description" property="description"/>
|
||
<result column="gps_code" property="gpsCode"/>
|
||
<result column="on_company" property="ownCo"/>
|
||
<result column="person" property="person"/>
|
||
<result column="person_phone" property="personPhone"/>
|
||
<result column="create_time" property="createTime"/>
|
||
<result column="creator" property="creator"/>
|
||
<result column="deposit" property="deposit"/>
|
||
<result column="is_active" property="isActive"/>
|
||
<result column="update_time" property="updateTime"/>
|
||
<result column="update_by" property="updateBy"/>
|
||
<result column="is_operator" property="isOperator"/>
|
||
<result column="specification" property="specification"/>
|
||
<result column="province_id" property="provinceId"/>
|
||
<result column="city_id" property="cityId"/>
|
||
<result column="area_id" property="areaId"/>
|
||
<result column="video_url" property="videoUrl"/>
|
||
<result column="check_date" property="checkDate"/>
|
||
<result column="check_cycle" property="checkCycle"/>
|
||
<result column="is_qc" property="isQc"/>
|
||
<result column="is_safe_book" property="isSafeBook"/>
|
||
<result column="total_up_day" property="totalUpDay"/>
|
||
<result column="total_lease_day" property="totalLeaseDay"/>
|
||
<result column="origina_value" property="originaValue"/>
|
||
<result column="change_status" jdbcType="CHAR" property="changeStatus"/>
|
||
<result column="expiration_time" jdbcType="DATE" property="expirationTime"/>
|
||
<result column="entry_status" jdbcType="CHAR" property="entryStatus"/>
|
||
<result column="up_down_status" jdbcType="CHAR" property="upDownStatus"/>
|
||
<result column="json_data" property="jsonData"/>
|
||
<result column="buy_price" property="buyPrice"/>
|
||
<result column="on_project" property="onProject"/>
|
||
<result column="childGx" property="childGx"/>
|
||
<result column="company_name" property="companyName"/>
|
||
<result column="devCategory" property="devCategory"/>
|
||
<result column="devModel" property="devModel"/>
|
||
<result column="devName" property="devName"/>
|
||
<result column="devSubcategory" property="devSubcategory"/>
|
||
<result column="mainGx" property="mainGx"/>
|
||
<result column="next_check_time" property="nextCheckTime"/>
|
||
<result column="proType" property="proType"/>
|
||
<result column="unit_name" property="unitName"/>
|
||
<result column="pro_name" property="proName"/>
|
||
|
||
</resultMap>
|
||
<sql id="Base_Column_List">
|
||
ma_id, device_name, device_weight, device_count, `code`, identify_code, type_id, ma_status,
|
||
lease_scope, `location`, brand, model_name, production_date, working_hours, serial_number,
|
||
pic_url, js_month_price, js_day_price, `description`,
|
||
gps_code, on_company, person, person_phone, create_time, creator, deposit, is_active,
|
||
update_time, update_by, is_operator, specification, province_id, city_id, area_id,
|
||
video_url, own_id, check_date, check_cycle, is_qc, is_safe_book, is_zone, zone_id,
|
||
total_up_day, total_lease_day, origina_value, change_status, expiration_time, entry_status,
|
||
up_down_status, json_data, buy_price, item_type_model, on_project
|
||
</sql>
|
||
<delete id="delProperties">
|
||
delete
|
||
from ma_dev_info_properties
|
||
where ma_id = #{maId}
|
||
</delete>
|
||
|
||
<insert id="insertDevInfoProperties">
|
||
insert into
|
||
ma_dev_info_properties(ma_id, property_name, property_value, create_time)
|
||
values
|
||
<foreach collection="list" item="item" index="index" separator=",">
|
||
(
|
||
#{maId},
|
||
#{item.propertyName},
|
||
#{item.propertyValue},
|
||
now()
|
||
)
|
||
</foreach>
|
||
</insert>
|
||
|
||
<update id="updateDeviceStatus">
|
||
UPDATE ma_dev_info
|
||
SET up_down_status =
|
||
CASE ma_id
|
||
<foreach collection="list" item="data">
|
||
WHEN #{data.key} THEN #{data.value}
|
||
</foreach>
|
||
END
|
||
WHERE ma_id IN
|
||
<foreach collection="list" item="data" open="(" separator="," close=")">
|
||
#{data.key}
|
||
</foreach>
|
||
</update>
|
||
|
||
|
||
<!-- 完善的updateDeviceApi方法 -->
|
||
<update id="updateDeviceApi" parameterType="com.bonus.material.devchange.domain.MaDevInfo">
|
||
UPDATE ma_dev_info
|
||
<set>
|
||
<!-- 基础信息字段 -->
|
||
<if test="deviceName != null and deviceName != ''">
|
||
device_name = #{deviceName},
|
||
</if>
|
||
|
||
<if test="deviceWeight != null">
|
||
device_weight = #{deviceWeight},
|
||
</if>
|
||
<if test="deviceCount != null">
|
||
device_count = #{deviceCount},
|
||
</if>
|
||
<if test="code != null and code != ''">
|
||
code = #{code},
|
||
</if>
|
||
<if test="identifyCode != null and identifyCode != ''">
|
||
identify_code = #{identifyCode},
|
||
</if>
|
||
<if test="typeId != null">
|
||
type_id = #{typeId},
|
||
</if>
|
||
<if test="maStatus != null and maStatus != ''">
|
||
ma_status = #{maStatus},
|
||
</if>
|
||
<if test="leaseScope != null and leaseScope != ''">
|
||
lease_scope = #{leaseScope},
|
||
</if>
|
||
<if test="location != null and location != ''">
|
||
`location` = #{location},
|
||
</if>
|
||
|
||
<!-- 设备属性字段 -->
|
||
<if test="brand != null and brand != ''">
|
||
brand = #{brand},
|
||
</if>
|
||
<if test="modelName != null and modelName != ''">
|
||
model_name = #{modelName},
|
||
</if>
|
||
<if test="productionDate != null">
|
||
production_date = #{productionDate},
|
||
</if>
|
||
<if test="workingHours != null">
|
||
working_hours = #{workingHours},
|
||
</if>
|
||
|
||
<!-- 价格相关字段 -->
|
||
<if test="monthLeasePrice != null">
|
||
month_lease_price = #{monthLeasePrice},
|
||
</if>
|
||
<if test="dayLeasePrice != null">
|
||
day_lease_price = #{dayLeasePrice},
|
||
</if>
|
||
<if test="jsMonthPrice != null">
|
||
js_month_price = #{jsMonthPrice},
|
||
</if>
|
||
<if test="jsDayPrice != null">
|
||
js_day_price = #{jsDayPrice},
|
||
</if>
|
||
<if test="deposit != null">
|
||
deposit = #{deposit},
|
||
</if>
|
||
<if test="buyPrice != null">
|
||
buy_price = #{buyPrice},
|
||
</if>
|
||
|
||
<!-- 状态相关字段 -->
|
||
<if test="isActive != null">
|
||
is_active = #{isActive},
|
||
</if>
|
||
<if test="changeStatus != null and changeStatus != ''">
|
||
change_status = #{changeStatus},
|
||
</if>
|
||
<if test="expirationTime != null">
|
||
expiration_time = #{expirationTime},
|
||
</if>
|
||
<if test="entryStatus != null and entryStatus != ''">
|
||
entry_status = #{entryStatus},
|
||
</if>
|
||
<if test="upDownStatus != null and upDownStatus != ''">
|
||
up_down_status = #{upDownStatus},
|
||
</if>
|
||
|
||
<!-- 其他信息字段 -->
|
||
<if test="picUrl != null and picUrl != ''">
|
||
pic_url = #{picUrl},
|
||
</if>
|
||
<if test="videoUrl != null and videoUrl != ''">
|
||
video_url = #{videoUrl},
|
||
</if>
|
||
<if test="description != null and description != ''">
|
||
description = #{description},
|
||
</if>
|
||
<if test="gpsCode != null and gpsCode != ''">
|
||
gps_code = #{gpsCode},
|
||
</if>
|
||
<if test="onProject != null and onProject != ''">
|
||
on_project = #{onProject},
|
||
</if>
|
||
|
||
<!-- 负责人信息 -->
|
||
<if test="person != null and person != ''">
|
||
person = #{person},
|
||
</if>
|
||
<if test="personPhone != null and personPhone != ''">
|
||
person_phone = #{personPhone},
|
||
</if>
|
||
|
||
<!-- 更新时间和操作人(建议每次更新都设置) -->
|
||
update_time = now(),
|
||
<if test="updateBy != null and updateBy != ''">
|
||
update_by = #{updateBy},
|
||
</if>
|
||
</set>
|
||
<!-- 必须指定更新条件,以ma_id为主键 -->
|
||
WHERE ma_id = #{maId}
|
||
</update>
|
||
|
||
<update id="delDevice">
|
||
UPDATE ma_dev_info SET is_active = 0 where ma_id in
|
||
<foreach collection="array" item="maId" open="(" separator="," close=")">
|
||
#{maId}
|
||
</foreach>
|
||
</update>
|
||
|
||
<select id="deviceTree" resultType="com.bonus.material.devchange.domain.DeviceTreeBean">
|
||
SELECT mt.type_id as id,
|
||
mt.type_name as name,
|
||
mt.level,
|
||
mt.parent_id as pId
|
||
FROM ma_type mt
|
||
WHERE mt.level != '7'
|
||
<if test="name != null and name != ''">
|
||
AND mt.type_name LIKE CONCAT('%', #{name}, '%')
|
||
</if>
|
||
</select>
|
||
|
||
<select id="deviceCount" resultType="com.bonus.material.devchange.domain.DeviceCountBean">
|
||
SELECT count(distinct if(mdi.change_status = '1', mdi.ma_id, null)) as inStock,
|
||
count(distinct if(mdi.change_status = '2', mdi.ma_id, null)) as ownUse,
|
||
count(distinct if(mdi.change_status = '3', mdi.ma_id, null)) as share,
|
||
count(distinct if(mdi.change_status = '5', mdi.ma_id, null)) as underRepair
|
||
FROM ma_dev_info mdi
|
||
WHERE mdi.is_active = 1
|
||
</select>
|
||
|
||
<select id="getProperties" resultType="com.bonus.material.device.domain.vo.DevInfoPropertyVo">
|
||
select mtp.id AS id,
|
||
mdip.property_name propertyName,
|
||
mdip.property_value propertyValue,
|
||
mtp.property_value AS value,
|
||
mtp.input_type AS inputType
|
||
from ma_dev_info_properties mdip
|
||
LEFT JOIN ma_type_properties mtp ON mtp.id = mdip.property_id
|
||
where ma_id = #{maId}
|
||
</select>
|
||
|
||
<select id="deviceLocationSel" resultType="com.bonus.material.devchange.domain.MapBean">
|
||
SELECT '0' as `key`,
|
||
location as `value`
|
||
FROM ma_dev_info
|
||
WHERE is_active = 1
|
||
</select>
|
||
|
||
<select id="companySel" resultType="com.bonus.material.devchange.domain.MapBean">
|
||
SELECT
|
||
bci.id as `key`,
|
||
bci.company_name as `value`
|
||
FROM
|
||
bm_company_info bci
|
||
<where>
|
||
<if test="id != null">
|
||
and bci.id = #{id}
|
||
</if>
|
||
</where>
|
||
</select>
|
||
<select id="list" resultType="com.bonus.material.devchange.domain.MaDevInfo">
|
||
select mdi.ma_id AS maId,
|
||
mdi.type_id AS typeId,
|
||
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.up_down_status AS upDownStatus,
|
||
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.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,
|
||
mdi.unit AS unit,
|
||
mdq.next_check_time AS nextMaintenanceDate,
|
||
mdi.max_working_hours AS maxServiceLifeYears,
|
||
( SELECT COUNT(*) FROM cs_device_change_details WHERE dev_id = mdi.ma_id AND repair_time IS NOT NULL ) AS
|
||
repairCount,
|
||
(
|
||
SELECT
|
||
COUNT(*)
|
||
FROM
|
||
cs_device_change_details
|
||
WHERE
|
||
dev_id = mdi.ma_id
|
||
AND `status` IN ( 2, 3 )) AS usageCount,
|
||
sc.name AS province
|
||
from ma_dev_info mdi
|
||
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 mdi.entry_status = '1'
|
||
<if test="typeId != null and typeId != 0 ">
|
||
and (
|
||
mtv.mainGxId = #{typeId}
|
||
or mtv.childGxId = #{typeId}
|
||
or mtv.devCategoryId = #{typeId}
|
||
or mtv.devSubcategoryId = #{typeId}
|
||
or mtv.maxTypeId = #{typeId}
|
||
)
|
||
</if>
|
||
<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="province != null and province != ''">
|
||
and sc.area_code = #{province}
|
||
</if>
|
||
|
||
<if test="usingProjectId != null and usingProjectId != ''">
|
||
and jsp.pro_code = #{usingProjectId}
|
||
</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 >= #{minOriginalValue} and mdi.buy_price <= #{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>
|
||
<if test="status != null and status != ''">
|
||
AND mdi.change_status=#{status}
|
||
</if>
|
||
</where>
|
||
|
||
</select>
|
||
<select id="getFileList" resultType="com.bonus.material.devchange.domain.MaDevFile">
|
||
SELECT
|
||
id,
|
||
ma_id AS maId,
|
||
file_type AS fileType,
|
||
file_name AS fileName,
|
||
file_url AS fileUrl,
|
||
creator,
|
||
create_time AS createTime,
|
||
is_active AS isActive
|
||
FROM ma_dev_file
|
||
WHERE
|
||
-- 基础条件:逻辑未删除
|
||
is_active = 1
|
||
-- 可选条件:按设备ID筛选(如果需要根据maId查询,取消注释并传入参数)
|
||
<if test="maId != null">AND ma_id = #{maId}</if>
|
||
-- 可选条件:按文件类型筛选(如果需要,取消注释并传入参数)
|
||
<if test="fileType != null">AND file_type = #{fileType}</if>
|
||
ORDER BY
|
||
create_time DESC -- 按上传时间倒序,最新的文件在前
|
||
</select>
|
||
<select id="getDevice" resultType="com.bonus.material.devchange.domain.MaDevInfo">
|
||
select mdi.ma_id AS maId,
|
||
mdi.type_id AS typeId,
|
||
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.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,
|
||
mdi.unit AS unit,
|
||
mdq.next_check_time AS nextMaintenanceDate,
|
||
mdi.max_working_hours AS maxServiceLifeYears
|
||
from ma_dev_info mdi
|
||
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
|
||
<where>
|
||
mdi.is_active = '1' AND mdi.ma_id =#{maId}
|
||
</where>
|
||
</select>
|
||
<select id="getDeviceByMaIds" resultType="com.bonus.material.devchange.domain.MaDevInfo">
|
||
SELECT ma_id AS devId,
|
||
device_name AS name,
|
||
item_type_model As specificationModel,
|
||
code AS code
|
||
from ma_dev_info
|
||
WHERE ma_id IN
|
||
<foreach collection="array"
|
||
item="maId"
|
||
open="("
|
||
separator=","
|
||
close=")">
|
||
#{maId}
|
||
</foreach>
|
||
</select>
|
||
|
||
|
||
<select id="selectTotalDeviceCount" resultType="java.lang.Integer">
|
||
SELECT COUNT(1)
|
||
FROM ma_dev_info d
|
||
JOIN ma_type t ON d.type_id = t.type_id
|
||
</select>
|
||
|
||
</mapper>
|