张延森 4 年之前
父節點
當前提交
44bd2925f8

+ 4
- 2
src/main/java/com/yunzhi/liyuanhui/controller/TaActivityEnrollController.java 查看文件

@@ -42,12 +42,14 @@ public class TaActivityEnrollController extends BaseController {
42 42
      * @param pageSize
43 43
      * @return
44 44
      */
45
-    @RequestMapping(value="/taActivityEnroll",method= RequestMethod.GET)
45
+    @RequestMapping(value="/admin/activityEnroll",method= RequestMethod.GET)
46 46
     public ResponseBean taActivityEnrollList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
47
-                                             @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
47
+                                             @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
48
+                                             @RequestParam(value ="activityId") Integer activityId) throws Exception{
48 49
 
49 50
         IPage<TaActivityEnroll> pg = new Page<>(pageNum, pageSize);
50 51
         QueryWrapper<TaActivityEnroll> queryWrapper = new QueryWrapper<>();
52
+        queryWrapper.eq("activity_id", activityId);
51 53
         queryWrapper.orderByDesc("create_date");
52 54
 
53 55
         IPage<TaActivityEnroll> result = iTaActivityEnrollService.page(pg, queryWrapper);

+ 111
- 0
src/main/java/com/yunzhi/liyuanhui/controller/TaActivityVoteItemController.java 查看文件

@@ -0,0 +1,111 @@
1
+package com.yunzhi.liyuanhui.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.liyuanhui.common.BaseController;
7
+import com.yunzhi.liyuanhui.common.ResponseBean;
8
+import org.slf4j.Logger;
9
+import org.slf4j.LoggerFactory;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.web.bind.annotation.PathVariable;
12
+import org.springframework.web.bind.annotation.RequestBody;
13
+import org.springframework.web.bind.annotation.RequestMapping;
14
+import org.springframework.web.bind.annotation.RequestMethod;
15
+import org.springframework.web.bind.annotation.RequestParam;
16
+import org.springframework.web.bind.annotation.ResponseBody;
17
+import com.yunzhi.liyuanhui.service.ITaActivityVoteItemService;
18
+import com.yunzhi.liyuanhui.entity.TaActivityVoteItem;
19
+import org.springframework.web.bind.annotation.RestController;
20
+
21
+import java.util.List;
22
+
23
+/**
24
+ * <p>
25
+    * 投票项目  前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2020-08-11
30
+ */
31
+@RestController
32
+@RequestMapping("/")
33
+public class TaActivityVoteItemController extends BaseController {
34
+
35
+    private final Logger logger = LoggerFactory.getLogger(TaActivityVoteItemController.class);
36
+
37
+    @Autowired
38
+    public ITaActivityVoteItemService iTaActivityVoteItemService;
39
+
40
+    /**
41
+     *
42
+     * @param client
43
+     * @param activityId
44
+     * @return
45
+     * @throws Exception
46
+     */
47
+    @RequestMapping(value="/{client}/activity/{activityId}/voteitem",method= RequestMethod.GET)
48
+    public ResponseBean taActivityVoteItemList(@PathVariable String client,
49
+                                               @PathVariable Integer activityId) throws Exception{
50
+
51
+        List<TaActivityVoteItem> result = iTaActivityVoteItemService.getAllAvailableItems(activityId);
52
+        return ResponseBean.success(result);
53
+    }
54
+
55
+    /**
56
+     *
57
+     * @param activityId
58
+     * @param voteItems
59
+     * @return
60
+     * @throws Exception
61
+     */
62
+    @RequestMapping(value="/admin/activity/{activityId}/voteitem",method= RequestMethod.POST)
63
+    public ResponseBean taActivityVoteItemAdd(@PathVariable Integer activityId,
64
+                                              @RequestBody List<TaActivityVoteItem> voteItems) throws Exception{
65
+        if (null == voteItems) {
66
+            return ResponseBean.error("未发现需要保存内容", ResponseBean.ERROR_ILLEGAL_PARAMS);
67
+        }
68
+
69
+        List<TaActivityVoteItem> result = iTaActivityVoteItemService.mergeBy(activityId, voteItems);
70
+        return ResponseBean.success(result);
71
+    }
72
+
73
+    /**
74
+     * 根据id删除对象
75
+     * @param id  实体ID
76
+     */
77
+    @ResponseBody
78
+    @RequestMapping(value="/admin/activityVoteItem/{id}", method= RequestMethod.DELETE)
79
+    public ResponseBean taActivityVoteItemDelete(@PathVariable Integer id) throws Exception{
80
+        if(iTaActivityVoteItemService.removeById(id)){
81
+            return ResponseBean.success("success");
82
+        }else {
83
+            return ResponseBean.error("删除失败", ResponseBean.ERROR_UNAVAILABLE);
84
+        }
85
+    }
86
+
87
+    /**
88
+     * 修改对象
89
+     * @param id  实体ID
90
+     * @param taActivityVoteItem 实体对象
91
+     * @return
92
+     */
93
+    @RequestMapping(value="/taActivityVoteItem/{id}",method= RequestMethod.PUT)
94
+    public ResponseBean taActivityVoteItemUpdate(@PathVariable Integer id,
95
+                                        @RequestBody TaActivityVoteItem taActivityVoteItem) throws Exception{
96
+        if (iTaActivityVoteItemService.updateById(taActivityVoteItem)){
97
+            return ResponseBean.success(taActivityVoteItem);
98
+        }else {
99
+            return ResponseBean.error("修改失败", ResponseBean.ERROR_UNAVAILABLE);
100
+        }
101
+    }
102
+
103
+    /**
104
+     * 根据id查询对象
105
+     * @param id  实体ID
106
+     */
107
+    @RequestMapping(value="/taActivityVoteItem/{id}",method= RequestMethod.GET)
108
+    public ResponseBean taActivityVoteItemGet(@PathVariable Integer id) throws Exception{
109
+        return ResponseBean.success(iTaActivityVoteItemService.getById(id));
110
+    }
111
+}

+ 4
- 0
src/main/java/com/yunzhi/liyuanhui/entity/SysModule.java 查看文件

@@ -1,6 +1,9 @@
1 1
 package com.yunzhi.liyuanhui.entity;
2 2
 
3 3
 import java.io.Serializable;
4
+
5
+import com.baomidou.mybatisplus.annotation.IdType;
6
+import com.baomidou.mybatisplus.annotation.TableId;
4 7
 import lombok.Data;
5 8
 import lombok.EqualsAndHashCode;
6 9
 import lombok.experimental.Accessors;
@@ -23,6 +26,7 @@ public class SysModule implements Serializable {
23 26
     /**
24 27
      * 模块编码
25 28
      */
29
+    @TableId(value = "module_code", type = IdType.INPUT)
26 30
     private String moduleCode;
27 31
 
28 32
     /**

+ 5
- 0
src/main/java/com/yunzhi/liyuanhui/entity/TaActivity.java 查看文件

@@ -119,6 +119,11 @@ public class TaActivity implements Serializable {
119 119
      */
120 120
     private Integer voteNum;
121 121
 
122
+    /**
123
+     * 是否报名
124
+     */
125
+    private Boolean isEnroll;
126
+
122 127
     /**
123 128
      * 报名人数
124 129
      */

+ 11
- 1
src/main/java/com/yunzhi/liyuanhui/entity/TaActivityVote.java 查看文件

@@ -45,7 +45,17 @@ public class TaActivityVote implements Serializable {
45 45
     private String activityThumb;
46 46
 
47 47
     /**
48
-     * 报名人
48
+     * 项目ID
49
+     */
50
+    private Integer itemId;
51
+
52
+    /**
53
+     * 项目名称
54
+     */
55
+    private String itemName;
56
+
57
+    /**
58
+     * 投票人
49 59
      */
50 60
     private Integer personId;
51 61
 

+ 63
- 0
src/main/java/com/yunzhi/liyuanhui/entity/TaActivityVoteItem.java 查看文件

@@ -0,0 +1,63 @@
1
+package com.yunzhi.liyuanhui.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import java.time.LocalDateTime;
6
+import java.io.Serializable;
7
+import lombok.Data;
8
+import lombok.EqualsAndHashCode;
9
+import lombok.experimental.Accessors;
10
+
11
+/**
12
+ * <p>
13
+ * 投票项目 
14
+ * </p>
15
+ *
16
+ * @author yansen
17
+ * @since 2020-08-11
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+public class TaActivityVoteItem implements Serializable {
23
+
24
+    private static final long serialVersionUID = 1L;
25
+
26
+    /**
27
+     * 项目ID
28
+     */
29
+    @TableId(value = "item_id", type = IdType.AUTO)
30
+    private Integer itemId;
31
+
32
+    /**
33
+     * 活动ID
34
+     */
35
+    private Integer activityId;
36
+
37
+    /**
38
+     * 名称
39
+     */
40
+    private String name;
41
+
42
+    /**
43
+     * 票数
44
+     */
45
+    private Integer voteNum;
46
+
47
+    /**
48
+     * 创建时间
49
+     */
50
+    private LocalDateTime createDate;
51
+
52
+    /**
53
+     * 状态
54
+     */
55
+    private Integer status;
56
+
57
+    /**
58
+     * 排序
59
+     */
60
+    private Integer sortNo;
61
+
62
+
63
+}

+ 42
- 0
src/main/java/com/yunzhi/liyuanhui/enums/BaseEnum.java 查看文件

@@ -0,0 +1,42 @@
1
+package com.yunzhi.liyuanhui.enums;
2
+
3
+public interface BaseEnum {
4
+
5
+    /**
6
+     * 获取枚举标识
7
+     *
8
+     * @return
9
+     */
10
+    Integer getCode();
11
+
12
+    /**
13
+     * 获取枚举描述
14
+     *
15
+     * @return
16
+     */
17
+    String getDesc();
18
+
19
+    /**
20
+     * 通过枚举类型和code值获取对应的枚举类型
21
+     * @param enumType
22
+     * @param code
23
+     * @param <T>
24
+     * @return
25
+     */
26
+    static <T extends BaseEnum> T valueOf(Class<? extends BaseEnum> enumType, Integer code) {
27
+        if (enumType == null || code == null) {
28
+            return null;
29
+        }
30
+        T[] enumConstants = (T[]) enumType.getEnumConstants();
31
+        if (enumConstants == null) {
32
+            return null;
33
+        }
34
+        for (T enumConstant : enumConstants) {
35
+            int enumCode = enumConstant.getCode();
36
+            if (code.equals(enumCode)) {
37
+                return enumConstant;
38
+            }
39
+        }
40
+        return null;
41
+    }
42
+}

+ 14
- 0
src/main/java/com/yunzhi/liyuanhui/enums/StatusEnum.java 查看文件

@@ -0,0 +1,14 @@
1
+package com.yunzhi.liyuanhui.enums;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Getter;
5
+
6
+@Getter
7
+@AllArgsConstructor
8
+public enum StatusEnum implements BaseEnum {
9
+    NORMAL(1, "正常"),
10
+    DELETED(-1, "删除");
11
+
12
+    private Integer code;
13
+    private String desc;
14
+}

+ 21
- 0
src/main/java/com/yunzhi/liyuanhui/mapper/TaActivityVoteItemMapper.java 查看文件

@@ -0,0 +1,21 @@
1
+package com.yunzhi.liyuanhui.mapper;
2
+
3
+import com.yunzhi.liyuanhui.entity.TaActivityVoteItem;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+import java.util.List;
8
+
9
+/**
10
+ * <p>
11
+ * 投票项目  Mapper 接口
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2020-08-11
16
+ */
17
+@Mapper
18
+public interface TaActivityVoteItemMapper extends BaseMapper<TaActivityVoteItem> {
19
+
20
+    List<Integer> selectIdsByActivity(Integer activityId);
21
+}

+ 21
- 0
src/main/java/com/yunzhi/liyuanhui/service/ITaActivityVoteItemService.java 查看文件

@@ -0,0 +1,21 @@
1
+package com.yunzhi.liyuanhui.service;
2
+
3
+import com.yunzhi.liyuanhui.entity.TaActivityVoteItem;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+import java.util.List;
7
+
8
+/**
9
+ * <p>
10
+ * 投票项目  服务类
11
+ * </p>
12
+ *
13
+ * @author yansen
14
+ * @since 2020-08-11
15
+ */
16
+public interface ITaActivityVoteItemService extends IService<TaActivityVoteItem> {
17
+
18
+    List<TaActivityVoteItem> mergeBy(Integer activityId, List<TaActivityVoteItem> voteItems) throws Exception;
19
+
20
+    List<TaActivityVoteItem> getAllAvailableItems(Integer activityId);
21
+}

+ 86
- 0
src/main/java/com/yunzhi/liyuanhui/service/impl/TaActivityVoteItemServiceImpl.java 查看文件

@@ -0,0 +1,86 @@
1
+package com.yunzhi.liyuanhui.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
5
+import com.yunzhi.liyuanhui.entity.TaActivityVoteItem;
6
+import com.yunzhi.liyuanhui.enums.StatusEnum;
7
+import com.yunzhi.liyuanhui.mapper.TaActivityVoteItemMapper;
8
+import com.yunzhi.liyuanhui.service.ITaActivityVoteItemService;
9
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.stereotype.Service;
12
+
13
+import java.util.ArrayList;
14
+import java.util.List;
15
+
16
+/**
17
+ * <p>
18
+ * 投票项目  服务实现类
19
+ * </p>
20
+ *
21
+ * @author yansen
22
+ * @since 2020-08-11
23
+ */
24
+@Service
25
+public class TaActivityVoteItemServiceImpl extends ServiceImpl<TaActivityVoteItemMapper, TaActivityVoteItem> implements ITaActivityVoteItemService {
26
+
27
+    @Autowired
28
+    TaActivityVoteItemMapper taActivityVoteItemMapper;
29
+
30
+    @Override
31
+    public List<TaActivityVoteItem> mergeBy(Integer activityId, List<TaActivityVoteItem> voteItems) throws Exception {
32
+        // 如果是一个没有, 则认为是全部删除
33
+        if (voteItems == null || voteItems.size() == 0) {
34
+            UpdateWrapper<TaActivityVoteItem> updateWrapper = new UpdateWrapper<>();
35
+            updateWrapper.set("status", StatusEnum.DELETED.getCode());
36
+            updateWrapper.eq("activity_id", activityId);
37
+
38
+            this.update(updateWrapper);
39
+            return null;
40
+        }
41
+
42
+        // 如果数据库中没有已经存在的, 则全部保存
43
+        List<Integer> existsIds = taActivityVoteItemMapper.selectIdsByActivity(activityId);
44
+        if (null == existsIds || existsIds.size() == 0) {
45
+            for(TaActivityVoteItem item : voteItems) {
46
+                item.setActivityId(activityId);
47
+                this.save(item);
48
+            }
49
+        } else {
50
+
51
+            // 否则遍历去 merge
52
+            for(TaActivityVoteItem item : voteItems) {
53
+                if (null == item.getItemId() || item.getItemId() < 1) {
54
+                    item.setActivityId(activityId);
55
+                    this.save(item);
56
+                } else {
57
+                    this.updateById(item);
58
+
59
+                    // 数据中心已经存在的 减去 正常更新的 , 剩余就是被删除的
60
+                    existsIds.remove(item.getActivityId());
61
+                }
62
+            }
63
+
64
+            if (existsIds.size() > 0) {
65
+                UpdateWrapper<TaActivityVoteItem> updateWrapper1 = new UpdateWrapper<>();
66
+                updateWrapper1.set("status", StatusEnum.DELETED.getCode());
67
+                updateWrapper1.in("item_id", existsIds);
68
+                update(updateWrapper1);
69
+            }
70
+        }
71
+
72
+        return getAllAvailableItems(activityId);
73
+    }
74
+
75
+    @Override
76
+    public List<TaActivityVoteItem> getAllAvailableItems(Integer activityId) {
77
+
78
+        QueryWrapper<TaActivityVoteItem> queryWrapper = new QueryWrapper<>();
79
+        queryWrapper.eq("activity_id", activityId);
80
+        queryWrapper.eq("status", StatusEnum.NORMAL.getCode());
81
+        queryWrapper.orderByAsc("sort_no");
82
+        queryWrapper.orderByDesc("create_date");
83
+
84
+        return list(queryWrapper);
85
+    }
86
+}

+ 11
- 0
src/main/resources/mapper/TaActivityVoteItemMapper.xml 查看文件

@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.liyuanhui.mapper.TaActivityVoteItemMapper">
4
+
5
+    <select id="selectIdsByActivity" resultType="java.lang.Integer">
6
+        SELECT t.item_id
7
+        FROM ta_activity_vote_item t
8
+        WHERE t.activity_id = #{activityId}
9
+        AND t.`status` = 1
10
+    </select>
11
+</mapper>