Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
6eb7d965
Commit
6eb7d965
authored
Jun 21, 2021
by
季圣华
Browse files
优化商品库存报表
parent
523a7d28
Changes
3
Hide whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java
View file @
6eb7d965
...
...
@@ -367,7 +367,7 @@ public class MaterialController {
src
=
workbook
.
getSheet
(
0
);
}
catch
(
Exception
e
)
{
}
res
=
materialService
.
importExcel
(
src
);
res
=
materialService
.
importExcel
(
src
,
request
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java
View file @
6eb7d965
...
...
@@ -15,6 +15,7 @@ import com.jsh.erp.service.depot.DepotService;
import
com.jsh.erp.service.depotItem.DepotItemService
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.materialCategory.MaterialCategoryService
;
import
com.jsh.erp.service.redis.RedisService
;
import
com.jsh.erp.service.unit.UnitService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.BaseResponseInfo
;
...
...
@@ -67,6 +68,8 @@ public class MaterialService {
private
DepotService
depotService
;
@Resource
private
MaterialExtendService
materialExtendService
;
@Resource
private
RedisService
redisService
;
public
Material
getMaterial
(
long
id
)
throws
Exception
{
Material
result
=
null
;
...
...
@@ -182,7 +185,8 @@ public class MaterialService {
String
number
=
jsonObj
.
getString
(
"initStock"
);
Long
depotId
=
jsonObj
.
getLong
(
"id"
);
if
(
StringUtil
.
isNotEmpty
(
number
)
&&
Double
.
valueOf
(
number
)>
0
)
{
insertStockByMaterialAndDepot
(
depotId
,
mId
,
parseBigDecimalEx
(
number
));
insertInitialStockByMaterialAndDepot
(
depotId
,
mId
,
parseBigDecimalEx
(
number
));
insertCurrentStockByMaterialAndDepot
(
depotId
,
mId
,
parseBigDecimalEx
(
number
));
}
}
}
...
...
@@ -216,13 +220,16 @@ public class MaterialService {
if
(
jsonObj
.
get
(
"id"
)
!=
null
&&
jsonObj
.
get
(
"initStock"
)
!=
null
)
{
String
number
=
jsonObj
.
getString
(
"initStock"
);
Long
depotId
=
jsonObj
.
getLong
(
"id"
);
//先清除再插入
//
初始库存-
先清除再插入
MaterialInitialStockExample
example
=
new
MaterialInitialStockExample
();
example
.
createCriteria
().
andMaterialIdEqualTo
(
material
.
getId
()).
andDepotIdEqualTo
(
depotId
);
materialInitialStockMapper
.
deleteByExample
(
example
);
if
(
StringUtil
.
isNotEmpty
(
number
)
&&
Double
.
valueOf
(
number
)
>
0
)
{
insertStockByMaterialAndDepot
(
depotId
,
material
.
getId
(),
parseBigDecimalEx
(
number
));
insert
Initial
StockByMaterialAndDepot
(
depotId
,
material
.
getId
(),
parseBigDecimalEx
(
number
));
}
//更新当前库存
Long
tenantId
=
redisService
.
getTenantId
(
request
);
depotItemService
.
updateCurrentStockFun
(
material
.
getId
(),
depotId
,
tenantId
);
}
}
}
...
...
@@ -435,7 +442,7 @@ public class MaterialService {
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
BaseResponseInfo
importExcel
(
Sheet
src
)
throws
Exception
{
public
BaseResponseInfo
importExcel
(
Sheet
src
,
HttpServletRequest
request
)
throws
Exception
{
List
<
Depot
>
depotList
=
depotService
.
getDepot
();
int
depotCount
=
depotList
.
size
();
List
<
MaterialWithInitStock
>
mList
=
new
ArrayList
<>();
...
...
@@ -577,13 +584,16 @@ public class MaterialService {
Long
depotId
=
null
;
for
(
Depot
depot:
depotList
){
BigDecimal
stock
=
stockMap
.
get
(
depot
.
getId
());
//先清除再插入
//
初始库存-
先清除再插入
MaterialInitialStockExample
example
=
new
MaterialInitialStockExample
();
example
.
createCriteria
().
andMaterialIdEqualTo
(
mId
).
andDepotIdEqualTo
(
depot
.
getId
());
materialInitialStockMapper
.
deleteByExample
(
example
);
if
(
stock
!=
null
&&
stock
.
compareTo
(
BigDecimal
.
ZERO
)!=
0
)
{
depotId
=
depot
.
getId
();
insertStockByMaterialAndDepot
(
depotId
,
mId
,
stock
);
insertInitialStockByMaterialAndDepot
(
depotId
,
mId
,
stock
);
//更新当前库存
Long
tenantId
=
redisService
.
getTenantId
(
request
);
depotItemService
.
updateCurrentStockFun
(
mId
,
depotId
,
tenantId
);
}
}
}
...
...
@@ -643,7 +653,7 @@ public class MaterialService {
* @param stock
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
insertStockByMaterialAndDepot
(
Long
depotId
,
Long
mId
,
BigDecimal
stock
){
public
void
insert
Initial
StockByMaterialAndDepot
(
Long
depotId
,
Long
mId
,
BigDecimal
stock
){
MaterialInitialStock
materialInitialStock
=
new
MaterialInitialStock
();
materialInitialStock
.
setDepotId
(
depotId
);
materialInitialStock
.
setMaterialId
(
mId
);
...
...
@@ -651,6 +661,21 @@ public class MaterialService {
materialInitialStockMapper
.
insertSelective
(
materialInitialStock
);
//存入初始库存
}
/**
* 写入当前库存
* @param depotId
* @param mId
* @param stock
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
insertCurrentStockByMaterialAndDepot
(
Long
depotId
,
Long
mId
,
BigDecimal
stock
){
MaterialCurrentStock
materialCurrentStock
=
new
MaterialCurrentStock
();
materialCurrentStock
.
setDepotId
(
depotId
);
materialCurrentStock
.
setMaterialId
(
mId
);
materialCurrentStock
.
setCurrentNumber
(
stock
);
materialCurrentStockMapper
.
insertSelective
(
materialCurrentStock
);
//存入初始库存
}
public
List
<
MaterialVo4Unit
>
getMaterialEnableSerialNumberList
(
String
q
,
Integer
offset
,
Integer
rows
)
throws
Exception
{
List
<
MaterialVo4Unit
>
list
=
null
;
try
{
...
...
jshERP-boot/src/main/resources/mapper_xml/MaterialMapperEx.xml
View file @
6eb7d965
...
...
@@ -320,19 +320,23 @@
<select
id=
"getListWithStock"
resultMap=
"ResultMapListWithStock"
>
select m.*, me.commodity_unit unitName, mc.name categoryName, me.bar_code,
ifnull(me.purchase_decimal,0) purchase_decimal, ifnull(sum(mis.number),0) initialStock,
ifnull(me.purchase_decimal,0) purchase_decimal,
(select ifnull(sum(mis.number),0) from jsh_material_initial_stock mis where mis.material_id = m.id
<if
test=
"depotId != null"
>
and mis.depot_id = #{depotId}
</if>
) initialStock,
ifnull(sum(mcs.current_number),0) currentStock,
sum(ifnull(me.purchase_decimal, 0) * ifnull(mcs.current_number, 0)) currentStockPrice
FROM jsh_material m
left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
left join jsh_material_initial_stock mis on m.id = mis.material_id and ifnull(mis.delete_flag,'0') !='1'
left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
where 1=1
and me.default_flag=1
<if
test=
"depotId != null"
>
and
(mis.depot_id = #{depotId} or
mcs.depot_id = #{depotId}
)
and mcs.depot_id = #{depotId}
</if>
<if
test=
"idList.size()>0"
>
and m.category_id in
...
...
@@ -356,14 +360,13 @@
select count(tb.id) from
(select m.id from jsh_material m
left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
left join jsh_material_initial_stock mis on m.id = mis.material_id and ifnull(mis.delete_flag,'0') !='1'
left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
where 1=1
and me.default_flag=1
<if
test=
"depotId != null"
>
and
(mis.depot_id = #{depotId} or
mcs.depot_id = #{depotId}
)
and mcs.depot_id = #{depotId}
</if>
<if
test=
"idList.size()>0"
>
and m.category_id in
...
...
@@ -385,14 +388,13 @@
sum(ifnull(me.purchase_decimal,0)*ifnull(mcs.current_number,0)) currentStockPrice
from jsh_material m
left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
left join jsh_material_initial_stock mis on m.id = mis.material_id and ifnull(mis.delete_flag,'0') !='1'
left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
where 1=1
and me.default_flag=1
<if
test=
"depotId != null"
>
and
(mis.depot_id = #{depotId} or
mcs.depot_id = #{depotId}
)
and mcs.depot_id = #{depotId}
</if>
<if
test=
"idList.size()>0"
>
and m.category_id in
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment