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

Commit 16ab3758 authored by sunyuntian's avatar sunyuntian

划卡调任务优化

parent 7352d869
......@@ -62,4 +62,6 @@ public class KylinRedisConst {
public static final String ADMIN_UPUSH_LIST_ANDROID = "basicServices:upushList:Android";
public static final String ADMIN_BANNER_LIST = "kylin:bannerList";
public static final String RETURN_ADDRESS_CODE = "kylin:address:code";//退货地址
}
package com.liquidnet.service.kylin.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
public class KylinFreightCharge {
@TableId(value = "mid", type = IdType.AUTO)
private Integer mid;
private String name; //区县名
private String adcode; //区县code
private String price; //价格
private String businessType; //快运参数
private String businessTypeDesc; //快运类型
}
package com.liquidnet.service.kylin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liquidnet.service.kylin.entity.KylinFreightCharge;
import java.util.HashMap;
public interface KylinFreightChargeMapper {
int setFreightCharge(KylinFreightCharge kylinFreightCharge);
}
<?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.liquidnet.service.kylin.mapper.KylinFreightChargeMapper">
<insert id="setFreightCharge">
insert into kylin_freight_charge(
<if test="name != null and name != ''">name,</if>
<if test="adcode != null and adcode != ''">adcode,</if>
<if test="price != null and price != ''">price,</if>
<if test="businessType != null and businessType != ''">business_type,</if>
<if test="businessTypeDesc != null and businessTypeDesc != ''">business_type_desc,</if>
)values (
<if test="name != null and name != ''">#{name},</if>
<if test="adcode != null and adcode != ''">#{adcode},</if>
<if test="price != null and price != ''">#{price},</if>
<if test="businessType != null and businessType != ''">#{businessType},</if>
<if test="businessTypeDesc != null and businessTypeDesc != ''">#{businessTypeDesc},</if>
)
</insert>
</mapper>
package com.liquidnet.service.kylin.controller;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.kylin.service.impl.KylinFreightChargeServiceImpl;
import com.liquidnet.service.kylin.utils.ShunfengSignUtils;
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;
import java.util.HashMap;
import java.util.Map;
@Api(tags = "运费")
@RestController
@RequestMapping("freightCharge")
@Slf4j
public class KylinFreightChargeController {
@Autowired
private KylinFreightChargeServiceImpl kylinFreightChargeService;
@GetMapping("get")
@ApiOperation("运费查询")
public void getFreightCharge(){
kylinFreightChargeService.getFreightCharge();
}
}
package com.liquidnet.service.kylin.service.impl;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.entity.KylinFreightCharge;
import com.liquidnet.service.kylin.mapper.KylinFreightChargeMapper;
import com.liquidnet.service.kylin.utils.ShunfengSignUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Service
public class KylinFreightChargeServiceImpl {
@Autowired
private ShunfengSignUtils shunfengSignUtils;
@Autowired
private RedisUtil redisUtil;
@Autowired
private KylinFreightCharge kylinFreightCharge;
@Autowired
private KylinFreightChargeMapper kylinFreightChargeMapper;
// @Autowired
// private KylinRedisConst kylinRedisConst;
public void getFreightCharge() {
Map<String, String> hBody = new HashMap<>();
String jProvince="云南省";
String jCity="昆明市";
String jAddress="五华区";
String addressCode= "530102";//区code
hBody.put("jProvince", jProvince);
hBody.put("jCity", jCity);
hBody.put("jAddress", jAddress);
hBody.put("dProvince", "北京市");
hBody.put("dCity", "北京");
hBody.put("dAddress", "东城区");
hBody.put("expressType", "2");
try {
// 生成签名并请求
String result = shunfengSignUtils.generateSignatureAndRequestNew(hBody, "/public/order/v1/getFreight");
HashMap hashMap = JsonUtils.fromJson(result, HashMap.class);
HashMap<String,String> map = (HashMap<String, String>) hashMap.get("result");
map.put("address",jProvince+":"+jCity+":"+jAddress);
kylinFreightCharge.setPrice(map.get("price"));
kylinFreightCharge.setAdcode(addressCode);
kylinFreightCharge.setBusinessType(map.get("businessType"));
kylinFreightCharge.setBusinessTypeDesc(map.get("businessTypeDesc"));
kylinFreightCharge.setName(jProvince+":"+jCity+":"+jAddress);
//存数据库
int i= kylinFreightChargeMapper.setFreightCharge(kylinFreightCharge);
//存redis
//redisUtil.set(kylinRedisConst.RETURN_ADDRESS_CODE+addressCode,map);
}catch (Exception e) {
e.printStackTrace();
log.error("顺丰接口调用失败", e);
}
}
}
package com.liquidnet.service.kylin.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.*;
@Slf4j
@Component
public class JSONUtils {
/**
* 读取json文件
* @param fileName json文件路径
* @return
*/
public static String readJsonFile(String fileName) {
//fileName = JsonTest.class.getClassLoader().getResource("city.json").getPath();
File jsonFile = new File(fileName);
String jsonStr = "";
log.info("————开始读取" + jsonFile.getPath() + "文件————");
//System.out.println("————开始读取" + jsonFile.getPath() + "文件————");
try {
FileReader fileReader = new FileReader(jsonFile);
Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
log.info("————读取" + jsonFile.getPath() + "文件结束!————");
//System.out.println("————读取" + jsonFile.getPath() + "文件结束!————");
return jsonStr;
} catch (Exception e) {
log.info("————读取" + jsonFile.getPath() + "文件出现异常,读取失败!————");
// System.out.println("————读取" + jsonFile.getPath() + "文件出现异常,读取失败!————");
e.printStackTrace();
return null;
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
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