|
|
@ -1,4 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.controller;
|
|
|
|
package com.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
@ -35,246 +34,276 @@ import com.alibaba.fastjson.*;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 字典表
|
|
|
|
* 字典表
|
|
|
|
* 后端接口
|
|
|
|
* 后端接口
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 该类作为 Spring MVC 的控制器,用
|
|
|
|
|
|
|
|
* 于处理与字典表相关的各种后端接口请求,
|
|
|
|
|
|
|
|
* 包含了对字典表数据的查询、新增、修改、删除以及一些其他相关操作的接口
|
|
|
|
|
|
|
|
* 方法,
|
|
|
|
|
|
|
|
* 通过依赖注入相关的服务层接口,调用对应的业务逻辑方法来实现具体功能,并使用日志记录操作信息,方便调试和问题排查。
|
|
|
|
* @author
|
|
|
|
* @author
|
|
|
|
* @email
|
|
|
|
* @email
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@Controller
|
|
|
|
@Controller
|
|
|
|
@RequestMapping("/dictionary")
|
|
|
|
@RequestMapping("/dictionary")
|
|
|
|
public class DictionaryController {
|
|
|
|
public class DictionaryController {
|
|
|
|
|
|
|
|
// 创建一个日志记录器,
|
|
|
|
|
|
|
|
// 用于记录该控制器类中各个方法执行过程中的相关信息,
|
|
|
|
|
|
|
|
// 方便在开发、调试以及运行时查看操作情况、排查问题等。
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DictionaryController.class);
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DictionaryController.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 通过 Spring 的依赖注入机制,
|
|
|
|
|
|
|
|
// 自动注入 DictionaryService 接口的实现类实例,用于调用字典表相关的业务逻辑方法,
|
|
|
|
|
|
|
|
// 比如查询分页数据、保存字典数据、
|
|
|
|
|
|
|
|
// 更新字典数据等操作,实现与数据库中字典表的交互。
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private DictionaryService dictionaryService;
|
|
|
|
private DictionaryService dictionaryService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 通过 Spring 的依赖注入机制,
|
|
|
|
|
|
|
|
// 自动注入 TokenService 接口的实现类实例,可能用于与用户身份验证相关的操作,
|
|
|
|
|
|
|
|
// 例如验证请求中携带的 token
|
|
|
|
|
|
|
|
// 是否有效等,确保接口访问的安全性(虽然在当前代码中未看到明确的使用场景,但具备这种依赖注入的可能性)。
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private TokenService tokenService;
|
|
|
|
private TokenService tokenService;
|
|
|
|
|
|
|
|
|
|
|
|
//级联表service
|
|
|
|
// 通过 Spring 的依赖注入机制,自动注入
|
|
|
|
|
|
|
|
// YonghuService 接口的实现类实例,这应该是与用户相关的服务层接口,
|
|
|
|
|
|
|
|
// 从名称来看可能用于处理用户相关的业务逻辑
|
|
|
|
|
|
|
|
// (在当前代码中虽未体现具体使用,但为后续扩展或关联用户操作预留了可能),属于级联表相关的服务注入。
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private YonghuService yonghuService;
|
|
|
|
private YonghuService yonghuService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 后端列表
|
|
|
|
* 后端列表
|
|
|
|
*/
|
|
|
|
* 用于处理获取字典表数据列表的请求,
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 支持分页查询以及按照指定字段排序,同时会对查询结果中的字典表数据进行转换处理(通过 `dictionaryConvert` 方法)。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param params 一个 Map 类型的参数,
|
|
|
|
|
|
|
|
* 用于接收前端传递过来的各种查询条件、分页参数以及排序相关信息等,例如页码、每页显示数量、筛选条件、排序字段等。
|
|
|
|
|
|
|
|
* @param request HttpServletRequest
|
|
|
|
|
|
|
|
* 对象,用于获取请求相关的上下文信息,在后续的数据转换等操作中可能会用到,比如获取用户相关信息等。
|
|
|
|
|
|
|
|
* @return 返回一个 `R` 类型的结果对象
|
|
|
|
|
|
|
|
* (从 `com.utils.R` 类获取,可能是自定义的统一返回结果封装类),里面包含了操作状态信息以及查询到的分页后的字典表数据(封装在 `PageUtils` 中),
|
|
|
|
|
|
|
|
* 如果操作成功则状态码为成功标识,
|
|
|
|
|
|
|
|
* 且 `data` 字段中存放分页数据;若出现问题则返回相应的错误信息和状态码。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@RequestMapping("/page")
|
|
|
|
@RequestMapping("/page")
|
|
|
|
@IgnoreAuth
|
|
|
|
@IgnoreAuth
|
|
|
|
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
|
|
|
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request) {
|
|
|
|
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
|
|
|
// 使用日志记录器记录当前
|
|
|
|
if(params.get("orderBy")==null || params.get("orderBy")==""){
|
|
|
|
// `page` 方法的执行情况,记录控制器类的名称以及传入的查询参数信息
|
|
|
|
params.put("orderBy","id");
|
|
|
|
// (将参数转换为 JSON 字符串格式记录),方便调试查看请求参数是否正确等情况。
|
|
|
|
|
|
|
|
logger.debug("page方法:,,Controller:{},,params:{}", this.getClass().getName(), JSONObject.toJSONString(params));
|
|
|
|
|
|
|
|
// 如果传入的参数中没有指定排序字段
|
|
|
|
|
|
|
|
// (`orderBy`)或者排序字段为空字符串,则默认按照 `id` 字段进行排序,设置默认的排序规则。
|
|
|
|
|
|
|
|
if (params.get("orderBy") == null || params.get("orderBy") == "") {
|
|
|
|
|
|
|
|
params.put("orderBy", "id");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 调用 `dictionaryService` 的
|
|
|
|
|
|
|
|
// `queryPage` 方法,传入查询参数 `params`,
|
|
|
|
|
|
|
|
// 获取分页后的字典表数据,该方法内部会与数据库交互进行查询操作,返回 `PageUtils` 对象,
|
|
|
|
|
|
|
|
// 里面包含了分页数据以及分页相关的元信息(如总记录数、总页数等)。
|
|
|
|
PageUtils page = dictionaryService.queryPage(params);
|
|
|
|
PageUtils page = dictionaryService.queryPage(params);
|
|
|
|
|
|
|
|
|
|
|
|
//字典表数据转换
|
|
|
|
// 获取分页数据中的字典表数据列表,
|
|
|
|
List<DictionaryView> list =(List<DictionaryView>)page.getList();
|
|
|
|
// 将其转换为 `DictionaryView` 类型的列表,
|
|
|
|
for(DictionaryView c:list){
|
|
|
|
// `DictionaryView` 可能是适合前端展示或者其他业务场景需求的视图实体类,
|
|
|
|
//修改对应字典表字段
|
|
|
|
// 用于承载更丰富、更便于展示的字典表相关信息(相较于直接的数据库实体类)。
|
|
|
|
|
|
|
|
List<DictionaryView> list = (List<DictionaryView>) page.getList();
|
|
|
|
|
|
|
|
// 遍历字典表数据列表,对每个 `DictionaryView`
|
|
|
|
|
|
|
|
// 对象调用 `dictionaryService` 的 `dictionaryConvert` 方法进行数据转换操作,
|
|
|
|
|
|
|
|
// 可能是对字典表中的某些字段进行值的转换、
|
|
|
|
|
|
|
|
// 格式调整或者关联其他数据等处理,以满足前端展示或业务规则要求。
|
|
|
|
|
|
|
|
for (DictionaryView c : list) {
|
|
|
|
dictionaryService.dictionaryConvert(c, request);
|
|
|
|
dictionaryService.dictionaryConvert(c, request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 返回包含操作成功状态信息(通过 `R.ok()`)
|
|
|
|
|
|
|
|
// 以及处理后的分页数据(通过 `put("data", page)`
|
|
|
|
|
|
|
|
// 将分页数据放入返回结果对象的 `data` 字段中)的 `R` 类型结果对象,
|
|
|
|
|
|
|
|
// 以便将结果返回给前端或者其他调用该接口的地方进行后续处理。
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 后端详情
|
|
|
|
* 后端详情
|
|
|
|
*/
|
|
|
|
* 用于处理获取指定 `id` 的字典表数据详情的请求,
|
|
|
|
|
|
|
|
* 先从数据库中查询出对应的数据实体,
|
|
|
|
|
|
|
|
* 然后转换为视图实体类并进行相应的数据转换操作后返回给前端。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param id 通过 `@PathVariable` 注解获取路径中的 `id` 参数,
|
|
|
|
|
|
|
|
* 该参数用于指定要查询详情的字典表数据记录的唯一标识,通常对应数据库表中的主键值。
|
|
|
|
|
|
|
|
* @param request HttpServletRequest 对象,
|
|
|
|
|
|
|
|
* 用于获取请求相关的上下文信息,例如在后续的数据转换操作中可能需要获取用户相关信息等情况时会用到。
|
|
|
|
|
|
|
|
* @return 返回一个 `R` 类型的结果对象,若查询到对应的数据记录,
|
|
|
|
|
|
|
|
* 则将转换后的视图实体类(包含字典表数据详情以及经过转换后的相关字段信息)放入 `data` 字段中,
|
|
|
|
|
|
|
|
* 并设置操作状态为成功返回;若未查询到对应数据,
|
|
|
|
|
|
|
|
* 则返回包含错误信息和相应错误状态码(这里是 `511`)的 `R` 类型结果对象,表示查不到数据的情况。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@RequestMapping("/info/{id}")
|
|
|
|
@RequestMapping("/info/{id}")
|
|
|
|
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
|
|
|
public R info(@PathVariable("id") Long id, HttpServletRequest request) {
|
|
|
|
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
|
|
|
// 使用日志记录器记录当前 `info`
|
|
|
|
|
|
|
|
// 方法的执行情况,记录控制器类的名称以及传入的 `id` 参数值,
|
|
|
|
|
|
|
|
// 方便调试查看请求的参数情况。
|
|
|
|
|
|
|
|
logger.debug("info方法:,,Controller:{},,id:{}", this.getClass().getName(), id);
|
|
|
|
|
|
|
|
// 调用 `dictionaryService` 的 `selectById` 方法,
|
|
|
|
|
|
|
|
// 根据传入的 `id` 参数从数据库中查询对应的 `DictionaryEntity`(字典表实体类)对象,
|
|
|
|
|
|
|
|
// 如果查询到则返回该对象,若不存在则返回 `null`。
|
|
|
|
DictionaryEntity dictionary = dictionaryService.selectById(id);
|
|
|
|
DictionaryEntity dictionary = dictionaryService.selectById(id);
|
|
|
|
if(dictionary !=null){
|
|
|
|
if (dictionary!= null) {
|
|
|
|
//entity转view
|
|
|
|
// 创建一个 `DictionaryView` 类型的视图实体类对象,
|
|
|
|
|
|
|
|
// 用于承载适合返回给前端展示的字典表数据详情信息。
|
|
|
|
DictionaryView view = new DictionaryView();
|
|
|
|
DictionaryView view = new DictionaryView();
|
|
|
|
BeanUtils.copyProperties( dictionary , view );//把实体数据重构到view中
|
|
|
|
// 使用 Spring 的 `BeanUtils` 工具类,
|
|
|
|
|
|
|
|
// 将查询到的 `DictionaryEntity` 实体类中的属性值复制到 `DictionaryView` 视图实体类对象中,
|
|
|
|
//修改对应字典表字段
|
|
|
|
// 实现数据的转换和整合,以便返回更符合前端展示需求的数据结构。
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(dictionary, view);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调用 `dictionaryService` 的 `dictionaryConvert` 方法,
|
|
|
|
|
|
|
|
// 对转换后的视图实体类对象进行数据转换操作,
|
|
|
|
|
|
|
|
// 可能是对字典表中的某些字段进行进一步的处理,
|
|
|
|
|
|
|
|
// 以满足前端展示或者业务规则要求,确保返回的数据格式和内容符合预期。
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
|
|
|
|
// 返回包含操作成功状态信息(通过 `R.ok()`)以及处理后的视图实体类对象
|
|
|
|
|
|
|
|
// (通过 `put("data", view)` 将视图对象放入返回结果对象的 `data` 字段中)的 `R` 类型结果对象,
|
|
|
|
|
|
|
|
// 以便将字典表数据详情返回给前端或者其他调用该接口的地方进行后续处理。
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
return R.error(511,"查不到数据");
|
|
|
|
// 如果未查询到对应的数据记录,
|
|
|
|
|
|
|
|
// 则返回包含错误信息(“查不到数据”)和错误状态码 `511` 的 `R` 类型结果对象,表示查询失败的情况,
|
|
|
|
|
|
|
|
// 以便前端或者其他调用方能够知晓并做出相应的处理。
|
|
|
|
|
|
|
|
return R.error(511, "查不到数据");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 后端保存
|
|
|
|
* 后端保存
|
|
|
|
*/
|
|
|
|
* 用于处理新增字典表数据的请求,
|
|
|
|
|
|
|
|
* 会先进行一些数据重复性校验,若数据不存在重复则将新数据插入数据库,并在插入成功后进行一些后续的数据处理操作(如更新监听器中的数据)。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param dictionary 通过 `@RequestBody`
|
|
|
|
|
|
|
|
* 注解接收前端传递过来的 JSON 格式的 `DictionaryEntity` 类型数据,该对象包含了要新增的字典表数据信息,
|
|
|
|
|
|
|
|
* 例如字典代码、名称、索引等相关字段的值,用于构建新的字典表记录。
|
|
|
|
|
|
|
|
* @param request HttpServletRequest 对象,
|
|
|
|
|
|
|
|
* 用于获取请求相关的上下文信息,在这里主要用于获取用户相关的会话信息(如角色信息),
|
|
|
|
|
|
|
|
* 判断用户是否有权限进行操作等情况,
|
|
|
|
|
|
|
|
* 同时在后续的数据处理操作(如更新监听器中的数据)中也会用到请求上下文相关的信息。
|
|
|
|
|
|
|
|
* @return 返回一个 `R` 类型的结果对象,若数据成功插入数据库且后续处理无异常,
|
|
|
|
|
|
|
|
* 则返回操作成功的状态信息(通过 `R.ok()`);
|
|
|
|
|
|
|
|
* 若插入的数据存在重复(通过查询判断),
|
|
|
|
|
|
|
|
* 则返回包含错误信息(“表中有相同数据”)和相应错误状态码(`511`)的 `R` 类型结果对象,
|
|
|
|
|
|
|
|
* 表示新增数据失败的情况。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@RequestMapping("/save")
|
|
|
|
@RequestMapping("/save")
|
|
|
|
public R save(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
|
|
|
|
public R save(@RequestBody DictionaryEntity dictionary, HttpServletRequest request) {
|
|
|
|
logger.debug("save方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
|
|
|
|
// 使用日志记录器记录当前 `save` 方法的执行情况,
|
|
|
|
|
|
|
|
// 记录控制器类的名称以及传入的要保存的字典表数据对象信息(将对象转换为字符串格式记录),
|
|
|
|
|
|
|
|
// 方便调试查看请求的数据情况。
|
|
|
|
|
|
|
|
logger.debug("save方法:,,Controller:{},,dictionary:{}", this.getClass().getName(), dictionary.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从请求的会话中获取用户的角色信息,将其转换为字符串类型,
|
|
|
|
|
|
|
|
// 虽然当前代码中 `if(false)` 这个条件永远为假,
|
|
|
|
|
|
|
|
// 可能是后续会添加基于角色判断是否有权限进行保存操作的逻辑,
|
|
|
|
|
|
|
|
// 这里先预留了代码结构,
|
|
|
|
|
|
|
|
// 暂时不会进入到后面的 `return R.error(511,"永远不会进入");` 这一行代码执行。
|
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
|
|
|
if(false)
|
|
|
|
if (false)
|
|
|
|
return R.error(511,"永远不会进入");
|
|
|
|
return R.error(511, "永远不会进入");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个 `EntityWrapper`
|
|
|
|
|
|
|
|
// 类型的查询条件包装器对象,用于构建查询字典表中是否已存在相同数据的条件,
|
|
|
|
|
|
|
|
// 通过 `eq` 方法设置相等条件,
|
|
|
|
|
|
|
|
// 分别按照 `dic_code`(字典代码)和 `index_name`
|
|
|
|
|
|
|
|
// (索引名称)字段与要保存的字典数据对象中的对应字段值进行相等匹配查询,
|
|
|
|
|
|
|
|
// 以此来判断是否存在重复数据
|
|
|
|
|
|
|
|
// (后续还可能根据具体情况添加更多条件判断,如针对特定字典代码类型添加额外条件等)。
|
|
|
|
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
|
|
|
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
|
|
|
.eq("dic_code", dictionary.getDicCode())
|
|
|
|
.eq("dic_code", dictionary.getDicCode())
|
|
|
|
.eq("index_name", dictionary.getIndexName())
|
|
|
|
.eq("index_name", dictionary.getIndexName())
|
|
|
|
;
|
|
|
|
;
|
|
|
|
if(dictionary.getDicCode().contains("_erji_types")){
|
|
|
|
// 如果要保存的字典数据对象的 `dic_code`
|
|
|
|
queryWrapper.eq("super_id",dictionary.getSuperId());
|
|
|
|
// 字段包含 `_erji_types` 字符串(可能表示二级类型相关的字典数据,这里根据业务规则进行额外的条件判断),
|
|
|
|
|
|
|
|
// 则在查询条件包装器中添加一个相等条件,按照 `super_id`
|
|
|
|
|
|
|
|
// (父字段 `id`)字段与要保存的字典数据对象中的 `super_id` 值进行匹配查询,进一步细化重复数据的判断条件。
|
|
|
|
|
|
|
|
if (dictionary.getDicCode().contains("_erji_types")) {
|
|
|
|
|
|
|
|
queryWrapper.eq("super_id", dictionary.getSuperId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
|
|
|
// 使用日志记录器记录构建好的查询条件对应的 SQL 语句片段(通过 `getSqlSegment` 方法获取),
|
|
|
|
|
|
|
|
// 方便调试查看查询条件是否正确构建,是否符合预期的数据库查询逻辑。
|
|
|
|
|
|
|
|
logger.info("sql语句:" + queryWrapper.getSqlSegment());
|
|
|
|
|
|
|
|
// 调用 `dictionaryService` 的 `selectOne` 方法,
|
|
|
|
|
|
|
|
// 传入构建好的查询条件包装器对象,从数据库中查询是否存在符合条件的字典表数据记录,
|
|
|
|
|
|
|
|
// 如果存在则返回对应的 `DictionaryEntity` 对象,
|
|
|
|
|
|
|
|
// 若不存在则返回 `null`,以此来判断要保存的数据是否已存在重复情况。
|
|
|
|
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
|
|
|
|
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
|
|
|
|
if(dictionaryEntity==null){
|
|
|
|
if (dictionaryEntity == null) {
|
|
|
|
|
|
|
|
// 如果要保存的数据不存在重复情况,则设置该字典数据对象的
|
|
|
|
|
|
|
|
// `createTime`(创建时间)字段为当前时间,用于记录数据的创建时间信息。
|
|
|
|
dictionary.setCreateTime(new Date());
|
|
|
|
dictionary.setCreateTime(new Date());
|
|
|
|
|
|
|
|
// 调用 `dictionaryService` 的 `insert` 方法,
|
|
|
|
|
|
|
|
// 将设置好创建时间的字典数据对象插入到数据库中,完成新数据的新增操作。
|
|
|
|
dictionaryService.insert(dictionary);
|
|
|
|
dictionaryService.insert(dictionary);
|
|
|
|
//字典表新增数据,把数据再重新查出,放入监听器中
|
|
|
|
|
|
|
|
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
|
|
|
|
|
|
|
|
ServletContext servletContext = request.getServletContext();
|
|
|
|
|
|
|
|
Map<String, Map<Integer,String>> map = new HashMap<>();
|
|
|
|
|
|
|
|
for(DictionaryEntity d :dictionaryEntities){
|
|
|
|
|
|
|
|
Map<Integer, String> m = map.get(d.getDicCode());
|
|
|
|
|
|
|
|
if(m ==null || m.isEmpty()){
|
|
|
|
|
|
|
|
m = new HashMap<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m.put(d.getCodeIndex(),d.getIndexName());
|
|
|
|
|
|
|
|
map.put(d.getDicCode(),m);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
servletContext.setAttribute("dictionaryMap",map);
|
|
|
|
|
|
|
|
return R.ok();
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
return R.error(511,"表中有相同数据");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// 字典表新增数据后,把字典表中的所有数据重新查询出来,
|
|
|
|
* 后端修改
|
|
|
|
// 用于放入监听器中(可能是为了在其他地方能够获取到最新的字典表数据,保持数据一致性等业务需求)。
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/update")
|
|
|
|
|
|
|
|
public R update(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
|
|
|
|
|
|
|
|
logger.debug("update方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
|
|
|
|
|
|
|
// if(false)
|
|
|
|
|
|
|
|
// return R.error(511,"永远不会进入");
|
|
|
|
|
|
|
|
//根据字段查询是否有相同数据
|
|
|
|
|
|
|
|
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
|
|
|
|
|
|
|
.notIn("id",dictionary.getId())
|
|
|
|
|
|
|
|
.eq("dic_code", dictionary.getDicCode())
|
|
|
|
|
|
|
|
.eq("index_name", dictionary.getIndexName())
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(dictionary.getDicCode().contains("_erji_types")){
|
|
|
|
|
|
|
|
queryWrapper.eq("super_id",dictionary.getSuperId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
|
|
|
|
|
|
|
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
|
|
|
|
|
|
|
|
if(dictionaryEntity==null){
|
|
|
|
|
|
|
|
dictionaryService.updateById(dictionary);//根据id更新
|
|
|
|
|
|
|
|
//如果字典表修改数据的话,把数据再重新查出,放入监听器中
|
|
|
|
|
|
|
|
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
|
|
|
|
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
|
|
|
|
|
|
|
|
// 获取当前请求的 `ServletContext` 对象,
|
|
|
|
|
|
|
|
// 它可以用于在整个应用程序的不同组件之间共享数据,在这里用于存放字典表数据信息,供监听器等其他组件使用。
|
|
|
|
ServletContext servletContext = request.getServletContext();
|
|
|
|
ServletContext servletContext = request.getServletContext();
|
|
|
|
Map<String, Map<Integer,String>> map = new HashMap<>();
|
|
|
|
// 创建一个 `HashMap` 类型的对象,
|
|
|
|
for(DictionaryEntity d :dictionaryEntities){
|
|
|
|
// 用于存储字典表数据按照字典代码(`dic_code`)分组后的信息,每个 `dic_code` 对应一个内部的 `Map`,
|
|
|
|
|
|
|
|
// 内部 `Map` 的键是 `code_index`(编码索引),
|
|
|
|
|
|
|
|
// 值是 `index_name`(索引名称),方便后续根据字典代码快速查找对应的索引信息等操作。
|
|
|
|
|
|
|
|
Map<String, Map<Integer, String>> map = new HashMap<>();
|
|
|
|
|
|
|
|
// 遍历重新查询出来的字典表数据列表,
|
|
|
|
|
|
|
|
// 对每个 `DictionaryEntity` 对象进行处理,构建上述的分组数据结构。
|
|
|
|
|
|
|
|
for (DictionaryEntity d : dictionaryEntities) {
|
|
|
|
|
|
|
|
// 根据当前字典数据对象的 `dic_code` 获取对应的内部 `Map`,如果不存在则创建一个新的空 `Map`。
|
|
|
|
Map<Integer, String> m = map.get(d.getDicCode());
|
|
|
|
Map<Integer, String> m = map.get(d.getDicCode());
|
|
|
|
if(m ==null || m.isEmpty()){
|
|
|
|
if (m == null || m.isEmpty()) {
|
|
|
|
m = new HashMap<>();
|
|
|
|
m = new HashMap<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m.put(d.getCodeIndex(),d.getIndexName());
|
|
|
|
// 将当前字典数据对象的 `code_index` 和
|
|
|
|
map.put(d.getDicCode(),m);
|
|
|
|
// `index_name` 放入对应的内部 `Map` 中,建立索引关系。
|
|
|
|
|
|
|
|
m.put(d.getCodeIndex(), d.getIndexName());
|
|
|
|
|
|
|
|
// 将包含当前字典数据对象索引信息的内部 `Map`
|
|
|
|
|
|
|
|
// 重新放入外层的 `map` 中,以 `dic_code` 为键进行关联,完成分组存储。
|
|
|
|
|
|
|
|
map.put(d.getDicCode(), m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
servletContext.setAttribute("dictionaryMap",map);
|
|
|
|
// 将构建好的包含字典表数据分组信息的 `map` 对象存入
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// `ServletContext` 中,设置一个名为 `dictionaryMap` 的属性,
|
|
|
|
|
|
|
|
// 以便其他组件(如监听器等)可以通过该属性名获取到最新的字典表数据分组信息,实现数据共享和后续的业务逻辑处理。
|
|
|
|
|
|
|
|
servletContext.setAttribute("dictionaryMap", map);
|
|
|
|
|
|
|
|
// 返回操作成功的状态信息(通过 `R.ok()`),表示字典表数据新增成功,
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 以便前端或者其他调用该接口的地方知晓操作结果并进行后续处理。
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
return R.error(511,"表中有相同数据");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 删除
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/delete")
|
|
|
|
|
|
|
|
public R delete(@RequestBody Integer[] ids){
|
|
|
|
|
|
|
|
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
|
|
|
|
|
|
|
dictionaryService.deleteBatchIds(Arrays.asList(ids));
|
|
|
|
|
|
|
|
return R.ok();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 最大值
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/maxCodeIndex")
|
|
|
|
|
|
|
|
public R maxCodeIndex(@RequestBody DictionaryEntity dictionary){
|
|
|
|
|
|
|
|
logger.debug("maxCodeIndex:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
|
|
|
|
|
|
|
|
List<String> descs = new ArrayList<>();
|
|
|
|
|
|
|
|
descs.add("code_index");
|
|
|
|
|
|
|
|
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
|
|
|
|
|
|
|
.eq("dic_code", dictionary.getDicCode())
|
|
|
|
|
|
|
|
.orderDesc(descs);
|
|
|
|
|
|
|
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
|
|
|
|
|
|
|
List<DictionaryEntity> dictionaryEntityList = dictionaryService.selectList(queryWrapper);
|
|
|
|
|
|
|
|
if(dictionaryEntityList != null ){
|
|
|
|
|
|
|
|
return R.ok().put("maxCodeIndex",dictionaryEntityList.get(0).getCodeIndex()+1);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
return R.ok().put("maxCodeIndex",1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果查询到要保存的数据已存在重复情况,
|
|
|
|
|
|
|
|
//
|
|
|
|
/**
|
|
|
|
// 则返回包含错误信息(“表中有相同数据”)和相应错误状态码(`511`)的 `R` 类型结果对象,
|
|
|
|
* 批量上传
|
|
|
|
// 表示新增数据失败,以便前端或者其他调用方能够知晓并做出相应的处理。
|
|
|
|
*/
|
|
|
|
return R.error(511, "表中有相同数据");
|
|
|
|
@RequestMapping("/batchInsert")
|
|
|
|
|
|
|
|
public R save( String fileName, HttpServletRequest request){
|
|
|
|
|
|
|
|
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
|
|
|
|
|
|
|
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
|
|
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<DictionaryEntity> dictionaryList = new ArrayList<>();//上传的东西
|
|
|
|
|
|
|
|
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
|
|
|
int lastIndexOf = fileName.lastIndexOf(".");
|
|
|
|
|
|
|
|
if(lastIndexOf == -1){
|
|
|
|
|
|
|
|
return R.error(511,"该文件没有后缀");
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
String suffix = fileName.substring(lastIndexOf);
|
|
|
|
|
|
|
|
if(!".xls".equals(suffix)){
|
|
|
|
|
|
|
|
return R.error(511,"只支持后缀为xls的excel文件");
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
|
|
|
|
|
|
|
File file = new File(resource.getFile());
|
|
|
|
|
|
|
|
if(!file.exists()){
|
|
|
|
|
|
|
|
return R.error(511,"找不到上传文件,请联系管理员");
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
|
|
|
|
|
|
|
dataList.remove(0);//删除第一行,因为第一行是提示
|
|
|
|
|
|
|
|
for(List<String> data:dataList){
|
|
|
|
|
|
|
|
//循环
|
|
|
|
|
|
|
|
DictionaryEntity dictionaryEntity = new DictionaryEntity();
|
|
|
|
|
|
|
|
// dictionaryEntity.setDicCode(data.get(0)); //字段 要改的
|
|
|
|
|
|
|
|
// dictionaryEntity.setDicName(data.get(0)); //字段名 要改的
|
|
|
|
|
|
|
|
// dictionaryEntity.setCodeIndex(Integer.valueOf(data.get(0))); //编码 要改的
|
|
|
|
|
|
|
|
// dictionaryEntity.setIndexName(data.get(0)); //编码名字 要改的
|
|
|
|
|
|
|
|
// dictionaryEntity.setSuperId(Integer.valueOf(data.get(0))); //父字段id 要改的
|
|
|
|
|
|
|
|
// dictionaryEntity.setBeizhu(data.get(0)); //备注 要改的
|
|
|
|
|
|
|
|
// dictionaryEntity.setCreateTime(date);//时间
|
|
|
|
|
|
|
|
dictionaryList.add(dictionaryEntity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//把要查询是否重复的字段放入map中
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询是否重复
|
|
|
|
|
|
|
|
dictionaryService.insertBatch(dictionaryList);
|
|
|
|
|
|
|
|
return R.ok();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
return R.error(511,"批量插入数据异常,请联系管理员");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 后端修改
|
|
|
|
|
|
|
|
* 用于处理修改字典表数据的请求,先进行数据重复性校验,若不存在重复数据
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|