Skip to content

Commit

Permalink
remove useless reference and modify log print type about core (linlin…
Browse files Browse the repository at this point in the history
  • Loading branch information
SoberChina authored and linlinjava committed Jun 26, 2019
1 parent b5d61aa commit 4fec87a
Show file tree
Hide file tree
Showing 28 changed files with 334 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class CorsConfig {
// 当前跨域请求最大有效时长。这里默认30天
private long maxAge = 30 * 24 * 60 * 60;

private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.linlinjava.litemall.core.config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.internal.engine.path.PathImpl;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MissingServletRequestParameterException;
Expand All @@ -17,41 +18,43 @@
import java.util.Set;

@ControllerAdvice
@Order( value = Ordered.LOWEST_PRECEDENCE )
@Order
public class GlobalExceptionHandler {

private Log logger = LogFactory.getLog(GlobalExceptionHandler.class);

@ExceptionHandler(IllegalArgumentException.class)
@ResponseBody
public Object badArgumentHandler(IllegalArgumentException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue();
}

@ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseBody
public Object badArgumentHandler(MethodArgumentTypeMismatchException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue();
}

@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseBody
public Object badArgumentHandler(MissingServletRequestParameterException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue();
}

@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseBody
public Object badArgumentHandler(HttpMessageNotReadableException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue();
}

@ExceptionHandler(ValidationException.class)
@ResponseBody
public Object badArgumentHandler(ValidationException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
if (e instanceof ConstraintViolationException) {
ConstraintViolationException exs = (ConstraintViolationException) e;
Set<ConstraintViolation<?>> violations = exs.getConstraintViolations();
Expand All @@ -66,7 +69,7 @@ public Object badArgumentHandler(ValidationException e) {
@ExceptionHandler(Exception.class)
@ResponseBody
public Object seriousHandler(Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.serious();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ public Jackson2ObjectMapperBuilderCustomizer customJackson() {
return new Jackson2ObjectMapperBuilderCustomizer() {
@Override
public void customize(Jackson2ObjectMapperBuilder builder) {
builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.serializerByType(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.serializerByType(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));

builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.deserializerByType(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.deserializerByType(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
builder.serializerByType(LocalDateTime.class,
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.serializerByType(LocalDate.class,
new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.serializerByType(LocalTime.class,
new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
builder.deserializerByType(LocalDateTime.class,
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.deserializerByType(LocalDate.class,
new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.deserializerByType(LocalTime.class,
new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
builder.serializationInclusion(JsonInclude.Include.NON_NULL);
builder.failOnUnknownProperties(false);
builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.linlinjava.litemall.core.express;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.express.config.ExpressProperties;
import org.linlinjava.litemall.core.express.dao.ExpressInfo;
import org.linlinjava.litemall.core.util.HttpUtil;
Expand All @@ -13,10 +15,12 @@

/**
* 物流查询服务
*
* <p>
* 快递鸟即时查询API http://www.kdniao.com/api-track
*/
public class ExpressService {

private final Log logger = LogFactory.getLog(ExpressService.class);
//请求url
private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";

Expand Down Expand Up @@ -59,7 +63,7 @@ public ExpressInfo getExpressInfo(String expCode, String expNo) {
ei.setShipperName(getVendorName(expCode));
return ei;
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}

return null;
Expand Down Expand Up @@ -103,7 +107,7 @@ private String MD5(String str, String charset) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes(charset));
byte[] result = md.digest();
StringBuffer sb = new StringBuffer(32);
StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < result.length; i++) {
int val = result[i] & 0xff;
if (val <= 0xf) {
Expand All @@ -126,12 +130,12 @@ private String encrypt(String content, String keyValue, String charset) {
if (keyValue != null) {
content = content + keyValue;
}
byte[] src = new byte[0];
byte[] src;
try {
src = MD5(content, charset).getBytes(charset);
return Base64Utils.encodeToString(src);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SmsResult send(String phone, String content) {
smsResult.setResult(result);
return smsResult;
} catch (HTTPException | IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}

return null;
Expand All @@ -52,7 +52,7 @@ public SmsResult sendWithTemplate(String phone, int templateId, String[] params)
smsResult.setResult(result);
return smsResult;
} catch (HTTPException | IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void sendWechatMsg(String touser, String templatId, String[] parms, Strin
sendMsg(touser, templatId, parms, page, "", "");
}

private void sendMsg(String touser, String templatId, String[] parms, String page, String color, String emphasisKeyword) {
private void sendMsg(String touser, String templatId, String[] parms, String page, String color,
String emphasisKeyword) {
LitemallUserFormid userFormid = formIdService.queryByOpenId(touser);
if (userFormid == null)
return;
Expand All @@ -68,7 +69,7 @@ private void sendMsg(String touser, String templatId, String[] parms, String pag
logger.warn("更新数据已失效");
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import cn.binarywang.wx.miniapp.api.WxMaService;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.storage.StorageService;
import org.linlinjava.litemall.core.system.SystemConfig;
import org.linlinjava.litemall.db.domain.LitemallGroupon;
Expand All @@ -18,6 +20,7 @@

@Service
public class QCodeService {
private final Log logger = LogFactory.getLog(QCodeService.class);
@Autowired
WxMaService wxMaService;

Expand All @@ -28,21 +31,23 @@ public class QCodeService {
public String createGrouponShareImage(String goodName, String goodPicUrl, LitemallGroupon groupon) {
try {
//创建该商品的二维码
File file = wxMaService.getQrcodeService().createWxaCodeUnlimit("groupon," + groupon.getId(), "pages/index/index");
File file = wxMaService.getQrcodeService().createWxaCodeUnlimit("groupon," + groupon.getId(), "pages" +
"/index/index");
FileInputStream inputStream = new FileInputStream(file);
//将商品图片,商品名字,商城名字画到模版图中
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData);
//存储分享图
LitemallStorage storageInfo = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(groupon.getId().toString()));
LitemallStorage storageInfo = storageService.store(inputStream2, imageData.length, "image/jpeg",
getKeyName(groupon.getId().toString()));

return storageInfo.getUrl();
} catch (WxErrorException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}

return "";
Expand All @@ -68,15 +73,16 @@ public String createGoodShareImage(String goodId, String goodPicUrl, String good
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData);
//存储分享图
LitemallStorage litemallStorage = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(goodId));
LitemallStorage litemallStorage = storageService.store(inputStream2, imageData.length, "image/jpeg",
getKeyName(goodId));

return litemallStorage.getUrl();
} catch (WxErrorException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}

return "";
Expand Down Expand Up @@ -126,7 +132,7 @@ private byte[] drawPicture(InputStream qrCodeImg, String goodPicUrl, String good
drawTextInImg(baseImage, goodName, 65, 867);

//写上商城名称
// drawTextInImgCenter(baseImage, shopName, 98);
// drawTextInImgCenter(baseImage, shopName, 98);


//转jpg
Expand Down Expand Up @@ -173,7 +179,8 @@ private void drawTextInImg(BufferedImage baseImage, String textToWrite, int x, i
g2D.dispose();
}

private void drawImgInImg(BufferedImage baseImage, BufferedImage imageToWrite, int x, int y, int width, int heigth) {
private void drawImgInImg(BufferedImage baseImage, BufferedImage imageToWrite, int x, int y, int width,
int heigth) {
Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
g2D.drawImage(imageToWrite, x, y, width, heigth, null);
g2D.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;

Expand All @@ -20,6 +22,8 @@
*/
public class AliyunStorage implements Storage {

private final Log logger = LogFactory.getLog(AliyunStorage.class);

private String endpoint;
private String accessKeyId;
private String accessKeySecret;
Expand Down Expand Up @@ -84,7 +88,7 @@ public void store(InputStream inputStream, long contentLength, String contentTyp
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata);
PutObjectResult putObjectResult = getOSSClient().putObject(putObjectRequest);
} catch (Exception ex) {
ex.printStackTrace();
logger.error(ex.getMessage(), ex);
}

}
Expand All @@ -110,7 +114,7 @@ public Resource loadAsResource(String keyName) {
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return null;
}
}
Expand All @@ -120,7 +124,7 @@ public void delete(String keyName) {
try {
getOSSClient().deleteObject(bucketName, keyName);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.linlinjava.litemall.core.storage;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;

Expand All @@ -18,6 +20,9 @@
*/
public class LocalStorage implements Storage {


private final Log logger = LogFactory.getLog(LocalStorage.class);

private String storagePath;
private String address;

Expand All @@ -34,7 +39,7 @@ public void setStoragePath(String storagePath) {
try {
Files.createDirectories(rootLocation);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}

Expand Down Expand Up @@ -83,7 +88,7 @@ public Resource loadAsResource(String filename) {
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return null;
}
}
Expand All @@ -94,13 +99,13 @@ public void delete(String filename) {
try {
Files.delete(file);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}

@Override
public String generateUrl(String keyName) {
String url = address + keyName;
return url;

return address + keyName;
}
}
Loading

0 comments on commit 4fec87a

Please sign in to comment.