package com.hc.web.controller.browser.back;

import com.hc.business.model.ZccmUser;
import com.hc.business.service.ZccmUserService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 用户表(ZccmUser)表控制层
 *
 * @author java
 * @since 2020-11-09 10:04:14
 */

@RestController
@RequestMapping("/new/api/back/user")
public class BackUserController {

    /**
     * 服务对象
     */
    private final ZccmUserService userService;

    public BackUserController(ZccmUserService userService) {
        this.userService = userService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 ZccmUser", response = Result.class)
    public Result selectBackDetail(@PathVariable("id") Integer id) {
        return Result.success(this.userService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 ZccmUser", response = Result.class)
    public Result addZccmUser(@Valid @RequestBody ZccmUser user) {
        return Result.success(userService.insert(user));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 ZccmUser", response = Result.class)
    public Result updateZccmUser(@RequestBody ZccmUser user) {
        return Result.success(userService.update(user));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "依据主键删除 ZccmUser", response = Result.class)
    public Result deleteZccmUser(@PathVariable("id") Integer id) {
        return Result.success(userService.deleteById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 ZccmUser列表(分页)", response = Result.class)
    public Result listZccmUser(@RequestParam(defaultValue = "0") Integer page,
                           @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(userService.queryAllByLimit(page, size));
    }

    @GetMapping("/week")
    @ApiOperation(value = "最近七天用户注册图表", response = Result.class)
    public Result listWeeks() {
        return Result.success(userService.queryByUserCount());
    }

    @GetMapping("/count")
    @ApiOperation(value = "用户数量统计", response = Result.class)
    public Result listCount() {
        return Result.success(userService.queryUserCount());
    }

    @GetMapping("/mobile")
    @ApiOperation(value = "依据手机号查询用户", response = Result.class)
    public Result queryByMobile(@ApiParam(value = "手机号") @RequestParam String userMobile) {
        return Result.success(userService.queryByMobile(userMobile));
    }

    @GetMapping("/card")
    @ApiOperation(value = "依据身份证号查询用户", response = Result.class)
    public Result queryByCardId(@ApiParam(value = "身份证号") @RequestParam String cardId) {
        return Result.success(userService.queryUserByCard(cardId));
    }

    @GetMapping("/name")
    @ApiOperation(value = "依据姓名查询用户", response = Result.class)
    public Result queryByName(@ApiParam(value = "姓名") @RequestParam String name) {
        return Result.success(userService.queryUserByName(name));
    }

    @GetMapping("/search")
    @ApiOperation(value = "依据培训班名字和支付状态", response = Result.class)
    public Result queryByClassName(@ApiParam(value = "培训班名称") @RequestParam String name,
                                   @ApiParam(value ="支付状态 1已支付 0 未支付") @RequestParam int pay) {
        return Result.success(userService.queryUserByClassName(name,pay));
    }
}