Skip to content

Commit

Permalink
Api controller change
Browse files Browse the repository at this point in the history
  • Loading branch information
Jzow committed Sep 4, 2023
1 parent be98f9c commit c6667e0
Show file tree
Hide file tree
Showing 35 changed files with 585 additions and 208 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
hs_err_pid*

.idea
**/target
**/target/
/logs.home_IS_UNDEFINED

**/*.iml
.gitattributes

/api/src/main/resources/application-prod.yml
43 changes: 43 additions & 0 deletions api/src/main/java/com/wansensoft/api/LogController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.wansensoft.api;

import com.wansensoft.entities.log.Log;
import com.wansensoft.entities.user.User;
import com.wansensoft.service.log.LogService;
import com.wansensoft.utils.BaseResponseInfo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/log")
public class LogController {

private final LogService logService;

public LogController(LogService logService) {
this.logService = logService;
}

@GetMapping("/getAllList")
public BaseResponseInfo getAllList(HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo();
try {
Map<String, Object> data = new HashMap<>();
List<Log> dataList = logService.getLog();
if(dataList!=null) {
data.put("logList", dataList);
}
res.code = 200;
res.data = data;
} catch(Exception e){
res.code = 500;
res.data = "获取失败";
}
return res;
}
}
24 changes: 24 additions & 0 deletions api/src/main/java/com/wansensoft/api/MybatisPlusConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.wansensoft.api;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("com.wansensoft.mappers")
public class MybatisPlusConfig {

/**
* 添加分页插件
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
90 changes: 60 additions & 30 deletions api/src/main/java/com/wansensoft/api/ResourceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.wansensoft.utils.constants.BusinessConstants;
import com.wansensoft.service.CommonQueryManager;
import com.wansensoft.utils.*;
import com.wansensoft.utils.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -19,34 +19,37 @@
@Api(tags = {"资源接口"})
public class ResourceController {

@Resource
private CommonQueryManager configResourceManager;
private final CommonQueryManager configResourceManager;

public ResourceController(CommonQueryManager configResourceManager) {
this.configResourceManager = configResourceManager;
}

@GetMapping(value = "/{apiName}/info")
@ApiOperation(value = "根据id获取信息")
public String getList(@PathVariable("apiName") String apiName,
public Response<Map<String, Object>> getList(@PathVariable("apiName") String apiName,
@RequestParam("id") Long id,
HttpServletRequest request) throws Exception {
Object obj = configResourceManager.selectOne(apiName, id);
Map<String, Object> objectMap = new HashMap<String, Object>();
if(obj != null) {
objectMap.put("info", obj);
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseData(objectMap);
} else {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
return Response.responseMsg(ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}

@GetMapping(value = "/{apiName}/list")
@ApiOperation(value = "获取信息列表")
public String getList(@PathVariable("apiName") String apiName,
public Response getList(@PathVariable("apiName") String apiName,
@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, String> parameterMap = ParamUtils.requestToMap(request);
parameterMap.put(Constants.SEARCH, search);
Map<String, Object> objectMap = new HashMap<String, Object>();
Map<String, Object> objectMap = new HashMap<>();
if (pageSize != null && pageSize <= 0) {
pageSize = 10;
}
Expand All @@ -58,77 +61,104 @@ public String getList(@PathVariable("apiName") String apiName,
if (list != null) {
objectMap.put("total", configResourceManager.counts(apiName, parameterMap));
objectMap.put("rows", list);
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseData(objectMap);
} else {
objectMap.put("total", BusinessConstants.DEFAULT_LIST_NULL_NUMBER);
objectMap.put("rows", new ArrayList<Object>());
return ResponseJsonUtil.returnJson(objectMap, "查找不到数据", ErpInfo.OK.code);
return Response.responseMsg(CodeEnum.QUERY_DATA_EMPTY);
}
}
// @GetMapping(value = "/{apiName}/list")
// @ApiOperation(value = "获取信息列表")
// public String getList(@PathVariable("apiName") String apiName,
// @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, String> parameterMap = ParamUtils.requestToMap(request);
// parameterMap.put(Constants.SEARCH, search);
// 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<?> list = configResourceManager.select(apiName, parameterMap);
// if (list != null) {
// objectMap.put("total", configResourceManager.counts(apiName, parameterMap));
// objectMap.put("rows", list);
// System.err.println(ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, Integer.parseInt(ErpInfo.OK.code)));
// return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, Integer.parseInt(ErpInfo.OK.code));
// } else {
// objectMap.put("total", BusinessConstants.DEFAULT_LIST_NULL_NUMBER);
// objectMap.put("rows", new ArrayList<Object>());
// return ResponseJsonUtil.returnJson(objectMap, "查找不到数据", Integer.parseInt(ErpInfo.OK.code));
// }
// }

@PostMapping(value = "/{apiName}/add", produces = {"application/javascript", "application/json"})
@ApiOperation(value = "新增")
public String addResource(@PathVariable("apiName") String apiName,
public Response addResource(@PathVariable("apiName") String apiName,
@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<String, Object>();
int insert = configResourceManager.insert(apiName, obj, request);
if(insert > 0) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseMsg(ErpInfo.OK.name, ErpInfo.OK.code);
} else if(insert == -1) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
return Response.responseMsg(ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
} else {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
return Response.responseMsg(ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}

@PutMapping(value = "/{apiName}/update", produces = {"application/javascript", "application/json"})
@ApiOperation(value = "修改")
public String updateResource(@PathVariable("apiName") String apiName,
public Response updateResource(@PathVariable("apiName") String apiName,
@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<String, Object>();
int update = configResourceManager.update(apiName, obj, request);
if(update > 0) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseMsg(ErpInfo.OK.name, ErpInfo.OK.code);
} else if(update == -1) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
return Response.responseMsg(ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
} else {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
return Response.responseMsg(ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}

@DeleteMapping(value = "/{apiName}/delete", produces = {"application/javascript", "application/json"})
@ApiOperation(value = "删除")
public String deleteResource(@PathVariable("apiName") String apiName,
public Response deleteResource(@PathVariable("apiName") String apiName,
@RequestParam("id") Long id, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<String, Object>();
int delete = configResourceManager.delete(apiName, id, request);
if(delete > 0) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseMsg(ErpInfo.OK.name, ErpInfo.OK.code);
} else if(delete == -1) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
return Response.responseMsg(ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
} else {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
return Response.responseMsg(ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}

@DeleteMapping(value = "/{apiName}/deleteBatch", produces = {"application/javascript", "application/json"})
@ApiOperation(value = "批量删除")
public String batchDeleteResource(@PathVariable("apiName") String apiName,
public Response batchDeleteResource(@PathVariable("apiName") String apiName,
@RequestParam("ids") String ids, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<String, Object>();
int delete = configResourceManager.deleteBatch(apiName, ids, request);
if(delete > 0) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseMsg(ErpInfo.OK.name, ErpInfo.OK.code);
} else if(delete == -1) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
return Response.responseMsg(ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
} else {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
return Response.responseMsg(ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}

@GetMapping(value = "/{apiName}/checkIsNameExist")
@ApiOperation(value = "检查名称是否存在")
public String checkIsNameExist(@PathVariable("apiName") String apiName,
public Response<Map<String, Object>> checkIsNameExist(@PathVariable("apiName") String apiName,
@RequestParam Long id, @RequestParam(value ="name", required = false) String name,
HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<String, Object>();
Expand All @@ -138,7 +168,7 @@ public String checkIsNameExist(@PathVariable("apiName") String apiName,
} else {
objectMap.put("status", false);
}
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseData(objectMap);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import com.wansensoft.service.systemConfig.SystemConfigService;
import com.wansensoft.utils.BaseResponseInfo;
import com.wansensoft.utils.ErpInfo;
import com.wansensoft.utils.ResponseJsonUtil;
import com.wansensoft.utils.Response;
import com.wansensoft.utils.enums.CodeEnum;
import com.wansensoft.vo.AccountVo4InOutList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand Down Expand Up @@ -153,15 +154,15 @@ public BaseResponseInfo findAccountInOutList(@RequestParam("currentPage") Intege
*/
@PostMapping(value = "/updateIsDefault")
@ApiOperation(value = "更新默认账户")
public String updateIsDefault(@RequestBody JSONObject object,
public Response updateIsDefault(@RequestBody JSONObject object,
HttpServletRequest request) throws Exception{
Long accountId = object.getLong("id");
Map<String, Object> objectMap = new HashMap<>();
int res = accountService.updateIsDefault(accountId);
if(res > 0) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseData(objectMap);
} else {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
return Response.responseData(CodeEnum.ERROR);
}
}

Expand Down Expand Up @@ -196,16 +197,16 @@ public BaseResponseInfo getStatistics(@RequestParam("name") String name,
*/
@PostMapping(value = "/batchSetStatus")
@ApiOperation(value = "批量设置状态")
public String batchSetStatus(@RequestBody JSONObject jsonObject,
public Response batchSetStatus(@RequestBody JSONObject jsonObject,
HttpServletRequest request)throws Exception {
Boolean status = jsonObject.getBoolean("status");
String ids = jsonObject.getString("ids");
Map<String, Object> objectMap = new HashMap<>();
int res = accountService.batchSetStatus(status, ids);
if(res > 0) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseData(objectMap);
} else {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
return Response.responseData(CodeEnum.ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.wansensoft.entities.account.AccountHeadVo4Body;
import com.wansensoft.entities.account.AccountHeadVo4ListEx;
import com.wansensoft.service.accountHead.AccountHeadService;
import com.wansensoft.utils.Response;
import com.wansensoft.utils.constants.ExceptionConstants;
import com.wansensoft.utils.BaseResponseInfo;
import com.wansensoft.utils.ErpInfo;
import com.wansensoft.utils.ResponseJsonUtil;
import com.wansensoft.utils.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
Expand Down Expand Up @@ -37,16 +37,16 @@ public class AccountHeadController {
*/
@PostMapping(value = "/batchSetStatus")
@ApiOperation(value = "批量设置状态-审核或者反审核")
public String batchSetStatus(@RequestBody JSONObject jsonObject,
public Response batchSetStatus(@RequestBody JSONObject jsonObject,
HttpServletRequest request) throws Exception{
Map<String, Object> objectMap = new HashMap<>();
String status = jsonObject.getString("status");
String ids = jsonObject.getString("ids");
int res = accountHeadService.batchSetStatus(status, ids);
if(res > 0) {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
return Response.responseData(objectMap);
} else {
return ResponseJsonUtil.returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
return Response.responseData(CodeEnum.ERROR);
}
}

Expand Down
Loading

0 comments on commit c6667e0

Please sign in to comment.