package bus.service.impl;

import bus.model.SnowflakeUtil;
import bus.model.dto.BNoticeInfoDto;
import bus.model.dto.page.BNoticeInfoPageDto;
import bus.model.po.BBusInfoPo;
import bus.model.vo.BNoticeInfoVo;
import bus.model.po.BNoticeInfoPo;
import bus.mapper.BNoticeInfoMapper;

import bus.service.BNoticeInfoService;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.orcas.common.sso.model.ExtInfo;
import com.orcas.iso.config.common.user.CurrentUserHolder;
import com.qzwisdom.qzframework.core.tool.exception.BusinessException;
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-01 10:21:43
 **/
@Service
public class BNoticeInfoServiceImpl extends ServiceImpl<BNoticeInfoMapper, BNoticeInfoPo> implements BNoticeInfoService {

    @Autowired
    private BNoticeInfoMapper bNoticeInfoMapper;
    @Resource
    private SnowflakeUtil snowflakeUtil;

	/**
     * 详情
     * @param id
     * @return
     */
    @Override
    public BNoticeInfoDto getDetailById(String id){
        BNoticeInfoPo bNoticeInfoPo = this.bNoticeInfoMapper.selectById(id);
        BNoticeInfoDto bNoticeInfoDto = BeanUtil.toBean(bNoticeInfoPo, BNoticeInfoDto.class);
        return bNoticeInfoDto;
    }

	/**
     * 保存
     * @param dto
     * @return
     */
    @Override
	public void save(BNoticeInfoDto dto){
        BNoticeInfoPo po = new BNoticeInfoPo();
        BeanUtils.copyProperties(dto,po);
        ExtInfo extInfo = CurrentUserHolder.get();
        po.setId(snowflakeUtil.snowflakeId());
        if(dto.getPubTime()==null) {
            po.setPubTime(new Date());
        }
        po.setCreateTime(new Date());
        po.setUpdateTime(new Date());
        po.setCreatorId(extInfo.getUserId());
        po.setUpdaterId(extInfo.getUserId());
        po.setCreatorName(extInfo.getUserName());
        po.setUpdaterName(extInfo.getUserName());
		this.bNoticeInfoMapper.insert(po);
    }

    /**
    * 列表
    * @param dto
    * @return
    */
    @Override
    public List<BNoticeInfoDto> list(BNoticeInfoPageDto dto){
        return this.bNoticeInfoMapper.list(dto);
    }

	/**
     * 修改
     * @param dto
     * @return
     */
    @Override
    public void update(BNoticeInfoDto dto){
        BNoticeInfoPo po = new BNoticeInfoPo();
        BeanUtils.copyProperties(dto,po);
        if(dto.getPubTime()==null) {
            po.setPubTime(new Date());
        }
        ExtInfo extInfo = CurrentUserHolder.get();
        po.setUpdateTime(new Date());
        po.setUpdaterId(extInfo.getUserId());
        po.setUpdaterName(extInfo.getUserName());
		bNoticeInfoMapper.updateById(po);
    }

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