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

View File

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

View File

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