123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- package com.chinacreator.videoalliance.order.action;
- import com.chinacreator.common.exception.BusinessException;
- import com.chinacreator.common.pipe.DataOutPipe;
- import com.chinacreator.common.util.DESUtil;
- import com.chinacreator.common.util.RequestUtil;
- import com.chinacreator.common.util.URLUtil;
- import com.chinacreator.videoalliance.common.annotation.DataOut;
- import com.chinacreator.videoalliance.common.dao.DictionaryDao;
- import com.chinacreator.videoalliance.common.util.ConfigUtil;
- import com.chinacreator.videoalliance.order.bean.EcbProductInfo;
- import com.chinacreator.videoalliance.order.bean.OrderInfo;
- import com.chinacreator.videoalliance.order.dao.CsOrderControlDao;
- import com.chinacreator.videoalliance.order.service.OrderService;
- import com.chinacreator.videoalliance.order.util.JsonUtil;
- import com.chinacreator.videoalliance.query.dao.ChangshiDebugDao;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import javax.servlet.http.HttpServletRequest;
- import java.io.UnsupportedEncodingException;
- import java.util.HashMap;
- import java.util.Map;
- @Controller
- public class CSChannleOrderAction {
- @Autowired
- private OrderService orderService;
- @Autowired
- private CsOrderControlDao csOrderControlDao;
- @Autowired
- private ChangshiDebugDao changshiDebugDao;
- @Autowired
- private DictionaryDao dictionaryDao;
- @RequestMapping({ "/cschannelorder.do" })
- @DataOut(callback = "cschannelorder")
- public DataOutPipe doOrder(HttpServletRequest request, OrderInfo orderInfo, String orderType, String channel,
- String productinfos,String sign) throws Exception {
- long begintime = System.currentTimeMillis();
- orderInfo.setTimes(begintime+"");
- String result = "0";
- DataOutPipe pipe = new DataOutPipe();
- try {
- if(StringUtils.isEmpty(productinfos)){
- throw new BusinessException("7002", "参数无效");
- }
- EcbProductInfo ecbProductInfo = (EcbProductInfo) JsonUtil.jsonToBean(productinfos, EcbProductInfo.class);
- String userid = orderInfo.getUserid();
- if (StringUtils.isEmpty(userid)) {
- throw new BusinessException("7002", "手机号码无效");
- }
- if (StringUtils.isEmpty(orderType) || (!orderType.equals("1") && !orderType.equals("0"))) {
- throw new BusinessException("7002", "操作类型无效无效");
- }
- try {
- orderInfo.setUserid(ConfigUtil.decrypt(userid, orderInfo.getCpid()));
- if ((orderInfo.getUserid() != null) && (orderInfo.getUserid().length() > 11)) {
- orderInfo.setUserid(ConfigUtil.getUserid(orderInfo.getUserid(), orderInfo.getCpid()));
- }
- } catch (Exception e) {
- throw new BusinessException("7002", "手机号码无效");
- }
- if(!changshiDebugDao.query(orderInfo.getUserid())){
- if(StringUtils.isEmpty(sign)){
- throw new BusinessException("7002", "参数无效");
- }
- if(!sign.equals(DESUtil.encode(orderInfo.getUserid()+ecbProductInfo.getProductId()+ecbProductInfo.getPackageCode()+ecbProductInfo.getDiscntCode()+ecbProductInfo.getDiscntValue(), "chsh5a1d"))){
- throw new BusinessException("9999", "订购失败");
- }
- }
- //System.out.println("+++++++orderType:"+orderType+"+++++++cpid:"+orderInfo.getCpid()+">>>>spid:"+orderInfo.getSpid()+">>>>>DiscntFee:"+ecbProductInfo.getDiscntFee()+">>>>DiscntValue:"+ecbProductInfo.getDiscntValue());
- orderInfo.setApptype(RequestUtil.getMobType(request));
- if (orderType.equals("0")) {//订购
- if("1150".equals(orderInfo.getSpid())){
- //20190628,xu.zhou 下线订购无限畅视产品
- throw new BusinessException("7020", "该产品已下线。");
- }
- //20190301,只允许畅视20元高清产品订购
- if("changshi".equals(orderInfo.getCpid()) && "1150".equals(orderInfo.getSpid())
- && "2000".equals(ecbProductInfo.getDiscntFee()) && "1".equals(ecbProductInfo.getDiscntValue())){
- //畅视20元高清产品,允许订购
- }else{
- throw new BusinessException("9923", "非畅视产品20元资费,不能订购");
- }
- if(!changshiDebugDao.query(orderInfo.getUserid())){
- if(ecbProductInfo.getDiscntCode().equals("8217798") || ecbProductInfo.getDiscntFee().equals("0")){
- throw new BusinessException("8006", "订购失败");
- }
- }
- orderInfo.setStatus(0);
- orderInfo.setOrderchannel(channel);
- orderInfo.setOrderstatus(2);
- orderInfo.setEndtime(ecbProductInfo.getDiscntEndDate());
- orderService.checkOrder(orderInfo);
- this.orderService.order(orderInfo, ecbProductInfo);
- } else {//退订
- orderInfo.setStatus(1);
- orderInfo.setOrderstatus(4);
- orderInfo.setCancelchannel(channel);
- orderService.checkCancelOrder(orderInfo);
- this.orderService.cancelOrder(orderInfo, ecbProductInfo);
- }
- if(orderInfo.getCpid().equals("changshi") && orderInfo.getSpid().equals("1150")){
- insertOrderMq(orderInfo, orderType, ecbProductInfo);
- insertHisMq(orderInfo, orderType);
- }
- } catch (Exception e) {
- result = "8000";
- if (e instanceof BusinessException) {
- result = ((BusinessException) e).getCode();
- }
- throw e;
- } finally {
- long endtime = System.currentTimeMillis();
- long times = (begintime - endtime);
- if (times > 5000) {
- Map<String, String> map = new HashMap<String, String>();
- map.put("userid", orderInfo.getUserid());
- map.put("cpid", orderInfo.getCpid());
- map.put("spid", orderInfo.getSpid());
- map.put("result", result);
- map.put("channel", channel);
- if ((!result.equals("0")) && (times > 5000 && times < 30000)) {
- map.put("style", "0");
- } else if ((!result.equals("0")) && (times > 30000)) {
- map.put("style", "1");
- } else if (result.equals("0")) {
- if(!orderInfo.getSpid().equals("1150")){
- map.put("style", "3");
- }
- }
- map.put("times", times + "");
- map.put("orderType", orderType);
- map.put("type", "cssms");
- URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
- //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
- }
- }
- return pipe;
- }
- public void insertOrderMq(OrderInfo orderInfo, String orderType, EcbProductInfo ecbProductInfo) {
- try {
- if (!csOrderControlDao.discntFeeControl(ecbProductInfo.getDiscntCode(), orderInfo.getCpid(),
- orderInfo.getSpid())) {
- Map<String, String> map = new HashMap<String, String>();
- map.put("userid", orderInfo.getUserid());
- map.put("cpid", orderInfo.getCpid());
- map.put("spid", orderInfo.getSpid());
- map.put("province", orderInfo.getProvince());
- map.put("area", orderInfo.getArea());
- map.put("ordertime", orderInfo.getOrdertime());
- map.put("canceltime", orderInfo.getCanceltime());
- if (orderType.equals("0")) {
- map.put("status", "0");
- } else {
- map.put("status", "1");
- }
- map.put("orderchannel", orderInfo.getOrderchannel());
- map.put("cancelchannel", orderInfo.getCancelchannel());
- map.put("videoid", orderInfo.getVideoid());
- map.put("type", "order");
- //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
- URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
- if(orderType.equals("0")){
- map = new HashMap<String, String>();
- map.put("userid", orderInfo.getUserid());
- map.put("cpid", orderInfo.getCpid());
- map.put("spid", orderInfo.getSpid());
- map.put("result", "0");
- map.put("channel", orderInfo.getOrderchannel());
- map.put("style", "6");
- map.put("times","");
- map.put("orderType", orderType);
- map.put("type", "cssms");
- //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
- URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void insertHisMq(OrderInfo orderInfo, String orderType) {
- try {
- if(orderInfo.getSpid().equals("1150")){
- Map<String, String> map = new HashMap<String, String>();
- map.put("userid", orderInfo.getUserid());
- map.put("cpid", orderInfo.getCpid());
- map.put("spid", orderInfo.getSpid());
- map.put("histype", "1");
- if (orderType.equals("0")) {
- map.put("result", "1");
- } else {
- map.put("result", "2");
- }
- map.put("vipcode", "");
- map.put("vipcpid", "");
- map.put("type", "cshis");
- //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
- URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) throws UnsupportedEncodingException, BusinessException, Exception {
- }
- }
|