| | |
| | | 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.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 |
| | |
| | | |
| | | 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) { |
| | | 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"); |
| | | response.setHeader("Access-Control-Allow-Credentials", "true"); |
| | | /*Equipment detail = equipmentService.getOne(Condition.getQueryWrapper(equipment));*/ |
| | | |
| | | return R.data(equipmentService.selectInfo(equipment)); |
| | |
| | | @GetMapping("/page") |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "分页", notes = "传入equipment") |
| | | public R<IPage<EquipmentVO>> page(EquipmentVO equipment, Query query) { |
| | | IPage<EquipmentVO> pages = equipmentService.selectEquipmentPage(Condition.getPage(query), equipment); |
| | | return R.data(pages); |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | equipmentService.s(equipment); |
| | | String deviceNumber = equipment.getDeviceNumber(); |
| | | String deviceName = equipment.getDeviceName(); |
| | | String bType="0"; |
| | | iDeployService.insterb(deviceNumber,deviceName,bType); |
| | | 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) { |
| | | public R update(@Valid @RequestBody EquipmentVOS 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"); |
| | | 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("/updateClinent") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "修改", notes = "传入equipment") |
| | | public R updateClinent(EquipmentVO 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"); |
| | | equipmentService.updateClinent(equipment); |
| | | return R.success("修改成功"); |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 设备列表 |
| | | * @param deviceType 设备类型 |
| | | * |
| | | * @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"); |
| | | response.setHeader("Access-Control-Allow-Credentials", "true"); |
| | | List<EquipmentVOS> list = equipmentService.selectList(deviceType); |
| | | return R.data(list); |
| | | } |