package com.product.admin.controller; import java.util.Date; import javax.servlet.http.HttpServletRequest; import com.product.admin.service.idel.IDictService; import com.product.common.lang.StringUtils; import com.product.util.support.AbstractBaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.product.core.config.CoreConst; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.entity.RequestParameterEntity; import com.product.core.exception.BaseException; import com.product.core.permission.PermissionService; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.module.sys.config.SystemErrorCode; import com.product.module.sys.entity.SystemUser; import com.product.module.sys.version.ApiVersion; import com.product.admin.config.CmnConst; import com.product.admin.config.SystemCode; import com.product.admin.service.DictService; /** * Copyright LX-BASE * * @Title: DictController * @Project: LX-BASE-SERVER * @Date: 2020年5月30日 上午11:55:29 * @Author: 郑盟 * @Description:普通参照配置 */ @RestController @RequestMapping("/api/dictionary") public class DictController extends AbstractBaseController { /** * 数据查询 ,spring 注入 */ @Autowired public DictService dictService; /** * 数据权限验证 */ @Autowired PermissionService permissionService; @RequestMapping(value = "/find-dict/{version}") public String findDict(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } // 数据操作的权限验证,特殊条件------------ // if (!permissionService.validDataPermission(fse, clientDataOperPermission("view"))) { // SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), // SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); // return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), // SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); // } // 数据操作的权限验证------------ if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } FieldSetEntity findDict = dictService.findDict(fse); return OK_List(findDict); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_INFO_FAIL.getValue(), SystemCode.SYSTEM_DICT_INFO_FAIL.getText() + e.getMessage()); } } @RequestMapping(value = "/find-dict-mobile/{version}") public String findDictMobile(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); String code = null; if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); code = reqp.getOther().get(CoreConst.SYSTEM_LANGUAGE_CODE).toString(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } // 数据操作的权限验证,特殊条件------------ if (!permissionService.validDataPermission(fse, clientDataOperPermission("view"))) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } // 手机端调用 // 客户端类型 FieldSetEntity findDict = dictService.findDictForMobile(fse, code); return OK_List(findDict); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_INFO_FAIL.getValue(), SystemCode.SYSTEM_DICT_INFO_FAIL.getText() + e.getMessage()); } } /** * 字典列表查询接口 * * @return */ @RequestMapping(value = "/list-dictionary/{version}", method = RequestMethod.POST) @ApiVersion(1) public String listDict(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } return OK_List(dictService.listDict(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_LIST_FAIL.getValue(), SystemCode.SYSTEM_DICT_LIST_FAIL.getText() + e.getMessage()); } } /** * 字典列表查询接口 * * @return */ @RequestMapping(value = "/list-dictionary-mobile/{version}", method = RequestMethod.POST) public String listDictMobile(HttpServletRequest request) { try { FieldSetEntity fse = null; String code = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); code = reqp.getOther().get(CoreConst.SYSTEM_LANGUAGE_CODE).toString(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } // 手机端调用 DataTableEntity dt = dictService.listDictForMobile(fse.getInteger("cpage"), fse.getInteger("pagesize"), code); // 客户端类型 return OK_List(dt); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_LIST_FAIL.getValue(), SystemCode.SYSTEM_DICT_LIST_FAIL.getText() + e.getMessage()); } } @PostMapping("/update-dict-status/{version}") @ApiVersion(1) public String updateDictStatus(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { return this.error(SystemCode.SYSTEM_FORM_NODATA); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA); } if (StringUtils.isEmpty(fse.getUUID())) { return error(SystemCode.SYSTEM_FORM_COUNT); } return dictService.updateDictIsUsed(fse) ? OK() : error(SystemCode.UPDATE_DICT_STATUS_FAIL); } catch (BaseException e) { return error(e); } catch (Exception e) { return error(SystemCode.UPDATE_DICT_STATUS_FAIL, e); } } @PostMapping("/get-dict-tree/{version}") @ApiVersion(1) public String getDictTree() { try { return OK_List(dictService.getDictTree()); } catch (BaseException e) { return error(e); } catch (Exception e) { return error(SystemCode.GET_DICT_TREE_LIST_FAIL, e); } } /** * 批量查询数据字典根据字典名称 * * @param request * @return */ @PostMapping("/find-dictionary/{version}") @ApiVersion(1) public String findMultipleDict(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } if (StringUtils.isEmpty(fse.getString(CmnConst.DICT_NAME))) { return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } return OK_List(dictService.findMultipleDict(fse)); } catch (BaseException e) { e.printStackTrace(); return this.error(e); } catch (Exception e) { e.printStackTrace(); return error(SystemCode.FIND_BATCH_DICT_FAIL.getValue(), SystemCode.FIND_BATCH_DICT_FAIL.getText() + e.getMessage()); } } /** * 数据字典保存 * * @param request * @return */ @PostMapping("/save-dictionary/{version}") @ApiVersion(1) public String saveMultipleDict(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { return this.error(SystemCode.SYSTEM_FORM_NODATA); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA); } IDictService iDictService = (IDictService) getProxyInstance(dictService); return iDictService.saveDict(fse) ? OK() : error(SystemCode.SAVE_BATCH_DICT_FAIL); } catch (BaseException e) { e.printStackTrace(); return this.error(e); } catch (Exception e) { e.printStackTrace(); return error(SystemCode.SAVE_BATCH_DICT_FAIL.getValue(), SystemCode.SAVE_BATCH_DICT_FAIL.getText() + e.getMessage()); } } /** * 数据字典新增 * * @param request * @return */ @RequestMapping(value = "/add-dictionary/{version}", method = RequestMethod.POST) @ApiVersion(1) public String addDict(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); String manager_type = null; if (currentUser != null && currentUser.getCurrentManager() != null) { manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE); } else { return error(SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getValue(), SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getText()); } String uuid = dictService.addDict(fse, "1".equals(manager_type) || "4".equals(manager_type) ? "" : SpringMVCContextHolder.getCurrentUser().getClientUuid()); if (uuid == null) { return error(SystemCode.SYSTEM_DICT_ADD_FAIL.getValue(), SystemCode.SYSTEM_DICT_ADD_FAIL.getText()); } return OK_Add(uuid); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_ADD_FAIL.getValue(), SystemCode.SYSTEM_DICT_ADD_FAIL.getText() + e.getMessage()); } } /** * 数据字典新增 * * @param request * @return */ @RequestMapping(value = "/add-dictionary-mobile/{version}", method = RequestMethod.POST) @ApiVersion(1) public String addDictMobile(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); String code = null; if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); code = reqp.getOther().get(CoreConst.SYSTEM_LANGUAGE_CODE).toString(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); String manager_type = null; if (currentUser != null && currentUser.getCurrentManager() != null) { manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE); } else { return error(SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getValue(), SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getText()); } // 手机端调用 String uuid = dictService.addDict(fse, "1".equals(manager_type) || "4".equals(manager_type) ? "" : SpringMVCContextHolder.getCurrentUser().getClientUuid(), code); if (uuid == null) { return error(SystemCode.SYSTEM_DICT_ADD_FAIL.getValue(), SystemCode.SYSTEM_DICT_ADD_FAIL.getText()); } return OK_Add(uuid); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_ADD_FAIL.getValue(), SystemCode.SYSTEM_DICT_ADD_FAIL.getText() + e.getMessage()); } } /** * 数据字典更新 * * @param request * @return */ @RequestMapping(value = "/update-dictionary/{version}", method = RequestMethod.POST) public String updateDict(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } // 数据操作的权限验证,特殊条件------------ if (!permissionService.validDataPermission(fse, clientDataOperPermission("update"))) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); String manager_type = null; if (currentUser != null && currentUser.getCurrentManager() != null) { manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE); } else { return error(SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getValue(), SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getText()); } return updateDictReturn(fse, manager_type); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_DICT_UPDATE_FAIL.getText() + e.getMessage()); } } /** * 数据字典更新return值封装 * * @param fse * @param manager_type * @return */ public String updateDictReturn(FieldSetEntity fse, String manager_type) { if (manager_type == null || manager_type.equals("")) { return error(SystemCode.SYSTEM_DICT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_DICT_UPDATE_FAIL.getText()); } if (manager_type.equals("1") || manager_type.equals("4")) { if (!dictService.dictRepeat(fse, "")) { return error(SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getValue(), SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getText()); } fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date()); return dictService.update(fse) ? OK() : error(SystemCode.SYSTEM_DICT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_DICT_UPDATE_FAIL.getText()); } else { fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); return dictService.updateDict(fse) ? OK() : error(SystemCode.SYSTEM_DICT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_DICT_UPDATE_FAIL.getText()); } } /** * 数据字典更新 * * @param request * @return */ @RequestMapping(value = "/update-dictionary-mobile/{version}", method = RequestMethod.POST) public String updateDictMobile(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); String code = null; if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); code = reqp.getOther().get(com.product.core.config.CoreConst.SYSTEM_LANGUAGE_CODE).toString(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } // 数据操作的权限验证,特殊条件------------ if (!permissionService.validDataPermission(fse, clientDataOperPermission("update"))) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); String manager_type = null; if (currentUser != null && currentUser.getCurrentManager() != null) { manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE); } else { return error(SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getValue(), SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getText()); } return updateDictMobileReturn(fse, manager_type, code); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_DICT_UPDATE_FAIL.getText() + e.getMessage()); } } /** * 移动端数据字典更新return值封装 * * @param fse * @param manager_type * @return */ public String updateDictMobileReturn(FieldSetEntity fse, String manager_type, String code) { if (manager_type == null || manager_type.equals("")) { return error(SystemCode.SYSTEM_DICT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_DICT_UPDATE_FAIL.getText()); } if (manager_type.equals("1") || manager_type.equals("4")) { if (!dictService.dictRepeat(fse, "")) { return error(SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getValue(), SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getText()); } fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date()); return dictService.update(fse) ? OK() : error(SystemCode.SYSTEM_DICT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_DICT_UPDATE_FAIL.getText()); } else { fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); return dictService.updateDict(fse, code) ? OK() : error(SystemCode.SYSTEM_DICT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_DICT_UPDATE_FAIL.getText()); } } /** * 根据名称获取数据字典列表 * * @return */ @RequestMapping(value = "/list-dictionary-byname-mobile/{version}", method = RequestMethod.POST) public String listDictBynameMobile(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; reqp.getFormData().setValue(CoreConst.SYSTEM_LANGUAGE_CODE, reqp.getOther().get(CoreConst.SYSTEM_LANGUAGE_CODE)); fse = reqp.getFormData(); } SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); String manager_type = null; if (currentUser != null && currentUser.getCurrentManager() != null) { manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE); } else { manager_type = null; } DataTableEntity dt = dictService.listDictByname(fse, manager_type); return OK_List(dt); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_INFO_NAMEFAIL.getValue(), SystemCode.SYSTEM_DICT_INFO_NAMEFAIL.getText() + e.getMessage()); } } /** * 根据名称获取数据字典列表 * * @return */ @RequestMapping(value = "/list-dictionary-byname/{version}", method = RequestMethod.POST) public String listDictByname(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); Object client_type = null; if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); client_type = reqp.getOther().get(CoreConst.SYSTEM_CLIENT_TYPE_); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } fse.setValue(CoreConst.SYSTEM_CLIENT_TYPE_, client_type); SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); String manager_type = null; if (currentUser != null && currentUser.getCurrentManager() != null) { manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE); } else { manager_type = null; } DataTableEntity dt = dictService.listDictByname(fse, manager_type); return OK_List(dt); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_INFO_NAMEFAIL.getValue(), SystemCode.SYSTEM_DICT_INFO_NAMEFAIL.getText() + e.getMessage()); } } /** * 批量删除数据字典根据字典名称 * * @param request * @return */ @PostMapping("/delete-multiple/{version}") @ApiVersion(1) public String deleteMultpleDict(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { return this.error(SystemCode.SYSTEM_FORM_NODATA); } if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_DICT.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA); } if (StringUtils.isEmpty(fse.getString(CmnConst.DICT_NAME))) { return error(SystemCode.SYSTEM_FORM_COUNT); } dictService.deleteMultipleDict(fse.getString(CmnConst.DICT_NAME)); return OK(); } catch (BaseException e) { return error(e); } catch (Exception e) { return error(SystemCode.MULTIPLE_DELETE_DICT_FAIL, e); } } /** * 根据UUID删除数据字典 * * @return */ @RequestMapping(value = "/delete-dictionary/{version}", method = RequestMethod.POST) public String deleteDict(HttpServletRequest request) { try { Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity reqp = (RequestParameterEntity) bean; FieldSetEntity fse = reqp.getFormData(); SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); String manager_type = null; String uuid = fse.getString("uuid"); if ("".equals(uuid) || null == uuid) { return this.error(SystemCode.SYSTEM_DICT_DELETE_FAIL.getValue(), SystemCode.SYSTEM_DICT_DELETE_FAIL.getText()); } if (null != currentUser && currentUser.getCurrentManager() != null) { manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE); } else { return this.error(SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getValue(), SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getText()); } // 数据操作的权限验证,特殊条件------------ // 数据操作的权限验证 if (!permissionService.validDataPermission(fse, clientDataOperPermission("del"))) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } if ("1".equals(manager_type) || manager_type.equals("4")) { return dictService.delete("product_sys_dict", "uuid=? and (client_uuid is null or client_uuid='')", new String[]{fse.getString("uuid")}) ? OK() : error(SystemCode.SYSTEM_DICT_DELETE_FAIL.getValue(), SystemCode.SYSTEM_DICT_DELETE_FAIL.getText()); } else { String org_level_uuid = SpringMVCContextHolder.getCurrentUser().getClient_uuid(); return dictService.delete("product_sys_dict", "uuid=? and client_uuid = ? ", new String[]{fse.getString("uuid"), org_level_uuid}) ? OK() : error(SystemCode.SYSTEM_DICT_DELETE_FAIL.getValue(), SystemCode.SYSTEM_DICT_DELETE_FAIL.getText()); } } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DICT_DELETE_FAIL.getValue(), SystemCode.SYSTEM_DICT_DELETE_FAIL.getText() + e.getMessage()); } } /** * 数据字典验证 * * @param * @return */ private String clientDataOperPermission(String type) { SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); // 判断是否为管理员 用管理员所管理的客户uuid进行特殊过滤 if (currentUser != null && currentUser.isManager()) { if ("del".equals(type)) { if (currentUser.getUserType() == 3) { // 隐藏管理类型 return "client_uuid in ('" + currentUser.getClientUuid().replace(",", "','") + "')"; } else if (currentUser.getUserType() == 1) { // 超级管理员删自己 return " (client_uuid is null or client_uuid='')"; } } if ("view".equals(type)) { if (currentUser.getUserType() == 3) { // 隐藏管理类型 return "(client_uuid in ('" + currentUser.getClientUuid().replace(",", "','") + "') or (client_uuid is null or client_uuid=''))"; } else if (currentUser.getUserType() == 1) { // 超级管理员 return " (client_uuid is null or client_uuid='')"; } } if ("update".equals(type)) { if (currentUser.getUserType() == 3) { // 隐藏管理类型 return "(client_uuid in ('" + currentUser.getClientUuid().replace(",", "','") + "') or (client_uuid is null or client_uuid=''))"; } else if (currentUser.getUserType() == 1) { // 超级管理员 return " (client_uuid is null or client_uuid='')"; } } } else { throw new BaseException(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText(), this.getClass(), "private String systemVersionOperPermission"); } throw new BaseException(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText(), this.getClass(), "private String systemVersionOperPermission"); } }