package com.yc.ship.module.resource.service.drivergroup;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.module.resource.controller.admin.drivergroup.vo.DriverGroupPageReqVO;
import com.yc.ship.module.resource.controller.admin.drivergroup.vo.DriverGroupSaveReqVO;
import com.yc.ship.module.resource.controller.admin.vo.SimpleListReqVO;
import com.yc.ship.module.resource.dal.dataobject.drivergroup.DriverGroupDO;
import com.yc.ship.module.resource.dal.mysql.drivergroup.DriverGroupMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;


/**
 * 驾驶员分组 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class DriverGroupServiceImpl implements DriverGroupService {

    @Resource
    private DriverGroupMapper driverGroupMapper;

    @Override
    public String createDriverGroup(DriverGroupSaveReqVO createReqVO) {
        // 插入
        DriverGroupDO driverGroup = BeanUtils.toBean(createReqVO, DriverGroupDO.class);
        driverGroup.setId(IdWorker.getIdStr(driverGroup));
        driverGroup.setDeleted(false);
        driverGroupMapper.insert(driverGroup);
        // 返回
        return driverGroup.getId();
    }

    @Override
    public void updateDriverGroup(DriverGroupSaveReqVO updateReqVO) {
        // 更新
        DriverGroupDO updateObj = BeanUtils.toBean(updateReqVO, DriverGroupDO.class);
        driverGroupMapper.updateById(updateObj);
    }

    @Override
    public void deleteDriverGroup(String id) {
        // 删除
        driverGroupMapper.deleteById(id);
    }

    @Override
    public DriverGroupDO getDriverGroup(String id) {
        return driverGroupMapper.selectById(id);
    }

    @Override
    public PageResult<DriverGroupDO> getDriverGroupPage(DriverGroupPageReqVO pageReqVO) {
        return driverGroupMapper.selectPage(pageReqVO);
    }

    @Override
    public List<DriverGroupDO> getGroupList(SimpleListReqVO listReqVO) {
        List<DriverGroupDO> list = driverGroupMapper.selectList(listReqVO);
        return list;
    }

}