1795 lines
81 KiB
XML
1795 lines
81 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.DevInfoMapper">
|
||
|
||
<resultMap type="com.bonus.material.device.domain.vo.DevInfoVo" id="DevInfoResult">
|
||
<result property="maId" column="ma_id" />
|
||
<result property="code" column="code" />
|
||
<result property="identifyCode" column="identify_code" />
|
||
<result property="typeId" column="type_id" />
|
||
<result property="maStatus" column="ma_status" />
|
||
<result property="leaseScope" column="lease_scope" />
|
||
<result property="location" column="location" />
|
||
<result property="provinceId" column="province_id" />
|
||
<result property="cityId" column="city_id" />
|
||
<result property="areaId" column="area_id" />
|
||
<result property="brand" column="brand" />
|
||
<result property="productionDate" column="production_date" />
|
||
<result property="workingHours" column="working_hours" />
|
||
<result property="dayLeasePrice" column="day_lease_price" />
|
||
<result property="jsMonthPrice" column="js_month_price" />
|
||
<result property="jsDayPrice" column="js_day_price" />
|
||
<result property="description" column="description" />
|
||
<result property="gpsCode" column="gps_code" />
|
||
<result property="ownCo" column="on_company" />
|
||
<result property="createTime" column="create_time" />
|
||
<result property="creator" column="creator" />
|
||
<result property="person" column="person" />
|
||
<result property="personPhone" column="person_phone" />
|
||
<result property="updateTime" column="update_time" />
|
||
<result property="updateBy" column="update_by" />
|
||
<result property="specification" column="specification" />
|
||
<result property="deposit" column="deposit" />
|
||
<result property="isOperator" column="is_operator" />
|
||
<result property="isActive" column="is_active" />
|
||
<result property="deviceName" column="device_name" />
|
||
<result property="groupName" column="group_name" />
|
||
<result property="companyName" column="company_name" />
|
||
</resultMap>
|
||
|
||
<sql id="selectDevInfoVo">
|
||
select ma_id, device_name, device_count, code, identify_code, type_id, ma_status, location,
|
||
province_id, city_id, area_id, brand, production_date, max_working_hours,
|
||
on_company, create_time,
|
||
creator, update_time, person, person_phone, update_by, is_active, update_time, update_by
|
||
from ma_dev_info
|
||
</sql>
|
||
|
||
<select id="selectDevInfoList" parameterType="com.bonus.material.device.domain.vo.DevInfoVo" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
t.picUrl,
|
||
t.proType,
|
||
t.mainGx,
|
||
t.childGx,
|
||
t.devCategory,
|
||
t.devSubcategory,
|
||
t.devName,
|
||
t.devType,
|
||
t.manageMode,
|
||
t.maId,
|
||
t.code,
|
||
t.identifyCode,
|
||
t.deviceName,
|
||
t.deviceCount,
|
||
t.typeId,
|
||
t.maStatus,
|
||
t.brand,
|
||
t.productionDate,
|
||
t.workingHours,
|
||
t.person,
|
||
t.personPhone,
|
||
t.createTime,
|
||
t.updateTime,
|
||
t.companyId,
|
||
t.companyName,
|
||
t.operateAddress,
|
||
t.dayLeasePrice
|
||
-- 注意:外层只查询业务需要的字段,去掉子查询中新增的辅助字段
|
||
FROM (
|
||
-- 第一个子查询:设备表数据
|
||
(
|
||
SELECT
|
||
IFNULL(mdf.file_url, bfi.url) AS picUrl,
|
||
mtv.proType,
|
||
mtv.mainGx,
|
||
mtv.childGx,
|
||
mtv.devCategory,
|
||
mtv.devSubcategory,
|
||
mtv.devName,
|
||
'0' AS devType,
|
||
'0' AS manageMode,
|
||
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.type_id AS typeId,
|
||
'1' AS maStatus,
|
||
d.brand AS brand,
|
||
d.production_date AS productionDate,
|
||
d.working_hours AS workingHours,
|
||
sd.leader AS person,
|
||
sd.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,
|
||
COALESCE(d.lease_price, mt.lease_price) AS dayLeasePrice,
|
||
-- 辅助字段:用于外层筛选(原表字段映射,无业务意义)
|
||
d.location AS location,
|
||
d.province_id AS provinceId,
|
||
d.city_id AS cityId,
|
||
d.area_id AS areaId,
|
||
mtv.maxTypeId AS maType,
|
||
null AS toolType,
|
||
c.company_name AS companyNameOrigin,
|
||
d.production_date AS productionDateOrigin,
|
||
d.working_hours AS workingHoursOrigin,
|
||
d.update_time AS updateTimeOrigin -- 用于外层时间筛选和排序
|
||
FROM
|
||
ma_dev_info d
|
||
LEFT JOIN sys_dept sd ON d.on_company = sd.dept_id
|
||
LEFT JOIN ma_type mt ON d.type_id = mt.type_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
|
||
LEFT JOIN bm_file_info bfi ON d.ma_id = bfi.model_id AND bfi.file_type = '0' AND bfi.task_type = '17'
|
||
LEFT JOIN ma_dev_file mdf ON d.ma_id = mdf.ma_id AND mdf.file_type = '1' AND mdf.is_active = '1'
|
||
WHERE
|
||
d.is_active = '1' AND d.ma_status='1'
|
||
AND d.up_down_status = '1'
|
||
<if test="maType != null and maType != ''">
|
||
AND mtv.maxTypeId = #{maType}
|
||
</if>
|
||
)
|
||
UNION ALL
|
||
-- 第二个子查询:工具表数据
|
||
(
|
||
SELECT
|
||
SUBSTRING_INDEX(tt.fileList, ',', 1) AS picUrl,
|
||
'' AS proType,
|
||
'' AS mainGx,
|
||
'' AS childGx,
|
||
'' AS devCategory,
|
||
'' AS devSubcategory,
|
||
tt.type_name AS devName,
|
||
'1' AS devType,
|
||
tt.manage_type AS manageMode,
|
||
tl.id AS maId,
|
||
tl.tool_code AS `code`,
|
||
tl.identify_code AS identifyCode,
|
||
tt1.type_name AS deviceName,
|
||
tl.available_num AS deviceCount,
|
||
tl.type_id AS typeId,
|
||
'1' AS maStatus,
|
||
'' AS brand,
|
||
tl.production_date AS productionDate,
|
||
0 AS workingHours,
|
||
sd.leader AS person,
|
||
sd.phone AS personPhone,
|
||
tl.create_time AS createTime,
|
||
tl.update_time AS updateTime,
|
||
tl.company_id AS companyId,
|
||
sd.dept_name AS companyName,
|
||
c.operate_address AS operateAddress,
|
||
COALESCE(tl.lease_price, tt.lease_price) AS dayLeasePrice,
|
||
-- 辅助字段:与设备表对齐(筛选条件需要,无则设为NULL/''/0)
|
||
NULL AS location,
|
||
NULL AS provinceId,
|
||
NULL AS cityId,
|
||
NULL AS areaId,
|
||
null AS maType, -- 工具表的maType对应tt4.type_id
|
||
tt4.type_id AS toolType, -- 工具表的maType对应tt4.type_id
|
||
c.company_name AS companyNameOrigin,
|
||
tl.production_date AS productionDateOrigin,
|
||
0 AS workingHoursOrigin, -- 工具表工时固定为0
|
||
tl.update_time AS updateTimeOrigin -- 用于外层时间筛选和排序
|
||
FROM
|
||
tool_ledger tl
|
||
LEFT JOIN sys_dept sd ON tl.company_id = sd.dept_id
|
||
INNER JOIN tool_type tt ON tt.type_id = tl.type_id
|
||
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
|
||
INNER JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
|
||
INNER JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
|
||
INNER JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
|
||
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
|
||
WHERE
|
||
tl.up_down_status = '1' AND tl.available_num >0
|
||
<if test="toolType != null and toolType != ''">
|
||
AND tt4.type_id = #{toolType}
|
||
</if>
|
||
)
|
||
) t
|
||
-- 外层筛选条件:所有动态和固定筛选条件集中在这里
|
||
WHERE 1=1
|
||
<if test="code != null and code != ''">
|
||
AND t.code = #{code}
|
||
</if>
|
||
<if test="deviceName != null and deviceName != ''">
|
||
AND t.deviceName LIKE CONCAT('%', #{deviceName}, '%')
|
||
</if>
|
||
<if test="leaseScope != null ">
|
||
AND t.leaseScope = #{leaseScope}
|
||
</if>
|
||
<if test="location != null and location != ''">
|
||
AND t.location = #{location}
|
||
</if>
|
||
<if test="provinceId != null and provinceId != ''">
|
||
AND t.provinceId = #{provinceId}
|
||
</if>
|
||
<if test="cityId != null and cityId != ''">
|
||
AND t.cityId = #{cityId}
|
||
</if>
|
||
<if test="areaId != null and areaId != ''">
|
||
AND t.areaId = #{areaId}
|
||
</if>
|
||
<if test="brand != null and brand != ''">
|
||
AND t.brand = #{brand}
|
||
</if>
|
||
-- 2. 设备年龄筛选(工具表无生产时间则自动过滤,不影响)
|
||
<if test="ageMin != null and ageMax != null">
|
||
AND TIMESTAMPDIFF(YEAR, t.productionDateOrigin, NOW()) >= #{ageMin}
|
||
AND TIMESTAMPDIFF(YEAR, t.productionDateOrigin, NOW()) <= #{ageMax}
|
||
</if>
|
||
<if test="ageMin == null and ageMax != null">
|
||
AND TIMESTAMPDIFF(YEAR, t.productionDateOrigin, NOW()) <= #{ageMax}
|
||
</if>
|
||
-- 3. 工时筛选(工具表工时为0,可根据需求调整)
|
||
<if test="workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != ''">
|
||
AND t.workingHoursOrigin >= #{workingHoursMin}
|
||
AND t.workingHoursOrigin <= #{workingHoursMax}
|
||
</if>
|
||
-- 4. 其他基础筛选
|
||
<if test="description != null and description != ''">
|
||
AND t.description = #{description}
|
||
</if>
|
||
<if test="gpsCode != null and gpsCode != ''">
|
||
AND t.gpsCode = #{gpsCode}
|
||
</if>
|
||
<if test="companyId != null and companyId != ''">
|
||
AND t.companyId = #{companyId}
|
||
</if>
|
||
<if test="specification != null ">
|
||
AND t.specification = #{specification}
|
||
</if>
|
||
<if test="deposit != null ">
|
||
AND t.deposit = #{deposit}
|
||
</if>
|
||
-- 5. 时间范围筛选
|
||
<if test="startTime != null and endTime != null">
|
||
AND t.updateTimeOrigin BETWEEN #{startTime} AND #{endTime}
|
||
</if>
|
||
-- 6. 关键字模糊筛选(覆盖设备和工具的所有关键字段)
|
||
<if test="keyWord != null and keyWord != ''">
|
||
AND
|
||
(
|
||
-- 设备表关键字段
|
||
LOCATE(#{keyWord}, t.mainGx) > 0
|
||
OR LOCATE(#{keyWord}, t.childGx) > 0
|
||
OR LOCATE(#{keyWord}, t.devCategory) > 0
|
||
OR LOCATE(#{keyWord}, t.devSubcategory) > 0
|
||
OR LOCATE(#{keyWord}, t.devName) > 0
|
||
OR LOCATE(#{keyWord}, t.companyNameOrigin) > 0
|
||
OR LOCATE(#{keyWord}, t.deviceName) > 0
|
||
OR LOCATE(#{keyWord}, t.identifyCode) > 0
|
||
-- 工具表关键字段(复用设备表字段别名,已在子查询中映射)
|
||
OR LOCATE(#{keyWord}, t.devName) > 0 -- 对应tt.type_name
|
||
OR LOCATE(#{keyWord}, t.deviceName) > 0 -- 对应tt1.type_name
|
||
OR LOCATE(#{keyWord}, t.companyName) > 0 -- 对应sd.dept_name
|
||
)
|
||
</if>
|
||
|
||
<if test="updateTimeOrderBy == null">
|
||
ORDER BY t.updateTime DESC
|
||
</if>
|
||
<if test="updateTimeOrderBy != null">
|
||
|
||
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'ASC'">
|
||
ORDER BY
|
||
t.updateTime ASC
|
||
</if>
|
||
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'DESC'">
|
||
ORDER BY
|
||
t.updateTime DESC
|
||
</if>
|
||
</if>
|
||
|
||
|
||
</select>
|
||
|
||
<select id="selectDevInfoHotList" parameterType="com.bonus.material.device.domain.vo.DevInfoVo" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
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.type_id as typeId,
|
||
mt4.type_name as typeName,
|
||
d.ma_status as maStatus,
|
||
d.brand as brand,
|
||
d.production_date as productionDate,
|
||
d.working_hours as workingHours,
|
||
d.person as person,
|
||
d.person_phone as personPhone,
|
||
d.on_company as companyId,
|
||
sd.dept_name as companyName,
|
||
c.operate_address as operateAddress,
|
||
d.create_time as createTime,
|
||
mt3.type_id as thirdId,
|
||
mt3.type_name as thirdName,
|
||
mt2.type_id as secondId,
|
||
mt2.type_name as secondName,
|
||
mt1.type_id as firstId,
|
||
mt1.type_name as firstName
|
||
FROM
|
||
ma_dev_info d
|
||
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 mt4 ON mt4.type_id = d.type_id and mt4.del_flag = '0'
|
||
LEFT JOIN ma_type mt3 ON mt3.type_id = mt4.parent_id and mt3.del_flag = '0'
|
||
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id and mt2.del_flag = '0'
|
||
LEFT JOIN ma_type mt1 ON mt1.type_id = mt2.parent_id and mt1.del_flag = '0'
|
||
where
|
||
d.is_active='1'
|
||
and d.ma_status = '2'
|
||
<if test="deviceName != null and deviceName != ''">
|
||
and d.device_name like concat('%',#{deviceName},'%')
|
||
</if>
|
||
order by d.create_time desc
|
||
</select>
|
||
|
||
<select id="selectDevInfoByMaId" parameterType="Long" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT d.ma_id as maId,
|
||
d.code as code,
|
||
d.buy_price as buyPrice,
|
||
d.device_type as deviceType,
|
||
'0' AS devType,
|
||
d.item_type_model as itemTypeModel,
|
||
identify_code as identifyCode,
|
||
d.device_name as deviceName,
|
||
d.device_count as deviceCount,
|
||
d.type_id as typeId,
|
||
d.check_date as checkDate,
|
||
d.check_cycle as checkCycle,
|
||
mtv.proType,
|
||
mtv.mainGx,
|
||
mtv.childGx,
|
||
mtv.devCategory,
|
||
mtv.devSubcategory,
|
||
mtv.devName,
|
||
mtv.unit_name,
|
||
mt4.type_name as typeName,
|
||
mt4.unit_name as unitName,
|
||
mt4.manage_type as manageType,
|
||
mt4.maintenance_alarm_day,
|
||
d.ma_status as maStatus,
|
||
d.brand as brand,
|
||
d.production_date as productionDate,
|
||
d.max_working_hours as workingHours,
|
||
sd.leader as person,
|
||
sd.phone as personPhone,
|
||
d.on_company as companyId,
|
||
sd.dept_name as companyName,
|
||
c.operate_address as operateAddress,
|
||
mt3.type_id as thirdId,
|
||
mt3.type_name as thirdName,
|
||
mt2.type_id as secondId,
|
||
mt2.type_name as secondName,
|
||
mt1.type_id as firstId,
|
||
mt1.type_name as firstName,
|
||
GROUP_CONCAT(CONCAT(mt1.type_name, '/', mt2.type_name, '/', mt3.type_name)) AS groupName,
|
||
IFNULL(h.search_num, 0) as searchNum,
|
||
d.create_time as createTime,
|
||
d.update_time as updateTime,
|
||
d.expiration_time,
|
||
d.entry_status,
|
||
COALESCE(d.lease_price, mt4.lease_price) as dayLeasePrice
|
||
FROM ma_dev_info d
|
||
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_hot_search h ON d.ma_id = h.ma_id
|
||
INNER JOIN ma_type_view mtv ON mtv.typeId = d.type_id
|
||
LEFT JOIN ma_type mt4 ON mt4.type_id = d.type_id and mt4.del_flag = '0'
|
||
LEFT JOIN ma_type mt3 ON mt3.type_id = mt4.parent_id and mt3.del_flag = '0'
|
||
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id and mt2.del_flag = '0'
|
||
LEFT JOIN ma_type mt1 ON mt1.type_id = mt2.parent_id and mt1.del_flag = '0'
|
||
where d.is_active = '1'
|
||
and d.ma_id = #{maId}
|
||
</select>
|
||
|
||
<select id="getFilesByMaId" parameterType="Long" resultType="com.bonus.common.biz.domain.SysFileInfo">
|
||
SELECT s.dic_id, s.file_name,s.file_url
|
||
from ma_dev_info d
|
||
left join sys_file_info s on d.ma_id = s.model_id
|
||
WHERE d.ma_id = #{maId} and d.is_active='1' and s.dic_id in (0,1,2,3)
|
||
</select>
|
||
|
||
<insert id="insertDevInfo" parameterType="com.bonus.material.device.domain.DevInfo" useGeneratedKeys="true" keyProperty="maId">
|
||
insert into ma_dev_info
|
||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||
<if test="deviceName != null and deviceName != '' ">device_name,</if>
|
||
<if test="deviceType != null">device_type,</if>
|
||
<if test="deviceCount != null">device_count,</if>
|
||
<if test="code != null and code != '' ">code,</if>
|
||
<if test="identifyCode != null and identifyCode != '' ">identify_code,</if>
|
||
<if test="typeId != null and typeId != ''">type_id,</if>
|
||
<if test="maStatus != null">ma_status,</if>
|
||
<if test="leaseScope != null and leaseScope != ''">lease_scope,</if>
|
||
<if test="location != null and location != ''" >location,</if>
|
||
<if test="provinceId != null and provinceId != ''">province_id,</if>
|
||
<if test="cityId != null and cityId != ''">city_id,</if>
|
||
<if test="areaId != null and areaId != ''">area_id,</if>
|
||
<if test="brand != null and brand != ''">brand,</if>
|
||
<if test="productionDate != null">production_date,</if>
|
||
<if test="workingHours != null and workingHours != ''">working_hours,</if>
|
||
<if test="jsMonthPrice != null and jsMonthPrice != ''">js_month_price,</if>
|
||
<if test="jsDayPrice != null and jsDayPrice != ''">js_day_price,</if>
|
||
<if test="description != null and description != ''">`description`,</if>
|
||
<if test="gpsCode != null and gpsCode != ''">gps_code,</if>
|
||
<if test="companyId != null and companyId != ''" >on_company,</if>
|
||
<if test="person != null and person != ''">person,</if>
|
||
<if test="personPhone != null and personPhone != ''">person_phone,</if>
|
||
create_time,
|
||
<if test="creator != null and creator != ''">creator,</if>
|
||
update_time,
|
||
<if test="updateBy != null and updateBy != ''">update_by,</if>
|
||
<if test="specification != null and specification != ''">specification,</if>
|
||
<if test="deposit != null and deposit != ''">deposit,</if>
|
||
<if test="isOperator != null and isOperator != ''">is_operator,</if>
|
||
<if test="isActive != null and isActive != ''">is_active,</if>
|
||
<if test="updateBy != null and updateBy != ''">update_by,</if>
|
||
<if test="checkDate != null">check_date,</if>
|
||
<if test="checkCycle != null">check_cycle,</if>
|
||
<if test="buyPrice != null">buy_price,</if>
|
||
<if test="itemTypeModel != null">item_type_model,</if>
|
||
<if test="changeStatus != null">change_status,</if>
|
||
<if test="expirationTime != null">expiration_time,</if>
|
||
<if test="entryStatus != null">entry_status,</if>
|
||
<if test="upDownStatus != null">up_down_status,</if>
|
||
</trim>
|
||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
|
||
<if test="deviceType != null">#{deviceType},</if>
|
||
<if test="deviceCount != null">#{deviceCount},</if>
|
||
<if test="code != null and code != ''">#{code},</if>
|
||
<if test="identifyCode != null and identifyCode != ''">#{identifyCode},</if>
|
||
<if test="typeId != null and typeId != ''">#{typeId},</if>
|
||
<if test="maStatus != null">#{maStatus},</if>
|
||
<if test="leaseScope != null and leaseScope != ''">#{leaseScope},</if>
|
||
<if test="location != null and location != ''">#{location},</if>
|
||
<if test="provinceId != null and provinceId != ''">#{provinceId},</if>
|
||
<if test="cityId != null and cityId != ''">#{cityId},</if>
|
||
<if test="areaId != null and areaId != ''">#{areaId},</if>
|
||
<if test="brand != null and brand != ''">#{brand},</if>
|
||
<if test="modelName != null and modelName != ''">#{modelName},</if>
|
||
<if test="productionDate != null">#{productionDate},</if>
|
||
<if test="workingHours != null and workingHours != ''">#{workingHours},</if>
|
||
<if test="picUrl != null and picUrl != ''">#{picUrl},</if>
|
||
<if test="jsMonthPrice != null and jsMonthPrice != ''">#{jsMonthPrice},</if>
|
||
<if test="jsDayPrice != null and jsDayPrice != ''">#{jsDayPrice},</if>
|
||
<if test="description != null and description != ''">#{description},</if>
|
||
<if test="gpsCode != null and gpsCode != ''">#{gpsCode},</if>
|
||
<if test="companyId != null and companyId != ''">#{companyId},</if>
|
||
<if test="person != null and person != ''">#{person},</if>
|
||
<if test="personPhone != null and personPhone != ''">#{personPhone},</if>
|
||
now(),
|
||
<if test="creator != null and creator != ''">#{creator},</if>
|
||
now(),
|
||
<if test="updateBy != null and updateBy != ''">#{update_by},</if>
|
||
<if test="specification != null and specification != ''">#{specification},</if>
|
||
<if test="deposit != null and deposit != ''">#{deposit},</if>
|
||
<if test="isOperator != null and isOperator != ''">#{isOperator},</if>
|
||
<if test="isActive != null and isActive != ''">#{isActive},</if>
|
||
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
|
||
<if test="ownId != null">#{ownId},</if>
|
||
<if test="checkDate != null">#{checkDate},</if>
|
||
<if test="checkCycle != null">#{checkCycle},</if>
|
||
<if test="isZone != null">#{isZone},</if>
|
||
<if test="zoneId != null">#{zoneId},</if>
|
||
<if test="buyPrice != null">#{buyPrice},</if>
|
||
<if test="itemTypeModel != null">#{itemTypeModel},</if>
|
||
|
||
<if test="changeStatus != null">#{changeStatus},</if>
|
||
<if test="expirationTime != null">#{expirationTime},</if>
|
||
<if test="entryStatus != null">#{entryStatus},</if>
|
||
<if test="upDownStatus != null">#{upDownStatus},</if>
|
||
</trim>
|
||
</insert>
|
||
|
||
<insert id="insertLon">
|
||
insert into gps_real_info
|
||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||
<if test="dto.gpsCode != null and dto.gpsCode != ''">gps_code,</if>
|
||
<if test="dto.lon != null and dto.lon !=''">lon,</if>
|
||
<if test="dto.lat != null and dto.lat != ''">lat,</if>
|
||
</trim>
|
||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||
<if test="dto.gpsCode != null and dto.gpsCode != ''">#{dto.gpsCode},</if>
|
||
<if test="dto.lon != null and dto.lon !=''">#{dto.lon},</if>
|
||
<if test="dto.lat != null and dto.lat != ''">#{dto.lat},</if>
|
||
</trim>
|
||
</insert>
|
||
|
||
<update id="updateDevInfo" parameterType="com.bonus.material.device.domain.DevInfo">
|
||
update ma_dev_info
|
||
<trim prefix="SET" suffixOverrides=",">
|
||
<if test="code != null and code != '' ">code = #{code},</if>
|
||
<if test="identifyCode != null and identifyCode != '' ">identify_code = #{identifyCode},</if>
|
||
<if test="deviceName != null and deviceName != '' ">device_name = #{deviceName},</if>
|
||
<if test="deviceCount != null">device_count = #{deviceCount},</if>
|
||
<if test="typeId != null">type_id = #{typeId},</if>
|
||
<if test="maStatus != null">ma_status = #{maStatus},</if>
|
||
<if test="leaseScope != null">lease_scope = #{leaseScope},</if>
|
||
<if test="location != null">location = #{location},</if>
|
||
<if test="provinceId != null">province_id = #{provinceId},</if>
|
||
<if test="cityId != null">city_id = #{cityId},</if>
|
||
<if test="areaId != null">area_id = #{areaId},</if>
|
||
<if test="brand != null">brand = #{brand},</if>
|
||
<if test="productionDate != null">production_date = #{productionDate},</if>
|
||
<if test="workingHours != null">working_hours = #{workingHours},</if>
|
||
<if test="jsMonthPrice != null">js_month_price = #{jsMonthPrice},</if>
|
||
<if test="jsDayPrice != null">js_day_price = #{jsDayPrice},</if>
|
||
<if test="description != null">`description` = #{description},</if>
|
||
<if test="gpsCode != null">gps_code = #{gpsCode},</if>
|
||
<if test="companyId != null">on_company = #{companyId},</if>
|
||
<if test="person != null">person = #{person},</if>
|
||
<if test="personPhone != null">person_phone = #{personPhone},</if>
|
||
<if test="specification != null">specification = #{specification},</if>
|
||
<if test="deposit != null">deposit = #{deposit},</if>
|
||
<if test="isOperator != null">is_active = #{isOperator},</if>
|
||
<if test="checkDate != null">check_date = #{checkDate},</if>
|
||
<if test="checkCycle != null">check_cycle = #{checkCycle},</if>
|
||
<if test="isZone != null">is_zone = #{isZone},</if>
|
||
<if test="zoneId != null">zone_id = #{zoneId},</if>
|
||
<if test="buyPrice != null">buy_price = #{buyPrice},</if>
|
||
<if test="itemTypeModel != null">item_type_model = #{itemTypeModel},</if>
|
||
|
||
<if test="expirationTime != null">expiration_time = #{expirationTime},</if>
|
||
|
||
update_time = now()
|
||
</trim>
|
||
where ma_id = #{maId}
|
||
</update>
|
||
|
||
<update id="deleteDevInfoByMaId" >
|
||
update ma_dev_info set is_active = '0'
|
||
where ma_id = #{maId,jdbcType=BIGINT} and is_active = '1' and ma_status != #{statusCode,jdbcType=INTEGER}
|
||
</update>
|
||
|
||
<update id="deleteDevInfoByMaIds" parameterType="String">
|
||
update ma_dev_info set is_active='0' where ma_id in
|
||
<foreach item="maId" collection="maIds" open="(" separator="," close=")">
|
||
#{maId}
|
||
</foreach>
|
||
</update>
|
||
|
||
<select id="selectUserCollectByUserId" parameterType="Long" resultType="com.bonus.common.biz.domain.UserCollect">
|
||
select id, user_id, ma_id, create_time from ma_user_collect
|
||
where user_id = #{userId}
|
||
</select>
|
||
|
||
<select id="getHotSearchCountByMaId" resultType="Integer">
|
||
select count(1) from ma_hot_search
|
||
where ma_id = #{maId}
|
||
</select>
|
||
|
||
<insert id="insertHotSearch">
|
||
INSERT INTO ma_hot_search (ma_id, search_num, create_time)
|
||
VALUES (#{maId}, 1, now())
|
||
</insert>
|
||
|
||
<update id="updateHotSearchByMaId" parameterType="Long">
|
||
update ma_hot_search
|
||
set search_num = search_num + 1,
|
||
update_time = now()
|
||
where ma_id = #{maId}
|
||
</update>
|
||
|
||
<update id="updateUpDown">
|
||
<if test="maIds != null and maIds.size() > 0">
|
||
<choose>
|
||
<when test="maIds.size() == 1">
|
||
<!-- 单个ID更新 -->
|
||
update ma_dev_info
|
||
set ma_status = #{maStatus} ,update_time = now()
|
||
where ma_id = #{maIds[0]}
|
||
</when>
|
||
<otherwise>
|
||
<!-- 批量更新 -->
|
||
update ma_dev_info
|
||
set ma_status = #{maStatus},update_time = now()
|
||
where ma_id in
|
||
<foreach collection="maIds" item="maId" open="(" separator="," close=")">
|
||
#{maId}
|
||
</foreach>
|
||
</otherwise>
|
||
</choose>
|
||
</if>
|
||
</update>
|
||
<update id="upMaStatus">
|
||
update ma_dev_info set ma_status = #{maStatus} where ma_id = #{maId} and is_active = 1
|
||
</update>
|
||
<update id="updateDevInfoIsQc">
|
||
update ma_dev_info set is_qc = 1 where ma_id = #{maId} and is_active = 1
|
||
</update>
|
||
<update id="updateDevInfoIsSafeBook">
|
||
update ma_dev_info set is_safe_book = 1 where ma_id = #{maId} and is_active = 1
|
||
</update>
|
||
|
||
<select id="getSysDic" resultType="com.bonus.common.biz.domain.SysDic">
|
||
select
|
||
dict_code AS id,p_id,code,`name`,description,`value`,sort,`level`,status,create_time,creator
|
||
from sys_dict_data
|
||
</select>
|
||
|
||
<select id="getSysDicById" resultType="com.bonus.common.biz.domain.SysDic">
|
||
select
|
||
id,p_id,code,`name`,description,`value`,sort,`level`,status,create_time,creator
|
||
from sys_dict_data
|
||
where id = #{id}
|
||
</select>
|
||
|
||
<select id="getBaseAddress" resultType="com.bonus.common.biz.domain.BaseAddress">
|
||
select id,name,code from base_address
|
||
</select>
|
||
|
||
<select id="getBaseAddressById" resultType="String">
|
||
select name from base_address where id = #{id}
|
||
</select>
|
||
|
||
<select id="selectDevInfoLists" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
select
|
||
d.*,
|
||
mt4.type_name as typeName,mt4.unit_name as unitName,
|
||
mt3.type_id as thirdId,mt3.type_name as thirdName,
|
||
mt2.type_id as secondId,mt2.type_name as secondName,
|
||
mt1.type_id as firstId,mt1.type_name as firstName
|
||
from
|
||
ma_dev_info d
|
||
left join ma_up_off u on d.ma_id = u.ma_id
|
||
left join ma_type mt4 ON mt4.type_id = d.type_id and mt4.del_flag = '0'
|
||
left join ma_type mt3 ON mt3.type_id = mt4.parent_id and mt3.del_flag = '0'
|
||
left join ma_type mt2 ON mt2.type_id = mt3.parent_id and mt2.del_flag = '0'
|
||
left join ma_type mt1 ON mt1.type_id = mt2.parent_id and mt1.del_flag = '0'
|
||
<where>
|
||
<if test="maId != null "> and d.ma_id = #{maId}</if>
|
||
<if test="code != null and code != ''"> and d.code = #{code}</if>
|
||
<if test="deviceName != null and deviceName != ''">
|
||
and d.device_name like concat('%',#{deviceName},'%')
|
||
</if>
|
||
<if test="typeId != null">
|
||
and d.type_id = #{typeId}
|
||
</if>
|
||
<if test="maStatus != null"> and d.ma_status = #{maStatus}</if>
|
||
<if test="leaseScope != null "> and d.lease_scope = #{leaseScope}</if>
|
||
<if test="areaId != null and areaId != ''"> and d.area_id = #{areaId}</if>
|
||
<if test="brand != null and brand != ''"> and d.brand = #{brand}</if>
|
||
<if test="companyId != null and companyId !=''"> and d.on_company = #{companyId}</if>
|
||
<if test="startTime != null and endTime !='' and endTime != null and endTime !=''">
|
||
and d.update_time between #{startTime} and #{endTime}
|
||
</if>
|
||
<if test="keyWord != null and keyWord != ''">
|
||
and (
|
||
locate(#{keyWord},c.company_name) > 0
|
||
or locate(#{keyWord},d.ma_id) > 0
|
||
or locate(#{keyWord},d.specification) > 0
|
||
or locate(#{keyWord},d.description) > 0
|
||
)
|
||
</if>
|
||
and d.on_company = #{companyId}
|
||
and d.is_active = '1'
|
||
</where>
|
||
ORDER BY d.create_time desc
|
||
</select>
|
||
|
||
<select id="selectDevInfoProperties" resultType="com.bonus.material.device.domain.vo.DevInfoPropertyVo">
|
||
select property_name as propertyName,
|
||
property_value as propertyValue
|
||
from ma_dev_info_properties
|
||
where ma_id = #{maId}
|
||
</select>
|
||
|
||
<delete id="deleteDevInfoProperties">
|
||
delete from ma_dev_info_properties where ma_id = #{maId}
|
||
</delete>
|
||
|
||
<delete id="batchDeleteDevInfoProperties">
|
||
delete from ma_dev_info_properties where ma_id in
|
||
<foreach item="maId" collection="maIds" open="(" separator="," close=")">
|
||
#{maId}
|
||
</foreach>
|
||
</delete>
|
||
|
||
<insert id="insertDevInfoProperties">
|
||
insert into
|
||
ma_dev_info_properties(ma_id,property_id, property_name, property_value, create_time)
|
||
values
|
||
<foreach collection="list" item="item" index="index" separator=",">
|
||
(
|
||
#{maId},
|
||
#{item.id},
|
||
#{item.propertyName},
|
||
#{item.propertyValue},
|
||
now()
|
||
)
|
||
</foreach>
|
||
</insert>
|
||
|
||
<select id="selectCompanyList" resultType="com.bonus.common.biz.domain.BmCompanyInfo">
|
||
SELECT
|
||
sd.dept_id as companyId,
|
||
sd.dept_name as companyName,
|
||
sd.dept_abbreviation as companyAbbreviationName,
|
||
sd.is_show as isShow,
|
||
b.operate_address as operateAddress
|
||
FROM
|
||
sys_dept sd
|
||
LEFT JOIN bm_company_info b ON sd.dept_id = b.company_id
|
||
WHERE sd.del_flag = 0
|
||
<if test="companyId != null">
|
||
and sd.dept_id = #{companyId}
|
||
</if>
|
||
<if test="companyName != null and companyName != ''">
|
||
and sd.dept_name like concat('%',#{companyName},'%')
|
||
</if>
|
||
and sd.dept_name !='省公司'
|
||
</select>
|
||
|
||
<select id="getMaCountByCompany" resultType="com.bonus.common.biz.domain.BmCompanyInfo">
|
||
select on_company as companyId,count(1) as maCount from ma_dev_info
|
||
where ma_status=2
|
||
group by on_company
|
||
</select>
|
||
|
||
<select id="getBookCar" resultType="com.bonus.material.book.domain.BookCarInfoDto">
|
||
SELECT
|
||
ma_id as maId,
|
||
order_user as orderUser,
|
||
order_company as orderCompany
|
||
FROM
|
||
book_car_detail
|
||
WHERE
|
||
order_user = #{userId}
|
||
AND ma_id = #{maId}
|
||
AND order_status = '0'
|
||
</select>
|
||
|
||
<insert id="insertDraft" parameterType="com.bonus.material.device.domain.DevInfo" useGeneratedKeys="true" keyProperty="maId">
|
||
insert into ma_dev_info
|
||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||
<if test="deviceName != null and deviceName != '' ">device_name,</if>
|
||
<if test="deviceCount != null">device_count,</if>
|
||
<if test="code != null and code != '' ">code,</if>
|
||
<if test="identifyCode != null and identifyCode != '' ">identify_code,</if>
|
||
<if test="typeId != null and typeId != ''">type_id,</if>
|
||
<if test="maStatus != null">ma_status,</if>
|
||
<if test="leaseScope != null and leaseScope != ''">lease_scope,</if>
|
||
<if test="location != null and location != ''" >location,</if>
|
||
<if test="provinceId != null and provinceId != ''">province_id,</if>
|
||
<if test="cityId != null and cityId != ''">city_id,</if>
|
||
<if test="areaId != null and areaId != ''">area_id,</if>
|
||
<if test="brand != null and brand != ''">brand,</if>
|
||
<if test="productionDate != null">production_date,</if>
|
||
<if test="workingHours != null and workingHours != ''">working_hours,</if>
|
||
<if test="jsMonthPrice != null and jsMonthPrice != ''">js_month_price,</if>
|
||
<if test="jsDayPrice != null and jsDayPrice != ''">js_day_price,</if>
|
||
<if test="description != null and description != ''">`description`,</if>
|
||
<if test="gpsCode != null and gpsCode != ''">gps_code,</if>
|
||
<if test="companyId != null and companyId != ''" >on_company,</if>
|
||
<if test="person != null and person != ''">person,</if>
|
||
<if test="personPhone != null and personPhone != ''">person_phone,</if>
|
||
create_time,
|
||
<if test="creator != null and creator != ''">creator,</if>
|
||
update_time,
|
||
<if test="updateBy != null and updateBy != ''">update_by,</if>
|
||
<if test="specification != null and specification != ''">specification,</if>
|
||
<if test="deposit != null and deposit != ''">deposit,</if>
|
||
<if test="isOperator != null and isOperator != ''">is_operator,</if>
|
||
is_active,
|
||
<if test="updateBy != null and updateBy != ''">update_by,</if>
|
||
<if test="checkDate != null">check_date,</if>
|
||
<if test="checkCycle != null">check_cycle,</if>
|
||
</trim>
|
||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
|
||
<if test="deviceWeight != null and deviceWeight != ''">#{deviceWeight},</if>
|
||
<if test="deviceCount != null">#{deviceCount},</if>
|
||
<if test="code != null and code != ''">#{code},</if>
|
||
<if test="identifyCode != null and identifyCode != ''">#{identifyCode},</if>
|
||
<if test="typeId != null and typeId != ''">#{typeId},</if>
|
||
<if test="maStatus != null">#{maStatus},</if>
|
||
<if test="leaseScope != null and leaseScope != ''">#{leaseScope},</if>
|
||
<if test="location != null and location != ''">#{location},</if>
|
||
<if test="provinceId != null and provinceId != ''">#{provinceId},</if>
|
||
<if test="cityId != null and cityId != ''">#{cityId},</if>
|
||
<if test="areaId != null and areaId != ''">#{areaId},</if>
|
||
<if test="brand != null and brand != ''">#{brand},</if>
|
||
<if test="modelName != null and modelName != ''">#{modelName},</if>
|
||
<if test="productionDate != null">#{productionDate},</if>
|
||
<if test="workingHours != null and workingHours != ''">#{workingHours},</if>
|
||
<if test="picUrl != null and picUrl != ''">#{picUrl},</if>
|
||
<if test="jsMonthPrice != null and jsMonthPrice != ''">#{jsMonthPrice},</if>
|
||
<if test="jsDayPrice != null and jsDayPrice != ''">#{jsDayPrice},</if>
|
||
<if test="description != null and description != ''">#{description},</if>
|
||
<if test="gpsCode != null and gpsCode != ''">#{gpsCode},</if>
|
||
<if test="companyId != null and companyId != ''">#{companyId},</if>
|
||
<if test="person != null and person != ''">#{person},</if>
|
||
<if test="personPhone != null and personPhone != ''">#{personPhone},</if>
|
||
now(),
|
||
<if test="creator != null and creator != ''">#{creator},</if>
|
||
now(),
|
||
<if test="updateBy != null and updateBy != ''">#{update_by},</if>
|
||
<if test="specification != null and specification != ''">#{specification},</if>
|
||
<if test="deposit != null and deposit != ''">#{deposit},</if>
|
||
<if test="isOperator != null and isOperator != ''">#{isOperator},</if>
|
||
1,
|
||
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
|
||
<if test="ownId != null and ownId != ''">#{ownId},</if>
|
||
<if test="checkDate != null">#{checkDate},</if>
|
||
<if test="checkCycle != null">#{checkCycle}</if>
|
||
</trim>
|
||
</insert>
|
||
|
||
<select id="getMaStatusByMaId" resultType="com.bonus.material.device.domain.DevInfo">
|
||
select
|
||
mdi.ma_status,mdi.device_count,mdi.person_phone
|
||
from
|
||
ma_dev_info mdi
|
||
where
|
||
mdi.ma_id = #{maId}
|
||
</select>
|
||
|
||
<select id="selectCompany" resultType="java.lang.Integer">
|
||
select COUNT(1) from ma_dev_info where ma_status = '2' and on_company = #{companyId}
|
||
</select>
|
||
|
||
<select id="getLeaseList" resultType="com.bonus.material.device.domain.vo.LeaseVo">
|
||
SELECT
|
||
m.order_id as orderId,
|
||
m.ma_id as maId,
|
||
m1.`code` as orderCode,
|
||
su.nick_name as leaseName,
|
||
m.rent_begin_time as leaseStartTime,
|
||
m.rent_end_time as leaseEndTime,
|
||
m.costs as leasePrice
|
||
FROM
|
||
ma_order_details m
|
||
LEFT JOIN ma_order_info m1 ON m.order_id = m1.order_id
|
||
LEFT JOIN sys_user su ON m1.buyer_id = su.user_id
|
||
WHERE
|
||
m.ma_id = #{maId}
|
||
</select>
|
||
|
||
<select id="getCompanyUpNum" resultType="java.lang.Integer">
|
||
SELECT
|
||
IFNULL(SUM( h.search_num ), 0) AS companyVisitNum
|
||
FROM
|
||
ma_hot_search h
|
||
LEFT JOIN ma_dev_info m ON h.ma_id = m.ma_id
|
||
AND m.is_active = '1'
|
||
WHERE
|
||
m.ma_status = '2'
|
||
AND m.on_company = #{companyId}
|
||
</select>
|
||
|
||
<select id="selectTaskNumByMonth" resultType="java.lang.String">
|
||
SELECT SUBSTRING(code, - 4) as code
|
||
FROM ma_dev_info
|
||
WHERE DATE_FORMAT(create_time, '%y%m') = DATE_FORMAT(#{date}, '%y%m')
|
||
ORDER BY create_time DESC LIMIT 1
|
||
</select>
|
||
|
||
<select id="selectCompanyById" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
select
|
||
company_id as companyId,
|
||
company_name as companyName,
|
||
create_time as companyCreateTime
|
||
from bm_company_info
|
||
where company_id = #{companyId}
|
||
</select>
|
||
<select id="getCodeByMaId" resultType="java.lang.String">
|
||
select code from ma_dev_info where ma_id = #{maId}
|
||
</select>
|
||
<select id="getDeviceNameCount" resultType="com.bonus.material.device.domain.DevInfo">
|
||
select ma_id from ma_dev_info
|
||
where device_name = #{deviceName,jdbcType=VARCHAR} and is_active = '1'
|
||
</select>
|
||
<select id="selectAssociationList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
select
|
||
d.*,
|
||
mt4.maintenance_alarm_day,
|
||
mt4.type_name as typeName,mt4.unit_name as unitName,
|
||
mt3.type_id as thirdId,mt3.type_name as thirdName,
|
||
mt2.type_id as secondId,mt2.type_name as secondName,
|
||
mt1.type_id as firstId,mt1.type_name as firstName
|
||
from
|
||
ma_dev_info d
|
||
left join ma_type mt4 ON mt4.type_id = d.type_id and mt4.del_flag = '0'
|
||
left join ma_type mt3 ON mt3.type_id = mt4.parent_id and mt3.del_flag = '0'
|
||
left join ma_type mt2 ON mt2.type_id = mt3.parent_id and mt2.del_flag = '0'
|
||
left join ma_type mt1 ON mt1.type_id = mt2.parent_id and mt1.del_flag = '0'
|
||
where
|
||
d.ma_status != 0
|
||
and d.is_active = '1'
|
||
and d.on_company = #{companyId}
|
||
ORDER BY d.create_time desc
|
||
</select>
|
||
<select id="getTagDevList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
d.*,
|
||
u.nick_name as nickName,
|
||
dept.dept_name as comName
|
||
FROM
|
||
ma_dev_info d
|
||
LEFT JOIN sys_user u ON d.creator = u.user_id
|
||
LEFT JOIN sys_dept dept ON d.on_company = dept.dept_id
|
||
WHERE
|
||
d.is_active = 1
|
||
AND d.ma_status !=0
|
||
AND d.on_company = #{ownCo}
|
||
<if test="code != null and code != ''">
|
||
and d.code like concat('%',#{code},'%')
|
||
</if>
|
||
<if test="deviceName != null and deviceName != ''">
|
||
and d.device_name like concat('%',#{deviceName},'%')
|
||
</if>
|
||
<if test="nickName != null and nickName != ''">
|
||
and u.nick_name like concat('%',#{nickName},'%')
|
||
</if>
|
||
<if test="comName != null and comName != ''">
|
||
and dept.dept_name like concat('%',#{comName},'%')
|
||
</if>
|
||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||
and DATE_FORMAT(d.create_time,'%Y-%m-%d') between #{startTime} and #{endTime}
|
||
</if>
|
||
</select>
|
||
<select id="getDevList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
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.type_id AS typeId,
|
||
mt4.type_name AS typeName,
|
||
mt4.unit_name AS unitName,
|
||
d.ma_status AS maStatus,
|
||
IFNULL(r.rent_num, 0) AS rentNum,
|
||
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,
|
||
mt3.type_id AS thirdId,
|
||
mt3.type_name AS thirdName,
|
||
mt2.type_id AS secondId,
|
||
mt2.type_name AS secondName,
|
||
mt1.type_id AS firstId,
|
||
mt1.type_name AS firstName
|
||
FROM
|
||
ma_dev_info d
|
||
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 (
|
||
SELECT md.ma_id, COUNT(moi.order_id) AS rent_num
|
||
FROM ma_order_details md
|
||
LEFT JOIN ma_order_info moi ON moi.order_id = md.order_id
|
||
GROUP BY md.ma_id
|
||
) r ON r.ma_id = d.ma_id
|
||
LEFT JOIN ma_type mt4 ON mt4.type_id = d.type_id
|
||
AND mt4.del_flag = '0'
|
||
LEFT JOIN ma_type mt3 ON mt3.type_id = mt4.parent_id
|
||
AND mt3.del_flag = '0'
|
||
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id
|
||
AND mt2.del_flag = '0'
|
||
LEFT JOIN ma_type mt1 ON mt1.type_id = mt2.parent_id
|
||
AND mt1.del_flag = '0'
|
||
WHERE
|
||
d.is_active = '1' and d.entry_status ='1'
|
||
<if test="deviceName != null and deviceName != ''">
|
||
AND d.device_name like concat('%',#{deviceName},'%')
|
||
</if>
|
||
<if test="code != null and code != ''">
|
||
AND d.code like concat('%',#{code},'%')
|
||
</if>
|
||
<if test="typeId != null">
|
||
AND d.type_id = #{typeId}
|
||
</if>
|
||
<if test="maStatus != null">
|
||
AND d.ma_status = #{maStatus}
|
||
</if>
|
||
<if test="rentNum != null">
|
||
AND IFNULL(r.rent_num, 0) = #{rentNum}
|
||
</if>
|
||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||
AND d.update_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
|
||
</if>
|
||
ORDER BY
|
||
d.create_time DESC
|
||
</select>
|
||
<select id="getDevStatus" resultType="com.bonus.material.device.domain.DevInfo">
|
||
SELECT
|
||
COUNT( moi.order_id ) AS rentNum,
|
||
mdi.ma_status
|
||
FROM
|
||
ma_dev_info mdi
|
||
LEFT JOIN ma_order_details md ON mdi.ma_id = md.ma_id
|
||
LEFT JOIN ma_order_info moi ON moi.order_id = md.order_id
|
||
WHERE
|
||
mdi.ma_id = #{maId}
|
||
GROUP BY
|
||
mdi.ma_status
|
||
ORDER BY
|
||
moi.order_time DESC
|
||
</select>
|
||
<select id="getTodayDevCount" resultType="java.lang.Integer">
|
||
SELECT
|
||
COUNT(1)
|
||
FROM
|
||
ma_dev_info
|
||
WHERE
|
||
DATE_FORMAT( create_time, '%Y-%m-%d' ) = DATE_FORMAT( NOW(), '%Y-%m-%d' )
|
||
AND is_active = '1'
|
||
AND ma_status != 0
|
||
</select>
|
||
|
||
<select id="getDevNum" resultType="java.lang.Integer">
|
||
SELECT
|
||
COUNT(1)
|
||
FROM
|
||
ma_dev_info
|
||
WHERE
|
||
is_active = '1'
|
||
AND ma_status != 0
|
||
</select>
|
||
|
||
<select id="getDevUpNum" resultType="java.lang.Integer">
|
||
SELECT
|
||
COUNT(1)
|
||
FROM
|
||
ma_dev_info
|
||
WHERE
|
||
is_active = '1'
|
||
AND ma_status = '2'
|
||
</select>
|
||
|
||
<select id="getDevUpCountByType" resultType="com.bonus.material.device.domain.DevInfo">
|
||
select b.type_name as typeName, sum(count) as deviceCount from
|
||
(
|
||
select mt3.type_name, a.count from (
|
||
SELECT type_id, count(1) as count FROM ma_dev_info
|
||
where is_active='1' and ma_status='2'
|
||
group by type_id
|
||
order by count(type_id) desc
|
||
) a
|
||
left join ma_type mt4 on mt4.type_id = a.type_id
|
||
left join ma_type mt3 on mt3.type_id = mt4.parent_id
|
||
) b
|
||
group by type_name
|
||
order by sum(count) desc
|
||
</select>
|
||
|
||
<select id="getDevLeasingNum" resultType="java.lang.Integer">
|
||
SELECT
|
||
COUNT(1)
|
||
FROM
|
||
ma_dev_info
|
||
WHERE
|
||
is_active = '1'
|
||
AND ma_status = '3'
|
||
</select>
|
||
|
||
<select id="getMaTypeLeasingNum" resultType="java.lang.Integer">
|
||
SELECT
|
||
count(DISTINCT(type_id)) as count
|
||
FROM
|
||
ma_dev_info
|
||
WHERE
|
||
is_active = '1'
|
||
AND ma_status = '3'
|
||
</select>
|
||
|
||
<select id="getRepairingDevNum" resultType="java.lang.Integer">
|
||
select count(1)
|
||
from lease_repair_record lrr
|
||
LEFT JOIN ma_order_details modd on modd.order_id=lrr.order_id
|
||
where IFNULL(lrr.repair_num,0) > 0 and modd.order_status < 20
|
||
</select>
|
||
|
||
<select id="getDevTypeNum" resultType="java.lang.Integer">
|
||
SELECT
|
||
count(distinct(type_id))
|
||
FROM
|
||
ma_dev_info
|
||
WHERE
|
||
is_active = '1'
|
||
AND ma_status != 0
|
||
</select>
|
||
|
||
<select id="getDevQcWarningNum" resultType="java.lang.Integer">
|
||
SELECT
|
||
COUNT(1)
|
||
FROM
|
||
ma_dev_info mdi
|
||
LEFT JOIN ma_dev_qc mdc ON mdi.ma_id = mdc.ma_id
|
||
where mdc.next_check_time < now()
|
||
</select>
|
||
|
||
<select id="getDevUsageRatio" resultType="com.bonus.material.device.domain.DevInfo">
|
||
SELECT
|
||
sum(total_up_day) as totalUpDay,
|
||
sum(total_lease_day) as totalLeaseDay
|
||
FROM
|
||
ma_dev_info
|
||
where is_active = '1'
|
||
</select>
|
||
|
||
<update id="updateTotalDevUpDay">
|
||
update ma_dev_info set total_up_day = IFNULL(total_up_day, 0) + 1
|
||
where is_active = '1' and ma_status = '2'
|
||
</update>
|
||
|
||
<update id="updateTotalDevLeaseDay">
|
||
update ma_dev_info set total_lease_day = IFNULL(total_lease_day, 0) + 1
|
||
where is_active = '1' and ma_status = '3'
|
||
</update>
|
||
|
||
<select id="getIdleDevRatio" resultType="com.bonus.material.device.domain.DevInfo">
|
||
SELECT
|
||
CASE
|
||
WHEN a.ratio is null or a.ratio < 0.3 THEN '0%-30%'
|
||
WHEN a.ratio >= 0.3 AND ratio <= 0.8 THEN '30%-80%'
|
||
ELSE '80%-100%'
|
||
END AS ratio_range,
|
||
COUNT(*) AS device_count
|
||
FROM
|
||
(SELECT total_lease_day/NULLIF(total_up_day+total_lease_day, 0) as ratio FROM ma_dev_info) a
|
||
GROUP BY
|
||
ratio_range
|
||
ORDER BY
|
||
ratio_range
|
||
</select>
|
||
|
||
<select id="getLeaseCountByTypeName" resultType="com.bonus.material.device.domain.DevInfo">
|
||
select mt5.type_name, count(1) as device_count
|
||
from ma_order_details modd
|
||
LEFT JOIN ma_dev_info mdi on modd.ma_id=mdi.ma_id
|
||
LEFT JOIN ma_type mt4 on mt4.type_id=mdi.type_id
|
||
LEFT JOIN ma_type mt3 on mt3.type_id=mt4.parent_id
|
||
LEFT JOIN ma_type mt2 on mt3.parent_id = mt2.type_id
|
||
LEFT JOIN ma_type mt1 on mt2.parent_id = mt1.type_id
|
||
LEFT JOIN ma_type mt5 on mt1.parent_id = mt5.type_id
|
||
where mt5.type_name is not null
|
||
and modd.order_status != 0 and modd.order_status != 99
|
||
group by mt1.type_name
|
||
</select>
|
||
|
||
<select id="getDeviceShareRanking" resultType="com.bonus.material.device.domain.DevInfo">
|
||
SELECT
|
||
sd.dept_name AS com_name,
|
||
count( mdi.ma_id ) AS device_count
|
||
FROM
|
||
ma_dev_info mdi
|
||
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
|
||
WHERE
|
||
mdi.up_down_status ='1'
|
||
GROUP BY
|
||
mdi.on_company
|
||
ORDER BY
|
||
device_count DESC
|
||
</select>
|
||
|
||
<select id="getLeaseDevList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
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.type_id AS typeId,
|
||
mt4.type_name AS typeName,
|
||
mt4.unit_name AS unitName,
|
||
d.ma_status AS maStatus,
|
||
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,
|
||
mt3.type_id AS thirdId,
|
||
mt3.type_name AS thirdName,
|
||
mt2.type_id AS secondId,
|
||
mt2.type_name AS secondName,
|
||
mt1.type_id AS firstId,
|
||
mt1.type_name AS firstName
|
||
FROM
|
||
ma_dev_info d
|
||
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 mt4 ON mt4.type_id = d.type_id
|
||
AND mt4.del_flag = '0'
|
||
LEFT JOIN ma_type mt3 ON mt3.type_id = mt4.parent_id
|
||
AND mt3.del_flag = '0'
|
||
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id
|
||
AND mt2.del_flag = '0'
|
||
LEFT JOIN ma_type mt1 ON mt1.type_id = mt2.parent_id
|
||
AND mt1.del_flag = '0'
|
||
WHERE
|
||
d.is_active = '1' and d.ma_status = '3'
|
||
<if test="keyWord != null and keyWord != ''">
|
||
AND (
|
||
d.device_name like concat('%',#{keyWord},'%') or
|
||
mt1.type_name like concat('%',#{keyWord},'%') or
|
||
mt2.type_name like concat('%',#{keyWord},'%') or
|
||
mt3.type_name like concat('%',#{keyWord},'%') or
|
||
mt4.type_name like concat('%',#{keyWord},'%') or
|
||
d.person like concat('%',#{keyWord},'%')
|
||
)
|
||
</if>
|
||
ORDER BY
|
||
d.create_time DESC
|
||
</select>
|
||
|
||
<select id="getCompanyNum" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
order_id as orderId
|
||
FROM
|
||
ma_order_details
|
||
WHERE order_status != 0 and order_status != 99
|
||
GROUP BY
|
||
order_id
|
||
</select>
|
||
<select id="selectDevInfoHotListRatio" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
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.type_id as typeId,
|
||
mt4.type_name as typeName,
|
||
d.ma_status as maStatus,
|
||
d.brand as brand,
|
||
d.production_date as productionDate,
|
||
d.working_hours as workingHours,
|
||
d.person as person,
|
||
d.person_phone as personPhone,
|
||
d.on_company as companyId,
|
||
d.total_lease_day as totalLeaseDay,
|
||
d.total_up_day as totalUpDay,
|
||
sd.dept_name as companyName,
|
||
c.operate_address as operateAddress,
|
||
d.create_time as createTime,
|
||
mt3.type_id as thirdId,
|
||
mt3.type_name as thirdName,
|
||
mt2.type_id as secondId,
|
||
mt2.type_name as secondName,
|
||
mt1.type_id as firstId,
|
||
mt1.type_name as firstName
|
||
FROM
|
||
ma_dev_info d
|
||
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 mt4 ON mt4.type_id = d.type_id and mt4.del_flag = '0'
|
||
LEFT JOIN ma_type mt3 ON mt3.type_id = mt4.parent_id and mt3.del_flag = '0'
|
||
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id and mt2.del_flag = '0'
|
||
LEFT JOIN ma_type mt1 ON mt1.type_id = mt2.parent_id and mt1.del_flag = '0'
|
||
where
|
||
d.is_active='1'
|
||
and d.ma_status In (1,2,3)
|
||
<if test="deviceName != null and deviceName != ''">
|
||
and d.device_name like concat('%',#{deviceName},'%')
|
||
</if>
|
||
order by d.create_time desc
|
||
</select>
|
||
<select id="getOrderByCompanyId" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
md.ma_id AS maId,
|
||
COUNT( md.order_id ) AS orderNum ,
|
||
mdi.on_company AS companyId,
|
||
md.order_id AS orderId,
|
||
sd.dept_name AS companyName
|
||
FROM
|
||
ma_order_details md
|
||
LEFT JOIN ma_dev_info mdi on md.ma_id = mdi.ma_id
|
||
LEFT JOIN sys_dept sd on mdi.on_company = sd.dept_id
|
||
WHERE md.order_status != 0 and md.order_status != 99 and mdi.on_company =#{companyId}
|
||
GROUP BY
|
||
md.order_id
|
||
|
||
</select>
|
||
<select id="getBuyCompanyList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
moi.buyer_company as companyId,
|
||
sd.dept_name as companyName
|
||
FROM
|
||
ma_order_info moi
|
||
LEFT JOIN sys_dept sd ON moi.buyer_company = sd.dept_id
|
||
WHERE moi.order_id = #{orderId}
|
||
</select>
|
||
<select id="selectDeptList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
d.dept_id AS companyId,
|
||
d.dept_name AS companyName
|
||
FROM
|
||
sys_dept d
|
||
WHERE
|
||
d.dept_id = #{companyId}
|
||
AND d.del_flag = '0'
|
||
</select>
|
||
|
||
<select id="selectDevTypeByName" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
type_id as typeId,
|
||
type_name as typeName,
|
||
manage_type as manageType,
|
||
unit_name as unitName
|
||
FROM
|
||
ma_type
|
||
WHERE
|
||
type_name = #{typeName}
|
||
AND `level` = '4'
|
||
AND del_flag = '0'
|
||
</select>
|
||
|
||
<select id="getDevNumList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
COUNT(1) AS deviceNum ,
|
||
sd.dept_name AS comName
|
||
FROM
|
||
ma_dev_info mdi
|
||
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 mdi.on_company = sd.dept_id
|
||
WHERE
|
||
is_active = '1'
|
||
AND ma_status != 0
|
||
<if test="keyWord != null and keyWord != ''">
|
||
AND (
|
||
mdi.device_name like concat('%',#{keyWord},'%') or
|
||
mt.type_name like concat('%',#{keyWord},'%') or
|
||
mt2.type_name like concat('%',#{keyWord},'%')
|
||
)
|
||
</if>
|
||
GROUP BY
|
||
sd.dept_name
|
||
</select>
|
||
<select id="getDevUpNumList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
mt.type_name as modelName ,mdi.device_name as deviceName,mt2.type_name as typeName,mdi.identify_code as identifyCode,
|
||
mdi.ma_status as maStatus,mdi.create_time as createTime,sd.dept_name as comName
|
||
FROM
|
||
ma_dev_info mdi
|
||
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 mdi.on_company = sd.dept_id
|
||
WHERE
|
||
is_active = '1'
|
||
AND ma_status = '2'
|
||
<if test="keyWord != null and keyWord != ''">
|
||
AND (
|
||
mdi.device_name like concat('%',#{keyWord},'%') or
|
||
mt.type_name like concat('%',#{keyWord},'%') or
|
||
mt2.type_name like concat('%',#{keyWord},'%')
|
||
)
|
||
</if>
|
||
</select>
|
||
<select id="getDevTypeNumList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
count(mdi.type_id) as deviceCount, mt2.type_name as typeName,mdi.device_name as deviceName,mt.type_name as modelName
|
||
FROM
|
||
ma_dev_info mdi
|
||
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
|
||
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
|
||
WHERE
|
||
is_active = '1'
|
||
AND ma_status != 0
|
||
GROUP BY mdi.type_id
|
||
<if test="keyWord != null and keyWord != ''">
|
||
AND (
|
||
mdi.device_name like concat('%',#{keyWord},'%') or
|
||
mt.type_name like concat('%',#{keyWord},'%') or
|
||
mt2.type_name like concat('%',#{keyWord},'%')
|
||
)
|
||
</if>
|
||
</select>
|
||
<select id="getDevQcWarningNumList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
mdc.*,mt.type_name as modelName,mdi.device_name as deviceName,mt2.type_name as typeName ,
|
||
mdi.identify_code as identifyCode, mdc.next_check_time as nextCheckDate
|
||
FROM
|
||
ma_dev_info mdi
|
||
LEFT JOIN ma_dev_qc mdc ON mdi.ma_id = mdc.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
|
||
where mdc.next_check_time < now()
|
||
<if test="keyWord != null and keyWord != ''">
|
||
AND (
|
||
mdi.device_name like concat('%',#{keyWord},'%') or
|
||
mt.type_name like concat('%',#{keyWord},'%') or
|
||
mt2.type_name like concat('%',#{keyWord},'%')
|
||
)
|
||
</if>
|
||
</select>
|
||
<select id="getMaTypeLeasingNumList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
|
||
SELECT
|
||
mdi.device_name as deviceName,mt.type_name as modelName,
|
||
count(mrd.ma_id) as rentNum
|
||
FROM
|
||
ma_order_details mrd
|
||
LEFT JOIN ma_dev_info mdi on mdi.ma_id = mrd.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
|
||
WHERE
|
||
mdi.is_active = '1'
|
||
|
||
<if test="keyWord != null and keyWord != ''">
|
||
AND (
|
||
mdi.device_name like concat('%',#{keyWord},'%') or
|
||
mt2.type_name like concat('%',#{keyWord},'%')
|
||
)
|
||
</if>
|
||
GROUP BY mrd.ma_id
|
||
|
||
</select>
|
||
<select id="getDevLeasingNumList" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
mdi.device_name as deviceName,mt.type_name as modelName,mdi.identify_code as identifyCode,
|
||
md.order_id as orderId,sd.dept_name as comName,mdi.person as person,sd2.dept_name as lessee,
|
||
su.user_name as lesseePerson,md.rent_begin_time as startTime ,md.rent_end_time as endTime ,moi.cost as cost
|
||
FROM
|
||
ma_dev_info mdi
|
||
LEFT JOIN ma_order_details md on mdi.ma_id = md.ma_id
|
||
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
|
||
LEFT JOIN sys_dept sd on sd.dept_id = mdi.on_company
|
||
LEFT JOIN ma_order_info moi on moi.order_id = md.order_id
|
||
LEFT JOIN sys_dept sd2 on moi.buyer_company = sd2.dept_id
|
||
LEFT JOIN sys_user su on moi.buyer_id = su.user_id
|
||
WHERE
|
||
mdi.is_active = '1'
|
||
AND mdi.ma_status = '3'
|
||
</select>
|
||
<select id="getRentToalNum" resultType="java.lang.Integer">
|
||
select sum(num)
|
||
from ma_order_details
|
||
where order_status NOT IN ( 0 , 99 )
|
||
</select>
|
||
<select id="getDevLeaseCount" resultType="com.bonus.material.largeScreen.entity.LeaseInfo">
|
||
SELECT
|
||
sum(hh.num) leaseNum,
|
||
sd.dept_name leaseCompanyName
|
||
FROM
|
||
ma_order_info moi
|
||
LEFT JOIN ma_order_details hh ON moi.order_id = hh.order_id
|
||
LEFT JOIN sys_dept sd on moi.buyer_company = sd.dept_id
|
||
WHERE hh.order_status NOT IN ( 0, 99 )
|
||
GROUP BY moi.buyer_company
|
||
</select>
|
||
<select id="getDevRentCount" resultType="com.bonus.material.largeScreen.entity.RentInfo">
|
||
SELECT
|
||
sum( hh.num ) rentNum,
|
||
sd.dept_name rentCompanyName
|
||
FROM
|
||
ma_order_details hh
|
||
LEFT JOIN ma_dev_info mdi ON hh.ma_id = mdi.ma_id
|
||
LEFT JOIN sys_dept sd ON mdi.on_company = sd.dept_id
|
||
WHERE
|
||
hh.order_status NOT IN ( 0, 99 )
|
||
GROUP BY
|
||
mdi.on_company
|
||
</select>
|
||
<select id="getMaTypeLeasingDetail" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT
|
||
mdi.device_name AS deviceName,
|
||
mt.type_name AS modelName,
|
||
mdi.identify_code AS identifyCode,
|
||
md.order_id AS orderId,
|
||
sd.dept_name AS comName,
|
||
mdi.person AS person,
|
||
sd2.dept_name AS lessee,
|
||
su.user_name AS lesseePerson,
|
||
md.rent_begin_time AS startTime,
|
||
md.rent_end_time AS endTime,
|
||
md.costs AS cost
|
||
FROM
|
||
ma_order_details md
|
||
LEFT JOIN ma_dev_info mdi ON mdi.ma_id = md.ma_id
|
||
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
|
||
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
|
||
LEFT JOIN ma_order_info moi ON moi.order_id = md.order_id
|
||
LEFT JOIN sys_dept sd2 ON moi.buyer_company = sd2.dept_id
|
||
LEFT JOIN sys_user su ON moi.buyer_id = su.user_id
|
||
WHERE
|
||
mdi.is_active = '1'
|
||
</select>
|
||
<select id="getDemandUnit" resultType="com.bonus.common.biz.domain.SysDept">
|
||
SELECT DISTINCT
|
||
sd.dept_name deptName,
|
||
sd.create_time createTime
|
||
FROM
|
||
ma_lease_info mli
|
||
LEFT JOIN sys_dept sd ON mli.publish_company = sd.dept_id
|
||
</select>
|
||
<select id="getTotalEquipment" resultType="java.lang.Integer">
|
||
select count(1) from ma_dev_info where is_active ='1' and entry_status = '1' and change_status !='4'
|
||
<if test="ownCo != null ">
|
||
AND on_company = #{ownCo}
|
||
</if>
|
||
<if test="changeStatus != null ">
|
||
AND change_status = #{changeStatus}
|
||
</if>
|
||
</select>
|
||
<select id="getTotalValue" resultType="java.math.BigDecimal">
|
||
select SUM(buy_price) from ma_dev_info where is_active ='1' and entry_status = '1' and change_status !='4'
|
||
<if test="ownCo != null ">
|
||
AND on_company = #{ownCo}
|
||
</if>
|
||
</select>
|
||
<select id="getLineNum" resultType="java.lang.Integer">
|
||
select count(1)
|
||
from ma_dev_info mdi
|
||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||
where mtv.maxTypeId = #{typeId}
|
||
and mdi.is_active = '1' and mdi.entry_status = '1' and mdi.change_status !='4'
|
||
and on_company = #{ownCo}
|
||
</select>
|
||
<select id="getLinePrice" resultType="java.math.BigDecimal">
|
||
select sum(mdi.buy_price)
|
||
from ma_dev_info mdi
|
||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||
where mtv.maxTypeId = #{typeId}
|
||
and mdi.is_active = '1' and mdi.entry_status = '1' and mdi.change_status !='4'
|
||
and on_company = #{ownCo}
|
||
</select>
|
||
<select id="getLineProductionDateList" resultType="java.lang.String">
|
||
select production_date
|
||
from ma_dev_info mdi
|
||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||
where mtv.maxTypeId = #{typeId}
|
||
and mdi.is_active = '1'
|
||
and on_company = #{ownCo}
|
||
</select>
|
||
|
||
<select id="getPrice" resultType="java.math.BigDecimal">
|
||
select SUM(buy_price) from ma_dev_info where is_active ='1' and on_company = #{deptId}
|
||
</select>
|
||
<select id="getEquipmentStatus" resultType="java.lang.Integer">
|
||
select count(1) from ma_dev_info where is_active ='1' and change_status = #{changeStatus}
|
||
<if test="deptId != null">
|
||
and on_company = #{deptId}
|
||
</if>
|
||
</select>
|
||
<select id="getChangeNum" resultType="java.lang.Integer">
|
||
select IFNULL(SUM(cdcd.num), 0)
|
||
from cs_device_change_details cdcd
|
||
LEFT JOIN cs_device_change cdc ON cdcd.change_id = cdc.id
|
||
where cdcd.del_flag = '0'
|
||
and cdcd.use_time is not null
|
||
and cdcd.is_finished = '1'
|
||
and cdcd.dev_type = '1'
|
||
AND cdcd.create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
|
||
<if test="deptId != null">
|
||
and cdc.company_id = #{deptId}
|
||
</if>
|
||
</select>
|
||
<select id="getTurnoverRate" resultType="java.lang.Integer">
|
||
select count(1)
|
||
from cs_device_change_details cdcd
|
||
left join cs_device_change cdc on cdcd.change_id = cdc.id
|
||
left join ma_dev_info mdi on mdi.code = cdcd.dev_code
|
||
where cdcd.del_flag = '0'
|
||
AND cdc.create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH);
|
||
</select>
|
||
|
||
<select id="selectCheckDevInfoList" resultMap="DevInfoResult">
|
||
SELECT
|
||
mtv.*,
|
||
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.type_id as typeId,
|
||
d.ma_status as maStatus,
|
||
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
|
||
FROM
|
||
ma_dev_info d
|
||
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="maId != null "> and d.ma_id = #{maId}</if>
|
||
<if test="code != null and code != ''"> and d.code = #{code}</if>
|
||
<if test="deviceName != null and deviceName != ''">
|
||
and d.device_name like concat('%',#{deviceName},'%')
|
||
</if>
|
||
<if test="maStatus != null"> and d.ma_status = #{maStatus}</if>
|
||
<if test="leaseScope != null "> and d.lease_scope = #{leaseScope}</if>
|
||
<if test="location != null and location != ''"> and d.location = #{location}</if>
|
||
<if test="provinceId != null and provinceId != ''"> and d.province_id = #{provinceId}</if>
|
||
<if test="cityId != null and cityId != ''"> and d.city_id = #{cityId}</if>
|
||
<if test="areaId != null and areaId != ''"> and d.area_id = #{areaId}</if>
|
||
<if test="brand != null and brand != ''"> and d.brand = #{brand}</if>
|
||
<if test="ageMin != null and ageMax != null">
|
||
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) >= #{ageMin}
|
||
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) <= #{ageMax}
|
||
</if>
|
||
<if test="ageMin == null and ageMax != null">
|
||
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) >= #{ageMax}
|
||
</if>
|
||
<if test="workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != ''">
|
||
and d.working_hours >= #{workingHoursMin} and d.working_hours <= #{workingHoursMax}
|
||
</if>
|
||
<if test="description != null and description != ''"> and d.description = #{description}</if>
|
||
<if test="gpsCode != null and gpsCode != ''"> and d.gps_code = #{gpsCode}</if>
|
||
<if test="companyId != null and companyId != ''"> and d.on_company = #{companyId}</if>
|
||
<if test="specification != null "> and d.specification = #{specification}</if>
|
||
<if test="deposit != null "> and d.deposit = #{deposit}</if>
|
||
<if test="startTime != null and endTime != null">
|
||
and d.update_time between #{startTime} and #{endTime}
|
||
</if>
|
||
<if test="isZone != null">
|
||
and d.is_zone = 1
|
||
</if>
|
||
<if test="zoneId != null">
|
||
and d.zone_id = #{zoneId}
|
||
</if>
|
||
<if test="keyWord != null and keyWord != ''">
|
||
and (
|
||
locate(#{keyWord},mtv.mainGx) > 0
|
||
or locate(#{keyWord},mtv.childGx) > 0
|
||
or locate(#{keyWord},mtv.devCategory) > 0
|
||
or locate(#{keyWord},mtv.devSubcategory) > 0
|
||
or locate(#{keyWord},mtv.devName) > 0
|
||
or locate(#{keyWord},c.company_name) > 0
|
||
or locate(#{keyWord},d.device_name) > 0
|
||
or locate(#{keyWord},d.identify_code) > 0
|
||
)
|
||
</if>
|
||
and d.is_active='1' and d.entry_status = #{entryStatus}
|
||
</where>
|
||
order by
|
||
d.is_active
|
||
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'ASC'">
|
||
,d.create_time
|
||
</if>
|
||
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'DESC'">
|
||
,d.create_time DESC
|
||
</if>
|
||
</select>
|
||
|
||
<update id="updateCheckStatus">
|
||
<foreach collection="list" item="data" index="index" separator=";" close=")" open="(">
|
||
UPDATE ma_dev_info SET entry_status = #{data.value} where ma_id =#{data.key}
|
||
</foreach>
|
||
</update>
|
||
|
||
<select id="getTotalEquipmentByLevel" resultType="java.lang.Integer">
|
||
select count(1)
|
||
from ma_dev_info mdi
|
||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||
where mtv.typeId = #{typeId} and mdi.is_active ='1'
|
||
<if test="changeStatus != null ">
|
||
AND change_status = #{changeStatus}
|
||
</if>
|
||
</select>
|
||
<select id="getTurnoverRateByLevel" resultType="java.lang.Integer">
|
||
select count(1) from cs_device_change_details cdcd
|
||
left join cs_device_change cdc on cdcd.change_id = cdc.id
|
||
left join ma_dev_info mdi on mdi.ma_id = cdcd.dev_id
|
||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||
where cdcd.del_flag = '0'
|
||
AND cdc.create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
|
||
<if test="typeId != null ">
|
||
AND mtv.typeId = #{typeId}
|
||
</if>
|
||
</select>
|
||
<select id="getProjectNUm" resultType="java.lang.Integer">
|
||
SELECT COUNT(1)
|
||
from jj_sing_project
|
||
</select>
|
||
<select id="selectToolByMaId" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
|
||
SELECT SUBSTRING_INDEX(tt.fileList, ',', 1) AS picUrl, -- 1. 对应第一部分 picUrl
|
||
'' AS proType, -- 2. 对应 proType
|
||
'' AS mainGx, -- 3. 对应 mainGx
|
||
'' AS childGx, -- 4. 对应 childGx
|
||
'' AS devCategory, -- 5. 对应 devCategory
|
||
'' AS devSubcategory, -- 6. 对应 devSubcategory
|
||
tt.type_name AS typeName, -- 7. 对应 devName
|
||
'1' AS devType, -- 8. 对应 devType
|
||
tl.manage_mode AS manageMode, -- 9. 对应 manageMode(与第一部分位置一致!)
|
||
tl.id AS maId, -- 10. 对应 maId
|
||
tl.tool_code AS `code`, -- 11. 对应 code
|
||
tl.identify_code AS identifyCode, -- 12. 对应 identifyCode
|
||
tt1.type_name AS deviceName, -- 13. 对应 deviceName
|
||
tl.available_num AS deviceCount, -- 14. 对应 deviceCount
|
||
tl.type_id AS typeId, -- 15. 对应 typeId
|
||
tl.STATUS AS maStatus, -- 16. 对应 maStatus
|
||
'' AS brand, -- 17. 对应 brand
|
||
tl.production_date AS productionDate, -- 18. 对应 productionDate
|
||
0 AS workingHours, -- 19. 对应 workingHours
|
||
sd.leader AS person, -- 20. 对应 person
|
||
sd.phone AS personPhone, -- 21. 对应 personPhone
|
||
tl.create_time AS createTime, -- 22. 对应 createTime
|
||
tl.update_time AS updateTime, -- 23. 对应 updateTime
|
||
tl.company_id AS companyId, -- 24. 对应 companyId
|
||
sd.dept_name AS companyName, -- 25. 对应 companyName
|
||
c.operate_address AS operateAddress, -- 26. 对应 operateAddress(列数对齐!)
|
||
tt.create_time AS companyCreateTime,
|
||
COALESCE(tl.lease_price, tt.lease_price) AS dayLeasePrice
|
||
|
||
FROM tool_ledger tl
|
||
LEFT JOIN sys_dept sd ON tl.company_id = sd.dept_id
|
||
INNER JOIN tool_type tt ON tt.type_id = tl.type_id
|
||
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id -- 确保 tt 有 parent_id,否则可能查不到数据
|
||
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
|
||
WHERE tl.up_down_status = '1'
|
||
and tl.id = #{maId}
|
||
</select>
|
||
<select id="getUnitEquipmentConfiguration" resultType="java.util.Map">
|
||
SELECT sd.dept_name AS deptName,
|
||
sd.dept_abbreviation AS deptAbbreviation,
|
||
ba.name AS cityName,
|
||
IFNULL(sd.location, CONCAT(ba.latitude, ',', ba.longitude)) AS location,
|
||
-- 统计关联了mdi且mtv.maxTypeId=5080的总数量
|
||
IFNULL(sum(mdi.buy_price), 0) AS totalValue,
|
||
SUM(CASE
|
||
WHEN sd.dept_id = mdi.on_company THEN 1 -- 仅当类型符合时计数
|
||
ELSE 0
|
||
END) AS totalEquipmentQuantity,
|
||
SUM(CASE
|
||
WHEN mtv.maxTypeId = 1 THEN 1 -- 仅当类型符合时计数
|
||
ELSE 0
|
||
END) AS cableNum,
|
||
SUM(CASE
|
||
WHEN mtv.maxTypeId = 3 THEN 1 -- 仅当类型符合时计数
|
||
ELSE 0
|
||
END) AS substationNum,
|
||
SUM(CASE
|
||
WHEN mtv.maxTypeId = 2 THEN 1 -- 仅当类型符合时计数
|
||
ELSE 0
|
||
END) AS lineNum,
|
||
0.0 AS configRate,
|
||
0.0 AS valueA,
|
||
0.0 AS valueB,
|
||
0.0 AS valueC
|
||
FROM sys_dept sd
|
||
-- 左连接设备表(过滤有效数据)
|
||
LEFT JOIN base_address ba ON ba.code = sd.city
|
||
LEFT JOIN ma_dev_info mdi
|
||
ON mdi.on_company = sd.dept_id
|
||
AND mdi.change_status != '4'
|
||
AND mdi.is_active = '1'
|
||
AND mdi.entry_status = '1'
|
||
-- 左连接类型表(不在这里加maxTypeId条件,避免过滤主表)
|
||
LEFT JOIN ma_type_view mtv
|
||
ON mtv.typeId = mdi.type_id
|
||
WHERE sd.del_flag = '0'
|
||
<if test="deptId != null">
|
||
AND sd.dept_id = #{deptId}
|
||
</if>
|
||
GROUP BY sd.dept_id, sd.dept_name -- 按部门分组,确保所有部门都被列出
|
||
ORDER BY totalValue DESC
|
||
</select>
|
||
<select id="getMaStatusByToolId" resultType="com.bonus.material.device.domain.DevInfo">
|
||
SELECT id AS id,
|
||
'1' AS maStatus
|
||
FROM tool_ledger
|
||
WHERE available_num >= #{num}
|
||
and id = #{id}
|
||
</select>
|
||
</mapper>
|