package com.moral.api.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.entity.ManageAccountRole; import com.moral.api.entity.ManageMenu; import com.moral.api.entity.ManageRole; import com.moral.api.mapper.ManageAccountRoleMapper; import com.moral.api.mapper.ManageRoleMapper; import com.moral.api.mapper.ManageRoleMenuMapper; import com.moral.api.service.ManageRoleService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.constant.Constants; import com.moral.constant.ResponseCodeEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** *

* 后台角色表 服务实现类 *

* * @author moral * @since 2021-03-09 */ @Service public class ManageRoleServiceImpl extends ServiceImpl implements ManageRoleService { @Resource ManageRoleMapper roleMapper; public ManageRole getManageRoleByAccountId(String accountId){ if(StringUtils.isEmpty(accountId)) return null; return null; } @Autowired(required = false) private ManageRoleMapper manageRoleMapper; @Autowired(required = false) private ManageRoleMenuMapper manageRoleMenuMapper; @Autowired(required = false) private ManageAccountRoleMapper manageAccountRoleMapper; @Override @Transactional public List getAllWithPagingQuery(Map map) { com.baomidou.mybatisplus.extension.plugins.pagination.Page page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(Integer.parseInt(map.get("current").toString()), Integer.parseInt(map.get("size").toString())); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("is_delete",0); com.baomidou.mybatisplus.extension.plugins.pagination.Page resultpage = manageRoleMapper.selectPage(page,wrapper); List manageRoles = resultpage.getRecords(); return manageRoles; } @Override @Transactional public Map insertOne(ManageRole manageRole,List list) { Map resultMap = new HashMap<>(); if (manageRole.getName()==null){ resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); return resultMap; } if (manageRoleMapper.getManageRoleByName(manageRole.getName()) != null){ resultMap.put("code",ResponseCodeEnum.ROLE_IS_EXPIRE.getCode()); resultMap.put("msg",ResponseCodeEnum.ROLE_IS_EXPIRE.getMsg()); }else { manageRoleMapper.insertOne(manageRole); resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); } Integer code = Integer.parseInt(resultMap.get("code").toString()); if (code.equals(ResponseCodeEnum.SUCCESS.getCode())){ ManageRole manageRoleIns = manageRoleMapper.getManageRoleByName(manageRole.getName()); int role_id = manageRoleIns.getId(); System.out.println(role_id); List insertList = new ArrayList(); for (Object temp: list) { Map insertMap = new HashMap<>(); insertMap.put("role_id",role_id); insertMap.put("menu_id",Integer.parseInt(temp.toString())); insertList.add(insertMap); } System.out.println(insertList); manageRoleMenuMapper.insertBatch(insertList); } return resultMap; } @Override @Transactional public Map updateManageRole(Map map) { Map resultMap = new HashMap<>(); if (!map.containsKey("id")){ resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); return resultMap; } if (manageRoleMapper.getManageRoleById(Integer.parseInt(map.get("id").toString())) == null){ resultMap.put("code",ResponseCodeEnum.ROLE_IS_NULL.getCode()); resultMap.put("msg",ResponseCodeEnum.ROLE_IS_NULL.getMsg()); }else { manageRoleMapper.updateManageRoleById(map); resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); } return resultMap; } @Override @Transactional public List getManageRoleByNameFuzzy(Map map) { com.baomidou.mybatisplus.extension.plugins.pagination.Page page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(Integer.parseInt(map.get("current").toString()), Integer.parseInt(map.get("size").toString())); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("is_delete",0); wrapper.like("name",map.get("name")); com.baomidou.mybatisplus.extension.plugins.pagination.Page resultpage = manageRoleMapper.selectPage(page,wrapper); List manageRoles = resultpage.getRecords(); return manageRoles; } @Override public Map deleteManageRole(Map map) { Map resultMap = new HashMap<>(); if (!map.containsKey("id")){ resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); return resultMap; } if (manageRoleMapper.getManageRoleById(Integer.parseInt(map.get("id").toString())) == null){ resultMap.put("code",ResponseCodeEnum.ROLE_IS_NULL.getCode()); resultMap.put("msg",ResponseCodeEnum.ROLE_IS_NULL.getMsg()); }else { ManageRole manageRole = new ManageRole(); manageRole.setId(Integer.parseInt(map.get("id").toString())); manageRole.setIsDelete(Constants.DELETE); Map deleteMap = new HashMap(); deleteMap.put("id",Integer.parseInt(map.get("id").toString())); deleteMap.put("is_delete",1); manageRoleMapper.updateManageRoleById(deleteMap); ManageAccountRole manageAccountRole = new ManageAccountRole(); manageAccountRole.setIsDelete("1"); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("role_id",Integer.parseInt(map.get("id").toString())); manageAccountRoleMapper.update(manageAccountRole,wrapper); resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); } return resultMap; } }