package cn.ezhizao.project.business.shaftCategory.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ezhizao.project.business.shaftCategory.domain.BizShaftCategory;
import cn.ezhizao.project.business.shaftCategory.service.IBizShaftCategoryService;

/**
 * 盘点同步Controller
 *
 * @author ezhizao
 * @date 2023-11-15
 */
@RestController
@RequestMapping("/base/shaftCategory")
public class BizShaftCategoryController extends BaseController {
    @Resource
    private IBizShaftCategoryService bizShaftCategoryService;
    @Resource
    HttpServletRequest request;

    /**
     * 查询盘点同步列表
     */
    @PreAuthorize("@ss.hasPermi('base:shaftCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizShaftCategory bizShaftCategory) throws NoSuchFieldException, IllegalAccessException {
        final String tenantId = request.getHeader("tenantId");
        bizShaftCategory.setTenantId(Long.valueOf(tenantId));
        startPage();
        List<BizShaftCategory> list = bizShaftCategoryService.getList(bizShaftCategory);
        return getDataTable(list);
    }

    /**
     * 导出盘点同步列表
     */
    @PreAuthorize("@ss.hasPermi('base:shaftCategory:export')")
    @Log(title = "盘点同步", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizShaftCategory bizShaftCategory) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(bizShaftCategory);
        List<BizShaftCategory> list = bizShaftCategoryService.getList(bizShaftCategory);
        ExcelUtil<BizShaftCategory> util = new ExcelUtil<BizShaftCategory>(BizShaftCategory.class);
        util.exportExcel(response, list, "盘点同步数据");
    }

    /**
     * 获取盘点同步详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:shaftCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizShaftCategoryService.getById(id));
    }

    /**
     * 新增盘点同步
     */
    @PreAuthorize("@ss.hasPermi('base:shaftCategory:add')")
    @Log(title = "盘点同步", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizShaftCategory bizShaftCategory) throws NoSuchFieldException, IllegalAccessException {
        String tenantId = request.getHeader("tenantId");
        bizShaftCategory.setTenantId(Long.valueOf(tenantId));
        return toAjax(bizShaftCategoryService.save(bizShaftCategory));
    }

    /**
     * 修改盘点同步
     */
    @PreAuthorize("@ss.hasPermi('base:shaftCategory:edit')")
    @Log(title = "盘点同步", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizShaftCategory bizShaftCategory) throws NoSuchFieldException, IllegalAccessException {
        String tenantId = request.getHeader("tenantId");
        bizShaftCategory.setTenantId(Long.valueOf(tenantId));
        return toAjax(bizShaftCategoryService.updateById(bizShaftCategory));
    }

    /**
     * 删除盘点同步
     */
    @PreAuthorize("@ss.hasPermi('base:shaftCategory:remove')")
    @Log(title = "盘点同步", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(bizShaftCategoryService.removeBatchByIds(ids));
    }

    /**
     * 获取轴类型Id
     */
    @GetMapping(value = "/getShaftCode")
    public BizShaftCategory getShaftCode(@PathVariable("id") String code) {
        return bizShaftCategoryService.query().eq("sub_category_code", code).one();
    }

}
