package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.entity.TbShopExtend;
import cn.ysk.cashier.mybatis.service.TbShopExtendService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import cn.ysk.cashier.dto.shop.TbShopExtendQueryCriteria;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 店铺扩展信息(TbShopExtend)表控制层
 *
 * @author ww
 * @since 2024-07-18 11:10:16
 */
@RestController
@RequestMapping("tbShopExtend")
public class TbShopExtendController {
    /**
     * 服务对象
     */
    @Resource
    private TbShopExtendService tbShopExtendService;

    @GetMapping
    @ApiOperation("分页查询")
    public ResponseEntity<Object> selectAll(TbShopExtendQueryCriteria criteria) {
        return new ResponseEntity<>(tbShopExtendService.queryAll(criteria), HttpStatus.OK);
    }

    @GetMapping("{id}")
    @ApiOperation("通过Id查询详情")
    public TbShopExtend selectOne(@PathVariable Serializable id) {
        return tbShopExtendService.getById(id);
    }

    @PostMapping
    @ApiOperation("新增")
    public ResponseEntity<Object> insert(@RequestBody TbShopExtend tbShopExtend) {
        tbShopExtend.setCreateTime(new Date());
        tbShopExtendService.saveInfo(tbShopExtend);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @ApiOperation("通过id修改")
    public ResponseEntity<Object> update(@RequestBody TbShopExtend tbShopExtend) {
        if (tbShopExtend.getId() != null) {
            tbShopExtendService.updateById(tbShopExtend);
        } else {
            tbShopExtendService.saveInfo(tbShopExtend);
        }
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @ApiOperation("删除")
    public ResponseEntity<Object> delete(@RequestParam("idList") List<Long> idList) {
        tbShopExtendService.removeByIds(idList);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}

