package com.css.txw.mhzc.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.css.ggzc.framework.common.util.gy.GyUtils;
import com.css.ggzc.framework.common.util.object.BeanUtils;
import com.css.ggzc.framework.file.utils.GgzcFileUtils;
import com.css.ggzc.framework.session.SessionUtils;
import com.css.txw.mhzc.pojo.domain.TxwMhzcGglbDO;
import com.css.txw.mhzc.mapper.TxwMhzcGglbMapper;
import com.css.txw.mhzc.pojo.vo.GglbReqVO;
import com.css.txw.mhzc.pojo.vo.GglbVO;
import com.css.txw.mhzc.service.TxwMhzcGglbService;
import com.css.txw.mhzc.service.TxwMhzcGglbService;
import org.springframework.stereotype.Service;

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

/**
* @author AirlH
* @description 针对表【txw_mhzc_gglb(广告栏表)】的数据库操作Service实现
* @createDate 2025-10-20 10:24:42
*/
@Service
public class TxwMhzcGglbServiceImpl extends ServiceImpl<TxwMhzcGglbMapper, TxwMhzcGglbDO>
    implements TxwMhzcGglbService {

    @Resource
    private TxwMhzcGglbMapper gglbMapper;

    @Override
    public String saveGgxx(GglbVO gglbVO) {
        TxwMhzcGglbDO txwMhzcGglbDO = BeanUtils.toBean(gglbVO, TxwMhzcGglbDO.class);
        if (GyUtils.isNull(gglbVO.getUuid())){
            txwMhzcGglbDO.setYxbz("Y");
            txwMhzcGglbDO.setLrrq(new Date());
            txwMhzcGglbDO.setUuid(IdUtil.fastSimpleUUID());
            txwMhzcGglbDO.setLrruuid(SessionUtils.getYhUuid());
            this.save(txwMhzcGglbDO);
        }else {
            txwMhzcGglbDO.setXgrq(new Date());
            txwMhzcGglbDO.setXgruuid(SessionUtils.getYhUuid());
            this.updateById(txwMhzcGglbDO);
        }

        return "success";
    }

    @Override
    public List<GglbVO> getGgxxList(GglbReqVO reqVO) {
        List<TxwMhzcGglbDO> ggxxList = gglbMapper.getGgxxList(reqVO);
        if (GyUtils.isNull(ggxxList)) return null;
        return BeanUtils.toBean(ggxxList,GglbVO.class);
    }

    @Override
    public String delGgxx(String uuid) {
        TxwMhzcGglbDO gglbDO = this.getById(uuid);
        if (!GyUtils.isNull(gglbDO)){//删除图片
            String tpid = gglbDO.getTpid();
            GgzcFileUtils.delete(tpid);
        }
        this.removeById(uuid);
        return "success";
    }
}




