package com.gci.boot.modules.vehicles.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gci.boot.common.log.annotation.AddSysLog;
import com.gci.boot.common.vo.Result;
import com.gci.boot.modules.vehicles.entity.TbCustomizedTemplatePart;
import com.gci.boot.modules.vehicles.service.ITbCustomizedTemplatePartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * <p>
 * 定制件详情表 前端控制器
 * </p>
 *
 * @author 2464
 * @since 2023-09-12
 */
@RestController
@RequestMapping("/tb-customized-template-part")
public class TbCustomizedTemplatePartController {
    @Autowired
    private ITbCustomizedTemplatePartService iTbCustomizedTemplatePartService;

    /**
     * 分页列表查询
     *
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AddSysLog(value = "定制件详情-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            HttpServletRequest req) {
        Page<TbCustomizedTemplatePart> page = new Page<TbCustomizedTemplatePart>(pageNo, pageSize);
        LambdaQueryWrapper<TbCustomizedTemplatePart> lambdaQueryWrapper = new LambdaQueryWrapper<TbCustomizedTemplatePart>();
        IPage<TbCustomizedTemplatePart> pageList = iTbCustomizedTemplatePartService.page(page, lambdaQueryWrapper);
        return Result.ok(pageList);
    }

    /**
     * 添加
     */
    @AddSysLog(value = "定制件详情-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody TbCustomizedTemplatePart tbCustomizedTemplatePart) {
        iTbCustomizedTemplatePartService.save(tbCustomizedTemplatePart);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑
     */
    @AddSysLog(value = "定制件详情-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody TbCustomizedTemplatePart tbCustomizedTemplatePart) {
        iTbCustomizedTemplatePartService.updateById(tbCustomizedTemplatePart);
        return Result.ok("编辑成功！");
    }

    /**
     * 删除
     */
    @AddSysLog(value = "定制件详情-删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        iTbCustomizedTemplatePartService.removeById(id);
        return Result.ok("删除成功！");
    }

    /**
     * 批量删除
     */
    @AddSysLog(value = "定制件详情-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        iTbCustomizedTemplatePartService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功！");
    }
}
