HasReportController.java 2.4 KB
package com.xkl.controller;

import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.LogAnnotation;
import com.xkl.authorization.annotation.Sign;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.User;
import com.xkl.domain.XklAmpReportEntity;
import com.xkl.model.ResultModel;
import com.xkl.repository.UserRepository;
import com.xkl.repository.XklAmpReportRespository;
import com.xkl.security.AntiXSS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 判断用户是否有报告。
 */
@RestController
@RequestMapping("/hasReport")
public class HasReportController {


    @Autowired
    private UserRepository userRepository;
    @Autowired
    private XklAmpReportRespository xklAmpReportRespository;


    @LogAnnotation
    @AntiXSS
    @Sign
    @RequestMapping(method = RequestMethod.GET)
    @ApiOperation(value = "判断用户在该系统中是否有报告")
    public ResponseEntity<ResultModel> hasReport(HttpServletRequest request,
                                                 @RequestParam String username, @RequestParam String sign, @RequestParam long t, @RequestParam int type) {

        if (!(boolean) request.getAttribute("signAspect"))
            return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
        User user = userRepository.findByLoginAccountAndStatus(username, Constants.STATUS_OK2);
        if (user == null) {  //用户不存在
            return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_NOT_FOUND), HttpStatus.OK);
        }
        List<XklAmpReportEntity> reportList = xklAmpReportRespository.findByMemberIdAndStatus(user.getMemberId(), Constants.STATUS_OK);
        if (reportList == null || reportList.size() <= 0) {
            return new ResponseEntity<>(ResultModel.ok(ResultStatus.REPORT_NOT_EXIST), HttpStatus.OK);
        } else {
            return new ResponseEntity<>(ResultModel.ok(ResultStatus.REPORT_EXIST), HttpStatus.OK);
        }
    }
}