package com.doumee.service.system.impl; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Utils; import com.doumee.dao.system.SystemUserRoleMapper; import com.doumee.dao.system.model.SystemUserRole; import com.doumee.service.system.SystemUserRoleService; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.List; /** * 用户角色关联Service实现 * @author Eva.Caesar Liu * @since 2025/03/31 16:44 */ @Service public class SystemUserRoleServiceImpl implements SystemUserRoleService { @Autowired private SystemUserRoleMapper systemUserRoleMapper; @Override public Integer create(SystemUserRole systemUserRole) { systemUserRoleMapper.insert(systemUserRole); return systemUserRole.getId(); } @Override public void deleteById(Integer id) { SystemUserRole systemUserRole = new SystemUserRole(); systemUserRole.setId(id); systemUserRole.setDeleted(Boolean.TRUE); this.updateById(systemUserRole); } @Override public void delete(SystemUserRole systemUserRole) { SystemUserRole newUserRole = new SystemUserRole(); newUserRole.setDeleted(Boolean.TRUE); UpdateWrapper updateWrapper = new UpdateWrapper<>(systemUserRole); systemUserRoleMapper.update(newUserRole, updateWrapper); } @Override @Transactional public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) return; for (Integer id : ids) { this.deleteById(id); } } @Override public void updateById(SystemUserRole systemUserRole) { systemUserRoleMapper.updateById(systemUserRole); } @Override @Transactional public void updateByIdInBatch(List systemUserRoles) { if (CollectionUtils.isEmpty(systemUserRoles)) return; for (SystemUserRole systemUserRole: systemUserRoles) { this.updateById(systemUserRole); } } @Override public SystemUserRole findById(Integer id) { return systemUserRoleMapper.selectById(id); } @Override public SystemUserRole findOne(SystemUserRole systemUserRole) { Wrapper wrapper = new QueryWrapper<>(systemUserRole); return systemUserRoleMapper.selectOne(wrapper); } @Override public List findList(SystemUserRole systemUserRole) { Wrapper wrapper = new QueryWrapper<>(systemUserRole); return systemUserRoleMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); QueryWrapper queryWrapper = new QueryWrapper<>(Utils.MP.blankToNull(pageWrap.getModel())); for(PageWrap.SortData sortData: pageWrap.getSorts()) { if (sortData.getDirection().equalsIgnoreCase("DESC")) { queryWrapper.orderByDesc(sortData.getProperty()); } else { queryWrapper.orderByAsc(sortData.getProperty()); } } return PageData.from(systemUserRoleMapper.selectPage(page, queryWrapper)); } @Override public long count(SystemUserRole systemUserRole) { Wrapper wrapper = new QueryWrapper<>(systemUserRole); return systemUserRoleMapper.selectCount(wrapper); } }