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

1489 lines
67 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="modelName" column="model_name" />
<result property="productionDate" column="production_date" />
<result property="workingHours" column="working_hours" />
<result property="serialNumber" column="serial_number" />
<result property="dayLeasePrice" column="day_lease_price" />
<result property="picUrl" column="pic_url" />
<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="own_co" />
<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_weight, device_count, code, identify_code, type_id, ma_status, lease_scope, location, province_id, city_id, area_id, brand, model_name, production_date, working_hours, serial_number,
pic_url, js_month_price, js_day_price, description, gps_code, own_co, create_time,
creator, update_time, person, person_phone, update_by, specification, deposit, is_operator, 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
d.ma_id as maId,
d.code as code,
d.identify_code as identifyCode,
d.device_name as deviceName,
d.device_weight as deviceWeight,
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.model_name as modelName,
d.production_date as productionDate,
d.working_hours as workingHours,
d.serial_number as serialNumber,
mt4.lease_price as dayLeasePrice,
d.person as person,
d.person_phone as personPhone,
d.create_time as createTime,
d.update_time as updateTime,
d.own_co 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.own_co = 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>
<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">
<choose>
<when test="level != null and level == 4">
and d.type_id = #{typeId}
</when>
<when test="level != null and level == 3">
and mt3.type_id = #{typeId}
</when>
<when test="level != null and level == 2">
and mt2.type_id = #{typeId}
</when>
<when test="level != null and level == 1">
and mt1.type_id = #{typeId}
</when>
</choose>
</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="modelName != null and modelName != ''"> and d.model_name like concat('%', #{modelName}, '%')</if>
<if test="ageMin != null and ageMax != null">
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) &gt;= #{ageMin}
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) &lt;= #{ageMax}
</if>
<if test="ageMin == null and ageMax != null">
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) &gt;= #{ageMax}
</if>
<if test="workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != ''">
and d.working_hours &gt;= #{workingHoursMin} and d.working_hours &lt;= #{workingHoursMax}
</if>
<if test="serialNumber != null and serialNumber != ''"> and d.serial_number = #{serialNumber}</if>
<if test="dayLeasePriceMin != null and dayLeasePriceMax != null">
and mt4.lease_price &gt;= #{dayLeasePriceMin} and mt4.lease_price &lt;= #{dayLeasePriceMax}
</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.own_co = #{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},mt1.type_name) > 0
or locate(#{keyWord},mt2.type_name) > 0
or locate(#{keyWord},mt3.type_name) > 0
or locate(#{keyWord},mt4.type_name) > 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'
</where>
order by
d.is_active
<if test="dayLeasePriceOrderBy != null and dayLeasePriceOrderBy == 'ASC'">
,mt4.lease_price
</if>
<if test="dayLeasePriceOrderBy != null and dayLeasePriceOrderBy == 'DESC'">
,mt4.lease_price DESC
</if>
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'ASC'">
,d.create_time
</if>
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'DESC'">
,d.create_time DESC
</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.device_weight as deviceWeight,
d.type_id as typeId,
mt4.type_name as typeName,
d.ma_status as maStatus,
d.brand as brand,
d.model_name as modelName,
d.production_date as productionDate,
d.working_hours as workingHours,
d.serial_number as serialNumber,
mt4.lease_price as dayLeasePrice,
d.person as person,
d.person_phone as personPhone,
d.own_co 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.own_co = 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,
d.item_type_model as itemTypeModel,
identify_code as identifyCode,
d.device_name as deviceName,
d.device_weight as deviceWeight,
d.device_count as deviceCount,
d.type_id as typeId,
d.check_date as checkDate,
d.check_cycle as checkCycle,
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.model_name as modelName,
d.production_date as productionDate,
d.working_hours as workingHours,
d.serial_number as serialNumber,
mt4.lease_price as dayLeasePrice,
d.person as person,
d.person_phone as personPhone,
d.own_id as ownId,
d.own_co 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.is_zone as isZone, d.zone_id as zoneId
FROM
ma_dev_info d
LEFT JOIN sys_dept sd ON d.own_co = 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
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="deviceWeight != null and deviceWeight != '' ">device_weight,</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="modelName != null and modelName != ''">model_name,</if>
<if test="productionDate != null">production_date,</if>
<if test="workingHours != null and workingHours != ''">working_hours,</if>
<if test="serialNumber != null and serialNumber != ''">serial_number,</if>
<if test="picUrl != null and picUrl != ''">pic_url,</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 != ''" >own_co,</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="ownId != null">own_id,</if>
<if test="checkDate != null">check_date,</if>
<if test="checkCycle != null">check_cycle,</if>
<if test="isZone != null">is_zone,</if>
<if test="zoneId != null">zone_id,</if>
<if test="buyPrice != null">buy_price,</if>
<if test="itemTypeModel != null">item_type_model,</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="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="serialNumber != null and serialNumber != ''">#{serialNumber},</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>
</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="deviceWeight != null">device_weight = #{deviceWeight},</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="modelName != null">model_name = #{modelName},</if>
<if test="productionDate != null">production_date = #{productionDate},</if>
<if test="workingHours != null">working_hours = #{workingHours},</if>
<if test="serialNumber != null">serial_number = #{serialNumber},</if>
<if test="picUrl != null">pic_url = #{picUrl},</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">own_co = #{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>
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="modelName != null and modelName != ''"> and d.model_name like concat('%', #{modelName}, '%')</if>
<if test="companyId != null and companyId !=''"> and d.own_co = #{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.model_name) > 0
or locate(#{keyWord},d.specification) > 0
or locate(#{keyWord},d.serial_number) > 0
or locate(#{keyWord},d.description) > 0
)
</if>
and d.own_co = #{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_name, property_value, create_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{maId},
#{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.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.parent_id = 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>
</select>
<select id="getMaCountByCompany" resultType="com.bonus.common.biz.domain.BmCompanyInfo">
select own_co as companyId,count(1) as maCount from ma_dev_info
where ma_status=2
group by own_co
</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="deviceWeight != null and deviceWeight != '' ">device_weight,</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="modelName != null and modelName != ''">model_name,</if>
<if test="productionDate != null">production_date,</if>
<if test="workingHours != null and workingHours != ''">working_hours,</if>
<if test="serialNumber != null and serialNumber != ''">serial_number,</if>
<if test="picUrl != null and picUrl != ''">pic_url,</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 != ''" >own_co,</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="ownId != null and ownId != ''">own_id,</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="serialNumber != null and serialNumber != ''">#{serialNumber},</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 own_co = #{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.own_co = #{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.own_co = #{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.own_id = u.user_id
LEFT JOIN sys_dept dept ON d.own_co = dept.dept_id
WHERE
d.is_active = 1
AND d.ma_status !=0
AND d.own_co = #{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_weight AS deviceWeight,
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.model_name AS modelName,
d.production_date AS productionDate,
d.working_hours AS workingHours,
d.serial_number AS serialNumber,
mt4.lease_price AS dayLeasePrice,
d.person AS person,
d.person_phone AS personPhone,
d.create_time AS createTime,
d.update_time AS updateTime,
d.own_co 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.own_co = 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'
<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="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 &lt; 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 &lt; 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>
<update id="updateTypeLeasePrice">
update ma_type set lease_price = #{dayLeasePrice}
where type_id = #{typeId}
</update>
<select id="getIdleDevRatio" resultType="com.bonus.material.device.domain.DevInfo">
SELECT
CASE
WHEN a.ratio is null or a.ratio &lt; 0.3 THEN '0%-30%'
WHEN a.ratio >= 0.3 AND ratio &lt;= 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 mt1.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
where mt1.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.own_co
where mdi.ma_status in (2,3)
group by mdi.own_co
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_weight AS deviceWeight,
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.model_name AS modelName,
d.production_date AS productionDate,
d.working_hours AS workingHours,
d.serial_number AS serialNumber,
mt4.lease_price AS dayLeasePrice,
d.person AS person,
d.person_phone AS personPhone,
d.create_time AS createTime,
d.update_time AS updateTime,
d.own_co 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.own_co = 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.device_weight as deviceWeight,
d.type_id as typeId,
mt4.type_name as typeName,
d.ma_status as maStatus,
d.brand as brand,
d.model_name as modelName,
d.production_date as productionDate,
d.working_hours as workingHours,
d.serial_number as serialNumber,
mt4.lease_price as dayLeasePrice,
d.person as person,
d.person_phone as personPhone,
d.own_co 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.own_co = 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.own_co 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.own_co = sd.dept_id
WHERE md.order_status != 0 and md.order_status != 99 and mdi.own_co =#{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,
lease_price as dayLeasePrice,
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
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.own_co = 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>
</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.own_co = 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 &lt; 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,
mt.lease_price as dayLeasePrice,
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.own_co
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.own_co = sd.dept_id
WHERE
hh.order_status NOT IN ( 0, 99 )
GROUP BY
mdi.own_co
</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.own_co
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'
<if test="ownCo != null ">
AND own_co = #{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'
<if test="ownCo != null ">
AND own_co = #{ownCo}
</if>
</select>
<select id="getLineNum" resultType="java.lang.Integer">
select count(1)
from ma_dev_info mdi
left join ma_type mt on mdi.type_id = mt.type_id
left join ma_type mt1 on mt.parent_id = mt1.type_id
left join ma_type mt2 on mt1.parent_id = mt2.type_id
left join ma_type mt3 on mt2.parent_id = mt3.type_id
left join ma_type mt4 on mt3.parent_id = mt4.type_id
left join ma_type mt5 on mt4.parent_id = mt5.type_id
left join ma_type mt6 on mt5.parent_id = mt6.type_id
where mt6.type_id = #{typeId} and mdi.is_active ='1'
</select>
<select id="getLinePrice" resultType="java.math.BigDecimal">
select sum(mdi.buy_price)
from ma_dev_info mdi
left join ma_type mt on mdi.type_id = mt.type_id
left join ma_type mt1 on mt.parent_id = mt1.type_id
left join ma_type mt2 on mt1.parent_id = mt2.type_id
left join ma_type mt3 on mt2.parent_id = mt3.type_id
left join ma_type mt4 on mt3.parent_id = mt4.type_id
left join ma_type mt5 on mt4.parent_id = mt5.type_id
left join ma_type mt6 on mt5.parent_id = mt6.type_id
where mt6.type_id = #{typeId} and mdi.is_active ='1'
</select>
<select id="getLineProductionDateList" resultType="java.lang.String">
select production_date
from ma_dev_info mdi
left join ma_type mt on mdi.type_id = mt.type_id
left join ma_type mt1 on mt.parent_id = mt1.type_id
left join ma_type mt2 on mt1.parent_id = mt2.type_id
left join ma_type mt3 on mt2.parent_id = mt3.type_id
left join ma_type mt4 on mt3.parent_id = mt4.type_id
left join ma_type mt5 on mt4.parent_id = mt5.type_id
left join ma_type mt6 on mt5.parent_id = mt6.type_id
where mt6.type_id = #{typeId} and mdi.is_active ='1'
</select>
<select id="getUnitEquipmentConfiguration" resultType="com.bonus.material.equipment.domain.SysDept">
select production_date
from ma_dev_info mdi
left join ma_type mt on mdi.type_id = mt.type_id
left join ma_type mt1 on mt.parent_id = mt1.type_id
left join ma_type mt2 on mt1.parent_id = mt2.type_id
left join ma_type mt3 on mt2.parent_id = mt3.type_id
left join ma_type mt4 on mt3.parent_id = mt4.type_id
left join ma_type mt5 on mt4.parent_id = mt5.type_id
left join ma_type mt6 on mt5.parent_id = mt6.type_id
where mt6.type_id = #{id} and mdi.is_active ='1'
</select>
<select id="getPrice" resultType="java.math.BigDecimal">
select SUM(buy_price) from ma_dev_info where is_active ='1' and own_co = #{deptId}
</select>
<select id="getEquipmentStatus" resultType="java.lang.Integer">
select count(1) from ma_dev_info where is_active ='1' and change_status = #{changeStatus}
</select>
<select id="getChangeNum" resultType="java.lang.Integer">
select SUM(dev_num) from cs_device_change where del_flag ='0'
AND create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH);
</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.ma_id = cdcd.dev_id
where cdcd.del_flag = '0'
AND cdc.create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH);
</select>
</mapper>