|
|
@@ -0,0 +1,136 @@
|
|
|
+package com.uas.platform.b2c.common.vote.service.Impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.uas.platform.b2c.common.account.dao.EnterpriseDao;
|
|
|
+import com.uas.platform.b2c.common.account.model.Enterprise;
|
|
|
+import com.uas.platform.b2c.common.vote.service.VoteService;
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
+import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
+import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
+import com.uas.ps.core.page.PageParams;
|
|
|
+import com.uas.ps.core.util.HttpUtil;
|
|
|
+import com.uas.ps.core.util.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: huj
|
|
|
+ * @Date: Created in 11:05 2018/10/30.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class VoteServiceImpl implements VoteService {
|
|
|
+
|
|
|
+ private Logger LOGGER = LoggerFactory.getLogger(VoteServiceImpl.class);
|
|
|
+ /**
|
|
|
+ * 项目地址
|
|
|
+ */
|
|
|
+ private final static String URL = "http://10.1.51.62:9999";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取单个企业url
|
|
|
+ */
|
|
|
+ private final static String ONEURL = "/vote/one";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取企业列表url
|
|
|
+ */
|
|
|
+ private final static String ALLURL = "/vote/all";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 企业报名url
|
|
|
+ */
|
|
|
+ private final static String APPLYURL = "/vote/apply";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户投票url
|
|
|
+ */
|
|
|
+ private final static String VOTEURL = "/vote/vote";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ EnterpriseDao enterpriseDao;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap getEnterprise(Long enUU) {
|
|
|
+ Map<String, Object> map = new HashMap<>(1);
|
|
|
+ map.put("enUU", enUU);
|
|
|
+ ResultMap result = new ResultMap(CodeType.ERROR, "请求失败");
|
|
|
+ try {
|
|
|
+ HttpUtil.Response response = HttpUtil.sendGetRequest(URL + ONEURL, map);
|
|
|
+ result = JSON.parseObject(response.getResponseText(), ResultMap.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("获取单个企业出错:" + enUU + "错误信息" + e.getMessage());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap getEnterprises(PageParams params, String type, String keyword) {
|
|
|
+ Map<String, Object> map = new HashMap<>(3);
|
|
|
+ map.put("count", params.getCount());
|
|
|
+ map.put("page", params.getPage());
|
|
|
+ if (!StringUtils.isEmpty(type)) {
|
|
|
+ map.put("type", type);
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ map.put("keyword", keyword);
|
|
|
+ }
|
|
|
+ ResultMap result = new ResultMap(CodeType.ERROR, "请求失败");
|
|
|
+ try {
|
|
|
+ HttpUtil.Response response = HttpUtil.sendGetRequest(URL + ALLURL, map);
|
|
|
+ result = JSON.parseObject(response.getResponseText(), ResultMap.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("获取企业列表出错:" + type + keyword + "错误信息" + e.getMessage());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap apply(Long enUU, String type) {
|
|
|
+ Map<String, Object> map = new HashMap<>(6);
|
|
|
+ if (StringUtils.isEmpty(enUU)) {
|
|
|
+ return new ResultMap(CodeType.ERROR, "参数错误");
|
|
|
+ }
|
|
|
+ Enterprise enterprise = enterpriseDao.findByUu(enUU);
|
|
|
+ if (StringUtils.isEmpty(enterprise)) {
|
|
|
+ return new ResultMap(CodeType.ERROR, "企业不存在");
|
|
|
+ }
|
|
|
+ map.put("enUU", enUU);
|
|
|
+ map.put("type", type);
|
|
|
+ map.put("userUU", SystemSession.getUser().getUserUU());
|
|
|
+ map.put("enDes", enterprise.getEnBusinessScope() == null ? "" : enterprise.getEnBusinessScope());
|
|
|
+ map.put("enName", enterprise.getEnName());
|
|
|
+ map.put("userName", SystemSession.getUser().getUserName());
|
|
|
+ map.put("pic", enterprise.getEnLogoUrl() == null ? "" : enterprise.getEnLogoUrl());
|
|
|
+ ResultMap result = new ResultMap(CodeType.ERROR, "请求失败");
|
|
|
+ try {
|
|
|
+ HttpUtil.Response response = HttpUtil.sendPostRequest(URL + APPLYURL, map);
|
|
|
+ result = JSON.parseObject(response.getResponseText(), ResultMap.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("企业报名出错:" + enUU + type + "错误信息" + e.getMessage());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap vote(Long enUU) {
|
|
|
+ Map<String, Object> map = new HashMap<>(4);
|
|
|
+ map.put("userUU", SystemSession.getUser().getUserUU());
|
|
|
+ map.put("enUU", enUU);
|
|
|
+ map.put("userName", SystemSession.getUser().getUserName());
|
|
|
+ ResultMap result = new ResultMap(CodeType.ERROR, "请求失败");
|
|
|
+ try {
|
|
|
+ HttpUtil.Response response = HttpUtil.sendPostRequest(URL + VOTEURL, map);
|
|
|
+ result = JSON.parseObject(response.getResponseText(), ResultMap.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("用户投票出错:" + SystemSession.getUser().getUserUU() +
|
|
|
+ " 投票企业uu:" + enUU + "错误信息" + e.getMessage());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|