Unverified Commit 324c8da3 authored by linlinjava's avatar linlinjava Committed by GitHub
Browse files

Merge branch 'master' into dev

parents 693cf5cd 4c46da9b
...@@ -15,6 +15,7 @@ public class TencentSmsSender implements SmsSender { ...@@ -15,6 +15,7 @@ public class TencentSmsSender implements SmsSender {
private final Log logger = LogFactory.getLog(TencentSmsSender.class); private final Log logger = LogFactory.getLog(TencentSmsSender.class);
private SmsSingleSender sender; private SmsSingleSender sender;
private String sign;
public SmsSingleSender getSender() { public SmsSingleSender getSender() {
return sender; return sender;
...@@ -35,16 +36,18 @@ public class TencentSmsSender implements SmsSender { ...@@ -35,16 +36,18 @@ public class TencentSmsSender implements SmsSender {
smsResult.setResult(result); smsResult.setResult(result);
return smsResult; return smsResult;
} catch (HTTPException | IOException e) { } catch (HTTPException | IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; SmsResult smsResult = new SmsResult();
smsResult.setSuccessful(false);
return smsResult;
} }
@Override @Override
public SmsResult sendWithTemplate(String phone, int templateId, String[] params) { public SmsResult sendWithTemplate(String phone, String templateId, String[] params) {
try { try {
SmsSingleSenderResult result = sender.sendWithParam("86", phone, templateId, params, "", "", ""); SmsSingleSenderResult result = sender.sendWithParam("86", phone, Integer.parseInt(templateId), params, this.sign, "", "");
logger.debug(result); logger.debug(result);
SmsResult smsResult = new SmsResult(); SmsResult smsResult = new SmsResult();
...@@ -52,9 +55,15 @@ public class TencentSmsSender implements SmsSender { ...@@ -52,9 +55,15 @@ public class TencentSmsSender implements SmsSender {
smsResult.setResult(result); smsResult.setResult(result);
return smsResult; return smsResult;
} catch (HTTPException | IOException e) { } catch (HTTPException | IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; SmsResult smsResult = new SmsResult();
smsResult.setSuccessful(false);
return smsResult;
}
public void setSign(String sign) {
this.sign = sign;
} }
} }
...@@ -47,7 +47,8 @@ public class WxTemplateSender { ...@@ -47,7 +47,8 @@ public class WxTemplateSender {
sendMsg(touser, templatId, parms, page, "", ""); 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); LitemallUserFormid userFormid = formIdService.queryByOpenId(touser);
if (userFormid == null) if (userFormid == null)
return; return;
...@@ -68,7 +69,7 @@ public class WxTemplateSender { ...@@ -68,7 +69,7 @@ public class WxTemplateSender {
logger.warn("更新数据已失效"); logger.warn("更新数据已失效");
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
......
package org.linlinjava.litemall.core.notify.config; package org.linlinjava.litemall.core.notify.config;
import com.github.qcloudsms.SmsSingleSender; import com.github.qcloudsms.SmsSingleSender;
import org.linlinjava.litemall.core.notify.AliyunSmsSender;
import org.linlinjava.litemall.core.notify.NotifyService; import org.linlinjava.litemall.core.notify.NotifyService;
import org.linlinjava.litemall.core.notify.TencentSmsSender; import org.linlinjava.litemall.core.notify.TencentSmsSender;
import org.linlinjava.litemall.core.notify.WxTemplateSender; import org.linlinjava.litemall.core.notify.WxTemplateSender;
...@@ -10,6 +11,8 @@ import org.springframework.context.annotation.Configuration; ...@@ -10,6 +11,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;
@Configuration @Configuration
@EnableConfigurationProperties(NotifyProperties.class) @EnableConfigurationProperties(NotifyProperties.class)
public class NotifyAutoConfiguration { public class NotifyAutoConfiguration {
...@@ -33,7 +36,13 @@ public class NotifyAutoConfiguration { ...@@ -33,7 +36,13 @@ public class NotifyAutoConfiguration {
NotifyProperties.Sms smsConfig = properties.getSms(); NotifyProperties.Sms smsConfig = properties.getSms();
if (smsConfig.isEnable()) { if (smsConfig.isEnable()) {
notifyService.setSmsSender(tencentSmsSender()); if(smsConfig.getActive().equals("tencent")) {
notifyService.setSmsSender(tencentSmsSender());
}
else if(smsConfig.getActive().equals("aliyun")) {
notifyService.setSmsSender(aliyunSmsSender());
}
notifyService.setSmsTemplate(smsConfig.getTemplate()); notifyService.setSmsTemplate(smsConfig.getTemplate());
} }
...@@ -52,6 +61,17 @@ public class NotifyAutoConfiguration { ...@@ -52,6 +61,17 @@ public class NotifyAutoConfiguration {
mailSender.setHost(mailConfig.getHost()); mailSender.setHost(mailConfig.getHost());
mailSender.setUsername(mailConfig.getUsername()); mailSender.setUsername(mailConfig.getUsername());
mailSender.setPassword(mailConfig.getPassword()); mailSender.setPassword(mailConfig.getPassword());
mailSender.setPort(mailConfig.getPort());
Properties properties = new Properties();
properties.put("mail.smtp.auth",true);
properties.put("mail.smtp.timeout",5000);
properties.put("mail.smtp.starttls.enable",true);
properties.put("mail.smtp.socketFactory.fallback", "false");
//阿里云 必须加入配置 outlook配置又不需要 视情况而定.发送不成功多数是这里的配置问题
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.socketFactory.port", mailConfig.getPort());
properties.put("debug", true);
mailSender.setJavaMailProperties(properties);
return mailSender; return mailSender;
} }
...@@ -65,7 +85,21 @@ public class NotifyAutoConfiguration { ...@@ -65,7 +85,21 @@ public class NotifyAutoConfiguration {
public TencentSmsSender tencentSmsSender() { public TencentSmsSender tencentSmsSender() {
NotifyProperties.Sms smsConfig = properties.getSms(); NotifyProperties.Sms smsConfig = properties.getSms();
TencentSmsSender smsSender = new TencentSmsSender(); TencentSmsSender smsSender = new TencentSmsSender();
smsSender.setSender(new SmsSingleSender(smsConfig.getAppid(), smsConfig.getAppkey())); NotifyProperties.Sms.Tencent tencent = smsConfig.getTencent();
smsSender.setSender(new SmsSingleSender(tencent.getAppid(), tencent.getAppkey()));
smsSender.setSign(smsConfig.getSign());
return smsSender;
}
@Bean
public AliyunSmsSender aliyunSmsSender() {
NotifyProperties.Sms smsConfig = properties.getSms();
AliyunSmsSender smsSender = new AliyunSmsSender();
NotifyProperties.Sms.Aliyun aliyun = smsConfig.getAliyun();
smsSender.setSign(smsConfig.getSign());
smsSender.setRegionId(aliyun.getRegionId());
smsSender.setAccessKeyId(aliyun.getAccessKeyId());
smsSender.setAccessKeySecret(aliyun.getAccessKeySecret());
return smsSender; return smsSender;
} }
} }
...@@ -43,7 +43,7 @@ public class NotifyProperties { ...@@ -43,7 +43,7 @@ public class NotifyProperties {
private String password; private String password;
private String sendfrom; private String sendfrom;
private String sendto; private String sendto;
private Integer port;
public boolean isEnable() { public boolean isEnable() {
return enable; return enable;
} }
...@@ -91,12 +91,22 @@ public class NotifyProperties { ...@@ -91,12 +91,22 @@ public class NotifyProperties {
public void setSendto(String sendto) { public void setSendto(String sendto) {
this.sendto = sendto; this.sendto = sendto;
} }
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
} }
public static class Sms { public static class Sms {
private boolean enable; private boolean enable;
private int appid; private String active;
private String appkey; private String sign;
private Tencent tencent;
private Aliyun aliyun;
private List<Map<String, String>> template = new ArrayList<>(); private List<Map<String, String>> template = new ArrayList<>();
public boolean isEnable() { public boolean isEnable() {
...@@ -107,28 +117,95 @@ public class NotifyProperties { ...@@ -107,28 +117,95 @@ public class NotifyProperties {
this.enable = enable; this.enable = enable;
} }
public int getAppid() { public List<Map<String, String>> getTemplate() {
return appid; return template;
}
public void setTemplate(List<Map<String, String>> template) {
this.template = template;
} }
public void setAppid(int appid) { public String getActive() {
this.appid = appid; return active;
} }
public String getAppkey() { public void setActive(String active) {
return appkey; this.active = active;
} }
public void setAppkey(String appkey) { public String getSign() {
this.appkey = appkey; return sign;
} }
public List<Map<String, String>> getTemplate() { public void setSign(String sign) {
return template; this.sign = sign;
} }
public void setTemplate(List<Map<String, String>> template) { public Tencent getTencent() {
this.template = template; return tencent;
}
public void setTencent(Tencent tencent) {
this.tencent = tencent;
}
public Aliyun getAliyun() {
return aliyun;
}
public void setAliyun(Aliyun aliyun) {
this.aliyun = aliyun;
}
public static class Tencent {
private int appid;
private String appkey;
public int getAppid() {
return appid;
}
public void setAppid(int appid) {
this.appid = appid;
}
public String getAppkey() {
return appkey;
}
public void setAppkey(String appkey) {
this.appkey = appkey;
}
}
public static class Aliyun {
private String regionId;
private String accessKeyId;
private String accessKeySecret;
public String getRegionId() {
return regionId;
}
public void setRegionId(String regionId) {
this.regionId = regionId;
}
public String getAccessKeyId() {
return accessKeyId;
}
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
}
public String getAccessKeySecret() {
return accessKeySecret;
}
public void setAccessKeySecret(String accessKeySecret) {
this.accessKeySecret = accessKeySecret;
}
} }
} }
......
...@@ -2,6 +2,8 @@ package org.linlinjava.litemall.core.qcode; ...@@ -2,6 +2,8 @@ package org.linlinjava.litemall.core.qcode;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import me.chanjar.weixin.common.error.WxErrorException; 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.storage.StorageService;
import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.system.SystemConfig;
import org.linlinjava.litemall.db.domain.LitemallGroupon; import org.linlinjava.litemall.db.domain.LitemallGroupon;
...@@ -18,6 +20,7 @@ import java.net.URL; ...@@ -18,6 +20,7 @@ import java.net.URL;
@Service @Service
public class QCodeService { public class QCodeService {
private final Log logger = LogFactory.getLog(QCodeService.class);
@Autowired @Autowired
WxMaService wxMaService; WxMaService wxMaService;
...@@ -28,21 +31,23 @@ public class QCodeService { ...@@ -28,21 +31,23 @@ public class QCodeService {
public String createGrouponShareImage(String goodName, String goodPicUrl, LitemallGroupon groupon) { public String createGrouponShareImage(String goodName, String goodPicUrl, LitemallGroupon groupon) {
try { 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); FileInputStream inputStream = new FileInputStream(file);
//将商品图片,商品名字,商城名字画到模版图中 //将商品图片,商品名字,商城名字画到模版图中
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); 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(); return storageInfo.getUrl();
} catch (WxErrorException e) { } catch (WxErrorException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return ""; return "";
...@@ -68,15 +73,16 @@ public class QCodeService { ...@@ -68,15 +73,16 @@ public class QCodeService {
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); 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(); return litemallStorage.getUrl();
} catch (WxErrorException e) { } catch (WxErrorException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return ""; return "";
...@@ -126,7 +132,7 @@ public class QCodeService { ...@@ -126,7 +132,7 @@ public class QCodeService {
drawTextInImg(baseImage, goodName, 65, 867); drawTextInImg(baseImage, goodName, 65, 867);
//写上商城名称 //写上商城名称
// drawTextInImgCenter(baseImage, shopName, 98); // drawTextInImgCenter(baseImage, shopName, 98);
//转jpg //转jpg
...@@ -173,7 +179,8 @@ public class QCodeService { ...@@ -173,7 +179,8 @@ public class QCodeService {
g2D.dispose(); 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(); Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
g2D.drawImage(imageToWrite, x, y, width, heigth, null); g2D.drawImage(imageToWrite, x, y, width, heigth, null);
g2D.dispose(); g2D.dispose();
......
...@@ -4,6 +4,8 @@ import com.aliyun.oss.OSSClient; ...@@ -4,6 +4,8 @@ import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata; import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult; 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.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -20,6 +22,8 @@ import java.util.stream.Stream; ...@@ -20,6 +22,8 @@ import java.util.stream.Stream;
*/ */
public class AliyunStorage implements Storage { public class AliyunStorage implements Storage {
private final Log logger = LogFactory.getLog(AliyunStorage.class);
private String endpoint; private String endpoint;
private String accessKeyId; private String accessKeyId;
private String accessKeySecret; private String accessKeySecret;
...@@ -84,7 +88,7 @@ public class AliyunStorage implements Storage { ...@@ -84,7 +88,7 @@ public class AliyunStorage implements Storage {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata); PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata);
PutObjectResult putObjectResult = getOSSClient().putObject(putObjectRequest); PutObjectResult putObjectResult = getOSSClient().putObject(putObjectRequest);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
} }
...@@ -110,7 +114,7 @@ public class AliyunStorage implements Storage { ...@@ -110,7 +114,7 @@ public class AliyunStorage implements Storage {
return null; return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }
...@@ -120,7 +124,7 @@ public class AliyunStorage implements Storage { ...@@ -120,7 +124,7 @@ public class AliyunStorage implements Storage {
try { try {
getOSSClient().deleteObject(bucketName, keyName); getOSSClient().deleteObject(bucketName, keyName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
......
package org.linlinjava.litemall.core.storage; 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.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -18,6 +20,9 @@ import java.util.stream.Stream; ...@@ -18,6 +20,9 @@ import java.util.stream.Stream;
*/ */
public class LocalStorage implements Storage { public class LocalStorage implements Storage {
private final Log logger = LogFactory.getLog(LocalStorage.class);
private String storagePath; private String storagePath;
private String address; private String address;
...@@ -34,7 +39,7 @@ public class LocalStorage implements Storage { ...@@ -34,7 +39,7 @@ public class LocalStorage implements Storage {
try { try {
Files.createDirectories(rootLocation); Files.createDirectories(rootLocation);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
...@@ -83,7 +88,7 @@ public class LocalStorage implements Storage { ...@@ -83,7 +88,7 @@ public class LocalStorage implements Storage {
return null; return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }
...@@ -94,13 +99,13 @@ public class LocalStorage implements Storage { ...@@ -94,13 +99,13 @@ public class LocalStorage implements Storage {
try { try {
Files.delete(file); Files.delete(file);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
@Override @Override
public String generateUrl(String keyName) { public String generateUrl(String keyName) {
String url = address + keyName;
return url; return address + keyName;
} }
} }
\ No newline at end of file
package org.linlinjava.litemall.core.storage; package org.linlinjava.litemall.core.storage;
import com.qiniu.common.QiniuException; import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager; import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration; import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager; import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth; import com.qiniu.util.Auth;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -17,6 +18,8 @@ import java.util.stream.Stream; ...@@ -17,6 +18,8 @@ import java.util.stream.Stream;
public class QiniuStorage implements Storage { public class QiniuStorage implements Storage {
private final Log logger = LogFactory.getLog(QiniuStorage.class);
private String endpoint; private String endpoint;
private String accessKey; private String accessKey;
private String secretKey; private String secretKey;
...@@ -71,9 +74,9 @@ public class QiniuStorage implements Storage { ...@@ -71,9 +74,9 @@ public class QiniuStorage implements Storage {
try { try {
String upToken = auth.uploadToken(bucketName); String upToken = auth.uploadToken(bucketName);
Response response = uploadManager.put(inputStream, keyName, upToken, null, contentType); uploadManager.put(inputStream, keyName, upToken, null, contentType);
} catch (QiniuException ex) { } catch (QiniuException ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
} }
...@@ -94,13 +97,11 @@ public class QiniuStorage implements Storage { ...@@ -94,13 +97,11 @@ public class QiniuStorage implements Storage {
Resource resource = new UrlResource(url); Resource resource = new UrlResource(url);
if (resource.exists() || resource.isReadable()) { if (resource.exists() || resource.isReadable()) {
return resource; return resource;
} else {
return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null;
} }
return null;
} }
@Override @Override
...@@ -111,11 +112,10 @@ public class QiniuStorage implements Storage { ...@@ -111,11 +112,10 @@ public class QiniuStorage implements Storage {
} }
bucketManager = new BucketManager(auth, new Configuration()); bucketManager = new BucketManager(auth, new Configuration());
} }
try { try {
bucketManager.delete(bucketName, keyName); bucketManager.delete(bucketName, keyName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
......
...@@ -6,8 +6,9 @@ import com.qcloud.cos.auth.BasicCOSCredentials; ...@@ -6,8 +6,9 @@ import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials; import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.model.ObjectMetadata; import com.qcloud.cos.model.ObjectMetadata;
import com.qcloud.cos.model.PutObjectRequest; import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region; import com.qcloud.cos.region.Region;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -22,6 +23,8 @@ import java.util.stream.Stream; ...@@ -22,6 +23,8 @@ import java.util.stream.Stream;
*/ */
public class TencentStorage implements Storage { public class TencentStorage implements Storage {
private final Log logger = LogFactory.getLog(TencentStorage.class);
private String secretId; private String secretId;
private String secretKey; private String secretKey;
private String region; private String region;
...@@ -74,7 +77,7 @@ public class TencentStorage implements Storage { ...@@ -74,7 +77,7 @@ public class TencentStorage implements Storage {
} }
private String getBaseUrl() { private String getBaseUrl() {
return "https://" + bucketName + ".cos-website." + region + ".myqcloud.com/"; return "https://" + bucketName + ".cos." + region + ".myqcloud.com/";
} }
@Override @Override
...@@ -84,11 +87,12 @@ public class TencentStorage implements Storage { ...@@ -84,11 +87,12 @@ public class TencentStorage implements Storage {
ObjectMetadata objectMetadata = new ObjectMetadata(); ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(contentLength); objectMetadata.setContentLength(contentLength);
objectMetadata.setContentType(contentType); objectMetadata.setContentType(contentType);
// 对象键(Key)是对象在存储桶中的唯一标识。例如,在对象的访问域名 `bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg` 中,对象键为 doc1/pic1.jpg, 详情参考 [对象键](https://cloud.tencent.com/document/product/436/13324) // 对象键(Key)是对象在存储桶中的唯一标识。例如,在对象的访问域名 `bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg`
// 中,对象键为 doc1/pic1.jpg, 详情参考 [对象键](https://cloud.tencent.com/document/product/436/13324)
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata); PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata);
PutObjectResult putObjectResult = getCOSClient().putObject(putObjectRequest); getCOSClient().putObject(putObjectRequest);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
} }
...@@ -109,13 +113,11 @@ public class TencentStorage implements Storage { ...@@ -109,13 +113,11 @@ public class TencentStorage implements Storage {
Resource resource = new UrlResource(url); Resource resource = new UrlResource(url);
if (resource.exists() || resource.isReadable()) { if (resource.exists() || resource.isReadable()) {
return resource; return resource;
} else {
return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null;
} }
return null;
} }
@Override @Override
...@@ -123,7 +125,7 @@ public class TencentStorage implements Storage { ...@@ -123,7 +125,7 @@ public class TencentStorage implements Storage {
try { try {
getCOSClient().deleteObject(bucketName, keyName); getCOSClient().deleteObject(bucketName, keyName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
......
...@@ -28,6 +28,8 @@ public class SystemConfig { ...@@ -28,6 +28,8 @@ public class SystemConfig {
public final static String LITEMALL_MALL_ADDRESS = "litemall_mall_address"; public final static String LITEMALL_MALL_ADDRESS = "litemall_mall_address";
public final static String LITEMALL_MALL_PHONE = "litemall_mall_phone"; public final static String LITEMALL_MALL_PHONE = "litemall_mall_phone";
public final static String LITEMALL_MALL_QQ = "litemall_mall_qq"; public final static String LITEMALL_MALL_QQ = "litemall_mall_qq";
public final static String LITEMALL_MALL_LONGITUDE = "litemall_mall_longitude";
public final static String LITEMALL_MALL_Latitude = "litemall_mall_latitude";
//所有的配置均保存在该 HashMap 中 //所有的配置均保存在该 HashMap 中
private static Map<String, String> SYSTEM_CONFIGS = new HashMap<>(); private static Map<String, String> SYSTEM_CONFIGS = new HashMap<>();
...@@ -112,6 +114,14 @@ public class SystemConfig { ...@@ -112,6 +114,14 @@ public class SystemConfig {
return getConfig(LITEMALL_MALL_QQ); return getConfig(LITEMALL_MALL_QQ);
} }
public static String getMallLongitude() {
return getConfig(LITEMALL_MALL_LONGITUDE);
}
public static String getMallLatitude() {
return getConfig(LITEMALL_MALL_Latitude);
}
public static void setConfigs(Map<String, String> configs) { public static void setConfigs(Map<String, String> configs) {
SYSTEM_CONFIGS = configs; SYSTEM_CONFIGS = configs;
} }
......
...@@ -31,6 +31,7 @@ class SystemInistService { ...@@ -31,6 +31,7 @@ class SystemInistService {
private final static Map<String, String> DEFAULT_CONFIGS = new HashMap<>(); private final static Map<String, String> DEFAULT_CONFIGS = new HashMap<>();
static { static {
// 小程序相关配置默认值 // 小程序相关配置默认值
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_WX_INDEX_NEW, "6"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_WX_INDEX_NEW, "6");
...@@ -47,11 +48,13 @@ class SystemInistService { ...@@ -47,11 +48,13 @@ class SystemInistService {
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_ORDER_UNPAID, "30"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_ORDER_UNPAID, "30");
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_ORDER_UNCONFIRM, "7"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_ORDER_UNCONFIRM, "7");
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_ORDER_COMMENT, "7"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_ORDER_COMMENT, "7");
// 订单相关配置默认值 // 商城相关配置默认值
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_NAME, "litemall"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_NAME, "litemall");
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_ADDRESS, "上海"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_ADDRESS, "上海");
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_Latitude, "31.201900");
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_LONGITUDE, "121.587839");
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_PHONE, "021-xxxx-xxxx"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_PHONE, "021-xxxx-xxxx");
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_QQ, "738696120"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_MALL_QQ, "705144434");
} }
@Autowired @Autowired
...@@ -63,7 +66,7 @@ class SystemInistService { ...@@ -63,7 +66,7 @@ class SystemInistService {
// 2. 分析DEFAULT_CONFIGS // 2. 分析DEFAULT_CONFIGS
for (Map.Entry<String, String> entry : DEFAULT_CONFIGS.entrySet()) { for (Map.Entry<String, String> entry : DEFAULT_CONFIGS.entrySet()) {
if(configs.containsKey(entry.getKey())){ if (configs.containsKey(entry.getKey())) {
continue; continue;
} }
...@@ -109,7 +112,9 @@ class SystemInistService { ...@@ -109,7 +112,9 @@ class SystemInistService {
infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 3, "系统设置"); infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 3, "系统设置");
infos.put("自动创建朋友圈分享图", Boolean.toString(SystemConfig.isAutoCreateShareImage())); infos.put("自动创建朋友圈分享图", Boolean.toString(SystemConfig.isAutoCreateShareImage()));
infos.put("商场名称", SystemConfig.getMallName()); infos.put("商场名称", SystemConfig.getMallName());
infos.put("首页显示记录数:NEW,HOT,BRAND,TOPIC,CatlogList,CatlogMore", SystemConfig.getNewLimit() + "," + SystemConfig.getHotLimit() + "," + SystemConfig.getBrandLimit() + "," + SystemConfig.getTopicLimit() + "," + SystemConfig.getCatlogListLimit() + "," + SystemConfig.getCatlogMoreLimit()); infos.put("首页显示记录数:NEW,HOT,BRAND,TOPIC,CatlogList,CatlogMore",
SystemConfig.getNewLimit() + "," + SystemConfig.getHotLimit() + "," + SystemConfig.getBrandLimit() +
"," + SystemConfig.getTopicLimit() + "," + SystemConfig.getCatlogListLimit() + "," + SystemConfig.getCatlogMoreLimit());
return infos; return infos;
} }
......
package org.linlinjava.litemall.core.task;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
public abstract class Task implements Delayed, Runnable{
private String id = "";
private long start = 0;
public Task(String id, long delayInMilliseconds){
this.id = id;
this.start = System.currentTimeMillis() + delayInMilliseconds;
}
public String getId() {
return id;
}
@Override
public long getDelay(TimeUnit unit) {
long diff = this.start - System.currentTimeMillis();
return unit.convert(diff, TimeUnit.MILLISECONDS);
}
@Override
public int compareTo(Delayed o) {
return (int)(this.getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (!(o instanceof Task)) {
return false;
}
Task t = (Task)o;
return this.id.equals(t.getId());
}
@Override
public int hashCode() {
return this.id.hashCode();
}
}
package org.linlinjava.litemall.core.task;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executors;
@Component
public class TaskService {
private TaskService taskService;
private DelayQueue<Task> delayQueue = new DelayQueue<Task>();
@PostConstruct
private void init() {
taskService = this;
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
while (true) {
try {
Task task = delayQueue.take();
task.run();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
public void addTask(Task task){
if(delayQueue.contains(task)){
return;
}
delayQueue.add(task);
}
public void removeTask(Task task){
delayQueue.remove(task);
}
}
package org.linlinjava.litemall.core.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class BeanUtil implements ApplicationContextAware {
protected static ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
public static Object getBean(String name) {
return context.getBean(name);
}
public static <T> T getBean(Class<T> c){
return context.getBean(c);
}
}
package org.linlinjava.litemall.core.util; package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
...@@ -14,6 +17,9 @@ import java.util.Map; ...@@ -14,6 +17,9 @@ import java.util.Map;
* @return 远程资源的响应结果 * @return 远程资源的响应结果
*/ */
public class HttpUtil { public class HttpUtil {
private static final Log logger = LogFactory.getLog(HttpUtil.class);
/** /**
* 向指定 URL 发送POST方法的请求 * 向指定 URL 发送POST方法的请求
* *
...@@ -53,9 +59,9 @@ public class HttpUtil { ...@@ -53,9 +59,9 @@ public class HttpUtil {
param.append(entry.getKey()); param.append(entry.getKey());
param.append("="); param.append("=");
param.append(entry.getValue()); param.append(entry.getValue());
//System.out.println(entry.getKey()+":"+entry.getValue());
} }
//System.out.println("param:"+param.toString());
out.write(param.toString()); out.write(param.toString());
} }
// flush输出流的缓冲 // flush输出流的缓冲
...@@ -68,7 +74,7 @@ public class HttpUtil { ...@@ -68,7 +74,7 @@ public class HttpUtil {
result.append(line); result.append(line);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
//使用finally块来关闭输出流、输入流 //使用finally块来关闭输出流、输入流
finally { finally {
...@@ -80,7 +86,7 @@ public class HttpUtil { ...@@ -80,7 +86,7 @@ public class HttpUtil {
in.close(); in.close();
} }
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
} }
return result.toString(); return result.toString();
......
package org.linlinjava.litemall.core.util; package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
...@@ -9,8 +12,10 @@ import java.net.UnknownHostException; ...@@ -9,8 +12,10 @@ import java.net.UnknownHostException;
*/ */
public class IpUtil { public class IpUtil {
private static final Log logger = LogFactory.getLog(IpUtil.class);
public static String getIpAddr(HttpServletRequest request) { public static String getIpAddr(HttpServletRequest request) {
String ipAddress = null; String ipAddress;
try { try {
ipAddress = request.getHeader("x-forwarded-for"); ipAddress = request.getHeader("x-forwarded-for");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
...@@ -27,7 +32,7 @@ public class IpUtil { ...@@ -27,7 +32,7 @@ public class IpUtil {
try { try {
inet = InetAddress.getLocalHost(); inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
ipAddress = inet.getHostAddress(); ipAddress = inet.getHostAddress();
} }
...@@ -42,7 +47,6 @@ public class IpUtil { ...@@ -42,7 +47,6 @@ public class IpUtil {
} catch (Exception e) { } catch (Exception e) {
ipAddress = ""; ipAddress = "";
} }
// ipAddress = this.getRequest().getRemoteAddr();
return ipAddress; return ipAddress;
} }
......
package org.linlinjava.litemall.core.util; package org.linlinjava.litemall.core.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class JacksonUtil { public class JacksonUtil {
private static final Log logger = LogFactory.getLog(JacksonUtil.class);
public static String parseString(String body, String field) { public static String parseString(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
if (leaf != null) if (leaf != null)
return leaf.asText(); return leaf.asText();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
...@@ -26,7 +32,7 @@ public class JacksonUtil { ...@@ -26,7 +32,7 @@ public class JacksonUtil {
public static List<String> parseStringList(String body, String field) { public static List<String> parseStringList(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
...@@ -35,28 +41,28 @@ public class JacksonUtil { ...@@ -35,28 +41,28 @@ public class JacksonUtil {
return mapper.convertValue(leaf, new TypeReference<List<String>>() { return mapper.convertValue(leaf, new TypeReference<List<String>>() {
}); });
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static Integer parseInteger(String body, String field) { public static Integer parseInteger(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
if (leaf != null) if (leaf != null)
return leaf.asInt(); return leaf.asInt();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static List<Integer> parseIntegerList(String body, String field) { public static List<Integer> parseIntegerList(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
...@@ -65,7 +71,7 @@ public class JacksonUtil { ...@@ -65,7 +71,7 @@ public class JacksonUtil {
return mapper.convertValue(leaf, new TypeReference<List<Integer>>() { return mapper.convertValue(leaf, new TypeReference<List<Integer>>() {
}); });
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
...@@ -73,21 +79,21 @@ public class JacksonUtil { ...@@ -73,21 +79,21 @@ public class JacksonUtil {
public static Boolean parseBoolean(String body, String field) { public static Boolean parseBoolean(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
if (leaf != null) if (leaf != null)
return leaf.asBoolean(); return leaf.asBoolean();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static Short parseShort(String body, String field) { public static Short parseShort(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
...@@ -96,14 +102,14 @@ public class JacksonUtil { ...@@ -96,14 +102,14 @@ public class JacksonUtil {
return value.shortValue(); return value.shortValue();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static Byte parseByte(String body, String field) { public static Byte parseByte(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
...@@ -112,20 +118,20 @@ public class JacksonUtil { ...@@ -112,20 +118,20 @@ public class JacksonUtil {
return value.byteValue(); return value.byteValue();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static <T> T parseObject(String body, String field, Class<T> clazz) { public static <T> T parseObject(String body, String field, Class<T> clazz) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
node = node.get(field); node = node.get(field);
return mapper.treeToValue(node, clazz); return mapper.treeToValue(node, clazz);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
...@@ -136,10 +142,10 @@ public class JacksonUtil { ...@@ -136,10 +142,10 @@ public class JacksonUtil {
} }
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {
JsonNode jsonNode = mapper.readTree(json);
return jsonNode; return mapper.readTree(json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
...@@ -148,11 +154,21 @@ public class JacksonUtil { ...@@ -148,11 +154,21 @@ public class JacksonUtil {
public static Map<String, String> toMap(String data) { public static Map<String, String> toMap(String data) {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
try { try {
return objectMapper.readValue(data, new TypeReference<Map<String, String>>(){}); return objectMapper.readValue(data, new TypeReference<Map<String, String>>() {
});
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static String toJson(Object data) {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.writeValueAsString(data);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
} }
...@@ -9,7 +9,8 @@ import java.util.regex.Pattern; ...@@ -9,7 +9,8 @@ import java.util.regex.Pattern;
/** /**
* RegexUtil类的代码是来自[AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode)的RegexUtils类和RegexConstants类 * RegexUtil类的代码是来自[AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode)的RegexUtils类和RegexConstants类
* https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java * https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java
* https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/constant/RegexConstants.java * https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/constant
* /RegexConstants.java
*/ */
public class RegexUtil { public class RegexUtil {
...@@ -19,13 +20,15 @@ public class RegexUtil { ...@@ -19,13 +20,15 @@ public class RegexUtil {
public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$"; public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
/** /**
* Regex of exact mobile. * Regex of exact mobile.
* <p>china mobile: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184, 187, 188, 198</p> * <p>china mobile: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184,
* 187, 188, 198</p>
* <p>china unicom: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186</p> * <p>china unicom: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186</p>
* <p>china telecom: 133, 153, 173, 177, 180, 181, 189, 199</p> * <p>china telecom: 133, 153, 173, 177, 180, 181, 189, 199</p>
* <p>global star: 1349</p> * <p>global star: 1349</p>
* <p>virtual operator: 170</p> * <p>virtual operator: 170</p>
*/ */
public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|(18[0-9])|(19[8,9]))\\d{8}$"; public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|" +
"(18[0-9])|(19[8,9]))\\d{8}$";
/** /**
* Regex of telephone number. * Regex of telephone number.
*/ */
...@@ -37,7 +40,8 @@ public class RegexUtil { ...@@ -37,7 +40,8 @@ public class RegexUtil {
/** /**
* Regex of id card number which length is 18. * Regex of id card number which length is 18.
*/ */
public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$"; public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}" +
"([0-9Xx])$";
/** /**
* Regex of email. * Regex of email.
*/ */
...@@ -60,7 +64,9 @@ public class RegexUtil { ...@@ -60,7 +64,9 @@ public class RegexUtil {
/** /**
* Regex of date which pattern is "yyyy-MM-dd". * Regex of date which pattern is "yyyy-MM-dd".
*/ */
public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$"; public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|" +
"(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|" +
"(?:0[48]|[2468][048]|[13579][26])00)-02-29)$";
/** /**
* Regex of ip address. * Regex of ip address.
*/ */
...@@ -255,7 +261,8 @@ public class RegexUtil { ...@@ -255,7 +261,8 @@ public class RegexUtil {
* @return the list of input matches the regex * @return the list of input matches the regex
*/ */
public static List<String> getMatches(final String regex, final CharSequence input) { public static List<String> getMatches(final String regex, final CharSequence input) {
if (input == null) return Collections.emptyList(); if (input == null)
return Collections.emptyList();
List<String> matches = new ArrayList<>(); List<String> matches = new ArrayList<>();
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input); Matcher matcher = pattern.matcher(input);
...@@ -273,7 +280,8 @@ public class RegexUtil { ...@@ -273,7 +280,8 @@ public class RegexUtil {
* @return the array of strings computed by splitting input around matches of regex * @return the array of strings computed by splitting input around matches of regex
*/ */
public static String[] getSplits(final String input, final String regex) { public static String[] getSplits(final String input, final String regex) {
if (input == null) return new String[0]; if (input == null)
return new String[0];
return input.split(regex); return input.split(regex);
} }
...@@ -291,7 +299,8 @@ public class RegexUtil { ...@@ -291,7 +299,8 @@ public class RegexUtil {
public static String getReplaceFirst(final String input, public static String getReplaceFirst(final String input,
final String regex, final String regex,
final String replacement) { final String replacement) {
if (input == null) return ""; if (input == null)
return "";
return Pattern.compile(regex).matcher(input).replaceFirst(replacement); return Pattern.compile(regex).matcher(input).replaceFirst(replacement);
} }
...@@ -309,7 +318,8 @@ public class RegexUtil { ...@@ -309,7 +318,8 @@ public class RegexUtil {
public static String getReplaceAll(final String input, public static String getReplaceAll(final String input,
final String regex, final String regex,
final String replacement) { final String replacement) {
if (input == null) return ""; if (input == null)
return "";
return Pattern.compile(regex).matcher(input).replaceAll(replacement); return Pattern.compile(regex).matcher(input).replaceAll(replacement);
} }
} }
package org.linlinjava.litemall.core.util; package org.linlinjava.litemall.core.util;
import com.github.pagehelper.Page;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -52,12 +55,44 @@ public class ResponseUtil { ...@@ -52,12 +55,44 @@ public class ResponseUtil {
return obj; return obj;
} }
public static Object ok(String errmsg, Object data) { public static Object okList(List list) {
Map<String, Object> obj = new HashMap<String, Object>(); Map<String, Object> data = new HashMap<String, Object>();
obj.put("errno", 0); data.put("list", list);
obj.put("errmsg", errmsg);
obj.put("data", data); if (list instanceof Page) {
return obj; Page page = (Page) list;
data.put("total", page.getTotal());
data.put("page", page.getPageNum());
data.put("limit", page.getPageSize());
data.put("pages", page.getPages());
} else {
data.put("total", list.size());
data.put("page", 1);
data.put("limit", list.size());
data.put("pages", 1);
}
return ok(data);
}
public static Object okList(List list, List pagedList) {
Map<String, Object> data = new HashMap<String, Object>();
data.put("list", list);
if (pagedList instanceof Page) {
Page page = (Page) pagedList;
data.put("total", page.getTotal());
data.put("page", page.getPageNum());
data.put("limit", page.getPageSize());
data.put("pages", page.getPages());
} else {
data.put("total", pagedList.size());
data.put("page", 1);
data.put("limit", pagedList.size());
data.put("pages", 1);
}
return ok(data);
} }
public static Object fail() { public static Object fail() {
......
package org.linlinjava.litemall.core.util; package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Map; import java.util.Map;
public class SystemInfoPrinter { public class SystemInfoPrinter {
private static final Log logger = LogFactory.getLog(SystemInfoPrinter.class);
public static final String CREATE_PART_COPPER = "XOXOXOXOX"; public static final String CREATE_PART_COPPER = "XOXOXOXOX";
private static int maxSize = 0; private static int maxSize = 0;
...@@ -34,24 +39,24 @@ public class SystemInfoPrinter { ...@@ -34,24 +39,24 @@ public class SystemInfoPrinter {
} }
private static void printHeader(String title) { private static void printHeader(String title) {
System.out.println(getLineCopper()); logger.info(getLineCopper());
System.out.println(""); logger.info("");
System.out.println(" " + title); logger.info(" " + title);
System.out.println(""); logger.info("");
} }
private static void printEnd() { private static void printEnd() {
System.out.println(" "); logger.info(" ");
System.out.println(getLineCopper()); logger.info(getLineCopper());
} }
private static String getLineCopper() { private static String getLineCopper() {
String copper = ""; StringBuilder sb = new StringBuilder();
for (int i = 0; i < maxSize; i++) { for (int i = 0; i < maxSize; i++) {
copper += "="; sb.append("=");
} }
return copper; return sb.toString();
} }
private static void printLine(String head, String line) { private static void printLine(String head, String line) {
...@@ -59,11 +64,11 @@ public class SystemInfoPrinter { ...@@ -59,11 +64,11 @@ public class SystemInfoPrinter {
return; return;
if (head.startsWith(CREATE_PART_COPPER)) { if (head.startsWith(CREATE_PART_COPPER)) {
System.out.println(""); logger.info("");
System.out.println(" [[ " + line + " ]]"); logger.info(" [[ " + line + " ]]");
System.out.println(""); logger.info("");
} else { } else {
System.out.println(" " + head + " -> " + line); logger.info(" " + head + " -> " + line);
} }
} }
} }
Supports Markdown
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