浏览代码

模块投票限制

wuweihao 3 年之前
父节点
当前提交
70ed5dd439

+ 16 - 0
gis_cms/src/main/java/com/gis/cms/controller/WebController.java

@@ -6,6 +6,7 @@ import com.gis.cms.entity.dto.GoodsWebPageDto;
 import com.gis.cms.entity.dto.NewsPageDataDto;
 import com.gis.admin.entity.dto.RegisterDto;
 import com.gis.cms.entity.dto.StatusPageDataDto;
+import com.gis.cms.entity.po.GoodsModuleEntity;
 import com.gis.cms.entity.vo.CommentVo;
 import com.gis.cms.mapper.MyBaseMapper;
 import com.gis.cms.service.*;
@@ -26,6 +27,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import tk.mybatis.mapper.entity.Condition;
 
 import javax.transaction.Transactional;
 import javax.validation.Valid;
@@ -72,6 +74,18 @@ public class WebController {
     ReportService reportService;
 
 
+    @Autowired
+    GoodsModuleService goodsModuleService;
+
+
+    @ApiOperation("v0.2-典藏模块列表")
+    @PostMapping("goods/module/list")
+    public Result<GoodsModuleEntity> goodsModuleList() {
+        Condition condition = new Condition(GoodsModuleEntity.class);
+        // 排序:默认模块>自定义模块还创建时间正序;
+        condition.orderBy("isDefault").desc().orderBy("createTime").asc();
+        return Result.success(goodsModuleService.findAll(condition));
+    }
 
 
 
@@ -240,4 +254,6 @@ public class WebController {
     }
 
 
+
+
 }

+ 13 - 9
gis_cms/src/main/java/com/gis/cms/controller/WebManageController.java

@@ -5,6 +5,7 @@ import com.gis.admin.entity.dto.UserWebDto;
 import com.gis.admin.entity.po.SysUserEntity;
 import com.gis.admin.service.SysUserService;
 import com.gis.cms.entity.dto.*;
+import com.gis.cms.entity.po.GoodsModuleEntity;
 import com.gis.cms.entity.po.QuestionGroupEntity;
 import com.gis.cms.service.*;
 import com.gis.common.base.aop.WebControllerLog;
@@ -22,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import tk.mybatis.mapper.entity.Condition;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
@@ -32,7 +34,7 @@ import java.util.Map;
  * Created by owen on 2021/6/28 0028 10:58
  */
 @Slf4j
-@Api(tags = "门户网站(需要token)")
+@Api(tags = "v0.2-门户网站(需要token)")
 @RestController
 @RequestMapping("cms/web/manage")
 public class WebManageController {
@@ -146,30 +148,30 @@ public class WebManageController {
         return sysUserService.saveEntity(userDto);
     }
 
-    @WebControllerLog(description = "门户网站-品投票", addDb = true)
-    @ApiOperation("v0.2-品投票")
+    @WebControllerLog(description = "门户网站-品投票", addDb = true)
+    @ApiOperation("v0.2-品投票")
     @PostMapping("goods/vote")
     public Result goodsVote(@Valid @RequestBody GoodsVoteDto param) {
         return goodsVoteService.goodsVote(param);
     }
 
 
-    @WebControllerLog(description = "门户网站-取消品投票", addDb = true)
-    @ApiOperation("v0.2-取消品投票")
+    @WebControllerLog(description = "门户网站-取消品投票", addDb = true)
+    @ApiOperation("v0.2-取消品投票")
     @GetMapping("goods/vote/del/{goodsId}")
     public Result goodsVoteDel(@PathVariable Long goodsId) {
         return goodsVoteService.goodsVoteDel(goodsId);
     }
 
-    @WebControllerLog(description = "门户网站-品点赞", addDb = true)
-    @ApiOperation("v0.2-品点赞")
+    @WebControllerLog(description = "门户网站-品点赞", addDb = true)
+    @ApiOperation("v0.2-品点赞")
     @PostMapping("goods/like")
     public Result goodsLike(@Valid @RequestBody GoodsVoteDto param) {
         return goodsVoteService.goodsLike(param);
     }
 
-    @WebControllerLog(description = "门户网站-取消品点赞", addDb = true)
-    @ApiOperation("v0.2-取消品点赞")
+    @WebControllerLog(description = "门户网站-取消品点赞", addDb = true)
+    @ApiOperation("v0.2-取消品点赞")
     @GetMapping("goods/like/del/{goodsId}")
     public Result goodsLikeDel(@PathVariable Long goodsId) {
         return goodsVoteService.goodsVoteDelByType(goodsId, "like");
@@ -179,4 +181,6 @@ public class WebManageController {
 
 
 
+
+
 }

+ 7 - 3
gis_cms/src/main/java/com/gis/cms/mapper/GoodsVoteMapper.java

@@ -16,10 +16,14 @@ import java.util.List;
 public interface GoodsVoteMapper extends IBaseMapper<GoodsVoteEntity, Long> {
 
 
-    @Select("select id from tb_goods_vote where is_delete=0 and goods_module_id=${goodsModuleId} " +
-            "and user_id=${userId} and type=${type}")
+    @Select("select id from tb_goods_vote where is_delete=0 and goods_module_id=#{goodsModuleId} " +
+            "and user_id=#{userId} and type=#{type}")
     List<String> findByGoodsModuleIdAndUserIdAndType(Long goodsModuleId, Long userId, String type);
 
-    @Update("update tb_goods_vote set is_delete=1 , update_time=NOW() where is_delete=0 and goods_id=#{goodsId} and type=${type}")
+    @Update("update tb_goods_vote set is_delete=1 , update_time=NOW() where is_delete=0 and goods_id=#{goodsId} and type=#{type}")
     void delByGoodsIdAndType(Long goodsId, String type);
+
+    @Select("select id from tb_goods_vote where is_delete=0 and goods_module_id=#{goodsModuleId} " +
+            "and user_id=#{userId} and type=#{type} and id=#{goodsId}")
+    List<String> findByGoodsModuleIdAndUserIdAndTypeAndGoodsId(Long goodsModuleId, Long tokenUserId, String typeVote, Long goodsId);
 }

+ 1 - 0
gis_cms/src/main/java/com/gis/cms/mapper/QuestionUserMapper.java

@@ -15,6 +15,7 @@ import java.util.List;
 public interface QuestionUserMapper extends IBaseMapper<QuestionUserEntity, Long> {
 
 
+    // 使用子查询
     @Select("select a.*,b.real_name as realName from " +
             "(select MAX(score) score, create_time, user_id,question_group_id  FROM tb_question_user WHERE is_delete=0 and question_group_id=#{questionGroupId} GROUP BY user_id) a " +
             "LEFT JOIN sys_user b on b.id=a.user_id ORDER BY a.score DESC, a.create_time limit 10")

+ 7 - 1
gis_cms/src/main/java/com/gis/cms/service/impl/GoodsServiceImpl.java

@@ -133,7 +133,8 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
 
         StringBuffer sql = new StringBuffer();
         // 判断是否登录
-        if (getTokenUserId() != null){  // 登录, 返回是否点赞、投票
+        String token = getToken();
+        if (StringUtils.isNotBlank(token) && getTokenUserId() != null){  // 登录, 返回是否点赞、投票
             // 使用了子查询
             sql.append("select a.*, if(b.countLike > 0, 1, 0) isLike, if(b.countVote > 0, 1, 0) isVote from tb_goods a left join " +
                     "(select g.id,sum(case when v.type='like' and v.is_delete=0 and v.user_id=" + getTokenUserId() +" then 1 else 0 end )countLike, " +
@@ -144,6 +145,11 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
             sql.append("select a.* from tb_goods a where a.is_delete=0");
         }
 
+        Long goodsModuleId = param.getGoodsModuleId();
+        if (goodsModuleId != null){
+            sql.append(" and a.goods_module_id=").append(goodsModuleId);
+        }
+
         sql.append(" and a.display=1 and a.status=3");
 
         String searchKey = param.getSearchKey();

+ 9 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/GoodsVoteServiceImpl.java

@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.time.LocalDateTime;
 import java.util.List;
@@ -71,12 +72,20 @@ public class GoodsVoteServiceImpl extends IBaseServiceImpl<GoodsVoteEntity, Long
         // 每个用户每个板块能投的票数,按后台设置
         Long goodsModuleId = param.getGoodsModuleId();
 
+        List<String> votes = entityMapper.findByGoodsModuleIdAndUserIdAndTypeAndGoodsId(goodsModuleId, getTokenUserId(), TYPE_VOTE, param.getGoodsId());
+        if (!CollectionUtils.isEmpty(votes)){
+            return Result.failure("该用户已投票");
+        }
+
+        // 一个用户允许此模块的投标数
         List<String> voteByUser = entityMapper.findByGoodsModuleIdAndUserIdAndType(goodsModuleId, getTokenUserId(), TYPE_VOTE);
         GoodsModuleEntity moduleEntity = goodsModuleService.findById(goodsModuleId);
         if (voteByUser.size() >= moduleEntity.getVoteCount()){
             return Result.failure("已达到投票上限");
         }
 
+
+
         // 保存投票
         GoodsVoteEntity entity =  new GoodsVoteEntity();
         BeanUtils.copyProperties(param, entity);

+ 3 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/ReportServiceImpl.java

@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -213,6 +214,8 @@ public class ReportServiceImpl implements ReportService {
         }
         VisitLogEntity entity = new VisitLogEntity();
         entity.setModule(type);
+        entity.setCreateTime(LocalDateTime.now());
+        entity.setIsDelete(0);
         visitLogMapper.insert(entity);
         return Result.success();
     }

+ 2 - 2
gis_common/src/main/java/com/gis/common/base/entity/dto/DateDto.java

@@ -15,11 +15,11 @@ public class DateDto {
      * 开始时间
      * 需要用字符串接收
      */
-    @ApiModelProperty(value = "开始时间, yyyy-mm-dd", name = "startTime")
+    @ApiModelProperty(value = "开始时间, yyyy-mm-dd 00:00:00", name = "startTime")
     private String startTime;
 
 
-    @ApiModelProperty(value = "结束时间, yyyy-mm-dd", name = "endTime")
+    @ApiModelProperty(value = "结束时间, yyyy-mm-dd 23:59:59", name = "endTime")
     private String endTime;