123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- <?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.dayou.mapper.ItemMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.dayou.vo.ItemVO">
- <result column="id" property="id" />
- <result column="deleted" property="deleted" />
- <result column="created" property="created" />
- <result column="modified" property="modified" />
- <result column="business_no" property="businessNo" />
- <result column="oa_no" property="oaNo" />
- <result column="name" property="name" />
- <result column="cate" property="cate" />
- <result column="business_source" property="businessSource" />
- <result column="belong_to" property="belongTo" />
- <result column="client_unit" property="clientUnit" />
- <result column="client_name" property="clientName" />
- <result column="mobile" property="mobile" />
- <result column="client_manager" property="clientManager" />
- <result column="skiller" property="skiller" />
- <result column="sign_date" property="signDate" />
- <result column="payment_method" property="paymentMethod" />
- <result column="amount" property="amount" />
- <result column="state" property="state" />
- <result column="department_id" property="departmentId" />
- <result column="contract_url" property="contractUrl" />
- <result column="user_id" property="userId" />
- <result column="customer_id" property="customerId" />
- <collection property="userIds" ofType="java.lang.Long" select="selectItemUserId" column="id"/>
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- i.id,
- i.deleted,
- i.created,
- i.modified,
- i.business_no, i.oa_no, i.name,i.cate, i.business_source,i.belong_to,i.client_unit,
- c.name as client_name, i.mobile, u.name as client_manager, i.skiller, i.sign_date, i.payment_method, i.amount, i.state,i.department_id,i.contract_url,i.user_id,i.customer_id
- </sql>
- <sql id="Common_query_item">
- SELECT
- <include refid="Base_Column_List"/>
- , d.name as departmentName,dd1.name as cateName,dd2.name as businessSourceName,
- (select name from item_stage s where curDate() >= s.start_date and curDate() <= s.end_date and s.item_id = i.id) as stageName,
- ( SELECT
- s.id
- FROM
- item_stage s
- WHERE
- curDate() >= s.start_date
- AND curDate() <= s.end_date
- AND s.item_id = i.id
- ) AS stageId,
- ( CASE when ((SELECT count(*) FROM item_stage s
- WHERE
- s.item_id = i.id
- AND curDate() >= ( SELECT min( start_date ) FROM item_stage WHERE item_id = i.id )
- AND curDate() <= ( SELECT max( end_date ) FROM item_stage WHERE item_id = i.id )
- )=0
- AND
- ( SELECT count(*) FROM item_stage s WHERE s.item_id = i.id ) !=0 )
- THEN
- '已完成'
- WHEN
- (SELECT
- count(*)
- FROM
- item_stage s
- WHERE
- s.item_id = i.id
- AND curDate() >= ( SELECT min( start_date ) FROM item_stage WHERE item_id = i.id )
- AND curDate() <= ( SELECT max( end_date ) FROM item_stage WHERE item_id = i.id ) )
- !=0
- THEN
- '进行中'
- WHEN
- (SELECT
- count(*)
- FROM
- item_stage s
- WHERE
- s.item_id = i.id)= 0
- THEN
- '未开始'
- ELSE ''
- END
- ) AS itemStatus
- FROM
- item i left join department d on i.department_id = d.id left join dict_data dd1 on i.cate = dd1.id
- left join dict_data dd2 on i.business_source = dd2.id left join user u on u.id = i.user_id left join customer c on c.id = i.customer_id
- where i.deleted = 0 and dd1.deleted =0 and dd2.deleted = 0
- </sql>
- <select id="stat" resultType="com.dayou.vo.ItemStatVO">
- SELECT
- ( SELECT count(*) FROM item WHERE state = '已完成' AND deleted = 0 ) AS doneNum,
- ( SELECT count(*) FROM item WHERE state = '进行中' AND deleted = 0 ) AS pendingNum,
- ( SELECT count(*) FROM item WHERE state = '未开始' AND deleted = 0 ) AS unplayedNum
- FROM
- item
- WHERE
- deleted =0
- </select>
- <select id="xDetail" parameterType="java.lang.Long" resultMap="BaseResultMap">
- select <include refid="Base_Column_List"/>, d.name as departmentName from item i left join department d on d.id = i.department_id left join user u on u.id = i.user_id where i.deleted = 0 and i.id =#{id}
- </select>
- <select id="selectItemUserId" parameterType="java.lang.Long" resultType="java.lang.Long">
- select user_id from item_user where item_id = #{id}
- </select>
- <select id="getPage" resultType="com.dayou.vo.ItemVO">
- <include refid="Common_query_item"/>
- <if test="item!=null and item.name!=null and item.name!='' ">
- and i.name like concat ('%',#{item.name},'%')
- </if>
- <if test="item!=null and item.cate!=null and item.cate!='' ">
- and i.cate =#{item.cate}
- </if>
- <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
- and i.business_no like concat (#{item.businessNo},'%')
- </if>
- <if test="item!=null and item.isCurYear!=null and item.isCurYear==true">
- AND i.sign_date >= concat( YEAR ( now())- 1, '-12-23' )
- AND i.sign_date <= concat( YEAR ( now()), '-12-22' )
- </if>
- <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
- and u.name like concat ('%',#{item.clientManager},'%')
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
- and i.user_id in
- <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- </if>
- <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- and i.department_id in
- <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- <if test="item!=null and item.state!=null and item.state!='' ">
- GROUP BY i.id
- HAVING itemStatus =#{item.state}
- </if>
- </select>
- <select id="getXPage" resultType="com.dayou.vo.ItemVO">
- <include refid="Common_query_item"/>
- <if test="item!=null and item.name!=null and item.name!='' ">
- and i.name like concat ('%',#{item.name},'%')
- </if>
- <if test="item!=null and item.cate!=null and item.cate!='' ">
- and i.cate =#{item.cate}
- </if>
- <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
- and i.business_no like concat (#{item.businessNo},'%')
- </if>
- <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
- and u.name like concat ('%',#{item.clientManager},'%')
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size==0">
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
- and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
- <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- )
- </if>
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size==0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- and i.department_id in
- <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- and (
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
- EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
- <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- )
- </if>
- <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- or i.department_id in
- <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- )
- </if>
- <if test="item!=null and item.state!=null and item.state!='' ">
- GROUP BY i.id
- HAVING itemStatus =#{item.state}
- </if>
- </select>
- <select id="xSelectList" parameterType="com.dayou.vo.ItemStageVO" resultType="com.dayou.vo.ItemVO">
- <include refid="Common_query_item"/>
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size==0">
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
- and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
- <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- )
- </if>
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size==0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- and i.department_id in
- <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- and (
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
- EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
- <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- )
- </if>
- <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- or i.department_id in
- <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- )
- </if>
- <if test="item!=null and item.state!=null and item.state!='' ">
- GROUP BY i.id
- HAVING itemStatus =#{item.state}
- </if>
- </select>
- <select id="getLastMonthItems" resultType="com.dayou.entity.ItemBrokerageGeneral">
- select ibg.*
- FROM
- item i
- left join item_brokerage_general ibg on ibg.item_id = i.id
- WHERE
- i.deleted = 0
- and i.upload_date is not null
- AND i.upload_date >= #{lastMonth23}
- AND i.upload_date <= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
- AND i.user_id = #{userId}
- and ibg.marketer_status=#{marketerStatus}
- </select>
- <select id="getLastMonthItemsInStatus" resultType="com.dayou.entity.ItemBrokerageGeneral">
- select ibg.*
- FROM
- item i
- left join item_brokerage_general ibg on ibg.item_id = i.id
- WHERE
- i.deleted = 0
- and i.upload_date is not null
- AND i.upload_date >= #{lastMonth23}
- AND i.upload_date <= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
- AND i.user_id = #{userId}
- and ibg.marketer_status in ('TO_PREDICTING','NOT_PAYMENT')
- </select>
- <select id="xList" resultType="com.dayou.vo.ItemVO">
- <include refid="Common_query_item"/>
- <if test="item!=null and item.name!=null and item.name!='' ">
- and i.name like concat ('%',#{item.name},'%')
- </if>
- <if test="item!=null and item.cate!=null and item.cate!='' ">
- and i.cate =#{item.cate}
- </if>
- <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
- and i.business_no like concat (#{item.businessNo},'%')
- </if>
- <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
- and u.name like concat ('%',#{item.clientManager},'%')
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size==0">
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
- and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
- <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- )
- </if>
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size==0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- and i.department_id in
- <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- and (
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
- EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
- <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- )
- </if>
- <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- or i.department_id in
- <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- )
- </if>
- <if test="item!=null and item.state!=null and item.state!='' ">
- GROUP BY i.id
- HAVING itemStatus =#{item.state}
- </if>
- order by i.id DESC
- </select>
- <select id="xMineList" resultType="com.dayou.vo.ItemVO">
- <include refid="Common_query_item"/>
- <if test="item!=null and item.name!=null and item.name!='' ">
- and i.name like concat ('%',#{item.name},'%')
- </if>
- <if test="item!=null and item.cate!=null and item.cate!='' ">
- and i.cate =#{item.cate}
- </if>
- <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
- and i.business_no like concat (#{item.businessNo},'%')
- </if>
- <if test="item!=null and item.isCurYear!=null and item.isCurYear==true">
- AND i.sign_date >= concat( YEAR ( now())- 1, '-12-23' )
- AND i.sign_date <= concat( YEAR ( now()), '-12-22' )
- </if>
- <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
- and u.name like concat ('%',#{item.clientManager},'%')
- </if>
- <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
- and i.user_id in
- <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- </if>
- <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
- and i.department_id in
- <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- <if test="item!=null and item.state!=null and item.state!='' ">
- GROUP BY i.id
- HAVING itemStatus =#{item.state}
- </if>
- order by i.id DESC
- </select>
- <select id="getItemByBrokerageGeneralId" parameterType="java.lang.Long" resultType="com.dayou.dto.ItemDTO">
- select <include refid="Base_Column_List"/>,ibg.brokerage_rate as ratio from item_brokerage_general ibg left join item i on i.id = ibg.item_id where i.deleted = 0 and ibg.deleted = 0 and ibg.id = #{generalId}
- </select>
- <select id="getLastMonthTeamItems" resultType="com.dayou.dto.ItemBrokerageGeneralDTO">
- select ibg.*,i.amount,i.user_id
- FROM
- item i
- left join item_brokerage_general ibg on ibg.item_id = i.id
- WHERE
- i.deleted = 0
- and i.upload_date is not null
- AND i.upload_date >= #{lastMonth23}
- AND i.upload_date <= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
- AND i.user_id in (
- <foreach collection="juniorUserIds" index="index" item="item" separator=",">
- #{item}
- </foreach>
- )
- and ibg.marketer_status != 'CLOSED'
- </select>
- </mapper>
|