package com.product.org.admin.controller; import javax.servlet.http.HttpServletRequest; import com.product.core.entity.DataTableEntity; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.org.admin.config.CmnCode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.alibaba.druid.util.StringUtils; import com.product.core.config.CoreConst; import com.product.core.controller.support.AbstractBaseController; 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.module.sys.config.SystemErrorCode; import com.product.module.sys.version.ApiVersion; import com.product.org.admin.config.CmnConst; import com.product.org.admin.config.SystemCode; import com.product.org.admin.service.SystemPostsService; /** * * * Copyright © 2020 LX-BASE * * @Title: LX-BASE-SERVER * @Project: base-server-org-admin * @Date: 2020年6月10日 * @Author: Mr.Xu * @Description:岗位管理Controller */ @RequestMapping(value = "/api/post") @RestController public class SystemPostsController extends AbstractBaseController { @Autowired private SystemPostsService systempostsService; @Autowired PermissionService permissionService; /** * 岗位列表查询 * @param request * @return */ @RequestMapping(value = "/list-post/{version}", method = RequestMethod.POST) @ApiVersion(1) public String listPosts(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_JOB_POSTS.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()); } // 判断分页参数是否正常 if (StringUtils.isEmpty(fse.getString(CmnConst.PAGESIZE)) || StringUtils.isEmpty(fse.getString(CmnConst.CPAGE))) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } return OK_List(systempostsService.listPosts(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch(Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_POSTS_LIST_FAIL.getValue(),SystemCode.SYSTEM_POSTS_LIST_FAIL.getText()); } } /** * 查询岗位详情 * @param request * @return */ @RequestMapping(value = "/find-post/{version}", method = RequestMethod.POST) @ApiVersion(1) public String findPost(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_JOB_POSTS.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()); } // 判断参数是否正常 if (StringUtils.isEmpty(fse.getString(CmnConst.UUID))) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } //数据操作的权限验证 if(!permissionService.validDataPermission(fse,CoreConst.DATA_PERMISSION_VALID_TYPE_ORG)) { 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()); } return OK_List(systempostsService.findPost(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch(Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_POSTS_INFO_FAIL.getValue(),SystemCode.SYSTEM_POSTS_INFO_FAIL.getText()); } } /** * 新增岗位详情 * @param request * @return */ @RequestMapping(value = "/add-post/{version}", method = RequestMethod.POST) @ApiVersion(1) public String addPost(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_JOB_POSTS.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_Add(systempostsService.addPost(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch(Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_POSTS_ADD_FAIL.getValue(),SystemCode.SYSTEM_POSTS_ADD_FAIL.getText()); } } /** * 修改岗位详情 * @param request * @return */ @RequestMapping(value = "/update-post/{version}", method = RequestMethod.POST) @ApiVersion(1) public String updatePost(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_JOB_POSTS.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()); } // 判断参数是否正常 if (StringUtils.isEmpty(fse.getString(CmnConst.UUID))) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } //数据操作的权限验证 if(!permissionService.validDataPermission(fse,CoreConst.DATA_PERMISSION_VALID_TYPE_ORG)) { 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(systempostsService.updatePost(fse)){ return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_POSTS_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_POSTS_UPDATE_FAIL.getText()); return error(SystemCode.SYSTEM_POSTS_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_POSTS_UPDATE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch(Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_POSTS_UPDATE_FAIL.getValue(),SystemCode.SYSTEM_POSTS_UPDATE_FAIL.getText()); } } /** * 删除岗位详情 * @param request * @return */ @RequestMapping(value = "/delete-post/{version}", method = RequestMethod.POST) @ApiVersion(1) public String deletePost(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_JOB_POSTS.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()); } // 判断参数是否正常 if (StringUtils.isEmpty(fse.getString(CmnConst.UUID))) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } //数据操作的权限验证 if(!permissionService.validDataPermission(fse,CoreConst.DATA_PERMISSION_VALID_TYPE_ORG)) { 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(systempostsService.deletePost(fse)){ return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_POSTS_DELETE_FAIL.getValue(), SystemCode.SYSTEM_POSTS_DELETE_FAIL.getText()); return error(SystemCode.SYSTEM_POSTS_DELETE_FAIL.getValue(), SystemCode.SYSTEM_POSTS_DELETE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch(Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_POSTS_DELETE_FAIL.getValue(),SystemCode.SYSTEM_POSTS_DELETE_FAIL.getText()); } } /** * 数据迁移 * @param request * @return */ @RequestMapping(value = "/move-post/{version}", method = RequestMethod.POST) @ApiVersion(1) public Boolean movePost(HttpServletRequest request) { try { return systempostsService.movePost(); } catch (BaseException e) { e.printStackTrace(); return false; } } /** * 获取通用岗位 * * @param request * @return */ @RequestMapping(value = "/list-GeneraPostName/{version}", method = RequestMethod.POST) @ApiVersion(1) public String getGeneralPostName(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (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()); } DataTableEntity dataTableEntity = systempostsService.getGeneralPostName(fse); return OK_List(dataTableEntity); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_POSTS_LIST_FAIL.getValue(),SystemCode.SYSTEM_POSTS_LIST_FAIL.getText()); } } /** * 获取通用岗位 * * @param request * @return */ @RequestMapping(value = "/add-GeneraPostName/{version}", method = RequestMethod.POST) @ApiVersion(1) public String addGeneralPostName(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (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(systempostsService.addGeneralPostName(fse)){ return OK(); } return this.error(SystemCode.SYSTEM_POSTS_ADD_FAIL.getValue(),SystemCode.SYSTEM_POSTS_ADD_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_POSTS_ADD_FAIL.getValue(),SystemCode.SYSTEM_POSTS_ADD_FAIL.getText()); } } }