Browse Source

增加顺丰快递价格查询接口

huangwenjie 7 years ago
parent
commit
d1ae75d9bc

+ 130 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/dict/DmExpressagePriceEntity.java

@ -0,0 +1,130 @@
package com.yihu.wlyy.entity.dict;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * 快递价目表
 */
@Entity
@Table(name = "dm_expressage_price", schema = "wlyy", catalog = "")
public class DmExpressagePriceEntity extends IdEntity {
    private String code;
    private String startAddressName;
    private String endAddressName;
    private Integer firstWeight;
    private Integer firstWeightPrice;
    private Integer continueWeight;
    private Integer continueWeightPrice;
    @Basic
    @Column(name = "code")
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Basic
    @Column(name = "start_address_name")
    public String getStartAddressName() {
        return startAddressName;
    }
    public void setStartAddressName(String startAddressName) {
        this.startAddressName = startAddressName;
    }
    @Basic
    @Column(name = "end_address_name")
    public String getEndAddressName() {
        return endAddressName;
    }
    public void setEndAddressName(String endAddressName) {
        this.endAddressName = endAddressName;
    }
    @Basic
    @Column(name = "first_weight")
    public Integer getFirstWeight() {
        return firstWeight;
    }
    public void setFirstWeight(Integer firstWeight) {
        this.firstWeight = firstWeight;
    }
    @Basic
    @Column(name = "first_weight_price")
    public Integer getFirstWeightPrice() {
        return firstWeightPrice;
    }
    public void setFirstWeightPrice(Integer firstWeightPrice) {
        this.firstWeightPrice = firstWeightPrice;
    }
    @Basic
    @Column(name = "continue_weight")
    public Integer getContinueWeight() {
        return continueWeight;
    }
    public void setContinueWeight(Integer continueWeight) {
        this.continueWeight = continueWeight;
    }
    @Basic
    @Column(name = "continue_weight_price")
    public Integer getContinueWeightPrice() {
        return continueWeightPrice;
    }
    public void setContinueWeightPrice(Integer continueWeightPrice) {
        this.continueWeightPrice = continueWeightPrice;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DmExpressagePriceEntity that = (DmExpressagePriceEntity) o;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (code != null ? !code.equals(that.code) : that.code != null) return false;
        if (startAddressName != null ? !startAddressName.equals(that.startAddressName) : that.startAddressName != null)
            return false;
        if (endAddressName != null ? !endAddressName.equals(that.endAddressName) : that.endAddressName != null)
            return false;
        if (firstWeight != null ? !firstWeight.equals(that.firstWeight) : that.firstWeight != null) return false;
        if (firstWeightPrice != null ? !firstWeightPrice.equals(that.firstWeightPrice) : that.firstWeightPrice != null)
            return false;
        if (continueWeight != null ? !continueWeight.equals(that.continueWeight) : that.continueWeight != null)
            return false;
        if (continueWeightPrice != null ? !continueWeightPrice.equals(that.continueWeightPrice) : that.continueWeightPrice != null)
            return false;
        return true;
    }
    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (code != null ? code.hashCode() : 0);
        result = 31 * result + (startAddressName != null ? startAddressName.hashCode() : 0);
        result = 31 * result + (endAddressName != null ? endAddressName.hashCode() : 0);
        result = 31 * result + (firstWeight != null ? firstWeight.hashCode() : 0);
        result = 31 * result + (firstWeightPrice != null ? firstWeightPrice.hashCode() : 0);
        result = 31 * result + (continueWeight != null ? continueWeight.hashCode() : 0);
        result = 31 * result + (continueWeightPrice != null ? continueWeightPrice.hashCode() : 0);
        return result;
    }
}

+ 19 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/dict/DmExpressagePriceDao.java

@ -0,0 +1,19 @@
package com.yihu.wlyy.repository.dict;
import com.yihu.wlyy.entity.dict.DmExpressagePriceEntity;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * 快递费用
 * @author huangwenjie 2017.08.03
 */
public interface DmExpressagePriceDao extends
        PagingAndSortingRepository<DmExpressagePriceEntity, Long>,
        JpaSpecificationExecutor<DmExpressagePriceEntity> {
    @Query("from DmExpressagePriceEntity where code = ?1 and endAddressName LIKE ?2 ")
    DmExpressagePriceEntity getExprePriceEntityByCodeAndEndAdressName(String code,String end_address_name);
}

+ 33 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/express/SFExpressService.java

@ -1,9 +1,11 @@
package com.yihu.wlyy.service.app.express;
import com.yihu.wlyy.entity.dict.DmExpressagePriceEntity;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressageLog;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
import com.yihu.wlyy.repository.dict.DmExpressagePriceDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.repository.prescription.PrescriptionExpressageDao;
import com.yihu.wlyy.repository.prescription.PrescriptionExpressageLogDao;
@ -59,6 +61,9 @@ public class SFExpressService extends BaseService {
    @Autowired
    private SFUtils SFUtils;
    @Autowired
    private JpaTransactionManager transactionManager;
    @Autowired
    private PrescriptionLogDao prescriptionLogDao;
@ -66,7 +71,7 @@ public class SFExpressService extends BaseService {
    private PrescriptionDao prescriptionDao;
    @Autowired
    private JpaTransactionManager transactionManager;
    private DmExpressagePriceDao dmExpressagePriceDao;
    @Autowired
    private PrescriptionExpressageLogDao prescriptionExpressageLogDao;
@ -391,13 +396,13 @@ public class SFExpressService extends BaseService {
        //根据快递单号获取处方配送详细信息
        PrescriptionExpressage sfexpress = prescriptionExpressageDao.findByPrescriptionExpressMailno(mailno);
        //根据快递单号获取本地的路由信息
        List<PrescriptionExpressageLog> localroutinfos = prescriptionExpressageLogDao.findByPrescriptionCode(sfexpress.getPrescriptionCode());
        //需要增量更新到本地的路由信息集合
        List<PrescriptionExpressageLog> newroutinfolist = new ArrayList<>();
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别,开启新事务
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事务隔离级别,开启新事务
        TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
        try {
@ -412,6 +417,7 @@ public class SFExpressService extends BaseService {
            for (PrescriptionExpressageLog pushlog: pushSFLogs) {
                //判断是否有已收件的路由节点
                if("已收件".equals(pushlog.getAcceptRemark())){
                    isContainEndRoutInfo = true;
                }
@ -429,7 +435,7 @@ public class SFExpressService extends BaseService {
                prescriptionExpressageLogDao.save(newroutinfolist);
            }
            //如果路由信息节点包含了"已收件"节点,这修改处方派送状态为完成,增加物流派送日志为完成
            //如果路由信息节点包含了"已收件"节点,则修改处方状态为完成,增加物流派送日志为完成
            if(isContainEndRoutInfo){
                //修改处方状态为完成
                prescriptionDao.updateStatus(sfexpress.getPrescriptionCode(), PrescriptionLog.PrescriptionLogStatus.finish.getValue());
@ -453,4 +459,26 @@ public class SFExpressService extends BaseService {
    }
    /**
     * 根据收寄地址获取快递费用
     * @param d_province 省份名称
     * @param d_city     城市名称
     * @return
     */
    public DmExpressagePriceEntity getSFExpressPrice(String d_province, String d_city) {
        String end_address_name = "";
        if("厦门市".equals(d_city)){
            end_address_name = "同城";
        }else{
            if("福建省".equals(d_province)){
                end_address_name = "省内";
            }else{
                end_address_name = d_city;
            }
        }
        DmExpressagePriceEntity sfprice =  dmExpressagePriceDao.getExprePriceEntityByCodeAndEndAdressName("shunfeng",end_address_name);
        return sfprice;
    }
}

+ 3 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SFUtils.java

@ -66,7 +66,7 @@ public class SFUtils {
    public String getSFOrderFilterXml(String d_address,String sf_code,String orderid,String j_tel,String j_address,String d_tel){
        //head 传入接口接入码
        StringBuilder xml = new StringBuilder("<Request service='OrderFilterService' lang='zh-cn'> <Head>"+sf_code+"</Head><Body>");
        StringBuilder xml = new StringBuilder("<Request service='OrderFilterService' lang='zh-cn'><Head>"+sf_code+"</Head><Body>");
        xml.append("<OrderFilter filter_type='1' ");
        //订单号
@ -113,7 +113,7 @@ public class SFUtils {
     */
    public String postSFOrderService(PrescriptionExpressage sfexpress_obj,String sf_code) {
        //head 传入接口接入码
        StringBuilder xml = new StringBuilder("<Request service='OrderService' lang='zh-cn'> <Head>"+sf_code+"</Head><Body>");
        StringBuilder xml = new StringBuilder("<Request service='OrderService' lang='zh-cn'><Head>"+sf_code+"</Head><Body>");
        xml.append("<Order ");
        //订单号(快递业务号作为订单号"SF开头的为顺丰快递")
        xml.append("orderid='"+sfexpress_obj.getCode()+"' ");
@ -192,7 +192,7 @@ public class SFUtils {
     */
    public String getRoutInfos(PrescriptionExpressage sfexpress_obj, String sf_code) {
        //head 传入接口接入码
        StringBuilder xml = new StringBuilder("<Request service='RouteService' lang='zh-cn'> <Head>"+sf_code+"</Head><Body>");
        StringBuilder xml = new StringBuilder("<Request service='RouteService' lang='zh-cn'><Head>"+sf_code+"</Head><Body>");
        xml.append("<RouteRequest tracking_type='1' method_type='1' ").append("tracking_number='"+sfexpress_obj.getMailno()+"' />");
        xml.append("</Body></Request>");
        return xml.toString();

+ 2 - 20
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/express/SFExpressApiController.java

@ -27,14 +27,7 @@ public class SFExpressApiController extends BaseController {
    @Autowired
    private SFExpressService sfexpressService;
    private String successxml = "<Response service=”RoutePushService”><Head>OK</Head></Response>";
    private String errorxml = "<Response service=”RoutePushService”>\n" +
            "\n" +
            "<Head>ERR</Head>\n" +
            "\n" +
            "<ERROR code=\"4001\">系统发生数据错误或运行时异常</ERROR>\n" +
            "\n" +
            "</Response>";
    private String successxml = "<Response service='RoutePushService'><Head>OK</Head></Response>";
    @RequestMapping(value="/routepushservice",method = RequestMethod.POST)
    @ResponseBody
@ -42,26 +35,15 @@ public class SFExpressApiController extends BaseController {
    @ObserverRequired
    public String SFRoutePushService (
            @ApiParam(name="xml", value="入参报文") @RequestParam(value = "xml",required = true) String xml){
        try {
            xml = URLDecoder.decode(xml,"utf-8");
            sfexpressService.SFRoutePushService(xml);
            return successxml;
        }catch (Exception e){
            //日志文件中记录异常信息
            error(e);
            //返回接口异常信息处理结果
            return "<Response service=”RoutePushService”>\n" +
                    "\n" +
                    "<Head>ERR</Head>\n" +
                    "\n" +
                    "<ERROR code=\"-1\">系统发生数据错误或运行时异常</ERROR>\n" +
                    "\n" +
                    "</Response>";
            return "<Response service='RoutePushService'><Head>ERR</Head><ERROR code='-1'>系统发生数据错误或运行时异常</ERROR></Response>";
        }
    }
}

+ 25 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/express/SFExpressController.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.web.patient.express;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.dict.DmExpressagePriceEntity;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressageLog;
@ -172,4 +173,28 @@ public class SFExpressController extends BaseController {
        }
    }
    @RequestMapping(value = "/getsfexpressprice", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("根据收寄地址获取快递费用")
    public String SFExpressPrice(
//            @ApiParam(name = "j_city", value = "寄方地址(城市),默认为厦门", defaultValue = "厦门")
//            @RequestParam(value = "j_city", required = false) String j_city,
            @ApiParam(name = "d_province", value = "收方地址(省份)")
            @RequestParam(value = "d_province", required = false) String d_province,
            @ApiParam(name = "d_city", value = "收方地址(城市)")
            @RequestParam(value = "d_city", required = false) String d_city){
        try {
            DmExpressagePriceEntity expreprice = sfexpressService.getSFExpressPrice(d_province,d_city);
            return write(200, "查询成功","data",expreprice);
        }catch (Exception e){
            //日志文件中记录异常信息
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "查询失败,"+e.getMessage());
        }
    }
}