return iDeptService.treeList(); | return iDeptService.treeList(); | ||||
} | } | ||||
@GetMapping("/test") | |||||
public JsonResult test(String id){ | |||||
return iDeptService.test(id); | |||||
} | |||||
} | } |
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
import com.tuoheng.miniprogram.entity.query.InspectionQuery; | import com.tuoheng.miniprogram.entity.query.InspectionQuery; | ||||
import com.tuoheng.miniprogram.service.IInspectionService; | import com.tuoheng.miniprogram.service.IInspectionService; | ||||
import com.tuoheng.miniprogram.vo.AirLineVO; | |||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.web.bind.annotation.GetMapping; | import org.springframework.web.bind.annotation.GetMapping; | ||||
import org.springframework.web.bind.annotation.PathVariable; | |||||
import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
import java.util.List; | |||||
/** | /** | ||||
* 巡检任务管理 前端控制器 | * 巡检任务管理 前端控制器 | ||||
* | * | ||||
return iInspectionService.index(query); | return iInspectionService.index(query); | ||||
} | } | ||||
/** | |||||
* | |||||
* 获取巡检路线 | |||||
* @param droneId | |||||
* @return | |||||
*/ | |||||
@GetMapping("/airport/line/{droneId}") | |||||
public List<AirLineVO> airLine(@PathVariable("droneId") Integer droneId){ | |||||
return iInspectionService.airLine(droneId); | |||||
} | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
import com.tuoheng.miniprogram.entity.Dept; | import com.tuoheng.miniprogram.entity.Dept; | ||||
import org.apache.ibatis.annotations.Param; | |||||
import java.util.List; | |||||
/** | /** | ||||
* @Author ChengWang | * @Author ChengWang | ||||
*/ | */ | ||||
public interface DeptMapper extends BaseMapper<Dept> { | public interface DeptMapper extends BaseMapper<Dept> { | ||||
List<String> selectAllChildListById(String id); | |||||
List<String> getSondeptId(@Param("parentId") String id); | |||||
} | } |
*/ | */ | ||||
public interface IDeptService { | public interface IDeptService { | ||||
JsonResult treeList(); | JsonResult treeList(); | ||||
JsonResult test(String id); | |||||
} | } |
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
import com.tuoheng.miniprogram.entity.query.InspectionQuery; | import com.tuoheng.miniprogram.entity.query.InspectionQuery; | ||||
import com.tuoheng.miniprogram.vo.AirLineVO; | |||||
import java.util.List; | |||||
/** | /** | ||||
* @Author ChengWang | * @Author ChengWang | ||||
*/ | */ | ||||
public interface IInspectionService { | public interface IInspectionService { | ||||
JsonResult index(InspectionQuery query); | JsonResult index(InspectionQuery query); | ||||
List<AirLineVO> airLine(Integer droneId); | |||||
} | } |
*/ | */ | ||||
@Override | @Override | ||||
public JsonResult treeList() { | public JsonResult treeList() { | ||||
List<Dept> deptTreeVoList = new ArrayList<>(); | |||||
List<Dept> list = deptMapper.selectList(new LambdaQueryWrapper<Dept>() | List<Dept> list = deptMapper.selectList(new LambdaQueryWrapper<Dept>() | ||||
.eq(Dept::getMark, 1)); | .eq(Dept::getMark, 1)); | ||||
Map<String, Dept> deptVoMap = new HashMap<>(); | |||||
for (Dept dept : list) { | |||||
deptVoMap.put(dept.getId(),dept); | |||||
} | |||||
for (Dept dept : list) { | |||||
Dept child = dept; | |||||
if("0".equals(child.getPid())){ | |||||
deptTreeVoList.add(dept); | |||||
}else { | |||||
Dept parent = deptVoMap.get(child.getPid()); | |||||
parent.getItemList().add(child); | |||||
} | |||||
} | |||||
return JsonResult.success(deptTreeVoList); | |||||
// 获取所有一级节点 | // 获取所有一级节点 | ||||
//预设id值为2 | //预设id值为2 | ||||
// List<Dept> result = list.stream(). | |||||
// filter(dept -> dept.getPid().equals("2")) | |||||
// .peek(dept -> dept.setItemList(getChildren(dept, list))).sorted(Comparator.comparingInt(dept -> (dept.getSort() == null ? 0 : dept.getSort()))) | |||||
// .collect(Collectors.toList()); | |||||
// List<String> list1 = new ArrayList<>(); | |||||
// for (Dept dept : result) { | |||||
// List<Dept> itemList = dept.getItemList(); | |||||
// if(itemList!=null) | |||||
// list1.add(dept.getId()); | |||||
// List<Dept> list1 = new ArrayList<>(); | |||||
// result.stream().map(item->{ | |||||
// TreeUtil.getByParent(list1,item.getPid()); | |||||
// }).collect(Collectors.toList()); | |||||
// return JsonResult.success(result); | |||||
List<Dept> result = list.stream(). | |||||
filter(dept -> dept.getPid().equals("1")) | |||||
.peek(dept -> dept.setItemList(getChildren(dept, list))).sorted(Comparator.comparingInt(dept -> (dept.getSort() == null ? 0 : dept.getSort()))) | |||||
.collect(Collectors.toList()); | |||||
//List<Dept> deptList = new ArrayList<>(); | |||||
return JsonResult.success(result); | |||||
// List<Dept> deptTreeVoList = new ArrayList<>(); | |||||
// Map<String, Dept> deptVoMap = new HashMap<>(); | |||||
// for (Dept dept : list) { | |||||
// deptVoMap.put(dept.getId(),dept); | |||||
// } | |||||
// for (Dept dept : list) { | |||||
// Dept child = dept; | |||||
// if("0".equals(child.getPid())){ | |||||
// deptTreeVoList.add(dept); | |||||
// }else { | |||||
// Dept parent = deptVoMap.get(child.getPid()); | |||||
// parent.getItemList().add(child); | |||||
// } | |||||
// } | |||||
// return JsonResult.success(deptTreeVoList); | |||||
} | |||||
@Override | |||||
public JsonResult test(String id) { | |||||
List<String> list = deptMapper.selectAllChildListById(id); | |||||
return JsonResult.success(list); | |||||
} | } | ||||
//查询出所有部门 | |||||
// List all; | |||||
// addAll(1,all,new ArrayList()); | |||||
// | |||||
// private void addAll(Integer id,List all,List res){ | |||||
// all.stream().filter(x->Objects.equals(x.getparentId,id)).forEach(x->{ | |||||
// res.add(x.getid()); | |||||
// addAll(x.getid(),all,res); | |||||
// }); | |||||
// } | |||||
/** | /** | ||||
* 递归获取部门的子集 | * 递归获取部门的子集 | ||||
* | * |
import com.tuoheng.miniprogram.entity.query.InspectionQuery; | import com.tuoheng.miniprogram.entity.query.InspectionQuery; | ||||
import com.tuoheng.miniprogram.service.IInspectionService; | import com.tuoheng.miniprogram.service.IInspectionService; | ||||
import com.tuoheng.miniprogram.utils.ShiroUtils; | import com.tuoheng.miniprogram.utils.ShiroUtils; | ||||
import com.tuoheng.miniprogram.vo.AirLineVO; | |||||
import com.tuoheng.miniprogram.vo.InspectionInfoVo; | import com.tuoheng.miniprogram.vo.InspectionInfoVo; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.beans.BeanUtils; | import org.springframework.beans.BeanUtils; | ||||
//查询部门及下级部门列表 | //查询部门及下级部门列表 | ||||
List<Dept> list = deptMapper.selectList(Wrappers.<Dept>lambdaQuery() | List<Dept> list = deptMapper.selectList(Wrappers.<Dept>lambdaQuery() | ||||
.eq(Dept::getMark, 1)); | .eq(Dept::getMark, 1)); | ||||
//预设id为2 | |||||
//初始部门id | |||||
String deptIdInt = query.getDeptId(); | |||||
//query.setDeptId("1"); | //query.setDeptId("1"); | ||||
// 获取所有下级部门列表 | |||||
// List<Dept> result = list.stream(). | |||||
// filter(dept -> dept.getPid().equals(query.getDeptId())) | |||||
// .peek(dept -> dept.setItemList(getChildren(dept, list))).sorted(Comparator.comparingInt(dept -> (dept.getSort() == null ? 0 : dept.getSort()))) | |||||
// .collect(Collectors.toList()); | |||||
//query.setTenantId("0"); | |||||
//获取当前部门对应的巡检任务 | |||||
// List<Inspection> inspectionList = inspectionMapper.selectList(Wrappers.<Inspection>lambdaQuery() | |||||
// .eq(StringUtils.isNotEmpty(query.getDeptId()), Inspection::getDeptId, query.getDeptId()) | |||||
// .eq(Inspection::getMark, 1) | |||||
// .eq(Inspection::getTenantId,0)); | |||||
//获取分页数据 | //获取分页数据 | ||||
IPage<Inspection> page = new Page<>(query.getPage(),query.getLimit()); | IPage<Inspection> page = new Page<>(query.getPage(),query.getLimit()); | ||||
//获取当前部门对应的巡检任务 | |||||
List<Inspection> inspectionList = inspectionMapper.selectList(Wrappers.<Inspection>lambdaQuery() | |||||
.eq(StringUtils.isNotEmpty(query.getDeptId()), Inspection::getDeptId, query.getDeptId()) | |||||
.eq(Inspection::getMark, 1) | |||||
.eq(Inspection::getTenantId,0)); | |||||
IPage<InspectionInfoVo> pageDataVo = new Page<>(query.getPage(),query.getLimit()); | |||||
Date startTime = null; | Date startTime = null; | ||||
Date endTime = null; | Date endTime = null; | ||||
if(StringUtils.isNotEmpty(query.getStartTime()) && StringUtils.isNotEmpty(query.getEndTime())){ | if(StringUtils.isNotEmpty(query.getStartTime()) && StringUtils.isNotEmpty(query.getEndTime())){ | ||||
} | } | ||||
query.setStartTimeDate(startTime); | query.setStartTimeDate(startTime); | ||||
query.setEndTimeDate(endTime); | query.setEndTimeDate(endTime); | ||||
// 根据部门id获取此部门id和所有下级部门id封装list集合 | |||||
List<String> deptLists = deptMapper.selectAllChildListById(query.getDeptId()); | |||||
List<InspectionInfoVo> inspectionInfoVoList = new ArrayList<>(); | |||||
IPage<InspectionInfoVo> pageData = inspectionMapper.queryPage(page,query); | |||||
pageData.getRecords().stream().forEach(x->{ | |||||
int problemsFoundNum = 0; | |||||
int problemsVerifiedNum = 0; | |||||
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(Wrappers.<InspectionFile>lambdaQuery() | |||||
.eq(StringUtils.isNotEmpty(x.getId()), InspectionFile::getInspectionId, x.getId()) | |||||
.eq(InspectionFile::getTenantId, 0)); | |||||
for (InspectionFile inspectionFile : inspectionFileList) { | |||||
if (5 == inspectionFile.getStatus()) { | |||||
problemsFoundNum += 1; | |||||
for (int i = 0; i < deptLists.size(); i++) { | |||||
String deptId = deptLists.get(i); | |||||
query.setDeptId(deptId); | |||||
IPage<InspectionInfoVo> pageData = inspectionMapper.queryPage(page,query); | |||||
pageData.getRecords().stream().forEach(x->{ | |||||
int problemsFoundNum = 0; | |||||
int problemsVerifiedNum = 0; | |||||
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(Wrappers.<InspectionFile>lambdaQuery() | |||||
.eq(StringUtils.isNotEmpty(x.getId()), InspectionFile::getInspectionId, x.getId()) | |||||
.eq(InspectionFile::getTenantId, 0)); | |||||
for (InspectionFile inspectionFile : inspectionFileList) { | |||||
if (5 == inspectionFile.getStatus()) { | |||||
problemsFoundNum += 1; | |||||
} | |||||
if (15 == inspectionFile.getStatus()) { | |||||
problemsVerifiedNum += 1; | |||||
} | |||||
} | } | ||||
if (15 == inspectionFile.getStatus()) { | |||||
problemsVerifiedNum += 1; | |||||
//获取任务deptId1:1为部门任务 0为子部门任务 | |||||
String deptId1 = query.getDeptId(); | |||||
if(deptIdInt.equals(deptId)){ | |||||
x.setFlag(1); | |||||
}else { | |||||
x.setFlag(0); | |||||
} | } | ||||
x.setProblemsFoundNum(problemsFoundNum); | |||||
x.setProblemsVerifiedNum(problemsVerifiedNum); | |||||
}); | |||||
List<InspectionInfoVo> records = pageData.getRecords(); | |||||
for (InspectionInfoVo record : records) { | |||||
inspectionInfoVoList.add(record); | |||||
} | } | ||||
x.setProblemsFoundNum(problemsFoundNum); | |||||
x.setProblemsVerifiedNum(problemsVerifiedNum); | |||||
}); | |||||
//查询每个任务对应的总问题数和已确认的问题数 | |||||
// List<InspectionInfoVo> inspectionInfoVoList = pageData.getRecords().stream().map(item -> { | |||||
// //InspectionInfoVo vo = new InspectionInfoVo(); | |||||
// // BeanUtils.copyProperties(item, vo); | |||||
// int problemsFoundNum = 0; | |||||
// int problemsVerifiedNum = 0; | |||||
// List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(Wrappers.<InspectionFile>lambdaQuery() | |||||
// .eq(StringUtils.isNotEmpty(item.getId()), InspectionFile::getInspectionId, item.getId()) | |||||
// .eq(InspectionFile::getTenantId, 0)); | |||||
// for (InspectionFile inspectionFile : inspectionFileList) { | |||||
// if (5 == inspectionFile.getStatus()) { | |||||
// problemsFoundNum += 1; | |||||
// } | |||||
// if (15 == inspectionFile.getStatus()) { | |||||
// problemsVerifiedNum += 1; | |||||
// } | |||||
// } | |||||
// vo.setProblemsFoundNum(problemsFoundNum); | |||||
// vo.setProblemsVerifiedNum(problemsVerifiedNum); | |||||
// return vo; | |||||
// | |||||
// }).collect(Collectors.toList()); | |||||
// pageData.setRecords(inspectionInfoVoList); | |||||
return JsonResult.success(pageData); | |||||
} | |||||
pageDataVo.setRecords(inspectionInfoVoList); | |||||
return JsonResult.success(pageDataVo); | |||||
} | |||||
@Override | |||||
public List<AirLineVO> airLine(Integer droneId) { | |||||
return null; | |||||
} | } | ||||
package com.tuoheng.miniprogram.vo; | |||||
import lombok.Data; | |||||
import lombok.NoArgsConstructor; | |||||
import java.io.Serializable; | |||||
/** | |||||
* @User qiujinyang | |||||
* @Description | |||||
* @Date Created by 2022/7/28 13:31 | |||||
*/ | |||||
@NoArgsConstructor | |||||
@Data | |||||
public class AirLineVO implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
/** | |||||
* 任务id | |||||
*/ | |||||
private Integer id; | |||||
/** | |||||
* 任务编号 | |||||
*/ | |||||
private String code; | |||||
/** | |||||
* 任务名称 | |||||
*/ | |||||
private String name; | |||||
/** | |||||
* 无人机id | |||||
*/ | |||||
private Integer droneId; | |||||
/** | |||||
* 无人机名称 | |||||
*/ | |||||
private String droneName; | |||||
/** | |||||
* 无人机直播播流地址 | |||||
*/ | |||||
private String liveUrl; | |||||
/** | |||||
* 航线id | |||||
*/ | |||||
private Integer airlineFileId; | |||||
/** | |||||
* 航线名称 | |||||
*/ | |||||
private String airlineFileName; | |||||
/** | |||||
* 航线文件地址路径 | |||||
*/ | |||||
private String airlineFileUrl; | |||||
/** | |||||
* 执行类型,1单次2每天 | |||||
*/ | |||||
private Integer type; | |||||
/** | |||||
* 单次执行时间 | |||||
*/ | |||||
private String singleTime; | |||||
/** | |||||
* 每天执行时间 | |||||
*/ | |||||
private Object everydayTime; | |||||
/** | |||||
* 任务备注 | |||||
*/ | |||||
private Object note; | |||||
/** | |||||
* 任务状态1待执行 2执行中 | |||||
*/ | |||||
private Integer status; | |||||
/** | |||||
* 创建人 | |||||
*/ | |||||
private Integer createUser; | |||||
/** | |||||
* 创建时间 | |||||
*/ | |||||
private String createTime; | |||||
/** | |||||
* 修改用户 | |||||
*/ | |||||
private Integer updateUser; | |||||
/** | |||||
* 修改时间 | |||||
*/ | |||||
private String updateTime; | |||||
} |
*/ | */ | ||||
private Integer problemsVerifiedNum; | private Integer problemsVerifiedNum; | ||||
/** | |||||
* 判断是否是本部的任务 flag: 1是 0否 | |||||
*/ | |||||
private Integer flag; | |||||
} | } |
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
<mapper namespace="com.tuoheng.miniprogram.dao.DeptMapper"> | <mapper namespace="com.tuoheng.miniprogram.dao.DeptMapper"> | ||||
<resultMap id="DeptResult" type="com.tuoheng.miniprogram.entity.Dept" > | |||||
<result property="id" column="id" /> | |||||
<result property="tenantId" column="tenant_id" /> | |||||
<result property="name" column="name" /> | |||||
<result property="code" column="code" /> | |||||
<result property="fullname" column="fullname" /> | |||||
<result property="type" column="type" /> | |||||
<result property="pid" column="pid" /> | |||||
<result property="sort" column="sort" /> | |||||
<result property="note" column="note" /> | |||||
<result property="createUser" column="create_user" /> | |||||
<result property="createTime" column="create_time" /> | |||||
<result property="updateUser" column="update_user" /> | |||||
<result property="updateTime" column="update_time" /> | |||||
<result property="mark" column="mark" /> | |||||
</resultMap> | |||||
<sql id="Base_Column_List"> | |||||
id, tenant_id, name, code, fullname, type, pid, sort, note, create_user, create_time, update_user, update_time, mark | |||||
</sql> | |||||
<select id="selectAllChildListById" parameterType="String" resultType="java.lang.String"> | |||||
SELECT id | |||||
FROM( | |||||
SELECT @ids AS p_ids, (SELECT @ids := GROUP_CONCAT(id) FROM th_dept WHERE FIND_IN_SET(pid, CONVERT(@ids USING utf8) COLLATE utf8_unicode_ci)) AS c_ids, @l := @l+1 AS LEVEL | |||||
FROM th_dept, (SELECT @ids := #{id}, @l := 0 ) b | |||||
having @ids IS NOT NULL | |||||
) u1 | |||||
JOIN th_dept u2 ON FIND_IN_SET(u2.id, CONVERT(u1.p_ids USING utf8) COLLATE utf8_unicode_ci); | |||||
</select> | |||||
<select id="getSondeptId" parameterType="String" resultType="java.lang.String"> | |||||
<![CDATA[ | |||||
select eo.id from th_dept eo where eo.pid=#{parentId} | |||||
]]> | |||||
</select> | |||||
</mapper> | </mapper> |