提交 1ee0fee3 authored 作者: 000516's avatar 000516

清洗百事门店逻辑临时加入

上级 455cd081
package com.sfa.job.domain.ls;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.Data;
/**
* ls_门店表
* @TableName ls_dis_store
*/
@TableName(value ="ls_dis_store")
@Data
public class LsDisStore implements Serializable {
/**
* 自增主键
*/
@TableId(type = IdType.AUTO)
private Long ldsIf;
//
// /**
// * DISTRIBUTOR[Division]
// */
// private String disDivision;
//
// /**
// * DISTRIBUTOR[经销商名称 - Distributor Name]
// */
// private String disName;
//
// /**
// * PRODUCT[DISBrand]
// */
// private String disBrand;
//
// /**
// * DISTRIBUTOR[经销商省份 - Distributor Province]
// */
// private String disProvince;
//
// /**
// * DISTRIBUTOR[City]
// */
// private String disCity;
//
// /**
// * DATE[YearMonth]
// */
// private String dateYm;
//
// /**
// * OUTLET[百事门店编码 – PepsiCo Store Code]
// */
// private String outletCode;
/**
* OUTLET[全量门店名称 - Outlet Name]
*/
private String outletName;
// /**
// * OUTLET[门店类型 - Outlet Type]
// */
// private String outletType;
//
// /**
// * 王小卤门店类型-大类
// */
// private String outletTypeWd;
//
// /**
// * 王小卤门店类型-小类
// */
// private String outletTypeWx;
//
// /**
// * OUTLET[门店省份 - Outlet Province]
// */
// private String outletProvince;
//
// /**
// * OUTLET[门店尼尔森城市 - Outlet Nielsen City]
// */
// private String outletNesCity;
/**
* OUTLET[门店地址 - Outlet Address]
*/
private String outletAddress;
/**
* 径度
*/
private String lng;
/**
* 纬度
*/
private String lat;
/**
* 省
*/
private String reProvince;
/**
* 市
*/
private String reCity;
/**
* 区
*/
private String reArea;
//
// /**
// * 百度地址
// */
// private String reAddress;
//
// /**
// * [销售金额_元___Sell_Out_Value__Yuan_]
// */
// private BigDecimal saleValue;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.sfa.job.domain.ls;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.sfa.job.domain.ls.mapper.LsDisStoreMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author : liqiulin
* @date : 2025-11-27 17
* @describe :
*/
@Slf4j
@DS("bi")
@Service
public class LsDisStoreDaoImpl {
@Autowired
private LsDisStoreMapper lsDisStoreMapper;
// 安徽王小卤主体
public void baiduAddressAnHui(Long ldsId){
List<LsDisStore> lsDisStores = lsDisStoreMapper.selectBaseO(ldsId);
if (lsDisStores.isEmpty()){
return;
}
ldsId = lsDisStores.get(lsDisStores.size() - 1).getLdsIf();
updateanhui(lsDisStores,ldsId);
}
private void updateanhui(List<LsDisStore> lsDisStores,Long ldsId){
for (LsDisStore lsDisStore : lsDisStores) {
String outlet = lsDisStore.getOutletName()+lsDisStore.getOutletAddress();
String s = HttpUtil.get("https://api.map.baidu.com/geocoding/v3/?address="+outlet+"&output=json&ak=1ZKO0CGs6nm9HuZWR6ucRiu4p9kM8f3i&city="+lsDisStore.getReCity());
JSONObject bd = JSONObject.parseObject(s);
Integer status = bd.getInteger("status");
if (status.intValue() >= 300 && status.intValue() <= 399){
log.info(s);
return;
}
if (status.intValue() != 0){
continue;
}
JSONObject jo = bd.getJSONObject("result");
String analysLevel = jo.getString("level");
lsDisStore.setLat(analysLevel);
if (!analysLevel.equals("省") && !analysLevel.equals("城市")){
JSONObject location = jo.getJSONObject("location");
Float lng = location.getFloat("lng");
Float lat = location.getFloat("lat");
lsDisStore.setLng(lat+","+lng);
}
}
lsDisStoreMapper.updateListO(lsDisStores);
baiduAddressAnHui(ldsId);
}
// 广州王小卤主体
public void baiduAddressGuangzhou(long ldsId) {
List<LsDisStore> lsDisStores = lsDisStoreMapper.selectBaseT(ldsId);
if (lsDisStores.isEmpty()){
return;
}
ldsId = lsDisStores.get(lsDisStores.size() - 1).getLdsIf();
updateGuangzhou(lsDisStores,ldsId);
}
private void updateGuangzhou(List<LsDisStore> lsDisStores,Long ldsId){
for (LsDisStore lsDisStore : lsDisStores) {
String outlet = lsDisStore.getOutletName()+lsDisStore.getOutletAddress();
String s = HttpUtil.get("https://api.map.baidu.com/geocoding/v3/?address="+outlet+"&output=json&ak=8ptRbXOnQNX2TTqGVVYv5AUw3vJZ77gZ&city="+lsDisStore.getReCity());
JSONObject bd = JSONObject.parseObject(s);
Integer status = bd.getInteger("status");
if (status.intValue() >= 300 && status.intValue() <= 399){
log.info(s);
return;
}
if (status.intValue() != 0){
continue;
}
JSONObject jo = bd.getJSONObject("result");
String analysLevel = jo.getString("level");
lsDisStore.setLat(analysLevel);
if (!analysLevel.equals("省") && !analysLevel.equals("城市")){
JSONObject location = jo.getJSONObject("location");
Float lng = location.getFloat("lng");
Float lat = location.getFloat("lat");
lsDisStore.setLng(lat+","+lng);
}
}
lsDisStoreMapper.updateListT(lsDisStores);
baiduAddressGuangzhou(ldsId);
}
public void baiduAddressAnHuisp(Long ldsId){
List<LsDisStore> lsDisStores = lsDisStoreMapper.selectBaseS(ldsId);
if (lsDisStores.isEmpty()){
return;
}
ldsId = lsDisStores.get(lsDisStores.size() - 1).getLdsIf();
updateanhuisp(lsDisStores,ldsId);
}
private void updateanhuisp(List<LsDisStore> lsDisStores,Long ldsId){
for (LsDisStore lsDisStore : lsDisStores) {
String outlet = lsDisStore.getOutletName()+lsDisStore.getOutletAddress();
String s = HttpUtil.get("https://api.map.baidu.com/geocoding/v3/?address="+outlet+"&output=json&ak=StY6BS8Bw50TrclA4Zd52MfEjsL1zUXI&city="+lsDisStore.getReCity());
JSONObject bd = JSONObject.parseObject(s);
Integer status = bd.getInteger("status");
if (status.intValue() >= 300 && status.intValue() <= 399){
log.info(s);
return;
}
if (status.intValue() != 0){
continue;
}
JSONObject jo = bd.getJSONObject("result");
String analysLevel = jo.getString("level");
lsDisStore.setLat(analysLevel);
if (!analysLevel.equals("省") && !analysLevel.equals("城市")){
JSONObject location = jo.getJSONObject("location");
Float lng = location.getFloat("lng");
Float lat = location.getFloat("lat");
lsDisStore.setLng(lat+","+lng);
}
}
lsDisStoreMapper.updateListS(lsDisStores);
baiduAddressAnHuisp(ldsId);
}
}
package com.sfa.job.domain.ls.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sfa.job.domain.ls.LsDisStore;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author a02200059
* @description 针对表【ls_dis_store(ls_门店表)】的数据库操作Mapper
* @createDate 2025-11-27 17:04:20
* @Entity com.sfa.job.domain.ls.LsDisStore
*/
@Repository
public interface LsDisStoreMapper extends BaseMapper<LsDisStore> {
List<LsDisStore> selectBaseO(Long lastId);
void updateListO(@Param("lsDisStores") List<LsDisStore> lsDisStores);
List<LsDisStore> selectBaseT(Long lastId);
void updateListT(@Param("lsDisStores") List<LsDisStore> lsDisStores);
List<LsDisStore> selectBaseS(Long lastId);
void updateListS(@Param("lsDisStores") List<LsDisStore> lsDisStores);
}
package com.sfa.job.xxljob.test;
import com.sfa.job.domain.ls.LsDisStoreDaoImpl;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author : liqiulin
* @date : 2025-04-08 13
* @describe :
*/
@Component
@Slf4j
public class TestTask {
@Autowired
private LsDisStoreDaoImpl lsDisStoreDaoImpl;
@XxlJob("ls_store_anhui")
public void lsStoreAnHui() {
lsDisStoreDaoImpl.baiduAddressAnHui(0L);
}
@XxlJob("ls_store_guangzhou")
public void lsStoreGuangzhou() {
lsDisStoreDaoImpl.baiduAddressGuangzhou(500000L);
}
@XxlJob("ls_store_ahsp")
public void lsStoreAnHuisp() {
lsDisStoreDaoImpl.baiduAddressAnHuisp(1000000L);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sfa.job.domain.ls.mapper.LsDisStoreMapper">
<resultMap id="LsDisStoreBase" type="com.sfa.job.domain.ls.LsDisStore">
<id property="ldsIf" column="lds_if" jdbcType="BIGINT"/>
<!-- <result property="disDivision" column="dis_division" jdbcType="VARCHAR"/>-->
<!-- <result property="disName" column="dis_name" jdbcType="VARCHAR"/>-->
<!-- <result property="disBrand" column="dis_brand" jdbcType="VARCHAR"/>-->
<!-- <result property="disProvince" column="dis_province" jdbcType="VARCHAR"/>-->
<!-- <result property="disCity" column="dis_city" jdbcType="VARCHAR"/>-->
<!-- <result property="dateYm" column="date_ym" jdbcType="VARCHAR"/>-->
<!-- <result property="outletCode" column="outlet_code" jdbcType="VARCHAR"/>-->
<result property="outletName" column="outlet_name" jdbcType="VARCHAR"/>
<!-- <result property="outletType" column="outlet_type" jdbcType="VARCHAR"/>-->
<!-- <result property="outletTypeWd" column="outlet_type_wd" jdbcType="VARCHAR"/>-->
<!-- <result property="outletTypeWx" column="outlet_type_wx" jdbcType="VARCHAR"/>-->
<!-- <result property="outletProvince" column="outlet_province" jdbcType="VARCHAR"/>-->
<!-- <result property="outletNesCity" column="outlet_nes_city" jdbcType="VARCHAR"/>-->
<result property="outletAddress" column="outlet_address" jdbcType="VARCHAR"/>
<result property="lng" column="lng" jdbcType="VARCHAR"/>
<result property="lat" column="lat" jdbcType="VARCHAR"/>
<result property="reProvince" column="re_province" jdbcType="VARCHAR"/>
<result property="reCity" column="re_city" jdbcType="VARCHAR"/>
<result property="reArea" column="re_area" jdbcType="VARCHAR"/>
<!-- <result property="reAddress" column="re_address" jdbcType="VARCHAR"/>-->
<!-- <result property="saleValue" column="sale_value" jdbcType="DECIMAL"/>-->
</resultMap>
<!-- 修改 limit 数量-->
<select id="selectBaseO" resultMap="LsDisStoreBase">
select lds_if,re_province,re_city,outlet_address,outlet_name
from ls_dis_store where lds_if &gt; #{lastId} and lds_if &lt;= 500000 and re_area is null and lng is null and outlet_address is not null limit 1000;
</select>
<update id="updateListO" parameterType="java.util.List">
<foreach collection="lsDisStores" item="item" separator=";">
update ls_dis_store set lng = #{item.lng} where lds_if = #{item.ldsIf}
</foreach>
</update>
<select id="selectBaseT" resultMap="LsDisStoreBase">
select lds_if,re_province,re_city,outlet_address,outlet_name
from ls_dis_store where lds_if &gt; #{lastId} and lds_if &lt;= 1000000 and re_area is null and lng is null and outlet_address is not null limit 1000;
</select>
<update id="updateListT" parameterType="java.util.List">
<foreach collection="lsDisStores" item="item" separator=";">
update ls_dis_store set lng = #{item.lng} where lds_if = #{item.ldsIf}
</foreach>
</update>
<select id="selectBaseS" resultMap="LsDisStoreBase">
select lds_if,re_province,re_city,outlet_address,outlet_name
from ls_dis_store where lds_if &gt; #{lastId} and lds_if &lt;= 1537130 and re_area is null and lng is null and outlet_address is not null limit 1000;
</select>
<update id="updateListS" parameterType="java.util.List">
<foreach collection="lsDisStores" item="item" separator=";">
update ls_dis_store set lng = #{item.lng} where lds_if = #{item.ldsIf}
</foreach>
</update>
</mapper>
package com.sfa.job.domain.ls;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
/**
* @author : liqiulin
* @date : 2025-11-27 18
* @describe :
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class LsDisStoreDaoImplTest {
@Autowired
private LsDisStoreDaoImpl lsDisStoreDaoImpl;
@Test
public void baiduAddress() {
Long ldsId = 0L;
lsDisStoreDaoImpl.baiduAddress(ldsId);
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论