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

393 lines
16 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.lease.mapper.MaLeaseInfoMapper">
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into ma_lease_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="leaseName != null and leaseName != ''">lease_name,</if>
<if test="leaseCode != null and leaseCode != ''">lease_code,</if>
<if test="typeId != null">type_id,</if>
<if test="ids != null">type_ids,</if>
<if test="companyId != null">company_id,</if>
<if test="areaId != null">area_id,</if>
<if test="leaseStatus != null">lease_status,</if>
<if test="leaseDay != null">lease_day,</if>
<if test="leaseNum != null">lease_num,</if>
<if test="startTime != null">start_time,</if>
<if test="publishUser != null">publish_user,</if>
<if test="endTime != null">end_time,</if>
<if test="person != null">person,</if>
<if test="personPhone != null">person_phone,</if>
<if test="description != null and description != ''">description,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="leaseName != null and leaseName != ''">#{leaseName},</if>
<if test="leaseCode != null and leaseCode != ''">#{leaseCode},</if>
<if test="typeId != null">#{typeId},</if>
<if test="ids != null">#{ids},</if>
<if test="companyId != null">#{companyId},</if>
<if test="areaId != null">#{areaId},</if>
<if test="leaseStatus != null">#{leaseStatus},</if>
<if test="leaseDay != null ">#{leaseDay},</if>
<if test="leaseNum != null ">#{leaseNum},</if>
<if test="startTime != null">#{startTime},</if>
<if test="publishUser != null">#{publishUser},</if>
<if test="endTime != null">#{endTime},</if>
<if test="person != null">#{person},</if>
<if test="personPhone != null">#{personPhone},</if>
<if test="description != null and description != ''">#{description},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<insert id="insertHotSearch">
insert into ma_hot_search(lease_id, lease_num, create_time)
values(#{id}, 1, now())
</insert>
<update id="updateDevInfo">
update ma_lease_info
<trim prefix="SET" suffixOverrides=",">
<if test="leaseName != null and leaseName != ''">lease_name = #{leaseName},</if>
<if test="typeId != null">type_id = #{typeId},</if>
<if test="ids != null">type_ids = #{ids},</if>
<if test="companyId != null">company_id = #{companyId},</if>
<if test="areaId != null">area_id = #{areaId},</if>
<if test="leaseDay != null ">lease_day = #{leaseDay},</if>
<if test="leaseStatus != null ">lease_status = #{leaseStatus},</if>
<if test="leaseNum != null ">lease_num = #{leaseNum},</if>
<if test="startTime != null">start_time = #{startTime},</if>
<if test="publishUser != null and publishUser != ''">publish_user = #{publishUser},</if>
<if test="endTime != null">end_time = #{endTime},</if>
<if test="person != null">person = #{person},</if>
<if test="personPhone != null">person_phone = #{personPhone},</if>
<if test="description != null and description != ''">description = #{description},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="orderUser != null and orderUser != ''">order_user = #{orderUser},</if>
<if test="orderTime != null">order_time = #{orderTime},</if>
</trim>
where id = #{id}
</update>
<update id="updateHotSearchByLeaseId">
update ma_hot_search
set lease_num = lease_num + 1,
update_time = now()
where lease_id = #{id}
</update>
<delete id="deleteById">
delete from ma_lease_info where id = #{id}
</delete>
<select id="selectByName" resultType="com.bonus.material.lease.domain.vo.MaLeaseVo">
SELECT
m.id as id,
m.lease_name as leaseName,
m.lease_code as leaseCode,
m.type_id as typeId,
m.type_ids as ids,
mt4.type_name as typeName,
m.company_id as companyId,
c.company_name as companyName,
c.operate_address as operateAddress,
m.lease_status as leaseStatus,
m.lease_day as leaseDay,
m.lease_num as leaseNum,
m.start_time as startTime,
m.end_time as endTime,
m.person as person,
m.person_phone as personPhone,
m.description as description,
IFNULL(h.lease_num, 0) AS searchNum,
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,
CASE
-- 第一级
WHEN mt1.type_id IS NULL
AND mt2.type_id IS NULL
AND mt3.type_id IS NULL
AND mt4.type_id IS NOT NULL THEN
mt4.type_name
-- 第二级
WHEN mt1.type_id IS NULL
AND mt2.type_id IS NULL
AND mt3.type_id IS NOT NULL
AND mt4.type_id IS NOT NULL THEN
CONCAT( mt3.type_name, '/', mt4.type_name )
-- 第三级
WHEN mt1.type_id IS NULL
AND mt2.type_id IS NOT NULL
AND mt3.type_id IS NOT NULL
AND mt4.type_id IS NOT NULL THEN
CONCAT( mt2.type_name, '/', mt3.type_name, '/', mt4.type_name )
-- 第四级
WHEN mt1.type_id IS NOT NULL
AND mt2.type_id IS NOT NULL
AND mt3.type_id IS NOT NULL
AND mt4.type_id IS NOT NULL THEN
CONCAT( mt1.type_name, '/', mt2.type_name, '/', mt3.type_name, '/', mt4.type_name )
ELSE NULL
END AS groupName,
m.publish_user as publishUser,
m.area_id as areaId,
b.name as areaName
FROM
ma_lease_info m
LEFT JOIN bm_company_info c ON m.company_id = c.company_id
LEFT JOIN base_address b ON b.id = m.area_id
LEFT JOIN ma_hot_search h ON h.lease_id = m.id
LEFT JOIN ma_type mt4 ON mt4.type_id = m.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 1 = 1
<if test="id != null">
and m.id = #{id}
</if>
<if test="leaseCode != null and leaseCode != ''">
and m.lease_code = #{leaseCode}
</if>
<if test="leaseName != null and leaseName != ''">
and m.lease_name = #{leaseName}
</if>
</select>
<select id="selectTaskNumByMonth" resultType="java.lang.String">
SELECT SUBSTRING(lease_code, - 4) as code
FROM ma_lease_info
WHERE DATE_FORMAT(create_time, '%y%m') = DATE_FORMAT(#{date}, '%y%m')
ORDER BY create_time DESC LIMIT 1
</select>
<select id="list" resultType="com.bonus.material.lease.domain.vo.MaLeaseVo">
SELECT
m.id as id,
m.lease_name as leaseName,
m.lease_code as leaseCode,
m.company_id as companyId,
c.company_name as companyName,
c.operate_address as operateAddress,
m.lease_status as leaseStatus,
m.start_time as startTime,
m.end_time as endTime,
CASE
WHEN lease_status = 0 THEN '待接单'
WHEN lease_status = 1 THEN '已接单'
WHEN lease_status = 2 THEN '已到期'
ELSE '未知'
END
AS leaseStatusName,
su.nick_name as publishUser
FROM
ma_lease_info m
LEFT JOIN bm_company_info c ON m.company_id = c.company_id
LEFT JOIN sys_user su ON m.publish_user = su.user_id
WHERE 1 = 1 and m.create_by = #{createBy}
<if test="leaseCode != null and leaseCode != ''">
and m.lease_code like concat('%',#{leaseCode},'%')
</if>
<if test="leaseName != null and leaseName != ''">
and m.lease_name like concat('%',#{leaseName},'%')
</if>
<if test="leaseStatus != null">
and m.lease_status = #{leaseStatus}
</if>
<if test="publishStartTime != null and publishStartTime != '' and publishEndTime != null and publishEndTime != ''">
and DATE_FORMAT(m.start_time,'%Y-%m-%d') between #{publishStartTime} and #{publishEndTime}
</if>
<if test="finishStartTime != null and finishStartTime != '' and finishEndTime != null and finishEndTime != ''">
and DATE_FORMAT(m.end_time,'%Y-%m-%d') between #{finishStartTime} and #{finishEndTime}
</if>
GROUP BY m.lease_code
ORDER BY m.start_time DESC
</select>
<select id="getHotSearchCountByLeaseId" resultType="java.lang.Integer">
select count(1) from ma_hot_search
where lease_id = #{leaseId}
</select>
<select id="leaseList" resultType="com.bonus.material.lease.domain.vo.MaLeaseVo">
SELECT
m.id as id,
m.lease_name as leaseName,
m.lease_code as leaseCode,
m.type_id as typeId,
mt4.type_name as typeName,
m.company_id as companyId,
c.company_name as companyName,
c.operate_address as operateAddress,
m.lease_status as leaseStatus,
m.lease_day as leaseDay,
m.lease_num as leaseNum,
m.start_time as startTime,
m.end_time as endTime,
m.person as person,
m.person_phone as personPhone,
m.description as description,
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,
CASE
-- 第一级
WHEN mt1.type_id IS NULL
AND mt2.type_id IS NULL
AND mt3.type_id IS NULL
AND mt4.type_id IS NOT NULL THEN
mt4.type_name
-- 第二级
WHEN mt1.type_id IS NULL
AND mt2.type_id IS NULL
AND mt3.type_id IS NOT NULL
AND mt4.type_id IS NOT NULL THEN
CONCAT( mt3.type_name, '/', mt4.type_name )
-- 第三级
WHEN mt1.type_id IS NULL
AND mt2.type_id IS NOT NULL
AND mt3.type_id IS NOT NULL
AND mt4.type_id IS NOT NULL THEN
CONCAT( mt2.type_name, '/', mt3.type_name, '/', mt4.type_name )
-- 第四级
WHEN mt1.type_id IS NOT NULL
AND mt2.type_id IS NOT NULL
AND mt3.type_id IS NOT NULL
AND mt4.type_id IS NOT NULL THEN
CONCAT( mt1.type_name, '/', mt2.type_name, '/', mt3.type_name, '/', mt4.type_name )
ELSE NULL
END AS groupName,
m.publish_user as publishUser,
b.id as areaId,
b.name as areaName,
su1.nick_name as orderUser,
su1.phonenumber as orderPhone
FROM
ma_lease_info m
LEFT JOIN bm_company_info c ON m.company_id = c.company_id
LEFT JOIN base_address b ON b.id = m.area_id
LEFT JOIN sys_user su ON m.publish_user = su.user_id
LEFT JOIN sys_user su1 ON m.order_user = su1.user_id
LEFT JOIN ma_type mt4 ON mt4.type_id = m.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 m.lease_status = '0'
<if test="typeId != null">
<choose>
<when test="level != null and level == 4">
and m.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 = 1
OR mt2.type_id = 1
OR mt3.type_id = 1
OR mt4.type_id = 1
)
</when>
</choose>
</if>
<if test="companyId != null and companyId != ''"> and m.company_id = #{companyId}</if>
<if test="areaId != null"> and m.area_id = #{areaId}</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},m.lease_name) > 0
)
</if>
GROUP BY m.lease_code
ORDER BY
m.lease_status
<if test="startTime != '' and startTime == 'ASC'">
,m.start_time
</if>
<if test="startTime != '' and startTime == 'DESC'">
,m.start_time DESC
</if>
<if test="rentDay != null and rentDay == 'ASC'">
,m.lease_day
</if>
<if test="rentDay != null and rentDay == 'DESC'">
,m.lease_day DESC
</if>
<if test="endTime != '' and endTime == 'ASC'">
,m.end_time
</if>
<if test="endTime != '' and endTime == 'DESC'">
,m.end_time DESC
</if>
<if test="rentNum != null and rentNum == 'ASC'">
,m.lease_num
</if>
<if test="rentNum != null and rentNum == 'DESC'">
,m.lease_num DESC
</if>
</select>
<select id="rentList" resultType="com.bonus.material.lease.domain.vo.MaLeaseVo">
SELECT
m.id as id,
m.lease_name as leaseName,
m.lease_code as leaseCode,
m.type_id as typeId,
m.company_id as companyId,
c.company_name as companyName,
c.operate_address as operateAddress,
m.lease_status as leaseStatus,
m.lease_day as leaseDay,
m.lease_num as leaseNum,
m.start_time as startTime,
m.end_time as endTime,
m.person as person,
m.person_phone as personPhone,
m.description as description,
su.nick_name as publishUser,
su1.nick_name as orderUser,
m.order_time as orderTime,
b.id as areaId,
b.name as areaName
FROM
ma_lease_info m
LEFT JOIN bm_company_info c ON m.company_id = c.company_id
LEFT JOIN base_address b ON b.id = m.area_id
LEFT JOIN sys_user su ON m.publish_user = su.user_id
LEFT JOIN sys_user su1 ON m.order_user = su1.user_id
WHERE 1 = 1 and m.order_user = #{orderUser} and m.lease_status = '1'
<if test="leaseCode != null and leaseCode != ''">
and m.lease_code like concat('%',#{leaseCode},'%')
</if>
<if test="leaseName != null and leaseName != ''">
and m.lease_name like concat('%',#{leaseName},'%')
</if>
<if test="finishStartTime != null and finishStartTime != '' and finishEndTime != null and finishEndTime != ''">
and DATE_FORMAT(m.end_time,'%Y-%m-%d') between #{finishStartTime} and #{finishEndTime}
</if>
<if test="orderStartTime != null and orderStartTime != '' and orderEndTime != null and orderEndTime != ''">
and DATE_FORMAT(m.order_time,'%Y-%m-%d') between #{orderStartTime} and #{orderEndTime}
</if>
GROUP BY m.lease_code
</select>
</mapper>