Commit 4f344c2a by wangli

mp2jpa

1 parent 14fd1c29
......@@ -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 com.dituhui.pea.order.entity.MapBlockInfoEntity;
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);
......
......@@ -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
// ...
......
......@@ -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.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,7 +11,6 @@ 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;
......@@ -21,9 +18,15 @@ 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;
......@@ -37,6 +40,8 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
@Autowired
private MapLayerCustomizeMPDao mapLayerCustomizeMPDao;
@Autowired
private MapLayerCustomizeDao mapLayerCustomizeDao;
@Autowired
private MapLayerCustomizeSkillMPDao mapLayerCustomizeSkillMPDao;
@Autowired
private OrgGroupDao orgGroupDao;
......@@ -48,6 +53,8 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
private ISaaSRemoteService saasRemoteService;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private EntityManager entityManager;
@Override
public Result<?> businessLayerUniversal() {
......@@ -55,7 +62,7 @@ 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
List<OrgGroupEntity> groups = new ArrayList<>();
......@@ -76,15 +83,19 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
Map<String, String> skillMapping = skills.stream().collect(Collectors.toMap(
SkillInfoEntity::getSkillCode, SkillInfoEntity::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);
//获取分页列表
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());
......@@ -107,9 +118,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);
......@@ -119,7 +130,7 @@ 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("图层不存在");
}
......@@ -167,7 +178,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);
......@@ -175,7 +186,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));
......@@ -187,14 +198,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));
......@@ -205,7 +215,7 @@ 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("图层不存在");
}
......@@ -226,7 +236,7 @@ public class BusinessLayerServiceImpl implements BusinessLayerService {
// 更新状态为删除状态
layer.setStatus(0);
mapLayerCustomizeMPDao.updateById(layer);
entityManager.merge(layer);
return Result.success(null);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!