package com.ydtech.modules.admin.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ydtech.modules.admin.dao.SysUserRoleKztMapper; import com.ydtech.modules.admin.model.SysUser; import com.ydtech.modules.admin.model.SysUserRoleKzt; import com.ydtech.modules.admin.model.dto.KZTUserQueryDto; import com.ydtech.modules.admin.service.SysUserRoleKztService; import com.ydtech.modules.base.controller.BaseController; import com.ydtech.modules.order.entity.BasePageResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * @author Administrator * @description 针对表【sys_user_role_kzt(控制台用户关联角色)】的数据库操作Service实现 * @createDate 2024-08-14 16:13:44 */ @Service public class SysUserRoleKztServiceImpl extends ServiceImpl implements SysUserRoleKztService { @Autowired private SysUserRoleKztMapper sysUserRoleKztMapper; @Autowired private SysUserRoleKztMapper sysRoleMenuKztService; /** * @version * @author: hxl * @Date: 2024/8/14 16:41 * @Description: 通過用戶id和系统类型查询数据 */ @Override public void deleteByUserId(String userId, String sysType) { sysUserRoleKztMapper.deleteByUserId(userId,sysType); } /** * @version * @author: hxl * @Date: 2024/8/14 16:48 * @Description: 保存用戶关联角色 */ @Override public void saveUserRoleKzt(String userId, String roleId, String sysType) { sysUserRoleKztMapper.deleteByUserId(userId,sysType); SysUserRoleKzt userRole = new SysUserRoleKzt(null, userId,Long.parseLong(roleId), sysType, new BaseController().getUserId(), new Date(), new BaseController().getUserId(), new Date()); this.save(userRole); } /** * @version * @author: hxl * @Date: 2024/8/14 17:07 * @Description: 通过机构id查询已授权的用户 */ @Override public BasePageResult queryPageByParam(KZTUserQueryDto kZTUserQueryDto) { Page page = new Page<>(kZTUserQueryDto.getPageNum(), kZTUserQueryDto.getPageSize()); kZTUserQueryDto.setSysType("2"); Page userPageResult = sysUserRoleKztMapper.queryPageByParam(page, kZTUserQueryDto); return new BasePageResult<>(kZTUserQueryDto.getPageNum(), page.getSize(), userPageResult.getTotal(), page.getPages(), userPageResult.getRecords()); } @Override @Transactional public void saveBatchUserRoleKzt(List userIds, String roleId, String number) { ArrayList saveObj = new ArrayList<>(); sysUserRoleKztMapper.deleteBatcgByUserId(userIds,number); for (String userId : userIds) { SysUserRoleKzt userRole = new SysUserRoleKzt(null, userId,Long.parseLong(roleId), number, new BaseController().getUserId(), new Date(), new BaseController().getUserId(), new Date()); saveObj.add(userRole); } this.saveBatch(saveObj); } }