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

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.gree.mall.manager.bean.admin.AdminUserCom;
import com.gree.mall.manager.logic.common.CommonLogic;
import com.gree.mall.manager.plus.entity.MiniNotice;
import com.gree.mall.manager.plus.service.MiniNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;


@Component
public class MiniNoticeLogic {
    @Autowired
    private MiniNoticeService miniNoticeService;

    @Autowired
    CommonLogic commonLogic;

    /**
     * 新增
     * @param miniNotice
     */
    public void add(HttpServletRequest request,MiniNotice miniNotice){
        //获取当前登录企业微信id
        AdminUserCom adminUser = commonLogic.getAdminUser(request);

        Date createDate = new Date();
        miniNotice.setCreateTime(createDate);
        miniNoticeService.save(miniNotice);
    }

    /**
     * 修改
     * @param miniNotice
     */
    public void update(MiniNotice miniNotice){
        miniNoticeService.updateById(miniNotice);
    }


    /**
     * 查询
     * @return
     */
    public List<MiniNotice> select(HttpServletRequest request){
        //获取当前登录企业微信id
        AdminUserCom adminUser = commonLogic.getAdminUser(request);
        List<String> companyWechatIds = adminUser.getAdminCompanyIds();


        List<MiniNotice> list = miniNoticeService.lambdaQuery()
                .in(CollectionUtils.isNotEmpty(companyWechatIds),MiniNotice::getCompanyId,companyWechatIds)
                .list();
        return list;
    }



























}
