Antiloveg 8 years ago
parent
commit
ff933e2673

+ 2 - 0
src/main/java/com/goafanti/common/dao/DemandInterestMapper.java

@@ -14,4 +14,6 @@ public interface DemandInterestMapper {
     int updateByPrimaryKeySelective(DemandInterest record);
 
     int updateByPrimaryKey(DemandInterest record);
+
+	DemandInterest selectDemandInterestByUidAndDemandId(String uid, String id);
 }

+ 7 - 0
src/main/java/com/goafanti/common/mapper/DemandInterestMapper.xml

@@ -79,4 +79,11 @@
       create_time = #{createTime,jdbcType=TIMESTAMP}
     where id = #{id,jdbcType=VARCHAR}
   </update>
+  
+   <select id="selectDemandInterestByUidAndDemandId" resultMap="BaseResultMap"  >
+    select 
+    <include refid="Base_Column_List" />
+    from demand
+    where uid = #{0} and demand_id = #{1}
+  </select>
 </mapper>

+ 2 - 0
src/main/java/com/goafanti/common/mapper/DemandMapper.xml

@@ -980,4 +980,6 @@
   	where d.id = #{1}
   </select>
   
+  
+  
 </mapper>

+ 4 - 2
src/main/java/com/goafanti/demand/service/DemandInterestService.java

@@ -1,7 +1,7 @@
 package com.goafanti.demand.service;
 
-import com.goafanti.core.mybatis.page.Pagination;
-import com.goafanti.portal.bo.AchievementInterestListBo;
+import com.goafanti.common.model.DemandInterest;
+
 
 public interface DemandInterestService {
 
@@ -9,5 +9,7 @@ public interface DemandInterestService {
 
 	void saveAchievementInterest(String id);
 
+	DemandInterest selectDemandInterestByUidAndDemandId(String userId, String id);
+
 
 }

+ 5 - 5
src/main/java/com/goafanti/demand/service/impl/DemandInterestServiceImpl.java

@@ -1,8 +1,6 @@
 package com.goafanti.demand.service.impl;
 
 import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.UUID;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,11 +9,8 @@ import org.springframework.stereotype.Service;
 import com.goafanti.common.dao.DemandInterestMapper;
 import com.goafanti.common.model.DemandInterest;
 import com.goafanti.core.mybatis.BaseMybatisDao;
-import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
-import com.goafanti.demand.bo.DemandManageListBo;
 import com.goafanti.demand.service.DemandInterestService;
-import com.goafanti.portal.bo.AchievementInterestListBo;
 
 @Service
 public class DemandInterestServiceImpl extends BaseMybatisDao<DemandInterestMapper> implements DemandInterestService {
@@ -39,5 +34,10 @@ public class DemandInterestServiceImpl extends BaseMybatisDao<DemandInterestMapp
 		demandInterestMapper.insert(di);
 	}
 
+	@Override
+	public DemandInterest selectDemandInterestByUidAndDemandId(String uid, String id) {
+		return demandInterestMapper.selectDemandInterestByUidAndDemandId(uid, id);
+	}
+
 	
 }

+ 21 - 13
src/main/java/com/goafanti/portal/controller/PortalSearchApiController.java

@@ -22,6 +22,7 @@ import com.goafanti.common.enums.DemandReleaseStatus;
 import com.goafanti.common.model.Achievement;
 import com.goafanti.common.model.AchievementInterest;
 import com.goafanti.common.model.Demand;
+import com.goafanti.common.model.DemandInterest;
 import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.demand.service.DemandInterestService;
 import com.goafanti.demand.service.DemandService;
@@ -63,7 +64,7 @@ public class PortalSearchApiController extends CertifyApiController {
 	@RequestMapping(value = "/demandCancelInterest", method = RequestMethod.POST)
 	public Result demandCancelInterest(String id) {
 		Result res = new Result();
-		if(!checkUserLogin(res)){
+		if (!checkUserLogin(res)) {
 			return res;
 		}
 		if (StringUtils.isBlank(id)) {
@@ -80,13 +81,19 @@ public class PortalSearchApiController extends CertifyApiController {
 	@RequestMapping(value = "/demandInterest", method = RequestMethod.POST)
 	public Result demandInterest(String id) {
 		Result res = new Result();
-		if(!checkUserLogin(res)){
+		if (!checkUserLogin(res)) {
 			return res;
 		}
 		if (StringUtils.isBlank(id)) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
 			return res;
 		}
+
+		DemandInterest di = demandInterestService.selectDemandInterestByUidAndDemandId(TokenManager.getUserId(), id);
+		if (null != di) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "当前科技科技需求已关注!"));
+			return res;
+		}
 		Demand d = demandService.selectByPrimaryKey(id);
 		if (null == d || d.getDeletedSign().equals(DeleteStatus.DELETED.getCode())
 				|| !d.getAuditStatus().equals(DemandAuditStatus.AUDITED.getCode())
@@ -105,7 +112,7 @@ public class PortalSearchApiController extends CertifyApiController {
 	@RequestMapping(value = "/achievementCancelInterest", method = RequestMethod.POST)
 	public Result achievementCancelInterest(String id) {
 		Result res = new Result();
-		if(!checkUserLogin(res)){
+		if (!checkUserLogin(res)) {
 			return res;
 		}
 		if (StringUtils.isBlank(id)) {
@@ -122,15 +129,23 @@ public class PortalSearchApiController extends CertifyApiController {
 	@RequestMapping(value = "/achievementInterest", method = RequestMethod.POST)
 	public Result achievementInterest(String id) {
 		Result res = new Result();
-		
-		if(!checkUserLogin(res)){
+
+		if (!checkUserLogin(res)) {
 			return res;
 		}
-		
+
 		if (StringUtils.isBlank(id)) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "科技成果ID"));
 			return res;
 		}
+
+		AchievementInterest ai = achievementInterestService
+				.selectAchievementInterestByUidAndAchievementId(TokenManager.getUserId(), id);
+		if (null != ai) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "当前科技成果已关注!"));
+			return res;
+		}
+
 		Achievement a = achievementService.selectByPrimaryKey(id);
 		if (null == a || a.getDeletedSign().equals(DeleteStatus.DELETED.getCode())
 				|| !a.getAuditStatus().equals(AchievementAuditStatus.AUDITED.getCode())
@@ -138,13 +153,6 @@ public class PortalSearchApiController extends CertifyApiController {
 			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "成果ID"));
 			return res;
 		}
-
-		AchievementInterest ai = achievementInterestService
-				.selectAchievementInterestByUidAndAchievementId(TokenManager.getUserId(), id);
-		if (null != ai){
-			res.getError().add(buildError(ErrorConstants.PARAM_ERROR,  "当前科技成果已关注!"));
-			return res;
-		}
 		achievementInterestService.saveAchievementInterest(id);
 		return res;
 	}