package com.usky.fire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.fire.domain.DemGridMemderVice;
import com.usky.fire.mapper.DemGridMemderViceMapper;
import com.usky.fire.service.DemGridMemderViceService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 网格员管理附属表 服务实现类
 * </p>
 *
 * @author JCB
 * @since 2022-11-15
 */
@Service
public class DemGridMemderViceServiceImpl extends AbstractCrudService<DemGridMemderViceMapper, DemGridMemderVice> implements DemGridMemderViceService {

    @Override
    public List<DemGridMemderVice> gridMemderViceList(List<Integer> gridMemberIdList) {
        LambdaQueryWrapper<DemGridMemderVice> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(CollectionUtils.isNotEmpty(gridMemberIdList), DemGridMemderVice::getGridMemberId, gridMemberIdList);
        List<DemGridMemderVice> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public void addGridMemderVice(DemGridMemderVice demGridMemderVice) {
        demGridMemderVice.setCreateTime(LocalDateTime.now());
        demGridMemderVice.setCreator(SecurityUtils.getUsername());
        this.save(demGridMemderVice);
    }

    @Override
    public void updateGridMemderVice(DemGridMemderVice demGridMemderVice) {
        demGridMemderVice.setUpdatePerson(SecurityUtils.getUsername());
        demGridMemderVice.setUpdateTime(LocalDateTime.now());
        this.updateById(demGridMemderVice);
    }

    @Override
    public List<String> gridMemderViceLists(Integer gridMemberId) {
        LambdaQueryWrapper<DemGridMemderVice> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(DemGridMemderVice::getId)
                .eq(DemGridMemderVice::getGridMemberId, gridMemberId);
        List<DemGridMemderVice> list = this.list(queryWrapper);
        List<String> list1 = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                list1.add("" + list.get(i).getId());
            }
        }
        return list1;
    }

    @Override
    public void delGridMemderVice(Integer id) {
        this.removeById(id);
    }

}
