style: 部分代码优化

1.格式优化:去除部分多余空行(较少代码段区分尽量不添加空行)、注释(代码尽量自解释)
2.完善部分 Swagger 注解信息
3.修复部分前后端警告
This commit is contained in:
2023-09-10 18:01:44 +08:00
parent b874ca0782
commit a3082e72a9
34 changed files with 116 additions and 99 deletions

View File

@@ -78,6 +78,6 @@ public @interface CrudRequestMapping {
/**
* 导出
*/
EXPORT,;
EXPORT,
}
}

View File

@@ -74,7 +74,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
* 分页查询条件
* @return 分页信息
*/
@Operation(summary = "分页查询列表")
@Operation(summary = "分页查询列表", description = "分页查询列表")
@ResponseBody
@GetMapping
public R<PageDataVO<V>> page(Q query, @Validated PageQuery pageQuery) {
@@ -92,7 +92,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
* 排序查询条件
* @return 树列表信息
*/
@Operation(summary = "查询树列表")
@Operation(summary = "查询树列表", description = "查询树列表")
@ResponseBody
@GetMapping("/tree")
public R<List<Tree<Long>>> tree(Q query, SortQuery sortQuery) {
@@ -110,7 +110,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
* 排序查询条件
* @return 列表信息
*/
@Operation(summary = "查询列表")
@Operation(summary = "查询列表", description = "查询列表")
@ResponseBody
@GetMapping("/list")
public R<List<V>> list(Q query, SortQuery sortQuery) {
@@ -126,8 +126,8 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
* ID
* @return 详情信息
*/
@Operation(summary = "查看详情")
@Parameter(name = "id", description = "ID", in = ParameterIn.PATH)
@Operation(summary = "查看详情", description = "查看详情")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@GetMapping("/{id}")
public R<D> get(@PathVariable Long id) {
@@ -143,7 +143,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
* 创建信息
* @return 自增 ID
*/
@Operation(summary = "新增数据")
@Operation(summary = "新增数据", description = "新增数据")
@ResponseBody
@PostMapping
public R<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C request) {
@@ -161,7 +161,8 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
* ID
* @return /
*/
@Operation(summary = "修改数据")
@Operation(summary = "修改数据", description = "修改数据")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@PutMapping("/{id}")
public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C request, @PathVariable Long id) {
@@ -177,8 +178,8 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
* ID 列表
* @return /
*/
@Operation(summary = "删除数据")
@Parameter(name = "ids", description = "ID 列表", in = ParameterIn.PATH)
@Operation(summary = "删除数据", description = "删除数据")
@Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH)
@ResponseBody
@DeleteMapping("/{ids}")
public R delete(@PathVariable List<Long> ids) {
@@ -197,7 +198,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
* @param response
* 响应对象
*/
@Operation(summary = "导出数据")
@Operation(summary = "导出数据", description = "导出数据")
@GetMapping("/export")
public void export(Q query, SortQuery sortQuery, HttpServletResponse response) {
this.checkPermission(Api.EXPORT);

View File

@@ -151,7 +151,9 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
// 设置排序
Sort sort = Opt.ofNullable(sortQuery).orElseGet(SortQuery::new).getSort();
for (Sort.Order order : sort) {
queryWrapper.orderBy(null != order, order.isAscending(), StrUtil.toUnderlineCase(order.getProperty()));
if (null != order) {
queryWrapper.orderBy(true, order.isAscending(), StrUtil.toUnderlineCase(order.getProperty()));
}
}
List<T> entityList = baseMapper.selectList(queryWrapper);
return BeanUtil.copyToList(entityList, targetClass);

View File

@@ -68,6 +68,7 @@ public class BaseVO implements Serializable {
/**
* 是否禁用修改
*/
@Schema(description = "是否禁用修改", example = "true")
@JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean disabled;
}

View File

@@ -68,8 +68,9 @@ public class RedisConfiguration extends CachingConfigurerSupport {
*/
@Bean
public RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties) {
ObjectMapper objectMapperCopy =
objectMapper.copy().enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
ObjectMapper objectMapperCopy = objectMapper.copy();
objectMapperCopy.activateDefaultTyping(objectMapperCopy.getPolymorphicTypeValidator(),
ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair

View File

@@ -16,8 +16,6 @@
package top.charles7c.cnadmin.common.config.easyexcel;
import java.math.BigDecimal;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
@@ -26,6 +24,7 @@ import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
/**
* Easy Excel 大数值转换器Excel 中对长度超过 15 位的数值输入是有限制的,从 16 位开始无论录入什么数字均会变为 0因此输入时只能以文本的形式进行录入
@@ -71,7 +70,7 @@ public class ExcelBigNumberConverter implements Converter<Long> {
return new WriteCellData<>(str);
}
}
WriteCellData<Object> writeCellData = new WriteCellData<>(BigDecimal.valueOf(value));
WriteCellData<Object> writeCellData = new WriteCellData<>(NumberUtil.toBigDecimal(value));
writeCellData.setType(CellDataTypeEnum.NUMBER);
return writeCellData;
}

View File

@@ -74,9 +74,9 @@ public class GlobalErrorHandler extends BasicErrorController {
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
objectMapper.writeValue(response.getWriter(), result);
} catch (IOException e) {
log.error("请求地址 [{}],发生 IO 异常。", path, e);
log.error("请求地址 [{}]默认错误处理时发生 IO 异常。", path, e);
}
log.error("请求地址 [{}],发生异常,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
return null;
}
@@ -88,7 +88,7 @@ public class GlobalErrorHandler extends BasicErrorController {
HttpStatus status = super.getStatus(request);
R<Object> result = R.fail(status.value(), (String)errorAttributeMap.get("error"));
result.setData(path);
log.error("请求地址 [{}],发生异常,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
return new ResponseEntity<>(BeanUtil.beanToMap(result), status);
}
}

View File

@@ -72,7 +72,7 @@ public class LoginHelper {
/**
* 获取登录用户信息
*
* @return 登录用户信息
* @return 登录用户信息(获取 TokenSession 时如未登录,会抛出异常)
*/
public static LoginUser getLoginUser() {
LoginUser loginUser = (LoginUser)SaHolder.getStorage().get(CacheConsts.LOGIN_USER_KEY);