Commit e0fdf8af by 张富康

feat(perfSalary): 新增考勤数据清洗定时任务及门店经纬度更新功能

- 新增 AttendanceDataCleansingJob 定时考勤数据清洗任务,执行日志输出
- 创建 AttendanceDataCleansingService 服务框架,支持事务回滚
- 扩展 MerchantAttendanceListMapper,增加获取门店考勤清单和更新经纬度方法
- 新增对应 XML 映射文件的 SQL 语句,支持查询和更新操作
- 编写 MerchantAttendanceListMapper 测试代码,通过百度地图 API 获取地址经纬度并更新数据库
- 引入 ore-boot-starter-elasticjob 依赖,支持 ElasticJob 定时任务框架
- 优化 PerfRuleRemoteService 引入新的 model 和工具类依赖,为后续功能扩展做准备
1 parent abdef890
...@@ -48,5 +48,10 @@ ...@@ -48,5 +48,10 @@
<artifactId>rpc-scrm-entmicro-api</artifactId> <artifactId>rpc-scrm-entmicro-api</artifactId>
<version>3.25.9-SNAPSHOT</version> <version>3.25.9-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.oreframework.boot</groupId>
<artifactId>ore-boot-starter-elasticjob</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.job;
import cn.com.glsx.dj.staff.service.perfSalary.AttendanceDataCleansingService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import javax.annotation.Resource;
@Slf4j
@ElasticJobConf(name = "AttendanceDataCleansing", cron = "0 6 1 * *", description = "考勤数据清洗", overwrite = false)
public class AttendanceDataCleansingJob implements SimpleJob {
@Resource
private AttendanceDataCleansingService attendanceDataCleansingService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("----------------考勤数据清洗开始-----------------");
try {
attendanceDataCleansingService.attendanceDataCleansing();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("----------------考勤数据清洗结束-----------------");
}
}
...@@ -2,9 +2,22 @@ package cn.com.glsx.dj.staff.mapper.perfSalary; ...@@ -2,9 +2,22 @@ package cn.com.glsx.dj.staff.mapper.perfSalary;
import cn.com.glsx.dj.staff.model.perfSalary.MerchantAttendanceList; import cn.com.glsx.dj.staff.model.perfSalary.MerchantAttendanceList;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List;
@Mapper @Mapper
public interface MerchantAttendanceListMapper extends OreMapper<MerchantAttendanceList> { public interface MerchantAttendanceListMapper extends OreMapper<MerchantAttendanceList> {
/**
* 测试打卡门店清单数据
*/
List<MerchantAttendanceList> getMerchantAttendanceList();
/**
* 根据门店id更新经纬度
*/
void updateMerchantLocation(@Param("id") Integer id, @Param("address_lng") String address_lng, @Param("address_lat") String address_lat);
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.service.perfSalary;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = RpcServiceException.class)
public class AttendanceDataCleansingService {
public void attendanceDataCleansing() {
}
}
...@@ -174,4 +174,7 @@ public class PerfRuleRemoteService { ...@@ -174,4 +174,7 @@ public class PerfRuleRemoteService {
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,5 +4,15 @@ ...@@ -4,5 +4,15 @@
<mapper namespace="cn.com.glsx.dj.staff.mapper.perfSalary.MerchantAttendanceListMapper"> <mapper namespace="cn.com.glsx.dj.staff.mapper.perfSalary.MerchantAttendanceListMapper">
<select id="getMerchantAttendanceList" resultType="cn.com.glsx.dj.staff.model.perfSalary.MerchantAttendanceList">
select id, merchant_id merchant_name, attendance_address attendanceAddress
from sal_merchant_attendance_list
where attendance_address is not null;
</select>
<update id="updateMerchantLocation">
update sal_merchant_attendance_list set address_lng = #{address_lng}, address_lat = #{address_lat} where id = #{id};
</update>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.mapper.perfSalary;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class LocationResponse {
private int status;
private Result result;
@Data
@Builder
public static class Result {
private Location location;
private int precise;
private int confidence;
private int comprehension;
private String level;
}
@Data
@Builder
public static class Location {
private String lng;
private String lat;
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.mapper.perfSalary;
import cn.com.glsx.dj.sale.service.BaseServiceTest;
import cn.com.glsx.dj.staff.model.perfSalary.MerchantAttendanceList;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import javax.annotation.Resource;
import java.util.List;
@Slf4j
public class MerchantAttendanceListMapperTest extends BaseServiceTest {
@Resource
private MerchantAttendanceListMapper merchantAttendanceListMapper;
/**
* 处理商户地址经纬度
*/
@Test
public void test(){
List<MerchantAttendanceList> infos = merchantAttendanceListMapper.getMerchantAttendanceList();
for (MerchantAttendanceList info : infos) {
// hutool get请求
log.info("address: {}", info.getAttendanceAddress());
String url = "https://api.map.baidu.com/geocoding/v3/?address="+ info.getAttendanceAddress() +"&output=json&ak=pbKP9T69inAX0GVwS9uar2l1Yz6OLyyg&ret_coordtype=gcj02ll";
String s = HttpUtil.get(url);
log.info("查询信息: {}", s);
LocationResponse bean = JSONUtil.toBean(s, LocationResponse.class);
// 更新经纬度
merchantAttendanceListMapper.updateMerchantLocation(info.getId(), bean.getResult().getLocation().getLng(), bean.getResult().getLocation().getLat());
}
}
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!