优化
This commit is contained in:
@ -1,15 +1,18 @@
|
|||||||
package com.ruoyi.web.controller.common;
|
package com.ruoyi.web.controller.common;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
import com.ruoyi.bgt.service.IBgtUserService;
|
import com.ruoyi.bgt.service.IBgtUserService;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.core.domain.Area;
|
||||||
import com.ruoyi.common.core.domain.entity.BgtUser;
|
import com.ruoyi.common.core.domain.entity.BgtUser;
|
||||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import com.ruoyi.common.core.domain.model.BgtLoginBody;
|
import com.ruoyi.common.core.domain.model.BgtLoginBody;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
import com.ruoyi.common.util.DataUtil;
|
import com.ruoyi.common.util.DataUtil;
|
||||||
|
import com.ruoyi.common.utils.AreaUtils;
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
import com.ruoyi.framework.web.service.AppLoginService;
|
import com.ruoyi.framework.web.service.AppLoginService;
|
||||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||||
@ -133,6 +136,14 @@ public class AppLoginController
|
|||||||
return AjaxResult.success(data);
|
return AjaxResult.success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/tree")
|
||||||
|
@ApiOperation("获得地区树")
|
||||||
|
public AjaxResult<List<Area>> getAreaTree() {
|
||||||
|
Area area = AreaUtils.getArea(Area.ID_CHINA);
|
||||||
|
Assert.notNull(area, "获取不到中国");
|
||||||
|
return AjaxResult.success(area.getChildren());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * 获取用户信息
|
// * 获取用户信息
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.ruoyi.common.core.domain;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ruoyi.common.enums.AreaType;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 区域节点,包括国家、省份、城市、地区等信息
|
||||||
|
*
|
||||||
|
* 数据可见 resources/area.csv 文件
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Area {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编号 - 全球,即根目录
|
||||||
|
*/
|
||||||
|
public static final Integer ID_GLOBAL = 0;
|
||||||
|
/**
|
||||||
|
* 编号 - 中国
|
||||||
|
*/
|
||||||
|
public static final Integer ID_CHINA = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编号
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
/**
|
||||||
|
* 名字
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*
|
||||||
|
* 枚举 {@link AreaType}
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父节点
|
||||||
|
*/
|
||||||
|
private Area parent;
|
||||||
|
/**
|
||||||
|
* 子节点
|
||||||
|
*/
|
||||||
|
private List<Area> children;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.ruoyi.common.enums;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.Area;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 区域类型枚举
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum AreaType{
|
||||||
|
|
||||||
|
COUNTRY(1, "国家"),
|
||||||
|
PROVINCE(2, "省份"),
|
||||||
|
CITY(3, "城市"),
|
||||||
|
DISTRICT(4, "地区"), // 县、镇、区等
|
||||||
|
;
|
||||||
|
|
||||||
|
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(AreaType::getType).toArray();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
private final Integer type;
|
||||||
|
/**
|
||||||
|
* 名字
|
||||||
|
*/
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public static List<Integer> getSkipType() {
|
||||||
|
return Arrays.asList(Area.ID_GLOBAL, Area.ID_CHINA);
|
||||||
|
}
|
||||||
|
}
|
@ -39,6 +39,6 @@ public enum RecruitApplyStatus
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getTaskStatus(){
|
public static List<String> getTaskStatus(){
|
||||||
return Arrays.asList(WGZ_PASS.getCode(),WORKING.getCode(), OUT_WORK.getCode());
|
return Arrays.asList(BGT_PASS.getCode(),WGZ_PASS.getCode(),WORKING.getCode(), OUT_WORK.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
155
ruoyi-common/src/main/java/com/ruoyi/common/utils/AreaUtils.java
Normal file
155
ruoyi-common/src/main/java/com/ruoyi/common/utils/AreaUtils.java
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.text.csv.CsvRow;
|
||||||
|
import cn.hutool.core.text.csv.CsvUtil;
|
||||||
|
import com.ruoyi.common.core.domain.Area;
|
||||||
|
import com.ruoyi.common.enums.AreaType;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 区域工具类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class AreaUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化 SEARCHER
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("InstantiationOfUtilityClass")
|
||||||
|
private final static AreaUtils INSTANCE = new AreaUtils();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Area 内存缓存,提升访问速度
|
||||||
|
*/
|
||||||
|
private static Map<Integer, Area> areas;
|
||||||
|
|
||||||
|
private AreaUtils() {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
areas = new HashMap<>();
|
||||||
|
areas.put(Area.ID_GLOBAL, new Area(Area.ID_GLOBAL, "全球", 0,
|
||||||
|
null, new ArrayList<>()));
|
||||||
|
// 从 csv 中加载数据
|
||||||
|
List<CsvRow> rows = CsvUtil.getReader().read(ResourceUtil.getUtf8Reader("area.csv")).getRows();
|
||||||
|
rows.remove(0); // 删除 header
|
||||||
|
for (CsvRow row : rows) {
|
||||||
|
// 创建 Area 对象
|
||||||
|
Area area = new Area(Integer.valueOf(row.get(0)), row.get(1), Integer.valueOf(row.get(2)),
|
||||||
|
null, new ArrayList<>());
|
||||||
|
// 添加到 areas 中
|
||||||
|
areas.put(area.getId(), area);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建父子关系:因为 Area 中没有 parentId 字段,所以需要重复读取
|
||||||
|
for (CsvRow row : rows) {
|
||||||
|
Area area = areas.get(Integer.valueOf(row.get(0))); // 自己
|
||||||
|
Area parent = areas.get(Integer.valueOf(row.get(3))); // 父
|
||||||
|
Assert.isTrue(area != parent, "{}:父子节点相同", area.getName());
|
||||||
|
area.setParent(parent);
|
||||||
|
parent.getChildren().add(area);
|
||||||
|
}
|
||||||
|
log.info("启动加载 AreaUtils 成功,耗时 ({}) 毫秒", System.currentTimeMillis() - now);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得指定编号对应的区域
|
||||||
|
*
|
||||||
|
* @param id 区域编号
|
||||||
|
* @return 区域
|
||||||
|
*/
|
||||||
|
public static Area getArea(Integer id) {
|
||||||
|
return areas.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有节点的全路径名称如:河南省/石家庄市/新华区
|
||||||
|
*
|
||||||
|
* @param areas 地区树
|
||||||
|
* @return 所有节点的全路径名称
|
||||||
|
*/
|
||||||
|
public static List<String> getAreaNodePathList(List<Area> areas) {
|
||||||
|
List<String> paths = new ArrayList<>();
|
||||||
|
areas.forEach(area -> getAreaNodePathList(area, "", paths));
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建一棵树的所有节点的全路径名称,并将其存储为 "祖先/父级/子级" 的形式
|
||||||
|
*
|
||||||
|
* @param node 父节点
|
||||||
|
* @param path 全路径名称
|
||||||
|
* @param paths 全路径名称列表,省份/城市/地区
|
||||||
|
*/
|
||||||
|
private static void getAreaNodePathList(Area node, String path, List<String> paths) {
|
||||||
|
if (node == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 构建当前节点的路径
|
||||||
|
String currentPath = path.isEmpty() ? node.getName() : path + "/" + node.getName();
|
||||||
|
paths.add(currentPath);
|
||||||
|
// 递归遍历子节点
|
||||||
|
for (Area child : node.getChildren()) {
|
||||||
|
getAreaNodePathList(child, currentPath, paths);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化区域
|
||||||
|
*
|
||||||
|
* @param id 区域编号
|
||||||
|
* @return 格式化后的区域
|
||||||
|
*/
|
||||||
|
public static String format(Integer id) {
|
||||||
|
return format(id, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化区域
|
||||||
|
*
|
||||||
|
* 例如说:
|
||||||
|
* 1. id = “静安区”时:上海 上海市 静安区
|
||||||
|
* 2. id = “上海市”时:上海 上海市
|
||||||
|
* 3. id = “上海”时:上海
|
||||||
|
* 4. id = “美国”时:美国
|
||||||
|
* 当区域在中国时,默认不显示中国
|
||||||
|
*
|
||||||
|
* @param id 区域编号
|
||||||
|
* @param separator 分隔符
|
||||||
|
* @return 格式化后的区域
|
||||||
|
*/
|
||||||
|
public static String format(Integer id, String separator) {
|
||||||
|
// 获得区域
|
||||||
|
Area area = areas.get(id);
|
||||||
|
if (area == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < AreaType.values().length; i++) { // 避免死循环
|
||||||
|
sb.insert(0, area.getName());
|
||||||
|
// “递归”父节点
|
||||||
|
area = area.getParent();
|
||||||
|
if (area == null
|
||||||
|
||
|
||||||
|
AreaType.getSkipType().contains(area.getId())) { // 跳过父节点为中国的情况
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sb.insert(0, separator);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
3639
ruoyi-common/src/main/resources/area.csv
Normal file
3639
ruoyi-common/src/main/resources/area.csv
Normal file
File diff suppressed because it is too large
Load Diff
@ -280,7 +280,8 @@ public class FbsProjectTaskServiceImpl extends ServicePlusImpl<FbsProjectTaskMap
|
|||||||
wrapper.eq(BgtProjectRecruitApply::getTaskId, id);
|
wrapper.eq(BgtProjectRecruitApply::getTaskId, id);
|
||||||
wrapper.in(BgtProjectRecruitApply::getStatus, RecruitApplyStatus.getTaskStatus());
|
wrapper.in(BgtProjectRecruitApply::getStatus, RecruitApplyStatus.getTaskStatus());
|
||||||
List<BgtProjectRecruitApply> list = recruitApplyService.list(wrapper);
|
List<BgtProjectRecruitApply> list = recruitApplyService.list(wrapper);
|
||||||
long wgzPassNum = list.stream().filter(apply -> apply.getStatus().equals(RecruitApplyStatus.WGZ_PASS.getCode())).count();
|
long wgzPassNum = list.stream().filter(apply -> apply.getStatus().equals(RecruitApplyStatus.WGZ_PASS.getCode())
|
||||||
|
|| apply.getStatus().equals(RecruitApplyStatus.BGT_PASS.getCode())).count();
|
||||||
long outWorkNum = list.stream().filter(apply -> apply.getStatus().equals(RecruitApplyStatus.OUT_WORK.getCode())).count();
|
long outWorkNum = list.stream().filter(apply -> apply.getStatus().equals(RecruitApplyStatus.OUT_WORK.getCode())).count();
|
||||||
long workingNum = list.stream().filter(apply -> apply.getStatus().equals(RecruitApplyStatus.WORKING.getCode())).count();
|
long workingNum = list.stream().filter(apply -> apply.getStatus().equals(RecruitApplyStatus.WORKING.getCode())).count();
|
||||||
return new BgtProjectTaskUseCountVO(wgzPassNum,workingNum,outWorkNum);
|
return new BgtProjectTaskUseCountVO(wgzPassNum,workingNum,outWorkNum);
|
||||||
|
@ -224,11 +224,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="dto.taskId != null">
|
<if test="dto.taskId != null">
|
||||||
and bpra.task_id = #{dto.taskId}
|
and bpra.task_id = #{dto.taskId}
|
||||||
</if>
|
</if>
|
||||||
<if test="dto.status != null">
|
<if test="dto.status != null and dto.status == 3">
|
||||||
|
AND bpra.status in ('1','3')
|
||||||
|
</if>
|
||||||
|
<if test="dto.status != null and dto.status != 3">
|
||||||
AND bpra.status = #{dto.status}
|
AND bpra.status = #{dto.status}
|
||||||
</if>
|
</if>
|
||||||
<if test="dto.status != null">
|
<if test="dto.status == null">
|
||||||
AND bpra.status in ('3','5','6')
|
AND bpra.status in ('1','3','5','6')
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
order by bpra.create_time desc
|
order by bpra.create_time desc
|
||||||
|
Reference in New Issue
Block a user