ProblemController.java 4.31 KB
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;
        }
    }
}