package com.bonus.material.basic.controller;

import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.InnerAuth;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
import com.bonus.material.basic.domain.BmUnit;

import com.bonus.material.basic.domain.BmUnitType;
import com.bonus.material.basic.service.IBmUnitTypeService;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.system.api.domain.SysDictData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 单位类型管理Controller
 * 
 * @author hongchao
 * @date 2024-12-27
 */
@Api(tags = "单位类型管理接口")
@RestController
@RequestMapping("/bm_unit_type")
@Slf4j
public class BmUnitTypeController extends BaseController
{
    @Autowired
    private IBmUnitTypeService bmUnitTypeService;

    @RequiresPermissionsOrInnerAuth(innerAuth = @InnerAuth, requiresPermissions = @RequiresPermissions("system:dict:list"))
    @GetMapping("/list")
    @SysLog(title = "字典管理", businessType = OperaType.QUERY,logType = 0,module = "系统管理->字典管理")
    public TableDataInfo list(BmUnitType bmUnitType) {
        try{
            startPage();
            List<BmUnitType> list = bmUnitTypeService.selectBmUnitTypeDataList(bmUnitType);
            return getDataTable(list);
        }catch (Exception e){
            log.error(e.toString(),e);
        }
        return  getDataTableError(new ArrayList<>());
    }


    /**
     * 导出往来单位管理列表
     */
    @ApiOperation(value = "导出单位类型管理列表")
    @PreventRepeatSubmit
    @RequiresPermissions("basic:unit:export")
    @SysLog(title = "往来单位管理", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出单位类型管理")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmUnitType bmUnitType)
    {
        List<BmUnitType> list = bmUnitTypeService.selectBmUnitTypeDataList(bmUnitType);
        ExcelUtil<BmUnitType> util = new ExcelUtil<BmUnitType>(BmUnitType.class);
        util.exportExcel(response, list, "单位类型管理数据");
    }

}
