| | |
| | | package com.highdatas.mdm.controller; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.highdatas.mdm.entity.MasterAuthor; |
| | | import com.highdatas.mdm.entity.MasterAuthorDetail; |
| | | import com.highdatas.mdm.entity.SysField; |
| | | import com.highdatas.mdm.entity.TUserRole; |
| | | import com.highdatas.mdm.pojo.CodeMsg; |
| | | import com.highdatas.mdm.pojo.MasterAuthorType; |
| | | import com.highdatas.mdm.pojo.Result; |
| | | import com.highdatas.mdm.service.*; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RestController |
| | | @RequestMapping("/masterAuthor/detail") |
| | | public class MasterAuthorDetailController { |
| | | @Autowired |
| | | IMasterAuthorService masterAuthorService; |
| | | @Autowired |
| | | IMasterAuthorDetailService masterAuthorDetailService; |
| | | @Autowired |
| | | ISysFieldService fieldService; |
| | | @Autowired |
| | | IMaintainFieldService maintainFieldService; |
| | | @Autowired |
| | | IMenuMappingService menuMappingService; |
| | | @Autowired |
| | | ITUserRoleService userRoleService; |
| | | |
| | | @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) |
| | | public Result addRole(@PathVariable String id,@RequestParam String field){ |
| | | MasterAuthor masterAuthor = masterAuthorService.selectById(id); |
| | | if (masterAuthor == null) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | boolean delete = masterAuthorDetailService.delete(new EntityWrapper<MasterAuthorDetail>() |
| | | .eq(Constant.PARENT_ID, masterAuthor.getId()).eq(Constant.FIELD, field)); |
| | | if (delete) { |
| | | return Result.success(CodeMsg.DELETE_SUCCESS); |
| | | }else { |
| | | return Result.error(CodeMsg.DELETE_ERROR); |
| | | } |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/getFieldByMaintainFieldId/{id}", method = RequestMethod.GET) |
| | | public Result getFieldByMaintainFieldId(@PathVariable String id, @RequestParam MasterAuthorType type, @RequestParam String characterId, HttpServletRequest request) { |
| | | List<SysField> result; |
| | | |
| | | String menuId = request.getParameter("menuId"); |
| | | String tableName = menuMappingService.getTableNameByMenu(menuId); |
| | | if (Constant.Default.equalsIgnoreCase(id)) { |
| | | if (StringUtils.isEmpty(tableName)) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | result = fieldService.getDefaultTableField(tableName); |
| | | }else if (Constant.All.equalsIgnoreCase(id)) { |
| | | if (StringUtils.isEmpty(tableName)) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | result = fieldService.getTotalTableField(tableName); |
| | | }else { |
| | | result = fieldService.getFieldByMaintainField(id); |
| | | } |
| | | JSONObject resultObj = new JSONObject(); |
| | | MasterAuthor masterAuthor = masterAuthorService.selectOne(new EntityWrapper<MasterAuthor>() |
| | | .eq(Constant.TYPE, type) |
| | | .eq("character_id", characterId).eq("maintain_field_id", id)); |
| | | |
| | | if (masterAuthor == null && type.equals(MasterAuthorType.user)) { |
| | | List<TUserRole> tUserRoles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq(Constant.USERID, characterId)); |
| | | List<String> roleIdList = tUserRoles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList()); |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = masterAuthorService.merageRoleAuthor(roleIdList); |
| | | String key = DbUtils.getFieldRedisKey(tableName, id); |
| | | masterAuthor = tableMasterAuthor.get(key); |
| | | } |
| | | |
| | | if (masterAuthor == null) { |
| | | |
| | | resultObj.fluentPut("unchecked", result); |
| | | return Result.success(resultObj); |
| | | } |
| | | List<MasterAuthorDetail> fields = masterAuthorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId())); |
| | | if (fields != null) { |
| | | List<String> checkedFieldStrList = fields.stream().map(masterAuthorDetail -> masterAuthorDetail.getField()).collect(Collectors.toList()); |
| | | result = result.stream().filter(sysField -> !checkedFieldStrList.contains(sysField.getField())).collect(Collectors.toList()); |
| | | } |
| | | resultObj.fluentPut("unchecked", result); |
| | | resultObj.fluentPut("checked", fields); |
| | | return Result.success(resultObj); |
| | | } |
| | | } |