记得上下班打卡 | git大法好,push需谨慎

Commit 4c799e27 authored by 胡佳晨's avatar 胡佳晨

Merge remote-tracking branch 'origin/dev_freight' into dev_merchant

# Conflicts:
#	liquidnet-bus-service/liquidnet-service-kylin/liquidnet-service-kylin-impl/src/main/java/com/liquidnet/service/kylin/controller/KylinGetShunFengPriceController.java
parents e7e33056 65ab5603
......@@ -5,8 +5,12 @@ import com.liquidnet.service.kylin.dao.KylinFreightChargeDao;
import java.util.HashMap;
import java.util.List;
public interface KylinFreightChargeMapper extends BaseMapper<KylinFreightChargeDao>{
int setFreightCharge(KylinFreightChargeDao kylinFreightCharge);
void delTableData();
List<KylinFreightChargeDao> findSFData();
}
......@@ -17,7 +17,12 @@
<if test="businessType != null and businessType != ''">#{businessType},</if>
<if test="businessTypeDesc != null and businessTypeDesc != ''">#{businessTypeDesc}</if>
)
</insert>
<delete id="delTableData">
DELETE FROM kylin_freight_charge
</delete>
<select id="findSFData" resultType="com.liquidnet.service.kylin.dao.KylinFreightChargeDao">
select * from kylin_freight_charge
</select>
</mapper>
package com.liquidnet.service.kylin.controller;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.dao.KylinFreightChargeDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "前端-获取快递价格")
@RestController
@RequestMapping("getShunFengPrice")
......@@ -23,16 +27,25 @@ public class KylinGetShunFengPriceController {
@GetMapping("getPrice")
@ApiOperation("运费查询")
public ResponseDto<String> getFreightCharge(String adcode, String productCode) {
Object obj = redisUtil.get(KylinRedisConst.RETURN_ADDRESS_CODE + adcode + KylinRedisConst.EXPRESS_TYPE + productCode);
if (obj != null) {
KylinFreightChargeDao k = (KylinFreightChargeDao) obj;
public ResponseDto<String> getFreightCharge(String adcode, String expressType){
/* String substring = adcode.substring(0, 3);
if(substring.equals("110") || substring.equals("120") || substring.equals("130")){
if (expressType.equals("1")){
return ResponseDto.success("23.00");
}
}*/
Object obj = redisUtil.get(KylinRedisConst.RETURN_ADDRESS_CODE + adcode + KylinRedisConst.EXPRESS_TYPE + expressType);
if (obj != null){
KylinFreightChargeDao k= (KylinFreightChargeDao)obj;
//运费为0元时返23元
if (k.getPrice().equals("0.00")){
return ResponseDto.success("23.00");
}
return ResponseDto.success(k.getPrice());
} else {
return ResponseDto.failure();
}else {
//查询不到运费数据时返回23元
return ResponseDto.success("23.00");
// return ResponseDto.failure("查询失败");
}
}
}
......@@ -23,4 +23,11 @@ public class KylinFreightChargeController {
kylinFreightChargeService.getFreightCharge();
}
@GetMapping("findDataAddRedis")
@ApiOperation("读取运费全表数据存redis")
public void findDataAddRedis(){
kylinFreightChargeService.findDataAddRedis();
System.out.println("1");
}
}
\ No newline at end of file
......@@ -2,11 +2,9 @@ package com.liquidnet.service.platform.service.impl.kylin;
import com.alibaba.fastjson.JSONObject;
import com.liquidnet.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.dao.KylinFreightChargeDao;
import com.liquidnet.service.kylin.dto.vo.KylinExpressModuleVo;
......@@ -48,12 +46,13 @@ public class KylinFreightChargeServiceImpl {
hBody.put("jProvince", jProvince); //寄件地址
hBody.put("jCity", jCity);
hBody.put("jAddress", jAddress);
String fileName = KylinFreightChargeServiceImpl.class.getClassLoader().getResource("city.json").getPath();
//清空表
kylinFreightChargeMapper.delTableData();
String fileName = KylinFreightChargeServiceImpl.class.getClassLoader().getResource("city_2021.json").getPath();
String s = jsonUtils.readJsonFile(fileName);
List<HashMap> provinceListMap = JSONObject.parseArray(s, HashMap.class);
long startTime = System.currentTimeMillis();
Integer num=0;
for (Map pMap : provinceListMap) {
String dProvince = (String) pMap.get("name");
List<HashMap> cityListMap = (List<HashMap>) pMap.get("districts");
......@@ -69,40 +68,55 @@ public class KylinFreightChargeServiceImpl {
String adcode = (String) adMap.get("adcode");
String dAddress = (String) adMap.get("name");
hBody.put("expressType", productCode);
hBody.put("dProvince", dProvince);
hBody.put("dProvince", dProvince); //省
hBody.put("dCity", dCity);
hBody.put("dAddress", dAddress);
KylinFreightChargeDao kylinFreightCharge = KylinFreightChargeDao.getNew();
HashMap hashMap = null;
try {
// 生成签名并请求
String result = shunfengSignUtils.generateSignatureAndRequestNew(hBody, "/public/order/v1/getFreight");
HashMap hashMap = JsonUtils.fromJson(result, HashMap.class);
hashMap = JsonUtils.fromJson(result, HashMap.class);
HashMap<String, String> map = (HashMap<String, String>) hashMap.get("result");
String price = map.get("price");
String p = price.replace("元",".00");
kylinFreightCharge.setFieldsId(IDGenerator.nextTimeId2());
kylinFreightCharge.setProvince(dProvince);
kylinFreightCharge.setCity(dCity);
kylinFreightCharge.setAdname(dAddress);
kylinFreightCharge.setPrice(p);
kylinFreightCharge.setAdcode(adcode);
String price = map.get("price");
String p = price.replace("元",".00");
kylinFreightCharge.setPrice(p);
kylinFreightCharge.setBusinessType(map.get("businessType"));
kylinFreightCharge.setBusinessTypeDesc(map.get("businessTypeDesc"));
} catch (Exception e) {
e.printStackTrace();
log.error("顺丰接口调用失败", e, kylinFreightCharge.getProvince() + " " + kylinFreightCharge.getCity() + " " + kylinFreightCharge.getAdname());
log.error("顺丰接口调用失败:"+kylinFreightCharge.getProvince() + " " + kylinFreightCharge.getCity() + " " + kylinFreightCharge.getAdname()+" "+kylinExpressModuleVo.getProductCode()+kylinExpressModuleVo.getTitle());
}
//存数据库
int i = kylinFreightChargeMapper.setFreightCharge(kylinFreightCharge);
//存redis
redisDataSourceUtil.getRedisKylinUtil().set(KylinRedisConst.RETURN_ADDRESS_CODE + adcode + KylinRedisConst.EXPRESS_TYPE + productCode, kylinFreightCharge);
//调用成功
if(hashMap.get("succ").toString().equals("ok")){
//存数据库
int i = kylinFreightChargeMapper.setFreightCharge(kylinFreightCharge);
//存redis
redisDataSourceUtil.getRedisKylinUtil().set(KylinRedisConst.RETURN_ADDRESS_CODE + adcode + KylinRedisConst.EXPRESS_TYPE + productCode, kylinFreightCharge);
num++;
}
}
}
}
}
}
log.info("耗时:{}", (System.currentTimeMillis() - startTime) + "毫秒");
log.info("耗时:{}", (System.currentTimeMillis() - startTime) + "毫秒"+" "+"总条数"+num);
}
//读取kylin_freight_charge全表数据存redis
public void findDataAddRedis(){
List<KylinFreightChargeDao> l=kylinFreightChargeMapper.findSFData();
for (KylinFreightChargeDao FreightCharge : l) {
String adcode = FreightCharge.getAdcode();
String businessType = FreightCharge.getBusinessType();
//存redis
redisDataSourceUtil.getRedisKylinUtil().set(KylinRedisConst.RETURN_ADDRESS_CODE + adcode + KylinRedisConst.EXPRESS_TYPE + businessType, FreightCharge);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment