Commit 914a1e04 by 刘鑫

Merge remote-tracking branch 'origin/develop' into develop

2 parents eb7f533c db6db1ee
......@@ -2,6 +2,7 @@ package com.dituhui.pea.enums;
/**
* 错误码枚举类
*
* @author zl
*/
......@@ -38,39 +39,39 @@ public enum StatusCodeEnum {
/**
* 文件不存在
*/
FILE_NOT_EXIST("005", "文件不存在",false),
FILE_NOT_EXIST("005", "文件不存在", false),
/**
* 系统异常
*/
SYSTEM_UNKNOWN_ERROR("006", "系统繁忙,请稍后再试....",false),
SYSTEM_UNKNOWN_ERROR("006", "系统繁忙,请稍后再试....", false),
REQUEST_LIMIT_ERROR("0429","请求超限!", false),
REQUEST_LIMIT_ERROR("0429", "请求超限!", false),
/**
* 没有查询到对应的数据
*/
NO_DATA("007", "没有查询到对应的数据",false),
NO_DATA("007", "没有查询到对应的数据", false),
/**
* 用户不存在
*/
USER_DOES_NOT_EXIST("008","用户不存在", false),
USER_DOES_NOT_EXIST("008", "用户不存在", false),
/**
* 团队不存在
*/
TEAM_DOES_NOT_EXIST("009","团队不存在", false),
TEAM_DOES_NOT_EXIST("009", "团队不存在", false),
/**
* 手机号码已存在
*/
MOBILE_NUMBER_EXISTS("010","手机号码已存在", false),
MOBILE_NUMBER_EXISTS("010", "手机号码已存在", false),
/**
* 账号已存在
*/
ACCOUNT_EXISTS("011", "账号已存在",false),
ACCOUNT_EXISTS("011", "账号已存在", false),
/**
* 邮箱已存在
......@@ -80,17 +81,17 @@ public enum StatusCodeEnum {
/**
* 用户已存在团队中,不能重复添加
*/
USER_ALREADY_EXISTS_TEAM("013","用户已存在团队中,不能重复添加",false),
USER_ALREADY_EXISTS_TEAM("013", "用户已存在团队中,不能重复添加", false),
/**
* 角色不存在
*/
ROLE_DOES_NOT_EXIST("014","角色不存在", false),
ROLE_DOES_NOT_EXIST("014", "角色不存在", false),
/**
* 角色资源为空
*/
ROLE_RESOURCE_EMPTY("015","角色资源为空!", false),
ROLE_RESOURCE_EMPTY("015", "角色资源为空!", false),
/**
* 权限资源不存在
......@@ -100,12 +101,12 @@ public enum StatusCodeEnum {
/**
* 角色中已存在该资源,不能重复添加
*/
RESOURCE_ALREADY_EXISTS_ROLE("017","角色中已存在该资源,不能重复添加", false),
RESOURCE_ALREADY_EXISTS_ROLE("017", "角色中已存在该资源,不能重复添加", false),
/**
* 用户状态异常或已被禁用
*/
USER_ISBAN_OR_ERROR("018","用户状态异常或已被禁用", false),
USER_ISBAN_OR_ERROR("018", "用户状态异常或已被禁用", false),
GIS_EXISTS("001", "已存在", false),
......@@ -117,8 +118,13 @@ public enum StatusCodeEnum {
GIS_AREA_SMALL("005", "对象操作后面积过小", false),
GIS_AREA_TOPOLOGY("006", "拓扑处理出错", false)
;
GIS_AREA_TOPOLOGY("006", "拓扑处理出错", false),
USER_PHONE_ERROR("019", "手机号格式有误", false),
USER_EMAIL_ERROR("020", "邮箱格式有误", false),
USER_ORG_NULL_ERROR("021", "组织结构异常或为空", false);
/**
* 状态码
......
......@@ -16,4 +16,9 @@ public class OrgInfo implements Serializable {
* 机构名称
*/
private String name;
/**
* 组织级别 0:大区 1:分部 2:站点
*/
private Integer orgLevel;
}
......@@ -20,6 +20,28 @@ public class OrderServiceDetailResp {
private OrderDetail reschedulingParams;
private List<KV> items;
/**
* 是否重物搬运(双人上门) 0:否 1:是 默认0
*/
private Integer isMultiple;
/**
* 是否指定某个工程师/是否排除某个工程师 0:否 1:指定 2:排除 默认0
*/
private Integer isAppointEngineer;
/**
* 指定某个工程师/排除某个工程师 codes 多个,分割
*/
private String appointEngineerCodes;
/**
* bean优先级,例如:紧急、正常
*/
private String beanPriority;;
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class OrderDetail{
......
......@@ -37,5 +37,21 @@ public class OrderServiceList {
*/
private String beanPriority;
/**
* 是否重物搬运(双人上门) 0:否 1:是 默认0
*/
private Integer isMultiple;
/**
* 是否指定某个工程师/是否排除某个工程师 0:否 1:指定 2:排除 默认0
*/
private Integer isAppointEngineer;
/**
* 指定某个工程师/排除某个工程师 codes 多个,分割
*/
private String appointEngineerCodes;
}
......@@ -7,56 +7,72 @@ import java.time.LocalDate;
@Data
public class OrderInfo {
private Long id;
private String orderId;
private LocalDate dt;
private String subId;
private String name;
private String phone;
private String address;
private String x;
private String y;
private String province;
private String city;
private String county;
private String brand;
private String type;
private String skill;
private Integer takeTime;
private Integer isWorkshop;
private String applyNote;
private String faultDescribe;
private Timestamp expectTimeBegin;
private Timestamp expectTimeEnd;
private String expectTimeDesc;
private String source;
private String beanPriority;
private String beanTags;
private String beanStatus;
private String beanSubStatus;
private String areaId;
private String orgClusterId;
private String orgBranchId;
private String orgGroupId;
private String orgTeamId;
private Integer priority;
private String tags;
private String appointmentMethod;
private String appointmentStatus;
private String dispatcher;
private String orderStatus;
private String serviceStatus;
private String engineerCode;
private String engineerName;
private String engineerPhone;
private String engineerCodeSub;
private Timestamp planStartTime;
private Timestamp planEndTime;
private Integer arriveElapsed;
private Integer arriveDistance;
private Timestamp actualStartTime;
private Timestamp actualEndTime;
private String description;
private Timestamp createTime;
private Timestamp updateTime;
private Long id;
private String orderId;
private LocalDate dt;
private String subId;
private String name;
private String phone;
private String address;
private String x;
private String y;
private String province;
private String city;
private String county;
private String brand;
private String type;
private String skill;
private Integer takeTime;
private Integer isWorkshop;
private String applyNote;
private String faultDescribe;
private Timestamp expectTimeBegin;
private Timestamp expectTimeEnd;
private String expectTimeDesc;
private String source;
private String beanPriority;
private String beanTags;
private String beanStatus;
private String beanSubStatus;
private String areaId;
private String orgClusterId;
private String orgBranchId;
private String orgGroupId;
private String orgTeamId;
private Integer priority;
private String tags;
private String appointmentMethod;
private String appointmentStatus;
private String dispatcher;
private String orderStatus;
private String serviceStatus;
private String engineerCode;
private String engineerName;
private String engineerPhone;
private String engineerCodeSub;
private Timestamp planStartTime;
private Timestamp planEndTime;
private Integer arriveElapsed;
private Integer arriveDistance;
private Timestamp actualStartTime;
private Timestamp actualEndTime;
private String description;
private Timestamp createTime;
private Timestamp updateTime;
/**
* 是否重物搬运(双人上门) 0:否 1:是 默认0
*/
private Integer isMultiple;
/**
* 是否指定某个工程师/是否排除某个工程师 0:否 1:指定 2:排除 默认0
*/
private Integer isAppointEngineer;
/**
* 指定某个工程师/排除某个工程师 codes 多个,分割
*/
private String appointEngineerCodes;
}
\ No newline at end of file
......@@ -44,10 +44,10 @@ public class OrderInfoEntity {
private String address;
@Column(name = "x", nullable = false, length = 20)
private String x="0";
private String x = "0";
@Column(name = "y", nullable = false, length = 20)
private String y="0";
private String y = "0";
@Column(name = "bean_brand", nullable = false, length = 20)
private String beanBrand;
......@@ -176,4 +176,25 @@ public class OrderInfoEntity {
private LocalDateTime updateTime = LocalDateTime.now();
// Getters and setters (omitted for brevity)
/**
* 是否重物搬运(双人上门) 0:否 1:是 默认0
*/
@Column(name = "is_multiple")
private Integer isMultiple = 0;
/**
* 是否指定某个工程师/是否排除某个工程师 0:否 1:指定 2:排除 默认0
*/
@Column(name = "is_appoint_engineer")
private Integer isAppointEngineer = 0;
/**
* 指定某个工程师/排除某个工程师 codes 多个,分割
*/
@Column(name = "appoint_engineer_codes")
private String appointEngineerCodes;
}
......@@ -7,6 +7,11 @@ package com.dituhui.pea.order.enums;
public enum OrganizationType {
/**
* 超管
*/
admin("admin"),
/**
* 大区
*/
cluster("cluster"),
......
......@@ -185,7 +185,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
btime = getHourMinute(order.getPlanStartTime(), -order.getArriveElapsed());
etime = getHourMinute(order.getPlanStartTime());
}
tips.add(new LabelValueDTO().setLabel("在途路程").setValue(String.format("%s", order.getArriveDistance())));
tips.add(new LabelValueDTO().setLabel("在途路程").setValue(String.format("%s公里(千米)", order.getArriveDistance())));
tips.add(new LabelValueDTO().setLabel("在途时间").setValue(String.format("%s-%s", btime, etime)));
tips.add(new LabelValueDTO().setLabel("在途耗时").setValue(String.format("%s分钟", order.getArriveElapsed())));
return tips;
......
......@@ -20,334 +20,340 @@ import java.util.stream.Collectors;
@Service
public class OrderServiceDetailImpl implements OrderServiceDetail {
@Autowired
private OrderInfoDao orderInfoDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrderEventDao orderEventDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private EngineerSkillGroupDao engineerSkillGroupDao;
@Autowired
private SkillInfoDao skillInfoDao;
@Transactional
@Override
public Result<?> getOrderServiceDetail(String orderId) {
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
List<KV> items = this.packOrderDetail(order);
// 设置订单详情信息
OrderServiceDetailResp.OrderDetail detail = new OrderServiceDetailResp.OrderDetail();
detail.setAddress(String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress()));
detail.setLocation(String.format("%s,%s", order.getX(), order.getY()));
detail.setDate(TimeUtils.IsoLocalDate2String(order.getDt()));
detail.setBrand(order.getBrand());
detail.setType(order.getType());
detail.setSkill(order.getSkill());
OrderServiceDetailResp res = new OrderServiceDetailResp();
res.setOrderId(orderId);
res.setRisk("");
res.setRiskDesc("");
res.setStatusDesc("正常");
res.setStatus(order.getOrderStatus());
res.setAppointmentStatus(order.getAppointmentStatus());
res.setOrderStatus(order.getOrderStatus());
res.setServiceStatus(order.getServiceStatus());
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setReschedulingParams(detail);
res.setItems(items);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderServiceDynamics(String orderId) {
// 获取服务单动态
List<OrderEventEntity> events = orderEventDao.findByOrderId(orderId);
// pack 动态items
List<OrderServiceDynamicsResp.Dynamics> dynamics = this.packOrderDynamics(events);
OrderServiceDynamicsResp res = new OrderServiceDynamicsResp();
res.setOrderId(orderId);
res.setDynamics(dynamics);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderAppointmentList(String orderId) throws BusinessException {
// 获取预约单里列表
OrderAppointmentListResp res = new OrderAppointmentListResp();
// 查询预约单列表
List<OrderInfoEntity> orders = orderInfoDao.findByOrderId(orderId);
if (orders.isEmpty()) {
// 没有指派单列表,返回
res.setOrderId(orderId);
res.setOrders(new ArrayList<>());
return Result.success(res);
}
// 获取工程师基础信息列表
Set<String> set = new HashSet<>();
orders.stream().map(OrderInfoEntity::getEngineerCode).forEach(set::add);
orders.stream().map(OrderInfoEntity::getEngineerCodeSub).forEach(set::add);
List<String> engineerCodes = new ArrayList<>(set);
HashMap<String, EngineerInfoEntity> egInfo = this.getEngineerInfos(engineerCodes);
// 获取groupIds 和 group信息
List<String> groupIds = egInfo.values().stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, OrgGroupEntity> groups = this.queryOrgGroups(groupIds);
// 获取工程师技能列表<engineerCode, skills>
Map<String, String> egSkill = this.getEngineerSkills(engineerCodes);
Comparator<OrderInfoEntity> dtDesc = Comparator.comparing(OrderInfoEntity::getDt).reversed();
List<OrderInfoEntity> results = orders.stream().sorted(dtDesc).collect(Collectors.toList());
LocalDate lastDt = results.get(0).getDt(); //最新预约
List<OrderAppointmentListResp.OrderAppointment> items = new ArrayList<>();
for (OrderInfoEntity o : results) {
EngineerInfoEntity eg = egInfo.getOrDefault(o.getEngineerCode(), null);
if(eg == null) {
log.warn("未获得工程师{}基础信息, 订单:{}", o.getEngineerCode(), o.getOrderId());
continue;
}
String skill = egSkill.getOrDefault(o.getEngineerCode(), null);
if(skill == null) {
log.warn("未获得工程师{}基础技能, 订单:{}", o.getEngineerCode(), o.getOrderId());
}
// 获取工程师姓名
String engineerName = (eg != null) ? eg.getName() : o.getEngineerCode();
// 获取title
String title = engineerName;
if (o.getDt().isBefore(lastDt)) {
title = String.format("%s_%s", engineerName, TimeUtils.IsoLocalDate2String(o.getDt()));
}
OrderAppointmentListResp.OrderAppointment item = new OrderAppointmentListResp.OrderAppointment();
item.setTitle(title);
item.setEngineerCode(o.getEngineerCode());
item.setExpectTime(TimeUtils.IsoLocalDateTime2String(o.getExpectTimeBegin()));
item.setTimelines(null); // TODO
item.setItems(this.packEngineerItems(eg, skill, groups.get(eg.getGroupId())));
items.add(item);
}
res.setOrderId(orderId);
res.setOrders(items);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderTeamBlock(String orderId) {
List<String> block = new ArrayList<>();
// 获取订单详情
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
OrderTeamBlockResp res = new OrderTeamBlockResp();
res.setOrderId(orderId);
res.setBlock(block);
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setSkill(order.getSkill());
return Result.success(res);
}
private HashMap<String, OrgGroupEntity> queryOrgGroups(List<String> groupIds) {
HashMap<String, OrgGroupEntity> map = new HashMap<>();
if (groupIds.isEmpty()) {
return map;
}
List<OrgGroupEntity> records = orgGroupDao.findByGroupIdIn(groupIds);
for (OrgGroupEntity r : records) {
map.put(r.getGroupId(), r);
}
return map;
}
private HashMap<String, EngineerInfoEntity> getEngineerInfos(List<String> egCodes) {
// 获取工程师信息列表
HashMap<String, EngineerInfoEntity> map = new HashMap<>();
if (egCodes.isEmpty()) {
return map;
}
List<EngineerInfoEntity> rows = engineerInfoDao.findByEngineerCodeIn(egCodes);;
for (EngineerInfoEntity row : rows) {
map.put(row.getEngineerCode(), row);
}
return map;
}
private Map<String, String> getEngineerSkills(List<String> egCodes) {
// 获取工程师技能列表
Map<String, String> map = new HashMap<>();
if (egCodes.isEmpty()) {
return map;
}
List<EngineerSkillGroupEntity> rows = engineerSkillGroupDao.findByEngineerCodeInAndStatus(egCodes, true);
// 根据engineerCode排序
Comparator<EngineerSkillGroupEntity> cmp = Comparator.comparing(EngineerSkillGroupEntity::getEngineerCode);
List<EngineerSkillGroupEntity> sortedResults = rows.stream().sorted(cmp).collect(Collectors.toList());
// 根据engineerCode分组
Map<String, List<EngineerSkillGroupEntity>> results = sortedResults.stream().collect(
Collectors.groupingBy(EngineerSkillGroupEntity::getEngineerCode));
// 获取所有技能
HashMap<String, String> skills = this.queryAllSkills();
for (Map.Entry<String, List<EngineerSkillGroupEntity>> entry : results.entrySet()) {
String engineerCode = entry.getKey();
List<String> engineerSkills = new ArrayList<>();
for (EngineerSkillGroupEntity r : entry.getValue()) {
String skill = skills.getOrDefault(r.getSkillGroupCode(), "");
if (skill.isEmpty()) {
continue;
}
engineerSkills.add(skill);
}
map.put(engineerCode, String.join("、", engineerSkills));
}
return map;
}
private HashMap<String, String> queryAllSkills() {
HashMap<String, String> map = new HashMap<>();
List<SkillInfoEntity> records = skillInfoDao.findAll();
Comparator<SkillInfoEntity> cmp = Comparator.comparing(SkillInfoEntity::getSkillGroupCode);
List<SkillInfoEntity> sortedResults = records.stream().sorted(cmp).collect(Collectors.toList());
Map<String, List<SkillInfoEntity>> results = sortedResults.stream().collect(Collectors.groupingBy(SkillInfoEntity::getSkillGroupCode));
for (Map.Entry<String, List<SkillInfoEntity>> entry : results.entrySet()) {
String skillGroupCode = entry.getKey();
HashSet<String> categories = new HashSet<>();
for (SkillInfoEntity s : entry.getValue()) {
categories.add(String.format("%s%s", s.getTypeCategory(), s.getSkillCategory()));
}
List<String> skills = new ArrayList<>(categories);
map.put(skillGroupCode, String.join("、", skills));
}
return map;
}
private List<KV> packEngineerItems(EngineerInfoEntity eg, String skill, OrgGroupEntity group) {
// 获取工程师信息
List<KV> items = new ArrayList<>();
if (eg == null && skill == null) {
return items;
}
if (eg != null) {
String groupName = "";
String kind = "";
if (group != null) {
groupName = group.getGroupName();
switch (group.getKind()) {
case 1:
kind = "分站";
break;
case 2:
kind = "外围";
break;
case 3:
kind = "小组";
break;
case 4:
kind = "网点";
break;
case 5:
kind = "自保点";
break;
default:
break;
}
}
items.add(this.packEngineer("技术员", eg.getName(), "engineer"));
items.add(this.packEngineer("小组", groupName, ""));
items.add(this.packEngineer("类型", kind, ""));
items.add(this.packEngineer("性别", eg.getGender(), ""));
items.add(this.packEngineer("工号", eg.getEngineerCode(), ""));
items.add(this.packEngineer("手机号", eg.getPhone(), ""));
}
items.add(this.packEngineer("技能", skill, ""));
return items;
}
private List<KV> packOrderDetail(OrderInfoEntity order) {
List<KV> items = new ArrayList<>();
items.add(this.packOrderItem("客户姓名", order.getName()));
items.add(this.packOrderItem("客户电话", order.getPhone()));
items.add(this.packOrderItem("客户地址", String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress())));
items.add(this.packOrderItem("品牌", order.getBrand()));
items.add(this.packOrderItem("设备", order.getType()));
items.add(this.packOrderItem("服务", order.getSkill()));
items.add(this.packOrderItem("故障描述", order.getFaultDescribe()));
items.add(this.packOrderItem("意向时间", TimeUtils.IsoLocalDateTime2String(order.getExpectTimeBegin())));
items.add(this.packOrderItem("时间要求", order.getExpectTimeDesc()));
items.add(this.packOrderItem("预约方式", order.getSource()));
items.add(this.packOrderItem("标签", order.getTags()));
items.add(this.packOrderItem("创建时间", TimeUtils.IsoLocalDateTime2String(order.getCreateTime())));
items.add(this.packOrderItem("备注", order.getApplyNote()));
return items;
}
private List<OrderServiceDynamicsResp.Dynamics> packOrderDynamics(List<OrderEventEntity> events) {
List<OrderServiceDynamicsResp.Dynamics> dynamics = new ArrayList<>();
// 根据happen排序
Comparator<OrderEventEntity> happen = Comparator.comparing(OrderEventEntity::getHappen);
List<OrderEventEntity> results = events.stream().sorted(happen).collect(Collectors.toList());
for (OrderEventEntity o : results) {
OrderServiceDynamicsResp.Dynamics d = new OrderServiceDynamicsResp.Dynamics();
d.setTitle(o.getEvent());
d.setSubTitle(String.format("操作人: %s", o.getOperatorName()));
d.setTime(TimeUtils.IsoLocalDateTime2String(o.getHappen()));
d.setMemo(o.getMemo());
dynamics.add(d);
}
return dynamics;
}
private KV packEngineer(String title, String value, String type) {
return this.PackKV(title, value, type, null, null);
}
private KV packOrderItem(String title, String value) {
return this.PackKV(title, value, null, null, null);
}
private KV PackKV(String title, String value, String type, String status, Object params) {
KV item = new KV();
item.setLabel(title);
item.setValue(value);
item.setType(type);
item.setStatus(status);
item.setParams(params);
return item;
}
@Autowired
private OrderInfoDao orderInfoDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrderEventDao orderEventDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private EngineerSkillGroupDao engineerSkillGroupDao;
@Autowired
private SkillInfoDao skillInfoDao;
@Transactional
@Override
public Result<?> getOrderServiceDetail(String orderId) {
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
List<KV> items = this.packOrderDetail(order);
// 设置订单详情信息
OrderServiceDetailResp.OrderDetail detail = new OrderServiceDetailResp.OrderDetail();
detail.setAddress(String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress()));
detail.setLocation(String.format("%s,%s", order.getX(), order.getY()));
detail.setDate(TimeUtils.IsoLocalDate2String(order.getDt()));
detail.setBrand(order.getBrand());
detail.setType(order.getType());
detail.setSkill(order.getSkill());
OrderServiceDetailResp res = new OrderServiceDetailResp();
res.setOrderId(orderId);
res.setRisk("");
res.setRiskDesc("");
res.setStatusDesc("正常");
res.setStatus(order.getOrderStatus());
res.setAppointmentStatus(order.getAppointmentStatus());
res.setOrderStatus(order.getOrderStatus());
res.setServiceStatus(order.getServiceStatus());
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setReschedulingParams(detail);
res.setItems(items);
res.setIsMultiple(order.getIsMultiple());
res.setIsAppointEngineer(order.getIsAppointEngineer());
res.setAppointEngineerCodes(order.getAppointEngineerCodes());
res.setBeanPriority(order.getBeanPriority());
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderServiceDynamics(String orderId) {
// 获取服务单动态
List<OrderEventEntity> events = orderEventDao.findByOrderId(orderId);
// pack 动态items
List<OrderServiceDynamicsResp.Dynamics> dynamics = this.packOrderDynamics(events);
OrderServiceDynamicsResp res = new OrderServiceDynamicsResp();
res.setOrderId(orderId);
res.setDynamics(dynamics);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderAppointmentList(String orderId) throws BusinessException {
// 获取预约单里列表
OrderAppointmentListResp res = new OrderAppointmentListResp();
// 查询预约单列表
List<OrderInfoEntity> orders = orderInfoDao.findByOrderId(orderId);
if (orders.isEmpty()) {
// 没有指派单列表,返回
res.setOrderId(orderId);
res.setOrders(new ArrayList<>());
return Result.success(res);
}
// 获取工程师基础信息列表
Set<String> set = new HashSet<>();
orders.stream().map(OrderInfoEntity::getEngineerCode).forEach(set::add);
orders.stream().map(OrderInfoEntity::getEngineerCodeSub).forEach(set::add);
List<String> engineerCodes = new ArrayList<>(set);
HashMap<String, EngineerInfoEntity> egInfo = this.getEngineerInfos(engineerCodes);
// 获取groupIds 和 group信息
List<String> groupIds = egInfo.values().stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, OrgGroupEntity> groups = this.queryOrgGroups(groupIds);
// 获取工程师技能列表<engineerCode, skills>
Map<String, String> egSkill = this.getEngineerSkills(engineerCodes);
Comparator<OrderInfoEntity> dtDesc = Comparator.comparing(OrderInfoEntity::getDt).reversed();
List<OrderInfoEntity> results = orders.stream().sorted(dtDesc).collect(Collectors.toList());
LocalDate lastDt = results.get(0).getDt(); //最新预约
List<OrderAppointmentListResp.OrderAppointment> items = new ArrayList<>();
for (OrderInfoEntity o : results) {
EngineerInfoEntity eg = egInfo.getOrDefault(o.getEngineerCode(), null);
if (eg == null) {
log.warn("未获得工程师{}基础信息, 订单:{}", o.getEngineerCode(), o.getOrderId());
continue;
}
String skill = egSkill.getOrDefault(o.getEngineerCode(), null);
if (skill == null) {
log.warn("未获得工程师{}基础技能, 订单:{}", o.getEngineerCode(), o.getOrderId());
}
// 获取工程师姓名
String engineerName = (eg != null) ? eg.getName() : o.getEngineerCode();
// 获取title
String title = engineerName;
if (o.getDt().isBefore(lastDt)) {
title = String.format("%s_%s", engineerName, TimeUtils.IsoLocalDate2String(o.getDt()));
}
OrderAppointmentListResp.OrderAppointment item = new OrderAppointmentListResp.OrderAppointment();
item.setTitle(title);
item.setEngineerCode(o.getEngineerCode());
item.setExpectTime(TimeUtils.IsoLocalDateTime2String(o.getExpectTimeBegin()));
item.setTimelines(null); // TODO
item.setItems(this.packEngineerItems(eg, skill, groups.get(eg.getGroupId())));
items.add(item);
}
res.setOrderId(orderId);
res.setOrders(items);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderTeamBlock(String orderId) {
List<String> block = new ArrayList<>();
// 获取订单详情
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
OrderTeamBlockResp res = new OrderTeamBlockResp();
res.setOrderId(orderId);
res.setBlock(block);
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setSkill(order.getSkill());
return Result.success(res);
}
private HashMap<String, OrgGroupEntity> queryOrgGroups(List<String> groupIds) {
HashMap<String, OrgGroupEntity> map = new HashMap<>();
if (groupIds.isEmpty()) {
return map;
}
List<OrgGroupEntity> records = orgGroupDao.findByGroupIdIn(groupIds);
for (OrgGroupEntity r : records) {
map.put(r.getGroupId(), r);
}
return map;
}
private HashMap<String, EngineerInfoEntity> getEngineerInfos(List<String> egCodes) {
// 获取工程师信息列表
HashMap<String, EngineerInfoEntity> map = new HashMap<>();
if (egCodes.isEmpty()) {
return map;
}
List<EngineerInfoEntity> rows = engineerInfoDao.findByEngineerCodeIn(egCodes);
;
for (EngineerInfoEntity row : rows) {
map.put(row.getEngineerCode(), row);
}
return map;
}
private Map<String, String> getEngineerSkills(List<String> egCodes) {
// 获取工程师技能列表
Map<String, String> map = new HashMap<>();
if (egCodes.isEmpty()) {
return map;
}
List<EngineerSkillGroupEntity> rows = engineerSkillGroupDao.findByEngineerCodeInAndStatus(egCodes, true);
// 根据engineerCode排序
Comparator<EngineerSkillGroupEntity> cmp = Comparator.comparing(EngineerSkillGroupEntity::getEngineerCode);
List<EngineerSkillGroupEntity> sortedResults = rows.stream().sorted(cmp).collect(Collectors.toList());
// 根据engineerCode分组
Map<String, List<EngineerSkillGroupEntity>> results = sortedResults.stream().collect(
Collectors.groupingBy(EngineerSkillGroupEntity::getEngineerCode));
// 获取所有技能
HashMap<String, String> skills = this.queryAllSkills();
for (Map.Entry<String, List<EngineerSkillGroupEntity>> entry : results.entrySet()) {
String engineerCode = entry.getKey();
List<String> engineerSkills = new ArrayList<>();
for (EngineerSkillGroupEntity r : entry.getValue()) {
String skill = skills.getOrDefault(r.getSkillGroupCode(), "");
if (skill.isEmpty()) {
continue;
}
engineerSkills.add(skill);
}
map.put(engineerCode, String.join("、", engineerSkills));
}
return map;
}
private HashMap<String, String> queryAllSkills() {
HashMap<String, String> map = new HashMap<>();
List<SkillInfoEntity> records = skillInfoDao.findAll();
Comparator<SkillInfoEntity> cmp = Comparator.comparing(SkillInfoEntity::getSkillGroupCode);
List<SkillInfoEntity> sortedResults = records.stream().sorted(cmp).collect(Collectors.toList());
Map<String, List<SkillInfoEntity>> results = sortedResults.stream().collect(Collectors.groupingBy(SkillInfoEntity::getSkillGroupCode));
for (Map.Entry<String, List<SkillInfoEntity>> entry : results.entrySet()) {
String skillGroupCode = entry.getKey();
HashSet<String> categories = new HashSet<>();
for (SkillInfoEntity s : entry.getValue()) {
categories.add(String.format("%s%s", s.getTypeCategory(), s.getSkillCategory()));
}
List<String> skills = new ArrayList<>(categories);
map.put(skillGroupCode, String.join("、", skills));
}
return map;
}
private List<KV> packEngineerItems(EngineerInfoEntity eg, String skill, OrgGroupEntity group) {
// 获取工程师信息
List<KV> items = new ArrayList<>();
if (eg == null && skill == null) {
return items;
}
if (eg != null) {
String groupName = "";
String kind = "";
if (group != null) {
groupName = group.getGroupName();
switch (group.getKind()) {
case 1:
kind = "分站";
break;
case 2:
kind = "外围";
break;
case 3:
kind = "小组";
break;
case 4:
kind = "网点";
break;
case 5:
kind = "自保点";
break;
default:
break;
}
}
items.add(this.packEngineer("技术员", eg.getName(), "engineer"));
items.add(this.packEngineer("小组", groupName, ""));
items.add(this.packEngineer("类型", kind, ""));
items.add(this.packEngineer("性别", eg.getGender(), ""));
items.add(this.packEngineer("工号", eg.getEngineerCode(), ""));
items.add(this.packEngineer("手机号", eg.getPhone(), ""));
}
items.add(this.packEngineer("技能", skill, ""));
return items;
}
private List<KV> packOrderDetail(OrderInfoEntity order) {
List<KV> items = new ArrayList<>();
items.add(this.packOrderItem("客户姓名", order.getName()));
items.add(this.packOrderItem("客户电话", order.getPhone()));
items.add(this.packOrderItem("客户地址", String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress())));
items.add(this.packOrderItem("品牌", order.getBrand()));
items.add(this.packOrderItem("设备", order.getType()));
items.add(this.packOrderItem("服务", order.getSkill()));
items.add(this.packOrderItem("故障描述", order.getFaultDescribe()));
items.add(this.packOrderItem("意向时间", TimeUtils.IsoLocalDateTime2String(order.getExpectTimeBegin())));
items.add(this.packOrderItem("时间要求", order.getExpectTimeDesc()));
items.add(this.packOrderItem("预约方式", order.getSource()));
items.add(this.packOrderItem("标签", order.getTags()));
items.add(this.packOrderItem("创建时间", TimeUtils.IsoLocalDateTime2String(order.getCreateTime())));
items.add(this.packOrderItem("备注", order.getApplyNote()));
return items;
}
private List<OrderServiceDynamicsResp.Dynamics> packOrderDynamics(List<OrderEventEntity> events) {
List<OrderServiceDynamicsResp.Dynamics> dynamics = new ArrayList<>();
// 根据happen排序
Comparator<OrderEventEntity> happen = Comparator.comparing(OrderEventEntity::getHappen);
List<OrderEventEntity> results = events.stream().sorted(happen).collect(Collectors.toList());
for (OrderEventEntity o : results) {
OrderServiceDynamicsResp.Dynamics d = new OrderServiceDynamicsResp.Dynamics();
d.setTitle(o.getEvent());
d.setSubTitle(String.format("操作人: %s", o.getOperatorName()));
d.setTime(TimeUtils.IsoLocalDateTime2String(o.getHappen()));
d.setMemo(o.getMemo());
dynamics.add(d);
}
return dynamics;
}
private KV packEngineer(String title, String value, String type) {
return this.PackKV(title, value, type, null, null);
}
private KV packOrderItem(String title, String value) {
return this.PackKV(title, value, null, null, null);
}
private KV PackKV(String title, String value, String type, String status, Object params) {
KV item = new KV();
item.setLabel(title);
item.setValue(value);
item.setType(type);
item.setStatus(status);
item.setParams(params);
return item;
}
}
......@@ -140,6 +140,9 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
record.setCreateTime(TimeUtils.IsoTimestamp2DateTime(o.getCreateTime()));
record.setBeanPriority(o.getBeanPriority());
record.setIsMultiple(o.getIsMultiple());
record.setIsAppointEngineer(o.getIsAppointEngineer());
record.setAppointEngineerCodes(o.getAppointEngineerCodes());
content.add(record);
}
......
......@@ -181,64 +181,76 @@ public class OrganizationServiceImpl implements OrganizationService {
.setTitle(orgClusterEntity.getName());
}
@Override
public List<OrganizationDTO> getAllOrganizations(String levelType, List<String> organizationIds) {
log.info("{} {}", levelType, organizationIds);
switch (OrganizationType.valueOf(levelType)) {
case cluster:
List<OrgClusterEntity> clusters = orgClusterDao.findByClusterIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(clusters)) {
return clusters.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getClusterId());
organizationDTO.setName(c.getName());
organizationDTO.setType(OrganizationType.cluster.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case branch:
List<OrgBranchEntity> branchs = orgBranchDao.findByBranchIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(branchs)) {
return branchs.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getBranchId());
organizationDTO.setName(c.getBranchName());
organizationDTO.setType(OrganizationType.branch.getValue());
return organizationDTO;
}
).collect(Collectors.toList());
}
break;
case group:
List<OrgGroupEntity> groups = orgGroupDao.findByGroupIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(groups)) {
return groups.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getGroupId());
organizationDTO.setName(c.getGroupName());
organizationDTO.setType(OrganizationType.group.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case team:
List<OrgTeamEntity> teams = orgTeamDao.findByTeamIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(teams)) {
return teams.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getTeamId());
organizationDTO.setName(c.getTeamName());
organizationDTO.setType(OrganizationType.team.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
default:
break;
}
return Lists.newArrayList();
}
@Override
public List<OrganizationDTO> getAllOrganizations(String levelType, List<String> organizationIds) {
log.info("{} {}", levelType, organizationIds);
switch (OrganizationType.valueOf(levelType)) {
case cluster:
List<OrgClusterEntity> clusters = orgClusterDao.findByClusterIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(clusters)) {
return clusters.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getClusterId());
organizationDTO.setName(c.getName());
organizationDTO.setType(OrganizationType.cluster.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case branch:
List<OrgBranchEntity> branchs = orgBranchDao.findByBranchIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(branchs)) {
return branchs.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getBranchId());
organizationDTO.setName(c.getBranchName());
organizationDTO.setType(OrganizationType.branch.getValue());
return organizationDTO;
}
).collect(Collectors.toList());
}
break;
case group:
List<OrgGroupEntity> groups = orgGroupDao.findByGroupIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(groups)) {
return groups.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getGroupId());
organizationDTO.setName(c.getGroupName());
organizationDTO.setType(OrganizationType.group.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case team:
List<OrgTeamEntity> teams = orgTeamDao.findByTeamIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(teams)) {
return teams.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getTeamId());
organizationDTO.setName(c.getTeamName());
organizationDTO.setType(OrganizationType.team.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case admin:
List<OrgClusterEntity> adminCluster = orgClusterDao.findAll();
if (CollectionUtils.isNotEmpty(adminCluster)) {
return adminCluster.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getClusterId());
organizationDTO.setName(c.getName());
organizationDTO.setType(OrganizationType.cluster.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
default:
break;
}
return Lists.newArrayList();
}
}
......@@ -4,9 +4,11 @@ import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import com.dituhui.pea.user.entity.UserEntity;
import org.springframework.data.repository.query.Param;
/**
* 用户表(User)表数据库访问层
......@@ -80,4 +82,14 @@ public interface UserDao extends JpaRepository<UserEntity, String>, JpaSpecifica
*/
List<UserEntity> findByIdIn(List<String> userIds);
/**
* 登录验证
* @param loginname 登录名(手机号、邮箱、用户名)
* @param password 密码
* @return
*/
@Query("select t from UserEntity t where (t.account=:loginname or t.email=:loginname or t.phone=:loginname) and t.password=:password")
public UserEntity findByLoginnameAndPass(@Param("loginname")String loginname, @Param("password")String password);
}
......@@ -21,5 +21,13 @@ public interface UserOrgDao extends JpaRepository<UserOrgEntity, String>, JpaSpe
*/
List<UserOrgEntity> findByUserId(String userId);
/**
* 根据用户id查询
*
* @param orgId
* @return
*/
List<UserOrgEntity> findByOrgId(String orgId);
void deleteByUserId(String userId);
}
......@@ -34,6 +34,14 @@ public interface UserRoleDao extends JpaRepository<UserRoleEntity, String>,
List<UserRoleEntity> findByUserId(String userId);
/**
* 根据用户ID查询
*
* @param userId 用户ID
* @return
*/
List<UserRoleEntity> findByUserIdIn(List<String> userId);
/**
* 根据角色ID和用户ID删除
*
* @param roleId 角色ID
......
......@@ -16,6 +16,7 @@ import com.dituhui.pea.pojo.*;
import com.dituhui.pea.pojo.user.OrgInfo;
import com.dituhui.pea.user.dao.*;
import com.dituhui.pea.user.entity.*;
import com.dituhui.pea.user.utils.LevelUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
......@@ -100,7 +101,7 @@ public class UserService {
UserOrgDao userOrgDao;
public Result<UserLoginDTO> userLogin(String account, String password) {
UserEntity user = userDao.findByAccountAndPassword(account, SecureUtil.md5(password));
UserEntity user = userDao.findByLoginnameAndPass(account, SecureUtil.md5(password));
log.info("{}/{} login", account, password);
if (null == user) {
return Result.failure("鉴权失败");
......@@ -122,76 +123,95 @@ public class UserService {
UserLoginDTO userDTO = BeanUtil.copyProperties(user, UserLoginDTO.class);
// 获取角色
List<UserRoleEntity> userRoles = userRoleDao.findByUserId(user.getId());
if (CollectionUtils.isNotEmpty(userRoles)) {
List<String> ids = userRoles.stream().map(r -> r.getRoleId()).collect(Collectors.toList());
List<RoleEntity> roles = roleDao.findAllById(ids);
if (CollectionUtils.isNotEmpty(roles)) {
userDTO.setRoles(roles.stream().map(r -> BeanUtil.copyProperties(r, RoleInfo.class))
.collect(Collectors.toList()));
// 获取资源
List<ResourceEntity> resources = null;
if (ids.contains(Globals.SUPER_ADMIN_ID)) {
// 超管处理,不用配置资源自动拥有所有权限
resources = resourceDao.findAll();
} else {
// 普通用户
List<RoleResourceEntity> roleResources = roleResourceDao.findByRoleIdIn(ids);
log.info("role : {} roleResources:{}", ids, CollectionUtils.isNotEmpty(roleResources));
if (CollectionUtils.isNotEmpty(roleResources)) {
List<String> resourceIds = roleResources.stream().map(r -> r.getResourceId())
.collect(Collectors.toList());
resources = resourceDao.findAllById(resourceIds);
}
if (CollectionUtils.isEmpty(userRoles)) {
return userDTO;
}
List<String> ids = userRoles.stream().map(r -> r.getRoleId()).collect(Collectors.toList());
List<RoleEntity> roles = roleDao.findAllById(ids);
if (CollectionUtils.isEmpty(roles)) {
return userDTO;
}
userDTO.setRoles(roles.stream().map(r -> BeanUtil.copyProperties(r, RoleInfo.class))
.collect(Collectors.toList()));
// 获取资源
List<ResourceEntity> resources = null;
if (ids.contains(Globals.SUPER_ADMIN_ID)) {
// 超管处理,不用配置资源自动拥有所有权限
resources = resourceDao.findAll();
} else {
// 普通用户
List<RoleResourceEntity> roleResources = roleResourceDao.findByRoleIdIn(ids);
log.info("role : {} roleResources:{}", ids, CollectionUtils.isNotEmpty(roleResources));
if (CollectionUtils.isNotEmpty(roleResources)) {
List<String> resourceIds = roleResources.stream().map(r -> r.getResourceId()).collect(Collectors.toList());
resources = resourceDao.findAllById(resourceIds);
}
}
if (CollectionUtils.isEmpty(resources)) {
return userDTO;
}
// 菜单嵌套处理+菜单排序
final Set<String> resourceIds = resources.stream().map(r -> r.getId()).collect(Collectors.toSet());
// 查出一级菜单
List<ResourceInfo> levelOne = resources.stream()
.filter(r -> StringUtils.isEmpty(r.getParentId()) && r.getType() == 1)
.map(r -> BeanUtil.copyProperties(r, ResourceInfo.class)).collect(Collectors.toList());
// 过滤二,三级菜单
for (ResourceInfo resourceInfo : levelOne) {
splitMenuExtra(resourceInfo);
// List<ResourceEntity> levelTow = resourceDao.findByParentId(resourceInfo.getId());
List<ResourceEntity> levelTow = resources.stream().filter(e -> StringUtils.isNotBlank(e.getParentId()) && e.getParentId().equals(resourceInfo.getId()))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(levelTow)) {
continue;
}
List<ResourceInfo> levelTowConvert = levelTow.stream().map(e -> BeanUtil.copyProperties(e, ResourceInfo.class)).collect(Collectors.toList());
for (ResourceInfo resourceThree : levelTowConvert) {
List<ResourceEntity> levelThree = resources.stream().filter(e -> StringUtils.isNotBlank(e.getParentId()) && e.getParentId().equals(resourceThree.getId())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(levelThree)) {
continue;
}
resourceThree.setChildren(levelThree.stream().map(e -> BeanUtil.copyProperties(e, ResourceInfo.class)).collect(Collectors.toList()));
}
resourceInfo.setChildren(levelTowConvert);
}
levelOne = levelOne.stream().sorted(Comparator.comparing(ResourceInfo::getOrder))
.collect(Collectors.toList());
userDTO.setMenus(levelOne);
if (CollectionUtils.isNotEmpty(resources)) {
// 菜单嵌套处理+菜单排序
final Set<String> resourceIds = resources.stream().map(r -> r.getId()).collect(Collectors.toSet());
List<ResourceInfo> levelOne = resources.stream()
.filter(r -> StringUtils.isEmpty(r.getParentId()) && r.getType() == 1)
.map(r -> BeanUtil.copyProperties(r, ResourceInfo.class)).collect(Collectors.toList());
for (ResourceInfo resourceInfo : levelOne) {
splitMenuExtra(resourceInfo);
List<ResourceEntity> levelTow = resourceDao.findByParentId(resourceInfo.getId());
List<ResourceInfo> levelTowResourceInfo = levelTow.stream()
// 过滤未配置二级菜单
.filter(r -> resourceIds.contains(r.getId())).map(r -> {
ResourceInfo res = BeanUtil.copyProperties(r, ResourceInfo.class);
splitMenuExtra(res);
return res;
}).collect(Collectors.toList());
resourceInfo.setChildren(levelTowResourceInfo);
}
levelOne = levelOne.stream().sorted(Comparator.comparing(ResourceInfo::getOrder))
.collect(Collectors.toList());
userDTO.setMenus(levelOne);
// 获取组织架构资源
List<OrganizationDTO> allOrgs = resources.stream().filter(r -> r.getType() == 3).map(r -> {
List<OrganizationDTO> orgs = Lists.newArrayList();
String[] temp = r.getExtra().split("\\|");
Result<List<OrganizationDTO>> result = organizationService.getAllOrganizations(temp[0],
Arrays.asList(temp[1].split(",")));
if (StringUtils.equals(ResultEnum.SUCCESS.getCode(), result.getCode())) {
orgs = result.getResult();
}
return orgs;
}).flatMap(a -> a.stream()).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(allOrgs)) {
// 设置第一个为当前权限等级
for (int i = 0; i < allOrgs.size(); i++) {
if (i == 0) {
allOrgs.get(i).setIsActive(true);
} else {
allOrgs.get(i).setIsActive(false);
}
}
}
userDTO.setAuths(allOrgs);
//用户组织机构从关联表获取
List<OrganizationDTO> allOrgs = new ArrayList<>();
// 超管处理,不用配置资源自动拥有所有权限
if (ids.contains(Globals.SUPER_ADMIN_ID)) {
Result<List<OrganizationDTO>> result = organizationService.getAllOrganizations("admin", Arrays.asList("admin"));
if (StringUtils.equals(ResultEnum.SUCCESS.getCode(), result.getCode())) {
allOrgs = result.getResult();
}
} else {
List<UserOrgEntity> byUserId = userOrgDao.findByUserId(userDTO.getId());
if (CollectionUtils.isNotEmpty(byUserId)) {
List<String> collect = byUserId.stream().map(UserOrgEntity::getOrgId).collect(Collectors.toList());
Result<List<OrganizationDTO>> result = organizationService.getAllOrganizations(LevelUtils.convertOrgLevel(byUserId.get(0).getOrgLevel()), collect);
if (StringUtils.equals(ResultEnum.SUCCESS.getCode(), result.getCode())) {
allOrgs = result.getResult();
}
}
}
if (CollectionUtils.isNotEmpty(allOrgs)) {
// 设置第一个为当前权限等级
for (int i = 0; i < allOrgs.size(); i++) {
if (i == 0) {
allOrgs.get(i).setIsActive(true);
} else {
allOrgs.get(i).setIsActive(false);
}
}
}
userDTO.setAuths(allOrgs);
return userDTO;
}
......@@ -554,7 +574,7 @@ public class UserService {
if (StringUtils.isNotBlank(userInfo.getPhone())) {
// 校验手机格式是否正确
if (!Validator.isMobile(userInfo.getPhone())) {
return Result.failed(StatusCodeEnum.COMMON_PARAM_ERROR, null);
return Result.failed(StatusCodeEnum.USER_PHONE_ERROR, null);
// throw new BusinessException(StatusCodeEnum.COMMON_PARAM_ERROR);
}
if (checkPhone(userInfo.getPhone(), userInfo.getId())) {
......@@ -566,7 +586,7 @@ public class UserService {
if (StringUtils.isNotBlank(userInfo.getEmail())) {
// 校验邮箱格式是否正确
if (!Validator.isEmail(userInfo.getEmail())) {
return Result.failed(StatusCodeEnum.COMMON_PARAM_ERROR, null);
return Result.failed(StatusCodeEnum.USER_EMAIL_ERROR, null);
// throw new BusinessException(StatusCodeEnum.COMMON_PARAM_ERROR);
}
if (checkEmail(userInfo.getEmail(), userInfo.getId())) {
......@@ -721,20 +741,38 @@ public class UserService {
entityManager.clear();
PageResult<UserInfoSearch> pageResult = new PageResult<>();
String count = "select count(*) ";
String select = "SELECT su.*,sr.name roleName ,sr.id roleId ";
String select = "SELECT su.* ";
String limit = " ORDER BY su.CREATED_TIME DESC limit " + (search.getPage() - 1) * search.getSize() + "," + search.getSize();
StringBuffer querySql = new StringBuffer("from sys_user su left join sys_user_role sur on su.id =sur.user_id left JOIN sys_role sr on sr.id =sur.role_id left join sys_user_org suo on su.id=suo.user_id where 1=1 ");
// StringBuffer querySql = new StringBuffer("from sys_user su left join sys_user_role sur on su.id =sur.user_id left JOIN sys_role sr on sr.id =sur.role_id left join sys_user_org suo on su.id=suo.user_id where 1=1 ");
StringBuffer querySql = new StringBuffer("from sys_user su where 1=1 ");
RoleEntity roleEntity = null;
List<UserRoleEntity> byRoleId = null;
if (StringUtils.isNotBlank(search.getRoleId())) {
querySql.append("and sr.id ='" + search.getRoleId() + "'");
roleEntity = roleDao.findById(search.getRoleId()).orElse(null);
if (ObjectUtil.isNull(roleEntity)) {
return pageResult;
}
byRoleId = userRoleDao.findByRoleId(search.getRoleId());
if (CollectionUtils.isEmpty(byRoleId)) {
return pageResult;
}
List<String> collect = byRoleId.stream().map(UserRoleEntity::getUserId).collect(Collectors.toList());
querySql.append(" and su.id in ('" + String.join("','", collect) + "') ");
}
if (null != search.getSource()) {
querySql.append("and su.source =" + search.getSource() + " ");
querySql.append(" and su.source =" + search.getSource() + " ");
}
if (null != search.getOrgId()) {
querySql.append("and suo.org_id ='" + search.getOrgId() + "'");
// querySql.append("and suo.org_id ='" + search.getOrgId() + "'");
List<UserOrgEntity> byOrgId = userOrgDao.findByOrgId(search.getOrgId());
if (CollectionUtils.isEmpty(byOrgId)) {
return pageResult;
}
List<String> collect = byOrgId.stream().map(UserOrgEntity::getUserId).collect(Collectors.toList());
querySql.append(" and su.id in ('" + String.join("','", collect) + "')");
}
if (null != search.getQueryString()) {
querySql.append("and (su.engineer_code LIKE '%" + search.getQueryString() + "%' or su.nickname like '%" + search.getQueryString() + "%' or su.phone like '%" + search.getQueryString() + "%' or su.email like '%" + search.getQueryString() + "%' )");
querySql.append(" and (su.engineer_code LIKE '%" + search.getQueryString() + "%' or su.nickname like '%" + search.getQueryString() + "%' or su.phone like '%" + search.getQueryString() + "%' or su.email like '%" + search.getQueryString() + "%' )");
}
log.info("countSql:" + (count + querySql.toString()));
BigInteger countNum = (BigInteger) entityManager.createNativeQuery(count + querySql.toString()).getSingleResult();
......@@ -744,13 +782,35 @@ public class UserService {
log.info("selectSql:" + (select + querySql.toString() + limit));
Query query = entityManager.createNativeQuery(select + querySql.toString() + limit);
List<Map<String, Object>> resultList1 = query.getResultList();
// List<Map<String, Object>> resultList1 = query.getResultList();
// log.info("resultList1:" + JSONObject.toJSONString(resultList1));
//将结果转换为Map,返回后的map中的key是数据库表字段,如果用实体接收,使用@JsonAlias设置一下在反序列化时进行映射
query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List<Map<String, Object>> resultList = query.getResultList();
// log.info("resultList:" + JSONObject.toJSONString(resultList));
List<UserInfoSearch> list = resultList.stream().map(a -> mapConvertToObject(a)).collect(Collectors.toList());
RoleEntity finalRoleEntity = roleEntity;
List<UserInfoSearch> list = resultList.stream().map(a -> mapConvertToObject(a, finalRoleEntity)).collect(Collectors.toList());
//组装角色信息
if (CollectionUtils.isNotEmpty(list) && CollectionUtils.isEmpty(byRoleId) && StringUtils.isBlank(search.getRoleId())) {
List<String> collect = list.stream().map(UserInfoSearch::getId).collect(Collectors.toList());
List<UserRoleEntity> byUserIdIn = userRoleDao.findByUserIdIn(collect);
if (CollectionUtils.isNotEmpty(byUserIdIn)) {
List<RoleEntity> allById = roleDao.findAllById(byUserIdIn.stream().map(UserRoleEntity::getRoleId).collect(Collectors.toList()));
if (CollectionUtils.isNotEmpty(allById)) {
Map<String, String> roleMap = allById.stream().collect(Collectors.toMap(RoleEntity::getId, RoleEntity::getName));
Map<String, String> userRoleMap = byUserIdIn.stream().collect(Collectors.toMap(UserRoleEntity::getUserId, UserRoleEntity::getRoleId));
for (UserInfoSearch infoSearch : list) {
if (userRoleMap.containsKey(infoSearch.getId())) {
if (roleMap.containsKey(userRoleMap.get(infoSearch.getId()))) {
infoSearch.setRoleId(userRoleMap.get(infoSearch.getId()));
infoSearch.setRoleName(roleMap.get(userRoleMap.get(infoSearch.getId())));
}
}
}
}
}
}
Integer pageInt = countNum.intValue() / search.getSize();
pageResult.setDataList(list);
pageResult.setCurrPage(search.getPage());
......@@ -766,7 +826,7 @@ public class UserService {
* @param map map
* @return r
*/
public static UserInfoSearch mapConvertToObject(Map<String, Object> map) {
public static UserInfoSearch mapConvertToObject(Map<String, Object> map, RoleEntity roleEntity) {
UserInfoSearch search = new UserInfoSearch();
search.setId(map.containsKey("id") && ObjectUtil.isNotEmpty(map.get("id")) ? map.get("id").toString() : null);
search.setAccount(map.containsKey("account") && ObjectUtil.isNotEmpty(map.get("account")) ? map.get("account").toString() : null);
......@@ -777,8 +837,6 @@ public class UserService {
search.setEmail(map.containsKey("email") && ObjectUtil.isNotEmpty(map.get("email")) ? map.get("email").toString() : null);
search.setPhone(map.containsKey("phone") && ObjectUtil.isNotEmpty(map.get("phone")) ? map.get("phone").toString() : null);
search.setEngineerCode(map.containsKey("engineer_code") && ObjectUtil.isNotEmpty(map.get("engineer_code")) ? map.get("engineer_code").toString() : null);
search.setRoleName(map.containsKey("roleName") && ObjectUtil.isNotEmpty(map.get("roleName")) ? map.get("roleName").toString() : null);
search.setRoleId(map.containsKey("roleId") && ObjectUtil.isNotEmpty(map.get("roleId")) ? map.get("roleId").toString() : null);
search.setBan(map.containsKey("ban") && ObjectUtil.isNotEmpty(map.get("ban")) ? Integer.parseInt(map.get("ban").toString()) : null);
search.setCreatedBy(map.containsKey("CREATED_BY") && ObjectUtil.isNotEmpty(map.get("CREATED_BY")) ? map.get("CREATED_BY").toString() : null);
search.setUpdatedBy(map.containsKey("UPDATED_BY") && ObjectUtil.isNotEmpty(map.get("UPDATED_BY")) ? map.get("UPDATED_BY").toString() : null);
......@@ -786,6 +844,10 @@ public class UserService {
search.setCreatedTime(map.containsKey("CREATED_TIME") && ObjectUtil.isNotEmpty(map.get("CREATED_TIME")) ? formatter.format(map.get("CREATED_TIME")) : null);
search.setUpdatedTime(map.containsKey("UPDATED_TIME") && ObjectUtil.isNotEmpty(map.get("UPDATED_TIME")) ? formatter.format(map.get("UPDATED_TIME")) : null);
search.setLastLoginTime(map.containsKey("LAST_LOGIN_TIME") && ObjectUtil.isNotEmpty(map.get("LAST_LOGIN_TIME")) ? formatter.format(map.get("LAST_LOGIN_TIME")) : null);
if (ObjectUtil.isNotNull(roleEntity)) {
search.setRoleName(roleEntity.getName());
search.setRoleId(roleEntity.getId());
}
return search;
}
......@@ -809,9 +871,18 @@ public class UserService {
if (CollectionUtils.isEmpty(byUserId)) {
return orgInfos;
}
byUserId.forEach(e -> {
List<String> collect = byUserId.stream().map(UserOrgEntity::getOrgId).collect(Collectors.toList());
Result<List<OrganizationDTO>> result = organizationService.getAllOrganizations(LevelUtils.convertOrgLevel(byUserId.get(0).getOrgLevel()), collect);
if (!StringUtils.equals(ResultEnum.SUCCESS.getCode(), result.getCode())) {
throw new BusinessException(StatusCodeEnum.USER_ORG_NULL_ERROR);
}
result.getResult().forEach(e -> {
OrgInfo orgInfo = new OrgInfo();
orgInfo.setId(e.getOrgId());
orgInfo.setId(e.getId());
orgInfo.setName(e.getName());
orgInfo.setOrgLevel(byUserId.get(0).getOrgLevel());
orgInfos.add(orgInfo);
});
return orgInfos;
......
package com.dituhui.pea.user.utils;
import cn.hutool.core.util.ObjectUtil;
public class LevelUtils {
/**
* 组织级别转换
*
* @param orgLevel
* @return
*/
public static String convertOrgLevel(Integer orgLevel) {
if (ObjectUtil.isNull(orgLevel)) {
return null;
}
String level = null;
switch (orgLevel) {
case 0:
return level = "cluster";
case 1:
return level = "branch";
case 2:
return level = "group";
}
return level;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!