screen-api/src/main/java/com/moral/api/controller/HandDeviceController.java
New file @@ -0,0 +1,139 @@ package com.moral.api.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.moral.api.entity.Device; import com.moral.api.entity.HandDevice; import com.moral.api.pojo.query.handdevice.HandDevicePageCond; import com.moral.api.service.DeviceService; import com.moral.api.service.HandDeviceService; import com.moral.api.service.SpecialDeviceService; import com.moral.api.utils.EasyExcelUtils; import com.moral.api.utils.NoModelWriteData; import com.moral.constant.PageResult; import com.moral.constant.ResponseCodeEnum; import com.moral.constant.ResultMessage; import com.moral.util.WebUtils; /** * Description //todo * * @author swb * @ClassName HandDeviceController * @date 2024.02.27 10:21 */ @Slf4j @Api(tags = {"手持设备"}) @RestController @RequestMapping("/hand") public class HandDeviceController { @Autowired private HandDeviceService handDeviceService; @Autowired private DeviceService deviceService; @Autowired private SpecialDeviceService specialDeviceService; @PostMapping("/page") @ApiOperation("分页") public ResultMessage page(@Valid @RequestBody HandDevicePageCond handDevicePageCond){ Page<HandDevice> page = handDeviceService.page(handDevicePageCond); PageResult<HandDevice> rsList = new PageResult<>(page); rsList.setList(page.getRecords()); return ResultMessage.ok(rsList); } @GetMapping("/check") @ApiOperation("查询手持设备") public ResultMessage select(){ List<Device> check = handDeviceService.check(); return ResultMessage.ok(check); } @GetMapping("/id") @ApiOperation("根据mac查询设备") public ResultMessage query(String mac){ HandDevice handDevice = handDeviceService.query(mac); return ResultMessage.ok(handDevice); } @PostMapping("/update") @ApiOperation("修改手持设备") public ResultMessage update(@RequestBody Device device){ if (device.getId() == null) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } /* if (device.getMac() != null) { //判断mac是否已存在,普通设备表和特殊设备表都要判断 QueryWrapper<Device> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE); QueryWrapper<SpecialDevice> specialDeviceQueryWrapper = new QueryWrapper<>(); specialDeviceQueryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE); if (deviceService.getOne(queryWrapper) != null || specialDeviceService.getOne(specialDeviceQueryWrapper) != null) { return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg()); } }*/ handDeviceService.update(device); return ResultMessage.ok(); } @GetMapping("/details") @ApiOperation("详情") public ResultMessage details(String mac,String startTime,String endTime,String type){ List<Map<String, Object>> details = handDeviceService.details(mac, startTime, endTime,type); return ResultMessage.ok(details); } @GetMapping("/unitExel") @ApiOperation("导出") public void exel(HttpServletResponse response, HttpServletRequest request){ Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); List<Map<String, Object>> details = handDeviceService.detailsExecl(params); if (CollectionUtils.isEmpty(details)) { return; } Map<String, Object> map = details.get(0); List<String> list = new ArrayList<>(); for (String key : map.keySet()) { list.add(key); } String[] s2 = new String[list.size()]; list.toArray(s2); NoModelWriteData d = new NoModelWriteData(); d.setFileName("数据导出"); d.setHeadMap(s2); d.setDataStrMap(s2); d.setDataList(details); try { EasyExcelUtils easyExcelUtils = new EasyExcelUtils(); easyExcelUtils.noModleWrite(d, response); } catch (Exception e) { int i = 0; } } } screen-api/src/main/java/com/moral/api/entity/HandDevice.java
New file @@ -0,0 +1,94 @@ package com.moral.api.entity; import lombok.Data; import lombok.EqualsAndHashCode; import java.util.Date; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.extension.activerecord.Model; import com.fasterxml.jackson.annotation.JsonFormat; /** * Description //todo * * @author swb * @ClassName HandDevice * @date 2024.02.27 09:46 */ @Data @EqualsAndHashCode(callSuper = false) public class HandDevice extends Model<HandDevice> { private static final long serialVersionUID = 1L; /** * 主键id */ @TableId(value = "id", type = IdType.AUTO) private Integer id; /** * 设备名称 */ private String name; /** * mac号 */ private String mac; /** * 设备地址 */ private String address; /** * 经度 */ private Double longitude; /** * 纬度 */ private Double latitude; /** * 开始时间 */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date startTime; /** * 结束时间 */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date endTime; /** * 创建人 */ private String createName; /** * 修改人 */ private String updateName; /** * 是否删除 */ private String isDelete; /** * 创建时间 */ private Date createTime; /** * 修改时间 */ private Date updateTime; private String state; } screen-api/src/main/java/com/moral/api/mapper/HandDeviceMapper.java
New file @@ -0,0 +1,19 @@ package com.moral.api.mapper; import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.moral.api.entity.HandDevice; import com.moral.api.pojo.query.handdevice.HandDevicePageCond; public interface HandDeviceMapper extends BaseMapper<HandDevice> { Page<HandDevice> Page(Page page, @Param("mac")String mac, @Param("name")String name, @Param("startTime")String startTime, @Param("endTime")String endTime); } screen-api/src/main/java/com/moral/api/pojo/enums/SysDictTypeEnum.java
@@ -43,6 +43,8 @@ SYS_AMEND("AMEND","立行立改修改数据"), SYS_HAND_DEVICE("HANDDEVICE","手持设备数据"), ; @EnumValue screen-api/src/main/java/com/moral/api/pojo/query/handdevice/HandDevicePageCond.java
New file @@ -0,0 +1,43 @@ package com.moral.api.pojo.query.handdevice; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import java.io.Serializable; import com.moral.api.pojo.query.PageCond; /** * Description //todo * * @author swb * @ClassName HandDevicePageCond * @date 2024.02.27 10:40 */ @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) @ApiModel(value="HandDevice - 分页查询对象", description="HandDevice - 分页查询对象") public class HandDevicePageCond implements Serializable { @ApiModelProperty(value = "mac号") private String mac; @ApiModelProperty(value = "分页参数") private PageCond page; @ApiModelProperty(value = "开始时间") private String startTime; @ApiModelProperty(value = "结束时间") private String endTime; @ApiModelProperty(value = "设备名称") private String name; } screen-api/src/main/java/com/moral/api/service/HandDeviceService.java
New file @@ -0,0 +1,60 @@ package com.moral.api.service; import java.util.List; import java.util.Map; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.moral.api.entity.Device; import com.moral.api.entity.HandDevice; import com.moral.api.pojo.query.handdevice.HandDevicePageCond; public interface HandDeviceService extends IService<HandDevice> { /** * 分页 * @param handDevicePageCond * @return */ Page<HandDevice> page(HandDevicePageCond handDevicePageCond); /** * 查询手持设备 * @return */ List<Device> check(); /** * 修改手持设备 * @return */ void update(Device device); /** * 根据mac查询 * @param mac * @return */ HandDevice query(String mac); /** * 详情 * @param mac * @param startTime * @param endTime * @return */ List<Map<String,Object>> details(String mac,String startTime,String endTime,String type); /** * 导出 * @param params * @return */ List<Map<String,Object>> detailsExecl(Map<String, Object> params); } screen-api/src/main/java/com/moral/api/service/HistoryFiveMinutelyService.java
@@ -55,4 +55,14 @@ QueryFiveDataByMacVO queryFiveDataByMac(String name,String chooseTime,String time); /** * @Description: 查询五分钟内某一mac的数据 * @Param: [mac, startDate, endDate] * @return: java.util.List<com.moral.api.entity.HistoryHourly> * @Author: 陈凯裕 * @Date: 2021/9/23 */ List<HistoryFiveMinutely> queryFiveMinutely(String mac, Date startDate, Date endDate); } screen-api/src/main/java/com/moral/api/service/impl/HandDeviceServiceImpl.java
New file @@ -0,0 +1,249 @@ package com.moral.api.service.impl; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.util.ArrayList; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.api.config.Interceptor.UserHelper; import com.moral.api.entity.Device; import com.moral.api.entity.HandDevice; import com.moral.api.entity.HistoryFiveMinutely; import com.moral.api.entity.HistoryHourly; import com.moral.api.mapper.DeviceMapper; import com.moral.api.mapper.HandDeviceMapper; import com.moral.api.pojo.query.handdevice.HandDevicePageCond; import com.moral.api.pojo.vo.user.QxUser; import com.moral.api.service.DeviceService; import com.moral.api.service.HandDeviceService; import com.moral.api.service.HistoryFiveMinutelyService; import com.moral.api.service.HistoryHourlyService; import com.moral.constant.Constants; import com.moral.util.DateUtils; /** * Description //todo * * @author swb * @ClassName HandDeviceServiceImpl * @date 2024.02.27 10:25 */ @Service public class HandDeviceServiceImpl extends ServiceImpl<HandDeviceMapper, HandDevice> implements HandDeviceService { @Autowired private HandDeviceMapper handDeviceMapper; @Autowired private DeviceService deviceService; @Autowired private DeviceMapper deviceMapper; @Autowired private HistoryHourlyService historyHourlyService; @Autowired private HistoryFiveMinutelyService historyFiveMinutelyService; /** * 分页 * * @param handDevicePageCond * @return */ @Override public Page<HandDevice> page(HandDevicePageCond handDevicePageCond) { Page<HandDevice> page = handDeviceMapper.Page(handDevicePageCond.getPage().convertPage(), handDevicePageCond.getMac(), handDevicePageCond.getName(), handDevicePageCond.getStartTime(), handDevicePageCond.getEndTime()); return page; } /** * 查询手持设备 * @return */ @Override public List<Device> check() { List<Device> organizationDevice = deviceService.getOrganizationDevice(123); return organizationDevice; } /** * 修改手持设备 * * @param device * @return */ @Override @Transactional public void update(Device device) { QxUser currentUser = UserHelper.getCurrentUser(); deviceMapper.updateById(device); QueryWrapper<HandDevice> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("mac",device.getMac()); queryWrapper.orderByDesc("create_time"); List<HandDevice> handDevices = handDeviceMapper.selectList(queryWrapper); HandDevice handDevice = new HandDevice(); handDevice.setAddress(device.getAddress()); handDevice.setName(device.getName()); handDevice.setMac(device.getMac()); handDevice.setLongitude(device.getLongitude()); handDevice.setLatitude(device.getLatitude()); handDevice.setIsDelete(Constants.NOT_DELETE); handDevice.setUpdateName(currentUser.getUserName()); handDevice.setStartTime(new Date()); handDevice.setUpdateTime(new Date()); handDevice.setCreateTime(new Date()); handDevice.setState("1"); if (!ObjectUtils.isEmpty(handDevices)){ HandDevice handDevice1 = handDevices.get(0); String state = handDevice1.getState(); if (state.equals("1")){ handDevice1.setState("0"); handDevice1.setEndTime(new Date()); handDeviceMapper.updateById(handDevice1); }else { handDeviceMapper.insert(handDevice); } }else { handDeviceMapper.insert(handDevice); } } @Override public HandDevice query(String mac) { QueryWrapper<HandDevice> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("mac",mac); queryWrapper.orderByDesc("create_time"); List<HandDevice> handDevices = handDeviceMapper.selectList(queryWrapper); HandDevice handDevice; if (ObjectUtils.isEmpty(handDevices)){ handDevice = new HandDevice(); Device deviceByMac = deviceService.getDeviceByMac(mac); BeanUtils.copyProperties(deviceByMac,handDevice); handDevice.setState("0"); }else { handDevice = handDevices.get(0); } return handDevice; } /** * 详情 * * @param mac * @param startTime * @param endTime * @return */ @Override public List<Map<String, Object>> details(String mac, String startTime, String endTime,String type) { Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_mm_EN); Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_mm_EN); // Date startDate = DateUtils.getDate("2024-01-02 00:00:00",DateUtils.yyyy_MM_dd_HH_mm_EN); // Date endDate = DateUtils.getDate("2024-01-03 05:00:00",DateUtils.yyyy_MM_dd_HH_mm_EN); List<Map<String, Object>> rsMap = new ArrayList<>(); if (type.equals("hour")){ List<HistoryHourly> valueByMacAndTime = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate); for (HistoryHourly historyHourly : valueByMacAndTime) { String value = historyHourly.getValue(); Map map = JSON.parseObject(value, Map.class); map.put("time",DateUtils.dateToDateString(historyHourly.getTime())); map.put("a21001",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); map.put("a21028",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); rsMap.add(map); } }else { List<HistoryFiveMinutely> historyFiveMinutelies = historyFiveMinutelyService.queryFiveMinutely(mac, startDate, endDate); for (HistoryFiveMinutely historyFiveMinutely : historyFiveMinutelies) { String value = historyFiveMinutely.getValue(); Map map = JSON.parseObject(value, Map.class); map.put("time",DateUtils.dateToDateString(historyFiveMinutely.getTime())); map.put("a21001",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); map.put("a21028",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); map.put("a31001",ObjectUtils.isEmpty(map.get("a31001"))?0:map.get("a31001")); rsMap.add(map); } } return rsMap; } /** * 导出 * @param params * @return */ @Override public List<Map<String, Object>> detailsExecl(Map<String, Object> params) { String type = params.get("type").toString(); String mac = params.get("mac").toString(); Date startDate = DateUtils.getDate(params.get("startTime").toString(),DateUtils.yyyy_MM_dd_HH_mm_EN); Date endDate = DateUtils.getDate(params.get("endTime").toString(),DateUtils.yyyy_MM_dd_HH_mm_EN); // Date startDate = DateUtils.getDate("2024-01-02 00:00:00",DateUtils.yyyy_MM_dd_HH_mm_EN); // Date endDate = DateUtils.getDate("2024-01-03 05:00:00",DateUtils.yyyy_MM_dd_HH_mm_EN); List<Map<String, Object>> rsMap = new ArrayList<>(); if (type.equals("hour")){ List<HistoryHourly> valueByMacAndTime = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate); for (HistoryHourly historyHourly : valueByMacAndTime) { LinkedHashMap<String, Object> map1 = new LinkedHashMap<>(); String value = historyHourly.getValue(); Map map = JSON.parseObject(value, Map.class); map1.put("时间",DateUtils.dateToDateString(historyHourly.getTime())); map1.put("pm25",ObjectUtils.isEmpty(map.get("a34004"))?0:map.get("a34004")); map1.put("pm10",ObjectUtils.isEmpty(map.get("a34002"))?0:map.get("a34002")); map1.put("二氧化氮",ObjectUtils.isEmpty(map.get("a21004"))?0:map.get("a21004")); map1.put("二氧化硫",ObjectUtils.isEmpty(map.get("a21026"))?0:map.get("a21026")); map1.put("一氧化碳",ObjectUtils.isEmpty(map.get("a21005"))?0:map.get("a21005")); map1.put("气压",ObjectUtils.isEmpty(map.get("a01006"))?0:map.get("a01006")); map1.put("温度",ObjectUtils.isEmpty(map.get("a01001"))?0:map.get("a01001")); map1.put("湿度",ObjectUtils.isEmpty(map.get("a01002"))?0:map.get("a01002")); map1.put("tvoc",ObjectUtils.isEmpty(map.get("a99054"))?0:map.get("a99054")); map1.put("甲醛",ObjectUtils.isEmpty(map.get("a31001"))?0:map.get("a31001")); map1.put("硫化氢",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); map1.put("氨气",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); rsMap.add(map1); } }else { List<HistoryFiveMinutely> historyFiveMinutelies = historyFiveMinutelyService.queryFiveMinutely(mac, startDate, endDate); for (HistoryFiveMinutely historyFiveMinutely : historyFiveMinutelies) { LinkedHashMap<String, Object> map1 = new LinkedHashMap<>(); String value = historyFiveMinutely.getValue(); Map map = JSON.parseObject(value, Map.class); map1.put("时间",DateUtils.dateToDateString(historyFiveMinutely.getTime())); map1.put("pm25",ObjectUtils.isEmpty(map.get("a34004"))?0:map.get("a34004")); map1.put("pm10",ObjectUtils.isEmpty(map.get("a34002"))?0:map.get("a34002")); map1.put("二氧化氮",ObjectUtils.isEmpty(map.get("a21004"))?0:map.get("a21004")); map1.put("二氧化硫",ObjectUtils.isEmpty(map.get("a21026"))?0:map.get("a21026")); map1.put("一氧化碳",ObjectUtils.isEmpty(map.get("a21005"))?0:map.get("a21005")); map1.put("气压",ObjectUtils.isEmpty(map.get("a01006"))?0:map.get("a01006")); map1.put("温度",ObjectUtils.isEmpty(map.get("a01001"))?0:map.get("a01001")); map1.put("湿度",ObjectUtils.isEmpty(map.get("a01002"))?0:map.get("a01002")); map1.put("tvoc",ObjectUtils.isEmpty(map.get("a99054"))?0:map.get("a99054")); map1.put("甲醛",ObjectUtils.isEmpty(map.get("a31001"))?0:map.get("a31001")); map1.put("硫化氢",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); map1.put("氨气",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); rsMap.add(map1); } } return rsMap; } } screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
@@ -328,6 +328,21 @@ return queryFiveDataByMacVO; } /** * @Description: 查询五分钟内某一mac的数据 * @Param: [mac, startDate, endDate] * @return: java.util.List<com.moral.api.entity.HistoryHourly> * @Author: 陈凯裕 * @Date: 2021/9/23 */ @Override public List<HistoryFiveMinutely> queryFiveMinutely(String mac, Date startDate, Date endDate) { List<HistoryFiveMinutely> valueByMacAndTime = getValueByMacAndTime(mac, startDate, endDate); return valueByMacAndTime; } //对六参以及时间进行排序 private Map<String, Object> orderSixParam(Map<String, Object> data) { LinkedHashMap result = new LinkedHashMap(); screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
@@ -217,8 +217,12 @@ result.put("userId", user.getId()); result.put("account", user.getAccount()); ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(user.getUnitId()); //设备秒级权限 List<Integer> list = responsibilityUnitMapper.selectCodeList(SysDictTypeEnum.SYS_DEVICE.value, user.getId()); //手持设备秒级权限 List<Integer> handList = responsibilityUnitMapper.selectCodeList(SysDictTypeEnum.SYS_HAND_DEVICE.value, user.getId()); result.put("device",ObjectUtils.isEmpty(list)? StateEnum.NOT_EFFECTIVE.value : StateEnum.TAKE_EFFECT.value); result.put("handDevice",ObjectUtils.isEmpty(handList)? StateEnum.NOT_EFFECTIVE.value : StateEnum.TAKE_EFFECT.value); result.put("unName",Objects.nonNull(responsibilityUnit)&&Objects.nonNull(responsibilityUnit.getUnitName())?responsibilityUnit.getUnitName():"管理员登陆"); result.put("openId",openid); Map<String, Object> userInfo = new LinkedHashMap<>(); screen-api/src/main/resources/mapper/HandDeviceMapper.xml
New file @@ -0,0 +1,45 @@ <?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="com.moral.api.mapper.HandDeviceMapper"> <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.moral.api.entity.HandDevice"> <id column="id" property="id" /> <result column="name" property="name" /> <result column="mac" property="mac" /> <result column="address" property="address" /> <result column="longitude" property="longitude" /> <result column="latitude" property="latitude" /> <result column="start_time" property="startTime" /> <result column="is_delete" property="isDelete" /> <result column="end_time" property="endTime" /> <result column="create_name" property="createName" /> <result column="update_name" property="updateName" /> </resultMap> <sql id="Base_Column_List"> id,name,mac,address,longitude,latitude,start_time,is_delete,end_time </sql> <select id="Page" resultType="com.moral.api.entity.HandDevice"> select <include refid="Base_Column_List"/> from hand_device <where> 1=1 and is_delete=0 <if test="name != null and name != ''"> and name = #{name} </if> <if test="mac != null and mac != ''"> and mac = #{mac} </if> <if test="startTime != null and startTime != '' "> and date(start_time) <![CDATA[>=]]> #{startTime} </if> <if test="endTime != null and endTime !='' "> and date(end_time) <![CDATA[<=]]> #{endTime} </if> </where> </select> </mapper>