Commit 5f12e018 by Java-李昕颖

Merge remote-tracking branch 'origin/develop' into develop

parents d35de3f9 59733c3a
...@@ -36,6 +36,7 @@ public class FrontReportBean extends BaseBean{ ...@@ -36,6 +36,7 @@ public class FrontReportBean extends BaseBean{
private Date createDate; //创建时间 private Date createDate; //创建时间
private String updateBy; //更新人\ private String updateBy; //更新人\
private Date updateDate; //更新时间 private Date updateDate; //更新时间
private List<String> ids;
private String code;// 验证码返回的code private String code;// 验证码返回的code
private String captcha;// 验证码 private String captcha;// 验证码
...@@ -273,4 +274,12 @@ public class FrontReportBean extends BaseBean{ ...@@ -273,4 +274,12 @@ public class FrontReportBean extends BaseBean{
public void setUpdateDate(Date updateDate) { public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate; this.updateDate = updateDate;
} }
public List<String> getIds() {
return ids;
}
public void setIds(List<String> ids) {
this.ids = ids;
}
} }
...@@ -10,7 +10,12 @@ import com.ejweb.modules.front.report.bean.FrontReportBean; ...@@ -10,7 +10,12 @@ import com.ejweb.modules.front.report.bean.FrontReportBean;
import com.ejweb.modules.front.report.bean.ReportAttachmentBean; import com.ejweb.modules.front.report.bean.ReportAttachmentBean;
import com.ejweb.modules.front.report.dao.FrontReportDao; import com.ejweb.modules.front.report.dao.FrontReportDao;
import com.ejweb.modules.front.report.entity.FrontReportEntity; import com.ejweb.modules.front.report.entity.FrontReportEntity;
import com.ejweb.modules.front.upload.util.ReportAttachmentUtils;
import com.ejweb.modules.reportAttachment.dao.ReportAttachmentMapper;
import com.ejweb.modules.reportAttachment.entity.ReportAttachment;
import com.ejweb.modules.sys.entity.User; import com.ejweb.modules.sys.entity.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -35,7 +40,7 @@ public class FrontReportService extends CrudService<FrontReportDao,FrontReportEn ...@@ -35,7 +40,7 @@ public class FrontReportService extends CrudService<FrontReportDao,FrontReportEn
bean.setReportTime(DateUtils.formatDate(date,"yyyy-MM-dd HH:mm:ss")); bean.setReportTime(DateUtils.formatDate(date,"yyyy-MM-dd HH:mm:ss"));
// 现在写的是微信公众号,可能不是这个 // 现在写的是微信公众号,可能不是这个
bean.setReportSource("wechat"); // bean.setReportSource("wechat");
bean.setReportStatus("0"); bean.setReportStatus("0");
// 查询管理员 // 查询管理员
...@@ -52,12 +57,10 @@ public class FrontReportService extends CrudService<FrontReportDao,FrontReportEn ...@@ -52,12 +57,10 @@ public class FrontReportService extends CrudService<FrontReportDao,FrontReportEn
// 添加举报信息表 // 添加举报信息表
int row = dao.insertReport(bean); int row = dao.insertReport(bean);
if(row == 1){ // 添加成功 if(row == 1){ // 添加成功
List<ReportAttachmentBean> list = bean.getReportAttachmentList(); List<String> attachmentIds = bean.getIds();
if(list != null && list.size()>0){ // 添加举报附件 if(attachmentIds != null && attachmentIds.size() > 0){ // 添加举报附件
for(ReportAttachmentBean reportAttachmentBean:list){ for(String attachmentId:attachmentIds){
reportAttachmentBean.setReportId(bean.getId()); ReportAttachmentUtils.addReportId(attachmentId,bean.getId());
reportAttachmentBean.setId(IdWorker.getNextId("RA"));
dao.insertReportAttachment(reportAttachmentBean);
} }
} }
......
...@@ -3,6 +3,9 @@ package com.ejweb.modules.front.upload.api; ...@@ -3,6 +3,9 @@ package com.ejweb.modules.front.upload.api;
import com.ejweb.conf.ErrorCode; import com.ejweb.conf.ErrorCode;
import com.ejweb.conf.GConstants; import com.ejweb.conf.GConstants;
import com.ejweb.core.api.ResponseBean; import com.ejweb.core.api.ResponseBean;
import com.ejweb.core.utils.IdGen;
import com.ejweb.modules.front.upload.util.ReportAttachmentUtils;
import com.ejweb.modules.report.entity.ReportAttachmentEntity;
import com.ejweb.modules.sys.service.LogService; import com.ejweb.modules.sys.service.LogService;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileItemFactory;
...@@ -34,6 +37,7 @@ import java.util.List; ...@@ -34,6 +37,7 @@ import java.util.List;
public class FileController { public class FileController {
private class UploadResultBean { private class UploadResultBean {
public String id;
public String uri; public String uri;
public int size; public int size;
public String extention; public String extention;
...@@ -51,7 +55,7 @@ public class FileController { ...@@ -51,7 +55,7 @@ public class FileController {
private String downloadFileParamName = "file"; private String downloadFileParamName = "file";
private String downloadImageMethodName = "downloadImage"; private String downloadImageMethodName = "downloadImage";
private String downloadImageParamName = "file"; private String downloadImageParamName = "file";
private String viewServer = GConstants.getValue("file.prefix.url","http://59.110.18.103:8089"); private String viewServer = GConstants.getValue("file.prefix.url");
// </editor-fold> // </editor-fold>
// <editor-fold desc="<===getters & setters======================================================================>"> // <editor-fold desc="<===getters & setters======================================================================>">
...@@ -182,8 +186,8 @@ public class FileController { ...@@ -182,8 +186,8 @@ public class FileController {
bean.extention = this.getExtension(name); bean.extention = this.getExtension(name);
bean.size = bts.length; bean.size = bts.length;
bean.fileName = name; bean.fileName = name;
String pathRel = this.getStoreRefDir() + name; String pathRel = "web/" + name;
File file = new File(this.savePath + pathSeparator + pathRel); File file = new File(this.savePath + pathRel);
try { try {
FileUtils.writeByteArrayToFile(file, bts); FileUtils.writeByteArrayToFile(file, bts);
...@@ -221,8 +225,17 @@ public class FileController { ...@@ -221,8 +225,17 @@ public class FileController {
} }
break; break;
} }
String id = IdGen.uuid();
bean.uri =viewServer + baseUri + "/" + method + "?" + param + "=" + pathRel.replace(this.pathSeparator, "_"); bean.id = id;
bean.uri = viewServer + pathRel;
//记录上传信息
ReportAttachmentEntity attachmentEntity = new ReportAttachmentEntity();
attachmentEntity.setId(id);
attachmentEntity.setAttachmentName(name);
attachmentEntity.setAttachmentSize(bean.size);
attachmentEntity.setAttachmentPath(viewServer + pathRel);
attachmentEntity.setAttachmentType("0");
ReportAttachmentUtils.add(attachmentEntity);
return bean; return bean;
} }
......
...@@ -6,11 +6,15 @@ import com.ejweb.conf.GConstants; ...@@ -6,11 +6,15 @@ import com.ejweb.conf.GConstants;
import com.ejweb.core.api.RequestBean; import com.ejweb.core.api.RequestBean;
import com.ejweb.core.api.ResponseBean; import com.ejweb.core.api.ResponseBean;
import com.ejweb.core.util.Util; import com.ejweb.core.util.Util;
import com.ejweb.core.utils.IdGen;
import com.ejweb.core.utils.IdWorker; import com.ejweb.core.utils.IdWorker;
import com.ejweb.modules.front.upload.bean.FileBean; import com.ejweb.modules.front.upload.bean.FileBean;
import com.ejweb.modules.front.upload.bean.FileResponse;
import com.ejweb.modules.front.upload.bean.UploadBean; import com.ejweb.modules.front.upload.bean.UploadBean;
import com.ejweb.modules.front.upload.bean.UploadFileBean; import com.ejweb.modules.front.upload.bean.UploadFileBean;
import com.ejweb.modules.front.upload.service.FrontUploadService; import com.ejweb.modules.front.upload.service.FrontUploadService;
import com.ejweb.modules.front.upload.util.ReportAttachmentUtils;
import com.ejweb.modules.report.entity.ReportAttachmentEntity;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
...@@ -28,10 +32,8 @@ import sun.misc.BASE64Decoder; ...@@ -28,10 +32,8 @@ import sun.misc.BASE64Decoder;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.FileInputStream; import java.net.URLDecoder;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -51,6 +53,9 @@ class FrontUploadController { ...@@ -51,6 +53,9 @@ class FrontUploadController {
@Autowired @Autowired
private FrontUploadService frontUploadService; private FrontUploadService frontUploadService;
private static final String savePath = GConstants.getValue("file.upload.dir");
private String viewServer = GConstants.getValue("file.prefix.url");
/** /**
* 使用BASE64上传文件 * 使用BASE64上传文件
* *
...@@ -62,74 +67,55 @@ class FrontUploadController { ...@@ -62,74 +67,55 @@ class FrontUploadController {
*/ */
@ApiOperation(value = "BASE64文件上传", httpMethod = "POST", response = ResponseBean.class, notes = "使用BASE64上传文件", position = 1) @ApiOperation(value = "BASE64文件上传", httpMethod = "POST", response = ResponseBean.class, notes = "使用BASE64上传文件", position = 1)
@ResponseBody @ResponseBody
@RequestMapping(value="/base64", method ={RequestMethod.POST}, produces={MediaType.APPLICATION_JSON_VALUE}) @RequestMapping(value="/base64", method ={RequestMethod.POST})
public ResponseBean base64(HttpServletRequest request, RequestBean requestBean) { public ResponseBean base64(HttpServletRequest request, HttpServletResponse response, RequestBean requestBean ,String files) {
ResponseBean responseBean = new ResponseBean(); ResponseBean responseBean = new ResponseBean();
List<UploadFileBean> uploadFiles = null; FileResponse file = new FileResponse();
response.setCharacterEncoding("UTF-8");
// String clientip = Util.getOnlineIP(request); String path = "";
UploadBean uploadFile = null;
uploadFile = JSON.parseObject(requestBean.getContent(), UploadBean.class);
String clientip = StringUtils.isEmpty(uploadFile.getClientip()) ? Util.getOnlineIP(request)
: uploadFile.getClientip();
String message = frontUploadService.validate(uploadFile);
if (message == null) {
uploadFiles = new ArrayList<UploadFileBean>(6);
// uploadFile.setFiles(uploadFiles);
List<UploadFileBean> files = uploadFile.getFiles();
if (files == null || files.size() == 0) {
responseBean.setStatus(ErrorCode.STATUS_CODE_4001);
responseBean.setMessage("获取不到文件列表!");
return responseBean;
}
// 生成本次会话的随机数随机数
String sessionId = IdWorker.getNextId();
for (UploadFileBean file : files) {// 遍历所有提交的文件
try { try {
String originalFilename = file.getName(); request.setCharacterEncoding("UTF-8");
if (StringUtils.isBlank(originalFilename)) String fileContent = request.getParameter("files");
originalFilename = "base64.png"; byte[] bytes = null;
if (StringUtils.isNotBlank(originalFilename)) {// 文件扩展名称不能为NULL if(StringUtils.isNotBlank(fileContent)){
if (originalFilename.contains("%") || originalFilename.contains(";")) { String name = request.getParameter("name");
responseBean.setStatus(ErrorCode.STATUS_CODE_4001); String suffix = name.split("\\.")[1];
responseBean.setMessage("上传文件不允许含有非法字符,请改正!"); path = "wap/" + System.currentTimeMillis() + "." + suffix;
return responseBean; bytes = new BASE64Decoder().decodeBuffer(fileContent.split(",")[1]);
} for (int i = 0; i < bytes.length; ++i) {
} if (bytes[i] < 0) {// 调整异常数据
if (StringUtils.isNotBlank(file.getData())) {// 文件扩展名称不能为NULL bytes[i] += 256;
file.setData(file.getData().replaceAll("data:image/jpeg;base64,", ""));
BASE64Decoder decoder = new BASE64Decoder();
byte[] buf = decoder.decodeBuffer(file.getData());
for (int i = 0, len = buf.length; i < len; ++i) {
if (buf[i] < 0) {// 调整异常数据
buf[i] += 256;
} }
} }
InputStream in = new ByteArrayInputStream(buf); OutputStream out = new FileOutputStream(savePath + path);
UploadFileBean fileBean = frontUploadService.addUploadFile(sessionId, in, file.getName(), out.write(bytes);
originalFilename, "image/png", uploadFile.getModule(), uploadFile.getAppCode(), clientip,uploadFile.getOrientataion()); out.flush();
fileBean.setOrientataion(uploadFile.getOrientataion()); out.close();
uploadFiles.add(fileBean); //ReportAttachment表的记录
ReportAttachmentEntity entity = new ReportAttachmentEntity();
entity.setAttachmentName(name);
entity.setAttachmentPath(viewServer + path);
entity.setAttachmentSize(fileContent.getBytes().length);
entity.setAttachmentType("0");
String id = IdGen.uuid();
entity.setId(id);
ReportAttachmentUtils.add(entity);
//返回数据
file.setName(name);
file.setSize(bytes.length);
file.setUri(viewServer + path);
file.setId(id);
responseBean.setData(file);
}else {
responseBean.setStatus(ErrorCode.STATUS_CODE_4001);
responseBean.setMessage("获取不到文件!");
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception e.printStackTrace();
} responseBean.setStatus(ErrorCode.STATUS_CODE_4004);
} responseBean.setMessage("系统错误!");
}
if (uploadFiles == null || uploadFiles.size() == 0) {
responseBean.setStatus(ErrorCode.STATUS_CODE_4001);
responseBean.setMessage("获取不到文件列表!");
return responseBean;
} }
uploadFile.setFiles(uploadFiles);
uploadFile.setSize(uploadFiles.size());
uploadFile.setUrl(GConstants.FILE_PREFIX_URL);
responseBean.setStatus(ErrorCode.STATUS_CODE_2000);
responseBean.setMessage(GConstants.OK);
responseBean.setData(uploadFile);
return responseBean; return responseBean;
} }
......
package com.ejweb.modules.front.upload.bean;
/**
* Created by mengxy on 2017/9/19.
*/
public class FileResponse {
private String id;
private String uri;
private int size;
private String name;
public FileResponse() {
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
package com.ejweb.modules.front.upload.util;
import com.ejweb.core.utils.SpringContextHolder;
import com.ejweb.modules.report.dao.ReportDao;
import com.ejweb.modules.report.entity.ReportAttachmentEntity;
import com.ejweb.modules.reportAttachment.dao.ReportAttachmentMapper;
import com.ejweb.modules.reportAttachment.entity.ReportAttachment;
/**
* Created by mengxy on 2017/9/19.
*/
public class ReportAttachmentUtils {
private static ReportDao reportDao = SpringContextHolder.getBean(ReportDao.class);
private static ReportAttachmentMapper attachmentMapper = SpringContextHolder.getBean(ReportAttachmentMapper.class);
public static void add(ReportAttachmentEntity attachmentEntity){
reportDao.addReportAttachment(attachmentEntity);
}
public static void addReportId(String id,String reportId){
ReportAttachment attachmentEntity = new ReportAttachment();
attachmentEntity.setId(id);
attachmentEntity.setReportId(reportId);
attachmentMapper.updateByPrimaryKeySelective(attachmentEntity);
}
}
package com.ejweb.modules.reportAttachment.dao;
import com.ejweb.core.persistence.CrudDao;
import com.ejweb.core.persistence.annotation.MyBatisDao;
import com.ejweb.modules.reportAttachment.entity.ReportAttachment;
@MyBatisDao
public interface ReportAttachmentMapper extends CrudDao<ReportAttachment> {
int deleteByPrimaryKey(String id);
int insert(ReportAttachment record);
int insertSelective(ReportAttachment record);
ReportAttachment selectByPrimaryKey(String id);
int updateByPrimaryKeySelective(ReportAttachment record);
int updateByPrimaryKey(ReportAttachment record);
}
\ No newline at end of file
package com.ejweb.modules.reportAttachment.entity;
public class ReportAttachment {
private String id;
private String reportId;
private String attachmentName;
private String attachmentPath;
private Integer attachmentSize;
private String attachmentType;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getReportId() {
return reportId;
}
public void setReportId(String reportId) {
this.reportId = reportId;
}
public String getAttachmentName() {
return attachmentName;
}
public void setAttachmentName(String attachmentName) {
this.attachmentName = attachmentName;
}
public String getAttachmentPath() {
return attachmentPath;
}
public void setAttachmentPath(String attachmentPath) {
this.attachmentPath = attachmentPath;
}
public Integer getAttachmentSize() {
return attachmentSize;
}
public void setAttachmentSize(Integer attachmentSize) {
this.attachmentSize = attachmentSize;
}
public String getAttachmentType() {
return attachmentType;
}
public void setAttachmentType(String attachmentType) {
this.attachmentType = attachmentType;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.ejweb.modules.reportAttachment.dao.ReportAttachmentMapper" >
<resultMap id="BaseResultMap" type="com.ejweb.modules.reportAttachment.entity.ReportAttachment" >
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="report_id" property="reportId" jdbcType="VARCHAR" />
<result column="attachment_name" property="attachmentName" jdbcType="VARCHAR" />
<result column="attachment_path" property="attachmentPath" jdbcType="VARCHAR" />
<result column="attachment_size" property="attachmentSize" jdbcType="INTEGER" />
<result column="attachment_type" property="attachmentType" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, report_id, attachment_name, attachment_path, attachment_size, attachment_type
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from report_attachment
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from report_attachment
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.ejweb.modules.reportAttachment.entity.ReportAttachment" >
insert into report_attachment (id, report_id, attachment_name,
attachment_path, attachment_size, attachment_type
)
values (#{id,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{attachmentName,jdbcType=VARCHAR},
#{attachmentPath,jdbcType=VARCHAR}, #{attachmentSize,jdbcType=INTEGER}, #{attachmentType,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.ejweb.modules.reportAttachment.entity.ReportAttachment" >
insert into report_attachment
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="reportId != null" >
report_id,
</if>
<if test="attachmentName != null" >
attachment_name,
</if>
<if test="attachmentPath != null" >
attachment_path,
</if>
<if test="attachmentSize != null" >
attachment_size,
</if>
<if test="attachmentType != null" >
attachment_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=VARCHAR},
</if>
<if test="reportId != null" >
#{reportId,jdbcType=VARCHAR},
</if>
<if test="attachmentName != null" >
#{attachmentName,jdbcType=VARCHAR},
</if>
<if test="attachmentPath != null" >
#{attachmentPath,jdbcType=VARCHAR},
</if>
<if test="attachmentSize != null" >
#{attachmentSize,jdbcType=INTEGER},
</if>
<if test="attachmentType != null" >
#{attachmentType,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.ejweb.modules.reportAttachment.entity.ReportAttachment" >
update report_attachment
<set >
<if test="reportId != null" >
report_id = #{reportId,jdbcType=VARCHAR},
</if>
<if test="attachmentName != null" >
attachment_name = #{attachmentName,jdbcType=VARCHAR},
</if>
<if test="attachmentPath != null" >
attachment_path = #{attachmentPath,jdbcType=VARCHAR},
</if>
<if test="attachmentSize != null" >
attachment_size = #{attachmentSize,jdbcType=INTEGER},
</if>
<if test="attachmentType != null" >
attachment_type = #{attachmentType,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.ejweb.modules.reportAttachment.entity.ReportAttachment" >
update report_attachment
set report_id = #{reportId,jdbcType=VARCHAR},
attachment_name = #{attachmentName,jdbcType=VARCHAR},
attachment_path = #{attachmentPath,jdbcType=VARCHAR},
attachment_size = #{attachmentSize,jdbcType=INTEGER},
attachment_type = #{attachmentType,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
...@@ -139,8 +139,8 @@ ...@@ -139,8 +139,8 @@
<!-- 支持Shiro对Controller的方法级AOP安全控制 end --> <!-- 支持Shiro对Controller的方法级AOP安全控制 end -->
<!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1024(B)=10485760 bytes --> <!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1024(B)=10485760 bytes -->
<bean id="multipartResolver" class="com.ejweb.core.filter.BaiduCommonsMultipartResolver"> <!--<bean id="multipartResolver" class="com.ejweb.core.filter.BaiduCommonsMultipartResolver">
<property name="maxUploadSize" value="${web.maxUploadSize}" /> <property name="maxUploadSize" value="${web.maxUploadSize}" />
</bean> </bean>-->
</beans> </beans>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment