drone-service/drone-fw/src/main/java/org/sxkj/fw/area/service/impl/FwDefenseZoneServiceImpl.java
@@ -21,11 +21,13 @@ import org.sxkj.common.utils.HeaderUtils; import org.sxkj.fw.area.dto.FwDefenseZoneDTO; import org.sxkj.fw.area.entity.FwAreaDivideEntity; import org.sxkj.fw.area.entity.FwDefenseSceneEntity; import org.sxkj.fw.area.entity.FwDefenseZoneEntity; import org.sxkj.fw.area.vo.FwDefenseZoneVO; import org.sxkj.fw.area.excel.FwDefenseZoneExcel; import org.sxkj.fw.area.mapper.FwDefenseZoneMapper; import org.sxkj.fw.area.service.IFwAreaDivideService; import org.sxkj.fw.area.service.IFwDefenseSceneService; import org.sxkj.fw.area.service.IFwDefenseZoneService; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.Wrapper; @@ -53,6 +55,9 @@ @Resource private IFwAreaDivideService fwAreaDivideService; @Resource private IFwDefenseSceneService fwDefenseSceneService; @Override public IPage<FwDefenseZoneVO> selectFwDefenseZonePage(IPage<FwDefenseZoneVO> page, FwDefenseZoneDTO fwDefenseZone) { IPage<FwDefenseZoneVO> result = page.setRecords(baseMapper.selectFwDefenseZonePage(page, fwDefenseZone)); @@ -74,22 +79,28 @@ return; } Set<Long> sceneIdSet = new HashSet<>(); Set<Long> areaIdSet = new HashSet<>(); Map<Long, List<Long>> zoneSceneMap = new HashMap<>(); Map<Long, List<Long>> zoneAreaMap = new HashMap<>(); for (FwDefenseZoneVO record : records) { List<Long> sceneIds = parseIdList(record.getDefenseSceneIds()); if (record.getId() != null) { zoneSceneMap.put(record.getId(), sceneIds); } sceneIdSet.addAll(sceneIds); List<Long> areaIds = parseIdList(record.getAreaDivideIds()); if (record.getId() != null) { zoneAreaMap.put(record.getId(), areaIds); } areaIdSet.addAll(areaIds); } if (sceneIdSet.isEmpty() && areaIdSet.isEmpty()) { Map<Long, List<Long>> sceneAreaMap = new HashMap<>(); Set<Long> sceneAreaIdSet = new HashSet<>(); if (!sceneIdSet.isEmpty()) { List<FwDefenseSceneEntity> sceneList = fwDefenseSceneService.listByIds(sceneIdSet); for (FwDefenseSceneEntity scene : sceneList) { if (scene == null || scene.getId() == null) { continue; } List<Long> sceneAreaIds = parseIdList(scene.getAreaDivideIds()); sceneAreaMap.put(scene.getId(), sceneAreaIds); sceneAreaIdSet.addAll(sceneAreaIds); } } if (sceneIdSet.isEmpty()) { for (FwDefenseZoneVO record : records) { record.setSceneCount(0); record.setDeviceCount(0); @@ -98,8 +109,8 @@ return; } Map<Long, List<Long>> areaDeviceMap = new HashMap<>(); if (!areaIdSet.isEmpty()) { List<FwAreaDivideEntity> areaList = fwAreaDivideService.listByIds(areaIdSet); if (!sceneAreaIdSet.isEmpty()) { List<FwAreaDivideEntity> areaList = fwAreaDivideService.listByIds(sceneAreaIdSet); for (FwAreaDivideEntity area : areaList) { if (area == null || area.getId() == null) { continue; @@ -115,19 +126,21 @@ } Set<Long> uniqueSceneIds = new HashSet<>(sceneIds); record.setSceneCount(uniqueSceneIds.size()); List<Long> zoneAreaIds = zoneAreaMap.get(record.getId()); if (zoneAreaIds == null) { zoneAreaIds = Collections.emptyList(); Set<Long> sceneAreaIds = new HashSet<>(); for (Long sceneId : uniqueSceneIds) { List<Long> areaIds = sceneAreaMap.get(sceneId); if (areaIds != null) { sceneAreaIds.addAll(areaIds); } } Set<Long> areaIds = new HashSet<>(zoneAreaIds); Set<Long> deviceIds = new HashSet<>(); for (Long areaId : areaIds) { for (Long areaId : sceneAreaIds) { List<Long> areaDeviceIds = areaDeviceMap.get(areaId); if (areaDeviceIds != null) { deviceIds.addAll(areaDeviceIds); } } record.setAreaCount(areaIds.size()); record.setAreaCount(sceneAreaIds.size()); record.setDeviceCount(deviceIds.size()); } } drone-service/drone-fw/src/main/java/org/sxkj/fw/detection/controller/FwDeviceConfigController.java
@@ -64,9 +64,18 @@ */ @GetMapping("/detail") @ApiOperationSupport(order = 1) @ApiOperation(value = "详情", notes = "传入fwDeviceConfig") public R<FwDeviceConfigVO> detail(FwDeviceConfigEntity fwDeviceConfig) { FwDeviceConfigEntity detail = fwDeviceConfigService.getOne(Condition.getQueryWrapper(fwDeviceConfig)); @ApiOperation(value = "详情", notes = "传入deviceId") public R<FwDeviceConfigVO> detail(@ApiParam(value = "设备id", required = true) @RequestParam Long deviceId) { if (deviceId == null) { return R.fail("设备id不能为空"); } FwDeviceConfigEntity detail = fwDeviceConfigService.selectLatestByDeviceId(deviceId); if (detail == null) { detail = fwDeviceConfigService.selectLatestVersionByDeviceId(deviceId); } if (detail == null) { return R.fail("数据不存在"); } return R.data(FwDeviceConfigWrapper.build().entityVO(detail)); } /** @@ -90,26 +99,26 @@ IPage<FwDeviceConfigVO> pages = fwDeviceConfigService.selectFwDeviceConfigPage(Condition.getPage(query), fwDeviceConfig); return R.data(pages); } /** * 设备配置表 新增 */ @PostMapping("/save") @ApiOperationSupport(order = 4) @ApiOperation(value = "新增", notes = "传入fwDeviceConfig") public R save(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { return R.status(fwDeviceConfigService.save(fwDeviceConfig)); } /** * 设备配置表 修改 */ @PostMapping("/update") @ApiOperationSupport(order = 5) @ApiOperation(value = "修改", notes = "传入fwDeviceConfig") public R update(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { return R.status(fwDeviceConfigService.updateById(fwDeviceConfig)); } // // /** // * 设备配置表 新增 // */ // @PostMapping("/save") // @ApiOperationSupport(order = 4) // @ApiOperation(value = "新增", notes = "传入fwDeviceConfig") // public R save(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { // return saveOrUpdateConfig(fwDeviceConfig); // } // // /** // * 设备配置表 修改 // */ // @PostMapping("/update") // @ApiOperationSupport(order = 5) // @ApiOperation(value = "修改", notes = "传入fwDeviceConfig") // public R update(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { // return saveOrUpdateConfig(fwDeviceConfig); // } /** * 设备配置表 新增或修改 @@ -118,7 +127,7 @@ @ApiOperationSupport(order = 6) @ApiOperation(value = "新增或修改", notes = "传入fwDeviceConfig") public R submit(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { return R.status(fwDeviceConfigService.saveOrUpdate(fwDeviceConfig)); return saveOrUpdateConfig(fwDeviceConfig); } /** @@ -148,4 +157,36 @@ ExcelUtil.export(response, "设备配置表数据" + DateUtil.time(), "设备配置表数据表", list, FwDeviceConfigExcel.class); } private R saveOrUpdateConfig(FwDeviceConfigEntity fwDeviceConfig) { if (fwDeviceConfig == null || fwDeviceConfig.getDeviceId() == null) { return R.fail("设备id不能为空"); } Long deviceId = fwDeviceConfig.getDeviceId(); FwDeviceConfigEntity existing = null; if (fwDeviceConfig.getId() != null) { existing = fwDeviceConfigService.getById(fwDeviceConfig.getId()); if (existing == null) { return R.fail("数据不存在"); } } if (existing == null) { Integer maxVersion = fwDeviceConfigService.selectMaxConfigVersion(deviceId); fwDeviceConfig.setConfigVersion(maxVersion == null ? 1 : maxVersion + 1); fwDeviceConfig.setIsLatest((byte) 1); fwDeviceConfigService.resetLatestByDeviceId(deviceId, null); return R.status(fwDeviceConfigService.save(fwDeviceConfig)); } if (fwDeviceConfig.getConfigVersion() == null) { fwDeviceConfig.setConfigVersion(existing.getConfigVersion()); } if (fwDeviceConfig.getIsLatest() == null) { fwDeviceConfig.setIsLatest(existing.getIsLatest()); } if (fwDeviceConfig.getIsLatest() != null && fwDeviceConfig.getIsLatest() == 1) { fwDeviceConfigService.resetLatestByDeviceId(deviceId, fwDeviceConfig.getId()); } return R.status(fwDeviceConfigService.updateById(fwDeviceConfig)); } } drone-service/drone-fw/src/main/java/org/sxkj/fw/detection/mapper/FwDeviceConfigMapper.java
@@ -42,6 +42,39 @@ */ List<FwDeviceConfigVO> selectFwDeviceConfigPage(IPage page, FwDeviceConfigVO fwDeviceConfig); /** * 获取最新配置 * * @param deviceId * @return */ FwDeviceConfigEntity selectLatestByDeviceId(@Param("deviceId") Long deviceId); /** * 获取最新版本配置 * * @param deviceId * @return */ FwDeviceConfigEntity selectLatestVersionByDeviceId(@Param("deviceId") Long deviceId); /** * 获取最新版本号 * * @param deviceId * @return */ Integer selectMaxConfigVersion(@Param("deviceId") Long deviceId); /** * 重置最新标记 * * @param deviceId * @param excludeId * @return */ int resetLatestByDeviceId(@Param("deviceId") Long deviceId, @Param("excludeId") Long excludeId); /** * 获取导出数据 drone-service/drone-fw/src/main/java/org/sxkj/fw/detection/mapper/FwDeviceConfigMapper.xml
@@ -66,6 +66,48 @@ </where> </select> <select id="selectLatestByDeviceId" resultMap="fwDeviceConfigResultMap"> select * from ja_fw_device_config <where> is_deleted = 0 and device_id = #{deviceId} and is_latest = 1 </where> order by config_version desc limit 1 </select> <select id="selectLatestVersionByDeviceId" resultMap="fwDeviceConfigResultMap"> select * from ja_fw_device_config <where> is_deleted = 0 and device_id = #{deviceId} </where> order by config_version desc limit 1 </select> <select id="selectMaxConfigVersion" resultType="java.lang.Integer"> select max(config_version) from ja_fw_device_config <where> is_deleted = 0 and device_id = #{deviceId} </where> </select> <update id="resetLatestByDeviceId"> update ja_fw_device_config set is_latest = 0 <where> is_deleted = 0 and device_id = #{deviceId} and is_latest = 1 <if test="excludeId != null"> and id != #{excludeId} </if> </where> </update> <select id="exportFwDeviceConfig" resultType="org.sxkj.fw.detection.excel.FwDeviceConfigExcel"> SELECT * FROM ja_fw_device_config ${ew.customSqlSegment} drone-service/drone-fw/src/main/java/org/sxkj/fw/detection/service/IFwDeviceConfigService.java
@@ -40,6 +40,39 @@ */ IPage<FwDeviceConfigVO> selectFwDeviceConfigPage(IPage<FwDeviceConfigVO> page, FwDeviceConfigVO fwDeviceConfig); /** * 获取最新配置 * * @param deviceId * @return */ FwDeviceConfigEntity selectLatestByDeviceId(Long deviceId); /** * 获取最新版本配置 * * @param deviceId * @return */ FwDeviceConfigEntity selectLatestVersionByDeviceId(Long deviceId); /** * 获取最新版本号 * * @param deviceId * @return */ Integer selectMaxConfigVersion(Long deviceId); /** * 重置最新标记 * * @param deviceId * @param excludeId * @return */ int resetLatestByDeviceId(Long deviceId, Long excludeId); /** * 导出数据 drone-service/drone-fw/src/main/java/org/sxkj/fw/detection/service/impl/FwDeviceConfigServiceImpl.java
@@ -41,6 +41,26 @@ return page.setRecords(baseMapper.selectFwDeviceConfigPage(page, fwDeviceConfig)); } @Override public FwDeviceConfigEntity selectLatestByDeviceId(Long deviceId) { return baseMapper.selectLatestByDeviceId(deviceId); } @Override public FwDeviceConfigEntity selectLatestVersionByDeviceId(Long deviceId) { return baseMapper.selectLatestVersionByDeviceId(deviceId); } @Override public Integer selectMaxConfigVersion(Long deviceId) { return baseMapper.selectMaxConfigVersion(deviceId); } @Override public int resetLatestByDeviceId(Long deviceId, Long excludeId) { return baseMapper.resetLatestByDeviceId(deviceId, excludeId); } @Override public List<FwDeviceConfigExcel> exportFwDeviceConfig(Wrapper<FwDeviceConfigEntity> queryWrapper) { drone-service/drone-fw/src/main/java/org/sxkj/fw/device/dto/FwDeviceDTO.java
@@ -42,7 +42,6 @@ * 设备名称 */ @ApiModelProperty(value = "设备名称", required = true) @NotEmpty private String deviceName; /** * 设备类型(察打一体/便捷侦测箱/反制枪) drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml
@@ -56,9 +56,10 @@ </if> <if test="param2.effectiveRangeKmIsNotNull != null and param2.effectiveRangeKmIsNotNull == 1"> and effective_range_km is not null and effective_range_km > 0 </if> <if test="param2.effectiveRangeKmIsNotNull != null and param2.effectiveRangeKmIsNotNull == 2"> and effective_range_km is null and (effective_range_km is null or effective_range_km = 0) </if> <if test="param2.manufacturer != null and param2.manufacturer != ''"> and manufacturer = #{param2.manufacturer}