<?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.SaleOrderInfoMapper">
|
<resultMap id="BaseResultMap" type="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"/>
|
<result column="isupload" property="isupload" jdbcType="TINYINT"/>
|
<result column="uploadat" property="uploadat" jdbcType="TIMESTAMP"/>
|
<result column="returncode" property="returncode" jdbcType="VARCHAR"/>
|
</resultMap>
|
|
<resultMap id="OrderInfo" type="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"/>
|
</resultMap>
|
<resultMap id="DailySaleReportResultMap" type="com.gk.firework.Domain.Vo.DailySaleReport">
|
</resultMap>
|
<sql id="Base_Column_List">
|
<!-- -->
|
id, `code`, createdat, createdby, customer, idcardnum, salesperson, shop, boxnum, totalprice,
|
pay, `change`, `type`, returnflag, isupload, uploadat, returncode
|
</sql>
|
|
<select id="selectOrderByDirectionAndCustomer" resultMap="BaseResultMap">
|
select
|
saleorder.id,
|
saleorder.code,
|
saleorder.createdat,
|
saleorder.createdby,
|
saleorder.customer,
|
saleorder.idcardnum,
|
saleorder.salesperson,
|
saleorder.shop,
|
saleorder.boxnum,
|
saleorder.totalprice,
|
saleorder.pay,
|
saleorder.`change`,
|
saleorder.`type`,
|
saleorder.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="selectSaleRecord1" resultType="java.util.Map">
|
select
|
sod.directioncode,
|
sod.itemname,
|
so.shop,
|
customer.idcardnum identify,
|
so.createdat saletime
|
from saleorder as so
|
left join saleorderdetail as sod on so.code = sod.ordercode
|
left join customer as customer on customer.id = so.customer
|
<where>
|
<choose>
|
<when test="params.enterprisenumber != null and params.enterprisenumber != ''">
|
and so.companynumber = #{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.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.shop != null and params.shop">
|
and so.shop like concat("%",#{params.shop},"%")
|
</if>
|
<if test="params.itemname != null and params.itemname">
|
and sod.itemname like concat("%",#{params.itemname},"%")
|
</if>
|
<if test="params.directioncode != null and params.directioncode">
|
and sod.directioncode like concat("%",#{params.directioncode},"%")
|
</if>
|
<if test="params.enterprisename != null and params.enterprisename != ''">
|
and e.enterprisename like concat("%",#{params.enterprisename},"%")
|
</if>
|
<if test="params.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
</where>
|
order by saletime desc
|
</select>
|
<select id="selectSaleRecord2" resultType="java.util.Map">
|
SELECT
|
e.enterprisename,
|
e.enterprisenumber,
|
count(if(sod.returnflag = 1,true,null)) returnnum,
|
count(0) salenum,
|
max(so.createdat)
|
from saleorderdetail sod
|
LEFT JOIN saleorder as so on so.code = sod.ordercode
|
LEFT JOIN enterprise as e on e.enterprisenumber = so.companynumber and e.validflag = 1
|
<where>
|
<choose>
|
<when test="params.enterprisenumber != null and params.enterprisenumber != ''">
|
and so.companynumber = #{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.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.filterProvince != null and params.filterProvince != ''">
|
and e.province = #{params.filterProvince}
|
</if>
|
<if test="params.filterCity != null and params.filterCity != ''">
|
and e.city = #{params.filterCity}
|
</if>
|
<if test="params.filterDistrict != null and params.filterDistrict != ''">
|
and e.district = #{params.filterDistrict}
|
</if>
|
<if test="params.filterStreet != null and params.filterStreet != ''">
|
and e.street = #{params.filterStreet}
|
</if>
|
<if test="params.filterCommittee != null and params.filterCommittee != ''">
|
and e.committee = #{params.filterCommittee}
|
</if>
|
<if test="params.enterprisename != null and params.enterprisename != ''">
|
and e.enterprisename like concat("%",#{params.enterprisename},"%")
|
</if>
|
<if test="params.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
|
</where>
|
group by so.companynumber
|
</select>
|
<select id="selectSaleRecord3" resultType="java.util.Map">
|
SELECT
|
a.itemcode,
|
a.itemname,
|
a.salenum,
|
a.boxnumber,
|
round(a.salenum / a.boxnumber,2) boxnum,
|
a.saletime
|
from (
|
SELECT
|
count(sod.directioncode) salenum,
|
p.directioncode itemcode,
|
p.`name` itemname,
|
p.boxnumber,
|
max(sod.createdat) saletime
|
FROM product as p
|
left join saleorderdetail as sod on sod.itemcode = p.directioncode
|
LEFT JOIN saleorder as so on so.code = sod.ordercode
|
LEFT JOIN enterprise AS e ON e.enterprisenumber = so.companynumber
|
where p.isdel = 0
|
and e.enterprisestatus = 'ON'
|
and e.validflag = 1
|
<if test="params.enterprisename != null and params.enterprisename != ''">
|
and e.enterprisename like concat("%",#{params.enterprisename},"%")
|
</if>
|
<if test="params.enterprisenumber != null and params.enterprisenumber != ''">
|
and e.enterprisenumber = #{params.enterprisenumber}
|
</if>
|
<if test="params.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
<if test="params.safetysupervision != null and params.safetysupervision != ''">
|
and e.safetysupervision = #{params.safetysupervision}
|
</if>
|
<if test="params.filterProvince != null and params.filterProvince != ''">
|
and e.province = #{params.filterProvince}
|
</if>
|
<if test="params.filterCity != null and params.filterCity != ''">
|
and e.city = #{params.filterCity}
|
</if>
|
<if test="params.filterDistrict != null and params.filterDistrict != ''">
|
and e.district = #{params.filterDistrict}
|
</if>
|
<if test="params.filterStreet != null and params.filterStreet != ''">
|
and e.street = #{params.filterStreet}
|
</if>
|
<if test="params.filterCommittee != null and params.filterCommittee != ''">
|
and e.committee = #{params.filterCommittee}
|
</if>
|
<if test="params.starttime != null and params.starttime != ''">
|
and sod.createdat >= #{params.starttime}
|
</if>
|
<if test="params.endtime != null and params.endtime != ''">
|
and DATE_FORMAT(sod.createdat,'%Y-%m-%d') <= #{params.endtime}
|
</if>
|
<if test="params.itemname != null and params.itemname != ''">
|
and p.name like concat("%",#{params.itemname},"%")
|
</if>
|
<if test="params.itemcode != null and params.itemcode != ''">
|
and p.directioncode like concat("%",#{params.itemcode},"%")
|
</if>
|
group by p.directioncode
|
) as a
|
order by salenum desc
|
|
</select>
|
<select id="selectSaleRecord4" resultType="java.util.Map">
|
SELECT
|
so.companynumber,
|
e.province,
|
e.city,
|
e.district,
|
e.enterprisename,
|
cu.idcardnum identify,
|
cu.path,
|
cu.nation,
|
cu.`name` name,
|
count(0) num,
|
sum(sod.returnflag) returnnum,
|
max(sod.createdat) saletime
|
FROM
|
<choose>
|
<when test="params.directioncode != null and params.directioncode != ''">
|
(select so.*
|
from
|
(
|
select a.companynumber,cu.idcardnum,cu.id customerid
|
from saleorderdetail as b
|
left join saleorder as a on b.ordercode = a.code
|
left join customer as cu on cu.id = a.customer
|
where b.directioncode like concat("%",#{params.directioncode},"%")
|
GROUP BY a.companynumber,cu.idcardnum) as m
|
left join saleorder as so on so.companynumber = m.companynumber and so.customer = m.customerid)
|
as so
|
</when>
|
<otherwise>
|
saleorder as so
|
</otherwise>
|
</choose>
|
left join saleorderdetail as sod on so.`code` = sod.ordercode
|
left join customer as cu on cu.id = so.customer
|
left join enterprise as e on e.enterprisenumber = so.companynumber
|
<where>
|
e.validflag = 1
|
and e.enterprisestatus = 'ON'
|
<choose>
|
<when test="params.enterprisenumber != null and params.enterprisenumber != ''">
|
and (
|
so.companynumber = #{params.enterprisenumber}
|
<if test="params.subList != null and params.subList.size() > 0">
|
<foreach collection="params.subList" item="item" index="index" >
|
or so.companynumber = #{item}
|
</foreach>
|
</if>
|
|
)
|
|
</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.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
<if test="params.starttime != null and params.starttime != ''">
|
and so.createdat >= #{params.starttime}
|
</if>
|
<if test="params.filterProvince != null and params.filterProvince != ''">
|
and e.province = #{params.filterProvince}
|
</if>
|
<if test="params.filterCity != null and params.filterCity != ''">
|
and e.city = #{params.filterCity}
|
</if>
|
<if test="params.filterDistrict != null and params.filterDistrict != ''">
|
and e.district = #{params.filterDistrict}
|
</if>
|
<if test="params.filterStreet != null and params.filterStreet != ''">
|
and e.street = #{params.filterStreet}
|
</if>
|
<if test="params.filterCommittee != null and params.filterCommittee != ''">
|
and e.committee = #{params.filterCommittee}
|
</if>
|
<if test="params.endtime != null and params.endtime != ''">
|
and so.createdat <= #{params.endtime}
|
</if>
|
<if test="params.identify != null and params.identify != ''">
|
and cu.idcardnum like concat("%",#{params.identify},"%")
|
</if>
|
<if test="params.nation != null and params.nation != ''">
|
and cu.nation like concat("%",#{params.nation},"%")
|
</if>
|
|
<if test="params.isNeedUploadPhoto == 1">
|
and cu.nation is null and cu.path is null
|
</if>
|
<if test="params.isNeedUploadPhoto == -1">
|
and cu.nation is null and cu.path is not null
|
</if>
|
|
|
</where>
|
group by cu.idcardnum,so.companynumber
|
order by max(sod.createdat) DESC
|
</select>
|
<select id="getPurchaseDetailInUnit" resultType="com.gk.firework.Domain.SaleOrderDetailInfo">
|
select
|
sod.*
|
from
|
<choose>
|
<when test="params.directioncode != null and params.directioncode != ''">
|
(select so.*
|
from
|
(
|
select a.companynumber,cu.idcardnum,cu.id customerid
|
from saleorderdetail as b
|
left join saleorder as a on b.ordercode = a.code
|
left join customer as cu on cu.id = a.customer
|
where b.directioncode like concat("%",#{params.directioncode},"%")
|
GROUP BY a.companynumber,cu.idcardnum) as m
|
left join saleorder as so on so.companynumber = m.companynumber and so.customer = m.customerid)
|
as so
|
</when>
|
<otherwise>
|
saleorder as so
|
</otherwise>
|
</choose>
|
left join saleorderdetail sod on so.code = sod.ordercode
|
left join customer cu on cu.id = so.customer
|
where cu.idcardnum = #{params.identify}
|
and so.companynumber= #{params.enterprisenumber}
|
<if test="params.starttime != null and params.starttime != ''">
|
and so.createdat > #{params.starttime}
|
</if>
|
<if test="params.endtime != null and params.endtime != ''">
|
and DATE_FORMAT(so.createdat ,'%Y-%m-%d') <= #{params.endtime}
|
</if>
|
</select>
|
<select id="selectEarlyWarn" resultType="com.gk.firework.Domain.SaleOrderInfo">
|
SELECT
|
saleorder.customer,
|
count(detail.id) as boxnum
|
from saleorder AS saleorder
|
left join saleorderdetail as detail on detail.ordercode = saleorder.code
|
where
|
saleorder.createdat >= #{starttime}
|
and saleorder.createdat <= #{endtime}
|
GROUP BY saleorder.customer
|
HAVING count(detail.id) >= #{min} and count(detail.id) < #{max}
|
</select>
|
<select id="selectAlarm" resultType="com.gk.firework.Domain.SaleOrderInfo">
|
SELECT
|
saleorder.customer,
|
count(detail.id) as boxnum
|
from saleorder AS saleorder
|
left join saleorderdetail as detail on detail.ordercode = saleorder.code
|
where
|
saleorder.createdat >= #{starttime}
|
and saleorder.createdat <= #{endtime}
|
GROUP BY saleorder.customer
|
HAVING count(detail.id) >= #{max}
|
</select>
|
<select id="selectByCustomer" resultType="java.lang.Long">
|
SELECT
|
enterprise.id
|
FROM saleorder AS saleorder
|
LEFT JOIN enterprise on enterprise.enterprisenumber = saleorder.companynumber
|
WHERE
|
saleorder.customer = #{customid}
|
ORDER BY createdat DESC
|
LIMIT 1
|
</select>
|
<select id="selectDailySaleReport" resultMap="DailySaleReportResultMap">
|
SELECT
|
a.itemCode,
|
a.itemName,
|
a.createdat,
|
saleNum,
|
saleAmount,
|
returnNum,
|
returnAmount,
|
saleAmount - returnAmount AS turnover
|
FROM
|
(
|
SELECT
|
detail.itemcode AS itemCode,
|
detail.itemname AS itemName,
|
count( 1 ) AS saleNum,
|
SUM( productprice.price ) AS saleAmount,
|
so.createdat
|
FROM
|
saleorderdetail AS detail
|
LEFT JOIN saleorder AS so ON so.`code` = detail.ordercode
|
LEFT JOIN productprice ON productprice.companynumber = so.companynumber
|
AND productprice.itemcode = detail.itemcode
|
<where>
|
1=1
|
AND so.createdat >= #{condition.startDate}
|
AND so.createdat <= #{condition.endDate}
|
<if test="condition.companynumber != null and condition.companynumber != ''">
|
AND so.companynumber = #{condition.companynumber}
|
</if>
|
</where>
|
GROUP BY
|
detail.itemcode
|
) a
|
LEFT JOIN (
|
SELECT
|
detail.itemcode AS itemCode,
|
detail.itemname AS itemName,
|
count( 1 ) AS returnNum,
|
SUM( productprice.price ) AS returnAmount,
|
so.createdat
|
FROM
|
saleorderdetail AS detail
|
LEFT JOIN saleorder AS so ON so.`code` = detail.ordercode
|
LEFT JOIN productprice ON productprice.companynumber = so.companynumber
|
AND productprice.itemcode = detail.itemcode
|
<where>
|
1=1
|
AND so.createdat >= #{condition.startDate}
|
AND so.createdat <= #{condition.endDate}
|
<if test="condition.companynumber != null and condition.companynumber != ''">
|
AND so.companynumber = #{condition.companynumber}
|
</if>
|
AND detail.returnflag = 1
|
</where>
|
GROUP BY
|
detail.itemcode
|
) b ON a.itemCode = b.itemCode
|
</select>
|
<select id="selectDataGrid" resultMap="OrderInfo">
|
select
|
so.id,
|
so.`code`,
|
so.createdat,
|
so.createdby,
|
so.customer,
|
so.idcardnum,
|
so.salesperson,
|
so.shop,
|
so.boxnum,
|
so.totalprice,
|
so.pay,
|
so.`change`,
|
so.`type`,
|
so.returnflag
|
from saleorder as so
|
<where>
|
1=1
|
AND so.createdat >= #{condition.startDate}
|
AND so.createdat <= #{condition.endDate}
|
<if test="condition.companynumber != null and condition.companynumber != ''">
|
AND so.companynumber = #{condition.companynumber}
|
</if>
|
<if test="condition.code != null and condition.code != ''">
|
AND so.code = #{condition.code}
|
</if>
|
</where>
|
</select>
|
|
<select id="selectDetails" resultType="com.gk.firework.Domain.SaleOrderDetailInfo">
|
SELECT
|
sod.id,
|
sod.ordercode,
|
sod.itemcode,
|
sod.itemname,
|
sod.directioncode,
|
sod.price,
|
sod.specification,
|
sod.returnflag
|
from saleorderdetail as sod
|
where sod.ordercode = #{ordercode}
|
</select>
|
<select id="getEnterpriseSaleDetail" resultType="com.gk.firework.Domain.SaleOrderDetailInfo">
|
SELECT sod.*
|
from saleorderdetail as sod
|
LEFT JOIN saleorder as so on so.code = sod.ordercode
|
LEFT JOIN enterprise AS e ON e.enterprisenumber = so.companynumber
|
where so.companynumber = #{enterpriseNumber}
|
and sod.itemcode = #{itemcode}
|
and sod.createdat >= #{starttime}
|
and sod.createdat <= #{endtime}
|
</select>
|
|
<select id="selectEnterpriseEnterSellStore" resultType="java.util.Map">
|
SELECT
|
a.itemcode,
|
a.itemname,
|
a.salenum,
|
a.boxnumber,
|
round(a.salenum / a.boxnumber,2) boxnum,
|
a.saletime
|
from (
|
SELECT
|
count(sod.directioncode) salenum,
|
p.directioncode itemcode,
|
p.`name` itemname,
|
p.boxnumber,
|
max(sod.createdat) saletime
|
FROM product as p
|
left join saleorderdetail as sod on sod.itemcode = p.directioncode
|
LEFT JOIN saleorder as so on so.code = sod.ordercode
|
LEFT JOIN enterprise AS e ON e.enterprisenumber = so.companynumber
|
where p.isdel = 0
|
<if test="params.enterprisename != null and params.enterprisename != ''">
|
and e.enterprisename like concat("%",#{params.enterprisename},"%")
|
</if>
|
<if test="params.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
<if test="params.safetysupervision != null and params.safetysupervision != ''">
|
and e.safetysupervision = #{params.safetysupervision}
|
</if>
|
<if test="params.filterProvince != null and params.filterProvince != ''">
|
and e.province = #{params.filterProvince}
|
</if>
|
<if test="params.filterCity != null and params.filterCity != ''">
|
and e.city = #{params.filterCity}
|
</if>
|
<if test="params.filterDistrict != null and params.filterDistrict != ''">
|
and e.district = #{params.filterDistrict}
|
</if>
|
<if test="params.filterStreet != null and params.filterStreet != ''">
|
and e.street = #{params.filterStreet}
|
</if>
|
<if test="params.filterCommittee != null and params.filterCommittee != ''">
|
and e.committee = #{params.filterCommittee}
|
</if>
|
<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.itemname != null and params.itemname != ''">
|
and p.name like concat("%",#{params.itemname},"%")
|
</if>
|
<if test="params.itemcode != null and params.itemcode != ''">
|
and p.directioncode like concat("%",#{params.itemcode},"%")
|
</if>
|
group by p.directioncode
|
) as a
|
order by salenum desc
|
</select>
|
|
<select id="selectEnterpriseSaleNumber" resultType="decimal">
|
SELECT
|
IFNULL(SUM( salenum ),0)
|
FROM
|
(
|
SELECT
|
count( 1 )/ p.boxnumber AS salenum
|
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
|
<where>
|
so.companynumber = #{companyNumber}
|
<if test="starttime != null and starttime != ''">
|
and so.createdat >= #{starttime}
|
</if>
|
<if test="endtime != null and endtime != ''">
|
and so.createdat <= #{endtime}
|
</if>
|
</where>
|
GROUP BY
|
itemcode
|
) temp
|
</select>
|
<select id="selectCitySaleNumber" resultType="decimal">
|
SELECT
|
IFNULL(SUM(salenum ),0)
|
FROM
|
(
|
SELECT
|
count( 1 )/ p.boxnumber AS salenum
|
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.city = #{city}
|
and e.enterprisestatus = 'ON'
|
and e.validflag = 1
|
<if test="starttime != null and starttime != ''">
|
and so.createdat >= #{starttime}
|
</if>
|
<if test="endtime != null and endtime != ''">
|
and so.createdat <= #{endtime}
|
</if>
|
</where>
|
GROUP BY
|
itemcode
|
) temp
|
</select>
|
<select id="selectSameOrder" resultMap="BaseResultMap">
|
SELECT
|
saleorder.id,
|
saleorder.`code`,
|
saleorder.createdat,
|
saleorder.createdby,
|
saleorder.customer,
|
saleorder.idcardnum,
|
saleorder.salesperson,
|
saleorder.shop,
|
saleorder.boxnum,
|
saleorder.totalprice,
|
saleorder.pay,
|
saleorder.`change`,
|
saleorder.`type`,
|
saleorder.returnflag
|
FROM
|
saleorder AS saleorder
|
LEFT JOIN saleorderdetail AS detail ON saleorder.`code` = detail.ordercode
|
<where>
|
saleorder.companynumber = #{companyNumber}
|
and saleorder.customer = #{customerId}
|
and saleorder.boxnum = #{num}
|
and detail.directioncode IN
|
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</where>
|
|
</select>
|
<select id="selectAllDailySaleReport" resultType="java.util.Map">
|
SELECT
|
count(1) saleNum,
|
IFNULL(SUM(productprice.price),0) as saleAmount,
|
count( if(detail.returnflag = 1,1,null)) returnNum,
|
IFNULL(SUM( if(detail.returnflag = 1,productprice.price,null) ),0) returnAmount
|
FROM
|
saleorderdetail AS detail
|
LEFT JOIN saleorder AS so ON so.`code` = detail.ordercode
|
LEFT JOIN productprice ON productprice.companynumber = so.companynumber
|
AND productprice.itemcode = detail.itemcode
|
<where>
|
1=1
|
AND so.createdat >= #{condition.startDate}
|
AND so.createdat <= #{condition.endDate}
|
<if test="condition.companynumber != null and condition.companynumber != ''">
|
AND so.companynumber = #{condition.companynumber}
|
</if>
|
</where>
|
|
</select>
|
<select id="selectProductSales" resultType="java.util.Map">
|
|
select round(ifnull(sum(saledata.boxnum) ,0),2) sales
|
from (
|
select p.directioncode,ifnull(count(0)/p.boxnumber,0) boxnum
|
from product as p
|
left join saleorderdetail as sod on p.directioncode = sod.itemcode
|
left join saleorder as so on sod.ordercode = so.code
|
left join enterprise as e on e.enterprisenumber = so.companynumber
|
where p.isdel = 0
|
and e.enterprisestatus = 'ON'
|
and e.validflag = 1
|
<if test="params.enterprisename != null and params.enterprisename != ''">
|
and e.enterprisename like concat("%",#{params.enterprisename},"%")
|
</if>
|
<if test="params.enterprisenumber != null and params.enterprisenumber != ''">
|
and e.enterprisenumber = #{params.enterprisenumber}
|
</if>
|
<if test="params.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
<if test="params.safetysupervision != null and params.safetysupervision != ''">
|
and e.safetysupervision = #{params.safetysupervision}
|
</if>
|
<if test="params.filterProvince != null and params.filterProvince != ''">
|
and e.province = #{params.filterProvince}
|
</if>
|
<if test="params.filterCity != null and params.filterCity != ''">
|
and e.city = #{params.filterCity}
|
</if>
|
<if test="params.filterDistrict != null and params.filterDistrict != ''">
|
and e.district = #{params.filterDistrict}
|
</if>
|
<if test="params.filterStreet != null and params.filterStreet != ''">
|
and e.street = #{params.filterStreet}
|
</if>
|
<if test="params.filterCommittee != null and params.filterCommittee != ''">
|
and e.committee = #{params.filterCommittee}
|
</if>
|
<if test="params.starttime != null and params.starttime != ''">
|
and sod.createdat >= #{params.starttime}
|
</if>
|
<if test="params.endtime != null and params.endtime != ''">
|
and DATE_FORMAT(sod.createdat,'%Y-%m-%d') <= #{params.endtime}
|
</if>
|
<if test="params.itemname != null and params.itemname != ''">
|
and p.name like concat("%",#{params.itemname},"%")
|
</if>
|
<if test="params.itemcode != null and params.itemcode != ''">
|
and p.directioncode like concat("%",#{params.itemcode},"%")
|
</if>
|
group by p.directioncode
|
) as saledata
|
|
|
</select>
|
<select id="selectCitySales" resultType="java.math.BigDecimal">
|
select ifnull(sum(saleorder.totalprice),0)/10000 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 = #{city}
|
<if test="starttime != null and starttime != ''">
|
and saleorder.createdat >= #{starttime}
|
</if>
|
<if test="endtime != null and endtime != ''">
|
and saleorder.createdat <= #{endtime}
|
</if>
|
|
</select>
|
<select id="selectSaleAllPerson" resultType="java.lang.Integer">
|
|
select
|
count(0) num
|
from (
|
SELECT
|
cu.idcardnum
|
FROM
|
<choose>
|
<when test="params.directioncode != null and params.directioncode != ''">
|
(select so.*
|
from
|
(
|
select a.companynumber,cu.idcardnum,cu.id customerid
|
from saleorderdetail as b
|
left join saleorder as a on b.ordercode = a.code
|
left join customer as cu on cu.id = a.customer
|
where b.directioncode like concat("%",#{params.directioncode},"%")
|
GROUP BY a.companynumber,cu.idcardnum) as m
|
left join saleorder as so on so.companynumber = m.companynumber and so.customer = m.customerid)
|
as so
|
</when>
|
<otherwise>
|
saleorder as so
|
</otherwise>
|
</choose>
|
left join saleorderdetail as sod on so.`code` = sod.ordercode
|
left join customer as cu on cu.id = so.customer
|
left join enterprise as e on e.enterprisenumber = so.companynumber
|
<where>
|
e.validflag = 1
|
and e.enterprisestatus = 'ON'
|
<choose>
|
<when test="params.enterprisenumber != null and params.enterprisenumber != ''">
|
and (
|
so.companynumber = #{params.enterprisenumber}
|
<if test="params.subList != null and params.subList.size() > 0">
|
<foreach collection="params.subList" item="item" index="index" >
|
or so.companynumber = #{item}
|
</foreach>
|
</if>
|
|
)
|
|
</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.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
<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.identify != null and params.identify != ''">
|
and cu.idcardnum like concat("%",#{params.identify},"%")
|
</if>
|
<if test="params.nation != null and params.nation != ''">
|
and cu.nation like concat("%",#{params.nation},"%")
|
</if>
|
<if test="params.isNeedUploadPhoto == 1">
|
and cu.nation is null and cu.path is null
|
</if>
|
<if test="params.isNeedUploadPhoto == -1">
|
and cu.nation is null and cu.path is not null
|
</if>
|
<if test="params.filterProvince != null and params.filterProvince != ''">
|
and e.province = #{params.filterProvince}
|
</if>
|
<if test="params.filterCity != null and params.filterCity != ''">
|
and e.city = #{params.filterCity}
|
</if>
|
<if test="params.filterDistrict != null and params.filterDistrict != ''">
|
and e.district = #{params.filterDistrict}
|
</if>
|
<if test="params.filterStreet != null and params.filterStreet != ''">
|
and e.street = #{params.filterStreet}
|
</if>
|
<if test="params.filterCommittee != null and params.filterCommittee != ''">
|
and e.committee = #{params.filterCommittee}
|
</if>
|
|
|
|
</where>
|
group by cu.idcardnum
|
) as res
|
|
</select>
|
<select id="selectAllSaleNum" resultType="java.lang.Integer">
|
SELECT
|
ifnull(sum(1),0)
|
FROM
|
<choose>
|
<when test="params.directioncode != null and params.directioncode != ''">
|
(select so.*
|
from
|
(
|
select a.companynumber,cu.idcardnum,cu.id customerid
|
from saleorderdetail as b
|
left join saleorder as a on b.ordercode = a.code
|
left join customer as cu on cu.id = a.customer
|
where b.directioncode like concat("%",#{params.directioncode},"%")
|
GROUP BY a.companynumber,cu.idcardnum) as m
|
left join saleorder as so on so.companynumber = m.companynumber and so.customer = m.customerid)
|
as so
|
</when>
|
<otherwise>
|
saleorder as so
|
</otherwise>
|
</choose>
|
left join saleorderdetail as sod on so.`code` = sod.ordercode
|
left join customer as cu on cu.id = so.customer
|
left join enterprise as e on e.enterprisenumber = so.companynumber
|
<where>
|
e.validflag = 1
|
and e.enterprisestatus = 'ON'
|
<choose>
|
<when test="params.enterprisenumber != null and params.enterprisenumber != ''">
|
and (
|
so.companynumber = #{params.enterprisenumber}
|
<if test="params.subList != null and params.subList.size() > 0">
|
<foreach collection="params.subList" item="item" index="index" >
|
or so.companynumber = #{item}
|
</foreach>
|
</if>
|
|
)
|
|
</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.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
<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.identify != null and params.identify != ''">
|
and cu.idcardnum like concat("%",#{params.identify},"%")
|
</if>
|
<if test="params.nation != null and params.nation != ''">
|
and cu.nation like concat("%",#{params.nation},"%")
|
</if>
|
<if test="params.isNeedUploadPhoto == 1">
|
and cu.nation is null and cu.path is null
|
</if>
|
<if test="params.isNeedUploadPhoto == -1">
|
and cu.nation is null and cu.path is not null
|
</if>
|
<if test="params.filterProvince != null and params.filterProvince != ''">
|
and e.province = #{params.filterProvince}
|
</if>
|
<if test="params.filterCity != null and params.filterCity != ''">
|
and e.city = #{params.filterCity}
|
</if>
|
<if test="params.filterDistrict != null and params.filterDistrict != ''">
|
and e.district = #{params.filterDistrict}
|
</if>
|
<if test="params.filterStreet != null and params.filterStreet != ''">
|
and e.street = #{params.filterStreet}
|
</if>
|
<if test="params.filterCommittee != null and params.filterCommittee != ''">
|
and e.committee = #{params.filterCommittee}
|
</if>
|
|
|
</where>
|
|
|
</select>
|
<select id="selectAllReturnNum" resultType="java.lang.Integer">
|
SELECT
|
ifnull( sum(sod.returnflag) ,0)
|
FROM
|
<choose>
|
<when test="params.directioncode != null and params.directioncode != ''">
|
(select so.*
|
from
|
(
|
select a.companynumber,cu.idcardnum,cu.id customerid
|
from saleorderdetail as b
|
left join saleorder as a on b.ordercode = a.code
|
left join customer as cu on cu.id = a.customer
|
where b.directioncode like concat("%",#{params.directioncode},"%")
|
GROUP BY a.companynumber,cu.idcardnum) as m
|
left join saleorder as so on so.companynumber = m.companynumber and so.customer = m.customerid)
|
as so
|
</when>
|
<otherwise>
|
saleorder as so
|
</otherwise>
|
</choose>
|
left join saleorderdetail as sod on so.`code` = sod.ordercode
|
left join customer as cu on cu.id = so.customer
|
left join enterprise as e on e.enterprisenumber = so.companynumber
|
<where>
|
e.validflag = 1
|
and e.enterprisestatus = 'ON'
|
<choose>
|
<when test="params.enterprisenumber != null and params.enterprisenumber != ''">
|
and (
|
so.companynumber = #{params.enterprisenumber}
|
<if test="params.subList != null and params.subList.size() > 0">
|
<foreach collection="params.subList" item="item" index="index" >
|
or so.companynumber = #{item}
|
</foreach>
|
</if>
|
|
)
|
|
</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.parententerprisename != null and params.parententerprisename != ''">
|
and e.parententerprisename like concat("%",#{params.parententerprisename},"%")
|
</if>
|
<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.identify != null and params.identify != ''">
|
and cu.idcardnum like concat("%",#{params.identify},"%")
|
</if>
|
<if test="params.nation != null and params.nation != ''">
|
and cu.nation like concat("%",#{params.nation},"%")
|
</if>
|
<if test="params.isNeedUploadPhoto == 1">
|
and cu.nation is null and cu.path is null
|
</if>
|
<if test="params.isNeedUploadPhoto == -1">
|
and cu.nation is null and cu.path is not null
|
</if>
|
<if test="params.filterProvince != null and params.filterProvince != ''">
|
and e.province = #{params.filterProvince}
|
</if>
|
<if test="params.filterCity != null and params.filterCity != ''">
|
and e.city = #{params.filterCity}
|
</if>
|
<if test="params.filterDistrict != null and params.filterDistrict != ''">
|
and e.district = #{params.filterDistrict}
|
</if>
|
<if test="params.filterStreet != null and params.filterStreet != ''">
|
and e.street = #{params.filterStreet}
|
</if>
|
<if test="params.filterCommittee != null and params.filterCommittee != ''">
|
and e.committee = #{params.filterCommittee}
|
</if>
|
|
|
</where>
|
</select>
|
</mapper>
|