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

Commit 5ca4638a authored by Tice's avatar Tice

Merge branch 'dev_merchant' into dev_merchant_tice

parents 6606d29c 66a3f5f1
......@@ -69,5 +69,9 @@ public class KylinRedisConst {
public static final String ADMIN_BANNER_LIST = "kylin:bannerList";
public static final String RETURN_ADDRESS_CODE = "kylin:address:code";//退货地址
public static final String EXPRESS_TYPE = "express:type";//退货地址
public static final String KYLIN_EXPRESS_MODULES = "kylin:express:modules";
}
......@@ -35,25 +35,25 @@ public class TicketCreateParam implements Serializable {
@ApiModelProperty(value = "快递类型[0无类型|1寄付|2到付|3包邮]", example = "2")
private Integer expressType;
@ApiModelProperty(value = "快递模板", example = "2")
@ApiModelProperty(value = "快递模板")
private List<String> expressModule;
@ApiModelProperty(value = "是否学生票 0否 1是", example = "0")
@NotNull(message = "是否学生票不能为空")
private Integer isStudent;
@ApiModelProperty(value = "是否电子票", example = "0")
@ApiModelProperty(value = "是否电子票", example = "1")
@NotNull(message = "是否电子票不能为空")
private Integer isElectronic;
@ApiModelProperty(value = "是否电子票", example = "0")
@ApiModelProperty(value = "快递票描述")
private String describeExpress;
@ApiModelProperty(value = "是否快递票", example = "0")
@NotNull(message = "是否快递票不能为空")
private Integer isExpress;
@ApiModelProperty(value = "是否电子票", example = "0")
@ApiModelProperty(value = "电子票描述")
private String describeElectronic;
@ApiModelProperty(value = "价格", example = "100.00")
......
......@@ -3,6 +3,7 @@ package com.liquidnet.client.admin.zhengzai.kylin.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liquidnet.client.admin.zhengzai.kylin.service.IToolService;
import com.liquidnet.client.admin.zhengzai.kylin.utils.DataUtils;
import com.liquidnet.client.admin.zhengzai.kylin.utils.MongoVoUtils;
import com.liquidnet.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.commons.lang.util.DateUtil;
......@@ -41,6 +42,10 @@ public class ToolServiceImpl implements IToolService {
private KylinOrderTicketsMapper kylinOrderTicketsMapper;
@Autowired
private KylinOrderTicketVoMapper kylinOrderTicketVoMapper;
@Autowired
private RedisDataSourceUtil redisDataSourceUtil;
@Autowired
private MongoVoUtils mongoVoUtils;
@Override
public Boolean supplementEnter(String orderTicketEntitiesId, String enterName, String enterMobile, String enterIdCode, Integer enterType, String orderId) {
......@@ -88,21 +93,16 @@ public class ToolServiceImpl implements IToolService {
List<KylinOrderTickets> KylinOrderTickets = kylinOrderTicketVoMapper.getExpressContactsByOrderCode(orderCode);
return KylinOrderTickets;
}
@Autowired
private RedisDataSourceUtil redisDataSourceUtil;
@Override
public Integer updOrderExpressPhoneByOrderCode(String orderCode, String expressPhone) {
int upd = kylinOrderTicketVoMapper.updOrderExpressPhoneByOrderCode(orderCode, expressPhone);
//存mongo
Query query = Query.query(Criteria.where("orderCode").is(orderCode));
Update update = Update.update("expressPhone",expressPhone);;
mongoTemplate.updateFirst(query,update,KylinOrderTicketVo.class,KylinOrderTicketVo.class.getSimpleName());
mongoVoUtils.orderSetMongo(orderCode, expressPhone);
//存redis
String redisK = KylinRedisConst.ORDER + orderCode;
KylinOrderTicketVo orderTicketVo = mongoTemplate.findOne(query, KylinOrderTicketVo.class, KylinOrderTicketVo.class.getSimpleName());
redisDataSourceUtil.getRedisKylinUtil().set(redisK, orderTicketVo);
// Object o = redisDataSourceUtil.getRedisKylinUtil().get(redisK);
dataUtils.orderSetRedis(orderCode);
Object o = redisDataSourceUtil.getRedisKylinUtil().get("kylin:order:id:201373316981841927358500");
return upd;
}
}
......@@ -7,7 +7,6 @@ import com.github.pagehelper.PageInfo;
import com.liquidnet.client.admin.zhengzai.kylin.dto.OrderOutLineVo;
import com.liquidnet.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.dto.vo.admin.OrderRefundAddress;
import com.liquidnet.service.kylin.dto.vo.express.KylinOrderExpressVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo;
......@@ -443,6 +442,14 @@ public class DataUtils {
return (PageInfo<OrderOutLineVo>) obj;
}
}
//订单信息存redis
public void orderSetRedis(String orderCode){
KylinOrderTicketVo orderTicketVo = mongoTemplate.findOne(Query.query(Criteria.where("orderCode").is(orderCode)), KylinOrderTicketVo.class, KylinOrderTicketVo.class.getSimpleName());
String orderTicketsId = orderTicketVo.getOrderTicketsId();
List<KylinOrderTicketEntitiesVo> kylinOrderTicketEntitiesVoList = mongoTemplate.find(Query.query(Criteria.where("orderId").is(orderTicketsId)), KylinOrderTicketEntitiesVo.class, KylinOrderTicketEntitiesVo.class.getSimpleName());
orderTicketVo.setEntitiesVoList(kylinOrderTicketEntitiesVoList);
redisDataSourceUtil.getRedisKylinUtil().set(KylinRedisConst.ORDER +orderTicketsId, orderTicketVo);
}
public void setkylinExpressModules(List<KylinExpressModuleVo> voList) {
String redisKey = KylinRedisConst.KYLIN_EXPRESS_MODULES;
......
......@@ -14,6 +14,10 @@ import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.merchant.dto.vo.MerchantFieldsVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
......@@ -43,6 +47,8 @@ public class MongoVoUtils {
private RedisDataSourceUtil redisDataSourceUtil;
@Autowired
private DataUtils dataUtils;
@Autowired
private MongoTemplate mongoTemplate;
public KylinPerformanceVo combinePerformanceVoData(String performancesId) {
try {
......@@ -222,4 +228,14 @@ public class MongoVoUtils {
return false;
}
}
/**
* 修改收货人手机号
* @param orderCode 订单编号
* @param expressPhone 收货人手机号
*/
public void orderSetMongo(String orderCode, String expressPhone ){
Query query = Query.query(Criteria.where("orderCode").is(orderCode));
Update update = Update.update("expressPhone",expressPhone);;
mongoTemplate.updateFirst(query,update,KylinOrderTicketVo.class,KylinOrderTicketVo.class.getSimpleName());
}
}
......@@ -52,15 +52,15 @@ liquidnet:
adam:
database: 255
dbs: 0,256
host: r-2ze3sf1ll8er966uuc.redis.rds.aliyuncs.com
host: r-2ze7002ckw5u75fguk.redis.rds.aliyuncs.com
port: 6380
password: Qwer1234
password: PO@B!Iud32
candy:
database: 255
dbs: 0,256
host: r-2zem98z0tongsw3fpc.redis.rds.aliyuncs.com
host: r-2ze7002ckw5u75fguk.redis.rds.aliyuncs.com
port: 6380
password: Qwer1234
password: PO@B!Iud32
mongodb:
host: 39.107.71.112:27017
port: 27017
......
package com.liquidnet.service.kylin.dao;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serializable;
@Data
public class KylinFreightChargeDao implements Serializable {
@TableId(value = "mid", type = IdType.AUTO)
private Integer mid;
private String fieldsId;
private String province; //省
private String city;//市
private String adname; //区县
private String adcode; //区县code
private String price; //价格
private String businessType; //快运参数
private String businessTypeDesc; //快运类型
private static final KylinFreightChargeDao obj = new KylinFreightChargeDao();
public static KylinFreightChargeDao getNew() {
try {
return (KylinFreightChargeDao) obj.clone();
} catch (CloneNotSupportedException e) {
return new KylinFreightChargeDao();
}
}
}
\ No newline at end of file
package com.liquidnet.service.kylin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liquidnet.service.kylin.dao.KylinFreightChargeDao;
import java.util.HashMap;
public interface KylinFreightChargeMapper extends BaseMapper<KylinFreightChargeDao>{
int setFreightCharge(KylinFreightChargeDao 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" parameterType="com.liquidnet.service.kylin.dao.KylinFreightChargeDao" useGeneratedKeys="true" keyProperty="mid">
insert into kylin_freight_charge(
mid,fields_id,province,city,adname,adcode,price,business_type,business_type_desc
)values (
#{mid},
<if test="fieldsId != null and fieldsId != ''">#{fieldsId},</if>
<if test="province != null and province != ''">#{province},</if>
<if test="city != null and city != ''">#{city},</if>
<if test="adname != null and adname != ''">#{adname},</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.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.common.cache.redis.util.RedisUtil;
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")
@Slf4j
public class KylinGetShunFengPriceController {
@Autowired
private RedisDataSourceUtil redisDataSourceUtil;
@Autowired
private RedisUtil redisUtil;
@GetMapping("getPrice")
@ApiOperation("运费查询")
public String getFreightCharge(String adcode,String expressType){
Object obj =redisUtil.get(KylinRedisConst.RETURN_ADDRESS_CODE+adcode+KylinRedisConst.EXPRESS_TYPE+expressType);
if (obj != null){
KylinFreightChargeDao k= (KylinFreightChargeDao)obj;
return k.getPrice();
}else {
return null;
}
}
}
package com.liquidnet.service.merchant.service;
import com.liquidnet.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.merchant.constant.MerchantRedisConst;
import com.liquidnet.service.merchant.dto.vo.*;
import com.liquidnet.service.merchant.util.ObjectUtil;
......@@ -16,7 +16,7 @@ import java.util.List;
public class MerchantRdmService {
@Autowired
RedisDataSourceUtil redisDataSourceUtil;
RedisUtil redisUtil;
@Autowired
private MerchantMongoService merchantMongoService;
......@@ -28,18 +28,18 @@ public class MerchantRdmService {
}
String key = MerchantRedisConst.INFO_FIELD.concat(fieldId);
long s = System.currentTimeMillis();
MerchantFieldsVo vo = (MerchantFieldsVo) redisDataSourceUtil.getRedisKylinUtil().get(key);
MerchantFieldsVo vo = (MerchantFieldsVo) redisUtil.get(key);
log.debug("#RDM耗时:{}ms", System.currentTimeMillis() - s);
if (null == vo) {
vo = merchantMongoService.getFieldsVoByFieldId(fieldId);
redisDataSourceUtil.getRedisKylinUtil().set(key, vo);
redisUtil.set(key, vo);
}
return vo;
}
// 【场地】更新详情
public boolean setFieldsVoByFieldId(String fieldId, MerchantFieldsVo vo) {
return redisDataSourceUtil.getRedisKylinUtil().set(MerchantRedisConst.INFO_FIELD.concat(fieldId), vo);
return redisUtil.set(MerchantRedisConst.INFO_FIELD.concat(fieldId), vo);
}
......@@ -50,11 +50,11 @@ public class MerchantRdmService {
}
String key = MerchantRedisConst.INFO_FIELD_APPLIES.concat(uid);
long s = System.currentTimeMillis();
List<MerchantFieldAppliesVo> vos = (List<MerchantFieldAppliesVo>) redisDataSourceUtil.getRedisKylinUtil().get(key);
List<MerchantFieldAppliesVo> vos = (List<MerchantFieldAppliesVo>) redisUtil.get(key);
log.debug("#RDM耗时:{}ms", System.currentTimeMillis() - s);
if (null == vos) {
vos = merchantMongoService.getFieldAppliesVosByUid(uid);
redisDataSourceUtil.getRedisKylinUtil().set(key, vos);
redisUtil.set(key, vos);
}
return vos;
}
......@@ -65,7 +65,7 @@ public class MerchantRdmService {
vos = ObjectUtil.getMerchantFieldAppliesVoArrayList();
}
vos.add(vo);
return redisDataSourceUtil.getRedisKylinUtil().set(MerchantRedisConst.INFO_FIELD_APPLIES.concat(uid), vos);
return redisUtil.set(MerchantRedisConst.INFO_FIELD_APPLIES.concat(uid), vos);
}
// 【场地申请】删除
......@@ -74,7 +74,7 @@ public class MerchantRdmService {
return true;
}
vos.removeIf(r -> r.getFieldApplyId().equals(vo.getFieldApplyId()));
return redisDataSourceUtil.getRedisKylinUtil().set(MerchantRedisConst.INFO_FIELD_APPLIES.concat(uid), vos);
return redisUtil.set(MerchantRedisConst.INFO_FIELD_APPLIES.concat(uid), vos);
}
......@@ -82,7 +82,7 @@ public class MerchantRdmService {
public List<MerchantFieldCheckersVo> getFieldCheckersVosByFieldId(String fieldId) {
String key = MerchantRedisConst.INFO_FIELD_CHECKERS.concat(fieldId);
long s = System.currentTimeMillis();
List<MerchantFieldCheckersVo> vos = (List<MerchantFieldCheckersVo>) redisDataSourceUtil.getRedisKylinUtil().get(key);
List<MerchantFieldCheckersVo> vos = (List<MerchantFieldCheckersVo>)redisUtil.get(key);
log.debug("#RDM耗时:{}ms", System.currentTimeMillis() - s);
return vos;
}
......@@ -93,7 +93,7 @@ public class MerchantRdmService {
vos = ObjectUtil.getMerchantFieldCheckersVoArrayList();
}
vos.add(vo);
return redisDataSourceUtil.getRedisKylinUtil().set(MerchantRedisConst.INFO_FIELD_CHECKERS.concat(fieldId), vos);
return redisUtil.set(MerchantRedisConst.INFO_FIELD_CHECKERS.concat(fieldId), vos);
}
// 【场地默认验票员】删除
......@@ -102,7 +102,7 @@ public class MerchantRdmService {
return true;
}
vos.removeIf(r -> r.getFieldCheckerId().equals(vo.getFieldCheckerId()));
return redisDataSourceUtil.getRedisKylinUtil().set(MerchantRedisConst.INFO_FIELD_CHECKERS.concat(fieldId), vos);
return redisUtil.set(MerchantRedisConst.INFO_FIELD_CHECKERS.concat(fieldId), vos);
}
// 【主办】详情
......@@ -112,18 +112,18 @@ public class MerchantRdmService {
}
String key = MerchantRedisConst.INFO_SPONSOR.concat(sponsorId);
long s = System.currentTimeMillis();
MerchantSponsorsVo vo = (MerchantSponsorsVo) redisDataSourceUtil.getRedisKylinUtil().get(key);
MerchantSponsorsVo vo = (MerchantSponsorsVo) redisUtil.get(key);
log.debug("#RDM耗时:{}ms", System.currentTimeMillis() - s);
if (null == vo) {
vo = merchantMongoService.getSponsorsVoBySponsorId(sponsorId);
redisDataSourceUtil.getRedisKylinUtil().set(key, vo);
redisUtil.set(key, vo);
}
return vo;
}
// 【主办】更新详情
public boolean setSponsorsVoBySponsorId(String sponsorId, MerchantSponsorsVo vo) {
return redisDataSourceUtil.getRedisKylinUtil().set(MerchantRedisConst.INFO_SPONSOR.concat(sponsorId), vo);
return redisUtil.set(MerchantRedisConst.INFO_SPONSOR.concat(sponsorId), vo);
}
// 【主办申请】我的列表
......@@ -133,11 +133,11 @@ public class MerchantRdmService {
}
String key = MerchantRedisConst.INFO_SPONSOR_APPLIES.concat(uid);
long s = System.currentTimeMillis();
List<MerchantSponsorAppliesVo> vos = (List<MerchantSponsorAppliesVo>) redisDataSourceUtil.getRedisKylinUtil().get(key);
List<MerchantSponsorAppliesVo> vos = (List<MerchantSponsorAppliesVo>) redisUtil.get(key);
log.debug("#RDM耗时:{}ms", System.currentTimeMillis() - s);
if (null == vos) {
vos = merchantMongoService.getSponsorAppliesVosByUid(uid);
redisDataSourceUtil.getRedisKylinUtil().set(key, vos);
redisUtil.set(key, vos);
}
return vos;
}
......@@ -148,7 +148,7 @@ public class MerchantRdmService {
vos = ObjectUtil.getMerchantSponsorAppliesVoArrayList();
}
vos.add(vo);
return redisDataSourceUtil.getRedisKylinUtil().set(MerchantRedisConst.INFO_SPONSOR_APPLIES.concat(uid), vos);
return redisUtil.set(MerchantRedisConst.INFO_SPONSOR_APPLIES.concat(uid), vos);
}
// 【主办申请】删除
......@@ -157,6 +157,6 @@ public class MerchantRdmService {
return true;
}
vos.removeIf(r -> r.getSponsorApplyId().equals(vo.getSponsorApplyId()));
return redisDataSourceUtil.getRedisKylinUtil().set(MerchantRedisConst.INFO_SPONSOR_APPLIES.concat(uid), vos);
return redisUtil.set(MerchantRedisConst.INFO_SPONSOR_APPLIES.concat(uid), vos);
}
}
......@@ -151,31 +151,37 @@ public class KylinTicketTimesPartnerServiceImpl implements IKylinTicketTimesPart
}
KylinPerformanceVo vo = redisMerchantUtils.getPerformanceVo(performanceId);
KylinTicketTimesVo ticketTimesData = null;
for (int x = 0; x < vo.getTicketTimeList().size(); x++) {
ticketTimesData = vo.getTicketTimeList().get(x);
if (ticketTimesData.getTimeId().equals(ticketTimesId)) {
break;
}
}
if (ticketTimesData != null) {
if (vo.getAuditStatus() == 0) {
return ResponseDto.failure(ErrorMapping.get(20101));
if (vo == null) {
mongoMerchantUtils.delTicketTimesPartnerVo(ticketTimesId);
return ResponseDto.success("删除成功");
} else {
for (int x = 0; x < vo.getTicketTimeList().size(); x++) {
ticketTimesData = vo.getTicketTimeList().get(x);
if (ticketTimesData.getTimeId().equals(ticketTimesId)) {
break;
}
}
if (vo.getAppStatus() == 0 || vo.getAppStatus() == 4) {//未提审||被拒绝
KylinTicketTimesPartnerVo ticketTimesPartnerVo = KylinTicketTimesPartnerVo.getNew();
ticketTimesPartnerVo.setTicketTimesId(ticketTimesId);
ticketTimesPartnerVo.setUpdatedAt(updatedAt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
ticketTimesPartnerVo.setStatus(0);
mongoMerchantUtils.insertTicketTimesPartnerVo(ticketTimesPartnerVo);
log.info(UserPathDto.setPartnerData("0", "deleteTimes", "ticketTimesId=" + ticketTimesId, "删除成功"));
return ResponseDto.success("删除成功");
if (ticketTimesData != null) {
if (vo.getAuditStatus() == 0) {
return ResponseDto.failure(ErrorMapping.get(20101));
}
if (vo.getAppStatus() == 0 || vo.getAppStatus() == 4) {//未提审||被拒绝
KylinTicketTimesPartnerVo ticketTimesPartnerVo = KylinTicketTimesPartnerVo.getNew();
ticketTimesPartnerVo.setTicketTimesId(ticketTimesId);
ticketTimesPartnerVo.setUpdatedAt(updatedAt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
ticketTimesPartnerVo.setStatus(0);
mongoMerchantUtils.insertTicketTimesPartnerVo(ticketTimesPartnerVo);
log.info(UserPathDto.setPartnerData("0", "deleteTimes", "ticketTimesId=" + ticketTimesId, "删除成功"));
return ResponseDto.success("删除成功");
} else {
return ResponseDto.failure(ErrorMapping.get(20106));
}
} else {
return ResponseDto.failure(ErrorMapping.get(20106));
mongoMerchantUtils.delTicketTimesPartnerVo(ticketTimesId);
return ResponseDto.success();
}
} else {
mongoMerchantUtils.delTicketTimesPartnerVo(ticketTimesId);
return ResponseDto.success();
}
} catch (Exception e) {
log.info(UserPathDto.setPartnerData("0", "deleteTimes", "ticketTimesId=" + ticketTimesId, e));
return ResponseDto.failure(ErrorMapping.get(20102));
......
......@@ -239,6 +239,10 @@ public class KylinTicketsPartnerServiceImpl implements IKylinTicketsPartnerServi
public ResponseDto<String> deleteTicket(String ticketsId, String performanceId) {
try {
LocalDateTime updatedAt = LocalDateTime.now();
PerformancePartnerVo data = mongoMerchantUtils.getPerformancePartnerVo(performanceId);
if (data == null || data.getAuditStatus() == null || data.getAuditStatus() == 0) {
return ResponseDto.failure(ErrorMapping.get("20106"));
}
KylinPerformanceVo vo = redisMerchantUtils.getPerformanceVo(performanceId);
KylinTicketTimesVo ticketTimesData;
KylinTicketVo ticketData = null;
......@@ -253,11 +257,6 @@ public class KylinTicketsPartnerServiceImpl implements IKylinTicketsPartnerServi
}
break;
}
PerformancePartnerVo data = mongoMerchantUtils.getPerformancePartnerVo(performanceId);
if (data == null || data.getAuditStatus() == null || data.getAuditStatus() == 0) {
return ResponseDto.failure(ErrorMapping.get("20106"));
}
if (ticketData == null) {
mongoMerchantUtils.deleteTicketPartnerVo(ticketsId);
return ResponseDto.success("删除成功");
......
package com.liquidnet.service.platform.controller.kylin;
import com.liquidnet.service.platform.service.impl.kylin.KylinFreightChargeServiceImpl;
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("freightCharge")
@Slf4j
public class KylinFreightChargeController {
@Autowired
private KylinFreightChargeServiceImpl kylinFreightChargeService;
@GetMapping("get")
@ApiOperation("运费查询")
public void getFreightCharge(){
kylinFreightChargeService.getFreightCharge();
}
}
\ No newline at end of file
package com.liquidnet.service.platform.service.impl.kylin;
import com.liquidnet.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.common.cache.redis.util.RedisUtil;
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.mapper.KylinFreightChargeMapper;
import com.liquidnet.service.platform.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 RedisDataSourceUtil redisDataSourceUtil;
@Autowired
private KylinFreightChargeMapper kylinFreightChargeMapper;
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", "东城区");
String expressType = "1";
hBody.put("expressType", "1");
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);
KylinFreightChargeDao kylinFreightCharge = KylinFreightChargeDao.getNew();
kylinFreightCharge.setFieldsId(IDGenerator.nextTimeId2());
kylinFreightCharge.setProvince(jProvince);
kylinFreightCharge.setCity(jCity);
kylinFreightCharge.setAdname(jAddress);
kylinFreightCharge.setPrice(map.get("price"));
kylinFreightCharge.setAdcode(addressCode);
kylinFreightCharge.setBusinessType(map.get("businessType"));
kylinFreightCharge.setBusinessTypeDesc(map.get("businessTypeDesc"));
//存数据库
int i= kylinFreightChargeMapper.setFreightCharge(kylinFreightCharge);
//存redis
redisDataSourceUtil.getRedisKylinUtil().set(KylinRedisConst.RETURN_ADDRESS_CODE+addressCode+KylinRedisConst.EXPRESS_TYPE+expressType,kylinFreightCharge);
}catch (Exception e) {
e.printStackTrace();
log.error("顺丰接口调用失败", e);
}
}
}
package com.liquidnet.service.platform.utils;
import org.apache.http.*;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class HttpsUtils {
private static final String HTTP = "http";
private static final String HTTPS = "https";
private static SSLConnectionSocketFactory sslsf = null;
private static PoolingHttpClientConnectionManager cm = null;
private static SSLContextBuilder builder = null;
static {
try {
builder = new SSLContextBuilder();
// 全部信任 不做身份鉴定
builder.loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
}
});
sslsf = new SSLConnectionSocketFactory(builder.build(), new String[]{"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.2"}, null, NoopHostnameVerifier.INSTANCE);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register(HTTP, new PlainConnectionSocketFactory())
.register(HTTPS, sslsf)
.build();
cm = new PoolingHttpClientConnectionManager(registry);
cm.setMaxTotal(200);//max connection
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* httpClient post请求
*
* @param url 请求url
* @param header 头部信息
* @param param 请求参数 form提交适用
* @param entity 请求实体 json/xml提交适用
* @return 可能为空 需要处理
* @throws Exception
*/
public static String post(String url, Map<String, String> header, Map<String, String> param, HttpEntity entity) throws Exception {
String result = "";
CloseableHttpClient httpClient = null;
try {
httpClient = getHttpClient();
HttpPost httpPost = new HttpPost(url);
// 设置头信息
if (!CollectionUtils.isEmpty(header)) {
for (Map.Entry<String, String> entry : header.entrySet()) {
httpPost.addHeader(entry.getKey(), entry.getValue());
}
}
// 设置请求参数
if (!CollectionUtils.isEmpty(param)) {
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> entry : param.entrySet()) {
//给参数赋值
formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
httpPost.setEntity(urlEncodedFormEntity);
}
// 设置实体 优先级高
if (entity != null) {
httpPost.setEntity(entity);
}
HttpResponse httpResponse = httpClient.execute(httpPost);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
HttpEntity resEntity = httpResponse.getEntity();
result = EntityUtils.toString(resEntity);
} else {
readHttpResponse(httpResponse);
}
} catch (Exception e) {
throw e;
} finally {
if (httpClient != null) {
httpClient.close();
}
}
return result;
}
public static CloseableHttpClient getHttpClient() throws Exception {
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.setConnectionManager(cm)
.setConnectionManagerShared(true)
.build();
return httpClient;
}
public static String readHttpResponse(HttpResponse httpResponse)
throws ParseException, IOException {
StringBuilder builder = new StringBuilder();
// 获取响应消息实体
HttpEntity entity = httpResponse.getEntity();
// 响应状态
builder.append("status:" + httpResponse.getStatusLine());
builder.append("headers:");
HeaderIterator iterator = httpResponse.headerIterator();
while (iterator.hasNext()) {
builder.append("\t" + iterator.next());
}
// 判断响应实体是否为空
if (entity != null) {
String responseString = EntityUtils.toString(entity);
builder.append("response length:" + responseString.length());
builder.append("response content:" + responseString.replace("\r\n", ""));
}
return builder.toString();
}
}
\ No newline at end of file
package com.liquidnet.service.platform.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; } }}
......@@ -2,10 +2,13 @@ package com.liquidnet.service.platform.utils;
import com.liquidnet.commons.lang.constant.LnsEnum;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.entity.StringEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
......@@ -13,6 +16,8 @@ import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* <p>
......@@ -25,6 +30,13 @@ import java.util.Arrays;
@Component
@Slf4j
public class ShunfengSignUtils {
@Value("${liquidnet.express.shunfeng.appid}")
private String APP_ID;
/**
* url
*/
@Value("${liquidnet.express.shunfeng.url}")
private String URL;
/**
* sk
*/
......@@ -38,6 +50,39 @@ public class ShunfengSignUtils {
@Autowired
Environment environment;
/**
* 生成签名并请求
* @param hbody 请求body
* @return
*/
public String generateSignatureAndRequestNew(Map<String, String> hbody, String url) {
long currentTimeMillis = System.currentTimeMillis(); // 时间戳
String timestamp = currentTimeMillis + "";
hbody.put("companyId", APP_ID);
String body = JsonUtils.toJson(hbody);
// 生成签名
String sign = genSign(timestamp,body);
Map<String, String> headers = new HashMap<>();
headers.put("sendAppId", APP_ID);
headers.put("timestamp", timestamp);
headers.put("sign", sign);
headers.put("Content-Type", "application/json;charset=utf-8");
headers.put("Accept", "application/json");
Map<String, String> querys = new HashMap<>();
try {
HttpEntity httpEntity = new StringEntity(body, "utf-8");
log.info("generateSignatureAndRequestNew body:[{}], headers:[{}]", body, headers);
String post = HttpsUtils.post(URL + url, headers, querys, httpEntity);
return post;
} catch (Exception e) {
System.out.println("发送请求失败");
e.printStackTrace();
return e.getMessage();
}
}
/**
* 生成签名
* @param timestamp 时间戳
......
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