UserAccountController.java 2.76 KB
package com.xkl.controller.uspih;

import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.*;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.User;
import com.xkl.domain.XklAdminEntity;
import com.xkl.domain.XklMemberEntity;
import com.xkl.model.ResultModel;
import com.xkl.model.UsrInfoModelForUSPIH;
import com.xkl.repository.UserRepository;
import com.xkl.repository.XklMemberRespository;
import com.xkl.security.AntiXSS;
import com.xkl.security.SecurityTool;
import com.xkl.tools.DatetimeTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
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.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhaoyue
 */
@RestController
@RequestMapping("/uspihusr")
public class UserAccountController {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private  XklMemberRespository memberRespository;
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟

    @RequestMapping(method = RequestMethod.GET)
    @AntiXSS
    @Authorization
    @ApiOperation(value = "USPIH usr account check")
    @LogAnnotation
    public ResponseEntity<ResultModel> verifyUsrAccount(@CurrentAdmin XklAdminEntity admin, @RequestParam String usraccount) {
        Assert.notNull(usraccount, "usraccount can not be empty");
        User user = userRepository.findByLoginAccountAndStatus(usraccount, Constants.STATUS_OK2);
        if (user == null) {//用户未找到
            return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_NOT_FOUND), HttpStatus.OK);
        }
        XklMemberEntity xklMemberEntity = memberRespository.findOne((long) user.getMemberId());
        Date birthDate = new Date();
        try {
            birthDate = sdf.parse(xklMemberEntity.getBirthDate());
        } catch (Exception e) {
            e.printStackTrace();
        }
        int age = DatetimeTools.getAge(birthDate, new Date());
        UsrInfoModelForUSPIH usrInfo = new UsrInfoModelForUSPIH(xklMemberEntity.getName(), xklMemberEntity.isSex() ?
                1 : 0, age);
        return new ResponseEntity<>(ResultModel.ok(usrInfo), HttpStatus.OK);
    }


}