Commit a5c2aff4 authored by Junling Bu's avatar Junling Bu
Browse files

chore[后端服务]: 后端服务代码基于IDEA的reformat code工具格式化代码,但是mybatis generator生成的代码除外。

parent 556f269d
......@@ -59,16 +59,18 @@ import java.security.SecureRandom;
public class BCrypt {
// BCrypt parameters
static final int MIN_LOG_ROUNDS = 4;
static final int MAX_LOG_ROUNDS = 31;
private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10;
private static final int BCRYPT_SALT_LEN = 16;
// Blowfish parameters
private static final int BLOWFISH_NUM_ROUNDS = 16;
// Initial contents of key schedule
private static final int P_orig[] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
private static final int P_orig[] = {0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377,
0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
0x9216d5d9, 0x8979fb1b };
private static final int S_orig[] = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
0x9216d5d9, 0x8979fb1b};
private static final int S_orig[] = {0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7,
0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5,
......@@ -238,26 +240,24 @@ public class BCrypt {
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76,
0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0,
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 };
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6};
// bcrypt IV: "OrpheanBeholderScryDoubt"
static private final int bf_crypt_ciphertext[] = { 0x4f727068, 0x65616e42,
0x65686f6c, 0x64657253, 0x63727944, 0x6f756274 };
static private final int bf_crypt_ciphertext[] = {0x4f727068, 0x65616e42,
0x65686f6c, 0x64657253, 0x63727944, 0x6f756274};
// Table for Base64 encoding
static private final char base64_code[] = { '.', '/', 'A', 'B', 'C', 'D', 'E', 'F',
static private final char base64_code[] = {'.', '/', 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
// Table for Base64 decoding
static private final byte index_64[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
static private final byte index_64[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
-1, -1, -1, -1, -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1 };
static final int MIN_LOG_ROUNDS = 4;
static final int MAX_LOG_ROUNDS = 31;
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1};
// Expanded Blowfish key
private int P[];
private int S[];
......@@ -270,7 +270,7 @@ public class BCrypt {
* @param d the byte array to encode
* @param len the number of bytes to encode
* @param rs the destination buffer for the base64-encoded string
* @exception IllegalArgumentException if the length is invalid
* @throws IllegalArgumentException if the length is invalid
*/
static void encode_base64(byte d[], int len, StringBuilder rs)
throws IllegalArgumentException {
......@@ -307,6 +307,7 @@ public class BCrypt {
/**
* Look up the 3 bits base64-encoded by the specified character, range-checking
* against conversion table
*
* @param x the base64-encoded value
* @return the decoded value of x
*/
......@@ -320,6 +321,7 @@ public class BCrypt {
/**
* Decode a string encoded using bcrypt's base64 scheme to a byte array. Note that
* this is *not* compatible with the standard MIME-base64 encoding.
*
* @param s the string to decode
* @param maxolen the maximum number of bytes to decode
* @return an array containing the decoded bytes
......@@ -366,36 +368,9 @@ public class BCrypt {
return out.toByteArray();
}
/**
* Blowfish encipher a single 64-bit block encoded as two 32-bit halves
* @param lr an array containing the two 32-bit half blocks
* @param off the position in the array of the blocks
*/
private final void encipher(int lr[], int off) {
int i, n, l = lr[off], r = lr[off + 1];
l ^= P[0];
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) {
// Feistel substitution on left word
n = S[(l >> 24) & 0xff];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[++i];
// Feistel substitution on right word
n = S[(r >> 24) & 0xff];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[++i];
}
lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1];
lr[off + 1] = l;
}
/**
* Cycically extract a word of key material
*
* @param data the string to extract the data from
* @param offp a "pointer" (as a one-entry array) to the current offset into data
* @return the next word of material from data
......@@ -414,74 +389,6 @@ public class BCrypt {
return word;
}
/**
* Initialise the Blowfish key schedule
*/
private void init_key() {
P = (int[]) P_orig.clone();
S = (int[]) S_orig.clone();
}
/**
* Key the Blowfish cipher
* @param key an array containing the key
*/
private void key(byte key[]) {
int i;
int koffp[] = { 0 };
int lr[] = { 0, 0 };
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) {
P[i] = P[i] ^ streamtoword(key, koffp);
}
for (i = 0; i < plen; i += 2) {
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
}
}
/**
* Perform the "enhanced key schedule" step described by Provos and Mazieres in
* "A Future-Adaptable Password Scheme" http://www.openbsd.org/papers/bcrypt-paper.ps
* @param data salt information
* @param key password information
*/
private void ekskey(byte data[], byte key[]) {
int i;
int koffp[] = { 0 }, doffp[] = { 0 };
int lr[] = { 0, 0 };
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) {
P[i] = P[i] ^ streamtoword(key, koffp);
}
for (i = 0; i < plen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
}
}
static long roundsForLogRounds(int log_rounds) {
if (log_rounds < 4 || log_rounds > 31) {
throw new IllegalArgumentException("Bad number of rounds");
......@@ -489,45 +396,9 @@ public class BCrypt {
return 1L << log_rounds;
}
/**
* Perform the central password hashing step in the bcrypt scheme
* @param password the password to hash
* @param salt the binary salt to hash with the password
* @param log_rounds the binary logarithm of the number of rounds of hashing to apply
* @return an array containing the binary hashed password
*/
private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) {
int cdata[] = (int[]) bf_crypt_ciphertext.clone();
int clen = cdata.length;
byte ret[];
long rounds = roundsForLogRounds(log_rounds);
init_key();
ekskey(salt, password);
for (long i = 0; i < rounds; i++) {
key(password);
key(salt);
}
for (int i = 0; i < 64; i++) {
for (int j = 0; j < (clen >> 1); j++) {
encipher(cdata, j << 1);
}
}
ret = new byte[clen * 4];
for (int i = 0, j = 0; i < clen; i++) {
ret[j++] = (byte) ((cdata[i] >> 24) & 0xff);
ret[j++] = (byte) ((cdata[i] >> 16) & 0xff);
ret[j++] = (byte) ((cdata[i] >> 8) & 0xff);
ret[j++] = (byte) (cdata[i] & 0xff);
}
return ret;
}
/**
* Hash a password using the OpenBSD bcrypt scheme
*
* @param password the password to hash
* @param salt the salt to hash with (perhaps generated using BCrypt.gensalt)
* @return the hashed password
......@@ -556,8 +427,7 @@ public class BCrypt {
}
if (salt.charAt(2) == '$') {
off = 3;
}
else {
} else {
minor = salt.charAt(2);
if (minor != 'a' || salt.charAt(3) != '$') {
throw new IllegalArgumentException("Invalid salt revision");
......@@ -578,8 +448,7 @@ public class BCrypt {
real_salt = salt.substring(off + 3, off + 25);
try {
passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
}
catch (UnsupportedEncodingException uee) {
} catch (UnsupportedEncodingException uee) {
throw new AssertionError("UTF-8 is not supported");
}
......@@ -605,6 +474,7 @@ public class BCrypt {
/**
* Generate a salt for use with the BCrypt.hashpw() method
*
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work
* factor therefore increases as 2**log_rounds. Minimum 4, maximum 31.
* @param random an instance of SecureRandom to use
......@@ -631,6 +501,7 @@ public class BCrypt {
/**
* Generate a salt for use with the BCrypt.hashpw() method
*
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work
* factor therefore increases as 2**log_rounds. Minimum 4, maximum 31.
* @return an encoded salt value
......@@ -642,6 +513,7 @@ public class BCrypt {
/**
* Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable
* default for the number of hashing rounds to apply
*
* @return an encoded salt value
*/
public static String gensalt() {
......@@ -650,6 +522,7 @@ public class BCrypt {
/**
* Check that a plaintext password matches a previously hashed one
*
* @param plaintext the plaintext password to verify
* @param hashed the previously-hashed password
* @return true if the passwords match, false otherwise
......@@ -672,4 +545,141 @@ public class BCrypt {
}
return ret == 0;
}
/**
* Blowfish encipher a single 64-bit block encoded as two 32-bit halves
*
* @param lr an array containing the two 32-bit half blocks
* @param off the position in the array of the blocks
*/
private final void encipher(int lr[], int off) {
int i, n, l = lr[off], r = lr[off + 1];
l ^= P[0];
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2; ) {
// Feistel substitution on left word
n = S[(l >> 24) & 0xff];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[++i];
// Feistel substitution on right word
n = S[(r >> 24) & 0xff];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[++i];
}
lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1];
lr[off + 1] = l;
}
/**
* Initialise the Blowfish key schedule
*/
private void init_key() {
P = (int[]) P_orig.clone();
S = (int[]) S_orig.clone();
}
/**
* Key the Blowfish cipher
*
* @param key an array containing the key
*/
private void key(byte key[]) {
int i;
int koffp[] = {0};
int lr[] = {0, 0};
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) {
P[i] = P[i] ^ streamtoword(key, koffp);
}
for (i = 0; i < plen; i += 2) {
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
}
}
/**
* Perform the "enhanced key schedule" step described by Provos and Mazieres in
* "A Future-Adaptable Password Scheme" http://www.openbsd.org/papers/bcrypt-paper.ps
*
* @param data salt information
* @param key password information
*/
private void ekskey(byte data[], byte key[]) {
int i;
int koffp[] = {0}, doffp[] = {0};
int lr[] = {0, 0};
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) {
P[i] = P[i] ^ streamtoword(key, koffp);
}
for (i = 0; i < plen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
}
}
/**
* Perform the central password hashing step in the bcrypt scheme
*
* @param password the password to hash
* @param salt the binary salt to hash with the password
* @param log_rounds the binary logarithm of the number of rounds of hashing to apply
* @return an array containing the binary hashed password
*/
private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) {
int cdata[] = (int[]) bf_crypt_ciphertext.clone();
int clen = cdata.length;
byte ret[];
long rounds = roundsForLogRounds(log_rounds);
init_key();
ekskey(salt, password);
for (long i = 0; i < rounds; i++) {
key(password);
key(salt);
}
for (int i = 0; i < 64; i++) {
for (int j = 0; j < (clen >> 1); j++) {
encipher(cdata, j << 1);
}
}
ret = new byte[clen * 4];
for (int i = 0, j = 0; i < clen; i++) {
ret[j++] = (byte) ((cdata[i] >> 24) & 0xff);
ret[j++] = (byte) ((cdata[i] >> 16) & 0xff);
ret[j++] = (byte) ((cdata[i] >> 8) & 0xff);
ret[j++] = (byte) (cdata[i] & 0xff);
}
return ret;
}
}
\ No newline at end of file
......@@ -28,16 +28,13 @@ import java.util.regex.Pattern;
* (exponentially) to hash the passwords. The default value is 10.
*
* @author Dave Syer
*
*/
public class BCryptPasswordEncoder {
private Pattern BCRYPT_PATTERN = Pattern
.compile("\\A\\$2a?\\$\\d\\d\\$[./0-9A-Za-z]{53}");
private final Log logger = LogFactory.getLog(getClass());
private final int strength;
private final SecureRandom random;
private Pattern BCRYPT_PATTERN = Pattern
.compile("\\A\\$2a?\\$\\d\\d\\$[./0-9A-Za-z]{53}");
public BCryptPasswordEncoder() {
this(-1);
......@@ -53,7 +50,6 @@ public class BCryptPasswordEncoder {
/**
* @param strength the log rounds to use, between 4 and 31
* @param random the secure random instance to use
*
*/
public BCryptPasswordEncoder(int strength, SecureRandom random) {
if (strength != -1 && (strength < BCrypt.MIN_LOG_ROUNDS || strength > BCrypt.MAX_LOG_ROUNDS)) {
......@@ -68,12 +64,10 @@ public class BCryptPasswordEncoder {
if (strength > 0) {
if (random != null) {
salt = BCrypt.gensalt(strength, random);
}
else {
} else {
salt = BCrypt.gensalt(strength);
}
}
else {
} else {
salt = BCrypt.gensalt();
}
return BCrypt.hashpw(rawPassword.toString(), salt);
......
......@@ -9,12 +9,13 @@ import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({ METHOD, FIELD, PARAMETER })
@Target({METHOD, FIELD, PARAMETER})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = OrderValidator.class)
public @interface Order {
String message() default "排序类型不支持";
String[] accepts() default {"desc", "asc"};
Class<?>[] groups() default {};
......
......@@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.List;
public class OrderValidator implements ConstraintValidator<Order, String>{
public class OrderValidator implements ConstraintValidator<Order, String> {
private List<String> valueList;
@Override
public void initialize(Order order) {
valueList = new ArrayList<String>();
for(String val : order.accepts()) {
for (String val : order.accepts()) {
valueList.add(val.toUpperCase());
}
}
@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
if(!valueList.contains(s.toUpperCase())) {
if (!valueList.contains(s.toUpperCase())) {
return false;
}
return true;
......
......@@ -9,12 +9,13 @@ import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({ METHOD, FIELD, PARAMETER })
@Target({METHOD, FIELD, PARAMETER})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = SortValidator.class)
public @interface Sort {
String message() default "排序字段不支持";
String[] accepts() default {"add_time", "id"};
Class<?>[] groups() default {};
......
......@@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.List;
public class SortValidator implements ConstraintValidator<Sort, String>{
public class SortValidator implements ConstraintValidator<Sort, String> {
private List<String> valueList;
@Override
public void initialize(Sort sort) {
valueList = new ArrayList<String>();
for(String val : sort.accepts()) {
for (String val : sort.accepts()) {
valueList.add(val.toUpperCase());
}
}
@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
if(!valueList.contains(s.toUpperCase())) {
if (!valueList.contains(s.toUpperCase())) {
return false;
}
return true;
......
......@@ -6,10 +6,8 @@ import org.linlinjava.litemall.core.storage.AliyunStorage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.FileCopyUtils;
import java.io.File;
import java.io.FileInputStream;
......
......@@ -9,14 +9,14 @@ import org.springframework.test.context.web.WebAppConfiguration;
/**
* 异步测试
*
*/
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class AsyncTest {
@Autowired AsyncTask task;
@Autowired
AsyncTask task;
@Test
public void test() {
......
......@@ -8,6 +8,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
......
......@@ -17,10 +17,10 @@ import java.util.concurrent.Executor;
/**
* 测试邮件发送服务
*
* <p>
* 注意LitemallNotifyService采用异步线程操作
* 因此测试的时候需要睡眠一会儿,保证任务执行
*
* <p>
* 开发者需要确保:
* 1. 在相应的邮件服务器设置正确notify.properties已经设置正确
* 2. 在相应的邮件服务器设置正确
......@@ -30,6 +30,14 @@ import java.util.concurrent.Executor;
@SpringBootTest
public class MailTest {
@Autowired
private NotifyService notifyService;
@Test
public void testMail() {
notifyService.notifyMail("订单信息", "订单1111111已付款,请发货");
}
@Configuration
@Import(Application.class)
static class ContextConfiguration {
......@@ -40,13 +48,5 @@ public class MailTest {
}
}
@Autowired
private NotifyService notifyService;
@Test
public void testMail() {
notifyService.notifyMail("订单信息", "订单1111111已付款,请发货");
}
}
......@@ -18,10 +18,10 @@ import java.util.concurrent.Executor;
/**
* 测试短信发送服务
*
* <p>
* 注意LitemallNotifyService采用异步线程操作
* 因此测试的时候需要睡眠一会儿,保证任务执行
*
* <p>
* 开发者需要确保:
* 1. 在腾讯云短信平台设置短信签名和短信模板notify.properties已经设置正确
* 2. 在腾讯云短信平台设置短信签名和短信模板
......@@ -32,23 +32,13 @@ import java.util.concurrent.Executor;
@SpringBootTest
public class SmsTest {
@Configuration
@Import(Application.class)
static class ContextConfiguration {
@Bean
@Primary
public Executor executor() {
return new SyncTaskExecutor();
}
}
@Autowired
private NotifyService notifyService;
@Test
public void testCaptcha() {
String phone = "xxxxxxxxxxx";
String[] params = new String[] {"123456"};
String[] params = new String[]{"123456"};
notifyService.notifySmsTemplate(phone, NotifyType.CAPTCHA, params);
}
......@@ -56,7 +46,7 @@ public class SmsTest {
@Test
public void testPaySucceed() {
String phone = "xxxxxxxxxxx";
String[] params = new String[] {"123456"};
String[] params = new String[]{"123456"};
notifyService.notifySmsTemplate(phone, NotifyType.PAY_SUCCEED, params);
}
......@@ -64,7 +54,7 @@ public class SmsTest {
@Test
public void testShip() {
String phone = "xxxxxxxxxxx";
String[] params = new String[] {"123456"};
String[] params = new String[]{"123456"};
notifyService.notifySmsTemplate(phone, NotifyType.SHIP, params);
}
......@@ -72,8 +62,18 @@ public class SmsTest {
@Test
public void testRefund() {
String phone = "xxxxxxxxxxx";
String[] params = new String[] {"123456"};
String[] params = new String[]{"123456"};
notifyService.notifySmsTemplate(phone, NotifyType.REFUND, params);
}
@Configuration
@Import(Application.class)
static class ContextConfiguration {
@Bean
@Primary
public Executor executor() {
return new SyncTaskExecutor();
}
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>litemall-db</artifactId>
......
......@@ -4,8 +4,6 @@ import org.apache.ibatis.annotations.Param;
import org.linlinjava.litemall.db.domain.LitemallOrder;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
public interface OrderMapper {
int updateWithOptimisticLocker(@Param("lastUpdateTime") LocalDateTime lastUpdateTime, @Param("order") LitemallOrder order);
......
......@@ -5,6 +5,8 @@ import java.util.Map;
public interface StatMapper {
List<Map> statUser();
List<Map> statOrder();
List<Map> statGoods();
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ public class JsonIntegerArrayTypeHandler extends BaseTypeHandler<Integer[]> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Integer[] parameter, JdbcType jdbcType) throws SQLException {
ps.setString(i,toJson(parameter));
ps.setString(i, toJson(parameter));
}
@Override
......
package org.linlinjava.litemall.db.mybatis;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/*
<columnOverride column="json_string" javaType="com.fasterxml.jackson.databind.JsonNode" typeHandler="JsonNodeTypeHandler"/>
*/
......@@ -34,7 +34,7 @@ public class JsonNodeTypeHandler extends BaseTypeHandler<com.fasterxml.jackson.d
@Override
public JsonNode getNullableResult(ResultSet rs, String columnName) throws SQLException {
String jsonSource = rs.getString(columnName);
if(jsonSource == null){
if (jsonSource == null) {
return null;
}
try {
......@@ -49,7 +49,7 @@ public class JsonNodeTypeHandler extends BaseTypeHandler<com.fasterxml.jackson.d
@Override
public JsonNode getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String jsonSource = rs.getString(columnIndex);
if(jsonSource == null){
if (jsonSource == null) {
return null;
}
try {
......@@ -65,7 +65,7 @@ public class JsonNodeTypeHandler extends BaseTypeHandler<com.fasterxml.jackson.d
@Override
public JsonNode getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String jsonSource = cs.getString(columnIndex);
if(jsonSource == null){
if (jsonSource == null) {
return null;
}
try {
......
package org.linlinjava.litemall.db.mybatis;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -20,7 +17,7 @@ public class JsonStringArrayTypeHandler extends BaseTypeHandler<String[]> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, String[] parameter, JdbcType jdbcType) throws SQLException {
ps.setString(i,toJson(parameter));
ps.setString(i, toJson(parameter));
}
@Override
......
package org.linlinjava.litemall.db.service;
import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallAdMapper;
import org.linlinjava.litemall.db.domain.LitemallAd;
import org.linlinjava.litemall.db.domain.LitemallAdExample;
import org.linlinjava.litemall.db.dao.LitemallAdMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
......
......@@ -60,10 +60,10 @@ public class LitemallAddressService {
LitemallAddressExample example = new LitemallAddressExample();
LitemallAddressExample.Criteria criteria = example.createCriteria();
if(userId != null){
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if(!StringUtils.isEmpty(name)){
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
......@@ -80,14 +80,14 @@ public class LitemallAddressService {
LitemallAddressExample example = new LitemallAddressExample();
LitemallAddressExample.Criteria criteria = example.createCriteria();
if(userId != null){
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if(!StringUtils.isEmpty(name)){
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
return (int)addressMapper.countByExample(example);
return (int) addressMapper.countByExample(example);
}
}
......@@ -14,6 +14,7 @@ import java.util.List;
@Service
public class LitemallAdminService {
private final Column[] result = new Column[]{Column.id, Column.username, Column.avatar};
@Resource
private LitemallAdminMapper adminMapper;
......@@ -27,12 +28,11 @@ public class LitemallAdminService {
return adminMapper.selectByPrimaryKey(id);
}
private final Column[] result = new Column[]{Column.id, Column.username, Column.avatar};
public List<LitemallAdmin> querySelective(String username, Integer page, Integer limit, String sort, String order) {
LitemallAdminExample example = new LitemallAdminExample();
LitemallAdminExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(username)){
if (!StringUtils.isEmpty(username)) {
criteria.andUsernameLike("%" + username + "%");
}
criteria.andDeletedEqualTo(false);
......@@ -49,12 +49,12 @@ public class LitemallAdminService {
LitemallAdminExample example = new LitemallAdminExample();
LitemallAdminExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(username)){
if (!StringUtils.isEmpty(username)) {
criteria.andUsernameLike("%" + username + "%");
}
criteria.andDeletedEqualTo(false);
return (int)adminMapper.countByExample(example);
return (int) adminMapper.countByExample(example);
}
public int updateById(LitemallAdmin admin) {
......
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