| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.ManageAccount; |
| | | import com.moral.api.entity.ManageAccountRole; |
| | | import com.moral.api.entity.ManageLog; |
| | | import com.moral.api.entity.ManageRole; |
| | | import com.moral.api.mapper.ManageAccountRoleMapper; |
| | | import com.moral.api.mapper.ManageLogMapper; |
| | | import com.moral.api.mapper.ManageRoleMapper; |
| | | import com.moral.api.mapper.ManageRoleMenuMapper; |
| | | import com.moral.api.pojo.dto.login.AccountInfoDTO; |
| | | import com.moral.api.service.ManageRoleService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.util.LogUtils; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | |
| | | |
| | | @Autowired(required = false) |
| | | private ManageAccountRoleMapper manageAccountRoleMapper; |
| | | |
| | | @Autowired |
| | | LogUtils logUtils; |
| | | |
| | | @Override |
| | | public Map<String,Object> getAllWithPagingQuery(Map map) { |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String,Object> insertOne(ManageRole manageRole,List list) { |
| | | public Map<String,Object> insertOne(ManageRole manageRole, List list) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | if (manageRole.getName()==null){ |
| | | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); |
| | |
| | | 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()); |
| | | return resultMap; |
| | | } |
| | | 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(); |
| | | List insertList = new ArrayList(); |
| | | for (Object temp: list) { |
| | | Map<String,Integer> insertMap = new HashMap<>(); |
| | | insertMap.put("role_id",role_id); |
| | | insertMap.put("menu_id",Integer.parseInt(temp.toString())); |
| | | insertList.add(insertMap); |
| | | } |
| | | manageRoleMapper.insertOne(manageRole); |
| | | ManageRole manageRoleIns = manageRoleMapper.getManageRoleByName(manageRole.getName()); |
| | | int role_id = manageRoleIns.getId(); |
| | | List insertList = new ArrayList(); |
| | | for (Object temp: list) { |
| | | Map<String,Integer> insertMap = new HashMap<>(); |
| | | insertMap.put("role_id",role_id); |
| | | insertMap.put("menu_id",Integer.parseInt(temp.toString())); |
| | | insertList.add(insertMap); |
| | | } |
| | | //判断在新建角色时,是否添加菜单 |
| | | if (insertList.size()>0){ |
| | | manageRoleMenuMapper.insertBatch(insertList); |
| | | } |
| | | //操作插入日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | String content = "添加角色:"+manageRole.getName()+";"; |
| | | logUtils.saveOperationForManage(request,content,"1"); |
| | | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return resultMap; |
| | | } |
| | | |
| | |
| | | Map deleteMap = new HashMap(); |
| | | deleteMap.put("id",Integer.parseInt(map.get("id").toString())); |
| | | deleteMap.put("is_delete",1); |
| | | manageRoleMapper.updateManageRoleById(deleteMap); |
| | | //manageRoleMapper.updateManageRoleById(deleteMap); |
| | | ManageAccountRole manageAccountRole = new ManageAccountRole(); |
| | | manageAccountRole.setIsDelete("1"); |
| | | QueryWrapper<ManageAccountRole> wrapper = new QueryWrapper(); |
| | | wrapper.eq("role_id",Integer.parseInt(map.get("id").toString())); |
| | | manageAccountRoleMapper.update(manageAccountRole,wrapper); |
| | | //manageAccountRoleMapper.update(manageAccountRole,wrapper); |
| | | //操作插入日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | ManageRole manageRole1 = manageRoleMapper.selectById(Integer.parseInt(map.get("id").toString())); |
| | | System.out.println(manageRole1); |
| | | String content = "删除角色:"+manageRole.getName()+";"; |
| | | //logUtils.saveOperationForManage(request,content,"1"); |
| | | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); |
| | | } |