Blame view

fw-rp-man/src/main/java/cn/fw/rp/web/controller/ProblemController.java 4.31 KB
0b3d3960   suchu   First commit
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
  package cn.fw.rp.web.controller;
  
  import cn.fw.data.base.db.query.Condition;
  import cn.fw.data.base.db.query.QueryCriterion;
  import cn.fw.data.base.domain.common.Message;
  import cn.fw.rp.common.util.DateUtils;
  import cn.fw.rp.common.util.StringUtils;
  import cn.fw.rp.dao.ProblemListDao;
  import cn.fw.rp.db.ProblemList;
  import cn.fw.rp.man.ProblemDto;
  import cn.fw.rp.man.ProblemQueryParam;
  import org.springframework.beans.BeanUtils;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.transaction.annotation.Transactional;
  import org.springframework.util.Assert;
  import org.springframework.web.bind.annotation.*;
  
  import java.util.List;
  
  /**
   * 需求controller
   *
   * @author suchu
   * @since 2018/5/8 16:05
   */
  @RestController()
  @RequestMapping("/problem")
  public class ProblemController {
      @Autowired
      ProblemListDao problemListDao;
  
      /**
       * 查询problem 列表
       *
       * @param queryParam
       * @return
       */
      @RequestMapping("/list")
      public Message query(@RequestBody ProblemQueryParam queryParam) {
          Message message = Message.success();
          QueryCriterion condition = Condition.open(ProblemList.class);
          if (StringUtils.isValid(queryParam.getBeginDate())) {
              condition.gte("createTime", queryParam.getBeginDate());
          }
          if (StringUtils.isValid(queryParam.getEndDate())) {
              condition.lte("createTime", queryParam.getEndDate());
          }
          if (StringUtils.isValid(queryParam.getStatus())) {
              condition.eq("status", queryParam.getStatus());
          }
          if (StringUtils.isValid(queryParam.getSystemRef())) {
              condition.eq("systemRef", queryParam.getSystemRef());
          }
          if (StringUtils.isValid(queryParam.getModuleRef())) {
              condition.eq("moduleRef", queryParam.getModuleRef());
          }
  
          if (StringUtils.isValid(queryParam.getTitle())) {
              condition.like("title", queryParam.getTitle());
          }
          condition.orderbyDesc("createTime");
          List list = problemListDao.selectList(condition);
          message.setData(list);
          return message;
      }
  
      @RequestMapping("/getFiles")
      public Message getFiles(Integer flag, Integer problemId) {
          Assert.notNull(problemId, "problemId must not be null");
          List result = problemListDao.getFiles(flag, problemId);
          Message message = Message.success();
          message.setData(result);
          return message;
      }
  
      /**
       * 查询problem 通过id
       *
       * @param problemId
       * @return
       */
      @GetMapping("/get/{problemId}")
      public Message get(@PathVariable Integer problemId) {
          Assert.notNull(problemId, "problemId must not be null");
          ProblemList problemList = problemListDao.selectById(problemId);
          if (problemList == null) {
              return Message.failure("没查询到相关数据");
          }
          Message message = Message.success();
          message.setData(problemList);
          return message;
      }
  
      /**
       * 统计problem上传的文件量
       *
       * @param problemId
       * @return
       */
      @RequestMapping("fileCount")
      public Message fileCount(Integer problemId) {
          Assert.notNull(problemId, "problemId must not be null");
          List data = problemListDao.fileCount(problemId);
          Message message = Message.success();
          message.setData(data);
          return message;
      }
  
  
      /**
       * 保存接口
       *
       * @param problemDto
       * @return
       */
      @Transactional(rollbackFor = Exception.class)
      @RequestMapping("/save")
      public Message save(@RequestBody ProblemDto problemDto) {
          if (problemDto.getId() != null) {
              System.out.println(problemDto.toString());
              ProblemList problemList = new ProblemList();
              BeanUtils.copyProperties(problemDto, problemList);
              problemList.setUpdateTime(DateUtils.getNow());
              int i = problemListDao.updateById(problemList);
              return Message.success();
          } else {
              Message message = Message.success();
              ProblemList problemList = new ProblemList();
              BeanUtils.copyProperties(problemDto, problemList);
              problemListDao.insert(problemList);
              message.setCode(10);
              message.setData(problemList.getId());
              return message;
          }
      }
  }