|
@@ -7,7 +7,9 @@ import com.miaxis.common.constant.Constants;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.AesUtil;
|
|
|
+import com.miaxis.feign.dto.FilmDTO;
|
|
|
import com.miaxis.film.domain.FilmOrder;
|
|
|
+import com.miaxis.film.dto.FilmOrderNotifyDTO;
|
|
|
import com.miaxis.film.dto.FilmWxpayDTO;
|
|
|
import com.miaxis.film.service.IFilmOrderService;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -18,6 +20,9 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -43,6 +48,12 @@ public class NotifyController {
|
|
|
@Autowired
|
|
|
private IFilmOrderService filmOrderService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
+
|
|
|
+ @Value("${film.notifyUrl}")
|
|
|
+ private String notifyUrl ;
|
|
|
+
|
|
|
/**
|
|
|
* 微信支付回调接口
|
|
|
*/
|
|
@@ -56,13 +67,43 @@ public class NotifyController {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(resourceString);
|
|
|
//将回调数据写入数据库
|
|
|
writeNotifyDataToDb(jsonObject);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
WxNotifyReturnDTO wxNotifyReturnDTO = new WxNotifyReturnDTO();
|
|
|
wxNotifyReturnDTO.setCode("SUCCESS");
|
|
|
wxNotifyReturnDTO.setMessage("成功");
|
|
|
return wxNotifyReturnDTO;
|
|
|
}
|
|
|
|
|
|
- private void writeNotifyDataToDb(JSONObject jsonObject) {
|
|
|
+ /**
|
|
|
+ * 电影回调接口
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/filmOrder")
|
|
|
+ @ApiOperation("电影订单回调")
|
|
|
+ public FilmNotifyReturnDTO filmOrderNotify(@RequestBody FilmOrderNotifyDTO filmOrderNotifyDTO) throws GeneralSecurityException, IOException {
|
|
|
+ FilmOrder filmOrder = filmOrderService.getByOutTradeNo(filmOrderNotifyDTO.getThirdOrderId());
|
|
|
+ //todo 检查sign
|
|
|
+ filmOrder.setOrderState(filmOrderNotifyDTO.getEventName());
|
|
|
+ filmOrder.setOrderPrice(Integer.valueOf(filmOrderNotifyDTO.getOrderPrice()));
|
|
|
+ filmOrder.setCloseCause(filmOrderNotifyDTO.getCloseCause());
|
|
|
+ filmOrder.setRealSeat(filmOrderNotifyDTO.getRealSeat());
|
|
|
+ filmOrder.setTicketCode(filmOrderNotifyDTO.getTicketCode());
|
|
|
+ filmOrder.setTicketImage(filmOrderNotifyDTO.getTicketImage());
|
|
|
+ filmOrderService.updateById(filmOrder);
|
|
|
+
|
|
|
+
|
|
|
+ FilmNotifyReturnDTO filmNotifyReturnDTO = new FilmNotifyReturnDTO();
|
|
|
+ filmNotifyReturnDTO.setCode("200");
|
|
|
+ filmNotifyReturnDTO.setMessage("请求成功");
|
|
|
+ return filmNotifyReturnDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void writeNotifyDataToDb(JSONObject jsonObject) {
|
|
|
String outTradeNo = jsonObject.getString("out_trade_no");
|
|
|
FilmOrder filmOrder = filmOrderService.getByOutTradeNo(outTradeNo);
|
|
|
if (filmOrder == null) {
|
|
@@ -85,8 +126,39 @@ public class NotifyController {
|
|
|
if (sceneInfo != null){
|
|
|
filmOrder.setDeviceId(sceneInfo.getString("device_id"));
|
|
|
}
|
|
|
- filmOrderService.updateById(filmOrder);
|
|
|
+ //如果订单还未下过电影票订单,则异步调用电影下单api
|
|
|
+ String orderState = filmOrder.getOrderState();
|
|
|
+ if (orderState == null){
|
|
|
+ threadPoolTaskExecutor.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ FilmDTO filmDTO = new FilmDTO();
|
|
|
+ filmDTO.setUrl("api/order/create");
|
|
|
+ StringBuffer paramData = new StringBuffer();
|
|
|
+ paramData.append("showId="+filmOrder.getShowId()+"&");
|
|
|
+ paramData.append("seat="+filmOrder.getSeat()+"&");
|
|
|
+ if (filmOrder.getReservedPhone() != null){
|
|
|
+ paramData.append("reservedPhone="+filmOrder.getReservedPhone()+"&");
|
|
|
+ }
|
|
|
+ paramData.append("thirdOrderId="+filmOrder.getOutTradeNo()+"&");
|
|
|
+ paramData.append("notifyUrl="+notifyUrl+"&");
|
|
|
+ if (filmOrder.getSeatId() != null){
|
|
|
+ paramData.append("seatId="+filmOrder.getSeatId()+"&");
|
|
|
+ }
|
|
|
+ if (filmOrder.getSeatNo() != null){
|
|
|
+ paramData.append("seatNo="+filmOrder.getSeatNo()+"&");
|
|
|
+ }
|
|
|
+ paramData.append("acceptChangeSeat="+filmOrder.getAcceptChangeSeat());
|
|
|
+ try {
|
|
|
+ filmOrderService.excuteFilmApi(filmDTO);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
+ filmOrderService.updateById(filmOrder);
|
|
|
}
|
|
|
@Data
|
|
|
public class WxNotifyReturnDTO {
|
|
@@ -94,4 +166,11 @@ public class NotifyController {
|
|
|
String message;
|
|
|
}
|
|
|
|
|
|
+ @Data
|
|
|
+ public class FilmNotifyReturnDTO {
|
|
|
+ String code;
|
|
|
+ String message;
|
|
|
+ Boolean success;
|
|
|
+ }
|
|
|
+
|
|
|
}
|