| | |
| | | package com.smartearth.poiexcel.service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.common.collect.Lists; |
| | | import com.smartearth.poiexcel.entity.*; |
| | | import com.smartearth.poiexcel.mapper.BasicMapper; |
| | | import com.smartearth.poiexcel.mapper.EntMapper; |
| | | import com.smartearth.poiexcel.utils.RestHelper; |
| | | import org.apache.commons.logging.Log; |
| | |
| | | try { |
| | | String url = String.format(generateToken, host); |
| | | |
| | | Map<String, Object> map = new HashMap<>(2); |
| | | Map<String, String> map = new HashMap<>(2); |
| | | map.put("userName", user); |
| | | map.put("passWord", pwd); |
| | | //String map = "userName=shikong001&passWord=123!@#qwe"; |
| | | |
| | | // String str = RestHelper.postForRest(url, map) |
| | | Result rs = postForRest(url, map, Result.class); |
| | | if (null == rs || StaticData.I200 != rs.getCode()) { |
| | | return null; |
| | | } |
| | | |
| | | TokenResult tr = JSONObject.parseObject(rs.getData(), TokenResult.class); |
| | | // TokenResult tr = JSONObject.parseObject(rs.getData().toJSONString(), TokenResult.class) |
| | | TokenResult tr = rs.getData().toJavaObject(TokenResult.class); |
| | | |
| | | return tr.getCtoken(); |
| | | } catch (Exception ex) { |
| | |
| | | return null; |
| | | } |
| | | |
| | | EntResult er = JSONObject.parseObject(rs.getData(), EntResult.class); |
| | | // EntResult er = JSONObject.parseObject(rs.getData().toJSONString(), EntResult.class) |
| | | EntResult er = rs.getData().toJavaObject(EntResult.class); |
| | | |
| | | return er.getPd().getList(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 插入企业 |
| | | */ |
| | | public Integer insertEnts(List<EntEntity> list) { |
| | | try { |
| | | int rows = 0; |
| | | List<List<EntEntity>> subLists = Lists.partition(list, StaticData.I200); |
| | | for (List<EntEntity> sub : subLists) { |
| | | try { |
| | | rows += entMapper.insertBatch(sub); |
| | | } catch (Exception ex) { |
| | | log.error(ex); |
| | | } |
| | | } |
| | | |
| | | return rows; |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * post请求(Rest) |
| | | */ |
| | | public <T> T postForRest(String url, Map<String, Object> map, Class<T> clazz) { |
| | | public <T> T postForRest(String url, Object map, Class<T> clazz) { |
| | | RestTemplate rest = RestHelper.getRestTemplate(); |
| | | |
| | | return rest.postForObject(url, map, clazz); |