package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.diagbot.entity.IntroduceDetail;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.impl.IntroduceDetailServiceImpl;
import com.diagbot.util.DateUtil;
import com.diagbot.util.UserUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:
 * @Author:zhaops
 * @time: 2018/11/16 14:31
 */
@Component
public class IntroduceDetailFacade extends IntroduceDetailServiceImpl {

    /**
     * 获取提示信息明细
     *
     * @param introduceId
     * @return
     */
    public List<IntroduceDetail> getByIntroduceId(Long introduceId) {
        QueryWrapper<IntroduceDetail> introduceDetailQueryWrapper = new QueryWrapper<>();
        introduceDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).
                eq("introduce_id", introduceId);
        return this.list(introduceDetailQueryWrapper);
    }

    /**
     * 单条删除提示信息明细 逻辑删除
     *
     * @param id
     * @return
     */
    public Boolean deleteRecord(Long id) {
        UpdateWrapper<IntroduceDetail> introduceDetailUpdateWrapper = new UpdateWrapper<>();
        introduceDetailUpdateWrapper.eq("id", id).
                eq("is_deleted", IsDeleteEnum.N.getKey()).
                set("is_deleted", IsDeleteEnum.Y.getKey()).
                set("modifier", UserUtils.getCurrentPrincipleID()).
                set("gmt_modified", DateUtil.now());
        this.update(new IntroduceDetail(), introduceDetailUpdateWrapper);
        return true;
    }

    /**
     * 批量删除提示信息明细 逻辑删除
     *
     * @param ids
     * @return
     */
    public Boolean deleteRecords(Long[] ids) {
        UpdateWrapper<IntroduceDetail> introduceDetailUpdateWrapper = new UpdateWrapper<>();
        introduceDetailUpdateWrapper.in("id", ids).
                eq("is_deleted", IsDeleteEnum.N.getKey()).
                set("is_deleted", IsDeleteEnum.Y.getKey()).
                set("modifier", UserUtils.getCurrentPrincipleID()).
                set("gmt_modified", DateUtil.now());
        this.update(new IntroduceDetail(), introduceDetailUpdateWrapper);
        return true;
    }
}