package com.product.text.message.controller; import javax.servlet.http.HttpServletRequest; import com.product.core.permission.PermissionService; import com.product.module.sys.config.SystemErrorCode; 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.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.spring.context.SpringMVCContextHolder; import com.product.module.sys.version.ApiVersion; import com.product.text.message.config.CmnCode; import com.product.text.message.config.CmnConst; import com.product.text.message.config.SystemCode; import com.product.text.message.service.MessageTemplateService; /** * * Copyright LX-BASE * @Title: LX-BASE- * @Project: MessageTemplateController * @Date: 2020-05-27 16:15 * @Author: 杜洪波 * @Description: */ @RequestMapping("/api/text/message") @RestController public class MessageTemplateController extends AbstractBaseController{ @Autowired private MessageTemplateService messageTemplateService; @Autowired PermissionService permissionService; @RequestMapping(value = "/list-template/{version}",method=RequestMethod.POST) @ApiVersion(1) public String listMessageTemplate(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 (!CmnConst.PRODUCT_SYS_MESSAGE_TEMPLATE.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } DataTableEntity dt=messageTemplateService.listMessageTemplate(fse); return OK_List(dt); } catch (BaseException e) { return this.error(e); } catch (Exception e) { e.printStackTrace(); return this.error(CmnCode.MESSAGETEMPLATE_ERROR.getValue(), CmnCode.MESSAGETEMPLATE_ERROR.getText()+e.getMessage()); } } /** * * @param request * @return */ @RequestMapping(value = "/find-template/{version}",method=RequestMethod.POST) @ApiVersion(1) public String findMessageTemplate(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(!permissionService.validDataPermission(fse,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 (!CmnConst.PRODUCT_SYS_MESSAGE_TEMPLATE.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } //判断uuid是否为空 if (StringUtils.isEmpty(fse.getUUID())) { return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } return messageTemplateService.findMessageTemplate(fse.getUUID()); } catch (BaseException e) { return this.error(e); } catch (Exception e) { e.printStackTrace(); return this.error(CmnCode.MESSAGETEMPLATE_ERROR.getValue(), CmnCode.MESSAGETEMPLATE_ERROR.getText()+e.getMessage()); } } /** * 消息模板新增 * @param request * @return */ @RequestMapping(value = "/add-template/{version}",method=RequestMethod.POST) @ApiVersion(1) public String addMessageTemplate(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 (!CmnConst.PRODUCT_SYS_MESSAGE_TEMPLATE.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } boolean succ=messageTemplateService.addMessageTemplate(fse); if (succ) { return OK(); } return error(CmnCode.MESSAGETEMPLATE_ERROR.getValue(), CmnCode.MESSAGETEMPLATE_ERROR.getText()); } catch (BaseException e) { return this.error(e); } catch (Exception e) { e.printStackTrace(); return this.error(CmnCode.MESSAGETEMPLATE_ERROR.getValue(), CmnCode.MESSAGETEMPLATE_ERROR.getText()+e.getMessage()); } } /** * 消息模板修改 * @param request * @return */ @RequestMapping(value = "/update-template/{version}",method=RequestMethod.POST) @ApiVersion(1) public String updateMessageTemplate(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(!permissionService.validDataPermission(fse,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 (!CmnConst.PRODUCT_SYS_MESSAGE_TEMPLATE.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } //判断uuid是否为空 if (StringUtils.isEmpty(fse.getUUID())) { return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } boolean succ=messageTemplateService.updateMessageTemplate(fse); if (succ) { return OK(); } return error(SystemCode.SYSTEM_MESSAGE_TEMPLATE_UPDATE_FAIL.getValue(),SystemCode.SYSTEM_MESSAGE_TEMPLATE_UPDATE_FAIL.getText()); } catch (BaseException e) { return this.error(e); } catch (Exception e) { e.printStackTrace(); return this.error(CmnCode.MESSAGETEMPLATE_ERROR.getValue(), CmnCode.MESSAGETEMPLATE_ERROR.getText()+e.getMessage()); } } /** * 消息模板删除 * @param request * @return */ @RequestMapping(value = "/delete-template/{version}",method=RequestMethod.POST) @ApiVersion(1) public String deleteMessageTemplate(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(!permissionService.validDataPermission(fse,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 (!CmnConst.PRODUCT_SYS_MESSAGE_TEMPLATE.equals(fse.getTableName())) { return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } //判断uuid是否为空 if (StringUtils.isEmpty(fse.getString("uuid"))) { return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } boolean succ=messageTemplateService.deleteMessageTemplate(fse.getUUID()); if (succ) { return OK(); } return error(SystemCode.SYSTEM_MESSAGE_TEMPLATE_DELETE_FAIL.getValue(),SystemCode.SYSTEM_MESSAGE_TEMPLATE_DELETE_FAIL.getText()); } catch(BaseException e) { return this.error(e); } catch (Exception e) { e.printStackTrace(); return this.error(CmnCode.MESSAGETEMPLATE_ERROR.getValue(), CmnCode.MESSAGETEMPLATE_ERROR.getText()+e.getMessage()); } } }