package com.miaxis.app.controller.jsgzh;

import com.miaxis.common.annotation.Log;
import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.poi.ExcelUtil;
import com.miaxis.jsgzh.domain.JsgzhUser;
import com.miaxis.jsgzh.service.IJsgzhUserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 【极速公众号用户】Controller
 *
 * @author miaxis
 * @date 2021-06-08
 */
@RestController
@Api(tags={"【小程序-极速公众号用户】"})
@RequestMapping(Constants.STUDENT_PREFIX+"/jsgzh/user")
public class JsgzhUserController extends BaseController{
    @Autowired
    private IJsgzhUserService jsgzhUserService;

    /**
     * 查询极速公众号用户列表
     */
    @GetMapping("/list")
    @ApiOperation("查询极速公众号用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<JsgzhUser> list(@ModelAttribute JsgzhUser jsgzhUser){
        startPage();
        List<JsgzhUser> list = jsgzhUserService.selectJsgzhUserList(jsgzhUser);
        return toResponsePageInfo(list);
    }

    /**
     * 导出极速公众号用户列表
     */
    @Log(title = "极速公众号用户", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出极速公众号用户列表Excel")
    public Response<String> export(@ModelAttribute JsgzhUser jsgzhUser){
        List<JsgzhUser> list = jsgzhUserService.selectJsgzhUserList(jsgzhUser);
        ExcelUtil<JsgzhUser> util = new ExcelUtil<JsgzhUser>(JsgzhUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取极速公众号用户详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取极速公众号用户详细信息")
    public Response<JsgzhUser> getInfo(
            @ApiParam(name = "id", value = "极速公众号用户参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(jsgzhUserService.getById(id));
    }

    /**
     * 新增极速公众号用户
     */
    @Log(title = "极速公众号用户", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增极速公众号用户")
    public Response<Integer> add(@RequestBody JsgzhUser jsgzhUser){
        return toResponse(jsgzhUserService.save(jsgzhUser) ? 1 : 0);
    }

    /**
     * 修改极速公众号用户
     */
    @Log(title = "极速公众号用户", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改极速公众号用户")
    public Response<Integer> edit(@RequestBody JsgzhUser jsgzhUser){
        return toResponse(jsgzhUserService.updateById(jsgzhUser) ? 1 : 0);
    }

    /**
     * 删除极速公众号用户
     */
    @Log(title = "极速公众号用户", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除极速公众号用户")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "极速公众号用户ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(jsgzhUserService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
