blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/controller/EquipmentController.java
@@ -258,38 +258,38 @@ page.getRecords().get(j).setDeptName(deptNameBuiffer.substring(0,deptNameBuiffer.length()-1)); } String expireTime = page.getRecords().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类型的 if (expireTime != null) { long st = sim.parse(expireTime).getTime(); long en = sim.parse(end).getTime(); //计算天数 int day = (int) ((st - en) / 86400000); if (day <= 30) { page.getRecords().get(j).setType(1); } else { page.getRecords().get(j).setType(0); } } //判断设备是否在线 String Heartbeat = page.getRecords().get(j).getHeartbeat(); if (Heartbeat != null){ long st = sim.parse(Heartbeat).getTime(); long en = sim.parse(end).getTime(); if ((en - st) >= (60 * 60 * 24 * 1000)){ page.getRecords().get(j).setOnlineStatus("0"); }else{ page.getRecords().get(j).setOnlineStatus("1"); } }else{ page.getRecords().get(j).setOnlineStatus("0"); } // String expireTime = page.getRecords().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类型的 // // if (expireTime != null) { // long st = sim.parse(expireTime).getTime(); // long en = sim.parse(end).getTime(); // //计算天数 // int day = (int) ((st - en) / 86400000); // if (day <= 30) { // page.getRecords().get(j).setType(1); // } else { // page.getRecords().get(j).setType(0); // } // } // // //判断设备是否在线 // String Heartbeat = page.getRecords().get(j).getHeartbeat(); // if (Heartbeat != null){ // long st = sim.parse(Heartbeat).getTime(); // long en = sim.parse(end).getTime(); // if ((en - st) >= (60 * 60 * 24 * 1000)){ // page.getRecords().get(j).setOnlineStatus("0"); // }else{ // page.getRecords().get(j).setOnlineStatus("1"); // } // }else{ // page.getRecords().get(j).setOnlineStatus("0"); // } } blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipmentinfo/controller/EquipmentInfoController.java
New file @@ -0,0 +1,145 @@ /* * 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.jfpt.equipmentinfo.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import io.swagger.annotations.*; import lombok.AllArgsConstructor; import org.springblade.common.vo.DeptVo; import org.springblade.core.boot.ctrl.BladeController; 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.utils.Func; import org.springblade.jfpt.equipment.entity.Equipment; import org.springblade.jfpt.equipment.feign.DeptFeignApi; import org.springblade.jfpt.equipment.vo.EquipmentVO; import org.springblade.jfpt.equipment.vo.EquipmentVOS; import org.springblade.jfpt.equipmentinfo.entity.EquipmentInfo; import org.springblade.jfpt.equipmentinfo.service.EquipmentInfoService; import org.springblade.jfpt.equipmentinfo.vo.EquipmentInfoVo; import org.springblade.system.entity.Region; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.text.ParseException; import java.util.Arrays; import java.util.List; /** * 设备管理控制器 * * @author BladeX * @since 2020-07-01 */ @RestController @AllArgsConstructor @RequestMapping("/equipmentInfo") public class EquipmentInfoController extends BladeController { private final EquipmentInfoService equipmentInfoService; private final DeptFeignApi deptFeignApi; /** * 新增或修改设备信息 * @param equipmentInfo 设备信息 */ @PostMapping("/submit") public R submit(@Valid @RequestBody EquipmentInfo equipmentInfo) { return R.status(equipmentInfoService.saveOrUpdate(equipmentInfo)); } /** * 删除设备信息 * @param ids id数组 */ @PostMapping("/delete") public R delete(@RequestParam String ids) { return R.status(equipmentInfoService.removeByIds(Func.toIntList(ids))); } /** * 自定义分页(部门挂接) * @param equipment 设备对象信息 * @param query 查询参数 * @param response servlet 响应对象 */ @GetMapping("/selectEquipmentInfoDeptPages") public R<IPage<EquipmentInfoVo>> selectEquipmentInfoDeptPages(EquipmentInfoVo equipment, Query query,String pid,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<DeptVo> deptVos = deptFeignApi.selDeptList(); //获取设备数据信息 IPage<EquipmentInfoVo> page = equipmentInfoService.selectEquipmentInfoDeptPages(Condition.getPage(query),pid, equipment); //遍历数据 for (int j = 0; j < page.getRecords().size(); j++) { if (null != page.getRecords().get(j).getDeptId()) { String[] split = page.getRecords().get(j).getDeptId().split(","); List<String> list = Arrays.asList(split); StringBuffer deptNameBuiffer = new StringBuffer(); //数据匹配封装 for (String deptId : list) { for (DeptVo deptVo : deptVos) { if (deptId.equals(deptVo.getId().toString())) { deptNameBuiffer.append(deptVo.getDeptName()).append(","); } } } //封装部门名称数据 page.getRecords().get(j).setDeptName(deptNameBuiffer.substring(0, deptNameBuiffer.length() - 1)); } } return R.data(page); } /** * 详情 * @param response * @param equipment EquipmentInfo 设备信息 ,必须包含id */ @GetMapping("/detail") public R<EquipmentInfoVo> detail(EquipmentInfo 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"); EquipmentInfoVo equipmentInfo = equipmentInfoService.getEquipmentInfoById(equipment.getId()); //获取部门数据 List<DeptVo> deptVos = deptFeignApi.selDeptList(); if (null!=equipmentInfo.getDeptId()){ String[] split =equipmentInfo.getDeptId().split(","); List<String> list = Arrays.asList(split); StringBuffer deptNameBuiffer = new StringBuffer(); //数据匹配封装 for (String deptId:list) { for (DeptVo deptVo:deptVos) { if (deptId.equals(deptVo.getId().toString())){ deptNameBuiffer.append(deptVo.getDeptName()).append("/"); } } } //封装部门名称数据 equipmentInfo.setDeptName(deptNameBuiffer.substring(0,deptNameBuiffer.length()-1)); } return R.data(equipmentInfo); } } blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipmentinfo/entity/EquipmentInfo.java
New file @@ -0,0 +1,104 @@ /* * 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.jfpt.equipmentinfo.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.util.Date; /** * 设备信息实体类 * * @author zhongrj * @time 2021-06-29 */ @Data @TableName("equipment_info") public class EquipmentInfo implements Serializable { private static final long serialVersionUID = 1L; @TableId(value = "id", type = IdType.AUTO) private Integer id; /** * 设备名称 */ private String name; /** * 设备类型 */ private String type; /** * 组织机构 id */ @TableField("dept_id") private String deptId; /** * 设备序列号 */ @TableField("serial_number") private String serialNumber; /** * 备注 */ private String remark; /** * 创建日期 */ @TableField("create_time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GTM+8") private Date createTime; /** * 省 */ private String province; /** * 市 */ private String city; /** * 区,县 */ private String district; /** * 详细地址 */ private String street; } blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipmentinfo/mapper/EquipmentInfoMapper.java
New file @@ -0,0 +1,51 @@ /* * 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.jfpt.equipmentinfo.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.springblade.jfpt.equipmentinfo.entity.EquipmentInfo; import org.springblade.jfpt.equipmentinfo.vo.EquipmentInfoVo; import java.util.List; /** * Mapper 接口 * * @author BladeX * @since 2020-07-01 */ public interface EquipmentInfoMapper extends BaseMapper<EquipmentInfo> { /** * 获取设备信息分页数据 * @param page 分页 * @param equipmentInfo 设备信息 * @return */ List<EquipmentInfoVo> selectEquipmentInfoDeptPages(@Param("equipmentInfo") EquipmentInfoVo equipmentInfo, @Param("pid")String pid); /** * 获取设备信息详情数据 * @param id 设备信息id * @return */ EquipmentInfoVo getEquipmentInfoById(@Param("id")Integer id); } blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipmentinfo/mapper/EquipmentInfoMapper.xml
New file @@ -0,0 +1,41 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.springblade.jfpt.equipmentinfo.mapper.EquipmentInfoMapper"> <select id="selectEquipmentInfoDeptPages" resultType="org.springblade.jfpt.equipmentinfo.vo.EquipmentInfoVo"> select id,name,type,dept_id deptId,serial_number serialNumber,remark,create_time createTime, province,city,district,street from equipment_info where 1=1 <if test="equipmentInfo.name!=null and equipmentInfo.name!=''"> and name like concat('%',#{equipmentInfo.name},'%') </if> <if test="equipmentInfo.serialNumber!=null and equipmentInfo.serialNumber!=''"> and serial_number like concat('%',#{equipmentInfo.serialNumber},'%') </if> <if test="equipmentInfo.province!=null and equipmentInfo.province!=''"> and province like concat('%',#{equipmentInfo.province},'%') </if> <if test="equipmentInfo.city!=null and equipmentInfo.city!=''"> and city like concat('%',#{equipmentInfo.city},'%') </if> <if test="equipmentInfo.district!=null and equipmentInfo.district!=''"> and district like concat('%',#{equipmentInfo.district},'%') </if> <if test="pid!=null and pid!=''"> and dept_id like concat('%',#{pid},'%') </if> order by create_time desc </select> <!--获取设备信息详情数据--> <select id="getEquipmentInfoById" resultType="org.springblade.jfpt.equipmentinfo.vo.EquipmentInfoVo"> select id,name,type,dept_id deptId,serial_number serialNumber,remark,create_time createTime, province,city,district,street from equipment_info where id = #{id} </select> </mapper> blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipmentinfo/service/EquipmentInfoService.java
New file @@ -0,0 +1,47 @@ /* * 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.jfpt.equipmentinfo.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.jfpt.equipmentinfo.entity.EquipmentInfo; import org.springblade.jfpt.equipmentinfo.vo.EquipmentInfoVo; /** * 服务类 * * @author BladeX * @since 2020-07-01 */ public interface EquipmentInfoService extends IService<EquipmentInfo> { /** * 获取设备信息分页数据 * @param page 分页 * @param equipmentInfo 设备信息 * @return */ IPage<EquipmentInfoVo> selectEquipmentInfoDeptPages(IPage<EquipmentInfoVo> page,String pid,EquipmentInfoVo equipmentInfo); /** * 获取设备信息详情数据 * @param id 设备信息id * @return */ EquipmentInfoVo getEquipmentInfoById(Integer id); } blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipmentinfo/service/impl/EquipmentInfoServiceImpl.java
New file @@ -0,0 +1,55 @@ /* * 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.jfpt.equipmentinfo.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springblade.jfpt.equipmentinfo.entity.EquipmentInfo; import org.springblade.jfpt.equipmentinfo.mapper.EquipmentInfoMapper; import org.springblade.jfpt.equipmentinfo.service.EquipmentInfoService; import org.springblade.jfpt.equipmentinfo.vo.EquipmentInfoVo; import org.springframework.stereotype.Service; /** * 服务实现类 * * @author BladeX * @since 2020-07-01 */ @Service public class EquipmentInfoServiceImpl extends ServiceImpl<EquipmentInfoMapper, EquipmentInfo> implements EquipmentInfoService { /** * 获取设备信息分页数据 * @param page 分页 * @param equipmentInfo 设备信息 * @return */ @Override public IPage<EquipmentInfoVo> selectEquipmentInfoDeptPages(IPage<EquipmentInfoVo> page,String pid, EquipmentInfoVo equipmentInfo) { return page.setRecords(baseMapper.selectEquipmentInfoDeptPages(equipmentInfo,pid)); } /** * 获取设备信息详情数据 * @param id 设备信息id * @return */ @Override public EquipmentInfoVo getEquipmentInfoById(Integer id) { return baseMapper.getEquipmentInfoById(id); } } blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipmentinfo/vo/EquipmentInfoVo.java
New file @@ -0,0 +1,34 @@ /* * 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.jfpt.equipmentinfo.vo; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.jfpt.equipment.entity.Equipment; import org.springblade.jfpt.equipmentinfo.entity.EquipmentInfo; /** * 视图实体类 * */ @Data public class EquipmentInfoVo extends EquipmentInfo { private static final long serialVersionUID = 1L; private String deptName; }