package com.sqx.modules.shipinquan.content;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.common.utils.Result;
import com.sqx.modules.shipinquan.entity.BlShipinquanPinglun;
import com.sqx.modules.shipinquan.service.BlShipinquanPinglunService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


@RestController
@RequestMapping("/bl/shipinquanPinglun")
public class BlShipinquanPinglunController {

    @Autowired
    private BlShipinquanPinglunService service;


    @GetMapping("/list")
    @ApiOperation("获取数据列表")
    public Result list(BlShipinquanPinglun entity, Integer page, Integer limit){
        QueryWrapper<BlShipinquanPinglun> qw = new QueryWrapper<>();
        qw.orderByDesc("create_time");
        IPage<BlShipinquanPinglun> pageList = service.page(new Page<>(page,limit),qw);
        return Result.success().put("data",pageList);
    }

    @PostMapping("/add")
    @ApiOperation("添加")
    public Result add(BlShipinquanPinglun BlShipinquanPinglun){
        BlShipinquanPinglun.setCreateTime(new Date());
        service.save(BlShipinquanPinglun);
        return Result.success();
    }

    @PostMapping("/modify")
    @ApiOperation("修改")
    public Result modify(BlShipinquanPinglun BlShipinquanPinglun){
        BlShipinquanPinglun.setCreateTime(new Date());
        service.updateById(BlShipinquanPinglun);
        return Result.success();
    }

    @PostMapping("/delete")
    @ApiOperation("删除")
    public Result delete(BlShipinquanPinglun BlShipinquanPinglun){
        service.removeById(BlShipinquanPinglun.getId());
        return Result.success();
    }

}
