kimi
2020-11-27 75c32d6d697a550400d0b4eec95b8570d83b726f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.highdatas.srs.web;
 
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.highdatas.srs.entity.*;
import com.highdatas.srs.mapper.SysRoleMapper;
import com.highdatas.srs.pojo.CodeMsg;
import com.highdatas.srs.pojo.Result;
import com.highdatas.srs.service.*;
import com.highdatas.srs.util.Constant;
import com.highdatas.srs.util.ContentBuilder;
import com.highdatas.srs.util.DbUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kimi
 * @since 2020-01-15
 */
@RestController
@RequestMapping("/topic")
public class TopicController {
    @Autowired
    ITopicService topicService;
    @Autowired
    ISchemeDetailService schemeDetailService;
    @Autowired
    ISchemeDetailParttimeService parttimeService;
    @Autowired
    ITitleServiceService titleServiceService;
    @Autowired
    ISchemeService schemeService;
 
    @Autowired
    SysRoleMapper mapper;
 
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result get(@PathVariable String id)  {
        Topic topic = topicService.selectById(id);
        String titleId = topic.getTitleId();
        TitleService titleService = titleServiceService.selectById(titleId);
        topic.setTitleService(titleService);
        return Result.success(topic);
    }
 
    @RequestMapping(value = "/page/{pageno}", method = RequestMethod.POST)
    public Result page(@PathVariable Integer pageno, @RequestBody TitleService titleService)  {
        Map<String, Object> stringObjectMap = DbUtils.beanToMap(titleService);
 
        Set<String> keySet = stringObjectMap.keySet();
        ContentBuilder builder = new ContentBuilder(" and ");
        for (String key : keySet) {
            if (key.equalsIgnoreCase("orderBy")){
                continue;
            }
            Object o = stringObjectMap.get(key);
            if (o == null) {
                continue;
            }
            builder.append(key + " like '%" + o.toString() + "%'");
        }
        String filter = builder.toString();
        if (StringUtils.isEmpty(filter)) {
            filter = Constant.WHERE_DEFAULT;
        }
        Long aLong = mapper.selectTopicCnt(filter);
        JSONObject object = new JSONObject();
        if (aLong == null) {
            return Result.success(object);
        }
        com.highdatas.srs.pojo.Page page = new com.highdatas.srs.pojo.Page(aLong);
        page.setPageNo(pageno);
        page.setPageSize(10);
        String orderBy = titleService.getOrderBy();
        if (StringUtils.isEmpty(orderBy)) {
            orderBy = " create_time desc ";
        } else {
            orderBy = orderBy + ", create_time desc";
        }
 
        List<Map<String, Object>> maps = mapper.selectTopic(filter, orderBy, page.getLimitSQL());
 
        object.fluentPut("records", maps);
        object.fluentPut("total", page.getRecordCount());
        object.fluentPut("maxPage", page.getPageCount());
        object.fluentPut("pageno", pageno);
 
        return Result.success(object);
 
 
    }
 
    @RequestMapping(value = "/exam/{id}", method = RequestMethod.GET)
    public Result exam(@PathVariable String id, @RequestParam String projectId)  {
        Topic topic = topicService.selectById(id);
        if (StringUtils.isEmpty(topic.getTitleId())) {
            return  Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        SchemeDetail detail = schemeDetailService.selectById(topic.getTitleId());
        detail.setParentId(projectId).updateById();
        topic.setExamine(true);
        topic.setLinkId(projectId);
 
        boolean insert = topic.updateById();
 
        if (insert) {
            return Result.success(null);
        } else {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
 
    }
    @RequestMapping(value = "/saveLinkTitle/{topicId}", method = RequestMethod.POST)
    public Result saveLinkTitle(@PathVariable String topicId, @RequestBody SchemeDetail detail)  {
        Topic topic = topicService.selectById(topicId);
        String titleId = topic.getTitleId();
        if (StringUtils.isEmpty(titleId)) {
            titleId = DbUtils.getUUID();
        }
 
        parttimeService.delete(new EntityWrapper<SchemeDetailParttime>().eq("parent_id", detail.getId()));
        if (detail.getParttime()  != null && detail.getParttime()) {
            List<SchemeDetailParttime> parttimeList = detail.getParttimeList();
            for (SchemeDetailParttime parttime : parttimeList) {
                parttime.setParentId(detail.getId()).setId(DbUtils.getUUID()).insert();
            }
        }
 
        detail.setId(titleId).setDetailInfoId(titleId).insertOrUpdate();
        JSONObject existsObject = detail.getExistsObject();
        if (existsObject != null) {
            TitleService titleService = JSONObject.parseObject(existsObject.toJSONString(), TitleService.class);
            String title = titleService.createTitle();
            Scheme scheme = schemeService.selectById(detail.getParentId());
            if (scheme == null) {
                scheme = new Scheme().setUserId(detail.getUserId()).setStatus("edit").setId(DbUtils.getUUID());
                scheme.setCreateTime(new Date());
            }
            scheme.setName(title);
        }
        topic.setTitleStatus(true).updateById();
        return Result.success(null);
    }
 
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result add(@RequestBody TitleService titleService)  {
        String id = titleService.getId();
        String title = titleService.createTitle();
        String userId = titleService.getUserId();
 
        if(StringUtils.isEmpty(title)) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
 
        if (StringUtils.isEmpty(id)) {
            Topic topic = new Topic().setUserId(userId).setCreateTime(new Date());
            String uuid = DbUtils.getUUID();
            titleService.setTitle(titleService.createTitle());
            titleService.setId(uuid).insert();
            topic.setId(uuid);
            topic.setTitleId(uuid);
            boolean insert = topic.insert();
            if (insert) {
                return Result.success(null);
            } else {
                return Result.error(CodeMsg.INSERT_ERROR);
            }
        } else {
            Topic topic = topicService.selectById(id);
            titleService.setTitle(titleService.createTitle());
            titleService.updateById();
            boolean b = topic.updateById();
            if (b) {
                return Result.success(null);
            } else {
                return Result.error(CodeMsg.INSERT_ERROR);
            }
        }
 
 
    }
}