package com.miaxis.pc.controller.fulu;

import com.miaxis.common.annotation.Log;
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.fulu.domain.FuluCommodityInfo;
import com.miaxis.fulu.service.IFuluCommodityInfoService;
import com.miaxis.fulu.vo.FuluCommodityInfoVo;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【福禄商品】Controller
 * @author wwl
 * @version 1.0
 * @date 2021/6/24 15:50
 */
@RestController
@AllArgsConstructor
@RequestMapping("/pc/fulu")
@Api(tags={"【pc-福禄商品】"})
public class FuluCommodityInfoController extends BaseController {

    private final IFuluCommodityInfoService fuluCommodityInfoService;

    /**
     * 查询福禄商品列表
     */
    @PreAuthorize("@ss.hasPermi('fulu:info:list')")
    @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<FuluCommodityInfoVo> list(@ModelAttribute FuluCommodityInfo fuluCommodityInfo){
        startPage();
        List<FuluCommodityInfoVo> list = fuluCommodityInfoService.selectFuluCommodityInfoList(fuluCommodityInfo);
        return toResponsePageInfo(list);
    }


    /**
     * 获取福禄商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('fulu:info:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取福禄商品详细信息")
    public Response<FuluCommodityInfoVo> getFuLuById(
            @ApiParam(name = "id", value = "福禄商品参数", required = true)
            @PathVariable("id") Long id
    ){
        return fuluCommodityInfoService.getFuLuById(id);
    }

    /**
     * 新增福禄商品
     */
    @PreAuthorize("@ss.hasPermi('fulu:info:add')")
    @Log(title = "福禄商品", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增福禄商品")
    public Response<Integer> add(@RequestBody FuluCommodityInfo fuluCommodityInfo){
        return toResponse(fuluCommodityInfoService.save(fuluCommodityInfo) ? 1 : 0);
    }

    /**
     * 修改福禄商品
     */
    @PreAuthorize("@ss.hasPermi('fulu:info:edit')")
    @Log(title = "福禄商品", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改福禄商品")
    public Response<Integer> edit(@RequestBody FuluCommodityInfo fuluCommodityInfo){
        return toResponse(fuluCommodityInfoService.updateById(fuluCommodityInfo) ? 1 : 0);
    }


    /**
     * 删除福禄商品（伪删除）
     */
    @PreAuthorize("@ss.hasPermi('fulu:info:remove')")
    @Log(title = "福禄商品", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping("/{ids}")
    @ApiOperation("删除福禄商品")
    public  Response remove(
            @ApiParam(name = "ids", value = "福禄商品ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return fuluCommodityInfoService.removeFuLuByIds(ids);
    }

}
