package com.bonus.material.basic.controller;

import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.basic.domain.BmUnit;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.basic.domain.BmUnitPerson;
import com.bonus.material.basic.service.IBmUnitPersonService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;

import java.util.List;

/**
 * 往来单位管理Controller
 * 
 * @author xsheng
 * @date 2024-09-27
 */
@Api(tags = "往来单位管理接口")
@RestController
@RequestMapping("/bm_unit_person")
public class BmUnitPersonController extends BaseController
{
    @Autowired
    private IBmUnitPersonService bmUnitPersonService;

    /**
     * 查询往来单位绑定管理列表
     */
    @ApiOperation(value = "查询往来单位绑定管理列表")
    @RequiresPermissions("basic:person:list")
    @GetMapping("/list")
    public TableDataInfo list(BmUnitPerson bmUnitPerson)
    {
        startPage();
        List<BmUnit> list = bmUnitPersonService.selectBmUnitList(bmUnitPerson);
        return getDataTable(list);
    }

    /**
     * 统计往来单位人员
     */
    @ApiOperation(value = "统计往来单位人员")
    @RequiresPermissions("basic:person:list")
    @SysLog(title = "往来单位管理", businessType = OperaType.QUERY, logType = 1,module = "仓储管理->统计往来单位人员")
    @GetMapping("/{unitId}")
    public AjaxResult countBmUnitPersonByUnitId(@PathVariable Long unitId)
    {
        int result = bmUnitPersonService.countBmUnitPersonByUnitId(unitId);
        return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
    }

    /**
     * 绑定往来单位人员列表
     */
    @ApiOperation(value = "绑定往来单位人员列表")
    @PreventRepeatSubmit
    @RequiresPermissions("basic:person:bind")
    @SysLog(title = "往来单位人员管理", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->绑定往来单位人员")
    @PostMapping("/bind")
    public AjaxResult bind(@RequestBody BmUnitPerson bmUnitPerson)
    {
        return bmUnitPersonService.insertBmUnitPerson(bmUnitPerson);
    }

    /**
     * 解绑往来单位人员列表
     */
    @ApiOperation(value = "解绑往来单位人员列表")
    @PreventRepeatSubmit
    @RequiresPermissions("basic:person:remove")
    @SysLog(title = "往来单位管理", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->解绑往来单位人员")
	@DeleteMapping("/{unitId}")
    public AjaxResult unbind(@PathVariable Long unitId)
    {
        return bmUnitPersonService.deleteBmUnitPersonByID(unitId);
    }
}
