| | |
| | | package com.highdatas.srs.web; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.highdatas.srs.entity.Topic; |
| | | 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.ITopicService; |
| | | 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 javax.servlet.http.HttpServletRequest; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | 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.GET) |
| | | public Result page(@PathVariable Integer pageno, HttpServletRequest request) { |
| | | String title = request.getParameter("title"); |
| | | String desp = request.getParameter("desp"); |
| | | EntityWrapper<Topic> topicEntityWrapper = new EntityWrapper<>(); |
| | | if (!StringUtils.isEmpty(title)) { |
| | | topicEntityWrapper.like("title", title); |
| | | @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() + "%'"); |
| | | } |
| | | if (!StringUtils.isEmpty(desp)) { |
| | | topicEntityWrapper.like("desp", desp); |
| | | String filter = builder.toString(); |
| | | if (StringUtils.isEmpty(filter)) { |
| | | filter = Constant.WHERE_DEFAULT; |
| | | } |
| | | Page<Topic> topicPage= new Page<Topic>(pageno, 15); |
| | | topicEntityWrapper.orderBy("create_time desc"); |
| | | Page<Topic> result = topicService.selectPage(topicPage, topicEntityWrapper); |
| | | List<Topic> records = result.getRecords(); |
| | | JSONArray array = new JSONArray(); |
| | | for (Topic record : records) { |
| | | JSONObject one = (JSONObject) JSON.toJSON(record); |
| | | Date createTime = record.getCreateTime(); |
| | | String s = DbUtils.convert_before(createTime.getTime()); |
| | | one.fluentPut("time", s); |
| | | array.add(one); |
| | | } |
| | | Long aLong = mapper.selectTopicCnt(filter); |
| | | JSONObject object = new JSONObject(); |
| | | object.fluentPut("records", array); |
| | | object.fluentPut("total", result.getTotal()); |
| | | object.fluentPut("maxPage", result.getPages()); |
| | | object.fluentPut("pageno", result.getCurrent()); |
| | | 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) { |
| | |
| | | } |
| | | |
| | | } |
| | | @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(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/add", method = RequestMethod.GET) |
| | | public Result add(HttpServletRequest request) { |
| | | String id = request.getParameter("id"); |
| | | String title = request.getParameter("title"); |
| | | String userId = request.getParameter("userId"); |
| | | 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); |
| | | } |
| | | String desp = request.getParameter("desp"); |
| | | |
| | | if (StringUtils.isEmpty(id)) { |
| | | Topic topic = new Topic().setUserId(userId).setTitle(title).setDesp(desp).setCreateTime(new Date()); |
| | | topic.setId(DbUtils.getUUID()); |
| | | 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 { |
| | | Topic topic = topicService.selectById(id); |
| | | boolean b = topic.setDesp(desp).setTitle(title).updateById(); |
| | | titleService.setTitle(titleService.createTitle()); |
| | | titleService.updateById(); |
| | | boolean b = topic.updateById(); |
| | | if (b) { |
| | | return Result.success(null); |
| | | } else { |