|  | @ -0,0 +1,209 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.hospital.endpoint.expressage;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyExpressagePriceDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionExpressageDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.PrescriptionExpressageService;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.Envelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
 | 
	
		
			
				|  |  | import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiParam;
 | 
	
		
			
				|  |  | import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RequestMapping;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RequestMethod;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RequestParam;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RestController;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.net.URLDecoder;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | @RestController
 | 
	
		
			
				|  |  | @RequestMapping(value = BaseHospitalRequestMapping.Expressage.PREFIX)
 | 
	
		
			
				|  |  | @Api(value = "门诊处方快递物流管理器", description = "门诊处方快递物流管理器", tags = {"wlyy基础服务 - 门诊处方快递物流管理服务接口"})
 | 
	
		
			
				|  |  | public class ExpressageEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  |     private static Logger logger = LoggerFactory.getLogger(ExpressageEndpoint.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionExpressageService sfexpressService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private OutpatientDao outpatientDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private String successxml = "<Response service='RoutePushService'><Head>OK</Head></Response>";
 | 
	
		
			
				|  |  |     private String failedxml = "<Response service='RoutePushService'><Head>ERR</Head><ERROR code='-1'>系统发生数据错误或运行时异常</ERROR></Response>";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value="/routepushservice",method = RequestMethod.POST)
 | 
	
		
			
				|  |  |     @ApiOperation("接受顺丰推送过来的路由信息")
 | 
	
		
			
				|  |  |     public Envelop SFRoutePushService (
 | 
	
		
			
				|  |  |             @ApiParam(name="content", value="入参报文") @RequestParam(value = "content",required = true) String content){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             content = URLDecoder.decode(content,"utf-8");
 | 
	
		
			
				|  |  |             logger.info("顺丰路由信息推送,xml="+content);
 | 
	
		
			
				|  |  |             sfexpressService.SFRoutePushService(content);
 | 
	
		
			
				|  |  |             return success(successxml);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             logger.error("接收顺丰路由信息推送失败,入参xml:"+content);
 | 
	
		
			
				|  |  |             //日志文件中记录异常信息
 | 
	
		
			
				|  |  |             //返回接口异常信息处理结果
 | 
	
		
			
				|  |  |             return failed(failedxml);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value="/sfrouteserviceSearch",method = RequestMethod.GET)
 | 
	
		
			
				|  |  |     @ApiOperation("通过门诊编号查询顺丰物流派送记录")
 | 
	
		
			
				|  |  |     public Envelop SFRouteServiceSearch(@ApiParam(name="outpatientId", value="门诊编号") @RequestParam(value = "outpatientId",required = true) String outpatientId){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             List<WlyyPrescriptionExpressageDO> expressageDOList = sfexpressService.findByField("outpatientId",outpatientId);
 | 
	
		
			
				|  |  |             if(CollectionUtils.isEmpty(expressageDOList)){
 | 
	
		
			
				|  |  |                 return failed("当前门诊没有物流信息!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             WlyyPrescriptionExpressageDO sfexpress_obj = expressageDOList.get(0);
 | 
	
		
			
				|  |  |             String result  = sfexpressService.getRoutInfosSearch(sfexpress_obj);
 | 
	
		
			
				|  |  |             return success(result);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             //返回接口异常信息处理结果
 | 
	
		
			
				|  |  |             return failed( "查询失败,"+e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/getsfexpressprice", method = RequestMethod.GET)
 | 
	
		
			
				|  |  |     @ApiOperation("根据收寄地址获取快递费用")
 | 
	
		
			
				|  |  |     public Envelop 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 {
 | 
	
		
			
				|  |  |             WlyyExpressagePriceDO expreprice = sfexpressService.getSFExpressPrice(d_province,d_city);
 | 
	
		
			
				|  |  |             return success(expreprice);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             //返回接口异常信息处理结果
 | 
	
		
			
				|  |  |             return failed("获取快递费用,"+e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/sforderfilterservice", method = RequestMethod.GET)
 | 
	
		
			
				|  |  |     @ApiOperation("查询派送地址是否属于顺丰的派送范围")
 | 
	
		
			
				|  |  |     public Envelop SFOrderFilterService(
 | 
	
		
			
				|  |  |             @ApiParam(name = "d_address", value = "派送地址", defaultValue = "福建省厦门市思明区软件园二期望海路55号")
 | 
	
		
			
				|  |  |             @RequestParam(value = "d_address", required = true) String d_address){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             boolean result = sfexpressService.getSFOrderFilterService(d_address);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if(result){
 | 
	
		
			
				|  |  |                 return success("地址可派送!");
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 return failed("地址不可派送!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             return failed("异常:"+e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value="/sforderservice",method = RequestMethod.POST)
 | 
	
		
			
				|  |  |     @ApiOperation("向顺丰快递下订单")
 | 
	
		
			
				|  |  |     public Envelop SFOrderService(
 | 
	
		
			
				|  |  |             @ApiParam(name="outpatientId", value="门诊编号") @RequestParam(value = "outpatientId",required = true) String outpatientId){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             List<WlyyPrescriptionExpressageDO> expressageDOList = sfexpressService.findByField("outpatientId",outpatientId);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if(CollectionUtils.isEmpty(expressageDOList)){
 | 
	
		
			
				|  |  |                 return failed("顺丰快递下单失败,未找到该处方的派送地址!");
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 WlyyPrescriptionExpressageDO sfexpress_obj = expressageDOList.get(0);
 | 
	
		
			
				|  |  |                 //如果该处方的快递单号已生成,则说明已经下单成功,不需要重复下单,直接返回成功
 | 
	
		
			
				|  |  |                 if(StringUtils.isNotBlank(sfexpress_obj.getMailno())){
 | 
	
		
			
				|  |  |                     return success("顺丰快递下单成功!");
 | 
	
		
			
				|  |  |                 }else{
 | 
	
		
			
				|  |  |                     //如果该处方的快递单号未生成,则继续下单
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //由于下单前已经判断过是否派送,这里不再重复判断----huangwenjie-2017.08.04
 | 
	
		
			
				|  |  |                     //先判断地址是否可派送boolean delivery = sfexpressService.getSFOrderFilterService(sfexpress_obj.getProvinceName()+sfexpress_obj.getCityName()+sfexpress_obj.getTownName()+sfexpress_obj.getAddress());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //根据业务订单号判断是否已经下单成功
 | 
	
		
			
				|  |  |                     boolean go_on = sfexpressService.sfOrderSearchService(sfexpress_obj);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //如果该业务订单号未下单成功过,则重新下单
 | 
	
		
			
				|  |  |                     if(go_on){
 | 
	
		
			
				|  |  |                         //请求顺丰接口下单,成功下单后,返回快递单号
 | 
	
		
			
				|  |  |                         sfexpress_obj = sfexpressService.postSFOrderService(sfexpress_obj);
 | 
	
		
			
				|  |  |                         //保存快递单号和增加处方物流记录为配送
 | 
	
		
			
				|  |  |                         sfexpressService.updatePrescriptionExpressage(sfexpress_obj);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     return success("顺丰快递下单成功!");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             //返回接口异常信息处理结果
 | 
	
		
			
				|  |  |             return failed(e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value="/sfgetorderinfoservice",method = RequestMethod.GET)
 | 
	
		
			
				|  |  |     @ApiOperation("通过门诊编号查询顺丰快递单信息(不包含物流记录)")
 | 
	
		
			
				|  |  |     public Envelop SFGetOrderInfo(
 | 
	
		
			
				|  |  |             @ApiParam(name="outpatientId", value="门诊编号") @RequestParam(value = "outpatientId",required = true) String outpatientId){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             List<WlyyPrescriptionExpressageDO> expressageDOList = sfexpressService.findByField("outpaitentId",outpatientId);
 | 
	
		
			
				|  |  |             if(CollectionUtils.isEmpty(expressageDOList)){
 | 
	
		
			
				|  |  |                 return failed( "查询失败,");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             WlyyPrescriptionExpressageDO sfexpress_obj = expressageDOList.get(0);
 | 
	
		
			
				|  |  |             return success(sfexpress_obj);
 | 
	
		
			
				|  |  |         }catch (Exception e) {
 | 
	
		
			
				|  |  |             return failed("查询失败," + e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value="/sfordersearchservice",method = RequestMethod.GET)
 | 
	
		
			
				|  |  |     @ApiOperation("通过门诊编号查询顺丰快递是否下单成功")
 | 
	
		
			
				|  |  |     public Envelop SFOrderSearchService(
 | 
	
		
			
				|  |  |             @ApiParam(name="outpatientId", value="门诊编号") @RequestParam(value = "outpatientId",required = true) String outpatientId){
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionExpressageDO> expressageDOList = sfexpressService.findByField("outpaitentId",outpatientId);
 | 
	
		
			
				|  |  |         if(CollectionUtils.isEmpty(expressageDOList)){
 | 
	
		
			
				|  |  |             return failed( "查询失败,");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             WlyyPrescriptionExpressageDO sfexpress_obj = expressageDOList.get(0);
 | 
	
		
			
				|  |  |             boolean go_on = sfexpressService.sfOrderSearchServiceJustSearch(sfexpress_obj);
 | 
	
		
			
				|  |  |             return success(go_on);
 | 
	
		
			
				|  |  |         }catch (Exception e) {
 | 
	
		
			
				|  |  |             return failed("查询失败," + e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value="/sforderConfirm",method = RequestMethod.GET)
 | 
	
		
			
				|  |  |     @ApiOperation("通过快递单号取消快递")
 | 
	
		
			
				|  |  |     public Envelop sforderConfirm(
 | 
	
		
			
				|  |  |             @ApiParam(name="mailno", value="快递单号") @RequestParam(value = "mailno",required = true) String mailno){
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionExpressageDO> expressageDOList = sfexpressService.findByField("mailno",mailno);
 | 
	
		
			
				|  |  |         if(CollectionUtils.isEmpty(expressageDOList)){
 | 
	
		
			
				|  |  |             return failed( "当前快递单号的门诊不存在,");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             WlyyPrescriptionExpressageDO sfexpress_obj = expressageDOList.get(0);
 | 
	
		
			
				|  |  |             String result = sfexpressService.postOrderConfirmService(sfexpress_obj);
 | 
	
		
			
				|  |  |             return success(result);
 | 
	
		
			
				|  |  |         }catch (Exception e) {
 | 
	
		
			
				|  |  |             return failed("异常," + e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |