| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- <?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.management.platform.mapper.BusinessOpportunityMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.management.platform.entity.BusinessOpportunity">
- <id column="id" property="id" />
- <result column="company_id" property="companyId" />
- <result column="name" property="name" />
- <result column="contacts_id" property="contactsId" />
- <result column="customer_id" property="customerId" />
- <result column="product_id" property="productId" />
- <result column="amount_of_money" property="amountOfMoney" />
- <result column="expected_transaction_date" property="expectedTransactionDate" />
- <result column="stage_id" property="stageId" />
- <result column="create_time" property="createTime" />
- <result column="edit_time" property="editTime" />
- <result column="creator_id" property="creatorId" />
- <result column="incharger_id" property="inchargerId" />
- <result column="remark" property="remark" />
- <result column="is_delete" property="isDelete" />
- <result column="plate1" property="plate1" />
- <result column="plate2" property="plate2" />
- <result column="plate3" property="plate3" />
- <result column="plate4" property="plate4" />
- <result column="plate5" property="plate5" />
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- id, company_id, name, contacts_id, customer_id, amount_of_money, expected_transaction_date, stage_id, create_time, edit_time, creator_id, incharger_id, remark, is_delete, plate1, plate2, plate3, plate4, plate5
- </sql>
- <select id="selectAllList" resultType="com.management.platform.entity.BusinessOpportunity">
- select
- <include refid="Base_Column_List"></include>,
- (select `name` from stage where id = stage_id) stageValue,
- (select custom_name from custom where id = customer_id) customerName,
- (select `name` from contacts where id = contacts_id) contactsName,
- (select `name` from `user` where id = incharger_id) inchargerName,
- (select `name` from `user` where id = creator_id) creatorName,
- (SELECT sum(total) from business_product WHERE business_id = id) total
- from business_opportunity
- where company_id = #{companyId}
- and is_delete = #{isDelete}
- <if test="name != null and name != ''">
- and `name` LIKE CONCAT('%', #{name}, '%')
- </if>
- <if test="inchargerId != null and inchargerId != '' ">
- and incharger_id = #{inchargerId}
- </if>
- <if test="startTime != null and endTime != null ">
- and create_time BETWEEN #{startTime} and #{endTime}
- </if>
- <if test="contactsName != null and contactsName != ''">
- and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{contactsName}, '%'))
- </if>
- <if test="customerName != null and customerName != ''">
- and customer_id in (select id from custom where `custom_name`LIKE CONCAT('%', #{customerName}, '%'))
- </if>
- <if test="stageId != null ">
- and stage_id = #{stageId}
- </if>
- <if test="productId != null ">
- and id in (select business_id from business_product where product_id = #{productId})
- </if>
- ORDER BY id DESC
- limit #{pageIndex},#{pageFrom}
- </select>
- <select id="getTotal" resultType="java.lang.Integer">
- select
- count(id)
- from business_opportunity
- where company_id = #{companyId}
- and is_delete = #{isDelete}
- <if test="name != null and name != ''">
- and `name` LIKE CONCAT('%', #{name}, '%')
- </if>
- <if test="inchargerId != null and inchargerId != ''">
- and incharger_id = #{inchargerId}
- </if>
- <if test="startTime != null and endTime != null ">
- and create_time BETWEEN #{startTime} and #{endTime}
- </if>
- <if test="contactsName != null and contactsName != ''">
- and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{contactsName}, '%'))
- </if>
- <if test="customerName != null and customerName != ''">
- and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{customerName}, '%'))
- </if>
- <if test="stageId != null ">
- and stage_id = #{stageId}
- </if>
- <if test="productId != null ">
- and id in (select business_id from business_product where product_id = #{productId})
- </if>
- </select>
- <select id="selectAllList1" resultType="com.management.platform.entity.BusinessOpportunity">
- select
- <include refid="Base_Column_List"></include>,
- (select `name` from stage where id = stage_id) stageValue,
- (select custom_name from custom where id = customer_id) customerName,
- (select `name` from contacts where id = contacts_id) contactsName,
- (select `name` from `user` where id = incharger_id) inchargerName,
- (select `name` from `user` where id = creator_id) creatorName,
- (SELECT sum(total) from business_product WHERE business_id = id)
- from business_opportunity
- where company_id = #{bo.companyId}
- and is_delete = #{bo.isDelete}
- and (incharger_id in
- (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{userId}))
- or incharger_id is null)
- <if test="bo.name != null and bo.name != ''">
- and `name` LIKE CONCAT('%', #{bo.name}, '%')
- </if>
- <if test="bo.inchargerId != null ">
- and incharger_id = #{bo.inchargerId}
- </if>
- <if test="bo.startTime != null and bo.endTime != null ">
- and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
- </if>
- <if test="bo.contactsName != null and bo.contactsName != ''">
- and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
- </if>
- <if test="bo.customerName != null and bo.customerName != ''">
- and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
- </if>
- <if test="bo.stageId != null ">
- and stage_id = #{bo.stageId}
- </if>
- <if test="bo.productId != null ">
- and id in (select business_id from business_product where product_id = #{bo.productId})
- </if>
- ORDER BY id DESC
- limit #{bo.pageIndex},#{bo.pageFrom}
- </select>
- <select id="getTotal1" resultType="java.lang.Integer">
- select
- count(id)
- from business_opportunity
- where company_id = #{bo.companyId}
- and is_delete = #{bo.isDelete}
- and (incharger_id in
- (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{userId}))
- or incharger_id is null)
- <if test="bo.name != null and bo.name != ''">
- and `name` LIKE CONCAT('%', #{bo.name}, '%')
- </if>
- <if test="bo.inchargerId != null ">
- and incharger_id = #{bo.inchargerId}
- </if>
- <if test="bo.startTime != null and bo.endTime != null ">
- and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
- </if>
- <if test="bo.contactsName != null and bo.contactsName != ''">
- and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
- </if>
- <if test="bo.customerName != null and bo.customerName != ''">
- and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
- </if>
- <if test="bo.stageId != null ">
- and stage_id = #{bo.stageId}
- </if>
- <if test="bo.productId != null ">
- and id in (select business_id from business_product where product_id = #{bo.productId})
- </if>
- </select>
- <select id="selectAllList2" resultType="com.management.platform.entity.BusinessOpportunity">
- select
- <include refid="Base_Column_List"></include>,
- (select `name` from stage where id = stage_id) stageValue,
- (select custom_name from custom where id = customer_id) customerName,
- (select `name` from contacts where id = contacts_id) contactsName,
- (select `name` from `user` where id = incharger_id) inchargerName,
- (select `name` from `user` where id = creator_id) creatorName,
- (SELECT sum(total) from business_product WHERE business_id = id)
- from business_opportunity
- where company_id = #{bo.companyId}
- and is_delete = #{bo.isDelete}
- and (incharger_id = #{userId} or incharger_id is null)
- <if test="bo.name != null and bo.name != ''">
- and `name` LIKE CONCAT('%', #{bo.name}, '%')
- </if>
- <if test="bo.inchargerId != null ">
- and incharger_id = #{bo.inchargerId}
- </if>
- <if test="bo.startTime != null and bo.endTime != null ">
- and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
- </if>
- <if test="bo.contactsName != null and bo.contactsName != ''">
- and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
- </if>
- <if test="bo.customerName != null and bo.customerName != ''">
- and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
- </if>
- <if test="bo.stageId != null ">
- and stage_id = #{bo.stageId}
- </if>
- <if test="bo.productId != null ">
- and id in (select business_id from business_product where product_id =#{bo.productId})
- </if>
- ORDER BY id DESC
- limit #{bo.pageIndex},#{bo.pageFrom}
- </select>
- <select id="getTotal2" resultType="java.lang.Integer">
- select
- count(id)
- from business_opportunity
- where company_id = #{bo.companyId}
- and is_delete = #{bo.isDelete}
- and (incharger_id = #{userId} or incharger_id is null)
- <if test="bo.name != null and bo.name != ''">
- and `name` LIKE CONCAT('%', #{bo.name}, '%')
- </if>
- <if test="bo.inchargerId != null ">
- and incharger_id = #{bo.inchargerId}
- </if>
- <if test="bo.startTime != null and bo.endTime != null ">
- and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
- </if>
- <if test="bo.contactsName != null and bo.contactsName != ''">
- and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
- </if>
- <if test="bo.customerName != null and bo.customerName != ''">
- and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
- </if>
- <if test="bo.stageId != null ">
- and stage_id = #{bo.stageId}
- </if>
- <if test="bo.productId != null ">
- and id in (select business_id from business_product where product_id = #{bo.productId})
- </if>
- </select>
- <select id="selectByIdToInfo" resultType="com.management.platform.entity.BusinessOpportunity">
- SELECT *,
- (select `name` from stage where id = stage_id) stageValue,
- (select custom_name from custom where id = customer_id) customerName,
- (select `name` from contacts where id = contacts_id) contactsName,
- (select `name` from `user` where id = incharger_id) inchargerName,
- (select `name` from `user` where id = creator_id) creatorName,
- (SELECT sum(total) from business_product WHERE business_id = id)
- from business_opportunity
- where id = #{id}
- </select>
- <select id="getDataSummary" resultType="java.util.Map">
- SELECT COUNT(*) newNum,SUM(bo.amount_of_money) AS allAmountOfMoney,SUM(s.name='赢单') winning,SUM(s.name='输单') losting FROM business_opportunity bo
- LEFT JOIN stage s ON bo.stage_id=s.id
- WHERE bo.company_id=#{companyId} and is_delete=0
- <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
- and DATE_FORMAT(bo.create_time,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
- </if>
- <if test="userId!=null and userId!=''">
- and incharger_id=#{userId}
- </if>
- <if test="list!=null and list.size()>0">
- and incharger_id in
- <foreach collection="list" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- </select>
- <select id="getDataStage" resultType="java.util.Map">
- SELECT IFNULL(s.name,'未分配') AS stageName,COUNT(1) AS num FROM business_opportunity bo
- LEFT JOIN stage s ON bo.stage_id=s.id
- WHERE bo.company_id=#{companyId} AND bo.is_delete=0
- <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
- and DATE_FORMAT(bo.create_time,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
- </if>
- <if test="userId!=null and userId!=''">
- and incharger_id=#{userId}
- </if>
- <if test="list!=null and list.size()>0">
- and incharger_id in
- <foreach collection="list" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- GROUP BY s.id
- </select>
- <select id="getAllList" resultType="com.management.platform.entity.BusinessOpportunity">
- select
- id,
- name
- from business_opportunity
- where company_id = #{companyId}
- and is_delete = 0
- </select>
- <select id="getAllList1" resultType="com.management.platform.entity.BusinessOpportunity">
- select
- id,
- name
- from business_opportunity
- where company_id = #{companyId}
- and is_delete = 0
- and (incharger_id in
- (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{id}))
- or incharger_id is null)
- </select>
- <select id="getAllList2" resultType="com.management.platform.entity.BusinessOpportunity">
- select id,
- name
- from business_opportunity
- where company_id = #{companyId}
- and is_delete = 0
- and (incharger_id = #{id} or incharger_id is null)
- </select>
- </mapper>
|