package com.mortals.xhx.module.site.service.impl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.xhx.module.matter.model.MatterEntity;
import com.mortals.xhx.module.matter.service.MatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.site.dao.SiteMatterDao;
import com.mortals.xhx.module.site.model.SiteMatterEntity;
import com.mortals.xhx.module.site.service.SiteMatterService;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
* SiteMatterService
* 站点事项 service实现
*
* @author zxfei
* @date 2022-01-12
*/
@Service("siteMatterService")
public class SiteMatterServiceImpl extends AbstractCRUDServiceImpl<SiteMatterDao, SiteMatterEntity, Long> implements SiteMatterService {

    @Autowired
    private MatterService matterService;


    @Override
    protected void findAfter(SiteMatterEntity params, PageInfo pageInfo, Context context, List<SiteMatterEntity> list) throws AppException {
        list.stream().peek(item->{
            if(!ObjectUtils.isEmpty(item.getMatterId())){
                MatterEntity matterEntity = matterService.getCache(item.getMatterId().toString());
                if(!ObjectUtils.isEmpty(matterEntity)){
                    item.setBelongDept(matterEntity.getBelongDept());
                    item.setWindowToTheSceneNum(matterEntity.getWindowToTheSceneNum());
                    item.setOnlineToTheSceneNum(matterEntity.getOnlineToTheSceneNum());
                }
            }
        }).count();

        super.findAfter(params, pageInfo, context, list);
    }
}