| | |
| | | package org.sxkj.gd.workorder.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.sxkj.common.constant.CommonConstant; |
| | | import org.sxkj.common.constant.WordOrderConstant; |
| | | import org.sxkj.common.utils.AmapUtils; |
| | | import org.sxkj.common.utils.GeomUtils; |
| | | import org.sxkj.common.utils.OrderNumUtils; |
| | | import org.sxkj.gd.workorder.entity.GdPatrolTaskEntity; |
| | |
| | | import org.sxkj.gd.workorder.vo.GdWorkOrderVO; |
| | | import org.sxkj.system.cache.SysCache; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 工单任务表 服务实现类 |
| | |
| | | * @author lw |
| | | * @since 2026-01-14 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class GdWorkOrderServiceImpl extends BaseServiceImpl<GdWorkOrderMapper, GdWorkOrderEntity> implements IGdWorkOrderService { |
| | | |
| | |
| | | } |
| | | entity.setGeom(validatedGeom); |
| | | |
| | | // 从几何数据中提取中心点坐标,用于获取行政区划编码 |
| | | double[] centerCoords = GeomUtils.extractCenterPoint(validatedGeom); |
| | | if (centerCoords == null || centerCoords.length < 2) { |
| | | return false; |
| | | } |
| | | String areaCodePrefix = getDistrictCodeByLocation(centerCoords[0], centerCoords[1]); |
| | | entity.setAreaCode(areaCodePrefix); |
| | | // 生成工单编号 |
| | | if (StringUtils.isBlank(entity.getWorkOrderCode())) { |
| | | String timestamp = OrderNumUtils.initOrderNum(WordOrderConstant.ORDER_REDIS_KEY); |
| | |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 根据经纬度获取行政区划编码 |
| | | * |
| | | * @param longitude 经度 |
| | | * @param latitude 纬度 |
| | | * @return 行政区划编码 |
| | | */ |
| | | public String getDistrictCodeByLocation(double longitude, double latitude) { |
| | | Map<String, String> districtInfo = getDistrictInfoByLocation(longitude, latitude); |
| | | String adcode = districtInfo.get("adcode"); |
| | | log.info("行政区划信息:{}", adcode); |
| | | // if (adcode != null && adcode.length() >= 3) { |
| | | // return adcode.substring(0, 2); |
| | | // } |
| | | return adcode; |
| | | } |
| | | |
| | | /** |
| | | * 根据经纬度获取行政区划信息 |
| | | * |
| | | * @param longitude 经度 |
| | | * @param latitude 纬度 |
| | | * @return 行政区划信息 |
| | | */ |
| | | public Map<String, String> getDistrictInfoByLocation(double longitude, double latitude) { |
| | | // 使用高德地图工具类获取行政区划信息 |
| | | String location = longitude + "," + latitude; |
| | | JSONObject result = AmapUtils.searchByLatLng(location); |
| | | |
| | | Map<String, String> districtInfo = new HashMap<>(); |
| | | if (result != null && "1".equals(result.getString("status"))) { |
| | | JSONObject regeocode = result.getJSONObject("regeocode"); |
| | | if (regeocode != null) { |
| | | JSONObject addressComponent = regeocode.getJSONObject("addressComponent"); |
| | | if (addressComponent != null) { |
| | | districtInfo.put("province", addressComponent.getString("province")); |
| | | districtInfo.put("city", addressComponent.getString("city")); |
| | | districtInfo.put("district", addressComponent.getString("district")); |
| | | districtInfo.put("adcode", addressComponent.getString("adcode")); |
| | | districtInfo.put("township", addressComponent.getString("township")); |
| | | districtInfo.put("formatted_address", regeocode.getString("formatted_address")); |
| | | } |
| | | } |
| | | } |
| | | return districtInfo; |
| | | } |
| | | } |