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);
|
}
|
}
|
|
|
}
|
}
|