Commit 1f28f9e6 by 陶光胜

Merge branch 'developer' into 'master'

Developer

See merge request !4
parents b0c1bc3f 30b546b8
...@@ -7,6 +7,8 @@ import com.gic.api.base.commons.ServiceResponse; ...@@ -7,6 +7,8 @@ import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse; import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.exception.CommonException; import com.gic.enterprise.exception.CommonException;
import org.apache.commons.collections.CollectionUtils;
/** /**
* controller统一返回结果 * controller统一返回结果
* @ClassName: ResultControllerUtils
 * @ClassName: ResultControllerUtils

...@@ -94,6 +96,9 @@ public class ResultControllerUtils { ...@@ -94,6 +96,9 @@ public class ResultControllerUtils {
public static RestResponse commonPageResult(ServiceResponse response, Class<?> clazz) { public static RestResponse commonPageResult(ServiceResponse response, Class<?> clazz) {
if (response.isSuccess()) { if (response.isSuccess()) {
Page page = (Page) response.getResult(); Page page = (Page) response.getResult();
if (page == null) {
return RestResponse.success();
}
page.setResult(EntityUtil.changeEntityListNew(clazz, page.getResult())); page.setResult(EntityUtil.changeEntityListNew(clazz, page.getResult()));
return RestResponse.success(page); return RestResponse.success(page);
} else { } else {
......
...@@ -13,4 +13,12 @@ public class FilterConfig { ...@@ -13,4 +13,12 @@ public class FilterConfig {
bean.addUrlPatterns("/*"); bean.addUrlPatterns("/*");
return bean; return bean;
} }
@Bean
public FilterRegistrationBean filterRegistrationBean2(){
FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new StringFilter());
bean.addUrlPatterns("/*");
return bean;
}
} }
package com.gic.enterprise.filter;
import com.gic.enterprise.request.ParameterRequestWrapper;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author zhiwj
* @Description:
* @date 2020-05-12 16:49
*/
public class StringFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
ParameterRequestWrapper requestWrapper = new ParameterRequestWrapper(httpServletRequest);
filterChain.doFilter(requestWrapper, httpServletResponse);
}
}
package com.gic.enterprise.request;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* @author zhiwj
* @Description:
* @date 2020-05-12 16:39
*/
public class ParameterRequestWrapper extends HttpServletRequestWrapper {
private Map<String , String[]> params = new HashMap<>();
@SuppressWarnings("unchecked")
public ParameterRequestWrapper(HttpServletRequest request) {
// 将request交给父类,以便于调用对应方法的时候,将其输出,其实父亲类的实现方式和第一种new的方式类似
super(request);
//将参数表,赋予给当前的Map以便于持有request中的参数
this.params.putAll(request.getParameterMap());
this.modifyParameterValues();
}
//重载一个构造方法
public ParameterRequestWrapper(HttpServletRequest request , Map<String , Object> extendParams) {
this(request);
addAllParameters(extendParams);//这里将扩展参数写入参数表
}
public void modifyParameterValues(){//将parameter的值去除空格后重写回去
Set<String> set =params.keySet();
Iterator<String> it=set.iterator();
while(it.hasNext()){
String key= it.next();
String[] values = params.get(key);
values[0] = values[0].trim();
params.put(key, values);
}
}
@Override
public String getParameter(String name) {//重写getParameter,代表参数从当前类中的map获取
String[]values = params.get(name);
if(values == null || values.length == 0) {
return null;
}
return values[0];
}
@Override
public String[] getParameterValues(String name) {//同上
return params.get(name);
}
public void addAllParameters(Map<String , Object>otherParams) {//增加多个参数
for(Map.Entry<String , Object>entry : otherParams.entrySet()) {
addParameter(entry.getKey() , entry.getValue());
}
}
public void addParameter(String name , Object value) {//增加参数
if(value != null) {
if(value instanceof String[]) {
params.put(name , (String[])value);
}else if(value instanceof String) {
params.put(name , new String[] {(String)value});
}else {
params.put(name , new String[] {String.valueOf(value)});
}
}
}
}
\ No newline at end of file
package com.gic.download.utils; package com.gic.download.utils;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.gic.download.constants.ExcelExtensionEnum; import com.gic.download.constants.ExcelExtensionEnum;
import com.gic.download.dto.DownloadReportTempDTO; import com.gic.download.dto.DownloadReportTempDTO;
import com.gic.download.qo.DownloadExcelQO; import com.gic.download.qo.DownloadExcelQO;
...@@ -26,6 +21,14 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; ...@@ -26,6 +21,14 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
public class DownloadUtils { public class DownloadUtils {
private static final Logger LOGGER = LogManager.getLogger(DownloadUtils.class); private static final Logger LOGGER = LogManager.getLogger(DownloadUtils.class);
...@@ -211,7 +214,7 @@ public class DownloadUtils { ...@@ -211,7 +214,7 @@ public class DownloadUtils {
} }
private <T> void downloadCommon(DownloadExcelQO param, DownloadDataLoader<T> loader) throws Exception { private <T> void downloadCommon(DownloadExcelQO param, DownloadDataLoader<T> loader) throws Exception {
LOGGER.info("下载导出数据参数:{}", JSON.toJSONString(param)); LOGGER.info("下载导出数据参数:{}", JSON.toJSONString(param, SerializerFeature.WriteMapNullValue));
Integer reportId = param.getReportId(); Integer reportId = param.getReportId();
String fileName = param.getFileName(); String fileName = param.getFileName();
...@@ -319,7 +322,7 @@ public class DownloadUtils { ...@@ -319,7 +322,7 @@ public class DownloadUtils {
out.flush(); out.flush();
tempFile.deleteOnExit(); tempFile.deleteOnExit();
//上传文件 //上传文件
SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMddHHmmss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String fieldCode = "/" + fileName + "_" + sdf.format(new Date()) + ExcelExtensionEnum.getExtensionByCode(excelExtensionCode); String fieldCode = "/" + fileName + "_" + sdf.format(new Date()) + ExcelExtensionEnum.getExtensionByCode(excelExtensionCode);
LOGGER.info("上传文件到腾讯云,文件名:" + fieldCode); LOGGER.info("上传文件到腾讯云,文件名:" + fieldCode);
//文件存进腾讯云 //文件存进腾讯云
......
...@@ -7,6 +7,7 @@ import java.util.*; ...@@ -7,6 +7,7 @@ import java.util.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import com.gic.download.qo.HeaderQO; import com.gic.download.qo.HeaderQO;
import org.apache.commons.beanutils.BeanMap; import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -213,6 +214,7 @@ public class ExcelUtils { ...@@ -213,6 +214,7 @@ public class ExcelUtils {
String value = entry.getKey(); String value = entry.getKey();
cell1.setCellValue(value); cell1.setCellValue(value);
cell1.setCellStyle(cellStyle); cell1.setCellStyle(cellStyle);
//2层标题 //2层标题
if (CollectionUtils.isEmpty(sonHeader)) { if (CollectionUtils.isEmpty(sonHeader)) {
//单标题 //单标题
...@@ -222,8 +224,11 @@ public class ExcelUtils { ...@@ -222,8 +224,11 @@ public class ExcelUtils {
n++; n++;
continue; continue;
} }
//创建第一行大标题 if (sonHeader.size() != 1) {
sheet.addMergedRegion(new CellRangeAddress(0, 0, n, (n + sonHeader.size() - 1))); //一个单元格,合并操作会报错
//创建第一行大标题
sheet.addMergedRegion(new CellRangeAddress(0, 0, n, (n + sonHeader.size() - 1)));
}
//赋值 //赋值
for (int j = 0, sonLength = sonHeader.size(); j < sonLength; j ++) { for (int j = 0, sonLength = sonHeader.size(); j < sonLength; j ++) {
Cell cell2 = row2.createCell(n++); Cell cell2 = row2.createCell(n++);
......
...@@ -211,7 +211,7 @@ public abstract class QrcodeDownload { ...@@ -211,7 +211,7 @@ public abstract class QrcodeDownload {
imageByte = addLogo_QRCode(bim, getPicByte(logoPic), logoName, format); imageByte = addLogo_QRCode(bim, getPicByte(logoPic), logoName, format);
return imageByte; return imageByte;
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error("创建二维码失败", e);
return imageByte; return imageByte;
} }
} }
......
...@@ -35,6 +35,40 @@ public class LogUtils { ...@@ -35,6 +35,40 @@ public class LogUtils {
* @return void
 * @return void


 */ 
 */
public static void createLog(String content, String operationObject) { public static void createLog(String content, String operationObject) {
doLog(content, operationObject, null, null);
}
/**
* 添加日志。需要填写的字段参考 createLog重载的接口
* @Title: createLogOfNoLogin

* @Description:

* @author guojuxing
* @param logDTO

* @return void


*/
public static void createLogOfNoLogin(final SystemSetLogDTO logDTO) {
ExecutorPoolSingleton.getInstance().executeTask(new Runnable() {
@Override
public void run() {
LOGGER.info("添加日志了,恭喜发财。{}", JSON.toJSONString(logDTO));
logApiService.saveSystemSetLog(logDTO);
}
});
}
/**
* 添加日志
* @param content 操作内容
* @param operationObject 操作对象
* @param relationId 菜单ID
* @param projectName 菜单名称
*/
public static void createLogForApp(String content, String operationObject, Integer relationId, String projectName) {
doLog(content, operationObject, relationId, projectName);
}
private static void doLog(String content, String operationObject, Integer relationId, String projectName) {
UserDetail userDetail = UserDetailUtils.getUserDetail(); UserDetail userDetail = UserDetailUtils.getUserDetail();
final SystemSetLogDTO logDTO = new SystemSetLogDTO(); final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间 //操作时间
...@@ -50,13 +84,18 @@ public class LogUtils { ...@@ -50,13 +84,18 @@ public class LogUtils {
////操作对象 ////操作对象
logDTO.setBusinessName(operationObject); logDTO.setBusinessName(operationObject);
//操作模块 //操作模块
String moduleMenuName = (String) RequestContext.getContext().getRequest().getAttribute("moduleMenuName"); if (relationId != null) {
Integer moduleMenuId = (Integer) RequestContext.getContext().getRequest().getAttribute("moduleMenuId"); logDTO.setRelationId(Long.valueOf(relationId));
if (moduleMenuId != null) { logDTO.setProject(projectName);
logDTO.setRelationId(Long.valueOf(moduleMenuId));
logDTO.setProject(moduleMenuName);
} else { } else {
LOGGER.info("操作模块数据有误"); String moduleMenuName = (String) RequestContext.getContext().getRequest().getAttribute("moduleMenuName");
Integer moduleMenuId = (Integer) RequestContext.getContext().getRequest().getAttribute("moduleMenuId");
if (moduleMenuId != null) {
logDTO.setRelationId(Long.valueOf(moduleMenuId));
logDTO.setProject(moduleMenuName);
} else {
LOGGER.info("操作模块数据有误");
}
} }
//账号(手机号) //账号(手机号)
logDTO.setRemark1(userDetail.getUserInfo().getPhoneAreaCode()); logDTO.setRemark1(userDetail.getUserInfo().getPhoneAreaCode());
...@@ -78,10 +117,12 @@ public class LogUtils { ...@@ -78,10 +117,12 @@ public class LogUtils {
* @Description: * @Description:

 * @author guojuxing 
 * @author guojuxing
* @param content 操作内容 * @param content 操作内容
* @param operationObject
 操作对象 * @param operationObject 
 操作对象
* @param s
* @param auditorPhone
* @return void
 * @return void


 */ 
 */
public static void createLog(String content, String operationObject, String username, Integer enterpriseId, String enterpriseName) { public static void createLog(String content, String operationObject, String username, Integer enterpriseId, String enterpriseName, String phoneAreaCode, String auditorPhone) {
UserDetail userDetail = UserDetailUtils.getUserDetail(); UserDetail userDetail = UserDetailUtils.getUserDetail();
final SystemSetLogDTO logDTO = new SystemSetLogDTO(); final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间 //操作时间
...@@ -94,6 +135,10 @@ public class LogUtils { ...@@ -94,6 +135,10 @@ public class LogUtils {
logDTO.setContent(content); logDTO.setContent(content);
// //
logDTO.setBusinessName(operationObject); logDTO.setBusinessName(operationObject);
//账号(手机号)
logDTO.setRemark1(userDetail.getUserInfo().getPhoneAreaCode());
logDTO.setRemark2(userDetail.getUserInfo().getPhoneNumber());
//操作模块 //操作模块
// String moduleMenuName = (String) RequestContext.getContext().getRequest().getAttribute("moduleMenuName"); // String moduleMenuName = (String) RequestContext.getContext().getRequest().getAttribute("moduleMenuName");
// Integer moduleMenuId = (Integer) RequestContext.getContext().getRequest().getAttribute("moduleMenuId"); // Integer moduleMenuId = (Integer) RequestContext.getContext().getRequest().getAttribute("moduleMenuId");
......
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