package com.maintain.business.controller;

import java.util.List;
import java.util.Arrays;

import com.maintain.business.domain.bo.ErpTyrePositionBo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.maintain.common.annotation.RepeatSubmit;
import com.maintain.common.annotation.Log;
import com.maintain.common.core.controller.BaseController;
import com.maintain.common.core.domain.PageQuery;
import com.maintain.common.core.domain.R;
import com.maintain.common.core.validate.AddGroup;
import com.maintain.common.core.validate.EditGroup;
import com.maintain.common.enums.BusinessType;
import com.maintain.common.utils.poi.ExcelUtil;
import com.maintain.business.domain.vo.ErpTyrePositionVo;
import com.maintain.business.service.IErpTyrePositionService;
import com.maintain.common.core.page.TableDataInfo;

/**
 * 客户信息-车型-胎位
 *
 * @author liushuai
 * @date 2025-03-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/vehicleModelTyre")
public class ErpTyrePositionController extends BaseController {

    private final IErpTyrePositionService iErpTyrePositionService;

    /**
     * 查询客户信息-车型-胎位列表
     */
    @SaCheckPermission("business:vehicleModelTyre:list")
    @GetMapping("/list")
    public TableDataInfo<ErpTyrePositionVo> list(ErpTyrePositionBo bo, PageQuery pageQuery) {
        return iErpTyrePositionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出客户信息-车型-胎位列表
     */
    @SaCheckPermission("business:vehicleModelTyre:export")
    @Log(title = "客户信息-车型-胎位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpTyrePositionBo bo, HttpServletResponse response) {
        List<ErpTyrePositionVo> list = iErpTyrePositionService.queryList(bo);
        ExcelUtil.exportExcel(list, "客户信息-车型-胎位", ErpTyrePositionVo.class, response);
    }

    /**
     * 获取客户信息-车型-胎位详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:vehicleModelTyre:query")
    @GetMapping("/{id}")
    public R<ErpTyrePositionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpTyrePositionService.queryById(id));
    }

    /**
     * 新增客户信息-车型-胎位
     */
    @SaCheckPermission("business:vehicleModelTyre:add")
    @Log(title = "客户信息-车型-胎位", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpTyrePositionBo bo) {
        return toAjax(iErpTyrePositionService.insertByBo(bo));
    }

    /**
     * 修改客户信息-车型-胎位
     */
    @SaCheckPermission("business:vehicleModelTyre:edit")
    @Log(title = "客户信息-车型-胎位", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpTyrePositionBo bo) {
        return toAjax(iErpTyrePositionService.updateByBo(bo));
    }

    /**
     * 删除客户信息-车型-胎位
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:vehicleModelTyre:remove")
    @Log(title = "客户信息-车型-胎位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpTyrePositionService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
