package com.gyee.frame.service.impl.ticket;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.frame.model.ticket.Labor;
import com.gyee.frame.mapper.ticket.LaborMapper;
import com.gyee.frame.service.ticket.LaborService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.frame.util.MD5Util;
import com.gyee.frame.util.ticket.TicketUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenmh
 * @since 2020-07-26
 */
@Service
public class LaborServiceImpl extends ServiceImpl<LaborMapper, Labor> implements LaborService {

    @Override
    public List<Labor> getLabors() {
        List<Labor> labors = baseMapper.selectList(null);
        return labors;
    }

    @Override
    public List<Labor> getLaborOfPersonGroup(String groupName) {
        List<Labor> labors = baseMapper.getLaborOfPersonGroup(groupName);
        return labors;
    }

    @Override
    public List<Labor> getLaborOfDept(String dept, String groupName) {
        String role = TicketUtil.roleFormat(groupName);
        List<Labor> labors = baseMapper.getLaborOfDept(dept, role);
        return labors;
    }

    @Override
    public List<Labor>  getLaborOfPerson(String role) {
        List<Labor> labors = baseMapper.getLaborOfPerson(role);
        return labors;
    }

    @Override
    public List<Labor> getLabors(String dept) {
        QueryWrapper<Labor> wrapper = new QueryWrapper<>();
        if (TicketUtil.allDept().contains(dept)){
            wrapper.in("DEPTNUM", dept, "公司领导","安全监察部");
        }

        List<Labor> labors = baseMapper.selectList(wrapper);

        return labors;
    }


    @Override
    public List<Labor> getLaborSingle(double instId, String role) {
        List<Labor> labor = baseMapper.getLaborSingle(instId, role);

        return labor;
    }

    @Override
    public Labor getLaborItem(String laborNum) {
        QueryWrapper<Labor> wrapper = new QueryWrapper<>();
        wrapper.eq("LABORNUM", laborNum);

        Labor labor = baseMapper.selectOne(wrapper);
        return labor;
    }

    @Override
    public List<Labor> getFlowStarter(double instId) {
        return baseMapper.getFlowStarter(instId);
    }

    @Override
    public Labor getLabor(String username, String password) {
        password = MD5Util.encode(password);
        return baseMapper.getLaborOfLogin(username, password);
    }
}
