Commit cfc5e307 by 王力

Merge branch 'dev_mp2jpa0803' into 'develop'

Dev mp2jpa0803

See merge request !324
2 parents ce9530f3 a44aca0c
......@@ -29,7 +29,7 @@ public class BusinessBlockController {
*/
@GetMapping("/business/service/block/list")
public Result<?> businessSeverBlocks(@RequestParam String levelType, @RequestParam String levelValue,
@RequestParam long page, @RequestParam long size,
@RequestParam int page, @RequestParam int size,
@RequestParam(required = false) String layerId,
@RequestParam(required = false) String teamId) {
Result<?> res = null;
......
......@@ -43,7 +43,7 @@ public class BusinessLayerController {
* @return
*/
@GetMapping("/business/layer/custom/list")
public Result<?> businessCustomLayers(String levelType, String levelValue, long page, long size) {
public Result<?> businessCustomLayers(String levelType, String levelValue, int page, int size) {
// 自定义图层列表
Result<?> res = null;
try {
......
package com.dituhui.pea.order.dao;
import java.util.List;
import com.dituhui.pea.order.entity.MapBlockInfoEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
import com.dituhui.pea.order.entity.MapBlockInfoEntity;
import java.util.List;
@Repository
public interface MapBlockInfoDao extends JpaRepository<MapBlockInfoEntity, Integer> {
public interface MapBlockInfoDao extends JpaRepository<MapBlockInfoEntity, Integer>, JpaSpecificationExecutor<MapBlockInfoEntity> {
List<MapBlockInfoEntity> findByBlockIdInAndLayerIdIn(List<String> blockIds, List<String> layerIds);
MapBlockInfoEntity findByBlockId(String blockId);
List<MapBlockInfoEntity> findByBlockIdInAndLayerIdIn(List<String> blockIds, List<String> layerIds);
MapBlockInfoEntity findByBlockId(String blockId);
List<MapBlockInfoEntity> findByGroupId(String groupId);
List<MapBlockInfoEntity> findByGroupId(String groupId);
List<MapBlockInfoEntity> findByLayerId(String layerId);
List<MapBlockInfoEntity> findByLayerId(String layerId);
MapBlockInfoEntity findByTeamIdAndLayerId(String teamId, String layerId);
MapBlockInfoEntity findByTeamIdAndLayerId(String teamId, String layerId);
}
......@@ -2,10 +2,11 @@ package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.MapLayerCustomizeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
public interface MapLayerCustomizeDao extends JpaRepository<MapLayerCustomizeEntity, Long> {
public interface MapLayerCustomizeDao extends JpaRepository<MapLayerCustomizeEntity, Long>, JpaSpecificationExecutor<MapLayerCustomizeEntity>{
public MapLayerCustomizeEntity findByBranchIdAndLayerIdAndStatus(String branchId, String layerId, int status);
......
package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.MapLayerCustomizeSkillEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface MapLayerCustomizeSkillDao extends JpaRepository<MapLayerCustomizeSkillEntity, Long>{
List<MapLayerCustomizeSkillEntity> findByLayerId(String layerId);
@Modifying
@Query("UPDATE MapLayerCustomizeSkill s SET s.status = :status WHERE s.layerId = :layerId")
void updateStatusByLayerId(int status, String layerId);
@Modifying
@Query("UPDATE MapLayerCustomizeSkill s SET s.status = :status WHERE s.layerId = :layerId and s.skillCode IN :skillCodes")
void updateStatusByLayerIdAndSkillCodeIn(int status, String layerId, List<String> skillCodes);
}
......@@ -3,6 +3,7 @@ package com.dituhui.pea.order.entity;
import lombok.Data;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Date;
@Entity
......@@ -36,10 +37,10 @@ public class MapLayerCustomizeEntity {
private String memo;
@Column(name = "create_time", nullable = false)
private Date createTime;
private LocalDateTime createTime;
@Column(name = "update_time", nullable = false)
private Date updateTime;
private LocalDateTime updateTime;
// Getters and Setters
// ...
......
package com.dituhui.pea.order.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;
@Data
public class MapLayerCustomizeSkillEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "layer_id", length = 32)
private String layerId;
@Column(name = "skill_code", length = 32)
private String skillCode;
@Column(name = "description", length = 50)
private String description;
@Column(name = "status", length = 1)
private Integer status;
@Column(name = "memo", length = 100)
private String memo;
@Column(name = "create_time", nullable = false, columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP")
private LocalDateTime createTime;
@Column(name = "update_time", nullable = false, columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
private LocalDateTime updateTime;
}
......@@ -4,7 +4,7 @@ import com.dituhui.pea.common.Result;
public interface BusinessBlockService {
Result<?> businessServerBlocks(String levelType, String levelValue, long page, long size, String layerId, String teamId);
Result<?> businessServerBlocks(String levelType, String levelValue, int page, int size, String layerId, String teamId);
Result<?> businessServiceBlockAdd(String layerId, String teamId);
......
......@@ -8,7 +8,7 @@ import java.util.List;
public interface BusinessLayerService {
Result<?> businessLayerUniversal();
Result<?> businessCustomLayers(String levelType, String levelValue, long page, long size);
Result<?> businessCustomLayers(String levelType, String levelValue, int page, int size);
Result<?> businessCustomLayer(String layerId);
......
package com.dituhui.pea.order.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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;
......@@ -14,13 +12,19 @@ import com.dituhui.pea.order.feign.ISaaSRemoteService;
import com.dituhui.pea.order.service.BusinessBlockService;
import com.dituhui.pea.order.utils.RegionUtils;
import com.dituhui.pea.order.utils.TypeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.criteria.Predicate;
import java.util.*;
import java.util.stream.Collectors;
......@@ -28,49 +32,42 @@ import java.util.stream.Collectors;
@Service
public class BusinessBlockServiceImpl implements BusinessBlockService {
@Value("${SaaS.ak}")
String ak;
@Value("${SaaS.url}")
String url;
@Autowired
private OrgTeamMPDao orgTeamMPDao;
@Autowired
private MapBlockInfoMPDao mapBlockInfoMPDao;
@Autowired
private OrgGroupMPDao orgGroupMPDao;
@Autowired
private MapLayerMPDao mapLayerMPDao;
@Autowired
private MapLayerCustomizeMPDao mapLayerCustomizeMPDao;
private OrgTeamDao orgTeamDao;
@Autowired
private ISaaSRemoteService saasRemoteService;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private MapLayerDao mapLayerDao;
@Autowired
private MapLayerCustomizeDao mapLayerCustomizeDao;
@Value("${SaaS.ak}")
String ak;
@Value("${SaaS.url}")
String url;
@Autowired
private EntityManager entityManager;
@Override
public Result<?> businessServerBlocks(String levelType, String levelValue, long page, long size, String layerId, String teamId) {
public Result<?> businessServerBlocks(String levelType, String levelValue, int page, int size, String layerId, String teamId) {
BusinessServerBlocksRespDTO resp = new BusinessServerBlocksRespDTO();
LambdaQueryWrapper<OrgTeam> lqwTeam = new LambdaQueryWrapper<>();
lqwTeam.eq(levelType.equals("cluster"), OrgTeam::getClusterId, levelValue);
lqwTeam.eq(levelType.equals("branch"), OrgTeam::getBranchId, levelValue);
lqwTeam.eq(levelType.equals("group"), OrgTeam::getGroupId, levelValue);
lqwTeam.eq(StringUtils.isNotEmpty(teamId), OrgTeam::getTeamId, teamId);
List<OrgTeam> teams = orgTeamMPDao.selectList(lqwTeam);
List<OrgTeamEntity> teams = new ArrayList<>();
if (levelType.equals("cluster")) {
teams = orgTeamDao.findAllByClusterId(levelValue);
} else if (levelType.equals("branch")) {
teams = orgTeamDao.findAllByBranchId(levelValue);
} else if (levelType.equals("group")) {
teams = orgTeamDao.findAllByGroupId(levelValue);
}
if (StringUtils.isNotEmpty(teamId)) {
teams = teams.stream().filter(t -> t.getTeamId().equals(teamId)).collect(Collectors.toList());
}
if (ListUtils.isEmpty(teams)) {
resp.setTotal(0);
resp.setPages(1);
......@@ -82,32 +79,42 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
}
// 获得teamId与team的映射
Map<String, OrgTeam> teamMapping = new HashMap<>();
for (OrgTeam t : teams) {
Map<String, OrgTeamEntity> teamMapping = new HashMap<>();
for (OrgTeamEntity t : teams) {
teamMapping.put(t.getTeamId(), t);
}
// teamId列表
List<String> teamIds = teams.stream().map(OrgTeam::getTeamId).collect(Collectors.toList());
List<String> teamIds = teams.stream().map(OrgTeamEntity::getTeamId).collect(Collectors.toList());
// 获取groupId集合
Set<String> groupIds = teams.stream().map(OrgTeam::getGroupId).collect(Collectors.toSet());
List<OrgGroup> groups = orgGroupMPDao.selectByGroupIds(new ArrayList<>(groupIds));
Map<String, String> groupMapping = groups.stream().collect(Collectors.toMap(OrgGroup::getGroupId, OrgGroup::getGroupName));
Page<MapBlockInfo> pg = new Page<>(page, size);
LambdaQueryWrapper<MapBlockInfo> lqwBlock = new LambdaQueryWrapper<>();
lqwBlock.eq(MapBlockInfo::getStatus, 1);
lqwBlock.in(MapBlockInfo::getTeamId, teamIds);
lqwBlock.eq(StringUtils.isNotEmpty(layerId), MapBlockInfo::getLayerId, layerId);
lqwBlock.orderByAsc(MapBlockInfo::getTeamId);
mapBlockInfoMPDao.selectPage(pg, lqwBlock);
Set<String> groupIds = teams.stream().map(OrgTeamEntity::getGroupId).collect(Collectors.toSet());
List<OrgGroupEntity> groups = orgGroupDao.findByGroupIdIn(new ArrayList<>(groupIds));
Map<String, String> groupMapping = groups.stream().collect(
Collectors.toMap(OrgGroupEntity::getGroupId, OrgGroupEntity::getGroupName));
// 获取blocks
Specification<MapBlockInfoEntity> specification = (root, query, criteriaBuilder) -> {
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
Predicate teamIdPredicate = root.get("teamId").in(teamIds);
Predicate layerIdPredicate;
if (StringUtils.isNotEmpty(layerId)) {
layerIdPredicate = criteriaBuilder.equal(root.get("layerId"), layerId);
} else {
layerIdPredicate = criteriaBuilder.conjunction();
}
return criteriaBuilder.and(statusPredicate, teamIdPredicate, layerIdPredicate);
};
Sort sort = Sort.by(Sort.Order.asc("teamId"));
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
Page<MapBlockInfoEntity> pg = mapBlockInfoDao.findAll(specification, pageRequest);
List<BusinessServerBlocksRespDTO.Block> blocks = new ArrayList<>();
for (MapBlockInfo b : pg.getRecords()) {
for (MapBlockInfoEntity b : pg.getContent()) {
BusinessServerBlocksRespDTO.Block block = new BusinessServerBlocksRespDTO.Block();
OrgTeam team = teamMapping.get(b.getTeamId());
OrgTeamEntity team = teamMapping.get(b.getTeamId());
String groupId = team.getGroupId();
String groupName = groupMapping.get(groupId);
......@@ -124,9 +131,9 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
blocks.add(block);
}
resp.setTotal(pg.getTotal());
resp.setPages(pg.getPages());
resp.setPageCurrent(pg.getCurrent());
resp.setTotal(pg.getTotalElements());
resp.setPages(pg.getTotalPages());
resp.setPageCurrent(pg.getNumber() + 1);
resp.setPageSize(pg.getSize());
resp.setTip("");
resp.setContent(blocks);
......@@ -134,15 +141,16 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
return Result.success(resp);
}
@Transactional
@Override
public Result<?> businessServiceBlockAdd(String layerId, String teamId) throws BusinessException {
String layerName;
// 获取layerName
MapLayer layer1 = mapLayerMPDao.getByLayerId(layerId);
if(layer1 == null) {
MapLayerCustomize layer2 = mapLayerCustomizeMPDao.getByLayerId(layerId);
MapLayerEntity layer1 = mapLayerDao.getByLayerId(layerId);
if (layer1 == null) {
MapLayerCustomizeEntity layer2 = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer2 == null) {
throw new BusinessException("图层标签不存在");
} else {
......@@ -152,13 +160,13 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
layerName = layer1.getLayer();
}
OrgTeam team = orgTeamMPDao.getByTeamId(teamId);
OrgTeamEntity team = orgTeamDao.getByTeamId(teamId);
if (team == null) {
throw new BusinessException("关联小队不存在");
}
// 重复检查layerId+teamId
MapBlockInfo existBlock = mapBlockInfoMPDao.getByTeamIdAndLayerId(teamId, layerId);
MapBlockInfoEntity existBlock = mapBlockInfoDao.findByTeamIdAndLayerId(teamId, layerId);
if (null != existBlock) {
return Result.failure("区块已存在");
}
......@@ -172,18 +180,18 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
if (StringUtils.isEmpty(saasLayerId)) {
return Result.failure("图层未配置");
}
String result = saasRemoteService.addArea(ak, team.getTeamName(), saasLayerId, region, "gcj02mc");
log.info("params:{} {} {} {} result:{}", team.getTeamName(), saasLayerId, region, result);
Result<String> saasResult = TypeUtils.<String>convertResult(result);
Result<String> saasResult = TypeUtils.convertResult(result);
if (!ResultEnum.SUCCESS.getCode().equals(saasResult.getCode())) {
return Result.failure("区块已存在或者裁剪为空");
}
String blockId = saasResult.getResult();
String blockName = String.format("%s_%s", layerName, team.getTeamName()); //区块名称
MapBlockInfo block = new MapBlockInfo();
MapBlockInfoEntity block = new MapBlockInfoEntity();
block.setBlockId(blockId);
block.setBlockName(blockName);
block.setBranchId(team.getBranchId());
......@@ -191,15 +199,15 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
block.setTeamId(teamId);
block.setLayerId(layerId);
block.setLayer(layerName);
block.setStatus(1);
mapBlockInfoMPDao.insert(block);
block.setStatus(true);
entityManager.persist(block);
return Result.success(null);
}
/**
* 获取saas图层id
*
*
* @param branchId
* @param layerId
* @return
......@@ -221,29 +229,30 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
return saasLayerId;
}
@Transactional
@Override
public Result<?> businessServiceBlockRemove(String blockId) throws BusinessException {
MapBlockInfo block = mapBlockInfoMPDao.getByBlockId(blockId);
MapBlockInfoEntity block = mapBlockInfoDao.findByBlockId(blockId);
if (block == null) {
throw new BusinessException("区块不存在");
}
block.setStatus(0);
mapBlockInfoMPDao.updateById(block);
block.setStatus(false);
entityManager.merge(block);
// 同步删除saas区块
String result = saasRemoteService.deleteArea(ak, blockId);
log.info("params:{} result:{}", blockId, result);
Result<Boolean> saasResult = TypeUtils.<Boolean>convertResult(result);
Result<Boolean> saasResult = TypeUtils.convertResult(result);
if (!ResultEnum.SUCCESS.getCode().equals(saasResult.getCode())) {
return Result.failure("删除失败,请联系管理员");
}
return Result.success(null);
}
@Override
public Result<?> saasBaseDataLayerUrl(String blockId) throws BusinessException {
MapBlockInfo block = mapBlockInfoMPDao.getByBlockId(blockId);
MapBlockInfoEntity block = mapBlockInfoDao.findByBlockId(blockId);
if (block == null) {
throw new BusinessException("区块不存在");
}
......@@ -266,8 +275,8 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
List<Map<String, String>> items = new ArrayList<>();
// 获取通用图层
List<MapLayer> layers = mapLayerMPDao.selectList(null);
for(MapLayer r: layers){
List<MapLayerEntity> layers = mapLayerDao.findAll();
for (MapLayerEntity r : layers) {
Map<String, String> m = new HashMap<>();
m.put("layerId", r.getLayerId());
m.put("layerName", r.getLayer());
......@@ -275,20 +284,21 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
}
// 获取自定义图层(只有branch才能创建自定义图层)
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);
Set<String> branchIds = orgGroupMPDao.selectList(lqw).stream().map(OrgGroup::getBranchId).collect(Collectors.toSet());
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);
}
Set<String> branchIds = groups.stream().map(OrgGroupEntity::getBranchId).collect(Collectors.toSet());
if (branchIds.isEmpty()) {
return Result.success(items);
}
LambdaQueryWrapper<MapLayerCustomize> lqwLayer = new LambdaQueryWrapper<>();
lqwLayer.eq(MapLayerCustomize::getStatus, 1);
lqwLayer.in(MapLayerCustomize::getBranchId, new ArrayList<>(branchIds));
List<MapLayerCustomize> layerCustomizes = mapLayerCustomizeMPDao.selectList(lqwLayer);
for(MapLayerCustomize r: layerCustomizes) {
List<MapLayerCustomizeEntity> layerCustomizes = mapLayerCustomizeDao.findByBranchIdInAndStatus(new ArrayList<>(branchIds), 1);
for (MapLayerCustomizeEntity r : layerCustomizes) {
Map<String, String> m = new HashMap<>();
m.put("layerId", r.getLayerId());
m.put("layerName", r.getLayer());
......
package com.dituhui.pea.order.service.impl;
import com.alibaba.nacos.common.utils.CollectionUtils;
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;
......@@ -13,17 +10,21 @@ 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 com.google.gson.internal.LinkedTreeMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.criteria.Predicate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -35,19 +36,21 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
@Value("${SaaS.ak}")
String ak;
@Autowired
private MapLayerCustomizeMPDao mapLayerCustomizeMPDao;
private MapLayerCustomizeDao mapLayerCustomizeDao;
@Autowired
private MapLayerCustomizeSkillMPDao mapLayerCustomizeSkillMPDao;
private MapLayerCustomizeSkillDao mapLayerCustomizeSkillDao;
@Autowired
private OrgGroupMPDao orgGroupMPDao;
private OrgGroupDao orgGroupDao;
@Autowired
private OrgBranchMPDao orgBranchMPDao;
private OrgBranchDao orgBranchDao;
@Autowired
private SkillInfoMPDao skillInfoMPDao;
private SkillInfoDao skillInfoDao;
@Autowired
private ISaaSRemoteService saasRemoteService;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private EntityManager entityManager;
@Override
public Result<?> businessLayerUniversal() {
......@@ -55,39 +58,47 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
}
@Override
public Result<?> businessCustomLayers(String levelType, String levelValue, long page, long size) throws BusinessException {
public Result<?> businessCustomLayers(String levelType, String levelValue, int page, int 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);
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(OrgGroup::getBranchId).collect(Collectors.toSet()));
List<String> branchIds = new ArrayList<>(groups.stream().map(OrgGroupEntity::getBranchId).collect(Collectors.toSet()));
// 获取skillCode与skillName映射信息
List<SkillInfo> skills = skillInfoMPDao.selectList(null);
Map<String, String> skillMapping = 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<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 (MapLayerCustomize layer : pg.getRecords()) {
for (MapLayerCustomizeEntity layer : pg.getContent()) {
BusinessCustomLayersRespDTO.LayerItem item = new BusinessCustomLayersRespDTO.LayerItem();
item.setLayerId(layer.getLayerId());
item.setLayerName(layer.getLayer());
item.setLayerDesc(layer.getLayerDescribe());
OrgBranch branch = orgBranchMPDao.getByBranchId(layer.getBranchId());
OrgBranchEntity branch = orgBranchDao.getByBranchId(layer.getBranchId());
if (branch != null) {
item.setBranchName(branch.getBranchName());
}
......@@ -103,9 +114,9 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
}
BusinessCustomLayersRespDTO res = new BusinessCustomLayersRespDTO();
res.setTotal(pg.getTotal());
res.setPages(pg.getPages());
res.setPageCurrent(pg.getCurrent());
res.setTotal(pg.getTotalElements());
res.setPages(pg.getTotalPages());
res.setPageCurrent(pg.getNumber() + 1);
res.setPageSize(pg.getSize());
res.setContent(items);
......@@ -115,19 +126,19 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
@Override
public Result<?> businessCustomLayer(String layerId) {
MapLayerCustomize layer = mapLayerCustomizeMPDao.getByLayerId(layerId);
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 获取技能code列表
List<MapLayerCustomizeSkill> skills = mapLayerCustomizeSkillMPDao.selectByLayerId(layerId);
List<MapLayerCustomizeSkillEntity> skills = mapLayerCustomizeSkillDao.findByLayerId(layerId);
List<String> skillCodes = skills.stream().filter(s -> s.getStatus() == 1).map(
MapLayerCustomizeSkill::getSkillCode).collect(Collectors.toList());
MapLayerCustomizeSkillEntity::getSkillCode).collect(Collectors.toList());
// 获取branchName
String branchName = "";
OrgBranch branch = orgBranchMPDao.getByBranchId(layer.getBranchId());
OrgBranchEntity branch = orgBranchDao.getByBranchId(layer.getBranchId());
if (branch != null) {
branchName = branch.getBranchName();
}
......@@ -147,7 +158,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
@Override
public Result<?> businessCustomLayerAdd(String branchId, String layerName, String layerDesc, List<String> skillCodes) {
if (orgBranchMPDao.getByBranchId(branchId) == null) {
if (orgBranchDao.getByBranchId(branchId) == null) {
throw new BusinessException("分部参数错误,请联系管理员/研发");
}
......@@ -163,7 +174,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
String layerId = UUID.randomUUID().toString().replace("-", "");
// 入库保存
MapLayerCustomize m = new MapLayerCustomize();
MapLayerCustomizeEntity m = new MapLayerCustomizeEntity();
m.setLayerId(layerId);
m.setSaasLayerId(saasLayerId);
m.setLayer(layerName);
......@@ -171,7 +182,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
m.setBranchId(branchId);
m.setStatus(1);
m.setCreateTime(LocalDateTime.now());
mapLayerCustomizeMPDao.insert(m);
entityManager.persist(m);
// 更新技能
this.updateLayerSkills(layerId, new HashSet<>(skillCodes));
......@@ -183,14 +194,13 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
@Override
public Result<?> businessCustomLayerUpdate(String layerId, String layerDesc, List<String> skillCodes) throws BusinessException {
MapLayerCustomize layer = mapLayerCustomizeMPDao.getByLayerId(layerId);
MapLayerCustomizeEntity layer = mapLayerCustomizeDao.getByLayerId(layerId);
if (layer == null) {
throw new BusinessException("图层不存在");
}
// 更新描述信息
layer.setLayerDescribe(layerDesc);
mapLayerCustomizeMPDao.updateById(layer);
entityManager.merge(layer);
// 更新技能
this.updateLayerSkills(layerId, new HashSet<>(skillCodes));
......@@ -201,17 +211,17 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
@Override
public Result<?> businessCustomLayerRemove(String layerId) throws BusinessException {
MapLayerCustomize layer = mapLayerCustomizeMPDao.getByLayerId(layerId);
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);
......@@ -222,7 +232,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
// 更新状态为删除状态
layer.setStatus(0);
mapLayerCustomizeMPDao.updateById(layer);
entityManager.merge(layer);
return Result.success(null);
}
......@@ -231,48 +241,41 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
// 更新技能信息
// 更新状态为0
LambdaUpdateWrapper<MapLayerCustomizeSkill> wrapper = new LambdaUpdateWrapper<>();
wrapper.set(MapLayerCustomizeSkill::getStatus, 0);
wrapper.eq(MapLayerCustomizeSkill::getLayerId, layerId);
mapLayerCustomizeSkillMPDao.update(null, wrapper);
mapLayerCustomizeSkillDao.updateStatusByLayerId(0, layerId);
List<MapLayerCustomizeSkill> skills = mapLayerCustomizeSkillMPDao.selectByLayerId(layerId);
Set<String> db = skills.stream().map(MapLayerCustomizeSkill::getSkillCode).collect(Collectors.toSet());
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()) {
LambdaUpdateWrapper<MapLayerCustomizeSkill> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(MapLayerCustomizeSkill::getStatus, 1);
updateWrapper.eq(MapLayerCustomizeSkill::getLayerId, layerId);
updateWrapper.in(MapLayerCustomizeSkill::getSkillCode, new ArrayList<>(updates));
mapLayerCustomizeSkillMPDao.update(null, updateWrapper);
if (!updates.isEmpty()) {
mapLayerCustomizeSkillDao.updateStatusByLayerIdAndSkillCodeIn(1, layerId, new ArrayList<>(updates));
}
// 需要新增插入的
Set<String> adds = new HashSet<>(skillCodes);
adds.removeAll(db);
for (String skillCode : adds) {
MapLayerCustomizeSkill c = new MapLayerCustomizeSkill();
MapLayerCustomizeSkillEntity c = new MapLayerCustomizeSkillEntity();
c.setLayerId(layerId);
c.setSkillCode(skillCode);
c.setStatus(1);
c.setMemo("");
c.setCreateTime(LocalDateTime.now());
mapLayerCustomizeSkillMPDao.insert(c);
entityManager.persist(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<SkillInfoEntity> skills = skillInfoDao.findAll();
Map<String, String> skillMap = skills.stream().collect(Collectors.toMap(
SkillInfoEntity::getSkillCode, SkillInfoEntity::getSkill));
List<MapLayerCustomizeSkill> laySkills = mapLayerCustomizeSkillMPDao.selectByLayerId(layerId);
for (MapLayerCustomizeSkill s : laySkills) {
List<MapLayerCustomizeSkillEntity> laySkills = mapLayerCustomizeSkillDao.findByLayerId(layerId);
for (MapLayerCustomizeSkillEntity s : laySkills) {
if (s.getStatus() == 0) {
continue;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!