Commit 63344de1 by huangjinxin

feat:1:图层派单优先级相关添加

2:分单基础类
1 parent 927d130d
package com.dituhui.pea.common;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
/**
* WEB接口响应封装对象
*/
public class SaasWebResult implements Serializable {
private static final long serialVersionUID = 1L;
private String code; //响应状态码
private Object result; //响应内容
private Object info;//其他信息
private String message;// 返回消息
/**
* 统计数据不做返回
*/
@JsonIgnore
private Object logBeans;
public Object getInfo() {
return info;
}
public void setInfo(Object info) {
this.info = info;
}
/**
* 构造函数
*
* @param code 状态码
* @param result 响应内容
*/
public SaasWebResult(String code, Object result) {
this.code = code;
this.result = result;
}
public SaasWebResult(String code, Object result, String message) {
this.code = code;
this.result = result;
this.message = message;
}
/**
* 存在统计数据
*
* @param code
* @param result
* @param logBeans 统计数据
*/
public SaasWebResult(String code, Object result, Object logBeans) {
this.code = code;
this.result = result;
this.logBeans = logBeans;
}
/**
* @return 状态码
*/
public String getCode() {
return code;
}
/**
* 状态码
*
* @param code
*/
public void setCode(String code) {
this.code = code;
}
/**
* @return 结果
*/
public Object getResult() {
return result;
}
/**
* 结果
*
* @param result
*/
public void setResult(Object result) {
this.result = result;
}
/**
* 统计数据
* @return
*/
public Object getLogBeans() {
return logBeans;
}
/**
* @param logBeans required "? extends LogBean" or "List<? extends LogBean>"
*/
public void setLogBeans(Object logBeans) {
this.logBeans = logBeans;
}
@Override
public String toString() {
return "WebResult{" +
"code='" + code + '\'' +
", result=" + result +
", info=" + info +
", message='" + message + '\'' +
", logBeans=" + logBeans +
'}';
}
}
package com.dituhui.pea.pojo.fendan;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
/**
* 地址解析返回结果
*/
public class APIAddressMatchResult implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* ID
*/
private String id;
/**
* x坐标
*/
private double x;
/**
* y坐标
*/
private double y;
/**
* 结果类型:1代表成功,2代表地址解析失败,3代表点查面失败
*/
private int resultType;
/**
* 结果内容
*/
@JsonIgnore
private String resultInfo;
/**
* 省
*/
private String province;
/**
* 市
*/
private String city;
/**
* 区
*/
private String county;
/**
* ADMINCODE
*/
private String admincode;
/**
* town
*/
private String town;
/**
* 区号
*/
private String aCode;
/**
* 评分
*/
@JsonIgnore
private double score = 0;
/**
* 逆地址解析的地址
*/
private String address ;
private String village;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getResultType() {
return resultType;
}
public void setResultType(int resultType) {
this.resultType = resultType;
}
public String getResultInfo() {
return resultInfo;
}
public void setResultInfo(String resultInfo) {
this.resultInfo = resultInfo;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCounty() {
return county;
}
public void setCounty(String county) {
this.county = county;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
public String getaCode() {
return aCode;
}
public void setaCode(String aCode) {
this.aCode = aCode;
}
public String getAdmincode() {
return admincode;
}
public void setAdmincode(String admincode) {
this.admincode = admincode;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public String getVillage() {
return village;
}
public void setVillage(String village) {
this.village = village;
}
public APIAddressMatchResult(String id) {
this.id = id;
}
@Override
public String toString() {
return "APIAddressMatchResult{" +
"id='" + id + '\'' +
", x=" + x +
", y=" + y +
", resultType=" + resultType +
", resultInfo='" + resultInfo + '\'' +
", province='" + province + '\'' +
", city='" + city + '\'' +
", county='" + county + '\'' +
", village='" + village + '\'' +
", admincode='" + admincode + '\'' +
", score=" + score +
'}';
}
public APIAddressMatchResult() {
}
}
package com.dituhui.pea.pojo.fendan;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* FenDanResult 加上es扩展字段
*
* @author guoping
*/
@Data
public class FenDanEsResult implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 地址解析
*/
private APIAddressMatchResult addressResult;
/**
* 分单面列表
*/
private List<Map<String, Object>> areaResults;
@JsonIgnore
public String statusCode = "S001"; // 状态码,默认成功
}
package com.dituhui.pea.pojo.fendan;
import lombok.Data;
@Data
public class FendanDTO {
/**
* 经纬度
*/
private String xy;
/**
* 区划样式
*/
private Boolean isShowStyle = false;
/**
* 需要行政区划
*/
private Boolean needDistrict = false;
}
......@@ -5,6 +5,7 @@ import com.dituhui.pea.order.dao.SkillInfoDao;
import com.dituhui.pea.order.entity.MapBlockInfoEntity;
import com.dituhui.pea.order.entity.SkillInfoEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -37,4 +38,24 @@ public class CapacityUtils {
return layers;
}
/**
* 根据服务品牌,产品类型,服务类型匹配查询匹配图层
*
* @param brand
* @param type
* @param skillCode
* @return
*/
public List<String> getLayersBySkillCode(String brand, String type, String skillCode) {
List<String> layers = new ArrayList<>();
List<SkillInfoEntity> entitys = skillInfoDao.getByBrandAndTypeAndsAndSkillCode(brand, type, skillCode);
if (CollectionUtils.isNotEmpty(entitys)) {
for (SkillInfoEntity entity : entitys) {
layers.add(entity.getLayerId());
}
}
return layers;
}
}
package com.dituhui.pea.order.common;
import com.alibaba.fastjson.JSONObject;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.common.SaasWebResult;
import com.dituhui.pea.order.dto.SaasFendanDTO;
import com.dituhui.pea.order.dto.SaasXyFendanDTO;
import com.dituhui.pea.order.feign.ISaaSRemoteService;
import com.dituhui.pea.pojo.fendan.FenDanEsResult;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
@Slf4j
......@@ -69,6 +76,33 @@ public class SaasUtils {
return blocks;
}
/**
* 根据提供的地址信息,获取对应的片区图层
*/
public List<BlockInfo> queryBlocksByXy(FendanDTO fendanDTO) {
long t = System.currentTimeMillis();
log.info("===> queryBlocksByXySingleT({})", t);
SaasWebResult webResult = saasRemoteService.single(ak, String.valueOf(t), fendanDTO);
log.info("queryBlocksByXySingle返回结果: ===> {}", webResult.getResult());
List<BlockInfo> blocks = new ArrayList<>();
if (!webResult.getCode().equals("S001")) {
return blocks;
}
//调用saas分单接口
FenDanEsResult fenDanEsResult = JSONObject.parseObject(JSONObject.toJSONString(webResult.getResult()), FenDanEsResult.class);
if (ObjectUtils.isEmpty(fenDanEsResult)) {
return blocks;
}
for (Map<String, Object> areaMap : fenDanEsResult.getAreaResults()) {
if (areaMap.containsKey("id") && areaMap.containsKey("areaName")) {
blocks.add(new BlockInfo()
.setBlockId(areaMap.get("id").toString())
.setBlockName(areaMap.get("areaName").toString()));
}
}
return blocks;
}
public List<BlockInfo> queryBlocksByAddress(String address) {
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
......
......@@ -106,7 +106,7 @@ public class BusinessLayerController {
// 自定义图层修改
Result<?> res = null;
try {
res = businessLayerService.businessCustomLayerUpdate(reqDTO.getLayerId(), reqDTO.getLayerDesc(), reqDTO.getSkills());
res = businessLayerService.businessCustomLayerUpdate(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
......
......@@ -9,6 +9,10 @@ import java.util.List;
public interface SkillInfoDao extends JpaRepository<SkillInfoEntity, Long> {
List<SkillInfoEntity> findAll();
Page<SkillInfoEntity> findAll(Pageable pageable);
SkillInfoEntity getByBrandAndTypeAndSkill(String brand, String type, String skill);
List<SkillInfoEntity> getByBrandAndTypeAndsAndSkillCode(String brand, String type, String skillCode);
}
......@@ -6,10 +6,16 @@ import java.util.List;
@Data
public class BusinessCustomLayerRespDTO {
private String layerId;
private String layerName;
private String layerDesc;
private String branchId;
private String branchName;
private List<String> skills;
private String layerId;
private String layerName;
private String layerDesc;
private String branchId;
private String branchName;
private List<String> skills;
/**
* 派单优先级(1-10,数值越小表示优先级越高,默认10)
*/
private Integer priority;
}
......@@ -9,4 +9,10 @@ public class BusinessCustomLayerUpdateReqDTO {
private String layerId;
private String layerDesc;
private List<String> skills;
/**
* 派单优先级(1-10,数值越小表示优先级越高,默认10)
*/
private Integer priority;
}
......@@ -20,7 +20,7 @@ public class MapLayerCustomizeEntity {
@Column(name = "layer_id", length = 32)
private String layerId;
@Column(name = "saas_layer_id", length = 32)
private String saasLayerId;
......@@ -45,4 +45,9 @@ public class MapLayerCustomizeEntity {
// Getters and Setters
// ...
/**
* 派单优先级(1-10,数值越小表示优先级越高,默认10)
*/
@Column(name = "priority", nullable = false)
private Integer priority = 10;
}
package com.dituhui.pea.order.feign;
import com.dituhui.pea.common.SaasWebResult;
import com.dituhui.pea.pojo.fendan.FenDanEsResult;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(url = "${SaaS.url}", name = "saasService")
......@@ -30,4 +34,8 @@ public interface ISaaSRemoteService {
@GetMapping("/v2/fendan")
public String blockByAddress(@RequestParam String ak, @RequestParam String addresses,
@RequestParam Boolean need_district, @RequestParam Boolean need_layer, @RequestParam String area_fields);
@PostMapping("/saas/fendan/distribute/single")
public SaasWebResult single(@RequestParam String ak, @RequestParam String t, @RequestBody FendanDTO fendanDTO);
}
......@@ -2,19 +2,22 @@ package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.BusinessCustomLayerUpdateReqDTO;
import java.util.List;
public interface BusinessLayerService {
Result<?> businessLayerUniversal();
Result<?> businessLayerUniversal();
Result<?> businessCustomLayers(String levelType, String levelValue, int page, int size);
Result<?> businessCustomLayers(String levelType, String levelValue, int page, int size);
Result<?> businessCustomLayer(String layerId);
Result<?> businessCustomLayer(String layerId);
Result<?> businessCustomLayerAdd(String branchId, String layerName, String layerDesc, List<String> skillCodes);
Result<?> businessCustomLayerAdd(String branchId, String layerName, String layerDesc, List<String> skillCodes);
Result<?> businessCustomLayerUpdate(String layerId, String layerDesc, List<String> skillCodes);
Result<?> businessCustomLayerUpdate(String layerId, String layerDesc, List<String> skillCodes);
Result<?> businessCustomLayerRemove(String layerId);
Result<?> businessCustomLayerUpdate(BusinessCustomLayerUpdateReqDTO reqDTO);
Result<?> businessCustomLayerRemove(String layerId);
}
......@@ -7,6 +7,7 @@ import com.dituhui.pea.common.ResultEnum;
import com.dituhui.pea.order.common.ListUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.BusinessCustomLayerRespDTO;
import com.dituhui.pea.order.dto.BusinessCustomLayerUpdateReqDTO;
import com.dituhui.pea.order.dto.BusinessCustomLayersRespDTO;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.feign.ISaaSRemoteService;
......@@ -14,6 +15,7 @@ import com.dituhui.pea.order.service.BusinessLayerService;
import com.dituhui.pea.order.utils.TypeUtils;
import com.google.gson.internal.LinkedTreeMap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
......@@ -33,258 +35,282 @@ import java.util.stream.Collectors;
@Service
public class BusinessLayerServiceImpl implements BusinessLayerService {
@Value("${SaaS.ak}")
String ak;
@Autowired
private MapLayerCustomizeDao mapLayerCustomizeDao;
@Autowired
private MapLayerCustomizeSkillDao mapLayerCustomizeSkillDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private OrgBranchDao orgBranchDao;
@Autowired
private SkillInfoDao skillInfoDao;
@Autowired
private ISaaSRemoteService saasRemoteService;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private EntityManager entityManager;
@Autowired
private MapLayerDao mapLayerDao;
@Override
public Result<?> businessLayerUniversal() {
List<MapLayerEntity> layers = mapLayerDao.findAll();
return Result.success(layers);
}
@Override
public Result<?> businessCustomLayers(String levelType, String levelValue, int page, int size) throws BusinessException {
// 获取branchIds
List<OrgGroupEntity> groups = new ArrayList<>();
if (levelType.equals("cluster")) {
groups = orgGroupDao.findAllByClusterId(levelValue);
} else if (levelType.equals("branch")) {
groups = orgGroupDao.findAllByBranchId(levelValue);
} else if (levelType.equals("group")) {
groups = orgGroupDao.findAllByGroupId(levelValue);
}
if (ListUtils.isEmpty(groups)) {
throw new BusinessException("大区/分部/小组组织结构配置可能错误或缺失,请联系管理员/研发");
}
List<String> branchIds = new ArrayList<>(groups.stream().map(OrgGroupEntity::getBranchId).collect(Collectors.toSet()));
// 获取skillCode与skillName映射信息
List<SkillInfoEntity> skills = skillInfoDao.findAll();
Map<String, String> skillMapping = skills.stream().collect(Collectors.toMap(
SkillInfoEntity::getSkillCode, SkillInfoEntity::getSkillCode));
//获取分页列表
Specification<MapLayerCustomizeEntity> specification = (root, query, criteriaBuilder) -> {
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
Predicate branchIdPredicate = root.get("branchId").in(branchIds);
return criteriaBuilder.and(statusPredicate, branchIdPredicate);
};
Sort sort = Sort.by(Sort.Order.asc("layerId"));
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
Page<MapLayerCustomizeEntity> pg = mapLayerCustomizeDao.findAll(specification, pageRequest);
// pack
List<BusinessCustomLayersRespDTO.LayerItem> items = new ArrayList<>();
for (MapLayerCustomizeEntity layer : pg.getContent()) {
BusinessCustomLayersRespDTO.LayerItem item = new BusinessCustomLayersRespDTO.LayerItem();
item.setLayerId(layer.getLayerId());
item.setLayerName(layer.getLayer());
item.setLayerDesc(layer.getLayerDescribe());
OrgBranchEntity branch = orgBranchDao.getByBranchId(layer.getBranchId());
if (branch != null) {
item.setBranchName(branch.getBranchName());
}
List<String> skillItems = this.queryLayerSkill(layer.getLayerId());
item.setSkillNum(skillItems.size());
List<String> skillNames = skillItems.stream().map(s -> skillMapping.getOrDefault(s, "")).collect(Collectors.toList());
String skillDesc = String.join("、", new ArrayList<>(new HashSet<>(skillNames)));
item.setSkillList(skillDesc);
items.add(item);
}
BusinessCustomLayersRespDTO res = new BusinessCustomLayersRespDTO();
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
res.setContent(items);
return Result.success(res);
}
@Override
public Result<?> businessCustomLayer(String layerId) {
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 获取技能code列表
List<MapLayerCustomizeSkillEntity> skills = mapLayerCustomizeSkillDao.findByLayerId(layerId);
List<String> skillCodes = skills.stream().filter(s -> s.getStatus() == 1).map(
MapLayerCustomizeSkillEntity::getSkillCode).collect(Collectors.toList());
// 获取branchName
String branchName = "";
OrgBranchEntity branch = orgBranchDao.getByBranchId(layer.getBranchId());
if (branch != null) {
branchName = branch.getBranchName();
}
BusinessCustomLayerRespDTO resp = new BusinessCustomLayerRespDTO();
resp.setLayerId(layerId);
resp.setLayerName(layer.getLayer());
resp.setLayerDesc(layer.getLayerDescribe());
resp.setBranchId(layer.getBranchId());
resp.setBranchName(branchName);
resp.setSkills(skillCodes);
return Result.success(resp);
}
@Transactional
@Override
public Result<?> businessCustomLayerAdd(String branchId, String layerName, String layerDesc, List<String> skillCodes) {
if (orgBranchDao.getByBranchId(branchId) == null) {
throw new BusinessException("分部参数错误,请联系管理员/研发");
}
// 同步创建saas图层,返回layerId
String result = saasRemoteService.addLayer(ak, layerName, 1, 1);
log.info("addLayer params:{} result:{}", layerName, result);
Result<LinkedTreeMap<String, Object>> saasResult = TypeUtils.convertResult(result);
if (!ResultEnum.SUCCESS.getCode().equals(saasResult.getCode())) {
return Result.failure(saasResult.getMessage());
}
String saasLayerId = (String) saasResult.getResult().get("id");// 存入pea
String layerId = UUID.randomUUID().toString().replace("-", "");
// 入库保存
MapLayerCustomizeEntity m = new MapLayerCustomizeEntity();
m.setLayerId(layerId);
m.setSaasLayerId(saasLayerId);
m.setLayer(layerName);
m.setLayerDescribe(layerDesc);
m.setBranchId(branchId);
m.setStatus(1);
m.setCreateTime(LocalDateTime.now());
entityManager.persist(m);
// 更新技能
this.updateLayerSkills(layerId, new HashSet<>(skillCodes));
return Result.success(null);
}
@Transactional
@Override
public Result<?> businessCustomLayerUpdate(String layerId, String layerDesc, List<String> skillCodes) throws BusinessException {
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 更新描述信息
layer.setLayerDescribe(layerDesc);
entityManager.merge(layer);
// 更新技能
this.updateLayerSkills(layerId, new HashSet<>(skillCodes));
return Result.success(null);
}
@Override
public Result<?> businessCustomLayerRemove(String layerId) throws BusinessException {
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 检查下面是否还有区块
List<MapBlockInfoEntity> blocks = mapBlockInfoDao.findByLayerId(layerId);
if (CollectionUtils.isNotEmpty(blocks)) {
return Result.failure("该图层下面还有区块");
}
// 同步删除saas图层
String result = saasRemoteService.deleteLayer(ak, layer.getSaasLayerId());
log.info("deleteLayer params:{} result:{}", layerId, result);
Result<Boolean> saasResult = TypeUtils.convertResult(result);
if (!ResultEnum.SUCCESS.getCode().equals(saasResult.getCode())) {
return Result.failure(saasResult.getMessage());
}
// 更新状态为删除状态
layer.setStatus(0);
entityManager.merge(layer);
return Result.success(null);
}
private void updateLayerSkills(String layerId, Set<String> skillCodes) {
// 更新技能信息
// 更新状态为0
mapLayerCustomizeSkillDao.updateStatusByLayerId(0, layerId);
List<MapLayerCustomizeSkillEntity> skills = mapLayerCustomizeSkillDao.findByLayerId(layerId);
Set<String> db = skills.stream().map(MapLayerCustomizeSkillEntity::getSkillCode).collect(Collectors.toSet());
// 需要更新为有效的
Set<String> updates = new HashSet<>(db);
updates.retainAll(skillCodes);
if (!updates.isEmpty()) {
mapLayerCustomizeSkillDao.updateStatusByLayerIdAndSkillCodeIn(1, layerId, new ArrayList<>(updates));
}
// 需要新增插入的
Set<String> adds = new HashSet<>(skillCodes);
adds.removeAll(db);
for (String skillCode : adds) {
MapLayerCustomizeSkillEntity c = new MapLayerCustomizeSkillEntity();
c.setLayerId(layerId);
c.setSkillCode(skillCode);
c.setStatus(1);
c.setMemo("");
c.setCreateTime(LocalDateTime.now());
entityManager.persist(c);
}
}
private List<String> queryLayerSkill(String layerId) {
List<String> items = new ArrayList<>();
List<SkillInfoEntity> skills = skillInfoDao.findAll();
Map<String, String> skillMap = skills.stream().collect(Collectors.toMap(
SkillInfoEntity::getSkillCode, SkillInfoEntity::getSkill));
List<MapLayerCustomizeSkillEntity> laySkills = mapLayerCustomizeSkillDao.findByLayerId(layerId);
for (MapLayerCustomizeSkillEntity s : laySkills) {
if (s.getStatus() == 0) {
continue;
}
String skill = skillMap.getOrDefault(s.getSkillCode(), "");
items.add(skill);
}
return items;
}
@Value("${SaaS.ak}")
String ak;
@Autowired
private MapLayerCustomizeDao mapLayerCustomizeDao;
@Autowired
private MapLayerCustomizeSkillDao mapLayerCustomizeSkillDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private OrgBranchDao orgBranchDao;
@Autowired
private SkillInfoDao skillInfoDao;
@Autowired
private ISaaSRemoteService saasRemoteService;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private EntityManager entityManager;
@Autowired
private MapLayerDao mapLayerDao;
@Override
public Result<?> businessLayerUniversal() {
List<MapLayerEntity> layers = mapLayerDao.findAll();
return Result.success(layers);
}
@Override
public Result<?> businessCustomLayers(String levelType, String levelValue, int page, int size) throws BusinessException {
// 获取branchIds
List<OrgGroupEntity> groups = new ArrayList<>();
if (levelType.equals("cluster")) {
groups = orgGroupDao.findAllByClusterId(levelValue);
} else if (levelType.equals("branch")) {
groups = orgGroupDao.findAllByBranchId(levelValue);
} else if (levelType.equals("group")) {
groups = orgGroupDao.findAllByGroupId(levelValue);
}
if (ListUtils.isEmpty(groups)) {
throw new BusinessException("大区/分部/小组组织结构配置可能错误或缺失,请联系管理员/研发");
}
List<String> branchIds = new ArrayList<>(groups.stream().map(OrgGroupEntity::getBranchId).collect(Collectors.toSet()));
// 获取skillCode与skillName映射信息
List<SkillInfoEntity> skills = skillInfoDao.findAll();
Map<String, String> skillMapping = skills.stream().collect(Collectors.toMap(
SkillInfoEntity::getSkillCode, SkillInfoEntity::getSkillCode));
//获取分页列表
Specification<MapLayerCustomizeEntity> specification = (root, query, criteriaBuilder) -> {
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
Predicate branchIdPredicate = root.get("branchId").in(branchIds);
return criteriaBuilder.and(statusPredicate, branchIdPredicate);
};
Sort sort = Sort.by(Sort.Order.asc("layerId"));
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
Page<MapLayerCustomizeEntity> pg = mapLayerCustomizeDao.findAll(specification, pageRequest);
// pack
List<BusinessCustomLayersRespDTO.LayerItem> items = new ArrayList<>();
for (MapLayerCustomizeEntity layer : pg.getContent()) {
BusinessCustomLayersRespDTO.LayerItem item = new BusinessCustomLayersRespDTO.LayerItem();
item.setLayerId(layer.getLayerId());
item.setLayerName(layer.getLayer());
item.setLayerDesc(layer.getLayerDescribe());
OrgBranchEntity branch = orgBranchDao.getByBranchId(layer.getBranchId());
if (branch != null) {
item.setBranchName(branch.getBranchName());
}
List<String> skillItems = this.queryLayerSkill(layer.getLayerId());
item.setSkillNum(skillItems.size());
List<String> skillNames = skillItems.stream().map(s -> skillMapping.getOrDefault(s, "")).collect(Collectors.toList());
String skillDesc = String.join("、", new ArrayList<>(new HashSet<>(skillNames)));
item.setSkillList(skillDesc);
items.add(item);
}
BusinessCustomLayersRespDTO res = new BusinessCustomLayersRespDTO();
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
res.setContent(items);
return Result.success(res);
}
@Override
public Result<?> businessCustomLayer(String layerId) {
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 获取技能code列表
List<MapLayerCustomizeSkillEntity> skills = mapLayerCustomizeSkillDao.findByLayerId(layerId);
List<String> skillCodes = skills.stream().filter(s -> s.getStatus() == 1).map(
MapLayerCustomizeSkillEntity::getSkillCode).collect(Collectors.toList());
// 获取branchName
String branchName = "";
OrgBranchEntity branch = orgBranchDao.getByBranchId(layer.getBranchId());
if (branch != null) {
branchName = branch.getBranchName();
}
BusinessCustomLayerRespDTO resp = new BusinessCustomLayerRespDTO();
resp.setLayerId(layerId);
resp.setLayerName(layer.getLayer());
resp.setLayerDesc(layer.getLayerDescribe());
resp.setBranchId(layer.getBranchId());
resp.setBranchName(branchName);
resp.setSkills(skillCodes);
resp.setPriority(layer.getPriority());
return Result.success(resp);
}
@Transactional
@Override
public Result<?> businessCustomLayerAdd(String branchId, String layerName, String layerDesc, List<String> skillCodes) {
if (orgBranchDao.getByBranchId(branchId) == null) {
throw new BusinessException("分部参数错误,请联系管理员/研发");
}
// 同步创建saas图层,返回layerId
String result = saasRemoteService.addLayer(ak, layerName, 1, 1);
log.info("addLayer params:{} result:{}", layerName, result);
Result<LinkedTreeMap<String, Object>> saasResult = TypeUtils.convertResult(result);
if (!ResultEnum.SUCCESS.getCode().equals(saasResult.getCode())) {
return Result.failure(saasResult.getMessage());
}
String saasLayerId = (String) saasResult.getResult().get("id");// 存入pea
String layerId = UUID.randomUUID().toString().replace("-", "");
// 入库保存
MapLayerCustomizeEntity m = new MapLayerCustomizeEntity();
m.setLayerId(layerId);
m.setSaasLayerId(saasLayerId);
m.setLayer(layerName);
m.setLayerDescribe(layerDesc);
m.setBranchId(branchId);
m.setStatus(1);
m.setCreateTime(LocalDateTime.now());
entityManager.persist(m);
// 更新技能
this.updateLayerSkills(layerId, new HashSet<>(skillCodes));
return Result.success(null);
}
@Transactional
@Override
public Result<?> businessCustomLayerUpdate(String layerId, String layerDesc, List<String> skillCodes) throws BusinessException {
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 更新描述信息
layer.setLayerDescribe(layerDesc);
entityManager.merge(layer);
// 更新技能
this.updateLayerSkills(layerId, new HashSet<>(skillCodes));
return Result.success(null);
}
@Transactional
@Override
public Result<?> businessCustomLayerUpdate(BusinessCustomLayerUpdateReqDTO reqDTO) throws BusinessException {
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(reqDTO.getLayerId());
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 更新描述信息
layer.setLayerDescribe(reqDTO.getLayerDesc());
if (ObjectUtils.isNotEmpty(reqDTO)) {
layer.setPriority(reqDTO.getPriority());
}
layer.setLayerDescribe(reqDTO.getLayerDesc());
entityManager.merge(layer);
// 更新技能
this.updateLayerSkills(reqDTO.getLayerId(), new HashSet<>(reqDTO.getSkills()));
return Result.success(null);
}
@Override
public Result<?> businessCustomLayerRemove(String layerId) throws BusinessException {
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 检查下面是否还有区块
List<MapBlockInfoEntity> blocks = mapBlockInfoDao.findByLayerId(layerId);
if (CollectionUtils.isNotEmpty(blocks)) {
return Result.failure("该图层下面还有区块");
}
// 同步删除saas图层
String result = saasRemoteService.deleteLayer(ak, layer.getSaasLayerId());
log.info("deleteLayer params:{} result:{}", layerId, result);
Result<Boolean> saasResult = TypeUtils.convertResult(result);
if (!ResultEnum.SUCCESS.getCode().equals(saasResult.getCode())) {
return Result.failure(saasResult.getMessage());
}
// 更新状态为删除状态
layer.setStatus(0);
entityManager.merge(layer);
return Result.success(null);
}
private void updateLayerSkills(String layerId, Set<String> skillCodes) {
// 更新技能信息
// 更新状态为0
mapLayerCustomizeSkillDao.updateStatusByLayerId(0, layerId);
List<MapLayerCustomizeSkillEntity> skills = mapLayerCustomizeSkillDao.findByLayerId(layerId);
Set<String> db = skills.stream().map(MapLayerCustomizeSkillEntity::getSkillCode).collect(Collectors.toSet());
// 需要更新为有效的
Set<String> updates = new HashSet<>(db);
updates.retainAll(skillCodes);
if (!updates.isEmpty()) {
mapLayerCustomizeSkillDao.updateStatusByLayerIdAndSkillCodeIn(1, layerId, new ArrayList<>(updates));
}
// 需要新增插入的
Set<String> adds = new HashSet<>(skillCodes);
adds.removeAll(db);
for (String skillCode : adds) {
MapLayerCustomizeSkillEntity c = new MapLayerCustomizeSkillEntity();
c.setLayerId(layerId);
c.setSkillCode(skillCode);
c.setStatus(1);
c.setMemo("");
c.setCreateTime(LocalDateTime.now());
entityManager.persist(c);
}
}
private List<String> queryLayerSkill(String layerId) {
List<String> items = new ArrayList<>();
List<SkillInfoEntity> skills = skillInfoDao.findAll();
Map<String, String> skillMap = skills.stream().collect(Collectors.toMap(
SkillInfoEntity::getSkillCode, SkillInfoEntity::getSkill));
List<MapLayerCustomizeSkillEntity> laySkills = mapLayerCustomizeSkillDao.findByLayerId(layerId);
for (MapLayerCustomizeSkillEntity s : laySkills) {
if (s.getStatus() == 0) {
continue;
}
String skill = skillMap.getOrDefault(s.getSkillCode(), "");
items.add(skill);
}
return items;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!