Skip to content

Commit 191614f

Browse files
committed
update code
1 parent 6f1a3d8 commit 191614f

File tree

6 files changed

+22
-35
lines changed

6 files changed

+22
-35
lines changed

core/src/main/java/info/xiaomo/core/untils/CastUtil.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ class CastUtil {
4141
}
4242

4343
fun toLong(number: Any?): Long {
44-
if (number == null) {
45-
return 0L
44+
return if (number == null) {
45+
0L
4646
} else if (number is Number) {
47-
return number.toLong()
47+
number.toLong()
4848
} else if (number is String) {
4949
val str = number as String?
5050
val isNumber = isNumeric(str)
51-
return if (isNumber == 1) java.lang.Long.parseLong(str!!) else if (isNumber == 2) java.lang.Double.valueOf(str!!).toLong() else 0L
51+
if (isNumber == 1) java.lang.Long.parseLong(str!!) else if (isNumber == 2) java.lang.Double.valueOf(str!!).toLong() else 0L
5252
} else {
53-
return 0L
53+
0L
5454
}
5555
}
5656

core/src/main/java/info/xiaomo/core/untils/LunarCalendarUtil.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ object LunarCalendarUtil {
1111
/**
1212
* 支持转换的最小农历年份
1313
*/
14-
val MIN_YEAR = 1900
14+
private val MIN_YEAR = 1900
1515
/**
1616
* 支持转换的最大农历年份
1717
*/
18-
val MAX_YEAR = 2099
18+
private val MAX_YEAR = 2099
1919

2020
/**
2121
* 公历每月前的天数
@@ -352,10 +352,3 @@ object LunarCalendarUtil {
352352
}
353353

354354
}
355-
/**
356-
* 传回农历year年month月的总天数
357-
*
358-
* @param year 要计算的年份
359-
* @param month 要计算的月
360-
* @return 传回天数
361-
*/

core/src/main/java/info/xiaomo/core/untils/MailUtil.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ object MailUtil {
3333
get() {
3434
val props = Properties()
3535
val dir = System.getProperty("user.dir")
36-
val `is` = FileInputStream(dir + "/website/src/main/resources/config/application.properties")
37-
props.load(`is`)
36+
val fileInputStream = FileInputStream(dir + "/website/src/main/resources/config/application.properties")
37+
props.load(fileInputStream)
3838
USERNAME = props["mail.username"].toString()
3939
PASSWORD = props["mail.password"].toString()
4040
val authenticator = object : Authenticator() {

core/src/main/java/info/xiaomo/core/untils/Md5Util.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object Md5Util {
5757
private fun byteToHexString(b: Byte): String {
5858
var n = b.toInt()
5959
if (n < 0) {
60-
n = 256 + n
60+
n += 256
6161
}
6262
val d1 = n / 16
6363
val d2 = n % 16

core/src/main/java/info/xiaomo/core/untils/RandomUtil.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,10 @@ object RandomUtil {
141141
* @return -1失败or随机的索引
142142
*/
143143
fun randomIndexByProb(array: IntArray?): Int {
144-
if (array == null || array.size == 0) {
144+
if (array == null || array.isEmpty()) {
145145
throw IllegalArgumentException("元素数组不能为空!")
146146
}
147-
val list: MutableList<Int>
148-
list = ArrayList()
149-
for (i in array) {
150-
list.add(i)
151-
}
147+
val list: MutableList<Int> = array.toMutableList()
152148
return randomIndexByProb(list)
153149
}
154150

website/src/main/java/info/xiaomo/website/controller/AdminUserController.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ constructor(private val service: AdminUserService) {
4747
*
4848
* @return 不分页
4949
*/
50-
val all: Result<*>
51-
@RequestMapping(value = "findAll", method = arrayOf(RequestMethod.GET))
52-
@ApiOperation(value = "返回所有用户信息", notes = "不分页", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
53-
@ApiResponses(value = *arrayOf(ApiResponse(code = 404, message = "Not Found"), ApiResponse(code = 400, message = "No Name Provided")))
54-
get() {
55-
val pages = service.getAdminUsers()
56-
return if (pages.isEmpty()) {
57-
Result(pages)
58-
} else Result(pages)
59-
}
50+
@RequestMapping(value = "findAll", method = arrayOf(RequestMethod.GET))
51+
@ApiOperation(value = "返回所有用户信息", notes = "不分页", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
52+
@ApiResponses(value = *arrayOf(ApiResponse(code = 404, message = "Not Found"), ApiResponse(code = 400, message = "No Name Provided")))
53+
fun findAll(): Result<List<AdminModel>> {
54+
val pages = service.getAdminUsers()
55+
return if (pages.isEmpty()) {
56+
Result(pages)
57+
} else Result(pages)
58+
}
6059

6160
/**
6261
* 后台账户登录
@@ -192,8 +191,7 @@ constructor(private val service: AdminUserService) {
192191
@ApiResponses(value = *arrayOf(ApiResponse(code = 404, message = "Not Found"), ApiResponse(code = 400, message = "No Name Provided")))
193192
@Throws(UserNotFoundException::class)
194193
fun forbid(@PathVariable("id") id: Long?): Result<*> {
195-
var model: AdminModel?
196-
model = service.forbidAdminUserById(id)
194+
val model: AdminModel? = service.forbidAdminUserById(id)
197195
return Result(model)
198196
}
199197
}

0 commit comments

Comments
 (0)