优化账户和租户两个模块的接口

This commit is contained in:
jishenghua
2025-02-21 01:28:44 +08:00
parent 20b100b5e2
commit 53004b1fa5
19 changed files with 263 additions and 392 deletions

View File

@@ -2,14 +2,15 @@ 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.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.AccountService;
import com.jsh.erp.service.systemConfig.SystemConfigService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
@@ -19,11 +20,13 @@ 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;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
/**
* @author jishenghua 75271*8920
@@ -40,6 +43,94 @@ public class AccountController {
@Resource
private SystemConfigService systemConfigService;
@GetMapping(value = "/info")
@ApiOperation(value = "根据id获取信息")
public String getList(@RequestParam("id") Long id,
HttpServletRequest request) throws Exception {
Account account = accountService.getAccount(id);
Map<String, Object> objectMap = new HashMap<>();
if(account != null) {
objectMap.put("info", account);
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
@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;
}
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);
}
}
@PostMapping(value = "/add")
@ApiOperation(value = "新增")
public String addResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int insert = accountService.insertAccount(obj, request);
return returnStr(objectMap, insert);
}
@PutMapping(value = "/update")
@ApiOperation(value = "修改")
public String updateResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int update = accountService.updateAccount(obj, request);
return returnStr(objectMap, update);
}
@DeleteMapping(value = "/delete")
@ApiOperation(value = "删除")
public String deleteResource(@RequestParam("id") Long id, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int delete = accountService.deleteAccount(id, request);
return returnStr(objectMap, delete);
}
@DeleteMapping(value = "/deleteBatch")
@ApiOperation(value = "批量删除")
public String batchDeleteResource(@RequestParam("ids") String ids, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int delete = accountService.batchDeleteAccount(ids, request);
return returnStr(objectMap, delete);
}
@GetMapping(value = "/checkIsNameExist")
@ApiOperation(value = "检查名称是否存在")
public String checkIsNameExist(@RequestParam Long id, @RequestParam(value ="name", required = false) String name,
HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int exist = accountService.checkIsNameExist(id, name);
if(exist > 0) {
objectMap.put("status", true);
} else {
objectMap.put("status", false);
}
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
}
/**
* 查找结算账户信息-下拉框
* @param request
@@ -184,10 +275,12 @@ public class AccountController {
BaseResponseInfo res = new BaseResponseInfo();
try {
Map<String, Object> map = new HashMap<>();
List<AccountVo4List> list = accountService.listWithBalance(StringUtil.toNull(name), StringUtil.toNull(serialNo), (currentPage-1)*pageSize, pageSize);
Long count = accountService.listWithBalanceCount(StringUtil.toNull(name), StringUtil.toNull(serialNo));
map.put("rows", list);
map.put("total", count);
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){