package com.mortals.xhx.module.sheet.service.impl;

import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.sheet.dao.SheetMatterDao;
import com.mortals.xhx.module.sheet.model.SheetMatterEntity;
import com.mortals.xhx.module.sheet.service.SheetMatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * SheetMatterService
 * 基础事项 service实现
 *
 * @author zxfei
 * @date 2022-09-27
 */
@Service("sheetMatterService")
public class SheetMatterServiceImpl extends AbstractCRUDServiceImpl<SheetMatterDao, SheetMatterEntity, Long> implements SheetMatterService {

    @Autowired
    private ISiteFeign siteFeign;

    @Override
    public Result<SheetMatterEntity> findSubList(SheetMatterEntity matterQuery, PageInfo pageInfo, Context context) throws AppException {
        Rest<SitePdu> rest = siteFeign.info(matterQuery.getSiteId());
        if (rest.getCode() == YesNoEnum.YES.getValue()) {
            if (ObjectUtils.isEmpty(matterQuery.getAreaCode())) {
                matterQuery.setAreaCode(rest.getData() == null ? null : rest.getData().getAreaCode());
            }
        } else {
            return new Result<>();
        }
        return this.dao.getSubList(matterQuery, pageInfo);
    }
}