From 59e91a4e9ddaf23cebb12993c774aa899ab22d16 Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: Mon, 19 Jun 2023 14:22:45 +0800
Subject: [PATCH] 描述
---
src/main/java/com/gk/firework/Mapper/mybatis/SaleOrderDetailInfoMapper.xml | 1533 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 1,533 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/gk/firework/Mapper/mybatis/SaleOrderDetailInfoMapper.xml b/src/main/java/com/gk/firework/Mapper/mybatis/SaleOrderDetailInfoMapper.xml
new file mode 100644
index 0000000..7a71a74
--- /dev/null
+++ b/src/main/java/com/gk/firework/Mapper/mybatis/SaleOrderDetailInfoMapper.xml
@@ -0,0 +1,1533 @@
+<?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.gk.firework.Mapper.SaleOrderDetailInfoMapper">
+ <resultMap id="BaseResultMap" type="com.gk.firework.Domain.SaleOrderDetailInfo">
+ <!-- -->
+ <id column="id" property="id" jdbcType="BIGINT"/>
+ <result column="ordercode" property="ordercode" jdbcType="VARCHAR"/>
+ <result column="itemcode" property="itemcode" jdbcType="VARCHAR"/>
+ <result column="itemname" property="itemname" jdbcType="VARCHAR"/>
+ <result column="directioncode" property="directioncode" jdbcType="VARCHAR"/>
+ <result column="createdat" property="createdat" jdbcType="TIMESTAMP"/>
+ <result column="createdby" property="createdby" jdbcType="VARCHAR"/>
+ <result column="price" property="price" jdbcType="DECIMAL"/>
+ <result column="specification" property="specification" jdbcType="VARCHAR"/>
+ </resultMap>
+
+ <resultMap id="SaleDetailVo" type="com.gk.firework.Domain.Vo.SaleDetailVo">
+ <!-- -->
+ <id column="id" property="id" jdbcType="BIGINT"/>
+ <result column="ordercode" property="ordercode" jdbcType="VARCHAR"/>
+ <result column="itemcode" property="itemcode" jdbcType="VARCHAR"/>
+ <result column="itemname" property="itemname" jdbcType="VARCHAR"/>
+ <result column="directioncode" property="directioncode" jdbcType="VARCHAR"/>
+ <result column="createdat" property="createdat" jdbcType="TIMESTAMP"/>
+ <result column="createdby" property="createdby" jdbcType="VARCHAR"/>
+ <result column="price" property="price" jdbcType="DECIMAL"/>
+ <result column="specification" property="specification" jdbcType="VARCHAR"/>
+ <result column="returnflag" property="returnflag" jdbcType="TINYINT"/>
+ <association property="product" javaType="com.gk.firework.Domain.ProductInfo">
+ <id column="id" property="id" jdbcType="BIGINT" />
+ <result column="name" property="name" jdbcType="VARCHAR" />
+ <result column="directioncode" property="directionCode" jdbcType="VARCHAR" />
+ <result column="purchaseprice" property="purchasePrice" jdbcType="DECIMAL" />
+ <result column="saleprice" property="salePrice" jdbcType="DECIMAL" />
+ <result column="manufacturer" property="manufacturer" jdbcType="VARCHAR" />
+ <result column="specification" property="specification" jdbcType="VARCHAR" />
+ <result column="explosivecontent" property="explosiveContent" jdbcType="DECIMAL" />
+ <result column="type" property="type" jdbcType="VARCHAR" />
+ <result column="secondarytype" property="secondaryType" jdbcType="VARCHAR" />
+ <result column="level" property="level" jdbcType="VARCHAR" />
+ <result column="productdate" property="productDate" jdbcType="TIMESTAMP" />
+ <result column="boxnumber" property="boxNumber" jdbcType="INTEGER" />
+ <result column="packing" property="packing" jdbcType="VARCHAR" />
+ <result column="companynumber" property="companyNumber" jdbcType="VARCHAR" />
+ </association>
+ <association property="saleOrderInfo" javaType="com.gk.firework.Domain.SaleOrderInfo">
+ <id column="id" property="id" jdbcType="BIGINT"/>
+ <result column="code" property="code" jdbcType="VARCHAR"/>
+ <result column="createdat" property="createdat" jdbcType="TIMESTAMP"/>
+ <result column="createdby" property="createdby" jdbcType="VARCHAR"/>
+ <result column="customer" property="customer" jdbcType="BIGINT"/>
+ <result column="idcardnum" property="idcardnum" jdbcType="VARCHAR"/>
+ <result column="salesperson" property="salesperson" jdbcType="VARCHAR"/>
+ <result column="shop" property="shop" jdbcType="VARCHAR"/>
+ <result column="boxnum" property="boxnum" jdbcType="DECIMAL"/>
+ <result column="totalprice" property="totalprice" jdbcType="DECIMAL"/>
+ <result column="pay" property="pay" jdbcType="DECIMAL"/>
+ <result column="change" property="change" jdbcType="DECIMAL"/>
+ <result column="type" property="type" jdbcType="TINYINT"/>
+ <result column="returnflag" property="returnflag" jdbcType="TINYINT"/>
+ </association>
+ </resultMap>
+ <sql id="Base_Column_List">
+ <!-- -->
+ id, ordercode, itemcode, itemname, directioncode, createdat, createdby, price, specification, returnflag
+ </sql>
+ <insert id="saveBatchOrderDetailInfo">
+
+ insert
+ into saleorderdetail
+ <trim prefix="(" suffix=") values" suffixOverrides=",">
+ ordercode,
+ itemcode,
+ itemname,
+ directioncode,
+ createdat,
+ createdby,
+ price,
+ specification,
+ returnflag,
+ </trim>
+ <foreach collection="list" item="item" separator=",">
+ <trim prefix="(" suffix=")" suffixOverrides=",">
+ #{item.ordercode},
+ #{item.itemcode},
+ #{item.itemname},
+ #{item.directioncode},
+ #{item.createdat},
+ #{item.createdby},
+ #{item.price},
+ #{item.specification},
+ #{item.returnflag},
+ </trim>
+ </foreach>
+
+
+ </insert>
+
+ <select id="selectDetailByIdCardNum" resultMap="BaseResultMap">
+ select
+ detail.directioncode,
+ detail.itemname,
+ saleorder.createdat,
+ detail.price,
+ detail.specification,
+ customer.idcardnum
+ from saleorderdetail as detail
+ left join saleorder as saleorder on saleorder.`code` = detail.ordercode
+ LEFT JOIN customer as customer ON saleorder.customer = customer.id
+ <where>
+ customer.idcardnum = #{idCardNum}
+ </where>
+ </select>
+ <select id="selectDetailByIdCardNumAndDire" resultMap="BaseResultMap">
+ select
+ detail.directioncode,
+ detail.itemname,
+ saleorder.createdat,
+ detail.price,
+ detail.specification,
+ customer.idcardnum
+ from saleorderdetail as detail
+ left join saleorder as saleorder on saleorder.`code` = detail.ordercode
+ LEFT JOIN customer as customer ON saleorder.customer = customer.id
+ <where>
+ customer.idcardnum = #{idCardNum}
+ and detail.returnflag = 0
+ <if test="directionCode != null and directionCode != ''">
+ and detail.directioncode = #{directionCode}
+ </if>
+ </where>
+ </select>
+
+ <select id="selectOrderByDirectionAndCustomer" resultMap="BaseResultMap">
+ select
+ detail.id,
+ detail.ordercode,
+ detail.itemcode,
+ detail.itemname,
+ detail.directioncode,
+ detail.createdat,
+ detail.createdby,
+ detail.price,
+ detail.specification,
+ detail.returnflag
+ from saleorder as saleorder
+ left join saleorderdetail as detail on detail.ordercode = saleorder.code
+ <where>
+ detail.directioncode = #{directionCode}
+ and customer = #{customer}
+ </where>
+
+ </select>
+ <select id="selectDetailDataGridByIdCardNum" resultMap="BaseResultMap">
+ select
+ detail.directioncode,
+ detail.itemname,
+ saleorder.createdat,
+ detail.price,
+ detail.specification,
+ customer.idcardnum
+ from saleorderdetail as detail
+ left join saleorder as saleorder on saleorder.`code` = detail.ordercode
+ LEFT JOIN customer as customer ON saleorder.customer = customer.id
+ <where>
+ customer.idcardnum = #{condition.idCardNum}
+ and detail.returnflag = 0
+ <if test="condition.directionCode != null and condition.directionCode != ''">
+ and detail.directioncode = #{condition.directionCode}
+ </if>
+ </where>
+ </select>
+ <select id="selectByCustomId" resultType="com.gk.firework.Domain.Vo.SaleDetailVo">
+ select
+ detail.directioncode,
+ detail.itemname,
+ detail.createdat,
+ detail.price,
+ detail.specification,
+ detail.createdby,
+ saleorder.shop
+ from saleorderdetail as detail
+ left join saleorder as saleorder on saleorder.`code` = detail.ordercode
+ LEFT JOIN customer as customer ON saleorder.customer = customer.id
+ <where>
+ 1=1
+ <if test="condition.customid != null">
+ and saleorder.customer = #{condition.customid}
+ </if>
+ <if test="condition.starttime != null">
+ and detail.createdat >= #{condition.starttime}
+ </if>
+ <if test="condition.endtime != null">
+ and detail.createdat <= #{condition.endtime}
+ </if>
+ </where>
+ </select>
+
+ <select id="getSaleNumByCondition" resultType="decimal">
+ select sum(num) from (
+ select
+ (count(1)/product.boxnumber)as num
+ from
+ saleorderdetail as detail
+ left join saleorder as sale on sale.`code` = detail.ordercode
+ left join product on detail.itemcode = product.directioncode and product.isdel = 0
+ <where>
+ sale.createdat >= #{condition.beginDate}
+ and sale.createdat <= #{condition.endDate}
+ and sale.companynumber = #{condition.companyNumber}
+ <if test="condition.itemCode != null">
+ and product.directioncode = #{condition.itemCode}
+ </if>
+ </where>
+ group by sale.companynumber,
+ product.directioncode
+ )temp
+ </select>
+
+ <select id="getSaleDataInDays" resultType="java.util.Map">
+
+ select
+ days.day,
+ ifnull(info.salenum,0) salenum
+ from
+ <foreach collection="days" item="item" open="(" close=")" separator="union all">
+ SELECT date_sub(curdate(), interval #{item} day) as day
+ </foreach>
+ as days
+ left join (
+ select
+ date_format(detail.createdat,"%Y-%m-%d") saledate,
+ count(0) salenum
+ from
+ saleorderdetail as detail
+ <where>
+ <if test="starttime !=null">
+ and detail.createdat > #{starttime}
+ </if>
+ <if test="endtime !=null">
+ and detail.createdat < #{endtime}
+ </if>
+ </where>
+ group by DATE_FORMAT(detail.createdat,"%Y-%m-%d")
+ ) as info on info.saledate = days.day
+ order by days.day
+ </select>
+
+ <select id="getSaleDataAreaInDays" resultType="java.util.Map">
+ select
+ count(0) salenum,
+ e.city
+ from saleorder as saleorder
+ LEFT JOIN saleorderdetail as detail on detail.ordercode = saleorder.code
+ left join enterprise as e on e.enterprisenumber = saleorder.companynumber and e.validflag =1
+ <where>
+ e.province = #{params.province}
+ <if test="starttime !=null">
+ and detail.createdat > #{starttime}
+ </if>
+ <if test="endtime !=null">
+ and detail.createdat < #{endtime}
+ </if>
+ </where>
+ group by e.city
+
+ </select>
+ <select id="getSaleDataProductTypeInDays" resultType="java.util.Map">
+ select
+ count(0) salenum,
+ product.type producttype
+ from saleorderdetail as detail
+ left join product as product on product.directioncode = detail.itemcode and product.isdel = 0
+ <if test="starttime !=null">
+ and detail.createdat > #{starttime}
+ </if>
+ <if test="endtime !=null">
+ and detail.createdat < #{endtime}
+ </if>
+ group by product.type
+ </select>
+ <select id="getSaleDataInYear" resultType="java.util.Map">
+ select months.month, count(detail.month) as salenum
+ from
+ (select 1 as month union all
+ select 2 union all
+ select 3 union all
+ select 4 union all
+ select 5 union all
+ select 6 union all
+ select 7 union all
+ select 8 union all
+ select 9 union all
+ select 10 union all
+ select 11 union all
+ select 12) as months
+ left join
+ (SELECT
+ month(detail.createdat) as month
+ from saleorderdetail as detail
+ left join saleorder as so on so.code = detail.ordercode
+ left join enterprise as e on e.enterprisenumber = so.companynumber
+ where year(detail.createdat) = #{year}
+ <if test="province != null and province != ''">
+ and e.province = #{province}
+ </if>
+ <if test="city != null and city != ''">
+ and e.city = #{city}
+ </if>
+ ) as detail on months.month = detail.month
+ group by months.month
+ order by months.month
+ </select>
+ <select id="getInboundInYear" resultType="java.util.Map">
+ select months.month,
+ ifnull(detail.num,0) num
+ from (
+ select 1 as month union all
+ select 2 union all
+ select 3 union all
+ select 4 union all
+ select 5 union all
+ select 6 union all
+ select 7 union all
+ select 8 union all
+ select 9 union all
+ select 10 union all
+ select 11 union all
+ select 12) as months
+ left join (
+ select
+ month(entryorder.entrydate) month,
+ sum(entryorder.num) num
+ from entryorder as entryorder
+ left join enterprise as e on e.enterprisenumber = entryorder.companynumber
+ where year(entryorder.entrydate) = #{year}
+ <if test="province != null and province != ''">
+ and e.province = #{province}
+ </if>
+ <if test="city != null and city != ''">
+ and e.city = #{city}
+ </if>
+ group by month(entryorder.entrydate) ) as detail on months.month = detail.month
+ order by months.month
+
+ </select>
+ <select id="getSaleNumThisDay" resultType="java.lang.Integer">
+ select count(0)
+ from saleorderdetail as detail
+ left join saleorder as so on so.code = detail.ordercode
+ where
+ so.createdat BETWEEN CONCAT(CURDATE(),' 00:00:00') AND CONCAT(CURDATE(),' 23:59:59')
+ </select>
+ <select id="getSaleNumThisYear" resultType="java.lang.Integer">
+ select count(0)
+ from saleorderdetail as detail
+ left join saleorder as so on so.code = detail.ordercode
+ where
+ so.createdat > STR_TO_DATE(CONCAT(year(now()),'-01-01 ','00:00:00'),'%Y-%m-%d %H:%i:%s')
+ and so.createdat < now()
+ </select>
+ <select id="getPurchasersNum" resultType="java.lang.Integer">
+ select count(0)
+ from (
+ select so.customer
+ from saleorder as so
+ where so.createdat > STR_TO_DATE(CONCAT(year(now()),'-01-01 ','00:00:00'),'%Y-%m-%d %H:%i:%s')
+ and so.createdat < now()
+ group by so.customer)
+ as tmp
+ </select>
+ <select id="selectCityInAndOut" resultType="java.util.Map">
+
+ select
+ indata.name,
+ indata.innum,
+ saledata.salenum,
+ deliverydata.outnum,
+ ifnull(salesdata.sales,0)/10000 sales
+ from
+ (
+ select
+ citys.name,round(sum(if(citysale.num is null,0,num)),2) salenum
+ from (
+
+ select *
+ from district
+ where parentcode =(
+ select district.code
+ from district as district
+ where district.name = #{params.province}
+ and type = 1)
+ and type =2
+
+ ) as citys
+ left join (
+
+ SELECT
+ e.city,sod.itemcode ,count( 1 ) /p.boxnumber num
+ FROM
+ saleorderdetail AS sod
+ LEFT JOIN saleorder AS so ON so.`code` = sod.ordercode
+ LEFT JOIN product AS p ON p.directioncode = sod.itemcode and p.isdel = 0
+ LEFT JOIN enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and sod.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and sod.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ GROUP BY
+ so.companynumber,sod.itemcode
+
+ ) as citysale
+ on citys.name = citysale.city
+ group by citys.name
+ )
+ as saledata
+ left join (
+
+ select
+ citys.name,round(sum(if(cityentry.entrynum is null,0,cityentry.entrynum)),2) innum
+ from (
+
+ select *
+ from district
+ where parentcode =(
+ select district.code
+ from district as district
+ where district.name = #{params.province}
+ and type = 1)
+ and type =2
+
+ ) as citys
+ left join (
+ select
+ e.city,SUM( ed.num )/ p.boxnumber AS entrynum
+ FROM
+ entrydetail AS ed
+ LEFT JOIN entryorder AS eo ON eo.`code` = ed.entryorder
+ LEFT JOIN product AS p ON p.directioncode = ed.itemcode and p.isdel = 0
+ LEFT JOIN enterprise AS e ON eo.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and eo.createddate >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and eo.createddate < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ GROUP BY
+ eo.companynumber,ed.itemcode
+
+ )
+ as cityentry
+
+ on citys.name = cityentry.city
+ group by citys.name)
+
+ as indata on indata.name = saledata.name
+
+ left join (
+
+ select
+
+ citys.name,round(ifnull(sum(citydelivery.deliverynum),0),2) as outnum
+
+ from (
+
+ select *
+ from district
+ where parentcode =(
+ select district.code
+ from district as district
+ where district.name = #{params.province}
+ and type = 1)
+ and type =2
+
+
+ ) as citys
+
+ left join (
+
+ select e.city,sum(detail.num)/product.boxnumber as deliverynum
+ from deliverydetail as detail
+ left join deliveryorder as deliveryorder on deliveryorder.ordercode = detail.deliverycode
+ left join product as product ON detail.itemcode = product.directioncode and product.isdel = 0
+ left join enterprise as e on e.enterprisenumber = deliveryorder.companynumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and detail.createat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and detail.createat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ group by
+ deliveryorder.companynumber,detail.itemcode
+ ) as citydelivery on citydelivery.city = citys.name
+ group by citys.name
+ ) as deliverydata on deliverydata.name = indata.name
+
+ left join
+
+ (
+ select e.city,sum(saleorder.totalprice) sales
+ from saleorder as saleorder
+ left join enterprise as e on e.enterprisenumber = saleorder.companynumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and saleorder.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and saleorder.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ group by e.city
+ ) as salesdata on salesdata.city = indata.name
+
+
+
+ order by indata.innum desc,saledata.salenum desc
+
+ </select>
+ <select id="getGenderSale" resultType="java.util.Map">
+ select
+ genders.gender,
+ ifnull(saleinfo.sum,0) sum
+ from (
+ select '男' as gender
+ union
+ select '女'
+ ) as genders
+ left join (
+ select case customer.gender when 1 then '男' else '女' end gender,count(0) sum
+ from saleorder as so
+ left join saleorderdetail as detail on so.code = detail.ordercode
+ left join customer as customer on customer.id = so.customer
+ left join enterprise as e on e.enterprisenumber = so.companynumber
+ left join product as product on product.directioncode = detail.itemcode and product.isdel = 0
+ <where>
+ e.validflag = 1
+ and e.enterprisestatus = 'ON'
+ and customer.gender != 0
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename},"%")
+ </if>
+ <if test="params.productname != null and params.productname != ''">
+ and detail.itemname like concat("%",#{params.productname},"%")
+ </if>
+ <if test="params.producttype != null and params.producttype != ''">
+ and product.type = #{params.producttype}
+ </if>
+ <if test="params.secondarytype != null and params.secondarytype != ''">
+ and product.secondarytype = #{params.secondarytype}
+ </if>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province}
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city}
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district}
+ </if>
+ <if test="params.street!= null and params.street != ''">
+ and e.street = #{params.street}
+ </if>
+ <if test="params.committee != null and params.committee != ''">
+ and e.committee = #{params.committee}
+ </if>
+ <if test="params.starttime != null and params.starttime != ''">
+ and detail.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and detail.createdat < #{params.endtime}
+ </if>
+ </where>
+ group by customer.gender) as saleinfo on saleinfo.gender = genders.gender
+ </select>
+ <select id="getRaceSale" resultType="java.util.Map">
+ select
+ customer.nation,
+ count(0) sum
+ from saleorder as so
+ left join saleorderdetail as detail on so.code = detail.ordercode
+ left join customer as customer on customer.id = so.customer
+ left join enterprise as e on e.enterprisenumber = so.companynumber
+ left join product as product on product.directioncode = detail.itemcode and product.isdel = 0
+ where 1 = 1
+ and e.validflag = 1
+ and e.enterprisestatus = 'ON'
+ <choose>
+ <when test="params.enterprisenumber != null and params.enterprisenumber !=''">
+ and e.enterprisenumber = #{params.enterprisenumber}
+ </when>
+ <otherwise>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province}
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city}
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district}
+ </if>
+ <if test="params.street != null and params.street != ''">
+ and e.street = #{params.street}
+ </if>
+ <if test="params.committee != null and params.committee != ''">
+ and e.committee = #{params.committee}
+ </if>
+ </otherwise>
+ </choose>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename},"%")
+ </if>
+ <if test="params.productname != null and params.productname != ''">
+ and detail.itemname like concat("%",#{params.productname},"%")
+ </if>
+ <if test="params.producttype != null and params.producttype != ''">
+ and product.type = #{params.producttype}
+ </if>
+ <if test="params.secondarytype != null and params.secondarytype != ''">
+ and product.secondarytype = #{params.secondarytype}
+ </if>
+ <if test="params.provinceFilter != null and params.provinceFilter != ''">
+ and e.province = #{params.province}
+ </if>
+ <if test="params.cityFilter != null and params.cityFilter != ''">
+ and e.city = #{params.city}
+ </if>
+ <if test="params.districtFilter != null and params.districtFilter != ''">
+ and e.district = #{params.district}
+ </if>
+ <if test="params.streetFilter!= null and params.streetFilter != ''">
+ and e.street = #{params.street}
+ </if>
+ <if test="params.committeeFilter != null and params.committeeFilter != ''">
+ and e.committee = #{params.committee}
+ </if>
+ <if test="params.starttime != null and params.starttime != ''">
+ and detail.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and detail.createdat < #{params.endtime}
+ </if>
+ group by customer.nation
+ </select>
+ <select id="getSaleInfoByGeneration" resultType="java.lang.Integer">
+
+ select count(0)
+ from saleorder as so
+ left join saleorderdetail as detail on so.code = detail.ordercode
+ left join customer as customer on customer.id = so.customer
+ left join enterprise as e on e.enterprisenumber = so.companynumber
+ left join product as product on product.directioncode = detail.itemcode and product.isdel = 0
+ where 1 = 1
+ and e.validflag = 1
+ and e.enterprisestatus = 'ON'
+ <choose>
+ <when test="params.enterprisenumber != null and params.enterprisenumber !=''">
+ and e.enterprisenumber = #{params.enterprisenumber}
+ </when>
+ <otherwise>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province}
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city}
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district}
+ </if>
+ <if test="params.street != null and params.street != ''">
+ and e.street = #{params.street}
+ </if>
+ <if test="params.committee != null and params.committee != ''">
+ and e.committee = #{params.committee}
+ </if>
+ </otherwise>
+ </choose>
+ and (YEAR (now()) - YEAR (substring(customer.idcardnum, 7, 8))) >= #{params.head}
+ <if test="params.tail != null and params.tail != ''">
+ and (YEAR (now()) - YEAR (substring(customer.idcardnum, 7, 8))) < #{params.tail}
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename},"%")
+ </if>
+ <if test="params.productname != null and params.productname != ''">
+ and detail.itemname like concat("%",#{params.productname},"%")
+ </if>
+ <if test="params.producttype != null and params.producttype != ''">
+ and product.type = #{params.producttype}
+ </if>
+ <if test="params.secondarytype != null and params.secondarytype != ''">
+ and product.secondarytype = #{params.secondarytype}
+ </if>
+ <if test="params.provinceFilter != null and params.provinceFilter != ''">
+ and e.province = #{params.province}
+ </if>
+ <if test="params.cityFilter != null and params.cityFilter != ''">
+ and e.city = #{params.city}
+ </if>
+ <if test="params.districtFilter != null and params.districtFilter != ''">
+ and e.district = #{params.district}
+ </if>
+ <if test="params.streetFilter!= null and params.streetFilter != ''">
+ and e.street = #{params.street}
+ </if>
+ <if test="params.committeeFilter != null and params.committeeFilter != ''">
+ and e.committee = #{params.committee}
+ </if>
+ <if test="params.starttime != null and params.starttime != ''">
+ and detail.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and detail.createdat < #{params.endtime}
+ </if>
+
+
+ </select>
+ <select id="selectOneByDirectionCode" resultMap="SaleDetailVo">
+ select detail.*,so.*,product.*
+ from saleorderdetail as detail
+ left join saleorder as so on so.code = detail.ordercode
+ left join product as product on product.directioncode = detail.itemcode and product.isdel = 0
+ where detail.directioncode = #{directionCode}
+ and detail.returnflag = 0
+ </select>
+ <select id="selectOrderByDirectionReturnflag" resultType="com.gk.firework.Domain.SaleOrderDetailInfo">
+ select
+ detail.id,
+ detail.ordercode,
+ detail.itemcode,
+ detail.itemname,
+ detail.directioncode,
+ detail.createdat,
+ detail.createdby,
+ detail.price,
+ detail.specification,
+ detail.returnflag
+ from saleorder as saleorder
+ left join saleorderdetail as detail on detail.ordercode = saleorder.code
+ <where>
+ detail.directioncode = #{directionCode}
+ and detail.returnflag = #{returnflag}
+ <if test="datetime != null">
+ and saleorder.createdat <#{datetime}
+ </if>
+ </where>
+ group by createdat asc
+ limit 1
+ </select>
+ <select id="selectSaleNumInfo" resultType="com.gk.firework.Domain.Vo.SaleNumVo">
+ select
+ ifnull(round(count(0)/product.boxnumber,2),0 )num,
+ detail.itemcode,
+ product.*,
+ enterprise.enterprisenumber,
+ enterprise.enterprisename
+ from saleorderdetail as detail
+ left join saleorder as saleorder on saleorder.code = detail.ordercode
+ left join product as product on product.directioncode = detail.itemcode and product.isdel = 0
+ left join enterprise as enterprise on enterprise.enterprisenumber = saleorder.companynumber
+ <where>
+ <if test="params.enterprisename != null and params.enterprisename != '' ">
+ and enterprise.enterprisename = #{params.enterprisename}
+ </if>
+ <if test="params.enterprisenumber != null and params.enterprisenumber != '' ">
+ and saleorder.companynumber = #{params.enterprisename}
+ </if>
+ <if test="params.starttime != null and params.starttime != '' ">
+ and detail.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != '' ">
+ and detail.createdat <= #{params.endtime}
+ </if>
+ </where>
+ group by detail.itemcode
+ </select>
+ <select id="selectSaleNumInfoDetail" resultType="com.gk.firework.Domain.SaleOrderDetailInfo">
+
+ select detail.*
+ from saleorderdetail as detail
+ left join saleorder as saleorder on saleorder.code= detail.ordercode
+ left join enterprise as enterprise on enterprise.enterprisenumber = saleorder.companynumber
+ <where>
+ <if test="params.enterprisename != null and params.enterprisename != '' ">
+ and enterprise.enterprisename = #{params.enterprisename}
+ </if>
+ <if test="params.enterprisenumber != null and params.enterprisenumber != '' ">
+ and saleorder.companynumber = #{params.enterprisename}
+ </if>
+ <if test="params.starttime != null and params.starttime != '' ">
+ and detail.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != '' ">
+ and detail.createdat <= #{params.endtime}
+ </if>
+ <if test="params.itemcode != null and params.itemcode != '' ">
+ and detail.itemcode = #{params.itemcode}
+ </if>
+ </where>
+ order by detail.createdat desc
+ </select>
+ <select id="selectCityInAndOutDetail" resultType="java.util.Map">
+
+ select
+ e.enterprisename,
+ round(ifnull(saledata.salenum ,0),2) salenum,
+ round(ifnull(entrydata.entrynum,0),2) innum,
+ round(ifnull(deliverydata.deliverynum ,0),2) outnum,
+ ifnull(saleInfo.sales/10000,0) sales
+ from (
+ select
+ enterprisename,enterprisenumber
+ from enterprise as e
+ where e.validflag = 1
+ and e.enterprisestatus = 'ON'
+ and e.city = #{params.city}
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ ) as e
+ left join (
+
+
+ select
+ saledata.enterprisename,sum(saledata.num) salenum
+ from(
+
+ SELECT
+ e.enterprisename,so.companynumber ,sod.itemcode ,count( 1 ) /p.boxnumber num
+ FROM
+ saleorderdetail AS sod
+ LEFT JOIN saleorder AS so ON so.`code` = sod.ordercode
+ LEFT JOIN product AS p ON p.directioncode = sod.itemcode and p.isdel = 0
+ LEFT JOIN enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag = 1
+ and city = #{params.city}
+ <if test="params.starttime != null and params.starttime != ''">
+ and sod.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and sod.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ GROUP BY
+ so.companynumber ,sod.itemcode
+ ) as saledata
+ group by saledata.companynumber
+ ) as saledata on saledata.enterprisename = e.enterprisename
+
+ left join (
+
+ select
+ entrydata.enterprisename , sum(entrydata.entrynum) entrynum
+ from (
+ select
+ e.enterprisename,eo.companynumber,ed.itemcode,SUM( ed.num )/ p.boxnumber AS entrynum
+ FROM
+ entrydetail AS ed
+ LEFT JOIN entryorder AS eo ON eo.`code` = ed.entryorder
+ LEFT JOIN product AS p ON p.directioncode = ed.itemcode and p.isdel = 0
+ LEFT JOIN enterprise AS e ON eo.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag = 1
+ and city = #{params.city}
+ <if test="params.starttime != null and params.starttime != ''">
+ and eo.createddate >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and eo.createddate < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ GROUP BY
+ eo.companynumber,ed.itemcode
+ ) as entrydata
+ group by entrydata.companynumber
+ ) as entrydata on entrydata.enterprisename = e.enterprisename
+
+ left join (
+
+ select
+ deliverydata.enterprisename,sum(deliverydata.deliverynum) deliverynum
+ from (
+ select e.enterprisename,deliveryorder.companynumber,detail.itemcode,sum(detail.num)/product.boxnumber as deliverynum
+ from deliverydetail as detail
+ left join deliveryorder as deliveryorder on deliveryorder.ordercode = detail.deliverycode
+ left join product as product ON detail.itemcode = product.directioncode and product.isdel = 0
+ left join enterprise as e on e.enterprisenumber = deliveryorder.companynumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag = 1
+ and e.city = #{params.city}
+ <if test="params.starttime != null and params.starttime != ''">
+ and detail.createat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and detail.createat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ group by
+ deliveryorder.companynumber,detail.itemcode
+ ) as deliverydata
+ group by deliverydata.companynumber
+ ) as deliverydata on deliverydata.enterprisename = e.enterprisename
+
+ left join (
+
+ select e.enterprisename,sum(saleorder.totalprice) sales
+ from saleorder as saleorder
+ left join enterprise as e on e.enterprisenumber = saleorder.companynumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag = 1
+ and e.city = #{params.city}
+ <if test="params.starttime != null and params.starttime != ''">
+ and saleorder.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and saleorder.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ group by saleorder.companynumber
+
+ ) as saleInfo on saleInfo.enterprisename = e.enterprisename
+
+
+
+ </select>
+ <select id="selectCityTypeSale" resultType="java.util.Map">
+ select
+ citys.name,
+ ifnull(allperson.num,0) personnum
+ <foreach collection="list" item="item" index="index">
+ ,round(ifnull(num_${item},0),2) num_${item}
+ </foreach>,
+ round(
+ <trim suffixOverrides="+">
+ <foreach collection="list" item="item" index="index">
+ ifnull(alldata.num_${item},0) +
+ </foreach>
+ </trim>
+ ,2) totalcol
+ from (
+ select district.name
+ from district
+ where parentcode =(
+ select district.code
+ from district as district
+ where district.name = #{params.province}
+ and type = 1)
+ and type =2
+ ) as citys
+
+ left join (
+ select
+ tmptmptmp.city
+ <foreach collection="list" item="item" index="index">
+ ,MAX(
+ CASE tmptmptmp.type
+ WHEN #{item} THEN
+ tmptmptmp.num
+ ELSE
+ 0
+ END
+ ) num_${item}
+ </foreach>
+
+ from (
+
+ select
+ tmptmp.city,tmptmp.type,sum(tmptmp.num) num
+ from
+ (
+ SELECT
+ e.city,so.companynumber,p.type,count( 1 ) /p.
+ boxnumber num
+ FROM
+ saleorderdetail AS sod
+ LEFT JOIN
+ saleorder AS so ON so.`code` = sod.ordercode
+ LEFT JOIN product AS p ON p.directioncode = sod.itemcode
+ LEFT JOIN
+ enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.
+ enterprisestatus = 'ON'
+ and e.validflag=1
+ and p.isdel = 0
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ GROUP BY
+ so.companynumber,sod.itemcode
+
+ ) as tmptmp
+ group by tmptmp.city,tmptmp.type
+
+ ) as tmptmptmp
+ group by tmptmptmp.city
+ ) as alldata
+ on citys.name = alldata.city
+ left join (
+
+ select cc.city,count(0) num
+ from (
+ select e.city,so.customer
+ from saleorder as so
+ left join enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ AND e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ group by so.customer
+ ) as cc
+ group by cc.city
+
+ ) as allperson on citys.name = allperson.city
+ </select>
+ <select id="selectEnterpriseTypeSale" resultType="java.util.Map">
+ select
+ alldata.*,
+ ifnull(allperson.personnum,0) personnum,
+ round(
+ <trim suffixOverrides="+">
+ <foreach collection="list" item="item" index="index">
+ alldata.num_${item} +
+ </foreach>
+ </trim>
+ ,2) totalcol
+
+ from (
+
+ select
+ tmptmptmp.city name,
+ tmptmptmp.enterprisename
+ <foreach collection="list" item="item" index="index">
+ ,MAX(
+ CASE tmptmptmp.type
+ WHEN #{item} THEN
+ round(tmptmptmp.num,2)
+ ELSE
+ 0
+ END
+ ) num_${item}
+ </foreach>
+
+ from (
+
+ select
+ tmptmp.city,tmptmp.enterprisename,tmptmp.type,sum(tmptmp.num) num
+ from
+ (
+ SELECT
+ e.city,e.enterprisename,so.companynumber,p.type,count( 1 ) /p.
+ boxnumber num
+ FROM
+ saleorderdetail AS sod
+ LEFT JOIN
+ saleorder AS so ON so.`code` = sod.ordercode
+ LEFT JOIN product AS p ON p.directioncode = sod.itemcode
+ LEFT JOIN
+ enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag=1
+ and p.isdel = 0
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province }
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city }
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district }
+ </if>
+ GROUP BY
+ so.companynumber,sod.itemcode
+
+ ) as tmptmp
+ group by tmptmp.companynumber,tmptmp.type
+ ) as tmptmptmp
+ group by tmptmptmp.enterprisename)
+ as alldata
+ left join (
+
+ select cc.enterprisename,count(0) personnum
+ from (
+ select e.city,e.enterprisename,so.customer
+ from saleorder as so
+ left join enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ AND e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province }
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city }
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district }
+ </if>
+ group by so.companynumber,so.customer
+ ) as cc
+ group by cc.enterprisename
+ ) as allperson
+ on allperson.enterprisename = alldata.enterprisename
+ </select>
+ <select id="selectAllType" resultType="java.util.Map">
+ select
+ lasttmp.*,
+ othertmp.personnum,
+ round(
+ <trim suffixOverrides="+">
+ <foreach collection="list" item="item" index="index">
+ ifnull(lasttmp.num_${item},0) +
+ </foreach>
+ </trim>
+ ,2) totalcol
+ from (
+ select
+ '合计' name
+ <foreach collection="list" item="item" index="index">
+ ,MAX(
+ CASE tmptmptmp.type
+ WHEN #{item} THEN
+ round(tmptmptmp.num,2)
+ ELSE
+ 0
+ END
+ ) num_${item}
+ </foreach>
+ from (
+
+
+ select
+ tmptmp.type,sum(tmptmp.num) num
+ from
+ (
+ SELECT
+ e.city,so.companynumber,p.type,count( 1 ) /p.
+ boxnumber num
+ FROM
+ saleorderdetail AS sod
+ LEFT JOIN
+ saleorder AS so ON so.`code` = sod.ordercode
+ LEFT JOIN product AS p ON p.directioncode = sod.itemcode
+ LEFT JOIN
+ enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag=1
+ and p.isdel = 0
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province }
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city }
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district }
+ </if>
+ GROUP BY
+ so.companynumber,sod.itemcode
+
+ ) as tmptmp
+ group by tmptmp.type
+
+
+ ) as tmptmptmp
+ ) as lasttmp
+ left join
+ (
+ select '合计' name,sum(1) personnum
+ from (
+ select
+ count(0) num
+ from saleorder as so
+ left join enterprise AS e ON so.companynumber = e.enterprisenumber
+ WHERE
+ e.enterprisestatus = 'ON'
+ AND e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province }
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city }
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district }
+ </if>
+ group by so.customer
+ ) as cc
+
+ ) as othertmp
+ on othertmp.name = lasttmp.name
+
+
+ </select>
+ <select id="selectDistrictTypeSale" resultType="java.util.Map">
+ select
+ citys.name,
+ ifnull(allperson.num,0) personnum
+ <foreach collection="list" item="item" index="index">
+ ,round(ifnull(num_${item},0),2) num_${item}
+ </foreach>,
+ round(
+ <trim suffixOverrides="+">
+ <foreach collection="list" item="item" index="index">
+ ifnull(alldata.num_${item},0) +
+ </foreach>
+ </trim>
+ ,2) totalcol
+ from (
+ select district.name
+ from district
+ where parentcode =(
+ select district.code
+ from district as district
+ where district.name = #{params.city}
+ and type = 2)
+ and type =3
+ ) as citys
+
+ left join (
+ select
+ tmptmptmp.district
+ <foreach collection="list" item="item" index="index">
+ ,MAX(
+ CASE tmptmptmp.type
+ WHEN #{item} THEN
+ tmptmptmp.num
+ ELSE
+ 0
+ END
+ ) num_${item}
+ </foreach>
+
+ from (
+
+ select
+ tmptmp.district,tmptmp.type,sum(tmptmp.num) num
+ from
+ (
+ SELECT
+ e.district,so.companynumber,p.type,count( 1 ) /p.
+ boxnumber num
+ FROM
+ saleorderdetail AS sod
+ LEFT JOIN
+ saleorder AS so ON so.`code` = sod.ordercode
+ LEFT JOIN product AS p ON p.directioncode = sod.itemcode
+ LEFT JOIN
+ enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.
+ enterprisestatus = 'ON'
+ and e.validflag=1
+ and p.isdel = 0
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ GROUP BY
+ so.companynumber,sod.itemcode
+
+ ) as tmptmp
+ group by tmptmp.district,tmptmp.type
+
+ ) as tmptmptmp
+ group by tmptmptmp.district
+ ) as alldata
+ on citys.name = alldata.district
+ left join (
+
+ select cc.district,count(0) num
+ from (
+ select e.district,so.customer
+ from saleorder as so
+ left join enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ AND e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ group by so.customer
+ ) as cc
+ group by cc.district
+
+ ) as allperson on citys.name = allperson.district
+ </select>
+ <select id="selectAllDistrictType" resultType="java.util.Map">
+ select
+ lasttmp.*,
+ othertmp.personnum,
+ round(
+ <trim suffixOverrides="+">
+ <foreach collection="list" item="item" index="index">
+ ifnull(lasttmp.num_${item},0) +
+ </foreach>
+ </trim>
+ ,2) totalcol
+ from (
+ select
+ '合计' name
+ <foreach collection="list" item="item" index="index">
+ ,MAX(
+ CASE tmptmptmp.type
+ WHEN #{item} THEN
+ round(tmptmptmp.num,2)
+ ELSE
+ 0
+ END
+ ) num_${item}
+ </foreach>
+ from (
+ select
+ tmptmp.type,sum(tmptmp.num) num
+ from
+ (
+ SELECT
+ e.city,so.companynumber,p.type,count( 1 ) /p.
+ boxnumber num
+ FROM
+ saleorderdetail AS sod
+ LEFT JOIN
+ saleorder AS so ON so.`code` = sod.ordercode
+ LEFT JOIN product AS p ON p.directioncode = sod.itemcode
+ LEFT JOIN
+ enterprise AS e ON so.companynumber = e.enterprisenumber
+ where
+ e.enterprisestatus = 'ON'
+ and e.validflag=1
+ and p.isdel = 0
+ and e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province }
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city }
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district }
+ </if>
+ GROUP BY
+ so.companynumber,sod.itemcode
+ ) as tmptmp
+ group by tmptmp.type
+ ) as tmptmptmp
+ ) as lasttmp
+ left join
+ (
+ select '合计' name,sum(1) personnum
+ from (
+ select
+ e.city,
+ e.district,
+ count(0) num
+ from saleorder as so
+ left join enterprise AS e ON so.companynumber = e.enterprisenumber
+ WHERE
+ e.enterprisestatus = 'ON'
+ AND e.validflag = 1
+ <if test="params.starttime != null and params.starttime != ''">
+ and so.createdat >= #{params.starttime}
+ </if>
+ <if test="params.endtime != null and params.endtime != ''">
+ and so.createdat < #{params.endtime}
+ </if>
+ <if test="params.safetysupervision != null and params.safetysupervision != ''">
+ and e.safetysupervision = #{params.safetysupervision }
+ </if>
+ <if test="params.enterprisename != null and params.enterprisename != ''">
+ and e.enterprisename like concat("%",#{params.enterprisename },"%")
+ </if>
+ <if test="params.province != null and params.province != ''">
+ and e.province = #{params.province }
+ </if>
+ <if test="params.city != null and params.city != ''">
+ and e.city = #{params.city }
+ </if>
+ <if test="params.district != null and params.district != ''">
+ and e.district = #{params.district }
+ </if>
+ group by so.customer
+ ) as cc
+ <where>
+ 1=1
+ <if test="params.city != null and params.city != ''">
+ and cc.city = #{params.city }
+ </if>
+ </where>
+ GROUP BY
+ cc.city
+ ) as othertmp
+ on othertmp.name = lasttmp.name
+ </select>
+</mapper>
--
Gitblit v1.9.2