# GmwrManagerFlashServiceImpl.java

    package cloud.wconnect.workperformance.service.gmwr.impl;

    import cloud.wconnect.commonlib.exception.ListenerException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.workperformance.entity.gmwr.GmwrManagerFlash;
    import cloud.wconnect.workperformance.mapper.gmwr.GmwrManagerFlashMapper;
    import cloud.wconnect.workperformance.pojo.bo.gmwr.GmwrManagerFlashBO;
    import cloud.wconnect.workperformance.service.gmwr.IGmwrManagerFlashService;
    import cloud.wconnect.workperformance.service.gmwr.managerflash.IGmwrManagerFlashParseService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import jakarta.annotation.Resource;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.context.ApplicationContext;
    import org.springframework.stereotype.Service;

    import java.io.InputStream;
    import java.util.Collection;
    import java.util.Objects;

    /**
     * <p>
     * GM Weekly Report Manager Flash 服务实现类
     * </p>
     *
     * @author zc
     * @since 2024-10-12
     */
    @Slf4j
    @Service
    @DS("work_performance")
    public class GmwrManagerFlashServiceImpl extends ServiceImpl<GmwrManagerFlashMapper, GmwrManagerFlash> implements IGmwrManagerFlashService {
        @Resource
        private ApplicationContext applicationContext;

        /**
         * 获取指定日期范围的 Manager Flash 数据
         *
         * @param propertyDTO 资产
         * @param month       指定年月(yyyyMM)
         * @return GmwrManagerFlash
         * @author zc
         * @date 2024/10/16
         */
        @Override
        public GmwrManagerFlash get(PropertyDTO propertyDTO, long month) {
            return getOne(new LambdaQueryWrapper<GmwrManagerFlash>()
                    .eq(GmwrManagerFlash::getMonth, month)
                    .eq(GmwrManagerFlash::getPropertyId, propertyDTO.getId()));
        }

        /**
         * 删除指定日期范围的 Manager Flash 数据
         *
         * @param propertyId 资产 id
         * @param month      指定年月(yyyyMM)
         * @author zc
         * @date 2024/10/16
         */
        @Override
        public void delete(int propertyId, long month) {
            remove(new LambdaQueryWrapper<GmwrManagerFlash>()
                    .eq(GmwrManagerFlash::getMonth, month)
                    .eq(GmwrManagerFlash::getPropertyId, propertyId));
        }

        /**
         * 解析报告 Manager Flash
         *
         * @param propertyDTO 资产
         * @param in          报告文件流
         * @param source      报告来源
         * @return GmwrManagerFlashBO 集合
         * @author zc
         * @date 2024/10/17
         */
        @Override
        public GmwrManagerFlashBO parseReport(PropertyDTO propertyDTO, InputStream in, String source) {
            Collection<IGmwrManagerFlashParseService> parserList = applicationContext.getBeansOfType(IGmwrManagerFlashParseService.class).values();
            for (IGmwrManagerFlashParseService parser : parserList) {
                if (parser.supports(source)) {
                    return parser.parse(propertyDTO, in);
                }
            }
            throw new ListenerException("Not found report parser");
        }

        /**
         * 处理 Manager Flash
         *
         * @param propertyDTO    资产
         * @param managerFlashBO 报告数据
         * @param targetDate     目标日期(yyyyMM)
         * @author zc
         * @date 2024/10/17
         */
        @Override
        public void handleManagerFlash(PropertyDTO propertyDTO, GmwrManagerFlashBO managerFlashBO, long targetDate) {
            if (Objects.isNull(managerFlashBO)) {
                return;
            }
            GmwrManagerFlash managerFlash = new GmwrManagerFlash();
            managerFlash.setPropertyId(propertyDTO.getId());
            managerFlash.setMonth(targetDate);
            managerFlash.setFbRevenue(managerFlashBO.getFbRevenue());
            managerFlash.setOthersRevenue(managerFlashBO.getOthersRevenue());
            baseMapper.insertOrUpdateByUnique(managerFlash);
        }
    }