package com.gree.mall.manager.logic.third;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.manager.bean.admin.AdminUserCom;
import com.gree.mall.manager.bean.third.ThirdPartyVO;
import com.gree.mall.manager.bean.websit.SettlementOrderLogicVO;
import com.gree.mall.manager.commonmapper.CommonMapper;
import com.gree.mall.manager.commonmapper.ThirdPartyCMapper;
import com.gree.mall.manager.logic.common.CommonLogic;
import com.gree.mall.manager.plus.entity.ThirdParty;
import com.gree.mall.manager.plus.service.ThirdPartyService;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import com.gree.mall.manager.zfire.util.FieldUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ThirdPartyLogic {

    @Autowired
    ThirdPartyCMapper thirdPartyCMapper;

    @Autowired
    CommonLogic commonLogic;

    @Autowired
    ThirdPartyService thirdPartyService;


    public IPage<ThirdPartyVO> page(ZfireParamBean zfireParamBean) {

        AdminUserCom adminUser = commonLogic.getAdminUser();
        List<String> companyWechatIds = adminUser.getCompanyWechatIds();

        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean, SettlementOrderLogicVO.class);
        IPage<ThirdPartyVO> settlementOrderLogicVOIPage = thirdPartyCMapper.page(new Page(zfireParamBean.getPageNum(),
                        zfireParamBean.getPageSize()),
                zfireParam
                , companyWechatIds);

        return settlementOrderLogicVOIPage;
    }

    public ThirdParty detail(String id) {
        ThirdParty thirdParty = thirdPartyService.getById(id);
        return thirdParty;
    }

    public void add(ThirdParty thirdParty) {
        thirdParty.insert();
    }

    public void update(ThirdParty thirdParty) {
        thirdParty.updateById();
    }

    public void del(String id) {
        thirdPartyService.removeById(id);
    }
}
