linwe
2024-07-22 748fc948fff5b0034dbea1110fabf11d22573e14
src/main/java/org/springblade/modules/place/service/impl/PlaceServiceImpl.java
@@ -18,20 +18,18 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import liquibase.pro.packaged.P;
import liquibase.pro.packaged.W;
import liquibase.repackaged.org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springblade.common.cache.SysCache;
import org.springblade.common.node.TreeStringNode;
import org.springblade.common.param.CommonParamSet;
import org.springblade.common.utils.IdUtils;
import org.springblade.common.utils.SpringUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.modules.category.entity.CategoryEntity;
import org.springblade.modules.category.service.ICategoryService;
@@ -42,37 +40,27 @@
import org.springblade.modules.grid.mapper.GridMapper;
import org.springblade.modules.grid.service.IGridRangeService;
import org.springblade.modules.grid.service.IGridService;
import org.springblade.modules.grid.service.IGridmanService;
import org.springblade.modules.grid.vo.GridVO;
import org.springblade.modules.house.entity.HouseholdEntity;
import org.springblade.modules.house.entity.UserHouseLabelEntity;
import org.springblade.modules.house.service.IHouseholdService;
import org.springblade.modules.house.vo.HouseholdVO;
import org.springblade.modules.label.entity.LabelEntity;
import org.springblade.modules.partyOrganization.vo.PartyOrganizationVO;
import org.springblade.modules.place.entity.*;
import org.springblade.modules.place.excel.ExportPlaceExcel;
import org.springblade.modules.place.excel.ImportPlaceExcel;
import org.springblade.modules.place.excel.NinePlaceExcel;
import org.springblade.modules.place.excel.PlaceAndRelExcel;
import org.springblade.modules.place.excel.PlaceExcel;
import org.springblade.modules.place.mapper.PlaceMapper;
import org.springblade.modules.place.service.*;
import org.springblade.modules.place.vo.PlaceCheckVO;
import org.springblade.modules.place.vo.PlacePoiLabelVO;
import org.springblade.modules.place.vo.PlaceVO;
import org.springblade.modules.place.mapper.PlaceMapper;
import org.springblade.modules.police.entity.PoliceAffairsGridEntity;
import org.springblade.modules.police.service.IPoliceAffairsGridService;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.entity.Region;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IDictBizService;
import org.springblade.modules.system.service.IRegionService;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.task.vo.TaskLabelReportingEventVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@@ -130,6 +118,9 @@
   public IPage<PlaceVO> selectPlacePage(IPage<PlaceVO> page, PlaceVO place) {
      // 公共参数设置
      CommonParamSet commonParamSet = new CommonParamSet().invoke(PlaceVO.class, place);
      if (StringUtils.isNotBlank(place.getPoiCodes())) {
         place.setPoiCodeList(Arrays.asList(place.getPoiCodes().split(",")));
      }
      List<PlaceVO> placeVOS = baseMapper.selectPlacePage(page,
         place,
         commonParamSet.getGridCodeList(),
@@ -217,6 +208,11 @@
      jwGridCodeBind(placeVO);
      // 保存从业人员
      savePlacePractitioner(placeVO);
      // 判断是否校园
      if (placeVO.getLabel().startsWith("16010")) {
         // 校园的新增一个主体用户和一个通用用户
         addSchoolUser(placeVO);
      }
      // 返回结果
      return flag;
   }
@@ -232,7 +228,7 @@
         IPlacePractitionerService practitionerService = SpringUtil.getBean(IPlacePractitionerService.class);
         // 查询对应已存在的租户
         QueryWrapper<PlacePractitionerEntity> wrapper = new QueryWrapper<>();
         wrapper.eq("place_id", placeVO.getId()).eq("is_deleted",0);
         wrapper.eq("place_id", placeVO.getId()).eq("is_deleted", 0);
         List<PlacePractitionerEntity> oldList = practitionerService.list(wrapper);
         // 取出从业人员信息
         List<PlacePractitionerEntity> placePractitionerList = placeVO.getPlacePractitioner();
@@ -348,6 +344,18 @@
            placeVO.setIsScene(2);
         }
      }
   }
   /**
    * 房屋绑定处理
    * @param placeEntity
    */
   public void houseCodeBindHandle(PlaceEntity placeEntity) {
      PlaceVO placeVO = new PlaceVO();
      placeVO.setId(placeEntity.getId());
      placeVO.setHouseCodeBinds(placeEntity.getHouseCodeBinds());
      // 绑定
      houseCodeBindHandle(placeVO);
   }
   /**
@@ -713,6 +721,48 @@
   }
   /**
    * 新增校方主体账号和通用账号
    *
    * @param placeVO
    * @return
    */
   @Transactional(rollbackFor = Exception.class)
   public void addSchoolUser(PlaceVO placeVO) {
      User newUser = new User();
      // 查询账号是否存在,存在则不创建
      long count = userService.count(Wrappers.<User>lambdaQuery()
         .eq(User::getAccount, placeVO.getPlaceName() + "主体"));
      // 如果用户不存在,则新增一个用户
      if (StringUtils.isNotBlank(placeVO.getPlaceName()) && count <= 0) {
         newUser.setAccount(placeVO.getPlaceName() + "主体");
         newUser.setName(placeVO.getPlaceName() + "-主体");
         newUser.setRealName(placeVO.getPlaceName() + "-主体");
         // 社区群众部门
         newUser.setDeptId("1727979636479037441");
         // 校园主体,
         newUser.setRoleId("1780786647371706370");
         // 默认密码为 123456
         newUser.setPassword("123456");
         // 设置机构
         // 用户新增
         newUser.setId(null);
         boolean submit = userService.submit(newUser);
         placeVO.setPrincipalAccount(newUser.getId());
         // 校园通用
         newUser.setId(null);
         newUser.setPassword("123456");
         newUser.setRoleId("1780786746076262402");
         newUser.setAccount(placeVO.getPlaceName() + "通用");
         newUser.setName(placeVO.getPlaceName() + "-通用");
         newUser.setRealName(placeVO.getPlaceName() + "-通用");
         boolean submit2 = userService.submit(newUser);
         placeVO.setUniversalAccount(newUser.getId());
         // 更新场所信息
         updateById(placeVO);
      }
   }
   /**
    * 场所负责人和用户绑定
    *
    * @param placeVO
@@ -725,7 +775,7 @@
         placeVO.setPrincipalPhone(placeVO.getPrincipalPhone());
         //根据手机号查询库里的数据
         List<User> list = userService.getUserListByPhoneOrAccount(placeVO.getPrincipalPhone());
         if (list.size()>0) {
         if (list.size() > 0) {
            User user = list.get(0);
            //如果用户存在,则该用户id绑定场所
            placeVO.setPrincipalUserId(user.getId());
@@ -944,50 +994,60 @@
    * @param isCovered
    */
   @Override
   public void importPlace(List<PlaceExcel> data, Boolean isCovered) {
      for (PlaceExcel placeExcel : data) {
   public String importPlace(List<ImportPlaceExcel> data, Boolean isCovered) {
      int totalNum = data.size();
      int importNum = 0;
      int updateNum = 0;
      int errorNum = 0;
      for (ImportPlaceExcel placeExcel : data) {
         if (Strings.isBlank(placeExcel.getPlaceName()) || Strings.isBlank(placeExcel.getHouseCode())){
            errorNum++;
            continue;
         }
         PlaceEntity placeEntity = Objects.requireNonNull(BeanUtil.copy(placeExcel, PlaceEntity.class));
         Long userId = updateUser(placeExcel);
         // 九小场所类型处理
         if (!Strings.isBlank(placeExcel.getNineType())) {
            placeEntity.setIsNine(1);
            placeEntity.setNineType(Integer.parseInt(placeExcel.getNineType()));
         }
         // 阵地类型处理
         if (!Strings.isBlank(placeExcel.getFrontType())) {
            placeEntity.setIsFront(1);
            placeEntity.setFrontType(Integer.parseInt(placeExcel.getFrontType()));
         }
         // 无诈类别
         if (!Strings.isBlank(placeExcel.getNoExplosionCategory())){
            placeEntity.setNoExplosionCategory(Integer.parseInt(placeExcel.getNoExplosionCategory()));
         }
         // 三级单位
         if (!Strings.isBlank(placeExcel.getThreeFireProtection())){
            if (placeExcel.getThreeFireProtection().equals("是")){
               placeEntity.setThreeFireProtection(1);
            }
            if (placeExcel.getThreeFireProtection().equals("否")){
               placeEntity.setThreeFireProtection(2);
            }
         }
         String[] split = placeExcel.getHouseCode().split(",");
         placeEntity.setHouseCode(split[0]);
         placeEntity.setHouseCodeBinds(placeExcel.getHouseCode());
         placeEntity.setPrincipalUserId(userId);
         // houseCode 关联处理 来源 1:地址总表  2:国控采集 3:商超
         houseCodeHandle(placeExcel, placeEntity);
         // 网格绑定处理
         importGridHandle(placeExcel, placeEntity);
         // 判断是否存在,不存在则插入,否则不操作
         QueryWrapper<PlaceEntity> wrapper = new QueryWrapper<>();
         wrapper.eq("is_deleted", 0)
            .eq("house_code", placeExcel.getHouseCode());
         PlaceEntity one = getOne(wrapper);
         if (null == one) {
            Long userId = updateUser(placeExcel);
            // 插入场所
            PlaceVO placeEntity = new PlaceVO();
            String[] split = placeExcel.getHouseCode().split(",");
            placeEntity.setHouseCode(split[0]);
            placeEntity.setHouseCodeBinds(placeExcel.getHouseCode());
            placeEntity.setPrincipalUserId(userId);
            placeEntity.setPrincipal(placeExcel.getName());
            placeEntity.setPrincipalPhone(placeExcel.getPhoneNumber());
            placeEntity.setCreateTime(new Date());
            placeEntity.setCreateUser(AuthUtil.getUserId());
            placeEntity.setUpdateTime(new Date());
            placeEntity.setUpdateUser(AuthUtil.getUserId());
            // 默认为未完善
            placeEntity.setStatus(1);
            // 是否现场采集  1:是  2:否
            placeEntity.setIsScene(1);
            // 来源 1:地址总表  2:国控采集 3:商超
            if (!Strings.isBlank(placeExcel.getHouseCode())) {
               placeEntity.setSource(1);
            }else {
               placeEntity.setSource(2);
               // 并生成36位的houseCode
               placeEntity.setHouseCode(IdUtils.getIdBy36());
            }
            // 九小场所类型处理
            if (!Strings.isBlank(placeExcel.getNineType())) {
               placeEntity.setIsNine(1);
               placeEntity.setNineType(Integer.parseInt(placeExcel.getNineType()));
            }
            // 网格绑定处理
            importGridHandle(placeExcel,placeEntity);
            // 新增
            save(placeEntity);
            importNum++;
            // 保存详情
            savePlaceExtAndTaskInfo(placeEntity);
            savePlaceExt(placeEntity,placeExcel);
            // 场所标签信息处理
            if (!Strings.isBlank(placeExcel.getLabelCode())) {
               PlaceVO placeVO = new PlaceVO();
@@ -998,59 +1058,94 @@
            }
            // 房屋编号绑定处理
            houseCodeBindHandle(placeEntity);
         }else {
            // 更新
            Long userId = updateUser(placeExcel);
            // 插入场所
            PlaceVO placeEntity = new PlaceVO();
            placeEntity.setId(one.getId());
            placeEntity.setHouseCode(placeExcel.getHouseCode());
            placeEntity.setHouseCodeBinds(placeExcel.getHouseCode());
            placeEntity.setPrincipalUserId(userId);
            placeEntity.setPrincipal(placeExcel.getName());
            placeEntity.setPrincipalPhone(placeExcel.getPhoneNumber());
            placeEntity.setCreateTime(new Date());
            placeEntity.setCreateUser(AuthUtil.getUserId());
            placeEntity.setUpdateTime(new Date());
            placeEntity.setUpdateUser(AuthUtil.getUserId());
            // 默认为未完善
            placeEntity.setStatus(1);
            // 是否现场采集  1:是  2:否
            placeEntity.setIsScene(1);
            // 来源 1:地址总表  2:国控采集 3:商超
            placeEntity.setSource(1);
            // 九小场所类型处理
            if (!Strings.isBlank(placeExcel.getNineType())) {
               placeEntity.setIsNine(1);
               placeEntity.setNineType(Integer.parseInt(placeExcel.getNineType()));
            }
            // 网格绑定处理
            importGridHandle(placeExcel,placeEntity);
            // 更新
            updateById(placeEntity);
            // 场所标签信息处理
            if (!Strings.isBlank(placeExcel.getLabelCode())) {
               PlaceVO placeVO = new PlaceVO();
               placeVO.setId(placeEntity.getId());
               placeVO.setLabel(placeExcel.getLabelCode());
               // 处理
               placeLabelBind(placeVO);
         } else {
            updateNum++;
            // 是否覆盖更新
            if (isCovered) {
               // 更新场所
               placeEntity.setId(one.getId());
               // 更新
               updateById(placeEntity);
               importNum++;
               // 场所标签信息处理
               if (!Strings.isBlank(placeExcel.getLabelCode())) {
                  PlaceVO placeVO = new PlaceVO();
                  placeVO.setId(one.getId());
                  placeVO.setLabel(placeExcel.getLabelCode());
                  // 处理
                  placeLabelBind(placeVO);
               }
            }
         }
      }
      StringBuilder builder = new StringBuilder("导入完成!");
      builder.append("其中本次表格共有 ").append(totalNum).append(" 条数据,")
         .append("成功导入 ").append(importNum).append(" 条数据。");
      if (updateNum>0) {
         builder.append("其中有 ").append(updateNum).append(" 条数据已存在。");
      }
      if (errorNum>0){
         builder.append("共有 ").append(errorNum).append(" 条数据由于无企业(店铺)名称信息或无地址编号未导入!");
      }
      return builder.toString();
   }
   /**
    * 保存场所详情信息
    * @param placeEntity
    * @param placeExcel
    */
   @Transactional(rollbackFor = Exception.class)
   public void savePlaceExt(PlaceEntity placeEntity, ImportPlaceExcel placeExcel) {
      PlaceVO placeVO = new PlaceVO();
      placeVO.setId(placeEntity.getId());
      PlaceExtEntity placeExtEntity = new PlaceExtEntity();
      placeExtEntity.setLegalPerson(placeExcel.getLegalPerson());
      placeExtEntity.setLegalTel(placeExcel.getLegalTel());
      placeExtEntity.setLegalIdCard(placeExcel.getLegalIdCard());
      // 设置详情
      placeVO.setPlaceExtEntity(placeExtEntity);
      // 保存详情
      savePlaceExtAndTaskInfo(placeVO);
   }
   /**
    *
    * @param placeExcel
    * @param placeEntity
    */
   public void houseCodeHandle(ImportPlaceExcel placeExcel, PlaceEntity placeEntity) {
      if (!Strings.isBlank(placeExcel.getHouseCode())) {
         placeEntity.setSource(1);
         // 设置经纬度及地址
         DoorplateAddressEntity doorplateAddressEntity
            = doorplateAddressService.getOne(Wrappers.<DoorplateAddressEntity>lambdaQuery()
            .eq(DoorplateAddressEntity::getAddressCode, placeExcel.getHouseCode()).last("limit 1"));
         if (null!=doorplateAddressEntity){
            placeEntity.setLng(doorplateAddressEntity.getX());
            placeEntity.setLat(doorplateAddressEntity.getY());
            placeEntity.setLocation(doorplateAddressEntity.getAddressName());
            placeEntity.setBuildingCode(doorplateAddressEntity.getBuildingCode());
            placeEntity.setAoiCode(doorplateAddressEntity.getAoiCode());
         }
      } else {
         placeEntity.setSource(2);
         // 并生成36位的houseCode
         placeEntity.setHouseCode(IdUtils.getIdBy36());
      }
   }
   /**
    * 导入是网格数据绑定处理
    *
    * @param placeExcel
    * @param placeEntity
    */
   private void importGridHandle(PlaceExcel placeExcel, PlaceVO placeEntity) {
      if (!Strings.isBlank(placeExcel.getCommunityName()) &&
         !Strings.isBlank(placeExcel.getGridName())){
   private void importGridHandle(ImportPlaceExcel placeExcel, PlaceEntity placeEntity) {
      if (Strings.isNotBlank(placeExcel.getCommunityName()) && Strings.isNotBlank(placeExcel.getGridName())) {
         // 查询对应的网格信息
         GridEntity gridEntity = gridService.getGridInfoByParam(placeExcel.getCommunityName(),placeExcel.getGridName());
         if (null!=gridEntity){
         GridEntity gridEntity = gridService.getGridInfoByParam(placeExcel.getCommunityName(), placeExcel.getGridName());
         if (null != gridEntity) {
            // 设置场所范围
            placeEntity.setGridId(gridEntity.getId());
            placeEntity.setGridCode(gridEntity.getGridCode());
@@ -1060,9 +1155,46 @@
            gridRangeEntity.setGridCode(gridEntity.getGridCode());
            gridRangeEntity.setHouseCode(placeEntity.getHouseCode());
            UpdateWrapper<GridRangeEntity> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("house_code",placeEntity.getHouseCode());
            gridRangeService.update(gridRangeEntity,updateWrapper);
            updateWrapper.eq("house_code", placeEntity.getHouseCode());
            gridRangeService.update(gridRangeEntity, updateWrapper);
         }
      } else if (StringUtils.isNotBlank(placeEntity.getLat()) && StringUtils.isNotBlank(placeEntity.getLng())) {
         // 点落面
         setGridInfo(placeEntity);
      }
   }
   /**
    * 设置警格网格信息
    *
    * @param placeEntity
    */
   public void setGridInfo(PlaceEntity placeEntity) {
      // 根据位置设置网格,警格编号
      IGridService gridService = SpringUtils.getBean(IGridService.class);
      IPoliceAffairsGridService policeAffairsGridService = SpringUtils.getBean(IPoliceAffairsGridService.class);
      String point = "'POINT(" + placeEntity.getLng() + " " + placeEntity.getLat() + ")'";
      // 点坐标解析网格
      List<GridEntity> gridEntityList = gridService.spatialAnalysis(point);
      if (gridEntityList.size() > 0) {
         GridEntity gridEntity = gridEntityList.get(0);
         // 设置场所范围
         placeEntity.setGridId(gridEntity.getId());
         placeEntity.setGridCode(gridEntity.getGridCode());
         // 更新网格范围绑定
         GridRangeEntity gridRangeEntity = new GridRangeEntity();
         gridRangeEntity.setGridId(gridEntity.getId());
         gridRangeEntity.setGridCode(gridEntity.getGridCode());
         gridRangeEntity.setHouseCode(placeEntity.getHouseCode());
         UpdateWrapper<GridRangeEntity> updateWrapper = new UpdateWrapper<>();
         updateWrapper.eq("house_code", placeEntity.getHouseCode());
         gridRangeService.update(gridRangeEntity, updateWrapper);
      }
      // 点坐标解析警格
      List<PoliceAffairsGridEntity> policeAffairsGridEntityList = policeAffairsGridService.spatialAnalysis(point);
      if (policeAffairsGridEntityList.size() > 0) {
         PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridEntityList.get(0);
         placeEntity.setJwGridCode(policeAffairsGridEntity.getJwGridCode());
      }
   }
@@ -1072,12 +1204,12 @@
    * @param placeExcel
    * @return
    */
   public Long updateUser(PlaceExcel placeExcel) {
      if (!Strings.isBlank(placeExcel.getPhoneNumber()) &&
         !Strings.isBlank(placeExcel.getName())) {
   public Long updateUser(ImportPlaceExcel placeExcel) {
      if (!Strings.isBlank(placeExcel.getPrincipal()) &&
         !Strings.isBlank(placeExcel.getPrincipalPhone())) {
         PlaceVO placeVO = new PlaceVO();
         placeVO.setPrincipal(placeExcel.getPhoneNumber());
         placeVO.setPrincipalPhone(placeExcel.getName());
         placeVO.setPrincipal(placeExcel.getPrincipal());
         placeVO.setPrincipalPhone(placeExcel.getPrincipalPhone());
         // 更新场所负责人
         User user = bindUserHandle(placeVO);
         // 返回
@@ -1396,6 +1528,9 @@
         PlaceEntity placeEntity = getById(id);
         if (null != placeEntity.getPrincipalUserId()) {
            User user = userService.getById(placeEntity.getPrincipalUserId());
            if (ObjectUtil.isEmpty(user)) {
               return;
            }
            // 查询场所判断是否还绑定有其他的场所
            QueryWrapper<PlaceEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("is_deleted", 0).eq("principal_user_id", user.getId());
@@ -1666,15 +1801,17 @@
   /**
    * 查询所有场所数据
    *
    * @return
    */
   @Override
   public List<PlaceVO> getAllList(int i,int size) {
      return baseMapper.getAllList(i,size);
   public List<PlaceVO> getAllList(int i, int size) {
      return baseMapper.getAllList(i, size);
   }
   /**
    * 查询所有场所数据总数
    *
    * @return
    */
   @Override
@@ -1684,6 +1821,7 @@
   /**
    * 查询对应的社区编号
    *
    * @param id
    * @return
    */
@@ -1691,4 +1829,31 @@
   public String getCommunityCode(Long id) {
      return baseMapper.getCommunityCode(id);
   }
   /**
    * 导出场所信息
    * @param place
    * @return
    */
   @Override
   public List<ExportPlaceExcel> exportPlaceList(PlaceVO place) {
      // 公共参数设置
      CommonParamSet commonParamSet = new CommonParamSet().invoke(PlaceVO.class, place);
      return baseMapper.exportPlaceList(place,
         commonParamSet.getGridCodeList(),
         commonParamSet.getRegionChildCodesList(),
         commonParamSet.getIsAdministrator()
      );
   }
   /**
    *  查询附近场所
    * @param lat
    * @param lng
    * @return
    */
   @Override
   public List<PlaceVO> getNearbyPlaceList(String lat, String lng) {
      return baseMapper.getNearbyPlaceList(lat, lng);
   }
}