【fix sonar】SysDictController.java 文件
This commit is contained in:
+60
-41
@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
@@ -69,13 +71,18 @@ public class SysDictController {
|
||||
@Autowired
|
||||
public RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@RequestMapping(value = "/page", method = RequestMethod.GET)
|
||||
private String DICT_CODE_ERROE = "字典Code格式不正确!";
|
||||
private String OPTION_SUCCESS = "操作成功!";
|
||||
private String DEL_SUCCESS = "删除成功!";
|
||||
|
||||
// @RequestMapping(value = "/page", method = RequestMethod.GET)
|
||||
@GetMapping("/page")
|
||||
@ApiOperation(value = "字典控制器-分页列表查询", notes = "字典控制器-分页列表查询")
|
||||
public Result<IPage<SysDict>> queryPageList(SysDict sysDict, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<IPage<SysDict>> result = new Result<IPage<SysDict>>();
|
||||
Result<IPage<SysDict>> result = new Result<>();
|
||||
QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, req.getParameterMap());
|
||||
Page<SysDict> page = new Page<SysDict>(pageNo, pageSize);
|
||||
Page<SysDict> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysDict> pageList = sysDictService.page(page, queryWrapper);
|
||||
log.debug("查询当前页:"+pageList.getCurrent());
|
||||
log.debug("查询当前页数量:"+pageList.getSize());
|
||||
@@ -95,7 +102,8 @@ public class SysDictController {
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-树形字典数据", notes = "字典控制器-树形字典数据")
|
||||
@RequestMapping(value = "/treeList", method = RequestMethod.GET)
|
||||
// @RequestMapping(value = "/treeList", method = RequestMethod.GET)
|
||||
@GetMapping("/treeList")
|
||||
public Result<List<SysDictTree>> treeList(SysDict sysDict, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<List<SysDictTree>> result = new Result<>();
|
||||
@@ -122,9 +130,10 @@ public class SysDictController {
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-获取全部字典数据", notes = "字典控制器-获取全部字典数据")
|
||||
@RequestMapping(value = "/queryAllDictItems", method = RequestMethod.GET)
|
||||
public Result<?> queryAllDictItems(HttpServletRequest request) {
|
||||
Map<String, List<DictModel>> res = new HashMap<String, List<DictModel>>();
|
||||
// @RequestMapping(value = "/queryAllDictItems", method = RequestMethod.GET)
|
||||
@GetMapping("/queryAllDictItems")
|
||||
public Result<Map<String, List<DictModel>>> queryAllDictItems(HttpServletRequest request) {
|
||||
Map<String, List<DictModel>> res ;
|
||||
res = sysDictService.queryAllDictItems();
|
||||
return Result.OK(res);
|
||||
}
|
||||
@@ -135,10 +144,11 @@ public class SysDictController {
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-通过字典code和字典值key获取字典数据", notes = "字典控制器-通过字典code和字典值key获取字典数据")
|
||||
@RequestMapping(value = "/getDictText/{dictCode}/{key}", method = RequestMethod.GET)
|
||||
// @RequestMapping(value = "/getDictText/{dictCode}/{key}", method = RequestMethod.GET)
|
||||
@GetMapping("/getDictText/{dictCode}/{key}")
|
||||
public Result<String> getDictText(@PathVariable("dictCode") String dictCode, @PathVariable("key") String key) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Result<String> result = new Result<String>();
|
||||
Result<String> result = new Result<>();
|
||||
String text = null;
|
||||
try {
|
||||
text = sysDictService.queryDictTextByKey(dictCode, key);
|
||||
@@ -157,14 +167,15 @@ public class SysDictController {
|
||||
* @param dictCode 表名,文本字段,code字段 | 举例:sys_user,realname,id
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
|
||||
// @RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
|
||||
@GetMapping("/getDictItems/{dictCode}")
|
||||
public Result<List<DictModel>> getDictItems(@PathVariable String dictCode, @RequestParam(value = "sign",required = false) String sign,HttpServletRequest request) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Result<List<DictModel>> result = new Result<List<DictModel>>();
|
||||
Result<List<DictModel>> result = new Result<>();
|
||||
try {
|
||||
List<DictModel> ls = sysDictService.getDictItems(dictCode);
|
||||
if (ls == null) {
|
||||
return Result.error("字典Code格式不正确!");
|
||||
return Result.error(DICT_CODE_ERROE);
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
@@ -183,17 +194,18 @@ public class SysDictController {
|
||||
* @param dictCode 字典code格式:table,text,code
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/loadDict/{dictCode}", method = RequestMethod.GET)
|
||||
// @RequestMapping(value = "/loadDict/{dictCode}", method = RequestMethod.GET)
|
||||
@GetMapping("/loadDict/{dictCode}")
|
||||
public Result<List<DictModel>> loadDict(@PathVariable String dictCode,
|
||||
@RequestParam(name="keyword") String keyword,
|
||||
@RequestParam(value = "sign",required = false) String sign,
|
||||
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||
log.info(" 加载字典表数据,加载关键字: "+ keyword);
|
||||
Result<List<DictModel>> result = new Result<List<DictModel>>();
|
||||
Result<List<DictModel>> result = new Result<>();
|
||||
try {
|
||||
List<DictModel> ls = sysDictService.loadDict(dictCode, keyword, pageSize);
|
||||
if (ls == null) {
|
||||
return Result.error("字典Code格式不正确!");
|
||||
return Result.error(DICT_CODE_ERROE);
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
@@ -213,7 +225,8 @@ public class SysDictController {
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/loadDictOrderByValue/{dictCode}", method = RequestMethod.GET)
|
||||
// @RequestMapping(value = "/loadDictOrderByValue/{dictCode}", method = RequestMethod.GET)
|
||||
@GetMapping("/loadDictOrderByValue/{dictCode}")
|
||||
public Result<List<DictModel>> loadDictOrderByValue(
|
||||
@PathVariable String dictCode,
|
||||
@RequestParam(name = "keyword") String keyword,
|
||||
@@ -255,14 +268,15 @@ public class SysDictController {
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/loadDictItem/{dictCode}", method = RequestMethod.GET)
|
||||
// @RequestMapping(value = "/loadDictItem/{dictCode}", method = RequestMethod.GET)
|
||||
@GetMapping("/loadDictItem/{dictCode}")
|
||||
public Result<List<String>> loadDictItem(@PathVariable String dictCode,@RequestParam(name="key") String keys, @RequestParam(value = "sign",required = false) String sign,@RequestParam(value = "delNotExist",required = false,defaultValue = "true") boolean delNotExist,HttpServletRequest request) {
|
||||
Result<List<String>> result = new Result<>();
|
||||
try {
|
||||
if(dictCode.indexOf(",")!=-1) {
|
||||
String[] params = dictCode.split(",");
|
||||
if(params.length!=3) {
|
||||
return Result.error("字典Code格式不正确!");
|
||||
return Result.error(DICT_CODE_ERROE);
|
||||
}
|
||||
List<String> texts = sysDictService.queryTableDictByKeys(params[0], params[1], params[2], keys, delNotExist);
|
||||
|
||||
@@ -270,7 +284,7 @@ public class SysDictController {
|
||||
result.setResult(texts);
|
||||
log.info(result.toString());
|
||||
}else {
|
||||
return Result.error("字典Code格式不正确!");
|
||||
return Result.error(DICT_CODE_ERROE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
@@ -285,14 +299,15 @@ public class SysDictController {
|
||||
* 根据表名——显示字段-存储字段 pid 加载树形数据
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-根据表名—显示字段-存储字段 pid 加载树形数据", notes = "字典控制器-根据表名—显示字段-存储字段 pid 加载树形数据")
|
||||
@RequestMapping(value = "/loadTreeData", method = RequestMethod.GET)
|
||||
// @RequestMapping(value = "/loadTreeData", method = RequestMethod.GET)
|
||||
@GetMapping("/loadTreeData")
|
||||
public Result<List<TreeSelectModel>> loadTreeData(@RequestParam(name="pid") String pid, @RequestParam(name="pidField") String pidField,
|
||||
@RequestParam(name="tableName") String tbname,
|
||||
@RequestParam(name="text") String text,
|
||||
@RequestParam(name="code") String code,
|
||||
@RequestParam(name="hasChildField", required = false) String hasChildField,
|
||||
@RequestParam(value = "sign", required = false) String sign, HttpServletRequest request) {
|
||||
Result<List<TreeSelectModel>> result = new Result<List<TreeSelectModel>>();
|
||||
Result<List<TreeSelectModel>> result = new Result<>();
|
||||
|
||||
// SQL注入漏洞 sign签名校验(表名,label字段,val字段,条件)
|
||||
String dictCode = tbname +","+ text +","+ code;
|
||||
@@ -307,13 +322,14 @@ public class SysDictController {
|
||||
* 查询后返回树型数据
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-根据表名—显示字段-存储字段 加载树形数据", notes = "字典控制器-根据表名—显示字段-存储字段 加载树形数据")
|
||||
@RequestMapping(value = "/queryAllTreeData", method = RequestMethod.GET)
|
||||
// @RequestMapping(value = "/queryAllTreeData", method = RequestMethod.GET)
|
||||
@GetMapping("/queryAllTreeData")
|
||||
public Result<List<TreeSelectModel>> queryAllTreeData(@RequestParam(name="pidField") String pidField,
|
||||
@RequestParam(name="tableName") String tbname,
|
||||
@RequestParam(name="text") String text,
|
||||
@RequestParam(name="code") String code,
|
||||
HttpServletRequest request) {
|
||||
Result<List<TreeSelectModel>> result = new Result<List<TreeSelectModel>>();
|
||||
Result<List<TreeSelectModel>> result = new Result<>();
|
||||
|
||||
// SQL注入漏洞 sign签名校验(表名,label字段,val字段,条件)
|
||||
String dictCode = tbname +","+ text +","+ code;
|
||||
@@ -330,7 +346,8 @@ public class SysDictController {
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-新增字典", notes = "字典控制器-新增字典")
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
// @RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
@PostMapping("/add")
|
||||
public Result<Object> add(@RequestBody SysDict sysDict) {
|
||||
try {
|
||||
sysDict.setCreateTime(new Date());
|
||||
@@ -338,7 +355,7 @@ public class SysDictController {
|
||||
sysDictService.save(sysDict);
|
||||
//添加成功后需要刷新缓存
|
||||
sysDictService.refreshCache();
|
||||
return Result.OK("操作成功!");
|
||||
return Result.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Result.error("操作失败");
|
||||
@@ -351,7 +368,8 @@ public class SysDictController {
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-编辑字典", notes = "字典控制器-编辑字典")
|
||||
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
|
||||
// @RequestMapping(value = "/edit", method = RequestMethod.PUT)
|
||||
@PutMapping("/edit")
|
||||
public Result<Object> edit(@RequestBody SysDict sysDict) {
|
||||
SysDict sysdict = sysDictService.getById(sysDict.getId());
|
||||
if(sysdict==null) {
|
||||
@@ -362,7 +380,7 @@ public class SysDictController {
|
||||
if(ok) {
|
||||
//编辑成功后需要刷新缓存
|
||||
sysDictService.refreshCache();
|
||||
return Result.OK("操作成功!");
|
||||
return Result.OK(OPTION_SUCCESS);
|
||||
}
|
||||
}
|
||||
return Result.OK();
|
||||
@@ -379,7 +397,7 @@ public class SysDictController {
|
||||
public Result<Object> delete(@RequestParam(name="id",required=true) String id) {
|
||||
boolean ok = sysDictService.removeById(id);
|
||||
if(ok) {
|
||||
return Result.OK("删除成功!");
|
||||
return Result.OK(DEL_SUCCESS);
|
||||
}else{
|
||||
return Result.error("删除失败!");
|
||||
}
|
||||
@@ -398,7 +416,7 @@ public class SysDictController {
|
||||
return Result.error("参数不识别!");
|
||||
}else {
|
||||
sysDictService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("删除成功!");
|
||||
return Result.OK(DEL_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,8 +426,8 @@ public class SysDictController {
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/refleshCache")
|
||||
public Result<?> refleshCache() {
|
||||
Result<?> result = new Result<SysDict>();
|
||||
public Result<SysDict> refleshCache() {
|
||||
Result<SysDict> result = new Result<>();
|
||||
sysDictService.refreshCache();
|
||||
return result;
|
||||
}
|
||||
@@ -425,7 +443,7 @@ public class SysDictController {
|
||||
QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, request.getParameterMap());
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
List<SysDictPage> pageList = new ArrayList<SysDictPage>();
|
||||
List<SysDictPage> pageList = new ArrayList<>();
|
||||
|
||||
List<SysDict> sysDictList = sysDictService.list(queryWrapper);
|
||||
for (SysDict dictMain : sysDictList) {
|
||||
@@ -438,12 +456,12 @@ public class SysDictController {
|
||||
}
|
||||
|
||||
// 导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "数据字典");
|
||||
mv.addObject(JeroController.FILE_NAME, "数据字典");
|
||||
// 注解对象Class
|
||||
mv.addObject(NormalExcelConstants.CLASS, SysDictPage.class);
|
||||
mv.addObject(JeroController.CLASS, SysDictPage.class);
|
||||
// 自定义表格参数
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("数据字典列表", "导出人:"+user.getRealname(), "数据字典"));
|
||||
mv.addObject(JeroController.PARAMS, new ExportParams("数据字典列表", "导出人:"+user.getRealname(), "数据字典"));
|
||||
// 导出数据列表
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
@@ -451,7 +469,7 @@ public class SysDictController {
|
||||
|
||||
|
||||
@PostMapping(value = "/importExcel")
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
public Result<T> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
@@ -469,7 +487,8 @@ public class SysDictController {
|
||||
List<SysDictPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SysDictPage.class, params);
|
||||
// 错误信息
|
||||
List<String> errorMessage = new ArrayList<>();
|
||||
int successLines = 0, errorLines = 0;
|
||||
int successLines = 0;
|
||||
int errorLines = 0;
|
||||
for (int i=0;i< list.size();i++) {
|
||||
SysDict po = new SysDict();
|
||||
BeanUtils.copyProperties(list.get(i), po);
|
||||
@@ -521,10 +540,10 @@ public class SysDictController {
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deletePhysic/{id}")
|
||||
public Result<?> deletePhysic(@PathVariable String id) {
|
||||
public Result<T> deletePhysic(@PathVariable String id) {
|
||||
try {
|
||||
sysDictService.deleteOneDictPhysically(id);
|
||||
return Result.OK("删除成功!");
|
||||
return Result.OK(DEL_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("删除失败!");
|
||||
@@ -537,10 +556,10 @@ public class SysDictController {
|
||||
* @return
|
||||
*/
|
||||
@PutMapping(value = "/back/{id}")
|
||||
public Result<?> back(@PathVariable String id) {
|
||||
public Result<T> back(@PathVariable String id) {
|
||||
try {
|
||||
sysDictService.updateDictDelFlag(0,id);
|
||||
return Result.OK("操作成功!");
|
||||
return Result.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("操作失败!");
|
||||
|
||||
Reference in New Issue
Block a user