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.BlShipinquan;
import com.sqx.modules.shipinquan.service.BlShipinquanService;
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/shipinquan")
public class BlShipinquanController {

    @Autowired
    private BlShipinquanService service;


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

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

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

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

}
