package com.product.admin.controller; import com.product.admin.config.CmnConst; import com.product.admin.config.SystemCode; import com.product.admin.service.CodeService; import com.product.admin.service.FunctionsService; import com.product.admin.service.idel.IFunctionService; import com.product.admin.util.ResultInfo; import com.product.common.lang.StringUtils; import com.product.core.config.CoreConst; import com.product.core.controller.support.AbstractBaseController; 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.version.ApiVersion; import com.product.util.BaseUtil; import com.product.util.SavePage; 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 javax.servlet.http.HttpServletRequest; import javax.swing.*; import java.util.Date; import java.util.Map; /** * Copyright LX-BASE * * @Title: FunctionsController * @Project: LX-BASE-SERVER * @Date: 2020-06-03 11:47 * @Author: ZhouJie * @Description: 功能管理 */ @RequestMapping("/api/functions") @RestController public class FunctionsController extends AbstractBaseController { @Autowired private FunctionsService functionsService; @Autowired CodeService codeService; /** * 数据权限验证 */ @Autowired PermissionService permissionService; /** * 产品模块树 * * @return * @auth cheng */ @PostMapping("/product-module/{version}") @ApiVersion(1) public String getProductModuleTree() { try { return OK_List(functionsService.getProductModuleTree()); } catch (BaseException e) { e.printStackTrace(); return error(e); } catch (Exception e) { e.printStackTrace(); return error(new BaseException(e)); } } /** * 根据模块查询功能 * * @return * @auth cheng */ @PostMapping("/get-function-by-module/{version}") @ApiVersion(1) public String getFunctionByModule(HttpServletRequest request) { try { return OK_List(functionsService.getFunctionByModule(BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_FUNCTIONS))); } catch (BaseException e) { e.printStackTrace(); return error(e); } catch (Exception e) { e.printStackTrace(); return error(new BaseException(e)); } } @RequestMapping(value = "/list-function/{version}") @ApiVersion(1) public String functionList(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_FUNCTIONS.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(functionsService.getFunctionList(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { e.printStackTrace(); return this.error(e.getMessage()); } } /** * @Date: 2020-06-03 16:02 * @Author: ZhouJie * @Description: 查看功能详情 */ @RequestMapping(value = "/find-function/{version}", method = RequestMethod.POST) @ApiVersion(1) public String findFunctionInfo(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_FUNCTIONS.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 fss = functionsService.findFunction(fse); Map subData = fss.getSubData(); subData.remove(""); return OK_List(fss); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_FUNCTION_GET_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_GET_FAIL.getText()); } } /** * @Date: 2020-06-03 11:49 * @Author: ZhouJie * @Description: 新增功能 */ @RequestMapping(value = "/add-functions/{version}", method = RequestMethod.POST) @ApiVersion(1) public String addFunction(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_FUNCTIONS.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 fsmk = functionsService.baseDao.getFieldSetEntity("product_sys_modules", fse.getString("module_uuid"), false); if (fsmk == 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()); } codeService.createCode(fse, CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, fsmk.getString(CmnConst.TRICODE)); fse.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());// 获取登录帐号 fse.setValue("created_utc_datetime", new Date());// 创建时间 String uuid = functionsService.addFunction(fse); if (!StringUtils.isEmpty(uuid)) { return OK_Add(uuid); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FUNCTION_ADD_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_ADD_FAIL.getText()); return error(SystemCode.SYSTEM_FUNCTION_ADD_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_ADD_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_FUNCTION_ADD_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_ADD_FAIL.getText()); } } /** * @Date: 2020-06-03 14:56 * @Author: ZhouJie * @Description: 按钮修改 */ @RequestMapping(value = "/update-button/{version}", method = RequestMethod.POST) @ApiVersion(1) public String updateBottons(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 || !"product_sys_function_buttons".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 uuids = fse.getString("uuid"); //周杰 2020年12月17日 上午11:16 if (StringUtils.isEmpty(uuids)) { 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(CmnConst.PRODUCT_SYS_FUNCTION_BUTTONS, uuids, CoreConst.DATA_PERMISSION_VALID_TYPE_USER)) { 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()); } fse.setValue("updated_by", SpringMVCContextHolder.getCurrentUser().getUser_id());// 获取登录帐号 fse.setValue("updated_utc_datetime", new Date());// 创建时间 boolean success = functionsService.updateButton(fse); if (success) { return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getText()); return error(SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getText()); } } @PostMapping("/save-module/{version}") @ApiVersion(1) public String saveModule(HttpServletRequest request) { try { FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_FUNCTIONS); IFunctionService service = (IFunctionService) getProxyInstance(functionsService); return OK_List(service.saveModule(fse)); } catch (BaseException e) { e.printStackTrace(); return error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_MODULE_UPDATE_FAIL); } } @PostMapping("/delete-module/{version}") @ApiVersion(1) public String deleteModule(HttpServletRequest request) { try { FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_FUNCTIONS); IFunctionService service = (IFunctionService) getProxyInstance(functionsService); service.deleteModule(fse); return OK(); } catch (BaseException e) { e.printStackTrace(); return error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_MODULE_DELETE_FAIL); } } /** * @Date: 2020-06-03 14:56 * @Author: ZhouJie * @Description: 功能修改 */ @RequestMapping(value = "/update-function/{version}", method = RequestMethod.POST) @ApiVersion(1) public String updateFunction(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_FUNCTIONS.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 uuids = fse.getString("uuid"); //周杰 2020年12月17日 上午11:16 if (StringUtils.isEmpty(uuids)) { 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(CmnConst.PRODUCT_SYS_FUNCTIONS, uuids, CoreConst.DATA_PERMISSION_VALID_TYPE_USER)) { 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()); } boolean success = functionsService.updatefunction(fse); if (success) { return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getText()); return error(SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_UPDATE_FAIL.getText()); } } /** * @Date: 2020-06-03 16:04 * @Author: ZhouJie * @Description: 删除功能 */ @RequestMapping(value = "/delete-function/{version}", method = RequestMethod.POST) @ApiVersion(1) public String deleteFunction(HttpServletRequest request) { try { Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); FieldSetEntity fse = null; 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()); } String uuids = fse.getString("uuid"); //周杰 2020年12月17日 上午11:16 if (StringUtils.isEmpty(uuids)) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_PROMPT_DELETE_FAIL.getValue(), SystemCode.SYSTEM_PROMPT_DELETE_FAIL.getText()); return this.error(SystemCode.SYSTEM_PROMPT_DELETE_FAIL.getValue(), SystemCode.SYSTEM_PROMPT_DELETE_FAIL.getText()); } //数据操作的权限验证 if (!permissionService.validDataPermission(CmnConst.PRODUCT_SYS_FUNCTIONS, uuids, CoreConst.DATA_PERMISSION_VALID_TYPE_USER)) { 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_FUNCTIONS.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()); } boolean success = functionsService.deletefunction(fse); if (success) { return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FUNCTION_DELETE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_DELETE_FAIL.getText()); return error(SystemCode.SYSTEM_FUNCTION_DELETE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_DELETE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_FUNCTION_DELETE_FAIL.getValue(), SystemCode.SYSTEM_FUNCTION_DELETE_FAIL.getText()); } } /** * @Date: 2020-06-11 10:06 * @Author: ZhouJie * @Description: 功能版本号 */ @RequestMapping(value = "/find-version/{version}", method = RequestMethod.POST) @ApiVersion(1) public String findVersion(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_FUNCTIONS.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 fss = functionsService.findVersion(fse); return OK_List(fss); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } } /** * @Date: 2020-09-03 10:06 * @Author: ZhouJie * @Description: 加载功能的所有按钮 */ @RequestMapping(value = "/onload-button/{version}", method = RequestMethod.POST) @ApiVersion(1) public String onloadButton(HttpServletRequest request) { try { Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); FieldSetEntity fse = null; String client_type = null; if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); client_type = reqp.getOther().get(CoreConst.SYSTEM_CLIENT_TYPE_).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()); } fse.setValue(CoreConst.SYSTEM_CLIENT_TYPE_, client_type); //updatetime 2021年1月14日20:03:21 判断客户端类型是否获取成功 if (StringUtils.isEmpty(client_type)) { 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 ResultInfo.success(functionsService.onloadButton(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getValue(), SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getText()); } } }