| | |
| | | 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.BeanUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.sxkj.fw.area.dto.FwAreaDivideDTO; |
| | | import org.sxkj.fw.area.dto.FwAreaDivideSubmitDTO; |
| | | import org.sxkj.fw.area.dto.FwAreaDivideStatisticsDTO; |
| | | import org.sxkj.fw.area.entity.FwAreaDivideEntity; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideVO; |
| | |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | import java.util.Map; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | |
| | | |
| | | /** |
| | | * 区域划分表 新增或修改 |
| | | * 说明:入参包含主表对象与扩展面列表;保存主表成功后批量写入扩展面数据 |
| | | */ |
| | | @PostMapping("/submit") |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperation(value = "新增或修改", notes = "传入fwAreaDivide") |
| | | public R submit(@Valid @RequestBody FwAreaDivideDTO fwAreaDivide) { |
| | | FwAreaDivideEntity fwAreaDivideEntity = Objects.requireNonNull(BeanUtil.copy(fwAreaDivide, FwAreaDivideEntity.class)); |
| | | @ApiOperation(value = "新增或修改", notes = "传入主表对象与扩展面列表") |
| | | public R submit(@Valid @RequestBody FwAreaDivideSubmitDTO fwAreaDivideSubmit) { |
| | | if (fwAreaDivideSubmit == null || fwAreaDivideSubmit.getAreaDivide() == null) { |
| | | return R.fail("区域信息不能为空"); |
| | | } |
| | | FwAreaDivideEntity fwAreaDivideEntity = fwAreaDivideSubmit.getAreaDivide(); |
| | | // if (isGeomInvalid(fwAreaDivideEntity.getGeom())) { |
| | | // return R.fail("几何数据格式不正确"); |
| | | // } |
| | | return R.status(fwAreaDivideService.saveOrUpdate(fwAreaDivideEntity)); |
| | | return R.status(fwAreaDivideService.saveOrUpdateWithExt(fwAreaDivideEntity, fwAreaDivideSubmit.getAreaDivideExtList())); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | List<FwAreaDivideExtExcel> exportFwAreaDivideExt(@Param("ew") Wrapper<FwAreaDivideExtEntity> queryWrapper); |
| | | |
| | | /** |
| | | * 批量新增(geom 文本转 geometry) |
| | | * |
| | | * @param fwAreaDivideExtList |
| | | * @return |
| | | */ |
| | | int insertBatchWithGeom(@Param("list") List<FwAreaDivideExtEntity> fwAreaDivideExtList); |
| | | |
| | | } |
| | |
| | | SELECT * FROM ja_fw_area_divide_ext ${ew.customSqlSegment} |
| | | </select> |
| | | |
| | | <insert id="insertBatchWithGeom"> |
| | | insert into ja_fw_area_divide_ext ( |
| | | area_divide_id, |
| | | area_type_key, |
| | | area_type_value, |
| | | geom, |
| | | area_code, |
| | | create_user, |
| | | create_dept, |
| | | create_time, |
| | | update_user, |
| | | update_time, |
| | | status, |
| | | is_deleted |
| | | ) values |
| | | <foreach collection="list" item="item" separator=","> |
| | | ( |
| | | #{item.areaDivideId}, |
| | | #{item.areaTypeKey}, |
| | | #{item.areaTypeValue}, |
| | | <choose> |
| | | <when test="item.geom != null and item.geom != ''"> |
| | | case |
| | | when instr(#{item.geom}, '|') > 0 then ST_SRID( |
| | | ST_GeomFromText(trim(substring_index(#{item.geom}, '|', 1))), |
| | | cast(trim(substring_index(#{item.geom}, '|', -1)) as unsigned) |
| | | ) |
| | | else ST_GeomFromText(trim(#{item.geom})) |
| | | end |
| | | </when> |
| | | <otherwise>null</otherwise> |
| | | </choose>, |
| | | #{item.areaCode}, |
| | | #{item.createUser}, |
| | | #{item.createDept}, |
| | | #{item.createTime}, |
| | | #{item.updateUser}, |
| | | #{item.updateTime}, |
| | | IFNULL(#{item.status}, '0'), |
| | | IFNULL(#{item.isDeleted}, 0) |
| | | ) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <result column="fly_date_start" property="flyDateStart"/> |
| | | <result column="fly_date_end" property="flyDateEnd"/> |
| | | <result column="area_code" property="areaCode"/> |
| | | <result column="police_station_name" property="policeStationName"/> |
| | | <result column="police_station_contact_person" property="policeStationContactPerson"/> |
| | | <result column="police_station_contact_phone" property="policeStationContactPhone"/> |
| | | <result column="create_user" property="createUser"/> |
| | | <result column="create_dept" property="createDept"/> |
| | | <result column="create_time" property="createTime"/> |
| | | <result column="update_user" property="updateUser"/> |
| | | <result column="update_time" property="updateTime"/> |
| | | <result column="status" property="status"/> |
| | | </resultMap> |
| | | |
| | | <resultMap id="fwAreaDivideStatisticsResultMap" type="org.sxkj.fw.area.vo.FwAreaDivideStatisticsVO"> |
| | | <result column="id" property="id"/> |
| | | <result column="area_name" property="areaName"/> |
| | | <result column="area_type" property="areaType"/> |
| | | <result column="scene_name" property="sceneName"/> |
| | | <result column="scene_type" property="sceneType"/> |
| | | <result column="device_count" property="deviceCount"/> |
| | |
| | | |
| | | <select id="selectFwAreaDividePage" resultMap="fwAreaDivideResultMap"> |
| | | select |
| | | ad.* |
| | | ad.id, |
| | | ad.area_name, |
| | | ad.trigger_condition, |
| | | ad.response_mechanism, |
| | | ad.control_level, |
| | | ad.police_station_id, |
| | | ad.device_ids, |
| | | ad.fly_date_start, |
| | | ad.fly_date_end, |
| | | ad.area_code, |
| | | ps.station_name as police_station_name, |
| | | ad.create_user, |
| | | ad.create_dept, |
| | | ad.create_time, |
| | | ad.update_user, |
| | | ad.update_time, |
| | | ad.status, |
| | | ad.is_deleted |
| | | from |
| | | ja_fw_area_divide ad |
| | | left join |
| | |
| | | </if> |
| | | <if test="param2.areaName != null and param2.areaName != ''"> |
| | | and ad.area_name like concat('%', #{param2.areaName}, '%') |
| | | </if> |
| | | <if test="param2.longitude != null and param2.longitude != ''"> |
| | | and ad.longitude = #{param2.longitude} |
| | | </if> |
| | | <if test="param2.latitude != null and param2.latitude != ''"> |
| | | and ad.latitude = #{param2.latitude} |
| | | </if> |
| | | <if test="param2.areaSize != null and param2.areaSize != ''"> |
| | | and ad.area_size = #{param2.areaSize} |
| | | </if> |
| | | <if test="param2.areaType != null and param2.areaType != ''"> |
| | | and ad.area_type = #{param2.areaType} |
| | | </if> |
| | | <if test="param2.triggerCondition != null and param2.triggerCondition != ''"> |
| | | and ad.trigger_condition = #{param2.triggerCondition} |
| | |
| | | |
| | | <select id="selectFwAreaDivideList" resultMap="fwAreaDivideResultMap"> |
| | | select |
| | | ad.* |
| | | ad.id, |
| | | ad.area_name, |
| | | ad.trigger_condition, |
| | | ad.response_mechanism, |
| | | ad.control_level, |
| | | ad.police_station_id, |
| | | ad.device_ids, |
| | | ad.fly_date_start, |
| | | ad.fly_date_end, |
| | | ad.area_code, |
| | | ps.station_name as police_station_name, |
| | | ad.create_user, |
| | | ad.create_dept, |
| | | ad.create_time, |
| | | ad.update_user, |
| | | ad.update_time, |
| | | ad.status, |
| | | ad.is_deleted |
| | | from ja_fw_area_divide ad |
| | | left join ja_fw_police_station ps on ps.id = ad.police_station_id and ps.is_deleted = 0 |
| | | <where> |
| | |
| | | select |
| | | ad.id, |
| | | ad.area_name, |
| | | ad.longitude, |
| | | ad.latitude, |
| | | ad.area_size, |
| | | case |
| | | when ad.geom is null then null |
| | | when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom) |
| | | else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom)) |
| | | end as geom, |
| | | ad.area_type, |
| | | ad.trigger_condition, |
| | | ad.response_mechanism, |
| | | ad.control_level, |
| | |
| | | select |
| | | stats.id, |
| | | stats.area_name, |
| | | stats.area_type, |
| | | stats.scene_name, |
| | | stats.scene_type, |
| | | stats.device_count, |
| | |
| | | select |
| | | ad.id, |
| | | ad.area_name, |
| | | ad.area_type, |
| | | ( |
| | | select group_concat(distinct ds.scene_name) |
| | | from ja_fw_defense_scene ds |
| | |
| | | <if test="param2.areaName != null and param2.areaName != ''"> |
| | | and ad.area_name like concat('%', #{param2.areaName}, '%') |
| | | </if> |
| | | <if test="param2.areaType != null and param2.areaType != ''"> |
| | | and ad.area_type = #{param2.areaType} |
| | | </if> |
| | | <if test="param2.sceneType != null and param2.sceneType != ''"> |
| | | and exists ( |
| | | select 1 |
| | |
| | | select |
| | | stats.id, |
| | | stats.area_name, |
| | | stats.area_type, |
| | | stats.scene_name, |
| | | stats.scene_type, |
| | | stats.device_count, |
| | |
| | | else '差' |
| | | end as control_effect |
| | | from ( |
| | | select |
| | | ad.id, |
| | | ad.area_name, |
| | | ad.area_type, |
| | | ( |
| | | select group_concat(distinct ds.scene_name) |
| | | from ja_fw_defense_scene ds |
| | | select |
| | | ad.id, |
| | | ad.area_name, |
| | | ( |
| | | select group_concat(distinct ds.scene_name) |
| | | from ja_fw_defense_scene ds |
| | | where ds.is_deleted = 0 |
| | | and find_in_set(ad.id, ds.area_divide_ids) |
| | | ) as scene_name, |
| | |
| | | SELECT |
| | | id, |
| | | area_name, |
| | | longitude, |
| | | latitude, |
| | | area_size, |
| | | concat(ST_AsText(geom), ' | ', ST_SRID(geom)) as geom, |
| | | area_type, |
| | | trigger_condition, |
| | | response_mechanism, |
| | | control_level, |
| | |
| | | insert into ja_fw_area_divide ( |
| | | id, |
| | | area_name, |
| | | longitude, |
| | | latitude, |
| | | area_size, |
| | | geom, |
| | | area_type, |
| | | trigger_condition, |
| | | response_mechanism, |
| | | control_level, |
| | |
| | | ) values ( |
| | | #{id}, |
| | | #{areaName}, |
| | | #{longitude}, |
| | | #{latitude}, |
| | | #{areaSize}, |
| | | <choose> |
| | | <when test="geom != null and geom != ''"> |
| | | case |
| | | when instr(#{geom}, '|') > 0 then ST_GeomFromText( |
| | | trim(substring_index(#{geom}, '|', 1)), |
| | | cast(trim(substring_index(#{geom}, '|', -1)) as unsigned) |
| | | ) |
| | | else ST_GeomFromText(trim(#{geom})) |
| | | end |
| | | </when> |
| | | <otherwise>null</otherwise> |
| | | </choose>, |
| | | #{areaType}, |
| | | #{triggerCondition}, |
| | | #{responseMechanism}, |
| | | #{controlLevel}, |
| | |
| | | update ja_fw_area_divide |
| | | <set> |
| | | <if test="areaName != null">area_name = #{areaName},</if> |
| | | <if test="longitude != null">longitude = #{longitude},</if> |
| | | <if test="latitude != null">latitude = #{latitude},</if> |
| | | <if test="areaSize != null">area_size = #{areaSize},</if> |
| | | <if test="geom != null and geom != ''"> |
| | | geom = case |
| | | when instr(#{geom}, '|') > 0 then ST_GeomFromText( |
| | | trim(substring_index(#{geom}, '|', 1)), |
| | | cast(trim(substring_index(#{geom}, '|', -1)) as unsigned) |
| | | ) |
| | | else ST_GeomFromText(trim(#{geom})) |
| | | end, |
| | | </if> |
| | | <if test="areaType != null">area_type = #{areaType},</if> |
| | | <if test="triggerCondition != null">trigger_condition = #{triggerCondition},</if> |
| | | <if test="responseMechanism != null">response_mechanism = #{responseMechanism},</if> |
| | | <if test="controlLevel != null">control_level = #{controlLevel},</if> |
| | |
| | | */ |
| | | List<FwAreaDivideExtExcel> exportFwAreaDivideExt(Wrapper<FwAreaDivideExtEntity> queryWrapper); |
| | | |
| | | /** |
| | | * 批量新增(geom 文本转 geometry) |
| | | * |
| | | * @param fwAreaDivideExtList |
| | | * @return |
| | | */ |
| | | boolean saveBatchWithGeom(List<FwAreaDivideExtEntity> fwAreaDivideExtList); |
| | | |
| | | } |
| | |
| | | import org.sxkj.fw.area.dto.FwAreaDivideDTO; |
| | | import org.sxkj.fw.area.dto.FwAreaDivideStatisticsDTO; |
| | | import org.sxkj.fw.area.entity.FwAreaDivideEntity; |
| | | import org.sxkj.fw.area.entity.FwAreaDivideExtEntity; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideVO; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideStatisticsVO; |
| | | import org.sxkj.fw.area.excel.FwAreaDivideExcel; |
| | |
| | | */ |
| | | List<FwAreaDivideExcel> exportFwAreaDivide(Wrapper<FwAreaDivideEntity> queryWrapper); |
| | | |
| | | /** |
| | | * 新增或修改(主表 + 扩展表批量) |
| | | * |
| | | * @param fwAreaDivide |
| | | * @param fwAreaDivideExtList |
| | | * @return |
| | | */ |
| | | boolean saveOrUpdateWithExt(FwAreaDivideEntity fwAreaDivide, List<FwAreaDivideExtEntity> fwAreaDivideExtList); |
| | | |
| | | } |
| | |
| | | return fwAreaDivideExtList; |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveBatchWithGeom(List<FwAreaDivideExtEntity> fwAreaDivideExtList) { |
| | | if (fwAreaDivideExtList == null || fwAreaDivideExtList.isEmpty()) { |
| | | return true; |
| | | } |
| | | return baseMapper.insertBatchWithGeom(fwAreaDivideExtList) > 0; |
| | | } |
| | | |
| | | } |
| | |
| | | import org.sxkj.fw.area.dto.FwAreaDivideDTO; |
| | | import org.sxkj.fw.area.dto.FwAreaDivideStatisticsDTO; |
| | | import org.sxkj.fw.area.entity.FwAreaDivideEntity; |
| | | import org.sxkj.fw.area.entity.FwAreaDivideExtEntity; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideVO; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideStatisticsVO; |
| | | import org.sxkj.fw.area.vo.FwDefenseSceneVO; |
| | | import org.sxkj.fw.area.excel.FwAreaDivideExcel; |
| | | import org.sxkj.fw.area.mapper.FwAreaDivideMapper; |
| | | import org.sxkj.fw.area.service.IFwAreaDivideService; |
| | | import org.sxkj.fw.area.service.IFwAreaDivideExtService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import lombok.AllArgsConstructor; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | |
| | | * @since 2026-01-07 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class FwAreaDivideServiceImpl extends BaseServiceImpl<FwAreaDivideMapper, FwAreaDivideEntity> |
| | | implements IFwAreaDivideService { |
| | | |
| | | private final IFwAreaDivideExtService fwAreaDivideExtService; |
| | | |
| | | @Override |
| | | public IPage<FwAreaDivideVO> selectFwAreaDividePage(IPage<FwAreaDivideVO> page, FwAreaDivideDTO fwAreaDivide) { |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveOrUpdateWithExt(FwAreaDivideEntity fwAreaDivide, List<FwAreaDivideExtEntity> fwAreaDivideExtList) { |
| | | // 主表与扩展面数据保持同一事务,扩展面列表为空时仅保存主表 |
| | | if (fwAreaDivide == null) { |
| | | return false; |
| | | } |
| | | boolean isCreate = fwAreaDivide.getId() == null; |
| | | boolean mainResult = saveOrUpdate(fwAreaDivide); |
| | | if (!mainResult) { |
| | | return false; |
| | | } |
| | | if (fwAreaDivideExtList == null || fwAreaDivideExtList.isEmpty()) { |
| | | return true; |
| | | } |
| | | List<FwAreaDivideExtEntity> extList = new ArrayList<>(); |
| | | for (FwAreaDivideExtEntity ext : fwAreaDivideExtList) { |
| | | if (ext == null) { |
| | | continue; |
| | | } |
| | | ext.setAreaDivideId(fwAreaDivide.getId()); |
| | | if (StringUtil.isBlank(ext.getAreaCode()) && StringUtil.isNotBlank(fwAreaDivide.getAreaCode())) { |
| | | ext.setAreaCode(fwAreaDivide.getAreaCode()); |
| | | } |
| | | fillCreateFieldsExt(ext); |
| | | extList.add(ext); |
| | | } |
| | | if (extList.isEmpty()) { |
| | | return true; |
| | | } |
| | | if (!isCreate) { |
| | | // 更新时先清理该主表下历史扩展面数据,再整体写入 |
| | | QueryWrapper<FwAreaDivideExtEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda().eq(FwAreaDivideExtEntity::getAreaDivideId, fwAreaDivide.getId()); |
| | | fwAreaDivideExtService.remove(wrapper); |
| | | } |
| | | if (!fwAreaDivideExtService.saveBatchWithGeom(extList)) { |
| | | throw new RuntimeException("保存区域扩展面数据失败"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private void fillCreateFields(FwAreaDivideEntity fwAreaDivide) { |
| | | Long userId = AuthUtil.getUserId(); |
| | | String deptIdStr = AuthUtil.getDeptId(); |
| | |
| | | fwAreaDivide.setUpdateTime(new Date()); |
| | | } |
| | | |
| | | private void fillCreateFieldsExt(FwAreaDivideExtEntity fwAreaDivideExt) { |
| | | Long userId = AuthUtil.getUserId(); |
| | | String deptIdStr = AuthUtil.getDeptId(); |
| | | Long deptId = null; |
| | | if (StringUtil.isNotBlank(deptIdStr)) { |
| | | try { |
| | | deptId = Long.valueOf(deptIdStr); |
| | | } catch (NumberFormatException ignored) { |
| | | deptId = null; |
| | | } |
| | | } |
| | | Date now = new Date(); |
| | | if (fwAreaDivideExt.getCreateUser() == null) { |
| | | fwAreaDivideExt.setCreateUser(userId); |
| | | } |
| | | if (fwAreaDivideExt.getUpdateUser() == null) { |
| | | fwAreaDivideExt.setUpdateUser(userId); |
| | | } |
| | | if (fwAreaDivideExt.getCreateDept() == null && deptId != null) { |
| | | fwAreaDivideExt.setCreateDept(deptId); |
| | | } |
| | | if (fwAreaDivideExt.getCreateTime() == null) { |
| | | fwAreaDivideExt.setCreateTime(now); |
| | | } |
| | | if (fwAreaDivideExt.getUpdateTime() == null) { |
| | | fwAreaDivideExt.setUpdateTime(now); |
| | | } |
| | | } |
| | | |
| | | private List<Long> parseIdList(String ids) { |
| | | if (StringUtil.isBlank(ids)) { |
| | | return new ArrayList<>(); |