优化单据的查询速度

This commit is contained in:
季圣华
2021-09-10 00:46:39 +08:00
parent 204e8dbe6a
commit fbcf6f9d1d

View File

@@ -167,7 +167,7 @@
<select id="findMaterialsListByHeaderId" resultType="java.lang.String"> <select id="findMaterialsListByHeaderId" resultType="java.lang.String">
select group_concat(concat(jsh_material.name,' ',ifnull(jsh_material.standard,''),' ',ifnull(jsh_material.model,''))) as mName select group_concat(concat(jsh_material.name,' ',ifnull(jsh_material.standard,''),' ',ifnull(jsh_material.model,''))) as mName
from jsh_depot_item from jsh_depot_item
inner join jsh_material on jsh_depot_item.material_id = jsh_material.Id and ifnull(jsh_material.delete_Flag,'0') !='1' left join jsh_material on jsh_depot_item.material_id = jsh_material.Id and ifnull(jsh_material.delete_Flag,'0') !='1'
where jsh_depot_item.header_id = #{id} where jsh_depot_item.header_id = #{id}
and ifnull(jsh_depot_item.delete_flag,'0') !='1' and ifnull(jsh_depot_item.delete_flag,'0') !='1'
</select> </select>
@@ -176,11 +176,11 @@
select dh.number,me.bar_code, m.`name` MName,m.model,m.standard,di.unit_price,di.material_unit as mUnit,di.oper_number,di.all_price,s.supplier SName,d.dName DName, select dh.number,me.bar_code, m.`name` MName,m.model,m.standard,di.unit_price,di.material_unit as mUnit,di.oper_number,di.all_price,s.supplier SName,d.dName DName,
date_format(dh.oper_time, '%Y-%m-%d') OperTime, concat(dh.sub_type,dh.type) as NewType, concat_ws(' ',dh.remark,di.remark) as newRemark date_format(dh.oper_time, '%Y-%m-%d') OperTime, concat(dh.sub_type,dh.type) as NewType, concat_ws(' ',dh.remark,di.remark) as newRemark
from jsh_depot_head dh from jsh_depot_head dh
inner join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1' left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
inner join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1' left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1' left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
inner join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1' left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
inner join (select id,name as dName,delete_Flag from jsh_depot ) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1' left join (select id,name as dName,delete_Flag from jsh_depot ) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<if test="oId != null"> <if test="oId != null">
and dh.organ_id = #{oId} and dh.organ_id = #{oId}
@@ -205,11 +205,11 @@
<select id="findByAllCount" resultType="java.lang.Integer"> <select id="findByAllCount" resultType="java.lang.Integer">
select count(1) select count(1)
from jsh_depot_head dh from jsh_depot_head dh
inner join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1' left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
inner join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1' left join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1'
left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1' left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
inner join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1' left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
inner join (select id,name as dName,delete_Flag from jsh_depot) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1' left join (select id,name as dName,delete_Flag from jsh_depot) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<if test="oId != null"> <if test="oId != null">
and dh.organ_id = #{oId} and dh.organ_id = #{oId}
@@ -231,7 +231,7 @@
<select id="findInOutMaterialCount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultInOutMaterialCount"> <select id="findInOutMaterialCount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultInOutMaterialCount">
select di.material_id, m.bar_code, m.mName,m.Model,m.standard,m.categoryName,m.materialUnit, select di.material_id, m.bar_code, m.mName,m.Model,m.standard,m.categoryName,m.materialUnit,
(select sum(jdi.basic_number) numSum from jsh_depot_head jdh (select sum(jdi.basic_number) numSum from jsh_depot_head jdh
INNER JOIN jsh_depot_item jdi on jdh.id=jdi.header_id and ifnull(jdi.delete_flag,'0') !='1' left JOIN jsh_depot_item jdi on jdh.id=jdi.header_id and ifnull(jdi.delete_flag,'0') !='1'
where jdi.material_id=di.material_id where jdi.material_id=di.material_id
and jdh.type=#{type} and jdh.oper_time >=#{beginTime} and jdh.oper_time &lt;=#{endTime} and jdh.type=#{type} and jdh.oper_time >=#{beginTime} and jdh.oper_time &lt;=#{endTime}
<if test="oId != null"> <if test="oId != null">
@@ -243,7 +243,7 @@
and ifnull(jdh.delete_flag,'0') !='1' and ifnull(jdh.delete_flag,'0') !='1'
) numSum, ) numSum,
(select sum(jdi.all_price) priceSum from jsh_depot_head jdh (select sum(jdi.all_price) priceSum from jsh_depot_head jdh
INNER JOIN jsh_depot_item jdi on jdh.id=jdi.header_id and ifnull(jdi.delete_flag,'0') !='1' left JOIN jsh_depot_item jdi on jdh.id=jdi.header_id and ifnull(jdi.delete_flag,'0') !='1'
where jdi.material_id=di.material_id where jdi.material_id=di.material_id
and jdh.type=#{type} and jdh.oper_time >=#{beginTime} and jdh.oper_time &lt;=#{endTime} and jdh.type=#{type} and jdh.oper_time >=#{beginTime} and jdh.oper_time &lt;=#{endTime}
<if test="oId != null"> <if test="oId != null">
@@ -255,13 +255,13 @@
and ifnull(jdh.delete_flag,'0') !='1' and ifnull(jdh.delete_flag,'0') !='1'
) priceSum ) priceSum
from jsh_depot_head dh from jsh_depot_head dh
INNER JOIN jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1' left JOIN jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
INNER JOIN (SELECT jsh_material.id,jsh_material.name mName, me.bar_code, Model, standard, left JOIN (SELECT jsh_material.id,jsh_material.name mName, me.bar_code, Model, standard,
jsh_material_category.`Name` categoryName, concat_ws('', jsh_material.unit, u.basic_unit) materialUnit jsh_material_category.`Name` categoryName, concat_ws('', jsh_material.unit, u.basic_unit) materialUnit
from jsh_material from jsh_material
left join jsh_unit u on jsh_material.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1' left join jsh_unit u on jsh_material.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
left join jsh_material_extend me on me.material_id=jsh_material.id and ifnull(me.delete_Flag,'0') !='1' left join jsh_material_extend me on me.material_id=jsh_material.id and ifnull(me.delete_Flag,'0') !='1'
LEFT JOIN jsh_material_category on jsh_material.category_id=jsh_material_category.Id and ifnull(jsh_material_category.delete_flag,'0') !='1' left JOIN jsh_material_category on jsh_material.category_id=jsh_material_category.Id and ifnull(jsh_material_category.delete_flag,'0') !='1'
where me.default_flag=1 and ifnull(jsh_material.delete_Flag,'0') !='1' where me.default_flag=1 and ifnull(jsh_material.delete_Flag,'0') !='1'
) m ) m
on m.Id=di.material_id where dh.type=#{type} and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} on m.Id=di.material_id where dh.type=#{type} and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
@@ -285,11 +285,11 @@
<select id="findInOutMaterialCountTotal" resultType="java.lang.Integer"> <select id="findInOutMaterialCountTotal" resultType="java.lang.Integer">
select count(1) from select count(1) from
(select di.material_id, m.mName,m.bar_code,m.Model,m.standard,m.categoryName from jsh_depot_head dh (select di.material_id, m.mName,m.bar_code,m.Model,m.standard,m.categoryName from jsh_depot_head dh
INNER JOIN jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1' left JOIN jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
INNER JOIN (SELECT jsh_material.id,jsh_material.name mName, me.bar_code, Model,standard,jsh_material_category.`Name` categoryName left JOIN (SELECT jsh_material.id,jsh_material.name mName, me.bar_code, Model,standard,jsh_material_category.`Name` categoryName
from jsh_material from jsh_material
left join jsh_material_extend me on me.material_id=jsh_material.id and ifnull(me.delete_Flag,'0') !='1' left join jsh_material_extend me on me.material_id=jsh_material.id and ifnull(me.delete_Flag,'0') !='1'
LEFT JOIN jsh_material_category on jsh_material.category_id=jsh_material_category.Id and ifnull(jsh_material_category.delete_flag,'0') !='1' left JOIN jsh_material_category on jsh_material.category_id=jsh_material_category.Id and ifnull(jsh_material_category.delete_flag,'0') !='1'
where me.default_flag=1 and ifnull(jsh_material.delete_Flag,'0') !='1' where me.default_flag=1 and ifnull(jsh_material.delete_Flag,'0') !='1'
) m on m.Id=di.material_id where dh.type=#{type} and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} ) m on m.Id=di.material_id where dh.type=#{type} and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<if test="oId != null"> <if test="oId != null">
@@ -310,12 +310,12 @@
select dh.number,me.bar_code, m.`name` MName,m.model,m.standard,di.unit_price,di.material_unit as mUnit,di.oper_number,di.all_price,SName, d.dName DName, select dh.number,me.bar_code, m.`name` MName,m.model,m.standard,di.unit_price,di.material_unit as mUnit,di.oper_number,di.all_price,SName, d.dName DName,
date_format(dh.oper_time, '%Y-%m-%d') OperTime, concat(dh.sub_type,dh.type) as NewType, concat_ws(' ',dh.remark,di.remark) as newRemark date_format(dh.oper_time, '%Y-%m-%d') OperTime, concat(dh.sub_type,dh.type) as NewType, concat_ws(' ',dh.remark,di.remark) as newRemark
from jsh_depot_head dh from jsh_depot_head dh
inner join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1' left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
inner join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1' left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1' left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
inner join (select id,name as dName,delete_Flag from jsh_depot ) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1' left join (select id,name as dName,delete_Flag from jsh_depot ) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
<!-- 调出仓库名查询 --> <!-- 调出仓库名查询 -->
inner join (select id as aid,name as SName,delete_Flag as adelete_Flag from jsh_depot ) ddd on ddd.aid=di.another_depot_id and ifnull(ddd.adelete_Flag,'0') !='1' left join (select id as aid,name as SName,delete_Flag as adelete_Flag from jsh_depot ) ddd on ddd.aid=di.another_depot_id and ifnull(ddd.adelete_Flag,'0') !='1'
where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<if test="depotIdF != null"> <if test="depotIdF != null">
and di.depot_id = #{depotIdF} and di.depot_id = #{depotIdF}
@@ -340,10 +340,10 @@
<select id="findAllocationDetailCount" resultType="java.lang.Integer"> <select id="findAllocationDetailCount" resultType="java.lang.Integer">
select count(1) select count(1)
from jsh_depot_head dh from jsh_depot_head dh
inner join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1' left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
inner join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1' left join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1'
left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1' left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
inner join (select id,name as dName,delete_Flag from jsh_depot) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1' left join (select id,name as dName,delete_Flag from jsh_depot) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<if test="depotIdF != null"> <if test="depotIdF != null">
and di.depot_id = #{depotIdF} and di.depot_id = #{depotIdF}
@@ -365,7 +365,7 @@
<select id="findStatementAccount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultStatementAccount"> <select id="findStatementAccount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultStatementAccount">
select dh.number,concat(dh.sub_type,dh.type) as type,dh.discount_last_money,dh.other_money,dh.change_amount,s.supplier supplierName, select dh.number,concat(dh.sub_type,dh.type) as type,dh.discount_last_money,dh.other_money,dh.change_amount,s.supplier supplierName,
date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime from jsh_depot_head dh date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime from jsh_depot_head dh
inner join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1' left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
where s.type=#{supType} and (dh.sub_type!='其它' and dh.sub_type!='采购订单' and dh.sub_type!='销售订单') where s.type=#{supType} and (dh.sub_type!='其它' and dh.sub_type!='采购订单' and dh.sub_type!='销售订单')
and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<if test="organId != null"> <if test="organId != null">
@@ -375,7 +375,7 @@
UNION ALL UNION ALL
select ah.bill_no number,ah.type as newType,ah.total_price discount_last_money, 0 other_money,ah.change_amount,s.supplier supplierName, select ah.bill_no number,ah.type as newType,ah.total_price discount_last_money, 0 other_money,ah.change_amount,s.supplier supplierName,
date_format(ah.bill_time,'%Y-%m-%d %H:%i:%S') as oTime from jsh_account_head ah date_format(ah.bill_time,'%Y-%m-%d %H:%i:%S') as oTime from jsh_account_head ah
inner join jsh_supplier s on s.id=ah.organ_id and ifnull(s.delete_Flag,'0') !='1' left join jsh_supplier s on s.id=ah.organ_id and ifnull(s.delete_Flag,'0') !='1'
where s.type=#{supType} where s.type=#{supType}
and ah.bill_time >=#{beginTime} and ah.bill_time &lt;=#{endTime} and ah.bill_time >=#{beginTime} and ah.bill_time &lt;=#{endTime}
<if test="organId != null"> <if test="organId != null">
@@ -392,7 +392,7 @@
select sum(a) from select sum(a) from
( (
select count(1) a from jsh_depot_head dh select count(1) a from jsh_depot_head dh
inner join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1' left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
where s.type=#{supType} and (dh.sub_type!='其它' and dh.sub_type!='采购订单' and dh.sub_type!='销售订单') where s.type=#{supType} and (dh.sub_type!='其它' and dh.sub_type!='采购订单' and dh.sub_type!='销售订单')
and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<if test="organId != null"> <if test="organId != null">
@@ -401,7 +401,7 @@
and ifnull(dh.delete_flag,'0') !='1' and ifnull(dh.delete_flag,'0') !='1'
UNION ALL UNION ALL
select count(1) a from jsh_account_head ah select count(1) a from jsh_account_head ah
inner join jsh_supplier s on s.id=ah.organ_id and ifnull(s.delete_Flag,'0') !='1' left join jsh_supplier s on s.id=ah.organ_id and ifnull(s.delete_Flag,'0') !='1'
where s.type=#{supType} where s.type=#{supType}
and ah.bill_time >=#{beginTime} and ah.bill_time &lt;=#{endTime} and ah.bill_time >=#{beginTime} and ah.bill_time &lt;=#{endTime}
<if test="organId != null"> <if test="organId != null">