Browse Source

投票接口

Hu Jie 7 years ago
parent
commit
fe4d070272

+ 31 - 0
src/main/java/com/uas/platform/b2c/common/vote/controller/ApiVoteController.java

@@ -0,0 +1,31 @@
+package com.uas.platform.b2c.common.vote.controller;
+
+import com.uas.platform.b2c.common.vote.service.ApiVoteService;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 投票所需数据接口
+ * @Author: huj
+ * @Date: Created in 17:17 2018/10/29.
+ */
+@RestController
+@RequestMapping("/api/vote")
+public class ApiVoteController {
+
+    @Autowired
+    ApiVoteService apiVoteService;
+
+    @RequestMapping("/store")
+    public ResultMap existStore(Long enUU) {
+        return apiVoteService.existStore(enUU);
+    }
+
+    @RequestMapping("/goods")
+    public Integer countGoods(Long enUU) {
+        return apiVoteService.countGoods(enUU);
+    }
+
+}

+ 69 - 0
src/main/java/com/uas/platform/b2c/common/vote/controller/VoteController.java

@@ -0,0 +1,69 @@
+package com.uas.platform.b2c.common.vote.controller;
+
+import com.uas.platform.b2c.common.vote.service.VoteService;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.ps.core.page.PageParams;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Author: huj
+ * @Date: Created in 11:01 2018/10/30.
+ */
+@RestController
+@RequestMapping("/vote")
+public class VoteController {
+
+    @Autowired
+    VoteService voteService;
+
+    /**
+     * 获取单个企业
+     * @param enUU
+     * @return
+     */
+    @RequestMapping("/one")
+    public ResultMap getEnterprise(Long enUU) {
+        return voteService.getEnterprise(enUU);
+    }
+
+    /**
+     * 获取企业列表
+     * @param params
+     * @param type
+     * @param keyword
+     * @return
+     */
+    @RequestMapping("/all")
+    public ResultMap getEnterprises(PageParams params, String type, String keyword) {
+        return voteService.getEnterprises(params, type, keyword);
+    }
+
+    /**
+     * 企业报名
+     * @param enUU
+     * @param type
+     * @param userUU
+     * @param enDes
+     * @param enName
+     * @return
+     */
+    @RequestMapping(value = "/apply", method = RequestMethod.POST)
+    public ResultMap apply(Long enUU, String type) {
+        return voteService.apply(enUU, type);
+    }
+
+    /**
+     * 用户投票
+     * @param userUU
+     * @param type
+     * @param enUU
+     * @return
+     */
+    @RequestMapping(value = "/vote", method = RequestMethod.POST)
+    public ResultMap vote(Long enUU) {
+        return voteService.vote(enUU);
+    }
+}

+ 24 - 0
src/main/java/com/uas/platform/b2c/common/vote/service/ApiVoteService.java

@@ -0,0 +1,24 @@
+package com.uas.platform.b2c.common.vote.service;
+
+import com.uas.platform.b2c.trade.support.ResultMap;
+
+/**
+ * @Author: huj
+ * @Date: Created in 17:23 2018/10/29.
+ */
+public interface ApiVoteService {
+
+    /**
+     * 是否存在店铺
+     * @param enUU 企业uu
+     * @return
+     */
+    ResultMap existStore(Long enUU);
+
+    /**
+     * 统计上架过产品数量
+     * @param enUU 企业uu
+     * @return
+     */
+    Integer countGoods(Long enUU);
+}

+ 41 - 0
src/main/java/com/uas/platform/b2c/common/vote/service/Impl/ApiVoteServiceImpl.java

@@ -0,0 +1,41 @@
+package com.uas.platform.b2c.common.vote.service.Impl;
+
+import com.uas.platform.b2c.common.vote.service.ApiVoteService;
+import com.uas.platform.b2c.prod.commodity.dao.GoodsHistoryDao;
+import com.uas.platform.b2c.prod.store.dao.StoreInDao;
+import com.uas.platform.b2c.prod.store.model.StoreIn;
+import com.uas.platform.b2c.trade.support.CodeType;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+
+/**
+ * @Author: huj
+ * @Date: Created in 17:24 2018/10/29.
+ */
+@Service
+public class ApiVoteServiceImpl implements ApiVoteService {
+
+    @Autowired
+    StoreInDao storeInDao;
+
+    @Autowired
+    GoodsHistoryDao goodsHistoryDao;
+
+    @Override
+    public ResultMap existStore(Long enUU) {
+        List<StoreIn> storeIns = storeInDao.findByEnUU(enUU);
+        if (!CollectionUtils.isEmpty(storeIns)) {
+            return ResultMap.success();
+        }
+        return new ResultMap(CodeType.NOT_PERMIT.code(), null);
+    }
+
+    @Override
+    public Integer countGoods(Long enUU) {
+        return goodsHistoryDao.countByEnUU(enUU);
+    }
+}

+ 136 - 0
src/main/java/com/uas/platform/b2c/common/vote/service/Impl/VoteServiceImpl.java

@@ -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;
+    }
+}

+ 37 - 0
src/main/java/com/uas/platform/b2c/common/vote/service/VoteService.java

@@ -0,0 +1,37 @@
+package com.uas.platform.b2c.common.vote.service;
+
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.ps.core.page.PageParams;
+
+
+/**
+ * @Author: huj
+ * @Date: Created in 14:19 2018/10/26.
+ */
+public interface VoteService {
+
+    /**
+     * 获取单个企业
+     * @return
+     */
+    ResultMap getEnterprise(Long enUU);
+
+    /**
+     * 获取所有企业
+     * @return
+     */
+    ResultMap getEnterprises(PageParams params, String type, String keyword);
+
+    /**
+     * 企业报名
+     * @return
+     */
+    ResultMap apply(Long enUU, String type);
+
+    /**
+     * 用户投票
+     * @return
+     */
+    ResultMap vote(Long enUU);
+
+}

+ 8 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/GoodsHistoryDao.java

@@ -69,4 +69,12 @@ public interface GoodsHistoryDao extends JpaSpecificationExecutor<GoodsHistory>,
      */
     List<GoodsHistory> findByEnUUAndCurrencyName(Long enUU, String currencyName);
 
+    /**
+     * 获取企业上架过产品数量
+     * @param enUU 企业uu
+     * @return
+     */
+    @Query(nativeQuery = true, value = "select count(distinct go_productid) from trade$goods_history where go_status in (601,602) and go_enuu = :enUU")
+    Integer countByEnUU(@Param("enUU") Long enUU);
+
 }

+ 1 - 0
src/main/webapp/WEB-INF/spring/webmvc.xml

@@ -124,6 +124,7 @@
 			<mvc:exclude-mapping path="/vendor/introduction/vendor/**" />
 			<mvc:exclude-mapping path="/vendor/introduction/product/**" />
 			<mvc:exclude-mapping path="/wx/**"/>
+			<mvc:exclude-mapping path="/vote/**"/>
 			<bean class="com.uas.platform.b2c.core.filter.SSOInterceptor"></bean>
 		</mvc:interceptor>
 		<!-- 对所有的请求拦截,将Session中的User信息设置进SystemSession -->