优化进销存统计接口

This commit is contained in:
季圣华
2021-11-26 00:22:46 +08:00
parent 3b3805ee93
commit f89d8f2a3f

View File

@@ -8,6 +8,7 @@ import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.vo.DepotItemStockWarningCount; import com.jsh.erp.datasource.vo.DepotItemStockWarningCount;
import com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList; import com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList;
import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.service.materialExtend.MaterialExtendService; import com.jsh.erp.service.materialExtend.MaterialExtendService;
import com.jsh.erp.service.depotItem.DepotItemService; import com.jsh.erp.service.depotItem.DepotItemService;
import com.jsh.erp.service.material.MaterialService; import com.jsh.erp.service.material.MaterialService;
@@ -53,6 +54,9 @@ public class DepotItemController {
@Resource @Resource
private UnitService unitService; private UnitService unitService;
@Resource
private DepotService depotService;
@Resource @Resource
private RedisService redisService; private RedisService redisService;
@@ -277,7 +281,7 @@ public class DepotItemController {
* 查找所有的明细 * 查找所有的明细
* @param currentPage * @param currentPage
* @param pageSize * @param pageSize
* @param depotId * @param depotIds
* @param monthTime * @param monthTime
* @param materialParam * @param materialParam
* @param mpList * @param mpList
@@ -289,16 +293,27 @@ public class DepotItemController {
@ApiOperation(value = "查找所有的明细") @ApiOperation(value = "查找所有的明细")
public BaseResponseInfo findByAll(@RequestParam("currentPage") Integer currentPage, public BaseResponseInfo findByAll(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize, @RequestParam("pageSize") Integer pageSize,
@RequestParam(value = "depotId", required = false) Long depotId, @RequestParam(value = "depotIds", required = false) String depotIds,
@RequestParam("monthTime") String monthTime, @RequestParam("monthTime") String monthTime,
@RequestParam("materialParam") String materialParam, @RequestParam("materialParam") String materialParam,
@RequestParam("mpList") String mpList, @RequestParam("mpList") String mpList,
HttpServletRequest request)throws Exception { HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME;
String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME;
try { try {
String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME;
String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME;
List<Long> depotList = new ArrayList<>();
if(StringUtil.isNotEmpty(depotIds)) {
depotList = StringUtil.strToLongList(depotIds);
} else {
//未选择仓库时默认为当前用户有权限的仓库
JSONArray depotArr = depotService.findDepotByCurrentUser();
for(Object obj: depotArr) {
JSONObject object = JSONObject.parseObject(obj.toString());
depotList.add(object.getLong("id"));
}
}
List<DepotItemVo4WithInfoEx> dataList = depotItemService.findByAll(StringUtil.toNull(materialParam), List<DepotItemVo4WithInfoEx> dataList = depotItemService.findByAll(StringUtil.toNull(materialParam),
timeB,(currentPage-1)*pageSize, pageSize); timeB,(currentPage-1)*pageSize, pageSize);
String[] mpArr = mpList.split(","); String[] mpArr = mpList.split(",");
@@ -324,11 +339,23 @@ public class DepotItemController {
item.put("materialOther", materialOther); item.put("materialOther", materialOther);
item.put("materialColor", diEx.getMColor()); item.put("materialColor", diEx.getMColor());
item.put("unitName", diEx.getMaterialUnit()); item.put("unitName", diEx.getMaterialUnit());
BigDecimal prevSum = BigDecimal.ZERO;
item.put("prevSum", depotItemService.getStockByParam(depotId,mId,null,timeA)); BigDecimal inSum = BigDecimal.ZERO;
item.put("inSum", depotItemService.getInNumByParam(depotId,mId,timeA,timeB)); BigDecimal outSum = BigDecimal.ZERO;
item.put("outSum", depotItemService.getOutNumByParam(depotId,mId,timeA,timeB)); BigDecimal thisSum = BigDecimal.ZERO;
BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,timeB); for(Long depotId: depotList) {
BigDecimal prevSumStock = depotItemService.getStockByParam(depotId,mId,null,timeA);
BigDecimal inSumStock = depotItemService.getInNumByParam(depotId,mId,timeA,timeB);
BigDecimal outSumStock = depotItemService.getOutNumByParam(depotId,mId,timeA,timeB);
BigDecimal thisSumStock = depotItemService.getStockByParam(depotId,mId,null,timeB);
prevSum = prevSum.add(prevSumStock);
inSum = inSum.add(inSumStock);
outSum = outSum.add(outSumStock);
thisSum = thisSum.add(thisSumStock);
}
item.put("prevSum", prevSum);
item.put("inSum", inSum);
item.put("outSum", outSum);
item.put("thisSum", thisSum); item.put("thisSum", thisSum);
for(MaterialExtend me:meList) { for(MaterialExtend me:meList) {
if(me.getMaterialId().longValue() == diEx.getMId().longValue()) { if(me.getMaterialId().longValue() == diEx.getMId().longValue()) {
@@ -354,7 +381,7 @@ public class DepotItemController {
/** /**
* 统计总计金额 * 统计总计金额
* @param depotId * @param depotIds
* @param monthTime * @param monthTime
* @param materialParam * @param materialParam
* @param request * @param request
@@ -362,21 +389,36 @@ public class DepotItemController {
*/ */
@GetMapping(value = "/totalCountMoney") @GetMapping(value = "/totalCountMoney")
@ApiOperation(value = "统计总计金额") @ApiOperation(value = "统计总计金额")
public BaseResponseInfo totalCountMoney(@RequestParam(value = "depotId", required = false) Long depotId, public BaseResponseInfo totalCountMoney(@RequestParam(value = "depotIds", required = false) String depotIds,
@RequestParam("monthTime") String monthTime, @RequestParam("monthTime") String monthTime,
@RequestParam("materialParam") String materialParam, @RequestParam("materialParam") String materialParam,
HttpServletRequest request) throws Exception{ HttpServletRequest request) throws Exception{
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
String endTime = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME;
try { try {
String endTime = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME;
List<Long> depotList = new ArrayList<>();
if(StringUtil.isNotEmpty(depotIds)) {
depotList = StringUtil.strToLongList(depotIds);
} else {
//未选择仓库时默认为当前用户有权限的仓库
JSONArray depotArr = depotService.findDepotByCurrentUser();
for(Object obj: depotArr) {
JSONObject object = JSONObject.parseObject(obj.toString());
depotList.add(object.getLong("id"));
}
}
List<DepotItemVo4WithInfoEx> dataList = depotItemService.findByAll(StringUtil.toNull(materialParam), List<DepotItemVo4WithInfoEx> dataList = depotItemService.findByAll(StringUtil.toNull(materialParam),
endTime, null, null); endTime, null, null);
BigDecimal thisAllPrice = BigDecimal.ZERO; BigDecimal thisAllPrice = BigDecimal.ZERO;
if (null != dataList) { if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) {
Long mId = diEx.getMId(); Long mId = diEx.getMId();
BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,endTime); BigDecimal thisSum = BigDecimal.ZERO;
for(Long depotId: depotList) {
BigDecimal thisSumStock = depotItemService.getStockByParam(depotId,mId,null,endTime);
thisSum = thisSum.add(thisSumStock);
}
BigDecimal unitPrice = diEx.getPurchaseDecimal(); BigDecimal unitPrice = diEx.getPurchaseDecimal();
if(unitPrice == null) { if(unitPrice == null) {
unitPrice = BigDecimal.ZERO; unitPrice = BigDecimal.ZERO;