diff --git a/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/entity/MechanicalEquipmentPositionDev.java b/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/entity/MechanicalEquipmentPositionDev.java index 6ff00e3d5..3d279c86d 100644 --- a/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/entity/MechanicalEquipmentPositionDev.java +++ b/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/entity/MechanicalEquipmentPositionDev.java @@ -84,4 +84,8 @@ public class MechanicalEquipmentPositionDev implements Serializable { @ApiModelProperty(value = "司机名称") @TableField(exist = false) private java.lang.String driverName; + + @TableField(exist = false) + @ApiModelProperty(value = "在线状态(0.离线 1.在线)") + private java.lang.Integer online; } diff --git a/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/service/impl/MechanicalEquipmentPositionDataServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/service/impl/MechanicalEquipmentPositionDataServiceImpl.java index 95952b3e2..74de32467 100644 --- a/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/service/impl/MechanicalEquipmentPositionDataServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/service/impl/MechanicalEquipmentPositionDataServiceImpl.java @@ -16,15 +16,19 @@ import com.zhgd.jeecg.common.system.query.QueryGenerator; import com.zhgd.xmgl.modules.mechanicalequipmentposition.entity.MechanicalEquipmentPositionAlarm; import com.zhgd.xmgl.modules.mechanicalequipmentposition.entity.MechanicalEquipmentPositionData; import com.zhgd.xmgl.modules.mechanicalequipmentposition.entity.MechanicalEquipmentPositionDev; +import com.zhgd.xmgl.modules.mechanicalequipmentposition.entity.MechanicalEquipmentPositionFence; import com.zhgd.xmgl.modules.mechanicalequipmentposition.entity.vo.PositionAddData; import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipmentPositionAlarmMapper; import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipmentPositionDataMapper; import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipmentPositionDevMapper; +import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipmentPositionFenceMapper; import com.zhgd.xmgl.modules.mechanicalequipmentposition.service.IMechanicalEquipmentPositionDataService; import com.zhgd.xmgl.util.PageUtil; import com.zhgd.xmgl.util.RefUtil; +import com.zhgd.xmgl.util.RegionUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,6 +54,10 @@ public class MechanicalEquipmentPositionDataServiceImpl extends ServiceImpl queryPageList(HashMap paramMap) { @@ -91,6 +99,41 @@ public class MechanicalEquipmentPositionDataServiceImpl extends ServiceImpl fenceList = mechanicalEquipmentPositionFenceMapper.selectList(new LambdaQueryWrapper() + .eq(MechanicalEquipmentPositionFence::getProjectSn, dev.getProjectSn())); + boolean inFence = false; + for (MechanicalEquipmentPositionFence fence : fenceList) { + //判断是否在围栏范围内 + if (Objects.equals(fence.getRangeType(), 1)) { + inFence = RegionUtil.isInCircle(mechanicalEquipmentPositionData.getLongitude(), mechanicalEquipmentPositionData.getLatitude(), fence.getLongitude(), fence.getLatitude(), fence.getAreaRadius()); + } else if (Objects.equals(fence.getRangeType(), 2)) { + String fenceShape = fence.getFenceShape(); + if (StrUtil.isNotBlank(fenceShape)) { + String[] couples = StringUtils.split(fenceShape, ","); + Double[] lon = new Double[couples.length]; + Double[] lat = new Double[couples.length]; + for (int i = 0; i < couples.length; i++) { + String couple = couples[i]; + String[] two = StringUtils.split(couple, "|"); + lon[i] = Double.valueOf(two[0]); + lat[i] = Double.valueOf(two[1]); + } + inFence = RegionUtil.isInPolygon(mechanicalEquipmentPositionData.getLongitude(), mechanicalEquipmentPositionData.getLatitude(), lon, lat); + } + } + if (inFence) { + break; + } + } + if (!inFence) { + MechanicalEquipmentPositionAlarm alarm = new MechanicalEquipmentPositionAlarm(); + alarm.setDevSn(dev.getDevSn()); + alarm.setAlarmTime(new Date()); + alarm.setAlarmInfo("翻越围栏报警"); + mechanicalEquipmentPositionAlarmService.add(alarm); + } } @Override diff --git a/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/service/impl/MechanicalEquipmentPositionDevServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/service/impl/MechanicalEquipmentPositionDevServiceImpl.java index 43f914bf3..973e85c1f 100644 --- a/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/service/impl/MechanicalEquipmentPositionDevServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/mechanicalequipmentposition/service/impl/MechanicalEquipmentPositionDevServiceImpl.java @@ -63,7 +63,8 @@ public class MechanicalEquipmentPositionDevServiceImpl extends ServiceImpl qw.lt(alias + RefUtil.fieldNameUlc(MechanicalEquipmentPositionDev::getHeartbeatTime), dateTime).or() + .isNull(alias + RefUtil.fieldNameUlc(MechanicalEquipmentPositionDev::getHeartbeatTime))); } } return queryWrapper; diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java index f78980191..319419103 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java @@ -1,28 +1,23 @@ package com.zhgd.xmgl.modules.safetyhat.controller; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.gexin.fastjson.JSON; +import com.zhgd.jeecg.common.api.vo.Result; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiImplicitParams; - -import java.util.HashMap; - -import springfox.documentation.annotations.ApiIgnore; - -import java.util.List; - -import com.zhgd.jeecg.common.api.vo.Result; -import org.apache.commons.collections.MapUtils; - -import org.simpleframework.xml.core.Validate; -import com.baomidou.mybatisplus.core.metadata.IPage; +import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; - +import org.apache.commons.collections.MapUtils; +import org.simpleframework.xml.core.Validate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.HashMap; +import java.util.List; /** @@ -37,95 +32,111 @@ import org.springframework.web.bind.annotation.*; @Slf4j @Api(tags = "智能安全帽-实时数据相关Api") public class SafetyHatDataController { - @Autowired - private ISafetyHatDataService safetyHatDataService; + @Autowired + private ISafetyHatDataService safetyHatDataService; - /** - * 分页列表查询 - * - * @return - */ - @ApiOperation(value = "分页列表查询智能安全帽-实时数据信息", notes = "分页列表查询智能安全帽-实时数据信息", httpMethod = "GET") - @ApiImplicitParams({ - @ApiImplicitParam(name = "pageNo", value = "第几页", paramType = "query", required = true, dataType = "Integer"), - @ApiImplicitParam(name = "pageSize", value = "每页显示条数", paramType = "query", required = true, dataType = "Integer"), - @ApiImplicitParam(name = "day", value = "日(yyyy-MM-dd)", paramType = "query", required = false, dataType = "String"), - }) - @GetMapping(value = "/page") - public Result> queryPageList(@ApiIgnore @RequestParam HashMap paramMap) { - return Result.success(safetyHatDataService.queryPageList(paramMap)); - } + /** + * 分页列表查询 + * + * @return + */ + @ApiOperation(value = "分页列表查询智能安全帽-实时数据信息", notes = "分页列表查询智能安全帽-实时数据信息", httpMethod = "GET") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNo", value = "第几页", paramType = "query", required = true, dataType = "Integer"), + @ApiImplicitParam(name = "pageSize", value = "每页显示条数", paramType = "query", required = true, dataType = "Integer"), + @ApiImplicitParam(name = "day", value = "日(yyyy-MM-dd)", paramType = "query", required = false, dataType = "String"), + }) + @GetMapping(value = "/page") + public Result> queryPageList(@ApiIgnore @RequestParam HashMap paramMap) { + return Result.success(safetyHatDataService.queryPageList(paramMap)); + } - /** - * 列表查询 - * - * @return - */ - @ApiOperation(value = "列表查询智能安全帽-实时数据信息", notes = "列表查询智能安全帽-实时数据信息", httpMethod = "GET") - @GetMapping(value = "/list") - public Result> queryList(@ApiIgnore @RequestParam HashMap paramMap) { - return Result.success(safetyHatDataService.queryList(paramMap)); - } + /** + * 列表查询 + * + * @return + */ + @ApiOperation(value = "列表查询智能安全帽-实时数据信息", notes = "列表查询智能安全帽-实时数据信息", httpMethod = "GET") + @GetMapping(value = "/list") + public Result> queryList(@ApiIgnore @RequestParam HashMap paramMap) { + return Result.success(safetyHatDataService.queryList(paramMap)); + } - /** - * 添加 - * - * @param safetyHatData - * @return - */ - @ApiOperation(value = "添加智能安全帽-实时数据信息", notes = "添加智能安全帽-实时数据信息", httpMethod = "POST") - @PostMapping(value = "/add") - public Result add(@RequestBody @Validate SafetyHatData safetyHatData) { + /** + * 添加 + * + * @param safetyHatData + * @return + */ + @ApiOperation(value = "添加智能安全帽-实时数据信息", notes = "添加智能安全帽-实时数据信息", httpMethod = "POST") + @PostMapping(value = "/add") + public Result add(@RequestBody @Validate SafetyHatData safetyHatData) { log.info("列表查询智能安全帽-实时数据信息:{}", JSON.toJSONString(safetyHatData)); safetyHatDataService.add(safetyHatData); - return Result.ok(); - } + return Result.ok(); + } - /** - * 编辑 - * - * @param safetyHatData - * @return - */ - @ApiOperation(value = "编辑智能安全帽-实时数据信息", notes = "编辑智能安全帽-实时数据信息", httpMethod = "POST") - @PostMapping(value = "/edit") - public Result edit(@RequestBody SafetyHatData safetyHatData) { - safetyHatDataService.edit(safetyHatData); - return Result.ok(); - } + /** + * 编辑 + * + * @param safetyHatData + * @return + */ + @ApiOperation(value = "编辑智能安全帽-实时数据信息", notes = "编辑智能安全帽-实时数据信息", httpMethod = "POST") + @PostMapping(value = "/edit") + public Result edit(@RequestBody SafetyHatData safetyHatData) { + safetyHatDataService.edit(safetyHatData); + return Result.ok(); + } - /** - * 通过id删除 - * - * @return - */ - @ApiOperation(value = "删除智能安全帽-实时数据信息", notes = "删除智能安全帽-实时数据信息", httpMethod = "POST") - @ApiImplicitParam(name = "id", value = "智能安全帽-实时数据ID", paramType = "body", required = true, dataType = "String", example = "{\"id\":\"1\"}") - @PostMapping(value = "/delete") - public Result delete(@ApiIgnore @RequestBody HashMap map) { - safetyHatDataService.delete(MapUtils.getString(map, "id")); - return Result.ok(); - } + /** + * 通过id删除 + * + * @return + */ + @ApiOperation(value = "删除智能安全帽-实时数据信息", notes = "删除智能安全帽-实时数据信息", httpMethod = "POST") + @ApiImplicitParam(name = "id", value = "智能安全帽-实时数据ID", paramType = "body", required = true, dataType = "String", example = "{\"id\":\"1\"}") + @PostMapping(value = "/delete") + public Result delete(@ApiIgnore @RequestBody HashMap map) { + safetyHatDataService.delete(MapUtils.getString(map, "id")); + return Result.ok(); + } - /** - * 通过id查询 - * - * @param id - * @return - */ - @ApiOperation(value = "通过id查询智能安全帽-实时数据信息", notes = "通过id查询智能安全帽-实时数据信息", httpMethod = "GET") - @ApiImplicitParam(name = "id", value = "智能安全帽-实时数据ID", paramType = "query", required = true, dataType = "Integer") - @GetMapping(value = "/queryById") - public Result queryById(@RequestParam(name = "id", required = true) String id) { - Result result = new Result(); - SafetyHatData safetyHatData = safetyHatDataService.getById(id); - if (safetyHatData == null) { - result.error500("未找到对应实体"); - } else { - result.setResult(safetyHatData); - result.setSuccess(true); - } - return result; - } + /** + * 通过id查询 + * + * @param id + * @return + */ + @ApiOperation(value = "通过id查询智能安全帽-实时数据信息", notes = "通过id查询智能安全帽-实时数据信息", httpMethod = "GET") + @ApiImplicitParam(name = "id", value = "智能安全帽-实时数据ID", paramType = "query", required = true, dataType = "Integer") + @GetMapping(value = "/queryById") + public Result queryById(@RequestParam(name = "id", required = true) String id) { + Result result = new Result(); + SafetyHatData safetyHatData = safetyHatDataService.getById(id); + if (safetyHatData == null) { + result.error500("未找到对应实体"); + } else { + result.setResult(safetyHatData); + result.setSuccess(true); + } + return result; + } + + /** + * 暂时没有使用 + * + * @param paramMap + * @return + */ + @ApiOperation(value = "获取每个设备最新一条实时数据信息", notes = "获取每个设备最新一条实时数据信息", httpMethod = "POST") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = true, dataType = "String"), + @ApiImplicitParam(name = "devSns", value = "设备sns(不传查全部)", paramType = "query", required = false, dataType = "String"), + }) + @PostMapping(value = "/getNewestList") + public Result> getNewestList(@ApiIgnore @RequestBody HashMap paramMap) { + return Result.success(safetyHatDataService.getNewestList(paramMap)); + } } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/SafetyHatDataMapper.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/SafetyHatDataMapper.java index 16378762b..a736a8c7d 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/SafetyHatDataMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/SafetyHatDataMapper.java @@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.Mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import java.util.HashMap; import java.util.List; /** @@ -25,4 +26,6 @@ public interface SafetyHatDataMapper extends BaseMapper { List queryList(@Param(Constants.WRAPPER) QueryWrapper queryWrapper); List getNewestData(String projectSn); + + List getNewestList(HashMap paramMap); } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatAlarmMapper.xml b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatAlarmMapper.xml index fbaafa3cc..8dbc76dd0 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatAlarmMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatAlarmMapper.xml @@ -15,6 +15,7 @@ from safety_hat_alarm where project_sn = #{projectSn} and alarm_time > date_sub(now(), interval 8 day) + and alarm_type is not null group by alarm_type, date_format(alarm_time, '%Y-%m-%d') diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatDataMapper.xml b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatDataMapper.xml index 14203f40b..c0b402dfe 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatDataMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatDataMapper.xml @@ -17,4 +17,21 @@ group by dev_sn) t on t.create_time = shd.create_time and t.dev_sn=shd.dev_sn group by shd.dev_sn + + diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/ISafetyHatDataService.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/ISafetyHatDataService.java index b1cc9e0cc..c9ab89439 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/ISafetyHatDataService.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/ISafetyHatDataService.java @@ -24,4 +24,6 @@ public interface ISafetyHatDataService extends IService { void edit(SafetyHatData safetyHatData); void delete(String id); + + List getNewestList(HashMap paramMap); } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java index 3f3d9b977..8db353df9 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java @@ -1,5 +1,6 @@ package com.zhgd.xmgl.modules.safetyhat.service.impl; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -7,13 +8,19 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.zhgd.jeecg.common.execption.OpenAlertException; import com.zhgd.jeecg.common.system.query.QueryGenerator; +import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev; +import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatFence; +import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatAlarmMapper; import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataMapper; import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper; +import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatFenceMapper; +import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; import com.zhgd.xmgl.util.PageUtil; import com.zhgd.xmgl.util.RefUtil; +import com.zhgd.xmgl.util.RegionUtil; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Objects; /** * @Description: 智能安全帽-实时数据 @@ -37,6 +45,12 @@ public class SafetyHatDataServiceImpl extends ServiceImpl queryPageList(HashMap paramMap) { @@ -84,6 +98,43 @@ public class SafetyHatDataServiceImpl extends ServiceImpl fenceList = safetyHatFenceMapper.selectList(new LambdaQueryWrapper() + .eq(SafetyHatFence::getProjectSn, dev.getProjectSn())); + boolean inFence = false; + for (SafetyHatFence fence : fenceList) { + //判断是否在围栏范围内 + if (Objects.equals(fence.getRangeType(), 1)) { + inFence = RegionUtil.isInCircle(safetyHatData.getLongitude(), safetyHatData.getLatitude(), fence.getLongitude(), fence.getLatitude(), fence.getAreaRadius()); + } else if (Objects.equals(fence.getRangeType(), 2)) { + String fenceShape = fence.getFenceShape(); + if (StrUtil.isNotBlank(fenceShape)) { + String[] couples = StringUtils.split(fenceShape, ","); + Double[] lon = new Double[couples.length]; + Double[] lat = new Double[couples.length]; + for (int i = 0; i < couples.length; i++) { + String couple = couples[i]; + String[] two = StringUtils.split(couple, "|"); + lon[i] = Double.valueOf(two[0]); + lat[i] = Double.valueOf(two[1]); + } + inFence = RegionUtil.isInPolygon(safetyHatData.getLongitude(), safetyHatData.getLatitude(), lon, lat); + } + } + if (inFence) { + break; + } + } + if (!inFence) { + SafetyHatAlarm alarm = new SafetyHatAlarm(); + alarm.setDevSn(dev.getDevSn()); + alarm.setAlarmTime(new Date()); + alarm.setAlarmType(2); + alarm.setLatitude(safetyHatData.getLatitude()); + alarm.setLongitude(safetyHatData.getLongitude()); + safetyHatAlarmService.add(alarm); + } } @Override @@ -100,5 +151,10 @@ public class SafetyHatDataServiceImpl extends ServiceImpl getNewestList(HashMap paramMap) { + return baseMapper.getNewestList(paramMap); + } + } diff --git a/src/main/java/com/zhgd/xmgl/task/ProjectTask.java b/src/main/java/com/zhgd/xmgl/task/ProjectTask.java index 3faf1ab9e..46fc5284a 100644 --- a/src/main/java/com/zhgd/xmgl/task/ProjectTask.java +++ b/src/main/java/com/zhgd/xmgl/task/ProjectTask.java @@ -152,6 +152,7 @@ public class ProjectTask { @RequestMapping("getMonthAttendanceStatistics") public void getMonthAttendanceStatistics() { try { + log.info("定时统计前一天的考勤状况"); SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd"); //计算前一天的考勤状况 Date date = DateUtils.addDays(new Date(), -1);