优化报表分组sql

This commit is contained in:
季圣华
2019-01-06 15:07:33 +08:00
parent d6c431089b
commit 40155c2752
3 changed files with 56 additions and 46 deletions

View File

@@ -580,14 +580,12 @@ public class DepotItemController {
if (null != dataList) { if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject(); JSONObject item = new JSONObject();
Double prevSum = sumNumber("入库", pid, diEx.getMaterialid(), monthTime, true) - sumNumber("出库", pid, diEx.getMaterialid(), monthTime, true); Double prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true) - sumNumber("出库", pid, diEx.getMId(), monthTime, true);
Double InSum = sumNumber("入库", pid, diEx.getMaterialid(), monthTime, false); Double InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
Double OutSum = sumNumber("出库", pid, diEx.getMaterialid(), monthTime, false); Double OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
Double prevPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, true) - sumPrice("出库", pid, diEx.getMaterialid(), monthTime, true); Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, false); Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMaterialid(), monthTime, false); Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
item.put("Id", diEx.getId());
item.put("MaterialId", diEx.getMaterialid());
item.put("MaterialName", diEx.getMName()); item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMColor()); item.put("MaterialModel", diEx.getMColor());
//扩展信息 //扩展信息
@@ -641,9 +639,9 @@ public class DepotItemController {
Double thisAllPrice = 0.0; Double thisAllPrice = 0.0;
if (null != dataList) { if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) {
Double prevPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, true) - sumPrice("出库", pid, diEx.getMaterialid(), monthTime, true); Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, false); Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMaterialid(), monthTime, false); Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
thisAllPrice = thisAllPrice + (prevPrice + InPrice - OutPrice); thisAllPrice = thisAllPrice + (prevPrice + InPrice - OutPrice);
} }
} }
@@ -689,12 +687,10 @@ public class DepotItemController {
if (null != dataList) { if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject(); JSONObject item = new JSONObject();
Double InSum = sumNumberBuyOrSale("入库", "采购", diEx.getMaterialid(), monthTime); Double InSum = sumNumberBuyOrSale("入库", "采购", diEx.getMId(), monthTime);
Double OutSum = sumNumberBuyOrSale("出库", "采购退货", diEx.getMaterialid(), monthTime); Double OutSum = sumNumberBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime);
Double InSumPrice = sumPriceBuyOrSale("入库", "采购", diEx.getMaterialid(), monthTime); Double InSumPrice = sumPriceBuyOrSale("入库", "采购", diEx.getMId(), monthTime);
Double OutSumPrice = sumPriceBuyOrSale("出库", "采购退货", diEx.getMaterialid(), monthTime); Double OutSumPrice = sumPriceBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime);
item.put("Id", diEx.getId());
item.put("MaterialId", diEx.getMaterialid());
item.put("MaterialName", diEx.getMName()); item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel()); item.put("MaterialModel", diEx.getMModel());
//扩展信息 //扩展信息
@@ -751,16 +747,14 @@ public class DepotItemController {
if (null != dataList) { if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject(); JSONObject item = new JSONObject();
Double OutSumRetail = sumNumberBuyOrSale("出库", "零售", diEx.getMaterialid(), monthTime); Double OutSumRetail = sumNumberBuyOrSale("出库", "零售", diEx.getMId(), monthTime);
Double OutSum = sumNumberBuyOrSale("出库", "销售", diEx.getMaterialid(), monthTime); Double OutSum = sumNumberBuyOrSale("出库", "销售", diEx.getMId(), monthTime);
Double InSumRetail = sumNumberBuyOrSale("入库", "零售退货", diEx.getMaterialid(), monthTime); Double InSumRetail = sumNumberBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime);
Double InSum = sumNumberBuyOrSale("入库", "销售退货", diEx.getMaterialid(), monthTime); Double InSum = sumNumberBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime);
Double OutSumRetailPrice = sumPriceBuyOrSale("出库", "零售", diEx.getMaterialid(), monthTime); Double OutSumRetailPrice = sumPriceBuyOrSale("出库", "零售", diEx.getMId(), monthTime);
Double OutSumPrice = sumPriceBuyOrSale("出库", "销售", diEx.getMaterialid(), monthTime); Double OutSumPrice = sumPriceBuyOrSale("出库", "销售", diEx.getMId(), monthTime);
Double InSumRetailPrice = sumPriceBuyOrSale("入库", "零售退货", diEx.getMaterialid(), monthTime); Double InSumRetailPrice = sumPriceBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime);
Double InSumPrice = sumPriceBuyOrSale("入库", "销售退货", diEx.getMaterialid(), monthTime); Double InSumPrice = sumPriceBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime);
item.put("Id", diEx.getId());
item.put("MaterialId", diEx.getMaterialid());
item.put("MaterialName", diEx.getMName()); item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel()); item.put("MaterialModel", diEx.getMModel());
//扩展信息 //扩展信息
@@ -817,10 +811,8 @@ public class DepotItemController {
if (null != dataList) { if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject(); JSONObject item = new JSONObject();
Double InSum = sumNumberGift("礼品充值", pid, diEx.getMaterialid(), "in"); Double InSum = sumNumberGift("礼品充值", pid, diEx.getMId(), "in");
Double OutSum = sumNumberGift("礼品销售", pid, diEx.getMaterialid(), "out"); Double OutSum = sumNumberGift("礼品销售", pid, diEx.getMId(), "out");
item.put("Id", diEx.getId());
item.put("MaterialId", diEx.getMaterialid());
item.put("MaterialName", diEx.getMName()); item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel()); item.put("MaterialModel", diEx.getMModel());
//扩展信息 //扩展信息
@@ -876,12 +868,12 @@ public class DepotItemController {
if (null != dataList) { if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) {
String[] objs = new String[9]; String[] objs = new String[9];
Double prevSum = sumNumber("入库", pid, diEx.getMaterialid(), monthTime, true) - sumNumber("出库", pid, diEx.getMaterialid(), monthTime, true); Double prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true) - sumNumber("出库", pid, diEx.getMId(), monthTime, true);
Double InSum = sumNumber("入库", pid, diEx.getMaterialid(), monthTime, false); Double InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
Double OutSum = sumNumber("出库", pid, diEx.getMaterialid(), monthTime, false); Double OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
Double prevPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, true) - sumPrice("出库", pid, diEx.getMaterialid(), monthTime, true); Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMaterialid(), monthTime, false); Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMaterialid(), monthTime, false); Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
Double unitPrice = 0.0; Double unitPrice = 0.0;
if (prevSum + InSum - OutSum != 0.0) { if (prevSum + InSum - OutSum != 0.0) {
unitPrice = (prevPrice + InPrice - OutPrice) / (prevSum + InSum - OutSum); unitPrice = (prevPrice + InPrice - OutPrice) / (prevSum + InSum - OutSum);

View File

@@ -48,6 +48,8 @@ public class DepotItemVo4WithInfoEx {
private String mtype; private String mtype;
private Long MId;
private String MName; private String MName;
private String MModel; private String MModel;
@@ -258,6 +260,14 @@ public class DepotItemVo4WithInfoEx {
this.mtype = mtype; this.mtype = mtype;
} }
public Long getMId() {
return MId;
}
public void setMId(Long MId) {
this.MId = MId;
}
public String getMName() { public String getMName() {
return MName; return MName;
} }

View File

@@ -33,6 +33,14 @@
<result column="UName" jdbcType="VARCHAR" property="UName" /> <result column="UName" jdbcType="VARCHAR" property="UName" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultByMaterial" type="com.jsh.erp.datasource.entities.DepotItemVo4WithInfoEx">
<result column="MId" jdbcType="VARCHAR" property="MId" />
<result column="MName" jdbcType="VARCHAR" property="MName" />
<result column="MModel" jdbcType="VARCHAR" property="MModel" />
<result column="MaterialUnit" jdbcType="VARCHAR" property="MaterialUnit" />
<result column="MColor" jdbcType="VARCHAR" property="MColor" />
</resultMap>
<select id="selectByConditionDepotItem" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="BaseResultMap"> <select id="selectByConditionDepotItem" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="BaseResultMap">
select * select *
FROM jsh_depotitem FROM jsh_depotitem
@@ -130,35 +138,35 @@
order by di.id asc order by di.id asc
</select> </select>
<select id="findByAll" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap"> <select id="findByAll" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultByMaterial">
select di.*, m.Name MName, m.Model MModel, m.Unit MaterialUnit, m.Color MColor select m.id MId, m.Name MName, m.Model MModel, m.Unit MaterialUnit, m.Color MColor
from jsh_depotitem di from jsh_depotitem di
inner join jsh_material m on di.MaterialId=m.id inner join jsh_material m on di.MaterialId=m.id
where 1=1 where 1=1
<if test="headIds != null"> <if test="headIds != null">
and HeaderId in (${headIds}) and di.HeaderId in (${headIds})
</if> </if>
<if test="materialIds != null"> <if test="materialIds != null">
and MaterialId in (${materialIds}) and di.MaterialId in (${materialIds})
</if> </if>
group by MaterialId group by m.id,m.Name, m.Model, m.Unit, m.Color
<if test="offset != null and rows != null"> <if test="offset != null and rows != null">
limit #{offset},#{rows} limit #{offset},#{rows}
</if> </if>
</select> </select>
<select id="findByAllCount" resultType="java.lang.Integer"> <select id="findByAllCount" resultType="java.lang.Integer">
select count(1) from (select di.Id select count(1) from (select m.id
from jsh_depotitem di from jsh_depotitem di
inner join jsh_material m on di.MaterialId=m.id inner join jsh_material m on di.MaterialId=m.id
where 1=1 where 1=1
<if test="headIds != null"> <if test="headIds != null">
and HeaderId in (${headIds}) and di.HeaderId in (${headIds})
</if> </if>
<if test="materialIds != null"> <if test="materialIds != null">
and MaterialId in (${materialIds}) and di.MaterialId in (${materialIds})
</if> </if>
group by MaterialId) cc group by m.id) cc
</select> </select>
<select id="findByTypeInIsPrev" resultType="java.lang.Double"> <select id="findByTypeInIsPrev" resultType="java.lang.Double">