| | |
| | | throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "保存数据失败"); |
| | | } |
| | | |
| | | ResponseEntity<String> responseEntity = new ResponseEntity<String>("", HttpStatus.OK); |
| | | JSONObject outParam = new JSONObject(); |
| | | outParam.put("fileId", fileDto.getFileId()); |
| | | |
| | | ResponseEntity<String> responseEntity = new ResponseEntity<String>(outParam.toJSONString(), HttpStatus.OK); |
| | | |
| | | context.setResponseEntity(responseEntity); |
| | | } |
| New file |
| | |
| | | package com.java110.web.components.file; |
| | | |
| | | |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.web.smo.app.IListAppsSMO; |
| | | import com.java110.web.smo.file.IGetFileSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | |
| | | /** |
| | | * 应用组件管理类 |
| | | * <p> |
| | | * add by wuxw |
| | | * <p> |
| | | * 2019-06-29 |
| | | */ |
| | | @Component("getFile") |
| | | public class GetFileComponent { |
| | | |
| | | @Autowired |
| | | private IGetFileSMO getFileSMOImpl; |
| | | |
| | | /** |
| | | * 查询应用列表 |
| | | * |
| | | * @param pd 页面数据封装 |
| | | * @return 返回 ResponseEntity 对象 |
| | | */ |
| | | public ResponseEntity<Object> file(IPageData pd) throws IOException { |
| | | return getFileSMOImpl.getFile(pd); |
| | | } |
| | | |
| | | public IGetFileSMO getGetFileSMOImpl() { |
| | | return getFileSMOImpl; |
| | | } |
| | | |
| | | public void setGetFileSMOImpl(IGetFileSMO getFileSMOImpl) { |
| | | this.getFileSMOImpl = getFileSMOImpl; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.web.components.notice; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.core.context.PageData; |
| | | import com.java110.web.smo.file.IAddFileSMO; |
| | | import com.java110.web.smo.notice.IAddNoticeSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * 添加公告组件 |
| | | */ |
| | | @Component("addNoticeView") |
| | | public class AddNoticeViewComponent { |
| | | |
| | | @Autowired |
| | | private IAddNoticeSMO addNoticeSMOImpl; |
| | | |
| | | @Autowired |
| | | private IAddFileSMO addFileSMOImpl; |
| | | |
| | | /** |
| | | * 添加公告数据 |
| | | * |
| | | * @param pd 页面数据封装 |
| | | * @return ResponseEntity 对象 |
| | | */ |
| | | public ResponseEntity<String> save(IPageData pd) { |
| | | return addNoticeSMOImpl.saveNotice(pd); |
| | | } |
| | | |
| | | /** |
| | | * 上传图片 |
| | | * |
| | | * @param pd 页面数据封装 |
| | | * @return ResponseEntity 对象 |
| | | */ |
| | | public ResponseEntity<String> uploadImage(IPageData pd, MultipartFile uploadFile) throws Exception { |
| | | JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); |
| | | paramIn.put("suffix", "jpeg"); |
| | | IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getToken(), paramIn.toJSONString(), pd.getComponentCode(), pd.getComponentMethod(), "", pd.getSessionId()); |
| | | return addFileSMOImpl.saveFile(newPd, uploadFile); |
| | | } |
| | | |
| | | public IAddNoticeSMO getAddNoticeSMOImpl() { |
| | | return addNoticeSMOImpl; |
| | | } |
| | | |
| | | public void setAddNoticeSMOImpl(IAddNoticeSMO addNoticeSMOImpl) { |
| | | this.addNoticeSMOImpl = addNoticeSMOImpl; |
| | | } |
| | | |
| | | public IAddFileSMO getAddFileSMOImpl() { |
| | | return addFileSMOImpl; |
| | | } |
| | | |
| | | public void setAddFileSMOImpl(IAddFileSMO addFileSMOImpl) { |
| | | this.addFileSMOImpl = addFileSMOImpl; |
| | | } |
| | | } |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.util.Map; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 调用组件 文件上传 |
| | | * /callComponent/upload/assetImport/importData |
| | | * |
| | | * @return |
| | | */ |
| | | |
| | | @RequestMapping(path = "/callComponent/download/{componentCode}/{componentMethod}") |
| | | public ResponseEntity<Object> callComponentDownloadFile( |
| | | @PathVariable String componentCode, |
| | | @PathVariable String componentMethod, |
| | | HttpServletRequest request, |
| | | HttpServletResponse response) { |
| | | ResponseEntity<Object> responseEntity = null; |
| | | Map formParam = null; |
| | | IPageData pd = null; |
| | | try { |
| | | Assert.hasLength(componentCode, "参数错误,未传入组件编码"); |
| | | Assert.hasLength(componentMethod, "参数错误,未传入调用组件方法"); |
| | | |
| | | Object componentInstance = ApplicationContextFactory.getBean(componentCode); |
| | | |
| | | Assert.notNull(componentInstance, "未找到组件对应的处理类,请确认 " + componentCode); |
| | | |
| | | Method cMethod = componentInstance.getClass().getDeclaredMethod(componentMethod, IPageData.class); |
| | | |
| | | Assert.notNull(cMethod, "未找到组件对应处理类的方法,请确认 " + componentCode + "方法:" + componentMethod); |
| | | pd = freshPageDate(request); |
| | | responseEntity = (ResponseEntity<Object>) cMethod.invoke(componentInstance, pd); |
| | | |
| | | } catch (SMOException e) { |
| | | logger.error("组件运行异常",e); |
| | | responseEntity = new ResponseEntity<Object>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } catch (Exception e) { |
| | | logger.error("组件运行异常",e); |
| | | String msg = ""; |
| | | if (e instanceof InvocationTargetException) { |
| | | Throwable targetEx = ((InvocationTargetException) e).getTargetException(); |
| | | if (targetEx != null) { |
| | | msg = targetEx.getMessage(); |
| | | } |
| | | } else { |
| | | msg = e.getMessage(); |
| | | } |
| | | responseEntity = new ResponseEntity<Object>(msg, HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } finally { |
| | | logger.debug("组件调用返回信息为{}", responseEntity); |
| | | return responseEntity; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 刷新 pd 对象 |
| | | * |
| | | * @param request HttpServletRequest 对象 |
| | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.context.IPageData; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * 组件抽象类 |
| | | * |
| | | * <p> |
| | | * add by wuxw 2019-06-19 |
| | | */ |
| | | public abstract class AbstractComponentSMO extends BaseComponentSMO{ |
| | | public abstract class AbstractComponentSMO extends BaseComponentSMO { |
| | | private static Logger logger = LoggerFactory.getLogger(AbstractComponentSMO.class); |
| | | |
| | | |
| | | /** |
| | | * 统一业务处理类 |
| | | * |
| | | * @param pd 页面数据封装 |
| | | * @return ResponseEntity对象 |
| | | */ |
| | | protected final ResponseEntity<String> businessProcess(IPageData pd){ |
| | | protected final ResponseEntity<String> businessProcess(IPageData pd) { |
| | | |
| | | JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); |
| | | |
| | | |
| | | //业务数据校验 |
| | | validate(pd, paramIn); |
| | | |
| | | ResponseEntity<String> businessResult = doBusinessProcess(pd, paramIn); |
| | | ResponseEntity<String> businessResult = null; |
| | | try { |
| | | businessResult = doBusinessProcess(pd, paramIn); |
| | | } catch (Exception e) { |
| | | logger.error("调用实现类异常:", e); |
| | | businessResult = new ResponseEntity<String>(e.getLocalizedMessage(), HttpStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | return businessResult; |
| | | |
| | |
| | | |
| | | /** |
| | | * 页面数据校验 方法 |
| | | * @param pd 页面数据封装 |
| | | * |
| | | * @param pd 页面数据封装 |
| | | * @param paramIn 前台数据对象 |
| | | */ |
| | | protected abstract void validate(IPageData pd, JSONObject paramIn); |
| | | |
| | | /** |
| | | * 业务数据处理类 |
| | | * @param pd 页面数据封装 |
| | | * |
| | | * @param pd 页面数据封装 |
| | | * @param paramIn 前台数据对象 |
| | | */ |
| | | protected abstract ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn); |
| | | protected abstract ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) throws IOException; |
| | | } |
| New file |
| | |
| | | package com.java110.web.smo.file; |
| | | |
| | | import com.java110.core.context.IPageData; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * 添加沃文件接口 |
| | | * |
| | | * add by wuxw 2019-06-30 |
| | | */ |
| | | public interface IAddFileSMO { |
| | | |
| | | /** |
| | | * 添加文件 |
| | | * @param pd 页面数据封装 |
| | | * @return ResponseEntity 对象 |
| | | */ |
| | | ResponseEntity<String> saveFile(IPageData pd, MultipartFile uploadFile) throws IOException; |
| | | } |
| New file |
| | |
| | | package com.java110.web.smo.file; |
| | | |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.utils.exception.SMOException; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * 公告管理服务接口类 |
| | | * |
| | | * add by wuxw 2019-06-29 |
| | | */ |
| | | public interface IGetFileSMO { |
| | | |
| | | /** |
| | | * 查询公告信息 |
| | | * @param pd 页面数据封装 |
| | | * @return ResponseEntity 对象数据 |
| | | * @throws SMOException 业务代码层 |
| | | */ |
| | | ResponseEntity<Object> getFile(IPageData pd) throws SMOException, IOException; |
| | | } |
| New file |
| | |
| | | package com.java110.web.smo.file.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.entity.component.ComponentValidateResult; |
| | | import com.java110.utils.constant.PrivilegeCodeConstant; |
| | | import com.java110.utils.constant.ServiceConstant; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.Base64Convert; |
| | | import com.java110.web.core.BaseComponentSMO; |
| | | import com.java110.web.smo.file.IAddFileSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | |
| | | /** |
| | | * 添加小区服务实现类 |
| | | * add by wuxw 2019-06-30 |
| | | */ |
| | | @Service("addNoticeSMOImpl") |
| | | public class AddFileSMOImpl extends BaseComponentSMO implements IAddFileSMO { |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public ResponseEntity<String> saveFile(IPageData pd, MultipartFile uploadFile) throws IOException { |
| | | |
| | | JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); |
| | | if (uploadFile.getSize() > 2 * 1024 * 1024) { |
| | | throw new IllegalArgumentException("上传文件超过两兆"); |
| | | } |
| | | |
| | | Assert.hasKeyAndValue(paramIn, "communityId", "必填,请填写小区ID"); |
| | | Assert.hasKeyAndValue(paramIn, "suffix", "必填,请填写文件类型"); |
| | | super.checkUserHasPrivilege(pd, restTemplate, PrivilegeCodeConstant.SAVE_FILE); |
| | | |
| | | ComponentValidateResult result = this.validateStoreStaffCommunityRelationship(pd, restTemplate); |
| | | InputStream is = uploadFile.getInputStream(); |
| | | String fileContext = Base64Convert.ioToBase64(is); |
| | | paramIn.put("file", fileContext); |
| | | paramIn.put("fileName", uploadFile.getOriginalFilename()); |
| | | |
| | | |
| | | String apiUrl = ServiceConstant.SERVICE_API_URL + "/api/file.saveFile" ; |
| | | |
| | | |
| | | ResponseEntity<String> responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), |
| | | apiUrl, |
| | | HttpMethod.POST); |
| | | return responseEntity; |
| | | |
| | | } |
| | | |
| | | public RestTemplate getRestTemplate() { |
| | | return restTemplate; |
| | | } |
| | | |
| | | public void setRestTemplate(RestTemplate restTemplate) { |
| | | this.restTemplate = restTemplate; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.web.smo.file.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.entity.component.ComponentValidateResult; |
| | | import com.java110.utils.constant.PrivilegeCodeConstant; |
| | | import com.java110.utils.constant.ServiceConstant; |
| | | import com.java110.utils.exception.SMOException; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.Base64Convert; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import com.java110.web.core.AbstractComponentSMO; |
| | | import com.java110.web.core.BaseComponentSMO; |
| | | import com.java110.web.smo.file.IGetFileSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 查询notice服务类 |
| | | */ |
| | | @Service("getFileSMOImpl") |
| | | public class GetFileSMOImpl extends BaseComponentSMO implements IGetFileSMO { |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Override |
| | | public ResponseEntity<Object> getFile(IPageData pd) throws SMOException,IOException { |
| | | JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); |
| | | |
| | | super.validatePageInfo(pd); |
| | | |
| | | Assert.hasKeyAndValue(paramIn, "communityId", "请求报文中未包含小区ID"); |
| | | Assert.hasKeyAndValue(paramIn, "fileId", "请求报文中未包含文件ID"); |
| | | |
| | | super.checkUserHasPrivilege(pd, restTemplate, PrivilegeCodeConstant.GET_FILE); |
| | | |
| | | ComponentValidateResult result = super.validateStoreStaffCommunityRelationship(pd, restTemplate); |
| | | |
| | | Map paramMap = BeanConvertUtil.beanCovertMap(result); |
| | | paramIn.putAll(paramMap); |
| | | |
| | | String apiUrl = ServiceConstant.SERVICE_API_URL + "/api/file.getFile"; |
| | | |
| | | |
| | | ResponseEntity<String> responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), |
| | | apiUrl, |
| | | HttpMethod.GET); |
| | | |
| | | //处理文件下载功能 |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | return new ResponseEntity<Object>(responseEntity.getBody(),responseEntity.getStatusCode()); |
| | | } |
| | | |
| | | JSONObject outParam = JSONObject.parseObject(responseEntity.getBody()); |
| | | MultiValueMap headers = new HttpHeaders(); |
| | | if ("jpeg".equals(outParam.getString("suffix"))) { |
| | | headers.add("content-type", "image/jpeg"); |
| | | } else { |
| | | headers.add("content-type", "application/octet-stream"); |
| | | } |
| | | headers.add("Content-Disposition", "attachment; filename=" + outParam.getString("fileName")); |
| | | |
| | | byte[] context = Base64Convert.base64ToByte(outParam.getString("context")); |
| | | |
| | | return new ResponseEntity<Object>(context,headers,HttpStatus.OK); |
| | | } |
| | | |
| | | public RestTemplate getRestTemplate() { |
| | | return restTemplate; |
| | | } |
| | | |
| | | public void setRestTemplate(RestTemplate restTemplate) { |
| | | this.restTemplate = restTemplate; |
| | | } |
| | | } |
| | |
| | | vc.component.addNoticeViewInfo.communityId = vc.getCurrentCommunity().communityId; |
| | | |
| | | vc.http.post( |
| | | 'addNotice', |
| | | 'addNoticeView', |
| | | 'save', |
| | | JSON.stringify(vc.component.addNoticeViewInfo), |
| | | { |
| | |
| | | var value = $(".noticeEndTime").val(); |
| | | vc.component.addNoticeViewInfo.endTime = value; |
| | | }); |
| | | $('.summernote').summernote({ |
| | | var $summernote = $('.summernote').summernote({ |
| | | lang:'zh-CN', |
| | | height: 300, |
| | | placeholder:'必填,请输入公告内容', |
| | | callbacks : { |
| | | onImageUpload: function(files, editor, $editable) { |
| | | sendFile(files); |
| | | vc.component.sendFile($summernote,files); |
| | | }, |
| | | onChange:function(contents,$editable){ |
| | | vc.component.addNoticeViewInfo.context = contents; |
| | |
| | | vc.emit('noticeManage','listNotice',{}); |
| | | |
| | | }, |
| | | sendFile:function(files){ |
| | | console.log('上传图片'); |
| | | sendFile:function($summernote,files){ |
| | | console.log('上传图片',files); |
| | | |
| | | var param = new FormData(); |
| | | param.append("uploadFile", files); |
| | | param.append('communityId',vc.getCurrentCommunity().communityId); |
| | | |
| | | vc.http.upload( |
| | | 'addNoticeView', |
| | | 'uploadImage', |
| | | param, |
| | | { |
| | | emulateJSON:true, |
| | | //添加请求头 |
| | | headers: { |
| | | "Content-Type": "multipart/form-data" |
| | | } |
| | | }, |
| | | function(json,res){ |
| | | //vm.menus = vm.refreshMenuActive(JSON.parse(json),0); |
| | | if(res.status == 200){ |
| | | var data = JSON.parse(json); |
| | | //关闭model |
| | | $summernote.summernote('insertImage', data, function ($image) { |
| | | $image.attr('src', "/callComponent/download/getFile/file?fileId="+data.fileId +"&communityId="+vc.getCurrentCommunity().communityId); |
| | | }); |
| | | return ; |
| | | } |
| | | vc.message(json); |
| | | }, |
| | | function(errInfo,error){ |
| | | console.log('请求失败处理'); |
| | | vc.message(errInfo); |
| | | }); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | public static final String AUDIT_ENTER_COMMUNITY = "502019091978690002"; |
| | | |
| | | public static final String GET_FILE = "502019100245350003"; |
| | | |
| | | public static final String SAVE_FILE = "502019100245350003"; |
| | | |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.java110.utils.util; |
| | | |
| | | import sun.misc.BASE64Decoder; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | | import java.io.*; |
| | | |
| | | public class Base64Convert { |
| | | |
| | | private void Base64Convert() { |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 流转换为字符串 |
| | | * |
| | | * @param in |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | public static String ioToBase64(InputStream in) throws IOException { |
| | | String strBase64 = null; |
| | | try { |
| | | // in.available()返回文件的字节长度 |
| | | byte[] bytes = new byte[in.available()]; |
| | | // 将文件中的内容读入到数组中 |
| | | in.read(bytes); |
| | | strBase64 = new BASE64Encoder().encode(bytes); //将字节流数组转换为字符串 |
| | | } finally { |
| | | if (in != null) { |
| | | in.close(); |
| | | } |
| | | } |
| | | |
| | | return strBase64; |
| | | } |
| | | |
| | | /** |
| | | * 将base64 转为字节 |
| | | * @param strBase64 |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | public static byte[] base64ToByte(String strBase64) throws IOException { |
| | | // 解码,然后将字节转换为文件 |
| | | byte[] bytes = new BASE64Decoder().decodeBuffer(strBase64); //将字符串转换为byte数组 |
| | | return bytes; |
| | | } |
| | | } |