123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- package com.chinacreator.videoalliance.order.action;
- import com.chinacreator.cache.util.AESUtil;
- import com.chinacreator.common.exception.BusinessException;
- import com.chinacreator.common.util.URLUtil;
- import com.chinacreator.videoalliance.common.dao.DictionaryDao;
- import com.chinacreator.videoalliance.order.bean.OrderInfo;
- import com.chinacreator.videoalliance.order.bean.QueryOrder;
- import com.chinacreator.videoalliance.order.bean.SPInfo;
- import com.chinacreator.videoalliance.order.dao.OrderDao;
- import com.chinacreator.videoalliance.order.dao.SPDao;
- import com.chinacreator.videoalliance.order.service.OrderService;
- import com.chinacreator.videoalliance.order.util.ExternalUtil;
- import com.chinacreator.videoalliance.order.util.JsonUtil;
- import net.sf.json.JSONObject;
- import net.sf.json.JSONSerializer;
- 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 javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @Controller
- public class ExternalOrderAction
- {
- @Autowired
- private OrderService orderService;
- @Autowired
- private SPDao spDao;
- @Autowired
- private OrderDao orderDao;
- @Autowired
- private DictionaryDao dictionaryDao;
- @RequestMapping({"/orderex.do"})
- public void Order(HttpServletRequest request, HttpServletResponse response)
- {
- String resultcode = "0";
- String resultinfo = "操作成功";
- String channelcode = null;
- String params = null;
- Map<String,String> map = new HashMap<String,String>();
- try
- {
- params = URLUtil.readInputStream(request.getInputStream());
- JSONObject jsonobj = JSONObject.fromObject(params);
- if (!jsonobj.containsKey("channelcode")) {
- throw new BusinessException("5101", "渠道编码无效", new String[0]);
- }
- channelcode = jsonobj.getString("channelcode");
- String password = getValue(channelcode);
- if (password == null) {
- throw new BusinessException("5101", "渠道编码无效", new String[0]);
- }
- params = jsonobj.getString("order");
- if (StringUtils.isEmpty(params)) {
- throw new BusinessException("8002", "参数无效", new String[0]);
- }
- params = AESUtil.decrypt(params, password);
- jsonobj = JSONObject.fromObject(params);
- String productid = ExternalUtil.getValue(jsonobj, "productid", "产品编码");
- OrderInfo orderinfo = toBean(jsonobj, channelcode);
- SPInfo info = this.spDao.findByVacId(productid);
- orderinfo.setSpid(info.getSpid());
- orderinfo.setCpid(info.getCpid());
- this.orderService.checkOrder(orderinfo);
- this.orderService.order(orderinfo);
- try{
- Map<String,String> mqmap = new HashMap<String, String>();
- mqmap.put("userid", orderinfo.getUserid());
- mqmap.put("cpid",orderinfo.getCpid());
- mqmap.put("spid", orderinfo.getSpid());
- mqmap.put("province", orderinfo.getProvince());
- mqmap.put("area", orderinfo.getArea());
- mqmap.put("ordertime", orderinfo.getOrdertime());
- mqmap.put("canceltime", "");
- mqmap.put("status", "0");
- mqmap.put("orderchannel", "spfbtx8");
- mqmap.put("cancelchannel", "");
- mqmap.put("videoid", orderinfo.getVideoid());
- mqmap.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));
- }catch(Exception e){
- e.printStackTrace();
- }
- } catch (Exception e) {
- if ((e instanceof BusinessException)) {
- BusinessException be = (BusinessException)e;
- resultcode = be.getCode();
- resultinfo = be.getMessage();
- } else {
- resultcode = "8000";
- resultinfo = "系统忙,请稍候再试";
- }
- }
- map.put("resultcode", resultcode);
- map.put("resultinfo", resultinfo);
- println(response, JSONSerializer.toJSON(map).toString());
- }
- @RequestMapping({"/queryorderex.do"})
- public void QueryOrder(HttpServletRequest request, HttpServletResponse response)
- {
- String resultcode = "0";
- String resultinfo = "操作成功";
- String channelcode = null;
- String params = null;
- String userid = "";
- Map<String,Object> map = new HashMap<String,Object>();
- List<QueryOrder> lists = new ArrayList<QueryOrder>();
- try {
- params = URLUtil.readInputStream(request.getInputStream());
- JSONObject jsonobj = JSONObject.fromObject(params);
- if (!jsonobj.containsKey("channelcode")) {
- throw new BusinessException("5101", "渠道编码无效", new String[0]);
- }
- channelcode = jsonobj.getString("channelcode");
- String password = getValue(channelcode);
- if (password == null) {
- throw new BusinessException("5101", "渠道编码无效", new String[0]);
- }
- userid = jsonobj.getString("userid");
- userid = AESUtil.decrypt(userid, password);
- List<OrderInfo> list = queryOrder(userid);
- for (OrderInfo bean : list) {
- QueryOrder order = new QueryOrder();
- order.setProductid(bean.getProductid());
- order.setExpiredate(bean.getOrdertime());
- order.setEffectivedate(bean.getEndtime());
- lists.add(order);
- }
- } catch (Exception e) {
- if ((e instanceof BusinessException)) {
- BusinessException be = (BusinessException)e;
- resultcode = be.getCode();
- resultinfo = be.getMessage();
- } else {
- resultcode = "8000";
- resultinfo = "系统忙,请稍候再试";
- }
- }
- map.put("resultcode", resultcode);
- map.put("resultinfo", resultinfo);
- map.put("userinfo", lists);
- println(response, JSONSerializer.toJSON(map).toString());
- }
- private OrderInfo toBean(JSONObject json, String channelcode)
- throws Exception
- {
- String userid = ExternalUtil.getValue(json, "userid", "手机号码");
- OrderInfo orderBean = new OrderInfo();
- if (ExternalUtil.isValid(userid))
- userid = ExternalUtil.format(userid);
- else {
- throw new BusinessException("7002", "手机号码无效", new String[0]);
- }
- orderBean.setUserid(userid);
- orderBean.setApptype("");
- orderBean.setStatus(0);
- orderBean.setOrderchannel(channelcode);
- orderBean.setOrderstatus(2);
- orderBean.setOrdertype(0);
- return orderBean;
- }
- public String getValue(String key)
- throws BusinessException
- {
- try
- {
- return this.orderDao.getValue(key); } catch (SQLException e) {
- }
- throw new BusinessException("5101", "渠道编码无效", new String[0]);
- }
- public List<OrderInfo> queryOrder(String userid)
- throws SQLException
- {
- return this.orderDao.findByUser(userid);
- }
- public void println(HttpServletResponse res, String message)
- {
- PrintWriter out = null;
- try {
- res.setCharacterEncoding("UTF-8");
- out = res.getWriter();
- out.print(message);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (out != null) {
- out.flush();
- out.close();
- }
- }
- }
- }
|