5ca2853204db9871f8ebcab82304f0fd88547213.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package com.chinacreator.process.job;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.chinacreator.process.bean.BoYuanBean;
  5. import com.chinacreator.process.bean.BoYuanLogBean;
  6. import com.chinacreator.process.bean.BoYuanPushBean;
  7. import com.chinacreator.process.dao.BoYuanSyncDao;
  8. import com.chinacreator.process.dao.DictionaryDao;
  9. import com.chinacreator.process.util.HttpBoYuanInvoke;
  10. import com.chinacreator.process.util.JsonUtil;
  11. import com.chinacreator.process.util.fakeid.MD5;
  12. import org.apache.log4j.Logger;
  13. import org.quartz.DisallowConcurrentExecution;
  14. import org.quartz.PersistJobDataAfterExecution;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import java.math.BigDecimal;
  17. import java.text.SimpleDateFormat;
  18. import java.util.*;
  19. /**
  20. * 后向送会员异步处理
  21. * @author xu.zhou
  22. * @date 20200818
  23. */
  24. @PersistJobDataAfterExecution
  25. @DisallowConcurrentExecution
  26. public class BoYuanSyncJob {
  27. private static Logger logger = Logger.getLogger("boyuan");
  28. @Autowired
  29. private BoYuanSyncDao boYuanSyncDao;
  30. @Autowired
  31. private DictionaryDao dictionaryDao;
  32. public void doProcess() throws Exception {
  33. logger.info("铂源数据推送定时任务开始========");
  34. long beginTime = System.currentTimeMillis();
  35. // BoYuanSyncDao boYuanSyncDao = new BoYuanSyncDao();
  36. List<BoYuanBean> list = boYuanSyncDao.findSyncData();
  37. if(list != null && list.size()>0){
  38. //将list封装成要发送的list数据
  39. List<BoYuanPushBean> pushList = convertData(list);
  40. String jsonParams = JsonUtil.objectToJson(pushList);
  41. // String jsonParams= jsonParams1.length()>1000?jsonParams1.substring(0,1000):jsonParams1;
  42. //批量推送
  43. String result = syncBoYuanBatch(pushList);
  44. if(result!= null && !result.equals("")){
  45. //解析json
  46. JSONObject jo = JSON.parseObject(result);
  47. String code = jo.getString("code");//获取code的值
  48. //{"code":10000,"message":"操作成功","data":"订购成功"}
  49. //0:已同步 1:未同步 2:正在同步中 3:同步失败
  50. String status = "3";
  51. String synctime = getDateStr(new Date());
  52. logger.info(synctime+"=====发送报文:【"+jsonParams+"】响应报文:【"+result+"】");
  53. if(code!= null && code.equals("10000")) //成功
  54. status = "0";
  55. for(BoYuanBean bean: list){
  56. bean.setStatus(status);
  57. bean.setSynctime(synctime);
  58. bean.setInputparams(synctime);
  59. bean.setOutparams(result);
  60. BoYuanLogBean logBean = new BoYuanLogBean();
  61. logBean.setSyncid(bean.getId());
  62. logBean.setUserid(bean.getUserid());
  63. logBean.setSpid(bean.getSpid());
  64. logBean.setCpid(bean.getCpid());
  65. logBean.setType(bean.getType());
  66. logBean.setSynctime(synctime);
  67. logBean.setInputtime(getDateStr(new Date()));
  68. logBean.setInputparams(jsonParams);
  69. logBean.setOutparams(result);
  70. logBean.setInputparamsback(synctime);
  71. //1修改主表数据
  72. boYuanSyncDao.updateBoYuan(bean);
  73. //2插入日志表数据
  74. boYuanSyncDao.insertBoYuanLogBean(logBean);
  75. }
  76. }
  77. }
  78. logger.info("铂源数据推送定时任务完成,耗时:"+(System.currentTimeMillis()-beginTime)/1000+" 秒");
  79. logger.info("铂源数据推送定时任务结束!");
  80. }
  81. //获取系统时间
  82. public String getDateStr(Date date) {
  83. SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
  84. String dateString = formatter.format(date);
  85. return dateString;
  86. }
  87. //将金额转换成2位小数
  88. public String getPrice(String param){
  89. String price = "0.00";
  90. if(param!= null && !param.equals("")) {
  91. BigDecimal b = new BigDecimal(param);
  92. price = b.setScale(2,BigDecimal.ROUND_HALF_UP).toString();
  93. }
  94. return price;
  95. }
  96. //将数据进行封装
  97. public List<BoYuanPushBean> convertData(List<BoYuanBean> list){
  98. List<BoYuanPushBean> pushList = new ArrayList<BoYuanPushBean>();
  99. String timestamp = System.currentTimeMillis() / 1000 + "";
  100. String channel = "af1af29d8821db08342578755f8c30a6";
  101. String secretkey = "f589b0116f63d840483833a0ef094645";
  102. for (BoYuanBean bean:list ) {
  103. BoYuanPushBean pushBean = new BoYuanPushBean();
  104. pushBean.setSpid(bean.getSpid());
  105. pushBean.setMoney(getPrice(bean.getPrice()));
  106. pushBean.setOrderid(bean.getId());
  107. pushBean.setPhone(bean.getUserid());
  108. pushBean.setChannel(channel);
  109. pushBean.setType(bean.getType());
  110. pushBean.setTimestamp(timestamp);
  111. pushBean.setSign(MD5.MD5Encode(pushBean.getSpid() + pushBean.getChannel()
  112. + pushBean.getOrderid() + pushBean.getPhone() + pushBean.getType() + pushBean.getTimestamp() + secretkey));
  113. pushList.add(pushBean);
  114. }
  115. return pushList;
  116. }
  117. //
  118. //
  119. // /**
  120. // *伯源订购关系同步推送
  121. // */
  122. // public void syncBoYuan1(String phone,String spid,String channel,String type,String orderid,String money) {
  123. // try {
  124. // String secretkey = "f589b0116f63d840483833a0ef094645";
  125. // String timestamp = System.currentTimeMillis() / 1000 + "";
  126. // String sign = MD5.MD5Encode(spid + channel + orderid + phone + type + timestamp + secretkey);
  127. // Map<String, String> params = new HashMap<String, String>();
  128. // params.put("spid", spid);
  129. // params.put("money", money);
  130. // params.put("channel", channel);
  131. // params.put("type", type);
  132. // params.put("timestamp", timestamp);
  133. // params.put("phone", phone);
  134. // params.put("sign", sign);
  135. // params.put("orderid", orderid);
  136. // List<Map<String,String>> list=new ArrayList<Map<String, String>>();
  137. // list.add(params);
  138. // jsonParams = "[{\"sign\":\"81ce9f00ba1237db32ff08d31b93f59d\",\"timestamp\":\"1622172065\",\"phone\":\"18673197465\",\"spid\":\"1211\",\"money\":\"1.00\",\"orderid\":\"1\",\"type\":\"0\",\"channel\":\"af1af29d8821db08342578755f8c30a6\"}" +
  139. // ",{\"sign\":\"81ce9f00ba1237db32ff08d31b93f59d\",\"timestamp\":\"1622172065\",\"phone\":\"18673197465\",\"spid\":\"1211\",\"money\":\"1.00\",\"orderid\":\"1\",\"type\":\"0\",\"channel\":\"af1af29d8821db08342578755f8c30a6\"}]";
  140. //// System.out.println("------"+JSONObject.toJSONString(list));
  141. // String jsonParams = JsonUtil.objectToJson(list);
  142. // System.out.println("------"+jsonParams);
  143. //// cbReqParams = JsonUtil.objectToJson(orderOutObj);
  144. // //String resp = URLUtil.postJson("https://face.mige.tv/cartoontest/insetApi/priorOrder", JSONObject.toJSONString(params));
  145. // Map reqProperty = new HashMap();
  146. // reqProperty.put("Content-type", "application/json;charset=UTF-8");
  147. //// reqProperty.put("Content-Type", "application/json; charset=UTF-8");
  148. //// reqProperty.put("Accept", "application/json");
  149. // String url="https://face.mige.tv/cartoontest/insetApi/priorOrder";
  150. // String resp = HttpInvoke.sendhttpsReq("POST", url, jsonParams, getProperty());
  151. //// String resp= HttpInvoke.sendhttpsReq("POST","https://face.mige.tv/cartoontest/insetApi/priorOrder",JsonUtil.objectToJson(list),reqProperty,0);
  152. //// String resp= HttpInvoke.sendHttpByPost("POST", "https://face.mige.tv/cartoontest/insetApi/priorOrder", JSONObject.toJSONString(list), reqProperty);
  153. // resp="{\"code\":10000,\"message\":\"操作成功\",\"data\":\"订购成功\"}";
  154. // System.out.println(resp);
  155. // } catch (Exception e) {
  156. // e.printStackTrace();
  157. // }
  158. // }
  159. /**
  160. * 批量数据推送且接收返回信息
  161. * @param list
  162. */
  163. public String syncBoYuanBatch(List<BoYuanPushBean> list) {
  164. String resp = "";
  165. try {
  166. String jsonParams = JsonUtil.objectToJson(list);
  167. Map reqProperty = new HashMap();
  168. reqProperty.put("Content-type", "application/json;charset=UTF-8");
  169. // DictionaryDao dictionaryDao = new DictionaryDao();
  170. String url = dictionaryDao.getValue("boyuanDataPushUrl");//调用数据推送接口
  171. resp = HttpBoYuanInvoke.sendhttpsReq("POST", url, jsonParams, getProperty());
  172. } catch (Exception e) {
  173. e.printStackTrace();
  174. }
  175. return resp;
  176. }
  177. /**
  178. * 单条数据推送
  179. * @param phone
  180. * @param spid
  181. * @param channel
  182. * @param type
  183. * @param orderid
  184. * @param money
  185. */
  186. public void syncBoYuan(String phone,String spid,String channel,String type,String orderid,String money) {
  187. try {
  188. String secretkey = "f589b0116f63d840483833a0ef094645";
  189. String timestamp = System.currentTimeMillis() / 1000 + "";
  190. String sign = MD5.MD5Encode(spid + channel + orderid + phone + type + timestamp + secretkey);
  191. Map<String, String> params = new HashMap<String, String>();
  192. params.put("spid", spid);
  193. params.put("money", money);
  194. params.put("channel", channel);
  195. params.put("type", type);
  196. params.put("timestamp", timestamp);
  197. params.put("phone", phone);
  198. params.put("sign", sign);
  199. params.put("orderid", orderid);
  200. List<Map<String,String>> list=new ArrayList<Map<String, String>>();
  201. list.add(params);
  202. String jsonParams = JsonUtil.objectToJson(list);
  203. System.out.println("------"+jsonParams);
  204. Map reqProperty = new HashMap();
  205. reqProperty.put("Content-type", "application/json;charset=UTF-8");
  206. String url="https://face.mige.tv/cartoontest/insetApi/priorOrder";
  207. String resp = HttpBoYuanInvoke.sendhttpsReq("POST", url, jsonParams, getProperty());
  208. System.out.println(resp);
  209. } catch (Exception e) {
  210. e.printStackTrace();
  211. }
  212. }
  213. private Map getProperty(){
  214. Map reqProperty = new HashMap();
  215. reqProperty.put("Content-type", "application/json;charset=UTF-8");
  216. return reqProperty;
  217. }
  218. // syncBoYuan("18673197465","1211","af1af29d8821db08342578755f8c30a6","0","2021051345","2.00");
  219. // public static void main(String[] args)throws Exception {
  220. // 订购接口
  221. // new BoYuanSyncJob().doProcess();
  222. // }
  223. }