Browse Source

预约订单

yuhaitao14 7 years ago
parent
commit
bbf7dce50f

+ 0 - 1
shop/src/main/java/com/zskk/shop/controller/web/BuyOrderController.java

@@ -69,7 +69,6 @@ public class BuyOrderController extends AbstractController {
 		this.initUser(model);
 		return "/mypayedorders";
 	}
-	
 	/**
 	 * 购买
 	 * @param gid

+ 37 - 0
shop/src/main/java/com/zskk/shop/controller/web/TJCallbackController.java

@@ -0,0 +1,37 @@
+/**
+* @版权信息 (@copyright Copyright 2017-XXXX JDJR.COM All Right Reserved);
+* @see
+* @author 于海涛 京东金融【技术研发部-证券及营销平台研发部-营销平台研发部】
+* @version 1.0
+* @date 2018年6月3日
+*/
+
+package com.zskk.shop.controller.web;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import com.zskk.shop.controller.bean.ControllerResult;
+import com.zskk.shop.service.FamilyPeopleService;
+
+@Controller
+@RequestMapping("tj")
+public class TJCallbackController {
+	
+	@Autowired
+	private FamilyPeopleService familyPeopleService;
+
+	@RequestMapping("callback")
+	@ResponseBody
+	public ControllerResult callback(@RequestParam("subscribe_id") String subscribeId, 
+			@RequestParam("status") Integer status, @RequestParam(name="report_url", required=false) String reportUrl){
+		if (reportUrl == null){
+			reportUrl = "";
+		}
+		familyPeopleService.updateAppointmentStatus(subscribeId, status, reportUrl);
+		return new ControllerResult(Boolean.TRUE);
+	}
+}

+ 1 - 0
shop/src/main/java/com/zskk/shop/dao/FamilyPeopleMapper.java

@@ -32,4 +32,5 @@ public interface FamilyPeopleMapper {
 	FamilyPeopleAppointment queryAppointmentFamily(@Param("bid") Long bid, @Param("itemid") Long itemid);
 	Appointment queryAppointment(Integer id);
 	int updateAppointment(Appointment appointment);
+	int updateAppointmentStatus(@Param("tjaid") String tjaid, @Param("tjstatus") Integer tjstatus, @Param("reportUrl") String reportUrl);
 }

+ 14 - 0
shop/src/main/java/com/zskk/shop/dao/entry/FamilyPeopleAppointment.java

@@ -12,6 +12,8 @@ public class FamilyPeopleAppointment extends FamilyPeople {
 	private Integer aid;
 	private String atime;
 	private String extend;
+	private Integer tjstatus;
+	private String reportUrl;
 	public Integer getAid() {
 		return aid;
 	}
@@ -30,4 +32,16 @@ public class FamilyPeopleAppointment extends FamilyPeople {
 	public void setExtend(String extend) {
 		this.extend = extend;
 	}
+	public Integer getTjstatus() {
+		return tjstatus;
+	}
+	public void setTjstatus(Integer tjstatus) {
+		this.tjstatus = tjstatus;
+	}
+	public String getReportUrl() {
+		return reportUrl;
+	}
+	public void setReportUrl(String reportUrl) {
+		this.reportUrl = reportUrl;
+	}
 }

+ 18 - 3
shop/src/main/java/com/zskk/shop/service/FamilyPeopleService.java

@@ -41,6 +41,9 @@ public class FamilyPeopleService {
 	@Autowired
 	private TJCenterService tjCenterService;
 	
+	@Autowired
+	private GoodService goodService;
+	
 	/**
 	 * 查询家庭成员
 	 * @param uid
@@ -143,6 +146,7 @@ public class FamilyPeopleService {
 			updateMyPeople(userBean.getUserid(), people.getId(), people.getName(), people.getPhone(), people.getIdcard(), people.getSex());
 		}
 		
+		
 		Appointment appointment = new Appointment();
 		appointment.setBid(order.getId());
 		appointment.setAtime(atime);
@@ -160,18 +164,20 @@ public class FamilyPeopleService {
 		}
 
 		//向体检系统 发起体检请求
-		tjCenterService.appointment(people, order, atime, extend);
+		tjCenterService.appointment(people, order, goodService.queryOneGoodBase(item.getGid()), atime, extend);
 	}
 	
 	@Transactional
 	public Appointment change(UserBean userBean, FamilyPeople people, Appointment appointment){
 		familyPeopleMapper.updateMyPeople(people);
 		
-		//TODO 取消原有订单
+		//取消原有订单
+		tjCenterService.cancelAppointment(people, appointment);
 		
 		//重新预约
 		BuyOrder order = buyOrderService.queryBuyOrder(appointment.getBid());
-		String tjid = tjCenterService.appointment(people, order, appointment.getAtime(), appointment.getExtend());
+		BuyOrderItem item = buyOrderService.queryItem(appointment.getItemid());
+		String tjid = tjCenterService.appointment(people, order, goodService.queryOneGoodBase(item.getGid()), appointment.getAtime(), appointment.getExtend());
 		appointment.setTjaid(tjid);
 		familyPeopleMapper.updateAppointment(appointment);
 		return appointment;
@@ -195,6 +201,15 @@ public class FamilyPeopleService {
 		return familyPeopleMapper.queryAppointment(id);
 	}
 	
+	/**
+	 * 修改体检状态 
+	 * @param tjid
+	 * @param status
+	 */
+	public void updateAppointmentStatus(String tjid, Integer status, String reportUrl){
+		familyPeopleMapper.updateAppointmentStatus(tjid, status, reportUrl);
+	}
+	
 	/**
 	 * 类型 转换
 	 * @param people

+ 31 - 15
shop/src/main/java/com/zskk/shop/service/TJCenterService.java

@@ -22,8 +22,10 @@ import org.springframework.stereotype.Service;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.zskk.shop.dao.entry.Appointment;
 import com.zskk.shop.dao.entry.BuyOrder;
 import com.zskk.shop.dao.entry.FamilyPeople;
+import com.zskk.shop.dao.entry.GoodBase;
 import com.zskk.shop.exception.ErrorConstant;
 import com.zskk.shop.exception.ZSKKException;
 import com.zskk.shop.utils.HttpClient;
@@ -38,6 +40,9 @@ public class TJCenterService {
 	
 	@Value("${zskk.tjkey}")
 	private String tjkey;
+	
+	@Value("${zskk.myhost}")
+	private String myhost;
 
 	public List<String> getDJDetail(String id) {
 		String url = tjcenter + "/public/api.php/shop/getPackageDetail?id=" + id;
@@ -62,20 +67,42 @@ public class TJCenterService {
 		}
 	}
 
-	public String appointment(FamilyPeople people, BuyOrder order, String atime, String extend) {
+	public String appointment(FamilyPeople people, BuyOrder order, GoodBase good, String atime, String extend) {
 		// 调用体检系统 预约
 		Map<String, String> data = new HashMap<>();
-		data.put("name", people.getName());
+		data.put("outer_key", people.getId().toString());
+		data.put("role_name", people.getName());
 		data.put("cardtype", "身份证");
 		data.put("idcard", people.getIdcard());
 		data.put("sex", people.getSex().equals(0) ? "2" : "1"); // 体检系统 1:男 2:女
 		data.put("vip", "0");
 		data.put("age", this.getAge(people.getBirth()));
 		data.put("birth", people.getBirth());
-		data.put("package_id", this.getPackageId(order));
+		data.put("package_id", good.getPackageid());
+		data.put("package_name", good.getPackageName());
 		data.put("maketime", atime);
 		data.put("phone", people.getPhone());
+		data.put("callback_url", myhost + "tj/callback");
+		
+		String url = tjcenter + "public/api.php/shop/addSubscribe";
+		String content = this.doPost(url, data);
+		JSONObject obj = JSON.parseObject(content);
+		if (obj.containsKey("code") && obj.getInteger("code").equals(1)) {
+			return obj.getJSONObject("data").getString("subscribe_id");
+		} else {
+			throw new ZSKKException(ErrorConstant.SERVER_ERROR);
+		}
+	}
+	
+	public void cancelAppointment(FamilyPeople people, Appointment appointment){
+		Map<String, String> data = new HashMap<>();
+		data.put("id", appointment.getTjaid());
+		data.put("outer_key", people.getId().toString());
 		
+		this.doPost(tjcenter + "public/api.php/shop/cancelSubscribe", data);
+	}
+	
+	private String doPost(String url, Map<String, String> data){
 		String main 		= JSON.toJSONString(data);
 		String nonce		= UUID.randomUUID().toString().replaceAll("-", "");
 		String timestamp 	= ToolsUtil.getNow().toString();
@@ -89,15 +116,9 @@ public class TJCenterService {
 		Map<String, String> params = new HashMap<>();
 		params.put("main", main);
 		
-		String url = tjcenter + "public/api.php/shop/addSubscribe";
 		try{
 			String content = HttpClient.doPost(url, params, headers);
-			JSONObject obj = JSON.parseObject(content);
-			if (obj.containsKey("code") && obj.getInteger("code").equals(0)){
-				return obj.getJSONObject("data").getString("id");
-			}else{
-				throw new ZSKKException(ErrorConstant.SERVER_ERROR);
-			}
+			return content;
 		}catch (Exception e) {
 			LogUtil.sysError(e.getMessage(), e);
 			throw new ZSKKException(ErrorConstant.NET_ERROR);
@@ -121,11 +142,6 @@ public class TJCenterService {
 		}
 	}
 
-	// 获取套餐ID
-	private String getPackageId(BuyOrder order) {
-		return "";
-	}
-
 	private String sign(String main, String nonce, String timestamp, String secretKey){
 		StringBuffer content = new StringBuffer(main.length() + 50);
 		content.append(main).append(":").append(nonce).append(":").append(timestamp);

+ 6 - 2
shop/src/main/resource/mapper/FamilyPeopleMapper.xml

@@ -31,7 +31,8 @@
 		values(#{bid}, ${itemid}, #{fid}, #{atime}, #{extend}, #{ctime})
 	</insert>
 	<select id="queryAppointmentFamily" resultType="com.zskk.shop.dao.entry.FamilyPeopleAppointment">
-		select f.id, f.uid, f.name, f.phone, f.idcard, f.ctime, f.is_del as isDel,a.id as aid, a.atime, a.extend
+		select f.id, f.uid, f.name, f.phone, f.idcard, f.ctime, f.is_del as isDel,
+			a.id as aid, a.atime, a.extend, a.tjstatus, a.report_url as reportUrl
 		from family_people f join appointment a on f.id=a.fid
 		where a.bid=#{bid} and a.itemid=${itemid}
 		limit 1
@@ -42,7 +43,10 @@
 		where id=#{id}
 	</select>
 	<update id="updateAppointment" parameterType="com.zskk.shop.dao.entry.Appointment">
-		upadte appointment set fid=#{fid},atime=#{atime},extend=#{extend},tjaid=#{tjaid}
+		update appointment set fid=#{fid},atime=#{atime},extend=#{extend},tjaid=#{tjaid}
 		where id=#{id}
 	</update>
+	<update id="updateAppointmentStatus">
+		update appointment set tjstatus=#{tjstatus},report_url=#{reportUrl} where tjaid=#{tjaid}
+	</update>
 </mapper>

+ 5 - 2
shop/src/main/resource/templates/mypayedorders.html

@@ -50,8 +50,11 @@
                             		<div class="cBlue mt10" th:if="${item.fa == null}">适应人群:<span>*</span></div>
                             		<div class="cBlue mt10" th:if="${item.fa != null}" >体检人:<span th:text="${item.fa.name}"></span> 预约日期:<span th:text="${item.fa.atime}"></span></div>
                             	</div>
-                            	<a th:attr="href='/appointment/goappointment/'+${item.bid}+'/'+${item.id}" class="btn-blue y" th:if="${item.fa == null}">预约体检</a>
-                            	<a th:attr="href='/appointment/gochangeappointment/'+${item.fa.aid}" class="btn-blue y" th:if="${item.fa != null}" >改约</a>
+                            	<a th:if="${item.fa == null}" th:attr="href='/appointment/goappointment/'+${item.bid}+'/'+${item.id}" class="btn-blue y" >预约体检</a>
+                            	<a th:if="${item.fa != null and item.fa.tjstatus eq -1}" th:attr="href='/appointment/gochangeappointment/'+${item.fa.aid}" class="btn-blue y" >改约</a>
+                            	<a th:if="${item.fa != null and item.fa.tjstatus eq 0}" href="#" class="btn-blue y" >已登记</a>
+                            	<a th:if="${item.fa != null and item.fa.tjstatus eq 1}" href="#" class="btn-blue y" >体检结束(报告生成中)</a>
+                            	<a th:if="${item.fa != null and item.fa.tjstatus eq 2}" th:attr="href=${item.fa.reportUrl}" class="btn-blue y" target="_blank" >查看报告</a>
                             </td>
                         </tr>
                     </tbody>