package com.gic.haoban.manage.service.service.role.impl;

import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.UniqueIdUtils;
import com.gic.haoban.manage.service.dao.mapper.role.TabHaobanRoleMapper;
import com.gic.haoban.manage.service.entity.role.TabHaobanRole;
import com.gic.haoban.manage.service.pojo.bo.role.HaobanRoleBO;
import com.gic.haoban.manage.service.service.role.HaobanRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 好办小程序权限(TabHaobanRole)表服务实现类
 *
 * @author mozhu
 * @since 2022-09-06 16:35:10
 */
@Service
public class HaobanRoleServiceImpl implements HaobanRoleService {

    @Autowired
    private TabHaobanRoleMapper tabHaobanRoleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param roleId 主键
     * @return 实例对象
     */
    @Override
    public TabHaobanRole queryById(Long roleId) {
        return this.tabHaobanRoleMapper.queryById(roleId);
    }

    @Override
    public int insertBatch(List<TabHaobanRole> tabHaobanRoles) {
        for (TabHaobanRole tabHaobanRole : tabHaobanRoles) {
            tabHaobanRole.setCreateTime(new Date());
            tabHaobanRole.setUpdateTime(new Date());
        }
        return tabHaobanRoleMapper.insertBatch(tabHaobanRoles);
    }

    /**
     * 修改数据
     *
     * @param tabHaobanRole 实例对象
     * @return 实例对象
     */
    @Override
    public TabHaobanRole update(TabHaobanRole tabHaobanRole) {
        tabHaobanRole.setUpdateTime(new Date());
        this.tabHaobanRoleMapper.update(tabHaobanRole);
        return this.queryById(tabHaobanRole.getRoleId());
    }

    @Override
    public boolean deleteByWxEnterpriseId(String wxEnterpriseId, Integer systemFlag) {
        return tabHaobanRoleMapper.deleteByWxEnterpriseId(wxEnterpriseId,systemFlag) > 0;
    }

    @Override
    public HaobanRoleBO getByWxEnterpriseIdAndClerkType(String wxEnterpriseId, Integer clerkType, Integer systemFlag) {
        TabHaobanRole tabHaobanRole = tabHaobanRoleMapper.getByWxEnterpriseIdAndClerkType(wxEnterpriseId, clerkType, systemFlag);
        return EntityUtil.changeEntityNew(HaobanRoleBO.class, tabHaobanRole);
    }

    @Override
    public List<HaobanRoleBO> getListByWxEnterpriseId(String wxEnterpriseId, Integer systemFlag) {
        List<TabHaobanRole> tabHaobanRoles = tabHaobanRoleMapper.getListByWxEnterpriseId(wxEnterpriseId, systemFlag);
        return EntityUtil.changeEntityListNew(HaobanRoleBO.class, tabHaobanRoles);
    }

    @Override
    public int getCountByWxEnterpriseId(String wxEnterpriseId, Integer systemFlag) {
        return tabHaobanRoleMapper.getCountByWxEnterpriseId(wxEnterpriseId, systemFlag);
    }

}
