2024-08-30 17:03:25 +08:00
|
|
|
package com.changhu.controller;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.lang.Dict;
|
|
|
|
import cn.hutool.core.util.ClassUtil;
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
|
|
import com.changhu.common.annotation.IsExtData;
|
|
|
|
import com.changhu.common.annotation.JsonBody;
|
|
|
|
import com.changhu.common.db.BaseEnum;
|
|
|
|
import com.changhu.common.pojo.model.JsonResult;
|
|
|
|
import com.changhu.common.pojo.vo.SelectNodeVo;
|
|
|
|
import com.changhu.common.pojo.vo.TreeNodeVo;
|
|
|
|
import com.changhu.pojo.params.PoliceUnitRegisterParams;
|
|
|
|
import com.changhu.pojo.params.SecurityUnitRegisterParams;
|
|
|
|
import com.changhu.service.AdministrativeDivisionService;
|
|
|
|
import com.changhu.service.CommonService;
|
|
|
|
import com.changhu.support.minio.service.MinioService;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-09-06 14:54:14 +08:00
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
2024-08-30 17:03:25 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author 20252
|
|
|
|
* @createTime 2024/8/30 下午2:16
|
|
|
|
* @desc CommonController...
|
|
|
|
*/
|
|
|
|
@Tag(name = "公共接口")
|
|
|
|
@RequestMapping("/common")
|
|
|
|
@JsonBody
|
|
|
|
public class CommonController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private CommonService commonService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private MinioService minioService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private AdministrativeDivisionService administrativeDivisionService;
|
|
|
|
|
|
|
|
private static final Map<String, List<SelectNodeVo<?>>> enumsResult = new HashMap<>();
|
|
|
|
|
|
|
|
|
2024-09-06 14:54:14 +08:00
|
|
|
@Cacheable(value = "common", key = "'AdministrativeDivisionLevel' + #level + 'Tree'")
|
2024-08-30 17:03:25 +08:00
|
|
|
@Operation(summary = "行政区划树")
|
|
|
|
@GetMapping("/administrativeDivisionTree")
|
|
|
|
public List<TreeNodeVo<String>> AdministrativeDivisionTree(@Schema(description = "等级") @RequestParam(defaultValue = "4") Integer level) {
|
|
|
|
return administrativeDivisionService.tree(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "保安单位注册")
|
|
|
|
@PostMapping("/securityUnitRegister")
|
|
|
|
public JsonResult<Void> securityUnitRegister(@RequestBody @Valid SecurityUnitRegisterParams params) {
|
|
|
|
return commonService.securityUnitRegister(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "公安单位注册")
|
|
|
|
@PostMapping("/policeUnitRegister")
|
|
|
|
public JsonResult<Void> policeUnitRegister(@RequestBody @Valid PoliceUnitRegisterParams params) {
|
|
|
|
return commonService.policeUnitRegister(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "获取临时上传地址")
|
|
|
|
@GetMapping("/getResignedObjectUrl")
|
|
|
|
public String getResignedObjectUrl(@RequestParam @Schema(description = "bucketName") String bucketName,
|
|
|
|
@RequestParam @Schema(description = "对象地址") String objectName) {
|
|
|
|
return minioService.getResignedObjectUrl(bucketName, objectName);
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/enums")
|
|
|
|
public Map<String, List<SelectNodeVo<?>>> enums() {
|
|
|
|
return enumsResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@PostConstruct
|
|
|
|
public void initEnums() {
|
|
|
|
Set<Class<?>> classes = ClassUtil.scanPackageBySuper("com.changhu.common.db.enums", BaseEnum.class);
|
|
|
|
for (Class<?> aClass : classes) {
|
|
|
|
if (BaseEnum.class.isAssignableFrom(aClass)) {
|
|
|
|
enumsResult.put(aClass.getSimpleName(), listSelectNodes((Class<? extends BaseEnum<?>>) aClass));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T extends BaseEnum<?>> List<SelectNodeVo<?>> listSelectNodes(Class<T> enumType) {
|
|
|
|
if (enumType == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Field[] fields = ReflectUtil.getFields(enumType);
|
|
|
|
|
|
|
|
List<String> extras = new ArrayList<>();
|
|
|
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
IsExtData annotation = field.getAnnotation(IsExtData.class);
|
|
|
|
if (ObjectUtil.isNotNull(annotation)) {
|
|
|
|
extras.add(field.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
T[] enumConstants = enumType.getEnumConstants();
|
|
|
|
if (enumConstants == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Stream.of(enumConstants).map(v -> {
|
|
|
|
SelectNodeVo<Object> vo = new SelectNodeVo<>();
|
|
|
|
vo.setValue(v.getValue());
|
|
|
|
vo.setLabel(v.getLabel());
|
|
|
|
if (CollUtil.isNotEmpty(extras)) {
|
|
|
|
Dict map = Dict.create();
|
|
|
|
for (String extra : extras) {
|
|
|
|
map.put(extra, ReflectUtil.getFieldValue(v, extra));
|
|
|
|
}
|
|
|
|
vo.setExtData(map);
|
|
|
|
}
|
|
|
|
return vo;
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|