电子看板-工程树接口
This commit is contained in:
parent
56c9aab08d
commit
516310a680
|
|
@ -1,7 +1,16 @@
|
|||
package com.bonus.digitalSignage.backstage.controller;
|
||||
|
||||
import com.bonus.digitalSignage.annotation.DecryptAndVerify;
|
||||
import com.bonus.digitalSignage.annotation.LogAnnotation;
|
||||
import com.bonus.digitalSignage.backstage.entity.dto.QueryParamDto;
|
||||
import com.bonus.digitalSignage.backstage.service.DigitalSignageService;
|
||||
import com.bonus.digitalSignage.system.vo.EncryptedReq;
|
||||
import com.bonus.digitalSignage.utils.ServerResponse;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
|
@ -20,5 +29,12 @@ import javax.annotation.Resource;
|
|||
public class DigitalSignageController {
|
||||
|
||||
@Resource(name = "DigitalSignageService")
|
||||
private DigitalSignageService digitalSignageService;
|
||||
private DigitalSignageService service;
|
||||
|
||||
@ApiOperation("电子看板-工程树")
|
||||
@PostMapping(value = "getProTree")
|
||||
@DecryptAndVerify(decryptedClass = QueryParamDto.class)//加解密统一管理
|
||||
public ServerResponse getProTree(EncryptedReq<QueryParamDto> dto) {
|
||||
return service.getProTree(dto.getData());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package com.bonus.digitalSignage.backstage.dao;
|
||||
|
||||
import com.bonus.digitalSignage.backstage.entity.dto.QueryParamDto;
|
||||
import com.bonus.digitalSignage.backstage.entity.vo.ProTreeVo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className:DigitalSignageDao
|
||||
* @author:cwchen
|
||||
|
|
@ -11,4 +15,12 @@ import org.springframework.stereotype.Repository;
|
|||
*/
|
||||
@Repository(value = "DigitalSignageDao")
|
||||
public interface DigitalSignageDao {
|
||||
/**
|
||||
* 电子看板-工程树
|
||||
* @param dto
|
||||
* @return List<ProTreeVo>
|
||||
* @author cwchen
|
||||
* @date 2025/4/24 10:49
|
||||
*/
|
||||
List<ProTreeVo> getProTree(QueryParamDto dto);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.bonus.digitalSignage.backstage.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className:ProTreeVo
|
||||
* @author:cwchen
|
||||
* @date:2025-04-24-10:40
|
||||
* @version:1.0
|
||||
* @description:工程树
|
||||
*/
|
||||
@Data
|
||||
public class ProTreeVo {
|
||||
|
||||
private String id;
|
||||
|
||||
private String title;
|
||||
|
||||
private String parentId;
|
||||
|
||||
private List<ProTreeVo> children;
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package com.bonus.digitalSignage.backstage.service;
|
||||
|
||||
import com.bonus.digitalSignage.backstage.entity.dto.QueryParamDto;
|
||||
import com.bonus.digitalSignage.utils.ServerResponse;
|
||||
|
||||
/**
|
||||
* @className:DigitalSignageService
|
||||
* @author:cwchen
|
||||
|
|
@ -8,4 +11,12 @@ package com.bonus.digitalSignage.backstage.service;
|
|||
* @description:电子看板-业务层
|
||||
*/
|
||||
public interface DigitalSignageService {
|
||||
/**
|
||||
* 电子看板-工程树
|
||||
* @param data
|
||||
* @return ServerResponse
|
||||
* @author cwchen
|
||||
* @date 2025/4/24 10:39
|
||||
*/
|
||||
ServerResponse getProTree(QueryParamDto data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package com.bonus.digitalSignage.backstage.service.impl;
|
||||
|
||||
import com.bonus.digitalSignage.backstage.dao.DigitalSignageDao;
|
||||
import com.bonus.digitalSignage.backstage.entity.dto.QueryParamDto;
|
||||
import com.bonus.digitalSignage.backstage.entity.vo.ProTreeVo;
|
||||
import com.bonus.digitalSignage.backstage.service.DigitalSignageService;
|
||||
import com.bonus.digitalSignage.utils.ServerResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @className:DigitalSignageServiceImpl
|
||||
|
|
@ -20,4 +24,42 @@ public class DigitalSignageServiceImpl implements DigitalSignageService {
|
|||
|
||||
@Resource(name = "DigitalSignageDao")
|
||||
private DigitalSignageDao dao;
|
||||
|
||||
@Override
|
||||
public ServerResponse getProTree(QueryParamDto dto) {
|
||||
List<ProTreeVo> tree = new ArrayList<>();
|
||||
try {
|
||||
List<ProTreeVo> list = Optional.ofNullable(dao.getProTree(dto)).orElseGet(ArrayList::new);
|
||||
tree = buildTreeWithMap(list);
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(), e);
|
||||
}
|
||||
return ServerResponse.createSuccess(tree);
|
||||
}
|
||||
|
||||
public List<ProTreeVo> buildTreeWithMap(List<ProTreeVo> nodes) {
|
||||
List<ProTreeVo> tree = new ArrayList<>();
|
||||
Map<String, ProTreeVo> nodeMap = new HashMap<>();
|
||||
|
||||
// 第一次遍历:将所有节点存入map
|
||||
for (ProTreeVo node : nodes) {
|
||||
nodeMap.put(node.getId(), node);
|
||||
}
|
||||
// 第二次遍历:建立父子关系
|
||||
for (ProTreeVo node : nodes) {
|
||||
String parentId = node.getParentId();
|
||||
if (parentId == null || parentId.isEmpty()) {
|
||||
tree.add(node);
|
||||
} else {
|
||||
ProTreeVo parent = nodeMap.get(parentId);
|
||||
if (parent != null) {
|
||||
if (parent.getChildren() == null) {
|
||||
parent.setChildren(new ArrayList<>());
|
||||
}
|
||||
parent.getChildren().add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,42 @@
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.digitalSignage.backstage.dao.DigitalSignageDao">
|
||||
|
||||
<!--电子看板-工程树-->
|
||||
<select id="getProTree" resultType="com.bonus.digitalSignage.backstage.entity.vo.ProTreeVo">
|
||||
SELECT DISTINCT A.* FROM (
|
||||
SELECT '0' AS id,
|
||||
'全部工程' AS title,
|
||||
null AS parentId
|
||||
UNION ALL
|
||||
SELECT CONCAT('departId-',td.id) AS id,
|
||||
td2.depart_name AS title,
|
||||
'0' AS parentId
|
||||
FROM tb_project tp
|
||||
LEFT JOIN tb_depart td ON tp.depart_id = td.id
|
||||
LEFT JOIN tb_depart td2 ON td.parent_id = td2.id
|
||||
<where>
|
||||
<if test="level != '1' and departs != null and departs.size() > 0">
|
||||
AND tp.depart_id IN
|
||||
<foreach collection="departs" item="departId" open="(" separator="," close=")">
|
||||
#{departId}
|
||||
</foreach>
|
||||
</if>
|
||||
AND tp.is_active = '1'
|
||||
</where>
|
||||
UNION ALL
|
||||
SELECT tp.id,
|
||||
tp.pro_name AS title,
|
||||
CONCAT('departId-',depart_id) AS parentId
|
||||
FROM tb_project tp
|
||||
<where>
|
||||
<if test="level != '1' and departs != null and departs.size() > 0">
|
||||
AND tp.depart_id IN
|
||||
<foreach collection="departs" item="departId" open="(" separator="," close=")">
|
||||
#{departId}
|
||||
</foreach>
|
||||
</if>
|
||||
AND tp.is_active = '1'
|
||||
</where>
|
||||
) A
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue