Commit e6b35122 by Java-李昕颖

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

parents 69a52b09 1c96ec28
......@@ -37,6 +37,9 @@
<dozer.version>5.5.1</dozer.version>
<poi.version>3.9</poi.version>
<freemarker.version>2.3.20</freemarker.version>
<!-- Spring Swagger -->
<swagger.version>2.6.1</swagger.version>
<swagger-annotations.version>1.5.16</swagger-annotations.version>
<!-- jdbc driver setting -->
<mysql.driver.version>5.1.30</mysql.driver.version>
<oracle.driver.version>10.2.0.4.0</oracle.driver.version>
......@@ -154,6 +157,7 @@
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- bean validate -->
<dependency>
<groupId>org.hibernate</groupId>
......@@ -261,6 +265,18 @@
<version>2.1</version>
<scope>provided</scope>
</dependency>
<!--io-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger/swagger-annotations -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations.version}</version>
</dependency>
<!-- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
......
......@@ -26,4 +26,13 @@ public class ErrorCode {
public static final String STATUS_CODE_4104 = "4104";// 校验码错误
public static final String STATUS_CODE_4105 = "4105";// 校验码已失效
public static final String STATUS_CODE_4106 = "4106";// 需要重新登录
/*文件上传模块*/
public static final String NO_FILE_UPLOADED = "6001";
public static final String NO_FILE_FOUND_DESC = "no file found";
public static final String WRITE_FILE_FAIL = "6002";
public static final String WRITE_FILE_FAIL_DESC = "fail to write file on disk";
/**数据库**/
public static final String SQL_ERROR= "5001";
}
......@@ -22,15 +22,15 @@ public abstract class BaseEntity implements Serializable,Cloneable {
*/
private static final long serialVersionUID = 5983695342897355824L;
@JSONField(serialize=false)
protected Long id;
protected String id;
@JSONField(serialize=false)
protected String dbprefix;
public Long getId() {
public String getId() {
return id;
}
public void setId(Long id) {
public void setId(String id) {
this.id = id;
}
public String getDbprefix() {
......
......@@ -18,7 +18,7 @@ public final class FindEntity extends BaseEntity {
}
public FindEntity(Long id) {
this.id = id;
this.id = String.valueOf(id);
}
public String getCode() {
......
package com.ejweb.modules.front.report.api;
import com.ejweb.conf.ErrorCode;
import com.ejweb.core.api.ResponseBean;
import com.ejweb.modules.front.report.bean.FrontReportBean;
import com.ejweb.modules.front.report.entity.Captcha;
import com.ejweb.modules.front.report.service.FrontReportService;
import com.ejweb.modules.front.report.utils.CaptchaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by lenovo on 2017/9/7.
*/
@RestController
@RequestMapping("/front/report")
public class FrontReportController {
@Autowired
private FrontReportService frontReportService;
/**
* 获取验证码的code值
* @return
*/
@RequestMapping("captchaCode")
public ResponseBean captchaCode() {
ResponseBean response = new ResponseBean();
Captcha captcha = new Captcha();
captcha.setCode(CaptchaUtil.getCaptchaCode());
response.setData(captcha);
return response;
}
/**
* 举报
* @param bean
* @return
*/
@RequestMapping("addReport")
public ResponseBean addReport(FrontReportBean bean){
ResponseBean responseBean = new ResponseBean();
if(bean!=null){
return frontReportService.addReport(bean);
}
responseBean.setStatus(ErrorCode.STATUS_CODE_4001);
responseBean.setMessage("接收参数失败");
return responseBean;
}
}
package com.ejweb.modules.front.report.bean;
import com.ejweb.core.base.BaseBean;
import java.util.List;
/**
* Created by lenovo on 2017/9/8.
*/
public class FrontReportBean extends BaseBean{
private String id;
private String reportProject; //varchar(255) NOT NULL COMMENT '被举报项目',
private String reportCity; //varchar(255) NOT NULL COMMENT '所在城市',
private String reportTime; //varchar(20) NOT NULL COMMENT '举报时间',
private String reportContent; //text NOT NULL COMMENT '举报内容',
private String reportPersonName; //varchar(255) NOT NULL COMMENT '举报人姓名',
private String reportPersonTel; //varchar(255) NOT NULL COMMENT '举报人电话',
private String reportPersonEmail; //varchar(255) NOT NULL COMMENT '举报人邮箱',
private String reportSource; //varchar(255) NOT NULL COMMENT '举报途径 web:官网 oa:融创OA系统 supplier:供应商系统 wechat:微信公众号 sunacE:融E offline:线下扫码 tel:电话 email:邮件 visit:来访',
private String reportStatus; //varchar(1) DEFAULT NULL COMMENT '举报状态 0 未处理 1 处理中 2 已处理',
private String supplementCompany; //varchar(255) DEFAULT NULL COMMENT '被举报公司',
private String supplementDepartment; //varchar(255) DEFAULT NULL COMMENT '被举报部门',
private String supplementInformant; //varchar(255) DEFAULT NULL COMMENT '被举报人',
private String supplementTitle; //varchar(255) DEFAULT NULL COMMENT '标题',
private String supplementType; //varchar(255) DEFAULT NULL COMMENT '业务类型 1 营销 2 工程 3 成本 4 招采 5人力 6物业 7投诉',
private String supplementArea; //varchar(255) DEFAULT NULL COMMENT '被举报区域',
private String supplementProject; //varchar(255) DEFAULT NULL COMMENT '被举报项目',
private String supplementContent; //text,
private String dealPersonName; //varchar(255) DEFAULT NULL COMMENT '处理人',
private String dealResult; //varchar(255) DEFAULT NULL COMMENT '处理结论 1 投诉 2 举报无效 3 举报属实',
private String exchangeBeforeUser; //varchar(255) DEFAULT NULL COMMENT '移交/转交前用户id',
private String exchangeAfterUser; //varchar(255) DEFAULT NULL COMMENT '移交/转交后用户id(只记录最新的移交用户,此处不记录历史)',
private List<ReportAttachmentBean> reportAttachmentList; // 附件
public String getReportProject() {
return reportProject;
}
public void setReportProject(String reportProject) {
this.reportProject = reportProject;
}
public String getReportCity() {
return reportCity;
}
public void setReportCity(String reportCity) {
this.reportCity = reportCity;
}
public String getReportTime() {
return reportTime;
}
public void setReportTime(String reportTime) {
this.reportTime = reportTime;
}
public String getReportContent() {
return reportContent;
}
public void setReportContent(String reportContent) {
this.reportContent = reportContent;
}
public String getReportPersonName() {
return reportPersonName;
}
public void setReportPersonName(String reportPersonName) {
this.reportPersonName = reportPersonName;
}
public String getReportPersonTel() {
return reportPersonTel;
}
public void setReportPersonTel(String reportPersonTel) {
this.reportPersonTel = reportPersonTel;
}
public String getReportPersonEmail() {
return reportPersonEmail;
}
public void setReportPersonEmail(String reportPersonEmail) {
this.reportPersonEmail = reportPersonEmail;
}
public String getReportSource() {
return reportSource;
}
public void setReportSource(String reportSource) {
this.reportSource = reportSource;
}
public String getReportStatus() {
return reportStatus;
}
public void setReportStatus(String reportStatus) {
this.reportStatus = reportStatus;
}
public String getSupplementCompany() {
return supplementCompany;
}
public void setSupplementCompany(String supplementCompany) {
this.supplementCompany = supplementCompany;
}
public String getSupplementDepartment() {
return supplementDepartment;
}
public void setSupplementDepartment(String supplementDepartment) {
this.supplementDepartment = supplementDepartment;
}
public String getSupplementInformant() {
return supplementInformant;
}
public void setSupplementInformant(String supplementInformant) {
this.supplementInformant = supplementInformant;
}
public String getSupplementTitle() {
return supplementTitle;
}
public void setSupplementTitle(String supplementTitle) {
this.supplementTitle = supplementTitle;
}
public String getSupplementType() {
return supplementType;
}
public void setSupplementType(String supplementType) {
this.supplementType = supplementType;
}
public String getSupplementArea() {
return supplementArea;
}
public void setSupplementArea(String supplementArea) {
this.supplementArea = supplementArea;
}
public String getSupplementProject() {
return supplementProject;
}
public void setSupplementProject(String supplementProject) {
this.supplementProject = supplementProject;
}
public String getSupplementContent() {
return supplementContent;
}
public void setSupplementContent(String supplementContent) {
this.supplementContent = supplementContent;
}
public String getDealPersonName() {
return dealPersonName;
}
public void setDealPersonName(String dealPersonName) {
this.dealPersonName = dealPersonName;
}
public String getDealResult() {
return dealResult;
}
public void setDealResult(String dealResult) {
this.dealResult = dealResult;
}
public String getExchangeBeforeUser() {
return exchangeBeforeUser;
}
public void setExchangeBeforeUser(String exchangeBeforeUser) {
this.exchangeBeforeUser = exchangeBeforeUser;
}
public String getExchangeAfterUser() {
return exchangeAfterUser;
}
public void setExchangeAfterUser(String exchangeAfterUser) {
this.exchangeAfterUser = exchangeAfterUser;
}
public List<ReportAttachmentBean> getReportAttachmentList() {
return reportAttachmentList;
}
public void setReportAttachmentList(List<ReportAttachmentBean> reportAttachmentList) {
this.reportAttachmentList = reportAttachmentList;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
package com.ejweb.modules.front.report.dao;
import com.ejweb.core.persistence.CrudDao;
import com.ejweb.modules.front.report.bean.FrontReportBean;
import com.ejweb.modules.front.report.bean.ReportAttachmentBean;
import com.ejweb.modules.front.report.entity.FrontReportEntity;
/**
* Created by lenovo on 2017/9/8.
*/
public interface FrontReportDao extends CrudDao<FrontReportEntity> {
// 添加举报信息
public Integer insertReport(FrontReportBean bean);
// 添加举报附件
public Integer insertReportAttachment(ReportAttachmentBean bean);
}
package com.ejweb.modules.front.report.entity;
/**
* Created by BrianHolsen on 2017-08-08 at 15:37.
*/
public class Captcha {
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
package com.ejweb.modules.front.report.entity;
import com.ejweb.core.persistence.DataEntity;
/**
* Created by lenovo on 2017/9/8.
*/
public class FrontReportEntity extends DataEntity<FrontReportEntity> {
}
package com.ejweb.modules.front.report.service;
import com.ejweb.conf.ErrorCode;
import com.ejweb.conf.GConstants;
import com.ejweb.core.api.ResponseBean;
import com.ejweb.core.service.CrudService;
import com.ejweb.core.utils.IdWorker;
import com.ejweb.modules.front.report.bean.FrontReportBean;
import com.ejweb.modules.front.report.bean.ReportAttachmentBean;
import com.ejweb.modules.front.report.dao.FrontReportDao;
import com.ejweb.modules.front.report.entity.FrontReportEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* Created by lenovo on 2017/9/8.
*/
@Service
@Transactional(readOnly = true)
public class FrontReportService extends CrudService<FrontReportDao,FrontReportEntity>{
// 添加举报信息
@Transactional(readOnly = false)
public ResponseBean addReport(FrontReportBean bean){
ResponseBean responseBean = new ResponseBean();
bean.setId(IdWorker.getNextId("R"));
// 添加举报信息表
int row = dao.insertReport(bean);
if(row == 1){ // 添加成功
List<ReportAttachmentBean> list = bean.getReportAttachmentList();
if(list != null && list.size()>0){ // 添加举报附件
for(ReportAttachmentBean reportAttachmentBean:list){
reportAttachmentBean.setReportId(bean.getId());
reportAttachmentBean.setId(IdWorker.getNextId("RA"));
dao.insertReportAttachment(reportAttachmentBean);
}
}
responseBean.setStatus(ErrorCode.STATUS_CODE_2000);
responseBean.setMessage(GConstants.OK);
return responseBean;
}
responseBean.setStatus(ErrorCode.SQL_ERROR);
responseBean.setMessage("数据添加失败");
return responseBean;
}
}
package com.ejweb.modules.front.report.servlet;
import com.ejweb.modules.front.report.utils.CaptchaUtil;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Random;
/**
* Created by BrianHolsen on 2017-08-08 at 11:42.
*/
public class CaptchaServlet extends HttpServlet {
private static final long serialVersionUID = 1325598241;
private int height = 25;
private int width = 90;
public CaptchaServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String ch = CaptchaUtil.getCaptcha(request.getParameter("code"));
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Max-Age", 0);
Random r = new Random(new Date().getTime());
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = image.createGraphics();
graphics2D.setColor(new Color(192, 192, 192)); // or the background color u want
graphics2D.fillRect(0, 0, width, height);
for (int i = 0; i < 20; i++) {
Line2D line1 = new Line2D.Float(Math.abs(r.nextInt()) % width, Math.abs(r.nextInt()) % height
, Math.abs(r.nextInt()) % width, Math.abs(r.nextInt()) % height);
graphics2D.setPaint(new GradientPaint(30, 30, new Color(Math.abs(r.nextInt())), 15, 25, new Color(Math.abs(r.nextInt()))));
graphics2D.draw(line1);
}
graphics2D.setPaint(new GradientPaint(30, 30, Color.BLUE, 15, 25, Color.RED, true));
Font font = new Font("Verdana", Font.CENTER_BASELINE, 20);
graphics2D.setFont(font);
graphics2D.drawString(ch, 5, 20);
graphics2D.dispose();
OutputStream outputStream = response.getOutputStream();
ImageIO.write(image, "jpeg", outputStream);
outputStream.close();
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
package com.ejweb.modules.front.report.utils;
import java.io.UnsupportedEncodingException;
import java.security.InvalidParameterException;
import java.util.Date;
import java.util.Random;
/**
* Created by BrianHolsen on 2017-08-08 at 13:35.
*/
public class CaptchaUtil {
private static byte[] KEY = {0x70, 0x3f, 0x2b, 0x47};
private static final char[] HEX_TABLE_LOWER_CASE = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
private static int LEN = 6;
private static int EXPIRE_MININUTES = 3;
/**
*
* @param str
* @return
*/
private static String encrypt(String str) {
if (null == str || str.equals("")) {
return str;
}
Random rand = new Random(new Date().getTime());
try {
StringBuffer buffer = new StringBuffer();
buffer.append(Math.abs(rand.nextInt()) % 10);
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
buffer.append(c);
for (int j = 0; j < c % 5; j++) {
buffer.append(Math.abs(rand.nextInt()) % 10);
}
}
byte[] bts = buffer.toString().getBytes("utf-8");
for (int i = 0; i < bts.length; i++) {
bts[i] ^= KEY[i % KEY.length];
}
return toHexString(bts);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return str;
}
private static String decrypt(String str) {
if (null == str || str.equals("")) {
return str;
}
byte[] bts = toByteArrayFromHexString(str);
for (int i = 0; i < bts.length; i++) {
bts[i] ^= KEY[i % KEY.length];
}
StringBuffer buffer = new StringBuffer();
for (int i = 1; i < bts.length; i++) {
buffer.append((char) bts[i]);
i += bts[i] % 5;
}
return buffer.toString();
}
private static String toHexString(int data) {
StringBuffer buf = new StringBuffer();
char[] hex_table = HEX_TABLE_LOWER_CASE;
int index8 = (data >> 28) & 0x0000000F;
int index7 = (data >> 24) & 0x0000000F;
int index6 = (data >> 20) & 0x0000000F;
int index5 = (data >> 16) & 0x0000000F;
int index4 = (data >> 12) & 0x0000000F;
int index3 = (data >> 8) & 0x0000000F;
int index2 = (data >> 4) & 0x0000000F;
int index1 = data & 0x0000000F;
buf.append(hex_table[index8])
.append(hex_table[index7])
.append(hex_table[index6])
.append(hex_table[index5])
.append(hex_table[index4])
.append(hex_table[index3])
.append(hex_table[index2])
.append(hex_table[index1]);
return buf.toString();
}
private static String toHexString(byte[] data) {
StringBuffer buf = new StringBuffer();
char[] hex_table = HEX_TABLE_LOWER_CASE;
for (int i = 0; i < data.length; i++) {
int index_low = data[i] & 0x0F;
int index_high = (data[i] >> 4) & 0x0F;
buf.append(hex_table[index_high]).append(hex_table[index_low]);
}
return buf.toString();
}
private static byte[] toByteArrayFromHexString(String hexString) {
if (hexString.length() % 2 != 0) {
throw new InvalidParameterException("The length of a hex string must be even");
}
hexString = hexString.toLowerCase();
byte[] bts = hexString.getBytes();
int startIndex = 0;
if (bts[0] == '0' && (bts[1] == 'x')) {
startIndex = 2;
}
byte[] result = new byte[(bts.length - startIndex) / 2];
for (int i = startIndex; i < bts.length; i += 2) {
byte high = bts[i];
byte low = bts[i + 1];
if ((high < '0' || (high > '9' && high < 'a') || high > 'f')
|| (low < '0' || (low > '9' && low < 'a') || low > 'f')) {
throw new InvalidParameterException("Invalid char(s) in hex string");
}
high -= 48;
low -= 48;
if (high > 10) {
high -= 39;
}
if (low > 10) {
low -= 39;
}
result[(i - startIndex) / 2] = (byte) ((high << 4) + low);
}
return result;
}
public static boolean validate(String captcha, String code) {
if (captcha == null || captcha.equals("") || code == null || code.equals("")) {
return false;
}
try {
String data = decrypt(code);
String correctCaptcha = data.substring(0, LEN);
long time = new Date().getTime();
long expires = Long.parseLong(data.substring(LEN));
if (captcha.equals(correctCaptcha) && expires > time) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
*
* 获取验证码对应的code值
* @return
*/
public static String getCaptchaCode() {
Random rand = new Random(new Date().getTime());
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < LEN; i++) {
buffer.append(Math.abs(rand.nextInt()) % 10);
}
//System.out.println(buffer.toString());
buffer.append(new Date().getTime() + EXPIRE_MININUTES * 60 * 1000);
//buffer.append(new Date().getTime() + 30 * 1000);
//System.out.println(buffer.toString());
return CaptchaUtil.encrypt(buffer.toString());
}
public static String getCaptcha(String code) {
if (code == null || code.equals("")) {
return "";
}
try {
String data = decrypt(code);
String correctCaptcha = data.substring(0, LEN);
return correctCaptcha;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static void main(String[] args) throws InterruptedException {
String code = getCaptchaCode();
System.out.println(code);
String captcha = getCaptcha(code);
System.out.println(captcha);
System.out.println(validate(captcha, code));
Thread.sleep(2000);
System.out.println(validate(captcha, code));
Thread.sleep(3000);
System.out.println(validate(captcha, code));
// System.out.println(CaptchaUtil.encrypt(buffer.toString()));
}
}
package com.ejweb.modules.front.upload.api;
import com.ejweb.conf.ErrorCode;
import com.ejweb.conf.GConstants;
import com.ejweb.core.api.ResponseBean;
import com.ejweb.modules.sys.service.LogService;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
;
/**
* Created by BrianHolsen on 2017-07-11 at 17:19.
*/
@RequestMapping("/front/file")
public class FileController {
private class UploadResultBean {
public String uri;
public int size;
public String extention;
public String fileName;
}
// <editor-fold desc="<===private fields=========================================================================>">
@Autowired
private LogService logService;
private static final String savePath = GConstants.getValue("file.upload.dir");
private static final String pathSeparator = GConstants.getValue("upload.path.separator", "\\");
private static final String allowedExt = GConstants.getValue("upload.extension", "");
private String downloadFileMethodName = "downloadFile";
private String downloadFileParamName = "file";
private String downloadImageMethodName = "downloadImage";
private String downloadImageParamName = "file";
private String viewServer = GConstants.getValue("file.prefix.url","http://59.110.18.103:8089");
// </editor-fold>
// <editor-fold desc="<===getters & setters======================================================================>">
public String getDownloadFileMethodName() {
return downloadFileMethodName;
}
public void setDownloadFileMethodName(String downloadFileMethodName) {
this.downloadFileMethodName = downloadFileMethodName;
}
public String getDownloadFileParamName() {
return downloadFileParamName;
}
public void setDownloadFileParamName(String downloadFileParamName) {
this.downloadFileParamName = downloadFileParamName;
}
public String getDownloadImageMethodName() {
return downloadImageMethodName;
}
public void setDownloadImageMethodName(String downloadImageMethodName) {
this.downloadImageMethodName = downloadImageMethodName;
}
public String getDownloadImageParamName() {
return downloadImageParamName;
}
public void setDownloadImageParamName(String downloadImageParamName) {
this.downloadImageParamName = downloadImageParamName;
}
// </editor-fold>
public ResponseBean upload(HttpServletRequest request) {
ResponseBean response = new ResponseBean();
boolean isMutipart = ServletFileUpload.isMultipartContent(request);
if (isMutipart) {
String currentUri = request.getRequestURI();
int index = currentUri.lastIndexOf("/");
String baseUri = currentUri.substring(0, index);
FileItemFactory factory = new org.apache.commons.fileupload.disk.DiskFileItemFactory();
ServletFileUpload fileUpload = new ServletFileUpload(factory);
try {
List<FileItem> fileItems = fileUpload.parseRequest(request);
if (fileItems.size() < 1) {
response.setStatus(ErrorCode.NO_FILE_UPLOADED);
response.setMessage(ErrorCode.NO_FILE_FOUND_DESC);
} else if (fileItems.size() == 1) {
FileItem item = fileItems.get(0);
UploadResultBean resultBean = this.storeFile(item.getName(), baseUri, item.get());
if (resultBean == null) {
response.setStatus(ErrorCode.WRITE_FILE_FAIL);
response.setMessage(ErrorCode.WRITE_FILE_FAIL_DESC);
} else {
response.setData(resultBean);
}
} else {
List<UploadResultBean> beans = new ArrayList<>();
for (FileItem item : fileItems) {
if(!item.isFormField()){
UploadResultBean resultBean = this.storeFile(item.getName(), baseUri, item.get());
beans.add(resultBean);
}
}
response.setData(beans);
}
} catch (FileUploadException e) {
//this.logService.logError(e.getMessage());
e.printStackTrace();
}
}
return response;
}
public void downloadFile(HttpServletRequest request, HttpServletResponse response, String file) {
if (file == null || file.isEmpty()) {
response.setStatus(HttpStatus.NOT_FOUND.value());
}
byte[] bts = this.getFile(file);
if (bts == null) {
response.setStatus(HttpStatus.NOT_FOUND.value());
}
response.setContentType("application/force-download");
response.setContentLength(bts.length);
response.setHeader("Content-Transfer-Encoding", "binary");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Content-Disposition", "attachment; filename=\"" + file + "\"");
OutputStream outputStream = null;
try {
outputStream = response.getOutputStream();
outputStream.write(bts);
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(outputStream);
}
}
@ResponseBody
public byte[] downloadImage(String file) {
return this.getFile(file);
}
// <editor-fold desc="<===private methods========================================================================>">
private UploadResultBean storeFile(String name, String baseUri, byte[] bts) {
UploadResultBean bean = new UploadResultBean();
// String id = UUIDUtil.uuid();
bean.extention = this.getExtension(name);
bean.size = bts.length;
bean.fileName = name;
String pathRel = this.getStoreRefDir() + name;
File file = new File(this.savePath + pathSeparator + pathRel);
try {
FileUtils.writeByteArrayToFile(file, bts);
} catch (IOException e) {
//this.logService.logError(e.getMessage());
e.printStackTrace();
return null;
}
String method = "";
String param = "";
switch (bean.extention.trim().toLowerCase()) {
case ".bmp":
case ".jpg":
case ".jpeg":
case ".png":
case ".gif":
method = this.getDownloadImageMethodName();
param = this.getDownloadImageParamName();
if (method == null || method.isEmpty()) {
method = "downloadImage";
}
if (param == null || param.isEmpty()) {
param = "file";
}
break;
default:
method = this.getDownloadFileMethodName();
param = this.getDownloadFileParamName();
if (method == null || method.isEmpty()) {
method = "downloadFile";
}
if (param == null || param.isEmpty()) {
param = "file";
}
break;
}
bean.uri =viewServer + baseUri + "/" + method + "?" + param + "=" + pathRel.replace(this.pathSeparator, "_");
return bean;
}
private byte[] getFile(String name) {
String path = this.savePath + this.pathSeparator + name.replace("_", this.pathSeparator);
try {
byte[] bts = FileUtils.readFileToByteArray(new File(path));
return bts;
} catch (IOException e) {
//this.logService.logError(e.getMessage());
e.printStackTrace();
return null;
}
}
private String getStoreRefDir() {
// SimpleDateFormat df = new SimpleDateFormat("yyyy" + pathSeparator + "MM" + pathSeparator + "dd");
// String str = df.format(new Date()) + this.pathSeparator;
return "";
}
private String getExtension(String name) {
if (name == null || name.isEmpty()) {
return "";
}
int index = name.lastIndexOf(".");
if (index > 0) {
return name.substring(index);
}
return "";
}
// </editor-fold>
}
\ No newline at end of file
package com.ejweb.modules.front.upload.bean;
import com.alibaba.fastjson.annotation.JSONField;
/**
* 单个文件实体
* @team IT Team
* @author renmb
* @version 1.0
* @time 2016-03-22
*
*/
public class FileBean {
private String name;
private String extesion;
@JSONField(deserialize=false)
private String path;
private String thumbs;
private String md5;
private int size;
@JSONField(serialize=false)
private String summary;
private int width;// 图片特有
private int height;// 图片特有
private int status=0;// 0:未处理 1:成功 2:格式不运行上传
public String getThumbs() {
return thumbs;
}
public void setThumbs(String thumbs) {
this.thumbs = thumbs;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getExtesion() {
return extesion;
}
public void setExtesion(String extesion) {
this.extesion = extesion;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
}
package com.ejweb.modules.front.upload.bean;
import com.alibaba.fastjson.annotation.JSONField;
import com.ejweb.core.base.BaseBean;
import java.util.List;
/**
* 接口请求Content实体
* @team IT Team
* @author renmb
* @version 1.0
* @time 2016-03-22
*
*/
public class UploadBean extends BaseBean {
// @NotEmpty(message="module字段不能为NULL")
private String module;
private String contentType="png";// 文件类型,即文件的后缀名称,如png,mp3登录
private String sessionId;
private String clientip;
private String url;
private String orientataion;
@JSONField(deserialize=false)
private int size;// 成功处理的文件格式
List<UploadFileBean> files;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
public List<UploadFileBean> getFiles() {
return files;
}
public void setFiles(List<UploadFileBean> files) {
this.files = files;
}
public String getClientip() {
return clientip;
}
public void setClientip(String clientip) {
this.clientip = clientip;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public String getOrientataion() {
return orientataion;
}
public void setOrientataion(String orientataion) {
this.orientataion = orientataion;
}
}
package com.ejweb.modules.front.upload.bean;
import com.alibaba.fastjson.annotation.JSONField;
/**
* 单个文件实体
* @team IT Team
* @author renmb
* @version 1.0
* @time 2016-03-22
*
*/
public class UploadFileBean {
private String name;
private String inputName;
private String extesion;
@JSONField(deserialize=false)
private String path;
private String thumbs;
private String md5;
private int size;
@JSONField(serialize=false)
private String summary;
private int width;// 图片特有
private int height;// 图片特有
private int status=0;// 0:未处理 1:成功 2:格式不允许上传
private String data;// BASE64字符编码
private String orientataion;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getInputName() {
return inputName;
}
public void setInputName(String inputName) {
this.inputName = inputName;
}
public String getExtesion() {
return extesion;
}
public void setExtesion(String extesion) {
this.extesion = extesion;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getThumbs() {
return thumbs;
}
public void setThumbs(String thumbs) {
this.thumbs = thumbs;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getOrientataion() {
return orientataion;
}
public void setOrientataion(String orientataion) {
this.orientataion = orientataion;
}
}
package com.ejweb.modules.front.upload.dao;
import com.ejweb.core.base.BaseDao;
import com.ejweb.core.base.FindEntity;
import com.ejweb.core.persistence.annotation.MyBatisDao;
import com.ejweb.modules.front.upload.entity.UploadEntity;
/**
* @team IT Team
* @author renmb
* @version 1.0
* @time 2016-03-22
*
*/
@MyBatisDao
public interface FrontUploadDao extends BaseDao {
public Long addUploadFile(UploadEntity fileUploadEntity);
public UploadEntity getUploadEntityByPath(FindEntity entity);
}
package com.ejweb.modules.front.upload.entity;
import com.ejweb.core.base.BaseEntity;
/**
*
* 上传文件返回实体
* @team IT Team
* @author renmb
* @version 1.0
* @time 2016-03-22
*
*/
public class UploadEntity extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 8395156713205116362L;
private String id;
private String appCode;
private String sessionId;
private String clientip;
private String name;
private String inputName;
private String module;
private String extesion;
private String path;
private String thumbs;
private String md5;
private int size;
private String summary;
private int width;
private int height;
private String orientataion;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public String getClientip() {
return clientip;
}
public void setClientip(String clientip) {
this.clientip = clientip;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public String getAppCode() {
return appCode;
}
public void setAppCode(String appCode) {
this.appCode = appCode;
}
public String getThumbs() {
return thumbs;
}
public void setThumbs(String thumbs) {
this.thumbs = thumbs;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getInputName() {
return inputName;
}
public void setInputName(String inputName) {
this.inputName = inputName;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
public String getExtesion() {
return extesion;
}
public void setExtesion(String extesion) {
this.extesion = extesion;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getOrientataion() {
return orientataion;
}
public void setOrientataion(String orientataion) {
this.orientataion = orientataion;
}
}
/**
*
*/
package com.ejweb.modules.front.upload.util;
import com.ejweb.conf.GConstants;
import com.ejweb.modules.upload.bean.UploadFileBean;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.util.List;
/**
*
* @team IT Team
* @author renmb
* @version 1.0
* @time 2016年8月8日
*/
public class UploadUtils {
/**
* 更加表单名称获取上传的文件实体
*
* @author renmb
* @time 2016年8月8日
* @param uploadFiles 上传的文件列表
* @param inputName
* @return
*/
public UploadFileBean getUploadFileByInputName(List<UploadFileBean> uploadFiles, String inputName){
if(StringUtils.isBlank(inputName) || uploadFiles == null || uploadFiles.size() == 0)
return null;
for(int i=0,len=uploadFiles.size();i<len;i++){// 以文件名称匹配
// 获取同MD5或者同名的文件对象
if(uploadFiles.get(i) != null && inputName.equalsIgnoreCase(uploadFiles.get(i).getInputName())){
return uploadFiles.get(i);
}
}
return null;
}
/**
* 获取上传文件的文件路径
*
* @author renmb
* @time 2016年8月8日
* @param uploadFiles
* @param inputName
* @return
*/
public String getUploadFilePathByInputName(List<UploadFileBean> uploadFiles, String inputName){
if(StringUtils.isBlank(inputName) || uploadFiles == null || uploadFiles.size() == 0)
return null;
for(int i=0,len=uploadFiles.size();i<len;i++){// 以文件名称匹配
// 获取同MD5或者同名的文件对象
if(uploadFiles.get(i) != null && inputName.equalsIgnoreCase(uploadFiles.get(i).getInputName())){
return uploadFiles.get(i).getPath();
}
}
return null;
}
/**
* 将文件复制到其它备份磁盘
*
* author renmb
* @time 2017年05月18日
* @param file
*/
public static void copyToMultiplePaths (final File file){
final String dirs = GConstants.getValue("file.upload.dirs");
if(StringUtils.isNotEmpty(dirs)){
try {
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
String basePath = file.getAbsolutePath().replace(GConstants.FILE_UPLOAD_DIR, "");
String[] paths = dirs.split(";");
for (String path:paths){
InputStream input = null;
OutputStream output = null;
try{
File newFilePath = new File(path, basePath);
if(!newFilePath.getParentFile().exists()){// 如果文件夹不存在则创建
newFilePath.getParentFile().mkdirs();
}
// LOG.debug("UploadService copyToMultiplePaths: "+file.getAbsolutePath()+" TO "+newFilePath.getAbsolutePath());
input = new FileInputStream(file);
output = new FileOutputStream(newFilePath);
IOUtils.copy(input, output);
} catch (Exception e){
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}
}
});
thread.start();
} catch (Exception e){
e.printStackTrace();
}
}
}
}
package com.ejweb.modules.front.upload.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 页面上传路径
* @team IT Team
* @author renmb
* @version 1.0
* @time 2016-03-22
*
*/
@Controller
@RequestMapping(value="/front/web/upload")
public class FrontUploadAction {
@RequestMapping("/index")
public String index(){
return "modules/upload/index";
}
@RequestMapping("/multipart")
public String multipart(){
return "modules/upload/multipart";
}
@RequestMapping("/stream/upload")
public String streamUpload(){
return "modules/upload/stream";
}
}
......@@ -96,6 +96,9 @@ file.image.thumb.height=640
# The Prefix Url
file.prefix.url=http://127.0.0.1:8080/static/
# The Prefix separator
file.upload.path.separator = /
# The Push Server Config
push.server.url=http://123.56.146.81:1880/v1/
......
<?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.front.upload.dao.FrontUploadDao">
<sql id="fileColumns">
id,
app_code,
session_id,
clientip,
module,
md5,
name,
input_name,
path,
thumbs,
extesion,
summary,
size,
width,
orientataion,
height
</sql>
<insert id="addUploadFile" useGeneratedKeys="true" keyProperty="id">
INSERT INTO upload_files(
<include refid="fileColumns"/>
) VALUES(
#{id},
#{appCode},
#{sessionId},
#{clientip},
#{module},
#{md5},
#{name},
#{inputName},
#{path},
#{thumbs},
#{extesion},
#{summary},
#{size},
#{width},
#{orientataion},
#{height}
)
</insert>
<select id="getUploadEntityByPath" resultType="com.ejweb.modules.upload.entity.UploadEntity">
SELECT
<include refid="fileColumns"/>
FROM upload_files
WHERE path = #{code}
ORDER BY created DESC
limit 1
</select>
</mapper>
\ 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.front.report.dao.FrontReportDao">
<sql id="reportColumns">
id,
report_project,
report_city,
report_time,
report_content,
report_person_name,
report_person_tel,
report_person_email,
report_source,
report_status,
supplement_company,
supplement_department,
supplement_informant,
supplement_title,
supplement_type,
supplement_area,
supplement_project,
supplement_content,
deal_person_name,
deal_result,
exchange_before_user,
exchange_after_user,
create_by,
create_date,
update_by,
update_date
</sql>
<insert id="insertReport" useGeneratedKeys="true" keyProperty="id">
INSERT INTO report(
id,
report_project,
report_city,
report_time,
report_content,
report_person_name,
report_person_tel,
report_person_email,
report_source,
report_status,
exchange_before_user,
exchange_after_user,
create_by,
create_date,
update_by,
update_date
) VALUES(
#{id},
#{reportProject},
#{reportCity},
#{reportTime},
#{reportContent},
#{reportPersonName},
#{reportPersonTel},
#{reportPersonEmail},
#{reportSource},
#{reportStatus},
#{exchangeBeforeUser},
#{exchangeAfterUser},
#{createBy},
#{createDate},
#{updateBy},
#{updateDate}
)
</insert>
<insert id="insertReportAttachment">
INSERT INTO report_attachment(
id,
report_id,
attachment_name,
attachment_path,
attachment_size,
attachment_type
)VALUES(
#{id},
#{reportId},
#{attachmentName},
#{attachmentPath},
#{attachmentSize},
#{attachmentType}
)
</insert>
</mapper>
\ No newline at end of file
......@@ -147,6 +147,18 @@
<servlet-name>ValidateCodeServlet</servlet-name>
<url-pattern>/servlet/validateCodeServlet</url-pattern>
</servlet-mapping>
<!--验证码-->
<servlet>
<servlet-name>captcha</servlet-name>
<servlet-class>com.ejweb.modules.front.report.servlet.CaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>captcha</servlet-name>
<url-pattern>/front/report/captcha</url-pattern>
</servlet-mapping>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/error/500.jsp</location>
......
......@@ -3,9 +3,9 @@ db.table.prefix=sunac_
jdbc.type=mysql
jdbc.driver.class=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/report_sunac?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=admin
jdbc.url=jdbc:mysql://123.56.146.7:3306/sunac_report?useUnicode=true&characterEncoding=utf-8
jdbc.username=reportuser
jdbc.password=$R@20$7
#初始化连接
jdbc.initialSize=0
......
......@@ -147,6 +147,18 @@
<servlet-name>ValidateCodeServlet</servlet-name>
<url-pattern>/servlet/validateCodeServlet</url-pattern>
</servlet-mapping>
<!--验证码-->
<servlet>
<servlet-name>captcha</servlet-name>
<servlet-class>com.ejweb.modules.front.report.servlet.CaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>captcha</servlet-name>
<url-pattern>/front/report/captcha</url-pattern>
</servlet-mapping>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/error/500.jsp</location>
......
......@@ -96,6 +96,9 @@ file.image.thumb.height=640
# The Prefix Url
file.prefix.url=http://127.0.0.1:8080/static/
# The Prefix separator
file.upload.path.separator = /
# The Push Server Config
push.server.url=http://123.56.146.81:1880/v1/
......
......@@ -3,9 +3,9 @@ db.table.prefix=sunac_
jdbc.type=mysql
jdbc.driver.class=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/report_sunac?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=admin
jdbc.url=jdbc:mysql://123.56.146.7:3306/sunac_report?useUnicode=true&characterEncoding=utf-8
jdbc.username=reportuser
jdbc.password=$R@20$7
#初始化连接
jdbc.initialSize=0
......
......@@ -147,6 +147,18 @@
<servlet-name>ValidateCodeServlet</servlet-name>
<url-pattern>/servlet/validateCodeServlet</url-pattern>
</servlet-mapping>
<!--验证码-->
<servlet>
<servlet-name>captcha</servlet-name>
<servlet-class>com.ejweb.modules.front.report.servlet.CaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>captcha</servlet-name>
<url-pattern>/front/report/captcha</url-pattern>
</servlet-mapping>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/error/500.jsp</location>
......
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