合并商品的库存到商品列表接口一起查询
This commit is contained in:
@@ -522,44 +522,10 @@
|
||||
{title: '单位', field: 'unit', width: 60},
|
||||
{title: '安全存量', field: 'safetystock', width: 70},
|
||||
{
|
||||
title: '库存', field: 'abc', width: 70, formatter: function (value, rec) {
|
||||
var monthTime = getNowFormatMonth();
|
||||
var mId = rec.id; //商品id
|
||||
var thisStock = 0;
|
||||
//查询库存
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: '/depotItem/findStockNumByMaterialId',
|
||||
data: {
|
||||
materialId: mId,
|
||||
monthTime: monthTime,
|
||||
currentPage: 1,
|
||||
pageSize: 10
|
||||
},
|
||||
dataType: "json",
|
||||
success: function (res) {
|
||||
if(res && res.code === 200) {
|
||||
if (res.data && res.data.page && res.data.page[0]) {
|
||||
thisStock = res.data.page[0].thisSum - 0;
|
||||
if (thisStock > 0) {
|
||||
$("#tablePanel .class-" + rec.id).text(thisStock); //延迟加载库存数据
|
||||
$("#tablePanel .class-" + rec.id).css("color", "blue").css("text-decoration", "underline").css("cursor", "pointer");
|
||||
$("#tablePanel .class-" + rec.id).off("click").on("click", function () {
|
||||
$('#materialDetailListDlg').dialog('open').dialog('setTitle', '<img src="/js/easyui-1.3.5/themes/icons/pencil.png"/> 查看出入库明细');
|
||||
$(".window-mask").css({width: webW, height: webH});
|
||||
initMaterialDetailData(mId);
|
||||
getMaterialInOutList(mId, 1, initPageSize);
|
||||
ininMaterialDetailPager(mId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$.messager.alert('查询提示', '查询数据后台异常,请稍后再试!', 'error');
|
||||
}
|
||||
});
|
||||
return "<span class='class-" + rec.id + "'>" + thisStock + "</span>";
|
||||
title: '库存', field: 'stock', width: 70, formatter: function (value, rec) {
|
||||
var str = '';
|
||||
str += '<span title="查看出入库明细" class="n-link" onclick="findStockList(' + rec.id + ');">' + rec.stock + '</span>';
|
||||
return str;
|
||||
}
|
||||
},
|
||||
{title: '零售价', field: 'retailprice', width: 60},
|
||||
@@ -765,6 +731,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
function findStockList(mId) {
|
||||
$('#materialDetailListDlg').dialog('open').dialog('setTitle', '<img src="/js/easyui-1.3.5/themes/icons/pencil.png"/> 查看出入库明细');
|
||||
$(".window-mask").css({width: webW, height: webH});
|
||||
initMaterialDetailData(mId);
|
||||
getMaterialInOutList(mId, 1, initPageSize);
|
||||
ininMaterialDetailPager(mId);
|
||||
}
|
||||
|
||||
//删除商品信息
|
||||
function deleteMaterial(materialID) {
|
||||
$.messager.confirm('删除确认', '确定要删除此商品信息吗?', function (r) {
|
||||
|
||||
@@ -94,48 +94,7 @@
|
||||
{title: '品名', field: 'name', width: 150},
|
||||
{title: '型号', field: 'model', width: 100},
|
||||
{title: '类别', field: 'categoryName', width: 130},
|
||||
{title: '单位', field: 'unit', width: 60},
|
||||
{
|
||||
title: '库存', field: 'abc', width: 70, formatter: function (value, rec) {
|
||||
var monthTime = getNowFormatMonth();
|
||||
var mId = rec.id; //商品id
|
||||
var thisStock = 0;
|
||||
//查询库存
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: '/depotItem/findStockNumByMaterialId',
|
||||
data: {
|
||||
materialId: mId,
|
||||
monthTime: monthTime,
|
||||
currentPage: 1,
|
||||
pageSize: 10
|
||||
},
|
||||
dataType: "json",
|
||||
success: function (res) {
|
||||
if(res && res.code === 200) {
|
||||
if (res.data && res.data.page && res.data.page[0]) {
|
||||
thisStock = res.data.page[0].thisSum - 0;
|
||||
if (thisStock > 0) {
|
||||
$("#tablePanel .class-" + rec.id).text(thisStock); //延迟加载库存数据
|
||||
$("#tablePanel .class-" + rec.id).css("color", "blue").css("text-decoration", "underline").css("cursor", "pointer");
|
||||
$("#tablePanel .class-" + rec.id).off("click").on("click", function () {
|
||||
$('#materialDetailListDlg').dialog('open').dialog('setTitle', '<img src="/js/easyui-1.3.5/themes/icons/pencil.png"/> 查看出入库明细');
|
||||
$(".window-mask").css({width: webW, height: webH});
|
||||
initMaterialDetailData(mId);
|
||||
getMaterialInOutList(mId, 1, initPageSize);
|
||||
ininMaterialDetailPager(mId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$.messager.alert('查询提示', '查询数据后台异常,请稍后再试!', 'error');
|
||||
}
|
||||
});
|
||||
return "<span class='class-" + rec.id + "'>" + thisStock + "</span>";
|
||||
}
|
||||
},
|
||||
{title: '单位', field: 'unit', width: 60}
|
||||
]],
|
||||
toolbar: [
|
||||
],
|
||||
@@ -162,54 +121,6 @@
|
||||
showMaterialDetails(1, initPageSize);
|
||||
}
|
||||
|
||||
|
||||
//分页信息处理
|
||||
function ininMaterialDetailPager(mId) {
|
||||
try {
|
||||
var opts = $("#materialTableData").datagrid('options');
|
||||
var pager = $("#materialTableData").datagrid('getPager');
|
||||
pager.pagination({
|
||||
onSelectPage: function (pageNum, pageSize) {
|
||||
opts.pageNumber = pageNum;
|
||||
opts.pageSize = pageSize;
|
||||
pager.pagination('refresh', {
|
||||
pageNumber: pageNum,
|
||||
pageSize: pageSize
|
||||
});
|
||||
getMaterialInOutList(mId, pageNum, pageSize);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
$.messager.alert('异常处理提示', "分页信息异常 : " + e.name + ": " + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function getMaterialInOutList(mId, pageNo, pageSize) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/depotItem/findDetailByTypeAndMaterialId",
|
||||
dataType: "json",
|
||||
data: ({
|
||||
materialId: mId,
|
||||
currentPage: pageNo,
|
||||
pageSize: pageSize
|
||||
}),
|
||||
success: function (res) {
|
||||
if(res && res.code === 200){
|
||||
if(res.data && res.data.page) {
|
||||
$("#materialTableData").datagrid('loadData', res.data.page);
|
||||
}
|
||||
}
|
||||
},
|
||||
//此处添加错误处理
|
||||
error: function () {
|
||||
$.messager.alert('查询提示', '查询数据后台异常,请稍后再试!', 'error');
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//初始化键盘enter事件
|
||||
$(document).keydown(function (event) {
|
||||
//兼容 IE和firefox 事件
|
||||
|
||||
@@ -152,77 +152,6 @@ public class DepotItemController {
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 只根据商品id查询库存数量
|
||||
* @param pageSize
|
||||
* @param currentPage
|
||||
* @param mId
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/findStockNumByMaterialId")
|
||||
public String findStockNumByMaterialId(
|
||||
@RequestParam(value = Constants.PAGE_SIZE, required = false) Integer pageSize,
|
||||
@RequestParam(value = Constants.CURRENT_PAGE, required = false) Integer currentPage,
|
||||
@RequestParam("materialId") String mId,
|
||||
@RequestParam("monthTime") String monthTime,
|
||||
HttpServletRequest request) throws Exception{
|
||||
Map<String, String> parameterMap = ParamUtils.requestToMap(request);
|
||||
parameterMap.put("mId", mId);
|
||||
parameterMap.put("monthTime", monthTime);
|
||||
PageQueryInfo queryInfo = new PageQueryInfo();
|
||||
Map<String, Object> objectMap = new HashMap<String, Object>();
|
||||
if (pageSize != null && pageSize <= 0) {
|
||||
pageSize = 10;
|
||||
}
|
||||
String offset = ParamUtils.getPageOffset(currentPage, pageSize);
|
||||
if (StringUtil.isNotEmpty(offset)) {
|
||||
parameterMap.put(Constants.OFFSET, offset);
|
||||
}
|
||||
List<DepotItemVo4Material> list = depotItemService.findStockNumByMaterialIdList(parameterMap);
|
||||
|
||||
//存放数据json数组
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if (null != list) {
|
||||
for (DepotItemVo4Material di : list) {
|
||||
JSONObject item = new JSONObject();
|
||||
int InSum = sumNumberByMaterialId("入库", di.getMaterialid());
|
||||
int OutSum = sumNumberByMaterialId("出库", di.getMaterialid());
|
||||
item.put("MaterialId", di.getMaterialid() == null ? "" : di.getMaterialid());
|
||||
item.put("MaterialName", di.getMname());
|
||||
item.put("MaterialModel", di.getMmodel());
|
||||
item.put("thisSum", InSum - OutSum);
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
objectMap.put("page", dataArray);
|
||||
if (list == null) {
|
||||
queryInfo.setRows(new ArrayList<Object>());
|
||||
queryInfo.setTotal(BusinessConstants.DEFAULT_LIST_NULL_NUMBER);
|
||||
return returnJson(objectMap, "查找不到数据", ErpInfo.OK.code);
|
||||
}
|
||||
queryInfo.setRows(list);
|
||||
queryInfo.setTotal(depotItemService.findStockNumByMaterialIdCounts(parameterMap));
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅根据商品Id进行数量合计
|
||||
*
|
||||
* @param type
|
||||
* @param mId
|
||||
* @return
|
||||
*/
|
||||
public int sumNumberByMaterialId(String type, Long mId)throws Exception {
|
||||
int allNumber = 0;
|
||||
try {
|
||||
allNumber = depotItemService.findByTypeAndMaterialId(type, mId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return allNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存明细
|
||||
* @param inserted
|
||||
|
||||
@@ -10,6 +10,8 @@ public class MaterialVo4Unit extends Material{
|
||||
|
||||
private String materialOther;
|
||||
|
||||
private Long stock;
|
||||
|
||||
public String getUnitName() {
|
||||
return unitName;
|
||||
}
|
||||
@@ -33,4 +35,12 @@ public class MaterialVo4Unit extends Material{
|
||||
public void setMaterialOther(String materialOther) {
|
||||
this.materialOther = materialOther;
|
||||
}
|
||||
|
||||
public Long getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public void setStock(Long stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
}
|
||||
@@ -45,10 +45,10 @@ public interface DepotItemMapperEx {
|
||||
@Param("mId") Long mId,
|
||||
@Param("monthTime") String monthTime);
|
||||
|
||||
int findByTypeAndMaterialIdIn(
|
||||
Long findByTypeAndMaterialIdIn(
|
||||
@Param("mId") Long mId);
|
||||
|
||||
int findByTypeAndMaterialIdOut(
|
||||
Long findByTypeAndMaterialIdOut(
|
||||
@Param("mId") Long mId);
|
||||
|
||||
int findByTypeAndDepotIdAndMaterialIdIn(
|
||||
|
||||
@@ -290,8 +290,8 @@ public class DepotItemService {
|
||||
return depotItemMapper.updateByPrimaryKeySelective(depotItem);
|
||||
}
|
||||
|
||||
public int findByTypeAndMaterialId(String type, Long mId) throws Exception{
|
||||
int result =0;
|
||||
public Long findByTypeAndMaterialId(String type, Long mId) throws Exception{
|
||||
Long result = 0l;
|
||||
try{
|
||||
if(type.equals(TYPE)) {
|
||||
result= depotItemMapperEx.findByTypeAndMaterialIdIn(mId);
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
|
||||
import com.jsh.erp.datasource.mappers.MaterialMapper;
|
||||
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.service.depotItem.DepotItemService;
|
||||
import com.jsh.erp.service.log.LogService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import com.jsh.erp.utils.BaseResponseInfo;
|
||||
@@ -38,6 +39,8 @@ public class MaterialService {
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private DepotItemMapperEx depotItemMapperEx;
|
||||
@Resource
|
||||
private DepotItemService depotItemService;
|
||||
|
||||
public Material getMaterial(long id)throws Exception {
|
||||
Material result=null;
|
||||
@@ -105,6 +108,9 @@ public class MaterialService {
|
||||
}
|
||||
}
|
||||
m.setMaterialOther(materialOther);
|
||||
Long InSum = depotItemService.findByTypeAndMaterialId("入库", m.getId());
|
||||
Long OutSum = depotItemService.findByTypeAndMaterialId("出库", m.getId());
|
||||
m.setStock(InSum - OutSum);
|
||||
resList.add(m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
|
||||
<select id="findDetailByTypeAndMaterialIdList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="DetailByTypeAndMIdResultMap">
|
||||
select dh.Number,concat(dh.SubType,dh.Type) as newType,
|
||||
case when type='入库' then di.BasicNumber when type='出库' then 0-di.BasicNumber else 0 end as b_num,
|
||||
case when type='入库' then ifnull(di.BasicNumber,0) when type='出库' then 0-di.BasicNumber else 0 end as b_num,
|
||||
date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime
|
||||
from jsh_depothead dh
|
||||
INNER JOIN jsh_depotitem di on dh.id=di.HeaderId and ifnull(di.delete_Flag,'0') !='1'
|
||||
@@ -131,7 +131,7 @@
|
||||
and ifnull(delete_Flag,'0') !='1'
|
||||
</select>
|
||||
|
||||
<select id="findByTypeAndMaterialIdIn" resultType="java.lang.Integer">
|
||||
<select id="findByTypeAndMaterialIdIn" resultType="java.lang.Long">
|
||||
select ifnull(sum(BasicNumber),0) as BasicNumber from jsh_depothead dh
|
||||
INNER JOIN jsh_depotitem di on dh.id=di.HeaderId and ifnull(di.delete_Flag,'0') !='1'
|
||||
where dh.type='入库'
|
||||
@@ -139,7 +139,7 @@
|
||||
and ifnull(dh.delete_Flag,'0') !='1'
|
||||
</select>
|
||||
|
||||
<select id="findByTypeAndMaterialIdOut" resultType="java.lang.Integer">
|
||||
<select id="findByTypeAndMaterialIdOut" resultType="java.lang.Long">
|
||||
select ifnull(sum(BasicNumber),0) as BasicNumber from jsh_depothead dh
|
||||
INNER JOIN jsh_depotitem di on dh.id=di.HeaderId and ifnull(di.delete_Flag,'0') !='1'
|
||||
where dh.type='出库'
|
||||
|
||||
Reference in New Issue
Block a user