package com.ghy.worker.service.impl;

import com.ghy.worker.domain.WorkerSpecialSkill;
import com.ghy.worker.mapper.WorkerSpecialSkillMapper;
import com.ghy.worker.service.WorkerSpecialSkillService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 师傅特殊技能Service
 *
 * @author HH 2022/6/7
 */
@Service
public class WorkerSpecialSkillServiceImpl implements WorkerSpecialSkillService {

    @Resource
    private WorkerSpecialSkillMapper workerSpecialSkillMapper;

    @Override
    public int insert(WorkerSpecialSkill workerArea) {
        return workerSpecialSkillMapper.insert(workerArea);
    }

    @Override
    public int delete(Long[] ids) {
        return workerSpecialSkillMapper.delete(ids);
    }

    @Override
    public int deleteByWorker(Long workerId) {
        return workerSpecialSkillMapper.deleteByWorker(workerId);
    }

    @Override
    public List<WorkerSpecialSkill> getByWorker(Long workerId) {
        return workerSpecialSkillMapper.getByWorker(workerId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateWorkerSpecialSkill(Long workerId, List<WorkerSpecialSkill> skills) {
        workerSpecialSkillMapper.deleteByWorker(workerId);
        if (CollectionUtils.isNotEmpty(skills)) {
            workerSpecialSkillMapper.batchInsert(skills);
        }
    }
}
