添加更新经纬度时,按照岗位id更新经纬度
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.ruoyi.cms.controller.cms;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.ruoyi.cms.domain.JobExcelImportRecord;
|
||||
import com.ruoyi.cms.service.IJobService;
|
||||
import com.ruoyi.cms.service.JobExcelImportRecordService;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
@@ -8,6 +10,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -24,6 +27,8 @@ public class JobExcelImportRecordController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private JobExcelImportRecordService jobExcelImportRecordService;
|
||||
@Autowired
|
||||
private IJobService jobService;
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
@@ -50,8 +55,24 @@ public class JobExcelImportRecordController extends BaseController {
|
||||
if (fileName == null || !fileName.endsWith(".xlsx") && !fileName.endsWith(".xls")) {
|
||||
return AjaxResult.error("请上传Excel格式的文件");
|
||||
}
|
||||
jobExcelImportRecordService.uploadFile(file);
|
||||
List<Long> effectIds=jobExcelImportRecordService.uploadFile(file);
|
||||
if (CollUtil.isNotEmpty(effectIds)) {
|
||||
this.asyncFillLonLat(effectIds);
|
||||
}
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新坐标
|
||||
* @param jobIdList
|
||||
*/
|
||||
@Async
|
||||
public void asyncFillLonLat(List<Long> jobIdList) {
|
||||
try {
|
||||
jobService.updateLonToByIds(jobIdList);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -122,4 +122,6 @@ public interface IJobService
|
||||
public int jobDown(Long jobId);
|
||||
|
||||
public int jobUp(Long jobId);
|
||||
|
||||
void updateLonToByIds(List<Long> ids);
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ public interface JobExcelImportRecordService {
|
||||
*/
|
||||
List<JobExcelImportRecord> selectShzJobExcelImportRecordList(JobExcelImportRecord jobExcelImportRecord);
|
||||
|
||||
void uploadFile(MultipartFile file) throws Exception;
|
||||
List<Long> uploadFile(MultipartFile file) throws Exception;
|
||||
}
|
||||
@@ -60,7 +60,8 @@ public class JobExcelImportRecordServiceImpl extends ServiceImpl<JobExcelImportR
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadFile(MultipartFile file) throws Exception{
|
||||
public List<Long> uploadFile(MultipartFile file) throws Exception{
|
||||
List<Long> allEffectJobIds = new ArrayList<>();
|
||||
String originalName = file.getOriginalFilename();
|
||||
String nameNoSuffix = FileNameUtil.getName(originalName);
|
||||
//获取字典
|
||||
@@ -86,7 +87,7 @@ public class JobExcelImportRecordServiceImpl extends ServiceImpl<JobExcelImportR
|
||||
if (CollUtil.isEmpty(validDataList)) {
|
||||
jobExcelImportRecord.setStorageNumber(0);
|
||||
jobExcelImportRecordMapper.insert(jobExcelImportRecord);
|
||||
return;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
jobExcelImportRecord.setStorageNumber(validDataList.size());
|
||||
|
||||
@@ -240,6 +241,7 @@ public class JobExcelImportRecordServiceImpl extends ServiceImpl<JobExcelImportR
|
||||
//批量新增岗位
|
||||
if (CollUtil.isNotEmpty(waitInsertJob)) {
|
||||
jobMapper.batchInsert(waitInsertJob);
|
||||
waitInsertJob.forEach(j -> allEffectJobIds.add(j.getJobId()));
|
||||
}
|
||||
//批量更新岗位
|
||||
if (CollUtil.isNotEmpty(waitUpdateJob)) {
|
||||
@@ -250,6 +252,7 @@ public class JobExcelImportRecordServiceImpl extends ServiceImpl<JobExcelImportR
|
||||
it.setCreateTime(null);
|
||||
it.setUpdateBy(detectionId);
|
||||
jobMapper.updateById(it);
|
||||
allEffectJobIds.add(it.getJobId());
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -269,8 +272,7 @@ public class JobExcelImportRecordServiceImpl extends ServiceImpl<JobExcelImportR
|
||||
jobExcelImportRecord.setStorageDetail(detailSb.toString());
|
||||
jobExcelImportRecordMapper.insert(jobExcelImportRecord);
|
||||
|
||||
//更新坐标并且刷选es
|
||||
jobService.updateLon();
|
||||
return allEffectJobIds;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.cms.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@@ -187,6 +188,61 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
|
||||
System.out.println("工作地址经纬度更新完成,共处理 " + jobs.size() + " 条记录");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新工作地址的经纬度信息
|
||||
*/
|
||||
@Override
|
||||
public void updateLonToByIds(List<Long> ids) {
|
||||
System.out.println("开始执行工作地址经纬度更新...");
|
||||
|
||||
// 1. 查询需要更新经纬度的工作地址
|
||||
List<Job> jobs = jobMapper.selectList(
|
||||
Wrappers.<Job>lambdaQuery()
|
||||
.in(Job::getJobId, ids)
|
||||
.and(wrapper -> wrapper.isNull(Job::getLongitude).or().eq(Job::getLongitude, BigDecimal.ZERO))
|
||||
// 限制每次处理10条
|
||||
);
|
||||
|
||||
if (jobs.isEmpty()) {
|
||||
System.out.println("没有需要更新经纬度的工作地址");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 遍历处理每个工作地址
|
||||
for (Job job : jobs) {
|
||||
try {
|
||||
System.out.println("\n正在处理工作ID: " + job.getJobId() +
|
||||
", 地址: " + job.getJobLocation());
|
||||
|
||||
// 调用高德API获取经纬度(添加适当延迟)
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
Map<String, BigDecimal> coordinates = getCoordinates(job.getJobLocation(), "石河子市");
|
||||
|
||||
if (coordinates != null) {
|
||||
// 3. 更新工作记录的经纬度
|
||||
job.setLongitude(coordinates.get("lng"));
|
||||
job.setLatitude(coordinates.get("lat"));
|
||||
|
||||
// 使用MyBatis Plus的update方法
|
||||
jobMapper.updateById(job);
|
||||
System.out.println("成功更新工作ID: " + job.getJobId() +
|
||||
" 的经纬度 -> 经度: " + job.getLongitude() +
|
||||
", 纬度: " + job.getLatitude());
|
||||
} else {
|
||||
System.out.println("无法获取工作地址的经纬度: " + job.getJobLocation());
|
||||
jobMapper.updateById(job);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("处理工作ID " + job.getJobId() + " 时出错: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("工作地址经纬度更新完成,共处理 " + jobs.size() + " 条记录");
|
||||
if (CollUtil.isNotEmpty(jobs)) {
|
||||
iesJobSearchService.resetTextCache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用高德地图API获取地址的经纬度并返回BigDecimal
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user