package com.yanzhu.jh.project.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanzhu.jh.project.mapper.SurProjectAttendanceGroupMapper;
import com.yanzhu.jh.project.domain.SurProjectAttendanceGroup;
import com.yanzhu.jh.project.service.ISurProjectAttendanceGroupService;
import com.ruoyi.common.utils.SecurityUtils;
/**
 * 广联达班组信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-09-26
 */
@Service
public class SurProjectAttendanceGroupServiceImpl implements ISurProjectAttendanceGroupService 
{
    @Autowired
    private SurProjectAttendanceGroupMapper surProjectAttendanceGroupMapper;

    /**
     * 查询广联达班组信息
     * 
     * @param id 广联达班组信息主键
     * @return 广联达班组信息
     */
    @Override
    public SurProjectAttendanceGroup selectSurProjectAttendanceGroupById(Long id)
    {
        return surProjectAttendanceGroupMapper.selectSurProjectAttendanceGroupById(id);
    }

    /**
     * 查询广联达班组信息列表
     * 
     * @param surProjectAttendanceGroup 广联达班组信息
     * @return 广联达班组信息
     */
    @Override
    public List<SurProjectAttendanceGroup> selectSurProjectAttendanceGroupViewList(SurProjectAttendanceGroup surProjectAttendanceGroup)
    {
        return surProjectAttendanceGroupMapper.selectSurProjectAttendanceGroupViewList(surProjectAttendanceGroup);
    }

    /**
     * 查询广联达班组信息列表
     *
     * @param surProjectAttendanceGroup 广联达班组信息
     * @return 广联达班组信息集合
     */
    public List<SurProjectAttendanceGroup> selectSurProjectAttendanceGroupList(SurProjectAttendanceGroup surProjectAttendanceGroup) {
        return surProjectAttendanceGroupMapper.selectSurProjectAttendanceGroupList(surProjectAttendanceGroup);
    }
    /**
     * 新增广联达班组信息
     * 
     * @param surProjectAttendanceGroup 广联达班组信息
     * @return 结果
     */
    @Override
    public int insertSurProjectAttendanceGroup(SurProjectAttendanceGroup surProjectAttendanceGroup)
    {
        if(StringUtils.isEmpty(surProjectAttendanceGroup.getCreateBy())){
            surProjectAttendanceGroup.setCreateBy("task");
        }
        return surProjectAttendanceGroupMapper.insertSurProjectAttendanceGroup(surProjectAttendanceGroup);
    }

    /**
     * 修改广联达班组信息
     * 
     * @param surProjectAttendanceGroup 广联达班组信息
     * @return 结果
     */
    @Override
    public int updateSurProjectAttendanceGroup(SurProjectAttendanceGroup surProjectAttendanceGroup)
    {
        if(StringUtils.isEmpty(surProjectAttendanceGroup.getCreateBy())){
            surProjectAttendanceGroup.setUpdateBy("task");
        }
        surProjectAttendanceGroup.setUpdateTime(DateUtils.getNowDate());
        return surProjectAttendanceGroupMapper.updateSurProjectAttendanceGroup(surProjectAttendanceGroup);
    }

    /**
     * 批量删除广联达班组信息
     * 
     * @param ids 需要删除的广联达班组信息主键
     * @return 结果
     */
    @Override
    public int deleteSurProjectAttendanceGroupByIds(Long[] ids)
    {
        return surProjectAttendanceGroupMapper.deleteSurProjectAttendanceGroupByIds(ids);
    }

    /**
     * 删除广联达班组信息信息
     * 
     * @param id 广联达班组信息主键
     * @return 结果
     */
    @Override
    public int deleteSurProjectAttendanceGroupById(Long id)
    {
        return surProjectAttendanceGroupMapper.deleteSurProjectAttendanceGroupById(id);
    }

    /**
     * 批量删除广联达班组信息
     *
     * @param list 需要删除的数据参数集合
     * @return 结果
     */
    @Override
    public int deleteSurProjectAttendanceGroupByParams(List<String> list) {
        return surProjectAttendanceGroupMapper.deleteSurProjectAttendanceGroupByParams(list);
    }

    /**
     * 批量新增广联达班组信息
     *
     * @param surProjectAttendanceGroupList 广联达班组信息列表
     * @return 结果
     */
    @Override
    public int batchSurProjectAttendanceGroup(List<SurProjectAttendanceGroup> surProjectAttendanceGroupList) {
        return surProjectAttendanceGroupMapper.batchSurProjectAttendanceGroup(surProjectAttendanceGroupList);
    }

    @Override
    public void add(SurProjectAttendanceGroup group) {
        SurProjectAttendanceGroup where=new SurProjectAttendanceGroup();
        where.setServerid(group.getServerid());
        List<SurProjectAttendanceGroup> list=selectSurProjectAttendanceGroupViewList(where);
        if(list.size()==0){
            insertSurProjectAttendanceGroup(group);
        }else{
            group.setId(list.get(0).getId());
            updateSurProjectAttendanceGroup(group);
        }
    }

    /**
     * 更新济工网的分组类型
     * @param group
     */
    @Override
    public void updateJgw(SurProjectAttendanceGroup group) {
        SurProjectAttendanceGroup where=new SurProjectAttendanceGroup();
        where.setBizLicense(group.getBizLicense());
        List<SurProjectAttendanceGroup> list=selectSurProjectAttendanceGroupList(where);
        for(SurProjectAttendanceGroup g:list){
            g.setCompanyTypeId(group.getCompanyTypeId());
            updateSurProjectAttendanceGroup(g);
        }
    }
}
