package bus.service.impl;

import bus.mapper.BAdvertMapper;
import bus.model.SnowflakeUtil;
import bus.model.dto.BAdvertDto;
import bus.model.dto.BAdvertPageDto;
import bus.model.po.BAdvertPo;
import bus.service.BAdvertService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.orcas.common.sso.model.ExtInfo;
import com.orcas.iso.config.common.user.CurrentUserHolder;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;

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

/**
 * @Program: bus
 * @Description: 描述
 * @Author: zy
 * @Date: 2025-03-06 22:43:32
 **/
@Service
public class BAdvertServiceImpl extends ServiceImpl<BAdvertMapper, BAdvertPo> implements BAdvertService {

    @Autowired
    private BAdvertMapper bAdvertMapper;
    @Resource
    private SnowflakeUtil snowflakeUtil;

	/**
     * 详情
     * @param id
     * @return
     */
    @Override
    public BAdvertPo getDetailById(String id){
        return this.bAdvertMapper.selectById(id);
    }

	/**
     * 保存
     * @param dto
     * @return
     */
    @Override
	public void save(BAdvertDto dto){
        BAdvertPo po = new BAdvertPo();
        BeanUtils.copyProperties(dto,po);

		this.bAdvertMapper.insert(po);
        ExtInfo extInfo = CurrentUserHolder.get();
        po.setId(snowflakeUtil.snowflakeId());
        po.setCreateTime(new Date());
        po.setUpdateTime(new Date());
        po.setCreatorId(extInfo.getUserId());
        po.setUpdaterId(extInfo.getUserId());
        po.setCreatorName(extInfo.getUserName());
        po.setUpdaterName(extInfo.getUserName());
    }

    /**
    * 列表
    * @param dto
    * @return
    */
    @Override
    public List<BAdvertPo> list(BAdvertPageDto dto){
        return this.bAdvertMapper.list(dto);
    }

	/**
     * 修改
     * @param dto
     * @return
     */
    @Override
    public void update(BAdvertDto dto){
        BAdvertPo po = new BAdvertPo();
        BeanUtils.copyProperties(dto,po);
        ExtInfo extInfo = CurrentUserHolder.get();
        po.setUpdateTime(new Date());
        po.setUpdaterId(extInfo.getUserId());
        po.setUpdaterName(extInfo.getUserName());
		bAdvertMapper.updateById(po);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public void delete(String id){
		bAdvertMapper.deleteById(id);
    }
}
