/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.equipment.controller;
|
|
import io.swagger.annotations.*;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import lombok.AllArgsConstructor;
|
|
import javax.servlet.http.HttpServletResponse;
|
import javax.validation.Valid;
|
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.constant.BladeConstant;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.modules.catalog.service.catalogService;
|
import org.springblade.modules.deploy.service.IDeployService;
|
import org.springblade.modules.equipment.vo.EquipmentVOS;
|
import org.springblade.modules.equipment.wrapper.EqWrapper;
|
import org.springframework.web.bind.annotation.*;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import org.springblade.modules.equipment.entity.Equipment;
|
import org.springblade.modules.equipment.vo.EquipmentVO;
|
import org.springblade.modules.equipment.service.IEquipmentService;
|
import org.springblade.core.boot.ctrl.BladeController;
|
import springfox.documentation.annotations.ApiIgnore;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 控制器
|
*
|
* @author BladeX
|
* @since 2020-07-01
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("equipment/equipment")
|
@Api(value = "", tags = "接口")
|
public class EquipmentController extends BladeController {
|
|
private final IEquipmentService equipmentService;
|
private final IDeployService iDeployService;
|
private final catalogService catalogService;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入equipment")
|
public R<EquipmentVOS> detail(Equipment equipment, HttpServletResponse response) {
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
response.setHeader("Access-Control-Allow-Credentials", "true");
|
/*Equipment detail = equipmentService.getOne(Condition.getQueryWrapper(equipment));*/
|
|
return R.data(equipmentService.selectInfo(equipment));
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入equipment")
|
public R<IPage<Equipment>> list(Equipment equipment, Query query) {
|
IPage<Equipment> pages = equipmentService.page(Condition.getPage(query), Condition.getQueryWrapper(equipment));
|
return R.data(pages);
|
}
|
|
/**
|
* 自定义分页
|
*/
|
@GetMapping("/page")
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "分页", notes = "传入equipment")
|
public R<List<EquipmentVO>> page(EquipmentVO equipment, Query query, String pid, HttpServletResponse response) throws ParseException {
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
response.setHeader("Access-Control-Allow-Credentials", "true");
|
|
//清空全局参数
|
childMenu = new ArrayList();
|
|
//根据查询条件得到所有设备
|
List<EquipmentVO> pages = equipmentService.selectEquipmentPage(equipment.getDeviceName(), equipment.getAddvcd(), equipment.getDtype(), equipment.getDevicestate());
|
|
List<EquipmentVO> datas = new ArrayList<>();
|
|
if (pid == null || pid.equals("")) {
|
for (int j = 0; j < pages.size(); j++) {
|
String expireTime = pages.get(j).getExpireTime();
|
//1.获取当前时间
|
Date dd = new Date();
|
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String end = sim.format(dd);
|
//把string类型转换为long类型的
|
long st = sim.parse(expireTime).getTime();
|
long en = sim.parse(end).getTime();
|
//计算天数
|
int day = (int) ((st - en) / 86400000);
|
if (day <= 30) {
|
pages.get(j).setType(1);
|
} else {
|
pages.get(j).setType(0);
|
}
|
}
|
datas = pages;
|
} else {
|
List<Map<String, Object>> treedatas = catalogService.selectCatalogEqNUmber(pid);
|
//根据传入的id递归出该节点下所有的设备
|
List<Map<String, Object>> childList = treeMenuList(treedatas, Integer.parseInt(pid));
|
//将得到的设备与查询所得设备进行匹配
|
for (int i = 0; i < childList.size(); i++) {
|
for (int j = 0; j < pages.size(); j++) {
|
String expireTime = pages.get(j).getExpireTime();
|
//1.获取当前时间
|
Date dd = new Date();
|
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String end = sim.format(dd);
|
//把string类型转换为long类型的
|
long st = sim.parse(expireTime).getTime();
|
long en = sim.parse(end).getTime();
|
//计算天数
|
int day = (int) ((st - en) / 86400000);
|
if (day <= 30) {
|
pages.get(j).setType(1);
|
} else {
|
pages.get(j).setType(0);
|
}
|
|
if (childList.get(i).get("eqid") != null) {
|
if (childList.get(i).get("eqid").equals(pages.get(j).getDeviceNumber())) {
|
datas.add(pages.get(j));
|
}
|
}
|
}
|
}
|
}
|
return R.data(datas);
|
}
|
|
//子节点
|
private static List childMenu = new ArrayList();
|
|
public static List treeMenuList(List<Map<String, Object>> menuList, int pid) {
|
for (int i = 0; i < menuList.size(); i++) {
|
//遍历出父id等于参数的id,add进子节点集合
|
|
if (pid != 0) {
|
if (menuList.get(i).get("pId").equals(pid)) {
|
//递归遍历下一级
|
treeMenuList(menuList, Integer.valueOf((Integer) menuList.get(i).get("id")));
|
childMenu.add(menuList.get(i));
|
}
|
}
|
|
}
|
return childMenu;
|
}
|
|
/**
|
* 新增
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入equipment")
|
public R save(@Valid @RequestBody EquipmentVOS equipment) {
|
if (equipment.getParentId() == null && equipment.getId() == null) {
|
equipment.setParentId(BladeConstant.TOP_PARENT_ID);
|
}
|
Date day = new Date();
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
equipment.setStime(df.format(day));
|
equipmentService.s(equipment);
|
String deviceNumber = equipment.getDeviceNumber();
|
String deviceName = equipment.getDeviceName();
|
String bType = "0";
|
iDeployService.insterb(deviceNumber, deviceName, bType);
|
return R.success("成功");
|
}
|
|
/**
|
* 修改
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入equipment")
|
public R update(@Valid @RequestBody EquipmentVOS equipment) {
|
Date day = new Date();
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
equipment.setStime(df.format(day));
|
equipmentService.updateOne(equipment);
|
return R.success("修改成功");
|
}
|
|
/**
|
* 新增或修改
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入equipment")
|
public R submit(@Valid @RequestBody Equipment equipment) {
|
return R.status(equipmentService.saveOrUpdate(equipment));
|
}
|
|
/**
|
* 删除
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 8)
|
@ApiOperation(value = "删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
return R.status(equipmentService.removeByIds(Func.toLongList(ids)));
|
}
|
|
/**
|
* 获取树形结构
|
*/
|
@GetMapping("/tree")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "树形结构", notes = "树形结构")
|
public R<List<EquipmentVOS>> tree() {
|
List<EquipmentVOS> tree = equipmentService.tree();
|
return R.data(tree);
|
}
|
|
|
/**
|
* 懒加载列表
|
*/
|
@GetMapping("/lazy-list")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "deptName", value = "部门名称", paramType = "query", dataType = "string"),
|
@ApiImplicitParam(name = "fullName", value = "部门全称", paramType = "query", dataType = "string")
|
})
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "懒加载列表", notes = "传入dept")
|
public R<List<EquipmentVOS>> lazyList(@ApiIgnore @RequestParam Map<String, Object> dept, Long parentId) {
|
List<EquipmentVOS> list = equipmentService.lazyList(parentId, dept);
|
return R.data(EqWrapper.build().listNodeLazyVO(list));
|
}
|
|
|
/**
|
* 设备列表
|
*
|
* @param deviceType 设备类型
|
* @return
|
*/
|
@GetMapping("/selectList")
|
public R<List<EquipmentVOS>> selectList(String deviceType, HttpServletResponse response) {
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
response.setHeader("Access-Control-Allow-Credentials", "true");
|
List<EquipmentVOS> list = equipmentService.selectList(deviceType);
|
return R.data(list);
|
}
|
|
}
|