|
@@ -0,0 +1,197 @@
|
|
|
+package com.platform.rest.controller.project;
|
|
|
+
|
|
|
+import com.platform.common.bean.AbstractPageResultBean;
|
|
|
+import com.platform.common.util.BeanConverterUtil;
|
|
|
+import com.platform.common.util.R;
|
|
|
+import com.platform.common.validation.group.AddGroup;
|
|
|
+import com.platform.common.validation.group.UpdateGroup;
|
|
|
+import com.platform.dao.dto.project.ProjectDTO;
|
|
|
+import com.platform.dao.dto.sb.SbTypeDTO;
|
|
|
+import com.platform.dao.entity.project.Project;
|
|
|
+import com.platform.dao.entity.sb.SbType;
|
|
|
+import com.platform.dao.util.ExcelUtil;
|
|
|
+import com.platform.dao.util.TreeUtil;
|
|
|
+import com.platform.dao.vo.export.sb.ExportSbTypeVO;
|
|
|
+import com.platform.dao.vo.query.project.ProjectVO;
|
|
|
+import com.platform.dao.vo.sb.SbTypeVO;
|
|
|
+import com.platform.rest.log.annotation.SysLog;
|
|
|
+import com.platform.service.project.ProjectService;
|
|
|
+import com.platform.service.sb.SbTypeService;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 设备类别 控制器
|
|
|
+ * @Author liuyu
|
|
|
+ * @Date 2020-04-21 16:53:51
|
|
|
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/project")
|
|
|
+public class ProjectController {
|
|
|
+
|
|
|
+ private final ProjectService projectService;
|
|
|
+
|
|
|
+ private final SbTypeService sbTypeService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询单条记录
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public R<Project> getById(@PathVariable("id") String id) {
|
|
|
+ return new R<>(projectService.getModelById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增记录
|
|
|
+ *
|
|
|
+ * @param sbTypeDTO 设备类别DTO
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @SysLog("新增设备类别")
|
|
|
+ @PostMapping
|
|
|
+ @PreAuthorize("@pms.hasPermission('sb-types-add')")
|
|
|
+ public R save(@Validated({AddGroup.class}) @RequestBody ProjectDTO sbTypeDTO) {
|
|
|
+ return new R<>(projectService.saveModelByDTO(sbTypeDTO));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改记录
|
|
|
+ *
|
|
|
+ * @param sbTypeDTO 设备类别DTO
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @SysLog("修改设备类别")
|
|
|
+ @PutMapping("/{id}")
|
|
|
+ @PreAuthorize("@pms.hasPermission('sb-types-edit')")
|
|
|
+ public R update(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody ProjectDTO sbTypeDTO) {
|
|
|
+ projectService.modModelByDTO(sbTypeDTO);
|
|
|
+ return new R<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除一条记录
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @SysLog("删除设备类别")
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
+ @PreAuthorize("@pms.hasPermission('sb-types-del')")
|
|
|
+ public R removeById(@PathVariable String id) {
|
|
|
+ projectService.deleteByPrimaryKey(id);
|
|
|
+ return new R<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量记录
|
|
|
+ *
|
|
|
+ * @param ids 主键
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @SysLog("批量删除设备类别")
|
|
|
+ @DeleteMapping("")
|
|
|
+ @PreAuthorize("@pms.hasPermission('sb-types-del')")
|
|
|
+ public R removeIds(@RequestBody List<String> ids) {
|
|
|
+ projectService.batchDelete(ids);
|
|
|
+ return new R<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分页
|
|
|
+ *
|
|
|
+ * @param pageNum 当前页码
|
|
|
+ * @param pageSize 每页条数
|
|
|
+ * @param sbTypeDTO 设备类别DTO
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ public R<AbstractPageResultBean<ProjectVO>> query(ProjectDTO sbTypeDTO, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
|
|
|
+ return new R<>(projectService.selectVOPage(sbTypeDTO, pageNum, pageSize));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取列表
|
|
|
+ *
|
|
|
+ * @param sbTypeDTO 设备类别DTO
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @GetMapping("")
|
|
|
+ public R query(ProjectDTO sbTypeDTO) {
|
|
|
+ return new R<>(projectService.selectVOList(sbTypeDTO));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备类别导出
|
|
|
+ *
|
|
|
+ * @param sbTypeDTO 设备类别DTO
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @GetMapping("/export")
|
|
|
+ @SysLog("设备类别导出")
|
|
|
+ @PreAuthorize("@pms.hasPermission('sb-types-export')")
|
|
|
+ public void export(HttpServletResponse response, ProjectDTO sbTypeDTO) {
|
|
|
+ List<ProjectVO> list = projectService.selectVOList(sbTypeDTO);
|
|
|
+ ExcelUtil.exportResponseDict(response, ExportSbTypeVO.class, BeanConverterUtil.copyListProperties(list, ExportSbTypeVO.class), "设备类别");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取设备tree
|
|
|
+ *
|
|
|
+ * @param sbTypeDTO 设备类别DTO
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @GetMapping("tree")
|
|
|
+ public R queryTree(ProjectDTO sbTypeDTO) {
|
|
|
+ return new R<>(TreeUtil.buildProjectTree(projectService.selectVOList(sbTypeDTO), ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取设备tables tree
|
|
|
+ *
|
|
|
+ * @param sbTypeDTO 设备类别DTO
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @GetMapping("tableTree")
|
|
|
+ public R queryTableTree(ProjectDTO sbTypeDTO) {
|
|
|
+
|
|
|
+ List<ProjectVO> typeList= projectService.selectVOList(sbTypeDTO);
|
|
|
+ List<ProjectVO> parentList = new ArrayList<ProjectVO>();
|
|
|
+ for(ProjectVO type: typeList){
|
|
|
+ if(type.getType() == 1){
|
|
|
+ ProjectVO parent = type;
|
|
|
+ List<ProjectVO> children = new ArrayList<ProjectVO>();
|
|
|
+ for(ProjectVO child: typeList){
|
|
|
+ if(type.getId().equals(child.getParentId())){
|
|
|
+ children.add(child);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ parent.setChildren(children);
|
|
|
+ parentList.add(parent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new R<>(parentList);
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 获取列表
|
|
|
+// *
|
|
|
+// * @param sbTypeDTO 设备位置DTO
|
|
|
+// * @return R
|
|
|
+// */
|
|
|
+// @GetMapping("/longYan")
|
|
|
+// public R queryLongYan(ProjectDTO sbTypeDTO) {
|
|
|
+// return new R<>(ProjectService.selectLongYanList(sbTypeDTO));
|
|
|
+// }
|
|
|
+
|
|
|
+}
|