linwe
2024-09-03 764d883b5ea3bdc06abbec548b6df0511e567978
src/main/java/org/springblade/modules/police/service/impl/PoliceAlarmRecordsServiceImpl.java
New file
@@ -0,0 +1,81 @@
/*
 *      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.modules.police.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.common.param.CommonParamSet;
import org.springblade.common.utils.AuthUtils;
import org.springblade.common.utils.SpringUtils;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.grid.entity.GridEntity;
import org.springblade.modules.grid.service.IGridService;
import org.springblade.modules.police.entity.PoliceAffairsGridEntity;
import org.springblade.modules.police.entity.PoliceAlarmRecordsEntity;
import org.springblade.modules.police.service.IPoliceAffairsGridService;
import org.springblade.modules.police.vo.PoliceAlarmRecordsVO;
import org.springblade.modules.police.mapper.PoliceAlarmRecordsMapper;
import org.springblade.modules.police.service.IPoliceAlarmRecordsService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
/**
 * 报警记录 服务实现类
 *
 * @author BladeX
 * @since 2024-03-13
 */
@Service
public class PoliceAlarmRecordsServiceImpl extends ServiceImpl<PoliceAlarmRecordsMapper, PoliceAlarmRecordsEntity> implements IPoliceAlarmRecordsService {
   @Override
   public IPage<PoliceAlarmRecordsVO> selectPoliceAlarmRecordsPage(IPage<PoliceAlarmRecordsVO> page, PoliceAlarmRecordsVO policeAlarmRecords) {
      policeAlarmRecords.setPoliceId(AuthUtil.getUserId());
      CommonParamSet commonParamSet = new CommonParamSet<>().invoke(PoliceAlarmRecordsVO.class, policeAlarmRecords);
      return page.setRecords(baseMapper.selectPoliceAlarmRecordsPage(page, policeAlarmRecords,
         commonParamSet.getIsAdministrator(),
         commonParamSet.getRegionChildCodesList(),
         commonParamSet.getGridCodeList()
         ));
   }
   /**
    * 报警记录 新增
    */
   @Override
   public boolean savePoliceAlarmRecordsEntity(PoliceAlarmRecordsEntity policeAlarmRecords) {
      // 根据位置设置网格,警格编号
      IGridService gridService = SpringUtils.getBean(IGridService.class);
      IPoliceAffairsGridService policeAffairsGridService = SpringUtils.getBean(IPoliceAffairsGridService.class);
      String point = "'POINT(" + policeAlarmRecords.getLongitude() + " " + policeAlarmRecords.getLatitude() + ")'";
      //点坐标解析网格
      List<GridEntity> gridEntityList = gridService.spatialAnalysis(point);
      if (gridEntityList.size()>0){
         GridEntity gridEntity = gridEntityList.get(0);
         policeAlarmRecords.setGridCode(gridEntity.getGridCode());
      }
      //点坐标解析警格
      List<PoliceAffairsGridEntity> policeAffairsGridEntityList = policeAffairsGridService.spatialAnalysis(point);
      if (policeAffairsGridEntityList.size()>0){
         PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridEntityList.get(0);
         policeAlarmRecords.setJwGridCode(policeAffairsGridEntity.getJwGridCode());
      }
      // 插入
      return save(policeAlarmRecords);
   }
}