package cn.com.ctop.common.module.service.impl;

import cn.com.ctop.common.module.entity.UserAllocation;
import cn.com.ctop.common.module.mapper.UserAllocationMapper;
import cn.com.ctop.common.module.service.IUserAllocationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 用户分配
 * @Author: jeecg-boot
 * @Date: 2019-08-08
 * @Version: V1.0
 */
@Service
@Primary
public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper, UserAllocation> implements IUserAllocationService {

    @Override
    public UserAllocation getByAccountId(Long accountId) {
        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account_id", accountId + "").orderByDesc("id").last("limit 1");
        return this.getOne(queryWrapper);
    }

    @Override
    public List<UserAllocation> getByProjectId(Long projectId, String systemType) {
        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
        if (null != projectId && projectId != 0) {
            queryWrapper.eq("project_id", projectId);
        }
        if (null != systemType && !"".equals(systemType.trim())) {
            queryWrapper.eq("system_type", systemType);
        }
        queryWrapper.orderByDesc("id");
        return this.list(queryWrapper);
    }
}
