Commit f0359f69 by 王力

Merge branch 'dev_layer0731' into 'develop'

Dev layer0731

See merge request !307
2 parents ab240cd0 aa78ee1d
......@@ -3,7 +3,11 @@ package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.OrgBranch;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface OrgBranchMPDao extends BaseMapper<OrgBranch> {
@Select("select * from org_branch where branch_id=#{branchId}")
OrgBranch getByBranchId(String branchId);
}
package com.dituhui.pea.order.dto;
import lombok.Data;
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;
}
package com.dituhui.pea.order.dto;
import lombok.Data;
import java.util.List;
@Data
public class BusinessCustomLayersRespDTO {
private long total;
private long pages;
private long pageCurrent;
private long pageSize;
private List<LayerItem> content;
@Data
public static class LayerItem{
private String layerId;
private String layerName;
private String layerDesc;
private String branchName;
private Integer skillNum;
private String skillList;
}
}
package com.dituhui.pea.order.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.common.ResultEnum;
import com.dituhui.pea.order.dao.MapLayerCustomizeMPDao;
import com.dituhui.pea.order.dao.MapLayerCustomizeSkillMPDao;
import com.dituhui.pea.order.entity.MapLayerCustomize;
import com.dituhui.pea.order.entity.MapLayerCustomizeSkill;
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.BusinessCustomLayersRespDTO;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.feign.ISaaSRemoteService;
import com.dituhui.pea.order.feign.dto.LayerDTO;
import com.dituhui.pea.order.service.BusinessLayerService;
import com.dituhui.pea.order.utils.TypeUtils;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class BusinessLayerServiceImpl implements BusinessLayerService {
@Value("${SaaS.ak}")
String ak;
@Autowired
private MapLayerCustomizeMPDao mapLayerCustomizeMPDao;
@Autowired
private MapLayerCustomizeSkillMPDao mapLayerCustomizeSkillMPDao;
@Autowired
private OrgGroupMPDao orgGroupMPDao;
@Autowired
private OrgBranchMPDao orgBranchMPDao;
@Autowired
private SkillInfoMPDao skillInfoMPDao;
@Autowired
private ISaaSRemoteService saasRemoteService;
@Value("${SaaS.ak}")
String ak;
@Override
public Result<?> businessLayerUniversal() {
return null;
}
@Override
public Result<?> businessCustomLayers(String levelType, String leveValue, long page, long size) {
return null;
public Result<?> businessCustomLayers(String levelType, String levelValue, long page, long size) throws BusinessException {
// 获取branchIds
LambdaQueryWrapper<OrgGroup> lqw = new LambdaQueryWrapper<>();
lqw.eq(levelType.equals("cluster"), OrgGroup::getClusterId, levelValue);
lqw.eq(levelType.equals("branch"), OrgGroup::getBranchId, levelValue);
lqw.eq(levelType.equals("group"), OrgGroup::getGroupId, levelValue);
List<OrgGroup> groups = orgGroupMPDao.selectList(lqw);
if (ListUtils.isEmpty(groups)) {
throw new BusinessException("大区/分部/小组组织结构配置可能错误或缺失,请联系管理员/研发");
}
List<String> branchIds = new ArrayList<>(groups.stream().map(OrgGroup::getBranchId).collect(Collectors.toSet()));
// 获取skillCode与skillName映射信息
List<SkillInfo> skills = skillInfoMPDao.selectList(null);
Map<String, String> branchNames = skills.stream().collect(Collectors.toMap(SkillInfo::getSkillCode, SkillInfo::getSkillCode));
Page<MapLayerCustomize> pg = new Page(page, size);
LambdaQueryWrapper<MapLayerCustomize> mapWrapper = new LambdaQueryWrapper<>();
mapWrapper.eq(MapLayerCustomize::getStatus, 1);
mapWrapper.in(MapLayerCustomize::getBranchId, branchIds);
mapWrapper.orderByAsc(MapLayerCustomize::getLayerId);
mapLayerCustomizeMPDao.selectPage(pg, mapWrapper);
List<BusinessCustomLayersRespDTO.LayerItem> items = new ArrayList<>();
for (MapLayerCustomize layer : pg.getRecords()) {
BusinessCustomLayersRespDTO.LayerItem item = new BusinessCustomLayersRespDTO.LayerItem();
item.setLayerId(layer.getLayerId());
item.setLayerName(layer.getLayer());
item.setLayerDesc(layer.getLayerDescribe());
item.setBranchName(branchNames.getOrDefault(layer.getBranchId(), ""));
List<String> skillItems = this.queryLayerSkill(layer.getLayerId());
item.setSkillNum(skillItems.size());
String skillDesc = String.join("、", new ArrayList<>(new HashSet<>(skillItems)));
item.setSkillList(skillDesc);
items.add(item);
}
BusinessCustomLayersRespDTO res = new BusinessCustomLayersRespDTO();
res.setTotal(pg.getTotal());
res.setPages(pg.getPages());
res.setPageCurrent(pg.getCurrent());
res.setPageSize(pg.getSize());
res.setContent(items);
return Result.success(res);
}
@Override
public Result<?> businessCustomLayer(String layerId) {
return null;
MapLayerCustomize layer = mapLayerCustomizeMPDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 获取技能code列表
List<MapLayerCustomizeSkill> skills = mapLayerCustomizeSkillMPDao.selectByLayerId(layerId);
List<String> skillCodes = skills.stream().filter(s -> s.getStatus() == 1).map(
MapLayerCustomizeSkill::getSkillCode).collect(Collectors.toList());
// 获取branchName
String branchName = "";
OrgBranch branch = orgBranchMPDao.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
......@@ -66,18 +140,32 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
// 同步创建saas图层,返回layerId
String result = saasRemoteService.addLayer(ak, layerName, 1, 1);
log.info("addLayer params:{} result:{}", layerName, result);
Result<LayerDTO> saasResult = TypeUtils.<LayerDTO>convertResult(result);
Result<LayerDTO> saasResult = TypeUtils.convertResult(result);
if (!ResultEnum.SUCCESS.getCode().equals(saasResult.getCode())) {
return Result.failure(saasResult.getMessage());
}
String layerId = saasResult.getResult().getId();// 存入pea
// 入库保存
MapLayerCustomize m = new MapLayerCustomize();
m.setLayerId(layerId);
m.setLayer(layerName);
m.setLayerDescribe(layerDesc);
m.setBranchId(branchId);
m.setStatus(1);
m.setCreateTime(LocalDateTime.now());
mapLayerCustomizeMPDao.insert(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{
public Result<?> businessCustomLayerUpdate(String layerId, String layerDesc, List<String> skillCodes) throws BusinessException {
MapLayerCustomize layer = mapLayerCustomizeMPDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
......@@ -94,7 +182,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
}
@Override
public Result<?> businessCustomLayerRemove(String layerId) throws BusinessException{
public Result<?> businessCustomLayerRemove(String layerId) throws BusinessException {
MapLayerCustomize layer = mapLayerCustomizeMPDao.getByLayerId(layerId);
if (layer == null) {
......@@ -108,7 +196,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
// 同步创建saas图层,返回layerId
String result = saasRemoteService.deleteLayer(ak, layerId);
log.info("deleteLayer params:{} result:{}", layerId, result);
Result<Boolean> saasResult = TypeUtils.<Boolean>convertResult(result);
Result<Boolean> saasResult = TypeUtils.convertResult(result);
if (!ResultEnum.SUCCESS.getCode().equals(saasResult.getCode())) {
return Result.failure(saasResult.getMessage());
}
......@@ -116,7 +204,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
return Result.success(null);
}
private void updateLayerSkills(String layerId, Set<String> skillCodes){
private void updateLayerSkills(String layerId, Set<String> skillCodes) {
// 更新技能信息
// 更新状态为0
......@@ -142,7 +230,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
// 需要新增插入的
Set<String> adds = new HashSet<>(skillCodes);
adds.removeAll(db);
for(String skillCode: adds){
for (String skillCode : adds) {
MapLayerCustomizeSkill c = new MapLayerCustomizeSkill();
c.setLayerId(layerId);
c.setSkillCode(skillCode);
......@@ -152,4 +240,21 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
mapLayerCustomizeSkillMPDao.insert(c);
}
}
private List<String> queryLayerSkill(String layerId) {
List<String> items = new ArrayList<>();
List<SkillInfo> skills = skillInfoMPDao.selectList(null);
Map<String, String> skillMap = skills.stream().collect(Collectors.toMap(SkillInfo::getSkillCode, SkillInfo::getSkill));
List<MapLayerCustomizeSkill> laySkills = mapLayerCustomizeSkillMPDao.selectByLayerId(layerId);
for (MapLayerCustomizeSkill 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!