123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?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="cn.ezhizao.project.business.collection.mapper.BizCollectionDetailMapper">
- <!-- 基础的返回map 多表复杂的 自行组合 -->
- <resultMap id="BaseResultMap" type="cn.ezhizao.project.business.collection.domain.BizCollectionDetail">
- </resultMap>
- <resultMap id="DetailResultMap" type="cn.ezhizao.project.business.collection.domain.BizCollectionDetail">
- <id column="id" property="id"/>
- <result column="collection_id" property="collectionId"/>
- <result column="contract_id" property="contractId"/>
- <association property="bizCollection" column="collection_id" select="getCollection" javaType="cn.ezhizao.project.business.collection.domain.BizCollection" />
- <association property="bizArchiveInput" column="contract_id" select="getArchiveInput" javaType="cn.ezhizao.project.business.collection.domain.vo.ArchiveVo" />
- </resultMap>
- <select id="getCollection" resultType="cn.ezhizao.project.business.collection.domain.BizCollection">
- select *,user1.nick_name as applierName,user2.nick_name as verifyName from biz_collection
- left join sys_user user1 on user1.user_id = biz_collection.applier_id
- left join sys_user user2 on user2.user_id = biz_collection.verify_id
- where id = #{collection_id}
- </select>
- <select id="getArchiveInput" resultType="cn.ezhizao.project.business.collection.domain.vo.ArchiveVo">
- select * from biz_archive_input where id = #{contract_id}
- </select>
- <!--带条件的List查询-->
- <select id="getList" resultMap="BaseResultMap">
- <include refid="getListSql"/>
- </select>
- <!--带条件的List查询 数据总条数-->
- <select id="getTotal" resultType="java.lang.Integer">
- SELECT COUNT(1) FROM (<include refid="getListSql"/>) AS C
- </select>
- <sql id="getListSql">
- SELECT
- t1.id,
- t1.contract_detail_id,
- t1.collection_id,
- t1.collection_contract_id,
- t1.task_type_id,
- t1.company_id,
- t4.address_style,
- t4.fiction_address_id,
- t4.province,
- t4.city,
- t4.district,
- t4.belong_region,
- t4.remark as inputRemark,
- t1.remark,
- t1.contract_id,
- t1.arrive_amount,
- t4.amount as amount,
- t3.name AS company_name,
- t2.name AS task_type_name,
- (select sum(cd.arrive_amount) from biz_collection_detail cd left join biz_collection c on c.id = cd.collection_id
- where cd.contract_detail_id = t1.contract_detail_id
- and cd.deleted = 0 and t1.contract_id = cd.contract_id and c.status = 1) arrived
- FROM
- biz_collection_detail t1
- left join biz_collection c on c.id = t1.collection_id
- left join biz_task_type t2 on t2.id = t1.task_type_id
- LEFT JOIN
- biz_company t3 on t1.company_id = t3.id
- left join biz_archive_input_detail t4 on t4.id = t1.contract_detail_id
- <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
- t1.deleted = 0 AND
- <if test="id != null ">
- t1.id = #{id} AND
- </if>
- <if test="collectionId != null ">
- t1.collection_id = #{collectionId} AND
- </if>
- <if test="tenantId != null">
- t1.tenant_id = #{tenantId} AND
- </if>
- <if test="collectionIds != null and collectionIds.size > 0 ">
- collection_id in
- <foreach collection="collectionIds" index="index" item="item" separator="," open="(" close=")">
- #{item,jdbcType=BIGINT}
- </foreach>
- AND
- </if>
- <if test="contractDetailId != null">
- t1.contract_detail_id = #{contractDetailId} AND
- </if>
- <if test="verifyStatus != null">
- c.status = #{verifyStatus} AND
- </if>
- <if test="contractId != null ">
- t1.contract_id = #{contractId} AND
- </if>
- <if test="companyId != null ">
- t1.company_id = #{companyId} AND
- </if>
- <if test="taskTypeId != null ">
- t1.task_type_id = #{taskTypeId} AND
- </if>
- <if test="remark != null and remark != '' ">
- t1.remark = #{remark} AND
- </if>
- <if test="ids != null ">
- t1.contract_id IN
- <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
- #{item,jdbcType=BIGINT}
- </foreach>
- AND
- </if>
- </trim>
- </sql>
- <!--根据主表id,删除 为的是表单保存时,明细统一物理删除后,再统一插入-->
- <update id="remove">
- UPDATE biz_collection_detail
- SET deleted=1
- WHERE collection_id in
- <foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
- #{id}
- </foreach>
- </update>
- <!--根据主表id,删除 为的是表单保存时,明细统一物理删除后,再统一插入-->
- <delete id="physicallyDelete">
- DELETE FROM
- biz_collection_detail
- WHERE id > 0
- <if test="id != null">
- AND id = #{id}
- </if>
- <if test="collectionId != null">
- AND collection_id = #{collectionId}
- </if>
- </delete>
- <select id="getDetailList" resultMap="DetailResultMap">
- select detail.*,(select sum(cd.arrive_amount) from biz_collection_detail cd left join biz_collection c on c.id =
- cd.collection_id
- where cd.contract_detail_id = detail.contract_detail_id
- and cd.deleted = 0 and detail.contract_id = cd.contract_id and c.status = 1) arrived from biz_collection_detail
- detail
- LEFT JOIN biz_collection collection on collection.id = detail.collection_id
- LEFT JOIN biz_task_type t2 on t2.id = detail.task_type_id
- LEFT JOIN biz_archive_input_detail inputDetail on inputDetail.id = detail.contract_detail_id
- LEFT JOIN biz_archive_input input on input.id = inputDetail.contract_id
- LEFT JOIN biz_company company on detail.company_id = company.id
- left join sys_user user1 on user1.user_id = collection.verify_id
- left join sys_user user2 on user2.user_id = collection.applier_id
- <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
- detail.deleted = 0 AND collection.status = 1
- <if test="id != null ">
- AND detail.id = #{id}
- </if>
- <if test="collectionId != null ">
- AND detail.collection_id = #{collectionId}
- </if>
- <if test="tenantId != null">
- AND detail.tenant_id = #{tenantId}
- </if>
- <if test="collectionIds != null and collectionIds.size > 0 ">
- AND collection_id in
- <foreach collection="collectionIds" index="index" item="item" separator="," open="(" close=")">
- #{item,jdbcType=BIGINT}
- </foreach>
- </if>
- <if test="contractDetailId != null">
- AND detail.contract_detail_id = #{contractDetailId}
- </if>
- <if test="bizArchiveInput != null and bizArchiveInput.contractNo != null and bizArchiveInput.contractNo != ''">
- AND input.contract_no LIKE CONCAT('%', #{bizArchiveInput.contractNo},'%')
- </if>
- <if test="bizArchiveInput != null and bizArchiveInput.boss != null and bizArchiveInput.boss != ''">
- AND input.boss LIKE CONCAT('%', #{bizArchiveInput.boss},'%')
- </if>
- <if test="bizArchiveInput != null and bizArchiveInput.party != null and bizArchiveInput.party != ''">
- AND input.party LIKE CONCAT('%', #{bizArchiveInput.party},'%')
- </if>
- <if test="bizArchiveInput != null and bizArchiveInput.contractType != null">
- AND input.contract_type = #{bizArchiveInput.contractType}
- </if>
- <if test="bizCollection != null and bizCollection.verifyName != null and bizCollection.verifyName != ''">
- AND user1.nick_name LIKE CONCAT('%', #{bizCollection.verifyName},'%')
- </if>
- <if test="bizCollection != null and bizCollection.applierName != null and bizCollection.applierName != ''">
- AND user2.nick_name LIKE CONCAT('%', #{bizCollection.applierName},'%')
- </if>
- <if test="bizCollection != null and bizCollection.isProject != null">
- AND collection.is_project = #{bizCollection.isProject}
- </if>
- <if test="bizCollection != null and bizCollection.projectMainName != null and bizCollection.projectMainName != ''">
- AND collection.project_main_name LIKE CONCAT('%', #{bizCollection.projectMainName},'%')
- </if>
- <if test="bizCollection != null and bizCollection.projectName != null and bizCollection.projectName != ''">
- AND collection.project_name LIKE CONCAT('%', #{bizCollection.projectName},'%')
- </if>
- <if test="verifyStatus != null">
- AND collection.status = #{verifyStatus}
- </if>
- <if test="contractId != null ">
- AND detail.contract_id = #{contractId}
- </if>
- <if test="bizCollection != null and bizCollection.companyName != null and bizCollection.companyName != '' ">
- AND company.name LIKE CONCAT('%', #{bizCollection.companyName},'%')
- </if>
- <if test=" bizArchiveInput != null and bizArchiveInput.map != null and bizArchiveInput.map.receiptDateFilter != null">
- AND (
- DATE_FORMAT(collection.arrive_date,'%Y-%m-%d') >= #{bizArchiveInput.map.receiptDateFilter[0]}
- AND
- DATE_FORMAT(collection.arrive_date,'%Y-%m-%d') <= #{bizArchiveInput.map.receiptDateFilter[1]}
- )
- </if>
- <if test=" bizArchiveInput != null and bizArchiveInput.map != null and bizArchiveInput.map.actuallyDateFilter != null">
- AND(
- DATE_FORMAT(collection.actually_date,'%Y-%m-%d') >= #{bizArchiveInput.map.actuallyDateFilter[0]}
- AND
- DATE_FORMAT(collection.actually_date,'%Y-%m-%d') <= #{bizArchiveInput.map.actuallyDateFilter[1]}
- )
- </if>
- <if test="taskTypeId != null ">
- and detail.task_type_id = #{taskTypeId} AND
- </if>
- <if test="remark != null and remark != '' ">
- detail.remark = #{remark} AND
- </if>
- <if test="ids != null ">
- detail.contract_id IN
- <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
- #{item,jdbcType=BIGINT}
- </foreach>
- AND
- </if>
- </trim>
- order by detail.create_time desc
- </select>
- </mapper>
|