调整账户的查询分页方式

This commit is contained in:
jishenghua
2025-02-22 15:47:37 +08:00
parent 73110d1170
commit 4c91e8cb08
4 changed files with 40 additions and 73 deletions

View File

@@ -2,15 +2,17 @@ package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.base.BaseController;
import com.jsh.erp.base.TableDataInfo;
import com.jsh.erp.datasource.entities.Account;
import com.jsh.erp.datasource.vo.AccountVo4InOutList;
import com.jsh.erp.datasource.vo.AccountVo4List;
import com.jsh.erp.service.account.AccountService;
import com.jsh.erp.service.systemConfig.SystemConfigService;
import com.jsh.erp.utils.*;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.ErpInfo;
import com.jsh.erp.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
@@ -20,7 +22,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -34,7 +35,7 @@ import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
@RestController
@RequestMapping(value = "/account")
@Api(tags = {"账户管理"})
public class AccountController {
public class AccountController extends BaseController {
private Logger logger = LoggerFactory.getLogger(AccountController.class);
@Resource
@@ -59,30 +60,13 @@ public class AccountController {
@GetMapping(value = "/list")
@ApiOperation(value = "获取信息列表")
public String getList(@RequestParam(value = Constants.PAGE_SIZE, required = false) Integer pageSize,
@RequestParam(value = Constants.CURRENT_PAGE, required = false) Integer currentPage,
@RequestParam(value = Constants.SEARCH, required = false) String search,
HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
if (pageSize != null && pageSize <= 0) {
pageSize = 10;
}
public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search,
HttpServletRequest request)throws Exception {
String name = StringUtil.getInfo(search, "name");
String serialNo = StringUtil.getInfo(search, "serialNo");
String remark = StringUtil.getInfo(search, "remark");
IPage<AccountVo4List> page = new Page<>();
page.setCurrent(currentPage);
page.setSize(pageSize);
IPage<AccountVo4List> list = accountService.select(page, name, serialNo, remark);
if (list != null) {
objectMap.put("total", list.getTotal());
objectMap.put("rows", list.getRecords());
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
objectMap.put("total", BusinessConstants.DEFAULT_LIST_NULL_NUMBER);
objectMap.put("rows", new ArrayList<Object>());
return returnJson(objectMap, "查找不到数据", ErpInfo.OK.code);
}
List<AccountVo4List> list = accountService.select(name, serialNo, remark);
return getDataTable(list);
}
@PostMapping(value = "/add")
@@ -267,28 +251,11 @@ public class AccountController {
*/
@GetMapping(value = "/listWithBalance")
@ApiOperation(value = "获取带余额的报表")
public BaseResponseInfo listWithBalance(@RequestParam("name") String name,
public TableDataInfo listWithBalance(@RequestParam("name") String name,
@RequestParam("serialNo") String serialNo,
@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
HttpServletRequest request) throws Exception {
BaseResponseInfo res = new BaseResponseInfo();
try {
Map<String, Object> map = new HashMap<>();
IPage<AccountVo4List> page = new Page<>();
page.setCurrent(currentPage);
page.setSize(pageSize);
IPage<AccountVo4List> list = accountService.listWithBalance(page, StringUtil.toNull(name), StringUtil.toNull(serialNo));
map.put("rows", list.getRecords());
map.put("total", list.getTotal());
res.code = 200;
res.data = map;
} catch(Exception e){
logger.error(e.getMessage(), e);
res.code = 500;
res.data = "获取数据失败";
}
return res;
List<AccountVo4List> list = accountService.listWithBalance(StringUtil.toNull(name), StringUtil.toNull(serialNo));
return getDataTable(list);
}
/**

View File

@@ -1,11 +1,8 @@
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jsh.erp.base.BaseController;
import com.jsh.erp.base.TableDataInfo;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.datasource.entities.Tenant;
import com.jsh.erp.datasource.entities.TenantEx;
import com.jsh.erp.service.tenant.TenantService;
@@ -18,7 +15,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

View File

@@ -1,6 +1,5 @@
package com.jsh.erp.datasource.mappers;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jsh.erp.datasource.entities.Account;
import com.jsh.erp.datasource.entities.AccountVo4Sum;
import com.jsh.erp.datasource.entities.DepotHead;
@@ -18,8 +17,7 @@ public interface AccountMapperEx {
@Param("name") String name,
@Param("serialNo") String serialNo);
IPage<AccountVo4List> selectByConditionAccount(
IPage<AccountVo4List> page,
List<AccountVo4List> selectByConditionAccount(
@Param("name") String name,
@Param("serialNo") String serialNo,
@Param("remark") String remark);
@@ -54,8 +52,8 @@ public interface AccountMapperEx {
@Param("beginTime") String beginTime,
@Param("endTime") String endTime,
@Param("forceFlag") Boolean forceFlag,
@Param("offset") Long offset,
@Param("rows") Long rows);
@Param("offset") Integer offset,
@Param("rows") Integer rows);
List<DepotHead> getManyAccountSumByParam(
@Param("beginTime") String beginTime,

View File

@@ -1,7 +1,8 @@
package com.jsh.erp.service.account;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jsh.erp.base.PageDomain;
import com.jsh.erp.base.TableSupport;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
@@ -13,6 +14,7 @@ import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.systemConfig.SystemConfigService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.PageUtils;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
@@ -99,10 +101,11 @@ public class AccountService {
return list;
}
public IPage<AccountVo4List> select(IPage<AccountVo4List> page, String name, String serialNo, String remark) throws Exception{
IPage<AccountVo4List> iPage = null;
public List<AccountVo4List> select(String name, String serialNo, String remark) throws Exception{
List<AccountVo4List> list = null;
try{
iPage = accountMapperEx.selectByConditionAccount(page, name, serialNo, remark);
PageUtils.startPage();
list = accountMapperEx.selectByConditionAccount(name, serialNo, remark);
String timeStr = Tools.getCurrentMonth();
String bTime = Tools.firstDayOfMonth(timeStr) + BusinessConstants.DAY_FIRST_TIME;
String eTime = Tools.lastDayOfMonth(timeStr) + BusinessConstants.DAY_LAST_TIME;
@@ -113,8 +116,9 @@ public class AccountService {
Map<Long, BigDecimal> currentAccountSumMap = new HashMap<>();
Map<Long, BigDecimal> currentAccountSumByHeadMap = new HashMap<>();
Map<Long, BigDecimal> currentAccountSumByDetailMap = new HashMap<>();
long offset = (page.getCurrent() - 1) * page.getSize();
long rows = page.getSize();
PageDomain pageDomain = TableSupport.buildPageRequest();
int offset = (pageDomain.getCurrentPage() - 1) * pageDomain.getPageSize();
int rows = pageDomain.getPageSize();
List<AccountVo4Sum> thisMonthAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, bTime, eTime, forceFlag, offset, rows);
List<AccountVo4Sum> currentAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, null, null, forceFlag, offset, rows);
List<DepotHead> thisMonthManyAmountList = accountMapperEx.getManyAccountSumByParam(bTime, eTime, forceFlag);
@@ -129,8 +133,8 @@ public class AccountService {
currentAccountSumByHeadMap.put(currentAmount.getId(), currentAmount.getAccountSumByHead());
currentAccountSumByDetailMap.put(currentAmount.getId(), currentAmount.getAccountSumByDetail());
}
if (null != iPage.getRecords()) {
for (AccountVo4List al : iPage.getRecords()) {
if (null != list) {
for (AccountVo4List al : list) {
DecimalFormat df = new DecimalFormat(".##");
BigDecimal thisMonthAmount = thisMonthAccountSumMap.get(al.getId())
.add(thisMonthAccountSumByHeadMap.get(al.getId()))
@@ -152,7 +156,7 @@ public class AccountService {
} catch(Exception e){
JshException.readFail(logger, e);
}
return iPage;
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
@@ -436,10 +440,11 @@ public class AccountService {
return sb.toString();
}
public IPage<AccountVo4List> listWithBalance(IPage<AccountVo4List> page, String name, String serialNo) throws Exception {
IPage<AccountVo4List> iPage = null;
public List<AccountVo4List> listWithBalance(String name, String serialNo) throws Exception {
List<AccountVo4List> list = null;
try{
iPage = accountMapperEx.selectByConditionAccount(page, name, serialNo, null);
PageUtils.startPage();
list = accountMapperEx.selectByConditionAccount(name, serialNo, null);
String timeStr = Tools.getCurrentMonth();
String bTime = Tools.firstDayOfMonth(timeStr) + BusinessConstants.DAY_FIRST_TIME;
String eTime = Tools.lastDayOfMonth(timeStr) + BusinessConstants.DAY_LAST_TIME;
@@ -450,8 +455,9 @@ public class AccountService {
Map<Long, BigDecimal> currentAccountSumMap = new HashMap<>();
Map<Long, BigDecimal> currentAccountSumByHeadMap = new HashMap<>();
Map<Long, BigDecimal> currentAccountSumByDetailMap = new HashMap<>();
long offset = (page.getCurrent() - 1) * page.getSize();
long rows = page.getSize();
PageDomain pageDomain = TableSupport.buildPageRequest();
int offset = (pageDomain.getCurrentPage() - 1) * pageDomain.getPageSize();
int rows = pageDomain.getPageSize();
List<AccountVo4Sum> thisMonthAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, bTime, eTime, forceFlag, offset, rows);
List<AccountVo4Sum> currentAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, null, null, forceFlag, offset, rows);
List<DepotHead> thisMonthManyAmountList = accountMapperEx.getManyAccountSumByParam(bTime, eTime, forceFlag);
@@ -466,8 +472,8 @@ public class AccountService {
currentAccountSumByHeadMap.put(currentAmount.getId(), currentAmount.getAccountSumByHead());
currentAccountSumByDetailMap.put(currentAmount.getId(), currentAmount.getAccountSumByDetail());
}
if (null != iPage.getRecords()) {
for (AccountVo4List al : iPage.getRecords()) {
if (null != list) {
for (AccountVo4List al : list) {
DecimalFormat df = new DecimalFormat(".##");
BigDecimal thisMonthAmount = thisMonthAccountSumMap.get(al.getId())
.add(thisMonthAccountSumByHeadMap.get(al.getId()))
@@ -489,7 +495,7 @@ public class AccountService {
} catch(Exception e){
JshException.readFail(logger, e);
}
return iPage;
return list;
}
public Map<String, Object> getStatistics(String name, String serialNo) {