package com.product.admin.controller; import javax.servlet.http.HttpServletRequest; 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 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.admin.config.CmnConst; import com.product.admin.config.SystemCode; import com.product.admin.service.SystemVersionService; 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.module.sys.version.ApiVersion; /** * Copyright © 2020 LX-BASE * @Title: LX-BASE-SERVER * @Project: lx-server-admin * @Date: 2020年11月17日 * @Author: Mr.Xu * @Description:系统版本Controller */ @RequestMapping(value = "/api/version") @RestController public class SystemVersionController extends AbstractBaseController { /** * 数据权限验证 */ @Autowired PermissionService permissionService; @Autowired private SystemVersionService systemVersionService; /** * 版本列表 * * @param request * @return */ @RequestMapping(value = "/list-sys-version/{version}", method = RequestMethod.POST) @ApiVersion(1) public String listSysVersion(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_VERSION.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(systemVersionService.listVersion(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_GET_VERSION_LIST_FAIL.getValue(), SystemCode.SYSTEM_GET_VERSION_LIST_FAIL.getText()); } } /** * 版本详情 * * @param request * @return */ @RequestMapping(value = "/find-sys-version/{version}", method = RequestMethod.POST) @ApiVersion(1) public String findSysVersion(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()); } systemVersionOperPermission(); // 判断表名是否正常 if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_VERSION.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()); } return OK_List(systemVersionService.findVersion(fse.getString(CmnConst.UUID))); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_GET_VERSION_INFO_FAIL.getValue(), SystemCode.SYSTEM_GET_VERSION_INFO_FAIL.getText()); } } /** * 新增版本详情 * * @param request * @return */ @RequestMapping(value = "/add-sys-version/{version}", method = RequestMethod.POST) @ApiVersion(1) public String addSysVersion(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()); } systemVersionOperPermission(); // 判断表名是否正常 if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_VERSION.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 (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_VERSION.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()); } String addVersion = systemVersionService.addVersion(fse); return !StringUtils.isEmpty(addVersion)?OK_Add(addVersion):error(SystemCode.SYSTEM_ADD_VERSION_FAIL.getValue(), SystemCode.SYSTEM_ADD_VERSION_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_ADD_VERSION_FAIL.getValue(), SystemCode.SYSTEM_ADD_VERSION_FAIL.getText()); } } /** * 修改版本详情 * * @param request * @return */ @RequestMapping(value = "/update-sys-version/{version}", method = RequestMethod.POST) @ApiVersion(1) public String updateSysVersion(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()); } systemVersionOperPermission(); // 判断表名是否正常 if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_VERSION.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()); } // 判断uuid是否正常 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()); } return systemVersionService.updateVersion(fse)?OK():error(SystemCode.SYSTEM_UPDATE_VERSION_FAIL.getValue(), SystemCode.SYSTEM_UPDATE_VERSION_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_UPDATE_VERSION_FAIL.getValue(), SystemCode.SYSTEM_UPDATE_VERSION_FAIL.getText()); } } /** * 系统版本操作权限 * @return */ private void systemVersionOperPermission() throws BaseException { SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); //判断是否为管理员 if (currentUser != null && currentUser.isManager()) { if (currentUser.getUserType() == 1) { // 超级管理员不做任何限制 return; } } 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"); } /** * 删除版本 * * @param request * @return */ @RequestMapping(value = "/delete-sys-version/{version}", method = RequestMethod.POST) @ApiVersion(1) public String deleteSysVersion(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()); } systemVersionOperPermission(); // 判断表名是否正常 if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_VERSION.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()); } // 判断uuid是否正常 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()); } return systemVersionService.deleteVersion(fse)?OK():error(SystemCode.SYSTEM_DELETE_VERSION_FAIL.getValue(), SystemCode.SYSTEM_DELETE_VERSION_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return this.error(SystemCode.SYSTEM_DELETE_VERSION_FAIL.getValue(), SystemCode.SYSTEM_DELETE_VERSION_FAIL.getText()); } } }