package com.shkj.wms.controller.temp;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.shkj.common.annotation.RepeatSubmit;
import com.shkj.wms.bo.BaseConsignorQueryBo;
import com.shkj.wms.bo.BaseConsignorQueryListBo;
import com.shkj.wms.bo.BaseConsignorSaveOrUpdateBo;
import com.shkj.wms.common.SwitchStatusEntity;
import com.shkj.wms.config.ValidList;
import com.shkj.wms.service.IBaseConsignorService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.shkj.common.core.controller.BaseController;
import com.shkj.common.core.domain.Result;
import com.shkj.wms.vo.BaseConsignorVo;
import com.shkj.common.core.page.TableDataInfo;

import javax.validation.Valid;

/**
 * 货主资料Controller
 *
 * @menu 货主资料管理
 * @author lch
 * @date 2022-03-22
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/consignor")
public class BaseConsignorController extends BaseController {

    private final IBaseConsignorService iBaseConsignorService;

    /**
     * 查询货主分页资料列表(下拉框)
     */
    @GetMapping("/list")
    public TableDataInfo<BaseConsignorVo> list(BaseConsignorQueryBo bo) {
        startPage();
        List<BaseConsignorVo> list = iBaseConsignorService.queryListOption(bo);
        return getDataTable(list);
    }

    /**
     * 查询当前人员具有权限的货主分页资料列表
     */
    @GetMapping("/queryList")
    public Result<List<BaseConsignorVo>> queryList(BaseConsignorQueryListBo bo) {
        BaseConsignorQueryBo boList =  BeanUtil.toBean(bo,BaseConsignorQueryBo.class);
        List<BaseConsignorVo> list = iBaseConsignorService.queryList(boList);
        return Result.ok().data(list);
    }

    /**
     * 保存或者修改业主资料（根据是否有id来判断新增或者修改）
     * @param list
     * @return
     */
    @PostMapping("/saveOrUpdateBaseConsignors")
    @RepeatSubmit
    public Result<Boolean> saveOrUpdateBaseConsignors(@Valid @RequestBody ValidList<BaseConsignorSaveOrUpdateBo> list){
        return iBaseConsignorService.saveOrUpdateBaseConsignors(list);
    }

    /**
     * 切换货主状态(开关 0 否 1 是)
     */
    @PostMapping("/switchStatus")
    public Result<Boolean> switchStatus(@Valid @RequestBody SwitchStatusEntity switchStatusEntity) {
        return iBaseConsignorService.switchStatus(switchStatusEntity);
    }

    /**
     * 删除货主资料
     */
    @PostMapping("/remove")
    public Result<Boolean> remove(@Valid @RequestBody ValidList<Long> ids) {
        return iBaseConsignorService.deleteWithValidById(ids, true);
    }

}
