package com.chinacreator.videoalliance.order.action; import com.chinacreator.common.exception.BusinessException; import com.chinacreator.common.util.AESUtil; import com.chinacreator.common.util.URLUtil; import com.chinacreator.common.util.UsermobUtil; import com.chinacreator.videoalliance.common.bean.AreaInfo; import com.chinacreator.videoalliance.common.util.AreaUtil; import com.chinacreator.videoalliance.order.bean.ChannelOrgBean; import com.chinacreator.videoalliance.order.bean.ChannelSyncBean; import com.chinacreator.videoalliance.order.bean.OrderInfo; import com.chinacreator.videoalliance.order.bean.SPInfo; import com.chinacreator.videoalliance.order.dao.ChannelDao; import com.chinacreator.videoalliance.order.dao.SPDao; import com.chinacreator.videoalliance.order.service.OrderService; import com.chinacreator.videoalliance.order.util.JsonUtil; 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 org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.Map; @Controller public class ChannelSyncAction { @Autowired private OrderService orderService; @Autowired private SPDao spDao; @Autowired private ChannelDao channelDao; @RequestMapping({"/channelSync.do"}) @ResponseBody public Object doOrder(HttpServletRequest request) throws Exception { Map pipe = new HashMap(); String resultcode = "0"; String resultinfo = ""; try{ String requestStr = URLUtil.readInputStream(request.getInputStream()); Map map = JsonUtil.jsonToMap(requestStr); String channelcode = (String)map.get("channelcode"); String syncOrder = (String)map.get("syncOrder"); ChannelSyncBean bean = null; ChannelOrgBean channelBean = channelDao.findByChannelId(channelcode); if(channelBean == null || !channelBean.getStatus().equals("0")){ throw new BusinessException("9040", "渠道同步已关闭"); } try{ String desSyncOrder = AESUtil.decrypt(syncOrder, channelBean.getPassword()); bean = (ChannelSyncBean) JsonUtil.jsonToBean(desSyncOrder, ChannelSyncBean.class); if(StringUtils.isEmpty(bean.getProductid()) && StringUtils.isEmpty(bean.getType()) && StringUtils.isEmpty(bean.getUpdateTime()) && StringUtils.isEmpty(bean.getUserid()) ){ throw new BusinessException("9036", "渠道同步参数错误"); } }catch(Exception e){ throw new BusinessException("9036", "渠道同步参数错误"); } SPInfo spInfo = spDao.findByVacId(bean.getProductid()); if(spInfo == null){ throw new BusinessException("9037", "渠道同步产品id验证失败"); } if(!UsermobUtil.isValid(bean.getUserid())){ throw new BusinessException("9038", "渠道同步产品手机号码验证失败"); } if(!(bean.getType().equals("0") || bean.getType().equals("1"))){ throw new BusinessException("9039", "渠道同步产品操作验证失败"); } OrderInfo orderInfo =new OrderInfo(); orderInfo.setUserid(bean.getUserid()); orderInfo.setCpid(spInfo.getCpid()); orderInfo.setSpid(spInfo.getSpid()); AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(bean.getUserid()); if (areaInfo == null) { areaInfo = new AreaInfo(); } orderInfo.setProvince(areaInfo.getProvince()); orderInfo.setArea(areaInfo.getArea()); orderInfo.setPaytype(2); if(bean.getType().equals("0")){ orderInfo.setStatus(0); orderInfo.setOrdertime(bean.getUpdateTime()); orderInfo.setOrderchannel(channelcode); orderInfo.setOrderstatus(3); orderService.order(orderInfo); }else{ orderInfo.setStatus(1); orderInfo.setOrderstatus(5); orderInfo.setCanceltime(bean.getUpdateTime()); orderInfo.setCancelchannel(channelcode); orderService.cancelOrder(orderInfo); } }catch(Exception e){ e.printStackTrace(); if(e instanceof BusinessException){ resultcode = ((BusinessException) e).getCode(); resultinfo = ((BusinessException) e).getMessage(); }else{ resultcode = "8000"; resultinfo = "系统忙"; } }finally { pipe.put("resultcode", resultcode); pipe.put("resultinfo", resultinfo); } return pipe; } public static void main(String[] args) throws Exception { Map map = new HashMap(); Map syncmap = new HashMap(); syncmap.put("userid", "18574414678"); syncmap.put("productid", "8000610900"); syncmap.put("type", "0"); syncmap.put("updateTime", "20170605235959"); map.put("channelcode", "hnsync"); map.put("syncOrder", AESUtil.encrypt(JsonUtil.objectToJson(syncmap), "exsgt73abb2f4521")); String result = URLUtil.post("http://114.255.201.228:86/videoif/channelSync.do", JsonUtil.objectToJson(map)); System.out.println(result); } }