/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.callcenter.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.callcenter.entity.Calllosscount;
import com.tofly.callcenter.mapper.CalllosscountMapper;
import com.tofly.callcenter.service.CalllosscountService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 标识未接来电记录用作统计
 *
 * @author admin
 * @date Thu Sep 29 00:00:00 CST 2022
 */
@Service("calllosscountService")
@AllArgsConstructor
public class CalllosscountServiceImpl extends ServiceImpl<CalllosscountMapper, Calllosscount> implements CalllosscountService {

    /**
     * 未接来电数量统计接口
     *
     * @return long
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long calllosscount(String empcode) {
        if (!StringUtils.isEmpty(empcode)){
            List<Calllosscount> info = baseMapper.getInsertInfo(empcode);
            if (info != null && !info.isEmpty()) {
                saveBatch(info);
            }
            return baseMapper.calllosscount(empcode);
        }else {
            return 0L;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateFlag(String empcode) {
        return update(Wrappers.<Calllosscount>lambdaUpdate()
                .eq(!StringUtils.isEmpty(empcode), Calllosscount::getEmpcode, empcode)
                .set(Calllosscount::getFlag, "1")
                .eq(Calllosscount::getFlag, "0"));
    }
}
