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

import com.hc.business.model.ZccmUserAdmin;
import com.hc.business.model.ZccmUserAdvise;
import com.hc.business.service.ZccmUserAdviseService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 用户建议表
 * (ZccmUserAdvise)表控制层
 *
 * @author java
 * @since 2020-11-16 14:20:06
 */

@RestController
@RequestMapping("/new/api/back/userAdvise")
public class BackUserAdviseController {

    /**
     * 服务对象
     */
    private final ZccmUserAdviseService userAdviseService;

    public BackUserAdviseController(ZccmUserAdviseService userAdviseService) {
        this.userAdviseService = userAdviseService;
    }

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

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增ZccmUserAdvise", response = Result.class)
    public Result insertZccmUserAdvise(@Valid @RequestBody ZccmUserAdvise userAdvise) {
        userAdvise.setAdviceType(1);
        return Result.success(userAdviseService.insert(userAdvise));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改ZccmUserAdvise", response = Result.class)
    public Result updateZccmUserAdvise(@RequestBody ZccmUserAdvise userAdvise) {
        return Result.success(userAdviseService.update(userAdvise));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 ZccmUserAdvise列表(分页)", response = Result.class)
    public Result listZccmUserAdvise(@ApiParam(value = "类别") @RequestParam(required = false) Integer adviceType,
                                 @RequestParam(defaultValue = "0") Integer page,
                                 @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(userAdviseService.queryAllByLimit(adviceType, page, size));
    }

    @GetMapping("/user/{userId}")
    @ApiOperation(value = "依据用户id获取 ZccmUserAdvise", response = Result.class)
    public Result listZccmUserAdviseById(@ApiParam(value = "用户id")
                                     @PathVariable("userId") Integer userId,
                                     @RequestParam(defaultValue = "0") Integer page,
                                     @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(this.userAdviseService.queryAllByUserId(userId, page, size));
    }


}