commit 397ba75479cb5804b01cc86055ecd9797da7dba7 Author: JSOWELL-PC\autum Date: Sat Mar 4 16:29:55 2023 +0800 commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..2b3b68c30 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ +.mvn/ diff --git a/bin/clean.bat b/bin/clean.bat new file mode 100644 index 000000000..24c09741e --- /dev/null +++ b/bin/clean.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [信息] 清理工程target生成路径。 +echo. + +%~d0 +cd %~dp0 + +cd .. +call mvn clean + +pause \ No newline at end of file diff --git a/bin/package.bat b/bin/package.bat new file mode 100644 index 000000000..c693ec067 --- /dev/null +++ b/bin/package.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [信息] 打包Web工程,生成war/jar包文件。 +echo. + +%~d0 +cd %~dp0 + +cd .. +call mvn clean package -Dmaven.test.skip=true + +pause \ No newline at end of file diff --git a/bin/run.bat b/bin/run.bat new file mode 100644 index 000000000..41efbd0f3 --- /dev/null +++ b/bin/run.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [信息] 使用Jar命令运行Web工程。 +echo. + +cd %~dp0 +cd ../ruoyi-admin/target + +set JAVA_OPTS=-Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -jar %JAVA_OPTS% ruoyi-admin.jar + +cd bin +pause \ No newline at end of file diff --git a/doc/2022骞11鏈17鏃ラ昏緫鏀瑰姩.md b/doc/2022骞11鏈17鏃ラ昏緫鏀瑰姩.md new file mode 100644 index 000000000..1038e47d7 --- /dev/null +++ b/doc/2022骞11鏈17鏃ラ昏緫鏀瑰姩.md @@ -0,0 +1,11 @@ +鍏呯數妗 + +1. 鍏呯數妗╂々绫诲瀷鍏ㄩ儴閮芥槸杩愯惀妗 +2. 鍏呯數妗╁繀椤荤粦瀹氳璐规ā鏉挎墠鑳戒娇鐢 +3. 鍏呯數妗╂々瀵圭櫧鍚嶅崟鐢ㄦ埛鍏嶈垂 +4. 鍒涘缓璁㈠崟鏃讹紝鍒ゆ柇鏄惁涓虹櫧鍚嶅崟鐢ㄦ埛 + +绔欑偣鐧藉悕鍗 + + + diff --git a/doc/鎺ュ彛鏂囨。.md b/doc/鎺ュ彛鏂囨。.md new file mode 100644 index 000000000..b2fc1e20b --- /dev/null +++ b/doc/鎺ュ彛鏂囨。.md @@ -0,0 +1,134 @@ +# 鏍规嵁鍏呯數妗﹊d鏌ヨ璇︽儏鎺ュ彛 + +>鏍规嵁鍏呯數妗﹊d鏌ヨ鐩稿叧淇℃伅锛屽寘鎷繍钀ュ晢淇℃伅銆佸厖鐢电珯淇℃伅銆佸厖鐢垫灙淇℃伅銆佸崗璁俊鎭乻im鍗′俊鎭瓑銆 + +鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ------ | ------ | -------- | -------- | +| pileId | String | Y | 鍏呯數妗﹊d | + +鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | ---------------------------- | +| sn | String | Y | sn鍙 | +| stationName | String | Y | 绔欑偣鍚嶇О station | +| merchantName | String | Y | 杩愯惀鍟嗗悕绉 merchant | +| pileType | String | Y | 璁惧绫诲瀷(1-姹借溅妗╋紝2-鐢靛崟杞) model | +| gunNum | int | Y | 鏋暟閲 model | +| interfaceStandard | String | Y | 鎺ュ彛鏍囧噯 model | +| ratedPower | int | Y | 棰濆畾鍔熺巼(鍗曚綅W) model | +| outputCurrent | int | Y | 杈撳嚭鐢垫祦(鍗曚綅A) model | +| ICCID | String | Y | sim鍗′俊鎭 | +| registrationTime | String | Y | 娉ㄥ唽鏃堕棿 licence | +| expireTime | String | Y | 鍒版湡鏃堕棿 licence | + +![image-20220924155754954](C:\Users\鏉庤嫍鑻梊AppData\Roaming\Typora\typora-user-images\image-20220924155754954.png) + +## 绔欑偣绠$悊鍒楄〃 + +#### 鍙嶅弬 + +PileStationVO + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------- | -------- | :----------: | +| id | String | | 绔欑偣id | +| stationName | string | | 绔欑偣鍚嶇О | +| areaCode | S | | 鐪佸競杈栧尯缂栫爜 | +| area | S | | 鍦板尯 | +| address | S | | 鍦板潃 | +| PileNum | Integer | | 鍏呯數璁惧鏁伴噺 | +| merchantId | S | | 杩愯惀鍟咺D | +| merchantName | S | | 杩愯惀鍟嗗悕绉 | +| merchantAdminName | S | | 杩愯惀鍟嗙鐞嗗憳 | +| stationStatus | Integer | | 绔欑偣鐘舵 | +| stationType | s | | 绔欑偣绫诲瀷 | +| createTime | s | | 鍒涘缓鏃堕棿 | +| stationTel | s | | 绔欑偣鐢佃瘽 | +| matchCars | s | | 閫傜敤杞﹀瀷鎻忚堪 | +| stationLng | s | | 缁忓害 | +| stationLat | s | | 绾害 | +| construction | s | | 寤鸿鍦烘墍 | +| businessHours | s | | 钀ヤ笟鏃堕棿鎻忚堪 | +| organizationCode | s | | 缁勭粐缁撴瀯浠g爜 | +| publicFlag | s | | 鏄惁瀵瑰寮鏀 | +| openFlag | s | | 鏄惁钀ヤ笟涓 | + +## BatchCreatePileDTO + +| 瀛楁鍚 | 绫诲瀷 | | 澶囨敞 | +| ---------------- | ---- | ---- | ---------------------------- | +| merchantId | s | | 杩愯惀鍟唅d | +| stationId | s | | 鍏呯數绔檌d | +| modelId | s | | 鍨嬪彿id | +| softwareProtocol | s | | 杞欢鍗忚锛1-浜戝揩鍏咃紱2-姘歌仈锛 | +| productionDate | Date | | 鐢熸垚鏃ユ湡 | +| connectorNum | int | | 鎺ュ彛鏁伴噺 | +| num | int | | 鐢熸垚鍙版暟 | +| remark | s | | 澶囨敞 | + +### 璁¤垂妯℃澘鏃舵璇︽儏 + +``` +CreateBillingTemplateDTO +``` + +| 瀛楁鍚 | 绫诲瀷 | | 澶囨敞 | +| ----------------- | -------------------------------------- | ---- | ---------------------------------------- | +| name | s | | 妯℃澘鍚嶇О | +| type | s | | 鏃舵绫诲瀷 | +| electricityPriceA | BigDecimal | | 灏栨椂娈电數璐 | +| servicePriceA | BigDecimal | | 灏栨椂娈垫湇鍔¤垂 | +| electricityPriceB | BigDecimal | | 宄版椂娈电數璐 | +| servicePriceB | | | 宄版椂娈垫湇鍔¤垂 | +| electricityPriceC | | | 骞虫椂娈电數璐 | +| servicePriceC | | | 骞虫椂娈垫湇鍔¤垂 | +| electricityPriceD | | | 璋锋椂娈电數璐 | +| servicePriceD | | | 璋锋椂娈垫湇鍔¤垂 | +| remark | s | | 澶囨敞 | +| 鏃舵娓呭崟 | private List timeList; | | | +| type | String | | 鏃舵绫诲瀷锛1-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂 | +| timeDesc | s | | 鏃舵 渚嬪锛00锛00-05锛00 | + +### 蹇熷缓绔橠TO FastCreateStationDTO + +| 瀛楁鍚 | | | 澶囨敞 | +| ----------- | ---- | ---- | ------------ | +| merchantId | S | | 鎵灞炶繍钀ュ晢id | +| stationName | S | | 鍚嶇О | +| address | S | | 鍦板潃 | +| areaCode | S | | 鍖哄煙 | + +### 绔欑偣瀵煎叆璁¤垂妯℃澘dto ImportBillingTemplateDTO + +| 瀛楁鍚 | 绫诲瀷 | | 澶囨敞 | +| ----------------- | ---- | ---- | ---------- | +| stationId | | | 绔欑偣id | +| billingTemplateId | | | 璁¤垂妯℃澘id | + +### 鏌ヨ鍏呯數鏋繑鍥炲墠鍙板弬鏁 + +PileConnectorInfoVO + +| 瀛楁鍚 | 绫诲瀷 | | 澶囨敞 | +| ------------------ | ---- | ---- | --------------------------- | +| connectorId | S | | 鍏呯數鏋彛id | +| connectorCode | S | | 鏋彛缂栧彿锛岀敱鍏呯數妗㏒N+01鐢熸垚 | +| connectorQrCodeUrl | S | | 鍏呯數浜岀淮鐮 | +| status | int | | 鐘舵 | +| type | S | | 绫诲瀷 | +| instantPower | B | | 鍗虫椂鍔熺巼 | +| electricity | big | | 鐢甸噺 | +| SOC | S | | SOC | +| plantformOrderNum | S | | 骞冲彴璁㈠崟 | +| equipmentOrderNum | S | | 璁惧璁㈠崟鍙 | +| chargingTime | S | | 鍏呯數鏃堕暱 | +| voltage | B | | 鐢靛帇 | +| current | B | | 鐢垫祦 | +| temperature | B | | 娓╁害 | +| userInfo | S | | 鐢ㄦ埛淇℃伅 | +| orderId | S | | 璁㈠崟id | +| carNo | S | | 杞︾墝鍙 | + diff --git a/doc/鎺ュ彛鏂囨。New.md b/doc/鎺ュ彛鏂囨。New.md new file mode 100644 index 000000000..0c6d2f560 --- /dev/null +++ b/doc/鎺ュ彛鏂囨。New.md @@ -0,0 +1,621 @@ +# 灏忕▼搴忔帴鍙 + +## 鎺ュ彛杩斿洖鏍煎紡 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ------- | ------ | -------- | ---------- | +| resCode | String | Y | 杩斿洖鐮 | +| msg | String | Y | 杩斿洖淇℃伅 | +| obj | Object | Y | 杩斿洖鐨勬暟鎹 | + +浠ヤ笅鎺ュ彛鍙嶅弬锛屾寚鐨勬槸obj涓殑鏁版嵁锛屾帴鍙h繑鍥為兘鏈塺esCode锛宮sg锛宱bj杩欎笁涓瓧娈点 + +### 绀轰緥 + +~~~json +# 鍏ュ弬 +{ + "pageSize": "10", + "pageNum": "1", + "stationLng": "55.96", + "stationLat": "155.77" +} + +# 鍙嶅弬 +{ + "resCode": "00100000", + "msg": "鎿嶄綔鎴愬姛", + "obj": { + "pageNum": 1, + "pageSize": 10, + "list": [ + { + "stationId": "2", + "stationName": "娴嬭瘯浠撳簱", + "stationAddress": "鍗庢柊闀囧崕闅嗚矾1777鍙6骞搴", + "distance": "10745.74", + "electricityPrice": null, + "servicePrice": null, + "fastTotal": 0, + "fastFree": 0, + "slowTotal": 3, + "slowFree": 0 + }, + { + "stationId": "1", + "stationName": "娴嬭瘯", + "stationAddress": "榛勫煍姹熷崡璺278鍙蜂妇瑙嗘柊鑳芥簮", + "distance": "10762.94", + "electricityPrice": null, + "servicePrice": null, + "fastTotal": 0, + "fastFree": 0, + "slowTotal": 0, + "slowFree": 0 + } + ], + "total": 2, + "pages": 1 + } +} + +# 閿欒鍙嶅弬 +{ + "resCode": "00100010", + "msg": "鏌ヨ鍏呯數绔欎俊鎭垪琛ㄥ紓甯", + "obj": null +} +~~~ + + + +## 1001 鐧诲綍娉ㄥ唽鎺ュ彛 + +## 1002 鏌ヨ浼氬憳淇℃伅 + +> 鎺ュ彛鍦板潃锛歨ttp://localhost:8080/uniapp/member/getMemberInfo +> +> 璇锋眰鏂瑰紡锛欸ET + +### 鍏ュ弬 + +null锛屽湪Header涓渶浼燗uthorization + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| -------- | ------ | -------- | ------------ | +| MemberVO | Object | Y | 鐢ㄦ埛淇℃伅瀵硅薄 | + +### MemberVO + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ------------------ | ------ | -------- | --------------------------- | +| memberId | String | Y | 浼氬憳Id | +| status | String | Y | 鐘舵(1-姝e父;0-鍋滅敤) | +| nickName | String | Y | 鐢ㄦ埛鏄电О | +| mobileNumber | String | Y | 鎵嬫満鍙风爜 | +| principalPrice | Number | Y | 鏈噾閲戦 | +| giftPrice | Number | Y | 璧犻侀噾棰 | +| totalAccountAmount | Number | Y | 鎬婚噾棰(鏈噾閲戦 + 璧犻侀噾棰) | + + + +## 1003 淇敼浼氬憳淇℃伅 + + + +## 2001 鏍规嵁缁忕含搴︽煡璇㈠厖鐢电珯鍒楄〃锛堝垎椤垫帓搴忥級 + +> 鎺ュ彛鍦板潃锛歨ttp://localhost:8080/uniapp/pile/queryStationInfos +> +> 璇锋眰绫诲瀷锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------- | ------ | -------- | ---------------- | +| stationLng | String | N | 缁忓害 | +| stationLat | String | N | 绾害 | +| pageNum | Number | Y | 椤电爜 | +| pageSize | Number | Y | 姣忛〉鏁伴噺 | +| stationName | String | y | 绔欑偣鍚嶇О锛堟悳绱級 | + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| -------- | ---------------- | -------- | ---------- | +| pageNum | Number | Y | 椤电爜 | +| pageSize | Number | Y | 姣忛〉鏁伴噺 | +| list | Array | Y | 鍏呯數绔欏垪琛 | +| total | Number | Y | 鎬绘暟 | +| pages | Number | Y | 鎬婚〉鏁 | + +StationVO + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ---------------- | ------------- | -------- | --------------------- | +| stationId | String | Y | 绔欑偣id | +| stationName | String | Y | 绔欑偣鍚嶇О | +| stationAddress | String | Y | 绔欑偣鍦板潃 | +| stationImgList | Array | N | 绔欑偣鍥剧墖 | +| distance | String | N | 璺濈 鍗曚綅鍗冪背 | +| electricityPrice | String | Y | 鐢佃垂 姣忓害鍗曚环 | +| servicePrice | String | Y | 鏈嶅姟璐 姣忓害鍗曚环 | +| totalPrice | String | Y | 鎬婚噾棰濓紙鐢佃垂+鏈嶅姟璐癸級 | +| fastTotal | Number | Y | 蹇厖鏋彛鎬绘暟 | +| fastFree | Number | Y | 蹇厖鏋彛绌洪棽鏁 | +| slowTotal | Number | Y | 鎱㈠厖鏋彛鎬绘暟 | +| slowFree | Number | Y | 鎱㈠厖鏋彛绌洪棽鏁 | +| stationLng | String | Y | 缁忓害 | +| stationLat | String | Y | 绾害 | + +## 3001 鏌ヨ鍏呯數妗╄鎯 + +## 3002 鏌ヨ鍏呯數妗╂灙鍙h鎯 +> 鎺ュ彛鍦板潃锛歨ttp://localhost:8080/uniapp/pile/selectConnectorListByParams +> +> 璇锋眰绫诲瀷锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------------- | -------- | --------------------------- | +| pageNum | Number | Y | 椤电爜 | +| pageSize | Number | Y | 姣忛〉鏁伴噺 | +| merchantId | String | N | 杩愯惀鍟唅d ==鎺ュ彛鏆傛湭鏀寔== | +| stationIdList | Array | N | 绔欑偣id鍒楄〃 | +| pileIds | Array | N | 鍏呯數妗﹊d鍒楄〃 | +| connectorIdList | Array | N | 鏋彛id鍒楄〃 | +| connectorCodeList | Array | N | 鏋彛鍙峰垪琛 | + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| -------- | -------------------------- | -------- | ------------ | +| pageNum | Number | Y | 椤电爜 | +| pageSize | Number | Y | 姣忛〉鏁伴噺 | +| list | Array | Y | 鍏呯數鏋彛瀵硅薄 | +| total | Number | Y | 鎬绘暟 | +| pages | Number | Y | 鎬婚〉鏁 | + +### PileConnectorInfoVO + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ------------------ | ---------- | :------: | ------------------------------------------------------------ | +| connectorId | String | Y | 鍏呯數鏋彛id | +| connectorCode | String | Y | 鏋彛缂栧彿 | +| connectorQrCodeUrl | String | Y | 鏋彛浜岀淮鐮 | +| status | Number | Y | 鐘舵 0锛氱缃 (榛樿)锛1锛氱┖闂诧紱2锛氬崰鐢紙鏈厖鐢碉級锛3锛氬崰鐢紙鍏呯數涓級锛4锛氬崰鐢紙棰勭害閿佸畾锛 锛255锛氭晠闅 | +| stationId | String | Y | 绔欑偣id | +| merchantId | String | Y | 杩愯惀鍟唅d | +| merchantName | String | Y | 杩愯惀鍟嗗悕绉 | +| pileSn | String | Y | 鍏呯數妗╃紪鍙 | +| type | String | Y | 绫诲瀷 1-鐩存祦鎺ュ彛 姹借溅妗+蹇厖 2-浜ゆ祦鎺ュ彛 姹借溅妗+鎱㈠厖 3-鎻掑骇鎺ュ彛 鐢靛崟杞︽々 | +| instantPower | BigDecimal | Y | 鍗虫椂鍔熺巼 | +| electricity | BigDecimal | Y | 鐢甸噺 | +| equipmentOrderNum | String | Y | 璁惧璁㈠崟鍙 | +| platformOrderNum | String | Y | 骞冲彴璁㈠崟 | +| chargingTime | String | Y | 鍏呯數鏃堕暱 | +| voltage | BigDecimal | Y | 鐢靛帇 | +| current | BigDecimal | Y | 鐢垫祦 | +| gunLineTemperature | String | Y | 鏋嚎娓╁害 | +| userInfo | String | Y | 鐢ㄦ埛淇℃伅 | +| orderId | String | Y | 璁㈠崟id | +| carNo | String | Y | 杞︾墝鍙 | +| soc | String | Y | SOC | +| chargingAmount | BigDecimal | Y | 鍏呯數閲戦 | +| chargingDegree | BigDecimal | Y | 鍏呯數搴︽暟 | +| businessType | | y | 缁忚惀绫诲瀷锛1-杩愯惀妗╋紱2-涓汉妗╋級 | + +### 绀轰緥锛 + +```json +#鍏ュ弬锛 +{ + "pageNum": 1, + "pageSize":10, + "connectorIdList":[1] +} + +#鍙嶅弬锛 +{ + "resCode": "00100000", + "msg": "鎿嶄綔鎴愬姛", + "obj": { + "pageNum": 1, + "pageSize": 10, + "list": [ + { + "connectorId": "1", + "connectorCode": "8800000000000101", + "connectorQrCodeUrl": "http://localhost/pileConnectorInfo&code=8800000000000101", + "status": 0, + "stationId": "2", + "merchantId": "5", + "merchantName": "涓捐(涓婃捣)鏂拌兘婧愮鎶鏈夐檺鍏徃", + "pileSn": "88000000000001", + "type": "2", + "instantPower": 0.00, + "electricity": null, + "equipmentOrderNum": null, + "platformOrderNum": null, + "chargingTime": null, + "voltage": 0.0, + "current": 0.0, + "gunLineTemperature": "0", + "userInfo": null, + "orderId": null, + "carNo": null, + "chargingAmount": 0.00, + "chargingDegree": 0.00, + "soc": "0" + } + ], + "total": 1, + "pages": 1 + } +} +``` + +## 4001 鍚姩鍏呯數 + +> 鎺ュ彛鍦板潃锛歨ttp://localhost:8080/uniapp/order/generateOrder +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | --------------------------- | +| pileSn | String | Y | 妗╃紪鐮 | +| connectorCode | String | Y | 鏋彛鍙 | +| pileConnectorCode | String | Y | 妗╂灙鍙g紪鍙凤紙妗╃紪鐮+鏋彛鍙凤級 | +| memToken | String | Y | 鐢ㄦ埛token锛堝啓鍦℉eader涓級 | + +澶囨敞锛歱ileSn + connectorCode 鎴 pileConnectorCode 閫夊叾涓锛屾帴鍙i兘鏀寔 + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| --------- | ------ | -------- | ------ | +| orderCode | String | Y | 璁㈠崟鍙 | + + + +## 4002 缁撴潫鍏呯數 + +> 鎺ュ彛鍦板潃锛歨ttp://localhost:8080/uniapp/order/settleOrder +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | --------------------------- | +| orderCode | String | Y | 璁㈠崟鍙 | +| pileSn | String | Y | 妗╃紪鐮 | +| connectorCode | String | Y | 鏋彛鍙 | +| pileConnectorCode | String | Y | 妗╂灙鍙g紪鍙凤紙妗╃紪鐮+鏋彛鍙凤級 | + +### 鍙嶅弬 + +null锛岃嫢鎴愬姛锛宮sg涓細鏈夆==鎿嶄綔鎴愬姛==鈥濇彁绀 + + + +## 5001 鏌ヨ璁㈠崟鍒楄〃 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/uniapp/order/getOrderList +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | --------------------------- | +| memberId | String | Y | 浼氬憳id | +| pageSize | Number | Y | | +| pageNum | Number | Y | | +| orderStatus | String | Y | 璁㈠崟鐘舵 1-鍏ㄩ儴 2-鏈畬鎴 3-宸插畬鎴 | +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | --------------------------- | +| orderCode | String | Y | 璁㈠崟鍙 | +| pileSn | String | Y | 妗╃紪鐮 | +| connectorCode | String | Y | 鏋彛鍙 | +| stationName | String | Y | 绔欑偣鍚嶇О | +| pileConnectorCode | String | Y | 妗╂灙鍙g紪鍙凤紙妗╃紪鐮+鏋彛鍙凤級 | +| chargingDegree | BigDecimal | Y | 鍏呯數搴︽暟| +| orderAmount | BigDecimal | Y | 璁㈠崟閲戦 | +| orderStatus | String | Y | 璁㈠崟鐘舵(0-寰呮敮浠橈紱1-鍏呯數涓紱2-寰呯粨绠楋紱3-寰呰ˉ缂达紱4-寮傚父锛5-鍙枒锛6-璁㈠崟瀹屾垚) | +| startTime | String | Y | 璁㈠崟寮濮嬫椂闂 | +| endTime | String | Y | 璁㈠崟缁撴潫鏃堕棿 | +| payAmount | BigDecimal | Y | 鐢ㄦ埛鏀粯閲戦 | +| payStatus | String | Y | 鏀粯鐘舵(0-寰呮敮浠橈紱1-鏀粯瀹屾垚) | +| reason | String | Y | 璁㈠崟寮傚父鍘熷洜 | + +## 60001 鏌ヨ浣欓鏄庣粏 + +> 璇锋眰鍦板潃锛 http://localhost:8080/uniapp/member/getMemberBalanceChanges +> +> 璇锋眰鏂瑰紡锛歅OST + + + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------- | ------ | -------- | ------------------------ | +| memberToken | String | Y | 浼氬憳浠ょ墝 | +| type | String | Y | 浜ゆ槗绫诲瀷 1-杩涜处锛2-鍑鸿处 | +| pageSize | | | | +| pageNum | | | | + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ------------------ | ------ | -------- | -------------------------- | +| memberId | String | Y | 浼氬憳Id | +| principalBalance | Number | Y | 褰撳墠璐︽埛鏈噾浣欓 | +| giftBalance | Number | Y | 褰撳墠璐︽埛璧犻佷綑棰 | +| totalAccountAmount | Number | Y | 璐︽埛鎬讳綑棰 | +| type | String | Y | 浜ゆ槗绫诲瀷 1-杩涜处锛2-鍑鸿处 | +| subType | String | Y | 瀛愮被鍨 | +| amount | String | Y | 鍑鸿处/鍏ヨ处閲戦 | +| transactionTime | String | Y | 浜ゆ槗鏃堕棿 | +| category | String | Y | 浣欓绫诲瀷锛1-鏈噾锛2-璧犻侊級 | + + + + + +## 7001 鐢熸垚璁㈠崟 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/uniapp/order/generateOrder +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | ---------- | +| pileConnectorCode | String | Y | 妗╂灙鍙g紪鐮 | +| chargeAmount | Number | Y | 鍏呯數閲戦 | + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| --------- | ------ | -------- | ------ | +| orderCode | String | Y | 璁㈠崟鍙 | + + + +## 7002 鏀粯璁㈠崟 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/uniapp/pay/payOrder +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| --------- | ------ | -------- | -------- | +| orderCode | String | Y | 璁㈠崟鍙 | +| payMode | String | Y | 鏀粯鏂瑰紡 | +| payAmount | String | Y | 鏀粯閲戦 | + +### 鍙嶅弬 + +null锛屾彁绀衡==鎿嶄綔鎴愬姛==鈥 + +## 7003 璁㈠崟鍋滄鍏呯數 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/uniapp/order/stopCharging +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| --------- | ------ | -------- | ------ | +| orderCode | String | Y | 璁㈠崟鍙 | + +### 鍙嶅弬 + +null锛屾彁绀衡==鎿嶄綔鎴愬姛==鈥 + + + + + + + +# 棣栭〉澶ф暟鎹睍绀 + +## 8001 姒傚喌 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/index/getGeneralSituation +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| --------- | ------ | -------- | ------ | +| stationId | String | N | 绔欑偣id | + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| --------------------- | ------ | -------- | ---------- | +| totalChargingDegree | String | Y | 鎬诲厖鐢电數閲 | +| totalChargingAmount | String | Y | 鎬诲厖鐢佃垂鐢 | +| totalChargingQuantity | String | Y | 鎬诲厖鐢电瑪鏁 | +| totalPileQuantity | String | Y | 鎬昏澶囨暟閲 | +| totalMemberAmount | String | Y | 鎬诲鎴蜂綑棰 | + + + +## 8002 璁㈠崟 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/index/getOrderInfo +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| --------- | ------ | -------- | ------ | +| stationId | String | N | 绔欑偣id | + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| -------------------------- | ------ | -------- | -------------- | +| date | String | Y | 鏃ユ湡 | +| totalElectricity | String | Y | 鎬荤敤鐢甸噺 | +| totalOrderAmount | String | Y | 鎬昏鍗曢噾棰 | +| totalSharpUsedElectricity | String | Y | 灏栨椂娈垫荤敤鐢甸噺 | +| totalPeakUsedElectricity | String | Y | 宄版椂娈垫荤敤鐢甸噺 | +| totalFlatUsedElectricity | String | Y | 骞虫椂娈垫荤敤鐢甸噺 | +| totalValleyUsedElectricity | String | Y | 璋锋椂娈垫荤敤鐢甸噺 | + + + +# 涓汉妗╃浉鍏 + +## 9001 鐢ㄦ埛缁戝畾涓汉妗 + +> 璇锋眰鍦板潃锛 http://localhost:8080/uniapp/personalPile/pileMemberBinding +> +> 璇锋眰鏂瑰紡锛 POST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ---------------- | ------ | -------- | -------------- | +| pileSn | String | Y | 妗╃紪鐮 | +| phoneNumber | String | Y | 鐢ㄦ埛鎵嬫満鍙风爜 | +| verificationCode | String | Y | 鐢ㄦ埛鎵嬫満楠岃瘉鐮 | + +### 鍙嶅弬 + + + + + +## 9002 妗╃鐞嗗憳涓嬪彂缁欏叾浠栫敤鎴 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/uniapp/personalPile/adminIssuePile +> +> 璇锋眰鏂瑰紡锛 POST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------- | ------ | -------- | -------------------- | +| PileSn | String | Y | 妗╃紪鐮 | +| phoneNumber | String | Y | 鍙︿竴涓敤鎴风殑鎵嬫満鍙风爜 | + + + +## 9003 鑾峰彇涓汉妗╁垪琛 + +> 璇锋眰鍦板潃锛 http://localhost:8080/uniapp/personalPile/getPersonalPileList +> +> 璇锋眰鏂瑰紡锛 GET + +### 鍙嶅弬 + +### List + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ------------ | ------ | -------- | ---------------------------- | +| pileSn | String | Y | 妗╃紪鐮 | +| connectorNum | String | Y | 鏋彛鏁伴噺==(2023.02.23鏂板)== | +| memberId | String | Y | 浼氬憳id | +| type | String | Y | 韬唤绫诲瀷 | +| modelName | String | Y | 鍨嬪彿 | +| ratedPower | String | Y | 棰濆畾鍔熺巼 | +| ratedCurrent | String | Y | 棰濆畾鐢垫祦 | +| ratedVoltage | String | Y | 棰濆畾鐢靛帇 | +| speedType | String | Y | 鍏呯數绫诲瀷 | + + + + + +## 9004 鑾峰彇鏋彛瀹炴椂鏁版嵁 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/uniapp/personalPile/getConnectorRealTimeInfo +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | -------- | +| pileConnectorCode | String | Y | 妗╂灙鍙e彿 | + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| -------------- | ------ | -------- | -------- | +| instantCurrent | Number | Y | 瀹炴椂鐢垫祦 | +| instantVoltage | Number | Y | 瀹炴椂鐢靛帇 | +| instantPower | Number | Y | 瀹炴椂鍔熺巼 | + + + +## 9005 绱Н鍏呯數閲忔暟鎹 + +> 璇锋眰鍦板潃锛歨ttp://localhost:8080/uniapp/personalPile/getAccumulativeInfo +> +> 璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | -------- | +| pileConnectorCode | String | Y | 妗╂灙鍙e彿 | +| startTime | String | Y | 寮濮嬫棩鏈 | +| endTime | String | Y | 缁撴潫鏃ユ湡 | + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ---------------------- | ------ | -------- | ------------ | +| memberId | String | Y | 浼氬憳id | +| startTime | String | Y | 寮濮嬫棩鏈 | +| endTime | String | Y | 缁撴潫鏃ユ湡 | +| sumChargingElectricity | String | Y | 绱鍏呯數閲 | +| sumChargingTime | String | Y | 绱鍏呯數鏃堕暱 | + + + +## 9006 鍏呯數璁板綍 + +璇锋眰鍦板潃锛歨ttp://localhost:8080/uniapp/personalPile/getChargingRecord + +璇锋眰鏂瑰紡锛歅OST + +### 鍏ュ弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ----------------- | ------ | -------- | -------- | +| pileConnectorCode | String | Y | 妗╂灙鍙e彿 | +| pageNum | Number | Y | 椤电爜 | +| pageSize | Number | Y | 姣忛〉鏁伴噺 | + + + +### 鍙嶅弬 + +| 瀛楁鍚 | 绫诲瀷 | 鏄惁蹇呬紶 | 澶囨敞 | +| ------------------- | ------ | -------- | -------- | +| startChargingTime | String | Y | 鍚姩鏃堕棿 | +| endChargingTime | String | Y | 缁撴潫鏃堕棿 | +| chargingElectricity | String | Y | 鐢ㄧ數閲 | +| chargingTime | String | Y | 鍏呯數鏃堕暱 | + diff --git a/doc/娴嬭瘯闂.md b/doc/娴嬭瘯闂.md new file mode 100644 index 000000000..af624781e --- /dev/null +++ b/doc/娴嬭瘯闂.md @@ -0,0 +1,5 @@ +# 娴嬭瘯闂 + +1銆佸厖鐢垫々鍨嬪彿琛 pile_model_info ==speed_type== 鍜==charger_pile_type==瀛楁锛屽湪鍓嶅彴鏂板妗╁瀷鍙锋椂鏈缃 + +2銆佺敤鎴锋甯稿紑濮嬪厖鐢靛悗锛屾々鐢变簬鎰忓鎯呭喌娓呴櫎璁㈠崟璁板綍锛屾鏃跺悗鍙拌璁㈠崟涓鐩翠负鍏呯數涓姸鎬侊紝鐢ㄦ埛鐨勫紑濮嬫墸娆鹃噾棰濇棤娉曢鍥 \ No newline at end of file diff --git a/jsowell-admin/pom.xml b/jsowell-admin/pom.xml new file mode 100644 index 000000000..b0ebfe083 --- /dev/null +++ b/jsowell-admin/pom.xml @@ -0,0 +1,127 @@ + + + 4.0.0 + + com.jsowell + jsowell-charger-web + 1.0.0 + + jar + jsowell-admin + + + web鏈嶅姟鍏ュ彛 + + + + + + + org.springframework.boot + spring-boot-devtools + true + + + + + io.springfox + springfox-boot-starter + + + + + io.swagger + swagger-models + 1.6.2 + + + + + mysql + mysql-connector-java + + + + + com.jsowell + jsowell-framework + + + + + com.jsowell + jsowell-quartz + + + + + com.jsowell + jsowell-generator + + + + com.jsowell + jsowell-pile + 1.0.0 + + + + com.jsowell + jsowell-netty + 1.0.0 + + + + org.springframework.boot + spring-boot-starter-test + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.1.RELEASE + + true + + + + + repackage + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + false + ${project.artifactId} + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + /src/test/** + + utf-8 + + + + ${project.artifactId} + + + \ No newline at end of file diff --git a/jsowell-admin/src/main/java/com/jsowell/JsowellApplication.java b/jsowell-admin/src/main/java/com/jsowell/JsowellApplication.java new file mode 100644 index 000000000..5acc5cce4 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/JsowellApplication.java @@ -0,0 +1,21 @@ +package com.jsowell; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +/** + * 鍚姩绋嬪簭 + * + * @author jsowell + */ + +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +public class JsowellApplication { + + public static void main(String[] args) { + // System.setProperty("spring.devtools.restart.enabled", "false"); + SpringApplication.run(JsowellApplication.class, args); + } + +} diff --git a/jsowell-admin/src/main/java/com/jsowell/JsowellServletInitializer.java b/jsowell-admin/src/main/java/com/jsowell/JsowellServletInitializer.java new file mode 100644 index 000000000..71aa4b195 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/JsowellServletInitializer.java @@ -0,0 +1,16 @@ +package com.jsowell; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +/** + * web瀹瑰櫒涓繘琛岄儴缃 + * + * @author jsowell + */ +public class JsowellServletInitializer extends SpringBootServletInitializer { + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(JsowellApplication.class); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/JumpController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/JumpController.java new file mode 100644 index 000000000..6aadef921 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/JumpController.java @@ -0,0 +1,70 @@ +package com.jsowell.api.uniapp; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.pile.vo.uniapp.PileConnectorVO; +import com.jsowell.service.PileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +@Anonymous +@RestController +@RequestMapping("/app-xcx-h5") +public class JumpController extends BaseController { + + @Autowired + private PileService pileService; + + /** + * 鏌ヨ鍏呯數妗╄鎯 + * http://localhost:8080/app-xcx-h5/pile/pileDetail/{pileSn} + */ + @GetMapping("/pile/pileDetail/{pileSn}") + public RestApiResponse getPileDetail(HttpServletRequest request, @PathVariable("pileSn") String pileSn) { + logger.info("app-xcx-h5鏌ヨ鍏呯數妗╄鎯 param:{}", pileSn); + RestApiResponse response = null; + try { + PileConnectorVO vo = pileService.getPileDetailByPileSn(pileSn); + response = new RestApiResponse<>(vo); + } catch (BusinessException e) { + logger.warn("app-xcx-h5鏌ヨ鍏呯數妗╄鎯 warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("app-xcx-h5鏌ヨ鍏呯數妗╄鎯 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PILE_DETAIL_ERROR); + } + logger.info("app-xcx-h5鏌ヨ鍏呯數妗╄鎯 result:{}", JSONObject.toJSONString(response)); + return response; + } + + /** + * 鏌ヨ鍏呯數鏋彛璇︽儏 + * http://localhost:8080/app-xcx-h5/pile/connectorDetail/{pileConnectorCode} + */ + @GetMapping("/pile/connectorDetail/{pileConnectorCode}") + public RestApiResponse getConnectorDetail(HttpServletRequest request, @PathVariable("pileConnectorCode") String pileConnectorCode) { + logger.info("app-xcx-h5鏌ヨ鍏呯數鏋彛璇︽儏 param:{}", pileConnectorCode); + RestApiResponse response = null; + try { + PileConnectorVO vo = pileService.getConnectorDetail(pileConnectorCode); + response = new RestApiResponse<>(vo); + } catch (BusinessException e) { + logger.warn("app-xcx-h5鏌ヨ鍏呯數鏋彛璇︽儏 warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("app-xcx-h5鏌ヨ鍏呯數鏋彛璇︽儏 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PILE_DETAIL_ERROR); + } + logger.info("app-xcx-h5鏌ヨ鍏呯數鏋彛璇︽儏 result:{}", JSONObject.toJSONString(response)); + return response; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/MemberController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/MemberController.java new file mode 100644 index 000000000..26cc700ab --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/MemberController.java @@ -0,0 +1,199 @@ +package com.jsowell.api.uniapp; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.common.util.SMSUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.dto.MemberRegisterAndLoginDTO; +import com.jsowell.pile.dto.MemberRegisterDTO; +import com.jsowell.pile.dto.UniAppQueryMemberBalanceDTO; +import com.jsowell.pile.dto.WechatLoginDTO; +import com.jsowell.pile.dto.WeixinPayDTO; +import com.jsowell.pile.vo.uniapp.MemberVO; +import com.jsowell.service.MemberService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * 灏忕▼搴忔帴鍙 + */ +// 涓嶇櫥褰曠洿鎺ヨ闂 +@Anonymous +@RestController +@RequestMapping("/uniapp/member") +public class MemberController extends BaseController { + + @Autowired + private MemberService memberService; + + /** + * 涓嬪彂鐭俊鎺ュ彛 business + * http://localhost:8080/uniapp/member/sendSMS + */ + @PostMapping("/sendSMS") + public RestApiResponse sendSMS(HttpServletRequest request, @RequestBody MemberRegisterAndLoginDTO dto) { + logger.info("涓嬪彂鐭俊鎺ュ彛 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + if (StringUtils.isBlank(dto.getMobileNumber())) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + String sendSMSResult = SMSUtil.sendSMS(request, dto.getMobileNumber()); + response = new RestApiResponse<>(sendSMSResult); + } catch (Exception e) { + logger.error("涓嬪彂鐭俊鎺ュ彛 鍙戠敓寮傚父 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_SEND_SMS_ERROR); + } + logger.info("涓嬪彂鐭俊鎺ュ彛 result:{}", JSONObject.toJSONString(response)); + return response; + } + + + /** + * 浼氬憳鐧诲綍娉ㄥ唽 + * 鐧诲綍鎴愬姛锛岃繑鍥瀖emberToken + * http://localhost:8080/uniapp/member/memberRegisterAndLogin + */ + @PostMapping("/memberRegisterAndLogin") + public RestApiResponse memberRegisterAndLogin(HttpServletRequest request, @RequestBody MemberRegisterAndLoginDTO dto) { + logger.info("浼氬憳鐧诲綍娉ㄥ唽鎺ュ彛 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + // 鎵ц鐧诲綍锛堟煡杩欎釜鎵嬫満鍙峰湪鍚庡彴鏈夋病鏈夋暟鎹紝濡傛灉娌℃湁灏遍潤榛樻敞鍐岋級 + String memberToken = memberService.memberRegisterAndLogin(dto); + + // 杩斿洖鍓嶇鎴愬姛 + Map map = Maps.newHashMap(); + map.put("memberToken", memberToken); + response = new RestApiResponse<>(map); + } catch (ServiceException e) { + logger.warn("浼氬憳鐧诲綍娉ㄥ唽鎺ュ彛 warn", e); + response = new RestApiResponse<>(e.getMessage()); + } catch (Exception e) { + logger.error("浼氬憳鐧诲綍娉ㄥ唽鎺ュ彛 鍙戠敓寮傚父 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_MEMBER_REGISTER_AND_LOGIN_ERROR); + } + return response; + } + + /** + * 寰俊涓閿櫥褰 + * http://localhost:8080/uniapp/member/wechatLogin + */ + @PostMapping("/wechatLogin") + public RestApiResponse wechatLogin(@RequestBody WechatLoginDTO dto) { + RestApiResponse response = null; + try { + String memberToken = memberService.wechatLogin(dto); + response = new RestApiResponse<>(ImmutableMap.of("memberToken", memberToken)); + } catch (Exception e) { + logger.error("寰俊鐧诲綍寮傚父", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_WECHAT_LOGIN_ERROR); + } + return response; + } + + /** + * 鎺ユ敹骞跺鐞嗗墠绔敤鎴蜂俊鎭 + * + * http://localhost:8080/uniapp/member/saveUserInfo + */ + @PostMapping("/saveUserInfo") + public RestApiResponse saveUserInfo(@RequestBody MemberRegisterDTO dto) { + logger.info("鎺ュ彈鍓嶇鐢ㄦ埛淇℃伅骞跺鐞 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + memberService.handleUserInfo(dto); + response = new RestApiResponse<>(); + } catch (Exception e) { + logger.error("澶勭悊鐢ㄦ埛淇℃伅寮傚父", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_HANDLE_USER_INFO_ERROR); + } + logger.info("鎺ュ彈鍓嶇鐢ㄦ埛淇℃伅骞跺鐞 result:{}", response); + return response; + } + + /** + * 鏌ヨ鐢ㄦ埛璐︽埛淇℃伅 + * + * http://localhost:8080/uniapp/member/getMemberInfo + * @return 鐢ㄦ埛璐︽埛淇℃伅 + */ + @GetMapping("/getMemberInfo") + public RestApiResponse getMemberInfo(HttpServletRequest request) { + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + logger.info("鏌ヨ璐︽埛鎬讳綑棰 param memberId:{}", memberId); + MemberVO memberVO = memberService.getMemberInfoByMemberId(memberId); + response = new RestApiResponse<>(memberVO); + }catch (BusinessException e) { + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e) { + logger.error("鏌ヨ鐢ㄦ埛璐︽埛鎬讳綑棰濆紓甯", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_MEMBER_ACCOUNT_AMOUNT_ERROR); + } + logger.info("鏌ヨ鐢ㄦ埛璐︽埛淇℃伅 result:{}", response); + return response; + } + + /** + * 鑾峰彇openId + * http://localhost:8080/uniapp/member/getOpenId + */ + @PostMapping("/getOpenId") + public RestApiResponse getOpenId(HttpServletRequest request, @RequestBody WeixinPayDTO dto) { + logger.info("鑾峰彇openId param:{}", dto.toString()); + RestApiResponse response; + try { + getMemberIdByAuthorization(request); + String openId = memberService.getOpenIdByCode(dto.getCode()); + response = new RestApiResponse<>(ImmutableMap.of("openId", openId)); + } catch (Exception e) { + logger.error("鑾峰彇openId error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR); + } + logger.info("鑾峰彇openId result:{}", response); + return response; + } + + + /** + * 鑾峰彇鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 + * http://localhost:8080/uniapp/member/getMemberBalanceChanges + * @param request + * @param dto + * @return + */ + @PostMapping("/getMemberBalanceChanges") + public RestApiResponse getMemberBalanceChanges(HttpServletRequest request, @RequestBody UniAppQueryMemberBalanceDTO dto) { + logger.info("鏌ヨ鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 params:{}", dto.toString() ); + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + dto.setMemberId(memberId); + PageResponse pageResponse = memberService.getMemberBalanceChanges(dto); + response = new RestApiResponse<>(pageResponse); + } catch (Exception e) { + logger.error("鏌ヨ鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 error:", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_BALANCE_CHANGES_ERROR); + } + logger.info("鏌ヨ鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 result:{}", response); + return response; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/OrderController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/OrderController.java new file mode 100644 index 000000000..9eb231df5 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/OrderController.java @@ -0,0 +1,244 @@ +package com.jsowell.api.uniapp; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.ImmutableMap; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.dto.GenerateOrderDTO; +import com.jsowell.pile.dto.QueryOrderDTO; +import com.jsowell.pile.dto.SettleOrderDTO; +import com.jsowell.pile.dto.StopChargingDTO; +import com.jsowell.pile.dto.UniAppQueryOrderDTO; +import com.jsowell.pile.vo.uniapp.UniAppOrderVO; +import com.jsowell.service.OrderService; +import com.jsowell.service.PileRemoteService; +import com.jsowell.wxpay.dto.WechatSendMsgDTO; +import com.jsowell.wxpay.service.WxAppletRemoteService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * 璁㈠崟鐩稿叧鎺ュ彛 + * 鎻愪緵缁欏皬绋嬪簭 + */ +@Anonymous +@RestController +@RequestMapping("/uniapp/order") +public class OrderController extends BaseController { + + @Autowired + private OrderService orderService; + + @Autowired + private PileRemoteService pileRemoteService; + + @Autowired + private WxAppletRemoteService wxAppletRemoteService; + + /** + * 鐢熸垚璁㈠崟 + * http://localhost:8080/uniapp/order/generateOrder + */ + @PostMapping("/generateOrder") + public RestApiResponse generateOrder(HttpServletRequest request, @RequestBody GenerateOrderDTO dto) { + logger.info("鐢熸垚璁㈠崟 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response; + try { + if ((StringUtils.isBlank(dto.getPileSn()) || StringUtils.isBlank(dto.getConnectorCode())) && StringUtils.isBlank(dto.getPileConnectorCode())) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + String memberId = getMemberIdByAuthorization(request); + if (StringUtils.isEmpty(memberId)) { + throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); + } + dto.setMemberId(memberId); + // 鐢熸垚璁㈠崟 + dto.setStartMode(Constants.ONE); // 鍚姩鏂瑰紡 1-app鍚姩 + String orderCode = orderService.generateOrder(dto); + response = new RestApiResponse<>(ImmutableMap.of("orderCode", orderCode)); + } catch (BusinessException e) { + logger.warn("鐢熸垚璁㈠崟 warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("鐢熸垚璁㈠崟 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GENERATE_ORDER_ERROR); + } + logger.info("鐢熸垚璁㈠崟 result:{}", JSONObject.toJSONString(response)); + return response; + } + + /** + * 鍋滄鍏呯數 + * http://localhost:8080/uniapp/order/stopCharging + */ + @PostMapping ("/stopCharging") + public RestApiResponse stopCharging(HttpServletRequest request, @RequestBody StopChargingDTO dto) { + logger.info("鍋滄鍏呯數 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response; + try { + String memberId = getMemberIdByAuthorization(request); + if (StringUtils.isEmpty(memberId)) { + throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); + } + dto.setMemberId(memberId); + orderService.stopCharging(dto); + response = new RestApiResponse<>(); + } catch (BusinessException e) { + logger.warn("鍋滄鍏呯數 warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("鍋滄鍏呯數 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_STOP_CHARGING_ERROR); + } + return response; + } + + /** + * 缁撶畻璁㈠崟 + * http://localhost:8080/uniapp/order/settleOrder + * @param dto 缁撶畻璁㈠崟DTO + * @return + */ + @PostMapping("/settleOrderForWeb") + public RestApiResponse settleOrder(HttpServletRequest request, @RequestBody SettleOrderDTO dto) { + logger.info("缁撶畻璁㈠崟 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response; + try { + orderService.settleOrderForWeb(dto); + response = new RestApiResponse<>(); + } catch (Exception e) { + logger.error("缁撶畻璁㈠崟閿欒", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_SETTLE_ORDER_ERROR); + } + return response; + } + + /** + * 鏌ヨ璁㈠崟淇℃伅 + * http://localhost:8080/uniapp/order/getOrderList + * @return + */ + @PostMapping("/getOrderList") + public RestApiResponse getOrderInfo(HttpServletRequest request, @RequestBody UniAppQueryOrderDTO dto) { + logger.info("鏌ヨ璁㈠崟淇℃伅 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + if (StringUtils.isBlank(memberId)) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + // 閫氳繃memberId鏌ヨ鏌愮姸鎬佽鍗曞垪琛 + PageResponse pageInfoList = orderService.getListByMemberIdAndOrderStatus(memberId, dto); + response = new RestApiResponse<>(pageInfoList); + } catch (BusinessException e) { + logger.warn("鏌ヨ璁㈠崟淇℃伅 warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("鏌ヨ璁㈠崟淇℃伅 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_ORDER_INFO_BY_MEMBER_ID_ERROR); + } + logger.info("鏌ヨ璁㈠崟淇℃伅, result:{}", JSONObject.toJSONString(response)); + return response; + } + + /** + * 灏忕▼搴忚幏鍙栬鍗曡鎯 + * http://localhost:8080/uniapp/order/getOrderDetail + * @param request + * @param dto + * @return + */ + @PostMapping("/getOrderDetail") + public RestApiResponse getOrderDetail(HttpServletRequest request, @RequestBody UniAppQueryOrderDTO dto) { + logger.info("灏忕▼搴忚幏鍙栬鍗曡鎯 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + if (StringUtils.isBlank(memberId)) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + UniAppOrderVO uniAppOrderDetail = orderService.getUniAppOrderDetail(dto.getOrderCode()); + response = new RestApiResponse<>(uniAppOrderDetail); + } catch (BusinessException e) { + logger.warn("灏忕▼搴忚幏鍙栬鍗曡鎯 warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("灏忕▼搴忚幏鍙栬鍗曡鎯 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_ORDER_DETAIL_ERROR); + } + logger.info("灏忕▼搴忚幏鍙栬鍗曡鎯, result:{}", JSONObject.toJSONString(response)); + return response; + } + + /** + * 鏍规嵁璁㈠崟鍙锋煡璇㈠厖鐢垫々鍚姩鐘舵 + * http://localhost:8080/uniapp/order/selectPileStarterStatus + */ + @PostMapping("/selectPileStarterStatus") + public RestApiResponse selectPileStarterStatus(HttpServletRequest request, @RequestBody UniAppQueryOrderDTO dto) { + logger.info("鏍规嵁璁㈠崟鍙锋煡璇㈠厖鐢垫々鍚姩鐘舵 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + // String memberId = getMemberIdByAuthorization(request); + String status = orderService.selectPileStarterStatus(dto.getOrderCode()); + response = new RestApiResponse<>(ImmutableMap.of("status", status)); + } catch (Exception e) { + logger.error("鏍规嵁璁㈠崟鍙锋煡璇㈠厖鐢垫々鍚姩鐘舵 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_ORDER_DETAIL_ERROR); + } + logger.info("鏍规嵁璁㈠崟鍙锋煡璇㈠厖鐢垫々鍚姩鐘舵 result:{}", JSONObject.toJSONString(response)); + return response; + } + + /** + * 寰俊灏忕▼搴忓彂閫佸惎鍔ㄥ厖鐢垫帹閫佹秷鎭 + * http://localhost:8080/uniapp/order/uniAppStartChargingSendMsg + * @param dto + * @return + */ + @PostMapping("/uniAppStartChargingSendMsg") + public RestApiResponse uniAppStartChargingSendMsg(@RequestBody WechatSendMsgDTO dto) { + logger.info("寰俊灏忕▼搴忓彂閫佸惎鍔ㄥ厖鐢垫帹閫佹秷鎭 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + Map resultMap = wxAppletRemoteService.startChargingSendMsg(dto); + response = new RestApiResponse<>(resultMap); + } catch (Exception e){ + logger.error("寰俊灏忕▼搴忓彂閫佸惎鍔ㄥ厖鐢垫帹閫佹秷鎭 error", e); + response = new RestApiResponse<>("00300001", "寰俊灏忕▼搴忓彂閫佸惎鍔ㄥ厖鐢垫帹閫佹秷鎭紓甯"); + } + logger.info("寰俊灏忕▼搴忓彂閫佸惎鍔ㄥ厖鐢垫帹閫佹秷鎭 result:{}", response); + return response; + } + + /** + * 鍏抽棴鏀粯鏈惎鍔ㄧ殑璁㈠崟 + * http://localhost:8080/uniapp/order/closeStartFailedOrder + */ + @PostMapping("/closeStartFailedOrder") + public RestApiResponse closeStartFailedOrder(@RequestBody QueryOrderDTO dto) { + logger.info("鍏抽棴鏀粯鏈惎鍔ㄧ殑璁㈠崟 param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + orderService.closeStartFailedOrder(dto); + response = new RestApiResponse<>(); + } catch (Exception e){ + logger.error("鍏抽棴鏀粯鏈惎鍔ㄧ殑璁㈠崟 error", e); + response = new RestApiResponse<>("00300002", "鍏抽棴鏀粯鏈惎鍔ㄧ殑璁㈠崟寮傚父"); + } + logger.info("鍏抽棴鏀粯鏈惎鍔ㄧ殑璁㈠崟 result:{}", response); + return response; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PayController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PayController.java new file mode 100644 index 000000000..ca656e7d6 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PayController.java @@ -0,0 +1,204 @@ +package com.jsowell.api.uniapp; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.ImmutableMap; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.enums.ykc.ScenarioEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.IdUtils; +import com.jsowell.pile.dto.PayOrderDTO; +import com.jsowell.pile.dto.PaymentScenarioDTO; +import com.jsowell.pile.dto.WeixinPayDTO; +import com.jsowell.service.MemberService; +import com.jsowell.service.OrderService; +import com.jsowell.wxpay.dto.WeChatRefundDTO; +import com.jsowell.wxpay.response.WechatPayNotifyParameter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * 鏀粯鐩稿叧controller + */ +@Anonymous +@RestController +@RequestMapping("/uniapp/pay") +public class PayController extends BaseController { + @Autowired + private MemberService memberService; + + @Autowired + private OrderService orderService; + + @Autowired + private RedisCache redisCache; + + /** + * 鍏呭间綑棰濇敮浠 + * 鎻愪緵缁欏皬绋嬪簭浣跨敤 + * http://localhost:8080/uniapp/pay/weixinPay + */ + @PostMapping("/weixinPay") + public RestApiResponse weixinPay(HttpServletRequest request, @RequestBody WeixinPayDTO dto) { + logger.info("寰俊鏀粯 param:{}", dto.toString()); + RestApiResponse response; + try { + if (StringUtils.isBlank(dto.getCode()) || StringUtils.isBlank(dto.getAmount())) { + return new RestApiResponse<>(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + // 閴存潈 + String memberId = getMemberIdByAuthorization(request); + if (StringUtils.isBlank(memberId)) { + throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); + } + dto.setMemberId(memberId); + String openId = memberService.getOpenIdByCode(dto.getCode()); + if (StringUtils.isBlank(openId)) { + throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR); + } + dto.setOpenId(openId); + // 鍏呭间綑棰 闄勫姞鍙傛暟 + PaymentScenarioDTO paymentScenarioDTO = new PaymentScenarioDTO(); + paymentScenarioDTO.setType(ScenarioEnum.BALANCE.getValue()); + paymentScenarioDTO.setMemberId(memberId); + dto.setAttach(JSONObject.toJSONString(paymentScenarioDTO)); + dto.setDescription("浼氬憳鍏呭间綑棰"); + Map weixinMap = orderService.weixinPayV3(dto); + response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap)); + } catch (Exception e) { + response = new RestApiResponse<>(); + } + return response; + } + + /** + * 鏀粯璁㈠崟 + * http://localhost:8080/uniapp/pay/payOrder + * + * @param request + * @param dto + * @return + */ + @PostMapping("/payOrder") + public RestApiResponse payOrder(HttpServletRequest request, @RequestBody PayOrderDTO dto) { + logger.info("鏀粯璁㈠崟 param:{}", dto.toString()); + RestApiResponse response; + + // 鏀粯璁㈠崟鍔犻攣 + String lockKey = "pay_order_" + dto.getOrderCode(); + String lockValue = IdUtils.fastUUID(); + try { + String memberId = getMemberIdByAuthorization(request); + if (StringUtils.isBlank(memberId)) { + throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); + } + dto.setMemberId(memberId); + dto.setLockValue(lockValue); + // redis閿 + Boolean isLock = redisCache.lock(lockKey, lockValue, 60); + Map map = null; + if (isLock) { + map = orderService.payOrder(dto); + } + // Map map = orderService.payOrder(dto); + response = new RestApiResponse<>(map); + } catch (BusinessException e) { + logger.warn("鏀粯璁㈠崟 warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("鏀粯璁㈠崟 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_ORDER_PAY_ERROR); + } finally { + // 鏀粯璁㈠崟瑙i攣 + if (lockValue.equals(redisCache.getCacheObject(lockKey).toString())) { + redisCache.unLock(lockKey); + } + } + logger.info("鏀粯璁㈠崟 result:{}", JSONObject.toJSONString(response)); + return response; + } + + /** + * 寰俊鏀粯鍥炶皟鎺ュ彛 + * http://localhost:8080/uniapp/pay/callback + * https://api.jsowellcloud.com/uniapp/pay/wechatPayCallback + */ + @PostMapping("/wechatPayCallback") + public RestApiResponse wechatPayCallback(HttpServletRequest request, @RequestBody WechatPayNotifyParameter body) { + logger.info("1----------->寰俊鏀粯鍥炶皟寮濮 body:{}", JSONObject.toJSONString(body)); + RestApiResponse response; + try { + orderService.wechatPayCallback(request, body); + response = new RestApiResponse<>(); + } catch (BusinessException e) { + logger.warn("寰俊鏀粯鍥炶皟鎺ュ彛warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("寰俊鏀粯鍥炶皟鎺ュ彛error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_ORDER_PAY_CALLBACK_ERROR); + } + return response; + } + + /** + * 寰俊閫娆惧洖璋冩帴鍙 + * @param request + * @param body + * @return + */ + @PostMapping("/wechatPayRefundCallback") + public RestApiResponse wechatPayRefundCallback(HttpServletRequest request, @RequestBody WechatPayNotifyParameter body) { + logger.info("寰俊閫娆惧洖璋冩帴鍙 body:{}", JSONObject.toJSONString(body)); + RestApiResponse response; + try { + orderService.wechatPayRefundCallback(request, body); + response = new RestApiResponse<>(); + } catch (BusinessException e) { + logger.warn("寰俊閫娆惧洖璋冩帴鍙arn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("寰俊閫娆惧洖璋冩帴鍙rror", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_ORDER_PAY_CALLBACK_ERROR); + } + return response; + } + + /** + * 寰俊閫娆炬帴鍙 + * https://api.jsowellcloud.com/uniapp/pay/refund + */ + @PostMapping("/refund") + public RestApiResponse weChatRefund(HttpServletRequest request, @RequestBody WeChatRefundDTO dto) { + RestApiResponse response; + try { + if (dto.getRefundAmount() == null) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + String memberId = getMemberIdByAuthorization(request); + if (StringUtils.isBlank(memberId)) { + throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); + } + dto.setMemberId(memberId); + dto.setRefundType("2"); + orderService.weChatRefund(dto); + response = new RestApiResponse<>(); + } catch (BusinessException e) { + logger.warn("寰俊閫娆炬帴鍙 warn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("寰俊閫娆炬帴鍙 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR); + } + return response; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PersonPileController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PersonPileController.java new file mode 100644 index 000000000..ccc1f7d18 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PersonPileController.java @@ -0,0 +1,213 @@ +package com.jsowell.api.uniapp; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.pile.dto.PileMemberBindingDTO; +import com.jsowell.pile.dto.QueryPersonPileDTO; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileMemberRelationService; +import com.jsowell.pile.vo.uniapp.OrderVO; +import com.jsowell.pile.vo.uniapp.PersonPileConnectorSumInfoVO; +import com.jsowell.pile.vo.uniapp.PersonPileRealTimeVO; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import com.jsowell.service.PileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * 涓汉妗ヽontroller + * + * @author JS-ZZA + * @date 2023/2/23 15:36 + */ +@Anonymous +@RestController +@RequestMapping("/uniapp/personalPile") +public class PersonPileController extends BaseController { + + @Autowired + private IPileMemberRelationService pileMemberRelationService; + + @Autowired + private PileService pileService; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + /** + * 鐢ㄦ埛缁戝畾涓汉妗 + * + * http://localhost:8080/uniapp/personalPile/pileMemberBinding + * + * @param dto + * @return + */ + @RequestMapping("/pileMemberBinding") + public RestApiResponse pileMemberBinding(HttpServletRequest request, @RequestBody PileMemberBindingDTO dto){ + logger.info("缁戝畾涓汉妗╀俊鎭 params:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + dto.setMemberId(memberId); + int i = pileService.pileMemberBinding(dto); + response = new RestApiResponse<>(i); + }catch (BusinessException e){ + logger.error("缁戝畾涓汉妗╀俊鎭 error,", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception exception){ + logger.error("缁戝畾涓汉妗╀俊鎭 error,", exception); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_BINDING_PERSONAL_PILE_ERROR); + } + logger.info("缁戝畾涓汉妗╀俊鎭 result:{}", response); + return response; + } + + /** + * 涓汉妗╃鐞嗗憳涓嬪彂缁欏叾浠栫敤鎴 + * + * http://localhost:8080/uniapp/personalPile/adminIssuePile + * + * @param request + * @param dto + * @return + */ + @RequestMapping("/adminIssuePile") + public RestApiResponse adminIssuePile(HttpServletRequest request, @RequestBody PileMemberBindingDTO dto){ + logger.info("妗╃鐞嗗憳涓嬪彂涓汉妗 params: {}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + dto.setMemberId(memberId); + pileService.adminIssuePile(dto); + response = new RestApiResponse<>(); + }catch (BusinessException e) { + logger.error("妗╃鐞嗗憳涓嬪彂涓汉妗 error", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e){ + logger.error("妗╃鐞嗗憳涓嬪彂涓汉妗 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_ADMIN_ISSUE_ERROR); + } + logger.info("妗╃鐞嗗憳涓嬪彂涓汉妗 result: {}", response); + return response; + } + + + /** + * 閫氳繃memberId鏌ヤ釜浜烘々鍒楄〃 + * + * http://localhost:8080/uniapp/personalPile/getPersonalPileList + * + * @return + */ + @GetMapping("/getPersonalPileList") + public RestApiResponse getPersonalPileList(HttpServletRequest request){ + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + logger.info("閫氳繃memberId鏌ヤ釜浜烘々鍒楄〃 params: {}", memberId); + List list = pileBasicInfoService.getPileInfoByMemberId(memberId); + response = new RestApiResponse<>(list); + }catch (Exception e){ + logger.error("閫氳繃memberId鏌ヤ釜浜烘々鍒楄〃寮傚父", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PERSONAL_PILE_BY_MEMBER_ID_ERROR); + } + logger.info("閫氳繃memberId鏌ヤ釜浜烘々鍒楄〃 result:{}", response); + return response; + } + + + /** + * 鑾峰彇鏋彛瀹炴椂鏁版嵁 + * + * http://localhost:8080/uniapp/personalPile/getConnectorRealTimeInfo + * + * @param request + * @param dto + * @return + */ + @PostMapping("/getConnectorRealTimeInfo") + public RestApiResponse getConnectorRealTimeInfo(HttpServletRequest request, @RequestBody QueryPersonPileDTO dto){ + logger.info("鑾峰彇涓汉妗╂灙鍙e疄鏃舵暟鎹 params:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + dto.setMemberId(memberId); + PersonPileRealTimeVO connectorRealTimeInfo = pileService.getConnectorRealTimeInfo(dto); + response = new RestApiResponse<>(connectorRealTimeInfo); + }catch (BusinessException e){ + logger.error("鑾峰彇涓汉妗╂灙鍙e疄鏃舵暟鎹 error", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e){ + logger.error("鑾峰彇涓汉妗╂灙鍙e疄鏃舵暟鎹 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PERSONAL_PILE_CONNECTOR_INFO_ERROR); + } + logger.info("鑾峰彇涓汉妗╂灙鍙e疄鏃舵暟鎹 result:{}", response); + return response; + } + + + /** + * 鑾峰彇鏌愭灙鍙f煇娈垫椂闂村唴绱淇℃伅 + * + * http://localhost:8080/uniapp/personalPile/getAccumulativeInfo + * + * @param dto + * @return + */ + @RequestMapping("/getAccumulativeInfo") + public RestApiResponse getAccumulativeInfo(HttpServletRequest request, @RequestBody QueryPersonPileDTO dto) { + logger.info("鑾峰彇鏌愭灙鍙f煇娈垫椂闂村唴绱淇℃伅 params:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + dto.setMemberId(memberId); + PersonPileConnectorSumInfoVO accumulativeInfo = pileService.getAccumulativeInfo(dto); + response = new RestApiResponse<>(accumulativeInfo); + } catch (BusinessException e){ + logger.error("鑾峰彇鏌愭灙鍙f煇娈垫椂闂村唴绱淇℃伅 error", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e){ + logger.error("鑾峰彇鏌愭灙鍙f煇娈垫椂闂村唴绱淇℃伅 error", e); + response = new RestApiResponse<>(e); + } + logger.info("鑾峰彇鏌愭灙鍙f煇娈垫椂闂村唴绱淇℃伅 result:{}", response); + return response; + } + + /** + * 鑾峰彇鍏呯數璁板綍 + * + * http://localhost:8080/uniapp/personalPile/getChargingRecord + * + * @param request + * @param dto + * @return + */ + @RequestMapping("/getChargingRecord") + public RestApiResponse getChargingRecord(HttpServletRequest request, @RequestBody QueryPersonPileDTO dto){ + logger.info("鑾峰彇涓汉妗╁厖鐢佃褰 params:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + dto.setMemberId(memberId); + PageResponse chargingRecord = pileService.getChargingRecord(dto); + response = new RestApiResponse<>(chargingRecord); + }catch (BusinessException e){ + logger.error("鑾峰彇涓汉妗╁厖鐢佃褰 error", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e){ + logger.error("鑾峰彇涓汉妗╁厖鐢佃褰 error", e); + response = new RestApiResponse<>(e); + } + logger.info("鑾峰彇涓汉妗╁厖鐢佃褰 result:{}", response); + return response; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PileController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PileController.java new file mode 100644 index 000000000..7e854bf4e --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/PileController.java @@ -0,0 +1,91 @@ +package com.jsowell.api.uniapp; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.pile.dto.QueryConnectorListDTO; +import com.jsowell.pile.dto.QueryStationDTO; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.service.IPileStationInfoService; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; + +/** + * 鍏呯數妗╃浉鍏虫帴鍙 + * 鎻愪緵缁欏皬绋嬪簭璋冪敤 + */ +// 涓嶇櫥褰曠洿鎺ヨ闂 +@Anonymous +@RestController +@RequestMapping("/uniapp/pile") +public class PileController extends BaseController { + + + + @Autowired + private IPileStationInfoService pileStationInfoService; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + + + /** + * 鏌ヨ鍏呯數绔欎俊鎭垪琛(涓婚〉) + * + * http://localhost:8080/uniapp/pile/queryStationInfos + */ + @PostMapping("/queryStationInfos") + public RestApiResponse queryStationInfos(HttpServletRequest request, @RequestBody QueryStationDTO queryStationDTO) { + logger.info("鏌ヨ鍏呯數绔欎俊鎭垪琛 param:{}", JSONObject.toJSONString(queryStationDTO)); + RestApiResponse response = null; + try { + getMemberIdByAuthorization(request); + // startPage(); + // List list = pileStationInfoService.uniAppQueryStationInfos(queryStationDTO); + PageResponse pageResponse = pileStationInfoService.uniAppQueryStationInfoList(queryStationDTO); + response = new RestApiResponse<>(pageResponse); + } catch (BusinessException e) { + logger.warn("鏌ヨ鍏呯數绔欎俊鎭垪琛╳arn", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("鏌ヨ鍏呯數绔欎俊鎭垪琛ㄥ紓甯 error", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PILE_STATION_INFO_ERROR); + } + logger.info("鏌ヨ鍏呯數绔欎俊鎭垪琛 result:{}", JSONObject.toJSONString(response)); + return response; + } + + /** + * 閫氳繃鍓嶇鍙傛暟鏌ヨ鍏呯數鏋彛鍒楄〃 + * + * http://localhost:8080/uniapp/pile/selectConnectorListByParams + * + * @param dto + * @return + */ + @PostMapping("/selectConnectorListByParams") + public RestApiResponse selectConnectorListByParams(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) { + logger.info("鏌ヨ鍏呯數鏋彛鍒楄〃 params:{}", JSONObject.toJSONString(dto)); + RestApiResponse response = null; + try { + PageResponse pageResponse = pileConnectorInfoService.getUniAppConnectorInfoListByParams(dto); + response = new RestApiResponse<>(pageResponse); + } catch (Exception e) { + logger.error("鏌ヨ鍏呯數鏋彛鍒楄〃寮傚父", e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR); + } + logger.info("鏌ヨ鍏呯數鏋彛鍒楄〃 result:{}", response); + return response; + } + + + +} diff --git a/jsowell-admin/src/main/java/com/jsowell/service/MemberService.java b/jsowell-admin/src/main/java/com/jsowell/service/MemberService.java new file mode 100644 index 000000000..b2c0e3996 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/service/MemberService.java @@ -0,0 +1,234 @@ +package com.jsowell.service; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.uniapp.BalanceChangesEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.JWTUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.IdUtils; +import com.jsowell.pile.domain.MemberBasicInfo; +import com.jsowell.pile.domain.MemberWalletInfo; +import com.jsowell.pile.dto.MemberRegisterAndLoginDTO; +import com.jsowell.pile.dto.MemberRegisterDTO; +import com.jsowell.pile.dto.UniAppQueryMemberBalanceDTO; +import com.jsowell.pile.dto.WechatLoginDTO; +import com.jsowell.pile.service.IMemberBasicInfoService; +import com.jsowell.pile.service.IPileMerchantInfoService; +import com.jsowell.pile.transaction.dto.MemberTransactionDTO; +import com.jsowell.pile.transaction.service.TransactionService; +import com.jsowell.pile.vo.uniapp.MemberVO; +import com.jsowell.pile.vo.uniapp.MemberWalletLogVO; +import com.jsowell.wxpay.service.WxAppletRemoteService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; + +@Service +public class MemberService { + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private RedisCache redisCache; + + @Autowired + private TransactionService transactionService; + + @Autowired + private IMemberBasicInfoService memberBasicInfoService; + + @Autowired + private IPileMerchantInfoService pileMerchantInfoService; + + @Autowired + private WxAppletRemoteService wxAppletRemoteService; + + /** + * 鏍¢獙鐭俊楠岃瘉鐮 + * @param dto + */ + public void checkVerificationCode(MemberRegisterAndLoginDTO dto) { + // 鍙栧嚭缂撳瓨涓殑楠岃瘉鐮佽繘琛屽姣旓紝濡傛灉缂撳瓨涓病鏈夛紝鍒欒秴鏃 + String captchaCode = redisCache.getCacheObject(CacheConstants.SMS_VERIFICATION_CODE_KEY + dto.getMobileNumber()); + if (StringUtils.isEmpty(captchaCode)) { + throw new BusinessException(ReturnCodeEnum.CODE_VERIFICATION_CODE_TIMEOUT_ERROR); + } + // 濡傛灉缂撳瓨涓湁锛屼絾涓庡疄闄呬笉涓鑷达紝鍒欎负楠岃瘉鐮侀敊璇 + if (!StringUtils.equals(captchaCode, dto.getVerificationCode())) { + throw new BusinessException(ReturnCodeEnum.CODE_VERIFICATION_CODE_ERROR); + } + } + + /** + * 鐭俊楠岃瘉鐮佺櫥褰曟敞鍐 + * @param dto + * @return + */ + public String memberRegisterAndLogin(MemberRegisterAndLoginDTO dto) { + // 鏍¢獙鐭俊楠岃瘉鐮 涓ょ鎯呭喌涓嶈兘閫氳繃鏍¢獙锛1-楠岃瘉鐮侀敊璇紱2-瓒呮椂 楠岃瘉鐮10鍒嗛挓鏈夋晥 + checkVerificationCode(dto); + String merchantId = ""; + return memberRegisterAndLogin(dto.getMobileNumber(), merchantId, null); + } + + /** + * 鍏叡鐧婚檰娉ㄥ唽鏂规硶 + * @param phoneNumber 鎵嬫満鍙 + * @param merchantId 鍟嗘埛id + * @return + */ + private String memberRegisterAndLogin(String phoneNumber, String merchantId, String openId) { + if (StringUtils.isBlank(phoneNumber)) { + throw new BusinessException(ReturnCodeEnum.CODE_GET_MOBILE_NUMBER_BY_CODE_ERROR); + } + // if (Objects.isNull(merchantId)) { + // throw new BusinessException(ReturnCodeEnum.CODE_GET_MERCHANT_ID_BY_APP_ID_ERROR); + // } + // 鏌ヨ鎵嬫満鍙风爜鏄惁娉ㄥ唽杩 + MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMobileNumberAndMerchantId(phoneNumber, merchantId); + if (Objects.isNull(memberBasicInfo)) { + // 涓嶅瓨鍦ㄥ垯鏂板鏁版嵁 + String memberId = IdUtils.getMemberId(); + memberBasicInfo = new MemberBasicInfo(); + memberBasicInfo.setStatus(Constants.ONE); + memberBasicInfo.setMemberId(memberId); + memberBasicInfo.setNickName("浼氬憳" + memberId); + memberBasicInfo.setMobileNumber(phoneNumber); + memberBasicInfo.setMerchantId(Long.valueOf(merchantId)); + memberBasicInfo.setOpenId(openId); + + // 棣栨鏂板缓浼氬憳锛屽悓鏃舵柊寤轰細鍛橀挶鍖 + MemberWalletInfo memberWalletInfo = MemberWalletInfo.builder().memberId(memberId).build(); + MemberTransactionDTO memberTransactionDTO = MemberTransactionDTO.builder() + .memberBasicInfo(memberBasicInfo) + .memberWalletInfo(memberWalletInfo) + .build(); + transactionService.createMember(memberTransactionDTO); + } else { + if (StringUtils.isBlank(memberBasicInfo.getOpenId()) && StringUtils.isNotBlank(openId)) { + memberBasicInfo.setOpenId(openId); + memberBasicInfoService.updateMemberBasicInfo(memberBasicInfo); + } + } + // 鏈嶅姟鍣ㄧ敓鎴恡oken杩旂粰鍓嶇 + String memberToken = JWTUtils.createMemberToken(memberBasicInfo.getMemberId(), memberBasicInfo.getNickName()); + // log.info("memToken:{}", memberToken); + return memberToken; + } + + /** + * 寰俊涓閿櫥褰 + * @param dto + */ + public String wechatLogin(WechatLoginDTO dto) { + // 閫氳繃寰俊浼犵殑code鑾峰彇鎵嬫満鍙风爜 + String mobileNumber = wxAppletRemoteService.getMobileNumberByCode(dto.getCode()); + if (StringUtils.isBlank(mobileNumber)) { + throw new BusinessException(ReturnCodeEnum.CODE_GET_MOBILE_NUMBER_BY_CODE_ERROR); + } + // 閫氳繃appid鑾峰彇杩愯惀鍟唅d + String merchantId = pileMerchantInfoService.getMerchantIdByAppId(dto.getAppId()); + // if (Objects.isNull(merchantId)) { + // throw new BusinessException(ReturnCodeEnum.CODE_GET_MERCHANT_ID_BY_APP_ID_ERROR); + // } + // 閫氳繃code鑾峰彇openId + String openId = ""; + try { + openId = getOpenIdByCode(dto.getOpenIdCode()); + } catch (Exception e) { + log.error("getOpenIdByCode鍙戠敓寮傚父", e); + } + // 鏌ヨ鎵嬫満鍙风爜鏄惁娉ㄥ唽杩 + return memberRegisterAndLogin(mobileNumber, merchantId, openId); + } + + /** + * 鑾峰彇openId + * @param code + * @return + */ + public String getOpenIdByCode(String code) { + return wxAppletRemoteService.getOpenIdByCode(code); + } + + /** + * 澶勭悊鐢ㄦ埛淇℃伅 + * + * @param dto 鐢ㄦ埛涓汉淇℃伅 + */ + public void handleUserInfo(MemberRegisterDTO dto) { + // 閫氳繃鐢ㄦ埛鎵嬫満鍙锋煡璇㈡暟鎹簱锛屽鏋滄暟鎹簱涓瓨鍦紝鍒欐洿鏂 + MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMobileNumber(dto.getMobileNumber()); + if (Objects.nonNull(memberBasicInfo)) { + MemberBasicInfo memberInfo = MemberBasicInfo.builder() + .avatarUrl(dto.getAvatarUrl()) + .mobileNumber(dto.getMobileNumber()) + .nickName(dto.getNickName()) + .build(); + memberBasicInfoService.updateMemberBasicInfo(memberInfo); + } + + } + + /** + * 閫氳繃memberToken鑾峰彇鐢ㄦ埛璐︽埛淇℃伅 + * + * @param memberId + * @return + */ + public MemberVO getMemberInfoByMemberId(String memberId) { + MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(memberId); + if (Objects.nonNull(memberVO)) { + memberVO.setTotalAccountAmount(memberVO.getPrincipalBalance().add(memberVO.getGiftBalance())); + } + return memberVO; + } + + /** + * 鏌ヨ鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 + * + * @param dto + */ + public PageResponse getMemberBalanceChanges(UniAppQueryMemberBalanceDTO dto) { + + // 鑾峰彇鍒嗛〉淇℃伅浠ュ強memberId + int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum(); + int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize(); + String memberId = dto.getMemberId(); + String type = dto.getType(); + + if (!StringUtils.equals("1", type) && !StringUtils.equals("2", type)) { + type = ""; + } + // 鍒嗛〉 + PageHelper.startPage(pageNum, pageSize); + List list = memberBasicInfoService.getMemberBalanceChanges(memberId, type); + PageInfo pageInfo = new PageInfo<>(list); + + for (MemberWalletLogVO walletLogVO : pageInfo.getList()) { + String subType = walletLogVO.getSubType(); + String subTypeValue = BalanceChangesEnum.getValueByCode(subType); + if (StringUtils.isNotBlank(subTypeValue)) { + walletLogVO.setSubType(subTypeValue); + } + // walletLogVO.setTotalAccountAmount(walletLogVO.getPrincipalBalance().add(walletLogVO.getGiftBalance())); + } + PageResponse pageResponse = PageResponse.builder() + .pageSize(pageSize) + .pageNum(pageNum) + .list(pageInfo.getList()) + .pages(pageInfo.getPages()) + .total(pageInfo.getTotal()) + .build(); + return pageResponse; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/service/OrderService.java b/jsowell-admin/src/main/java/com/jsowell/service/OrderService.java new file mode 100644 index 000000000..cfb09e2a3 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/service/OrderService.java @@ -0,0 +1,780 @@ +package com.jsowell.service; + +import com.alibaba.fastjson2.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.MemberWalletEnum; +import com.jsowell.common.enums.ykc.ActionTypeEnum; +import com.jsowell.common.enums.ykc.OrderPayModeEnum; +import com.jsowell.common.enums.ykc.OrderPayRecordEnum; +import com.jsowell.common.enums.ykc.OrderPayStatusEnum; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.enums.ykc.PayModeEnum; +import com.jsowell.common.enums.ykc.ScenarioEnum; +import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.IdUtils; +import com.jsowell.netty.command.ykc.StartChargingCommand; +import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; +import com.jsowell.pile.domain.MemberTransactionRecord; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.domain.OrderDetail; +import com.jsowell.pile.domain.OrderPayRecord; +import com.jsowell.pile.domain.WxpayCallbackRecord; +import com.jsowell.pile.dto.BasicPileDTO; +import com.jsowell.pile.dto.GenerateOrderDTO; +import com.jsowell.pile.dto.PayOrderDTO; +import com.jsowell.pile.dto.PayOrderSuccessCallbackDTO; +import com.jsowell.pile.dto.PaymentScenarioDTO; +import com.jsowell.pile.dto.QueryConnectorListDTO; +import com.jsowell.pile.dto.QueryOrderDTO; +import com.jsowell.pile.dto.SettleOrderDTO; +import com.jsowell.pile.dto.StopChargingDTO; +import com.jsowell.pile.dto.UniAppQueryOrderDTO; +import com.jsowell.pile.dto.WeixinPayDTO; +import com.jsowell.pile.service.IMemberBasicInfoService; +import com.jsowell.pile.service.IMemberTransactionRecordService; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.service.IOrderPayRecordService; +import com.jsowell.pile.service.IPileBillingTemplateService; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.service.WechatPayService; +import com.jsowell.pile.service.WxpayCallbackRecordService; +import com.jsowell.pile.transaction.dto.OrderTransactionDTO; +import com.jsowell.pile.transaction.service.TransactionService; +import com.jsowell.pile.vo.base.PileInfoVO; +import com.jsowell.pile.vo.uniapp.MemberVO; +import com.jsowell.pile.vo.uniapp.OrderVO; +import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO; +import com.jsowell.pile.vo.uniapp.UniAppOrderVO; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import com.jsowell.pile.vo.web.OrderDetailInfoVO; +import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; +import com.jsowell.wxpay.dto.WeChatRefundDTO; +import com.jsowell.wxpay.response.WechatPayNotifyParameter; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@Service +public class OrderService { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @Autowired + private TransactionService pileTransactionService; + + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Autowired + private PileRemoteService pileRemoteService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Autowired + private PileService pileService; + + @Autowired + private MemberService memberService; + + @Autowired + private IMemberBasicInfoService memberBasicInfoService; + + @Autowired + private IOrderPayRecordService orderPayRecordService; + + @Autowired + private WechatPayService wechatPayService; + + @Autowired + private WxpayCallbackRecordService wxpayCallbackRecordService; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + @Autowired + private IMemberTransactionRecordService memberTransactionRecordService; + + @Autowired + private RedisCache redisCache; + + /** + * 鐢熸垚璁㈠崟 + * + * @param dto + * @return + */ + public String generateOrder(GenerateOrderDTO dto) { + log.info("generateOrder param:{}", JSONObject.toJSONString(dto)); + // 澶勭悊鍓嶇浼犵殑鍙傛暟 + analysisPileParameter(dto); + + // 鏍¢獙鍏呯數妗╃浉鍏崇殑淇℃伅 + checkPileInfo(dto); + + // 淇濆瓨璁㈠崟鍒版暟鎹簱 saveOrder2Database + String orderCode = saveOrder2Database(dto); + return orderCode; + } + + /** + * 璁㈠崟鏀粯 + * + * @param dto + */ + public Map payOrder(PayOrderDTO dto) throws Exception { + Map resultMap = Maps.newHashMap(); + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode()); + if (orderInfo == null) { + throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR); + } + if (!StringUtils.equals(orderInfo.getPayStatus(), "0")) { + // 璁㈠崟宸叉敮浠 + throw new BusinessException(ReturnCodeEnum.CODE_ORDER_IS_NOT_TO_BE_PAID_ERROR); + } + String orderCode = orderInfo.getOrderCode(); + // 璇ヨ鍗曞厖鐢甸噾棰 + BigDecimal chargeAmount = dto.getPayAmount(); + // 璁板綍鏀粯娴佹按 + List payRecordList = Lists.newArrayList(); + if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) { // 浣欓鏀粯 + // 鏌ヨ璇ヤ細鍛樼殑浣欓 + MemberVO memberVO = memberService.getMemberInfoByMemberId(dto.getMemberId()); + BigDecimal totalAccountAmount = memberVO.getTotalAccountAmount(); + + if (totalAccountAmount.compareTo(chargeAmount) < 0) { + // 鎬讳綑棰濆皬浜庡厖鐢甸噾棰 + throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_IS_INSUFFICIENT); + } + BigDecimal principalAmount = memberVO.getPrincipalBalance(); // 浼氬憳鍓╀綑鏈噾閲戦 + BigDecimal giftAmount = memberVO.getGiftBalance(); // 浼氬憳鍓╀綑璧犻佷綑棰 + + BigDecimal principalPay = null; // 30 + BigDecimal giftPay = null; // 10 + // 鍏堟墸闄ゆ湰閲戦噾棰濓紝鍐嶆墸闄よ禒閫侀噾棰 + BigDecimal subtract = principalAmount.subtract(chargeAmount); + if (subtract.compareTo(BigDecimal.ZERO) >= 0) { + principalPay = chargeAmount; + } else { + if (principalAmount.compareTo(BigDecimal.ZERO) > 0) { + principalPay = principalAmount; + } + giftPay = subtract.negate(); + } + + // 鏇存柊浼氬憳閽卞寘 + UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder() + .memberId(dto.getMemberId()) + .type(MemberWalletEnum.TYPE_OUT.getValue()) + .subType(MemberWalletEnum.SUBTYPE_PAYMENT_FOR_ORDER.getValue()) + .updatePrincipalBalance(principalPay) + .updateGiftBalance(giftPay) + .relatedOrderCode(orderCode) + .build(); + memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO); + + // 璁板綍娴佹按 + if (principalPay != null) { + payRecordList.add(OrderPayRecord.builder() + .orderCode(dto.getOrderCode()) + .payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue()) + .payAmount(principalPay) + .createBy(dto.getMemberId()) + .build()); + } + if (giftPay != null) { + payRecordList.add(OrderPayRecord.builder() + .orderCode(dto.getOrderCode()) + .payMode(OrderPayRecordEnum.GIFT_BALANCE_PAYMENT.getValue()) + .payAmount(giftPay) + .createBy(dto.getMemberId()) + .build()); + } + // 浣欓鏀粯鍙互鐩存帴璋冩敮浠樺洖璋冩柟娉 + PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder() + .orderCode(orderCode) + .payAmount(chargeAmount) + .payMode(dto.getPayMode()) + .build(); + payOrderSuccessCallback(callbackDTO); + + // 浣欓鏀粯璁㈠崟 璁板綍浼氬憳浜ゆ槗娴佹按 + MemberTransactionRecord record = MemberTransactionRecord.builder() + .orderCode(orderCode) + .scenarioType(ScenarioEnum.ORDER.getValue()) + .memberId(memberVO.getMemberId()) + .actionType(ActionTypeEnum.FORWARD.getValue()) + .payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue()) + .amount(dto.getPayAmount()) // 鍗曚綅鍏 + .build(); + memberTransactionRecordService.insertSelective(record); + } else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { // 寰俊鏀粯 + String openId = memberService.getOpenIdByCode(dto.getCode()); + if (StringUtils.isBlank(openId)) { + throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR); + } + WeixinPayDTO weixinPayDTO = new WeixinPayDTO(); + weixinPayDTO.setOpenId(openId); + weixinPayDTO.setAmount(dto.getPayAmount().toString()); + // 鏀粯璁㈠崟 闄勫姞鍙傛暟 + PaymentScenarioDTO paymentScenarioDTO = PaymentScenarioDTO.builder() + .type(ScenarioEnum.ORDER.getValue()) + .orderCode(dto.getOrderCode()) + .memberId(orderInfo.getMemberId()) + .build(); + weixinPayDTO.setAttach(JSONObject.toJSONString(paymentScenarioDTO)); + weixinPayDTO.setDescription("鍏呯數璐圭敤"); + Map weixinMap = this.weixinPayV3(weixinPayDTO); + // 杩斿洖寰俊鏀粯鍙傛暟 + resultMap.put("weixinMap", weixinMap); + } else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 鏀粯瀹濇敮浠 + // TODO 杩斿洖鏀粯瀹濇敮浠樺弬鏁 + } + + // 璁㈠崟鏀粯娴佹按鍏ュ簱 + if (CollectionUtils.isNotEmpty(payRecordList)) { + orderPayRecordService.batchInsert(payRecordList); + } + return resultMap; + } + + /** + * 璁㈠崟鏀粯鎴愬姛 鏀粯鍥炶皟 + * 鏀粯鎴愬姛鍚庢帀鐢ㄨ繖涓柟娉 + * 1. 淇敼璁㈠崟鏀粯鐘舵 + * 2. 鍙戦佸惎鍔ㄥ厖鐢垫寚浠 + */ + public void payOrderSuccessCallback(PayOrderSuccessCallbackDTO dto) { + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode()); + BigDecimal payAmount = dto.getPayAmount(); + + // 淇敼璁㈠崟 + orderInfo.setPayMode(dto.getPayMode()); + orderInfo.setPayStatus("1"); + orderInfo.setPayAmount(payAmount); + orderInfo.setPayTime(new Date()); + orderBasicInfoService.updateOrderBasicInfo(orderInfo); + + // 鍙戦佸惎鍔ㄦ寚浠 + StartChargingCommand startChargingCommand = StartChargingCommand.builder() + .pileSn(orderInfo.getPileSn()) + .connectorCode(orderInfo.getConnectorCode()) + .orderCode(dto.getOrderCode()) + .chargeAmount(payAmount) + .build(); + ykcPushCommandService.pushStartChargingCommand(startChargingCommand); + } + + /** + * 淇濆瓨璁㈠崟淇℃伅鍒版暟鎹簱 + * + * @param dto + * @return + */ + private String saveOrder2Database(GenerateOrderDTO dto) { + String orderCode = IdUtils.generateOrderCode(dto.getPileSn(), dto.getConnectorCode()); + // 璁㈠崟鍩烘湰淇℃伅 + OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder() + .orderCode(orderCode) + .orderStatus(OrderStatusEnum.NOT_START.getValue()) + .memberId(dto.getMemberId()) + .stationId(dto.getPileConnector().getStationId()) + .pileSn(dto.getPileSn()) + .connectorCode(dto.getConnectorCode()) + .pileConnectorCode(dto.getPileSn() + dto.getConnectorCode()) + .startMode(dto.getStartMode()) + .payStatus(Constants.ZERO) + .payAmount(dto.getChargeAmount()) + .payMode(dto.getPayMode()) + .orderAmount(BigDecimal.ZERO) + .build(); + + // 璁㈠崟璇︽儏 + OrderDetail orderDetail = OrderDetail.builder() + .orderCode(orderCode) + .sharpElectricityPrice(dto.getBillingTemplate().getSharpElectricityPrice()) + .sharpServicePrice(dto.getBillingTemplate().getSharpServicePrice()) + .peakElectricityPrice(dto.getBillingTemplate().getPeakElectricityPrice()) + .peakServicePrice(dto.getBillingTemplate().getPeakServicePrice()) + .flatElectricityPrice(dto.getBillingTemplate().getFlatElectricityPrice()) + .flatServicePrice(dto.getBillingTemplate().getFlatServicePrice()) + .valleyElectricityPrice(dto.getBillingTemplate().getValleyElectricityPrice()) + .valleyServicePrice(dto.getBillingTemplate().getValleyServicePrice()) + .build(); + + OrderTransactionDTO createOrderTransactionDTO = OrderTransactionDTO.builder() + .orderBasicInfo(orderBasicInfo) + .orderDetail(orderDetail) + .build(); + pileTransactionService.doCreateOrder(createOrderTransactionDTO); + return orderCode; + } + + /** + * 鏍¢獙鍏呯數妗╃浉鍏崇殑淇℃伅 + * + * @param dto + */ + private void checkPileInfo(GenerateOrderDTO dto) { + // 鏌ヨ鍏呯數妗╃姸鎬 鏄惁绌洪棽 鏋彛鏄惁鍗犵敤 + PileConnectorDetailVO pileConnector = pileService.queryPileConnectorDetail(dto.getPileSn() + dto.getConnectorCode()); + if (pileConnector == null) { + log.error("checkPileInfo鍏呯數鏋彛涓虹┖ pileSn:{}, connectorCode:{}", dto.getPileSn(), dto.getConnectorCode()); + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + // 鍒ゆ柇鏋彛鐘舵 + if (!(StringUtils.equals(pileConnector.getConnectorStatus(), PileConnectorDataBaseStatusEnum.FREE.getValue()) + || StringUtils.equals(pileConnector.getConnectorStatus(), PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue()))) { + log.error("checkPileInfo鍏呯數鏋彛鐘舵佷笉姝g‘锛屽綋鍓嶇姸鎬佷负:{}", pileConnector.getConnectorStatus()); + throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_ERROR); + } + // 鏌ヨ鍏呯數妗╃殑璁¤垂妯℃澘 + BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(dto.getPileSn()); + if (billingTemplateVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_BILLING_TEMPLATE_NULL_ERROR); + } + dto.setPileConnector(pileConnector); + dto.setBillingTemplate(billingTemplateVO); + } + + + /** + * 澶勭悊鍓嶇浼犵殑鍙傛暟 + * pileConnectorCode = pileSn + connectorCode + * + * @param dto + */ + public void analysisPileParameter(BasicPileDTO dto) { + if (StringUtils.isBlank(dto.getPileSn()) || StringUtils.isBlank(dto.getConnectorCode())) { + // 浠巔ileConnectorCode瑙f瀽 + String pileConnectorCode = dto.getPileConnectorCode(); + if (StringUtils.isNotEmpty(pileConnectorCode) && pileConnectorCode.length() == Constants.PILE_CONNECTOR_CODE_LENGTH) { + dto.setPileSn(StringUtils.substring(pileConnectorCode, 0, pileConnectorCode.length() - 2)); + dto.setConnectorCode(StringUtils.substring(pileConnectorCode, pileConnectorCode.length() - 2, pileConnectorCode.length())); + } else { + throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR); + } + } else { + // 璇存槑pileSn 鍜 connectorCode鍓嶇浼犱簡锛岄偅灏辨牎楠屼竴涓嬮暱搴 + if (dto.getPileSn().length() != Constants.PILE_SN_LENGTH || dto.getConnectorCode().length() != Constants.CONNECTOR_CODE_LENGTH) { + throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR); + } + } + } + + /** + * 缁撶畻璁㈠崟 + * endCharging + * + * @param dto 缁撶畻璁㈠崟鍙傛暟 + */ + public void settleOrderForWeb(SettleOrderDTO dto) { + analysisPileParameter(dto); + // 鏌ヨ璁㈠崟璇︽儏锛岄獙璇佽鍗曚腑鐨勬々缂栧彿鏄惁姝g‘ + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode()); + if (orderBasicInfo == null) { + throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR); + } + if (!(StringUtils.equals(orderBasicInfo.getPileSn(), dto.getPileSn()) + && StringUtils.equals(orderBasicInfo.getConnectorCode(), dto.getConnectorCode()))) { + throw new BusinessException(ReturnCodeEnum.CODE_ORDER_PILE_MAPPING_ERROR); + } + // push杩滅▼鍋滄満鎸囦护 + pileRemoteService.remoteStopCharging(dto.getPileSn(), dto.getConnectorCode()); + + // 妗╄绠楃殑娑堣垂閲戦 + + // 瀵规瘮涓涓嬶紝鏄惁闇瑕侀娆 + + + } + + /** + * 閫氳繃浼氬憳Id鏌ヨ璁㈠崟鍒楄〃 + * + * @param memberId 浼氬憳Id + * @return 璁㈠崟淇℃伅闆嗗悎 + */ + public PageResponse getListByMemberIdAndOrderStatus(String memberId, UniAppQueryOrderDTO dto) throws ParseException { + String orderStatus = dto.getOrderStatus(); + if (StringUtils.isBlank(orderStatus)) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + ArrayList orderStatusList = Lists.newArrayList(); + if (StringUtils.equals("2", orderStatus)) { + // 鏌ユ湭瀹屾垚璁㈠崟 + CollectionUtils.addAll(orderStatusList, "0", "1", "2", "3", "4", "5"); + } else if (StringUtils.equals("3", orderStatus)) { + // 鏌ュ凡瀹屾垚璁㈠崟 + orderStatusList.add("6"); + } + // 鍒嗛〉 + PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); + List list = orderBasicInfoService.getListByMemberIdAndOrderStatus(memberId, orderStatusList); + + PageInfo pageInfo = new PageInfo<>(list); + + for (OrderVO orderVO : pageInfo.getList()) { + orderVO.setPileConnectorCode(orderVO.getPileSn() + orderVO.getConnectorCode()); + Date endTimeDate; + Date startTimeDate = sdf.parse(orderVO.getStartTime()); + if (StringUtils.isNotBlank(orderVO.getEndTime())) { + endTimeDate = sdf.parse(orderVO.getEndTime()); + } else { + endTimeDate = new Date(); + } + // 璁$畻鍑轰袱涓椂闂村樊 + orderVO.setChargingTime(DateUtils.getDatePoor(endTimeDate, startTimeDate)); + } + + // 杩斿洖缁撴灉闆 + PageResponse pageResponse = PageResponse.builder() + .pageNum(dto.getPageNum()) + .pageSize(dto.getPageSize()) + .list(pageInfo.getList()) + .pages(pageInfo.getPages()) + .total(pageInfo.getTotal()) + .build(); + return pageResponse; + } + + /** + * 寰俊鏀粯v3 + * + * @param dto + * @return + * @throws Exception + */ + public Map weixinPayV3(WeixinPayDTO dto) throws Exception { + return wechatPayService.weixinPayV3(dto); + } + + /** + * 鐢ㄦ埛鍋滄鍏呯數 + * + * @param dto + */ + public void stopCharging(StopChargingDTO dto) { + // 鏌ヨ鍗 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode()); + if (orderInfo == null) { + throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR); + } + // 鏍¢獙璁㈠崟涓殑浼氬憳涓庢搷浣滀細鍛樻槸鍚︿竴鑷 + if (!StringUtils.equals(orderInfo.getMemberId(), dto.getMemberId())) { + throw new BusinessException(ReturnCodeEnum.CODE_ORDER_MEMBER_NOT_MATCH_ERROR); + } + // 鍙戦佸仠姝㈡寚浠 + pileRemoteService.remoteStopCharging(orderInfo.getPileSn(), orderInfo.getConnectorCode()); + log.info("璁㈠崟鍙:{}鍙戦佸仠鏈烘寚浠ゆ垚鍔", dto.getOrderCode()); + } + + /** + * 寰俊鏀粯鍥炶皟 + * + * @param request + * @param body + * @throws Exception + */ + public void wechatPayCallback(HttpServletRequest request, WechatPayNotifyParameter body) throws Exception { + // 鑾峰彇寰俊鏀粯鎴愬姛杩斿洖鐨勪俊鎭 + Map map = wechatPayService.wechatPayCallbackInfo(request, body); + String type = (String) map.get("type"); + BigDecimal amount = (BigDecimal) map.get("amount"); // 寰俊缁欑殑amount鍗曚綅鏄垎 + amount = amount.divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP); // 杞崲涓哄厓 + + String orderCode = (String) map.get("orderCode"); + String memberId = (String) map.get("memberId"); + if (StringUtils.equals(type, ScenarioEnum.ORDER.getValue())) { // 1-璁㈠崟鏀粯 + // 鏀粯璁㈠崟鎴愬姛 + // orderCode = (String) map.get("orderCode"); + PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder() + .orderCode(orderCode) + .payAmount(amount) + .payMode(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue()) + .build(); + // 璁㈠崟鏀粯鎴愬姛 鏀粯鍥炶皟 + payOrderSuccessCallback(callbackDTO); + + // 璁板綍璁㈠崟鏀粯娴佹按 + OrderPayRecord orderPayRecord = OrderPayRecord.builder() + .orderCode(orderCode) + .payMode(OrderPayRecordEnum.WECHATPAY_PAYMENT.getValue()) + .payAmount(amount) + .createBy(null) + .build(); + orderPayRecordService.batchInsert(Lists.newArrayList(orderPayRecord)); + } else if (StringUtils.equals(type, ScenarioEnum.BALANCE.getValue())) { // 2-鍏呭间綑棰 + // 鍏呭间綑棰濇垚鍔 + // memberId = (String) map.get("memberId"); + UpdateMemberBalanceDTO dto = new UpdateMemberBalanceDTO(); + dto.setMemberId(memberId); + dto.setType(MemberWalletEnum.TYPE_IN.getValue()); + dto.setSubType(MemberWalletEnum.SUBTYPE_TOP_UP.getValue()); + dto.setUpdatePrincipalBalance(amount); + memberBasicInfoService.updateMemberBalance(dto); + } + + // 寰俊鏀粯璁㈠崟 璁板綍浼氬憳浜ゆ槗娴佹按 + MemberTransactionRecord record = MemberTransactionRecord.builder() + .orderCode(orderCode) + .scenarioType(type) + .memberId(memberId) + .actionType(ActionTypeEnum.FORWARD.getValue()) + .payMode(PayModeEnum.PAYMENT_OF_WECHATPAY.getValue()) + .amount(amount) // 鍗曚綅鍏 + .outTradeNo(String.valueOf(map.get("out_trade_no"))) + .transactionId(String.valueOf(map.get("transaction_id"))) + .build(); + memberTransactionRecordService.insertSelective(record); + } + + public void weChatRefund(WeChatRefundDTO dto) { + log.info("寰俊閫娆炬帴鍙 param:{}", JSONObject.toJSONString(dto)); + orderBasicInfoService.weChatRefund(dto); + } + + /** + * 鏌ヨ璁㈠崟璇︽儏淇℃伅 + * @param orderCode 璁㈠崟缂栧彿 + * @return + */ + public OrderDetailInfoVO queryOrderDetailInfo(String orderCode) { + OrderDetailInfoVO vo = new OrderDetailInfoVO(); + + // 璁㈠崟淇℃伅 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderBasicInfo == null) { + return vo; + } + OrderDetailInfoVO.OrderInfo order = new OrderDetailInfoVO.OrderInfo(); + order.setOrderCode(orderBasicInfo.getOrderCode()); + order.setOrderStatus(orderBasicInfo.getOrderStatus()); + order.setStartTime(DateUtils.formatDateTime(orderBasicInfo.getChargeStartTime())); + order.setEndTime(DateUtils.formatDateTime(orderBasicInfo.getChargeEndTime())); + order.setCreateTime(DateUtils.formatDateTime(orderBasicInfo.getCreateTime())); + order.setStopReasonMsg(orderBasicInfo.getReason()); + order.setStartSOC(orderBasicInfo.getStartSOC()); + order.setEndSOC(orderBasicInfo.getEndSOC()); + vo.setOrderInfo(order); + + // 璁惧淇℃伅 + PileInfoVO pileInfoVO = pileService.selectPileInfoBySn(orderBasicInfo.getPileSn()); + vo.setPileInfo(pileInfoVO); + + // 鏋彛瀹炴椂鏁版嵁淇℃伅 + String pileConnectorCode = orderBasicInfo.getPileSn() + orderBasicInfo.getConnectorCode(); + QueryConnectorListDTO dto = new QueryConnectorListDTO(); + dto.setConnectorCodeList(Lists.newArrayList(pileConnectorCode)); + List chargingRealTimeDataList = orderBasicInfoService.getChargingRealTimeData(orderCode); + if (CollectionUtils.isNotEmpty(chargingRealTimeDataList)) { + List infoList = Lists.newArrayList(); + for (RealTimeMonitorData realTimeMonitorData : chargingRealTimeDataList) { + OrderDetailInfoVO.RealTimeMonitorData info = new OrderDetailInfoVO.RealTimeMonitorData(); + info.setInstantCurrent(realTimeMonitorData.getOutputCurrent()); // 鐢垫祦 + info.setInstantVoltage(realTimeMonitorData.getOutputVoltage()); // 鐢靛帇 + info.setInstantPower(realTimeMonitorData.getOutputPower()); // 鍔熺巼 + info.setSOC(realTimeMonitorData.getSOC()); + info.setTime(realTimeMonitorData.getDateTime()); // 鏃堕棿 + infoList.add(info); + } + + // 鐩戞帶淇℃伅 + OrderDetailInfoVO.OrderRealTimeInfo realTimeInfo = new OrderDetailInfoVO.OrderRealTimeInfo(); + + RealTimeMonitorData realTimeMonitorData = chargingRealTimeDataList.get(0); + realTimeInfo.setOrderAmount(realTimeMonitorData.getChargingAmount()); + // realTimeInfo.setTotalElectricityAmount(); + // realTimeInfo.setTotalServiceAmount(); + realTimeInfo.setChargedDegree(realTimeMonitorData.getChargingDegree()); + // realTimeInfo.setSOC(realTimeMonitorData.getSOC()); + realTimeInfo.setChargingTime(realTimeMonitorData.getSumChargingTime()); + vo.setOrderRealTimeInfo(realTimeInfo); + + // 鏍规嵁鏃堕棿杩涜姝e簭鎺掑簭 + infoList = infoList.stream() + .sorted(Comparator.comparing(OrderDetailInfoVO.RealTimeMonitorData::getTime)) + .collect(Collectors.toList()); + vo.setRealTimeMonitorDataList(infoList); + } + + // 鏀粯娴佹按 + List orderPayRecordList = orderPayRecordService.getOrderPayRecordList(orderCode); + if (CollectionUtils.isNotEmpty(orderPayRecordList)) { + OrderPayRecord orderPayRecord = orderPayRecordList.get(0); + List payRecordList = Lists.newArrayList(); + OrderDetailInfoVO.PayRecord payInfo = new OrderDetailInfoVO.PayRecord(); + // 浣欓鏀粯濡傛灉鏄敱鏈噾鍜岃禒閫佷竴璧锋敮浠樼殑锛屽悎骞朵负涓涓 + BigDecimal bigDecimal = orderPayRecordList.stream() + .map(OrderPayRecord::getPayAmount) + .reduce(BigDecimal.ZERO, BigDecimal::add); + payInfo.setPayAmount(bigDecimal.toString()); + payInfo.setPayStatus(orderBasicInfo.getPayStatus()); + payInfo.setPayTime(DateUtils.formatDateTime(orderBasicInfo.getPayTime())); + String payMode = orderPayRecord.getPayMode(); + if (StringUtils.equals(payMode, OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue()) + || StringUtils.equals(payMode, OrderPayRecordEnum.GIFT_BALANCE_PAYMENT.getValue())) { + // 浣跨敤浣欓鏀粯 + payInfo.setPayMode(OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue()); + payInfo.setPayModeDesc(OrderPayModeEnum.PAYMENT_OF_BALANCE.getLabel()); + } else if (StringUtils.equals(payMode, OrderPayRecordEnum.WECHATPAY_PAYMENT.getValue())){ + // 浣跨敤寰俊鏀粯 + payInfo.setPayMode(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue()); + payInfo.setPayModeDesc(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getLabel()); + // 鏌ュ井淇℃敮浠樺洖璋冭褰 + WxpayCallbackRecord wxpayCallbackRecord = wxpayCallbackRecordService.selectByOrderCode(orderCode); + if (wxpayCallbackRecord != null) { + payInfo.setOutTradeNo(wxpayCallbackRecord.getOutTradeNo()); + payInfo.setTransactionId(wxpayCallbackRecord.getTransactionId()); + } + } else if (StringUtils.equals(payMode, OrderPayRecordEnum.WHITELIST_PAYMENT.getValue())){ + // 浣跨敤鐧藉悕鍗曟敮浠 + payInfo.setPayMode(OrderPayModeEnum.PAYMENT_OF_WHITELIST.getValue()); + payInfo.setPayModeDesc(OrderPayModeEnum.PAYMENT_OF_WHITELIST.getLabel()); + } + payRecordList.add(payInfo); + vo.setPayRecordList(payRecordList); + } + + + + // 鐢ㄦ埛淇℃伅 + MemberVO memberVO = memberService.getMemberInfoByMemberId(orderBasicInfo.getMemberId()); + vo.setMemberInfo(memberVO); + + return vo; + } + + public void wechatPayRefundCallback(HttpServletRequest request, WechatPayNotifyParameter body) throws Exception { + // 鑾峰彇寰俊閫娆炬垚鍔熻繑鍥炵殑淇℃伅 + Map map = wechatPayService.wechatPayRefundCallbackInfo(request, body); + } + + /** + * 鑾峰彇灏忕▼搴忚鍗曡鎯 + * @param orderCode + * @return + */ + public UniAppOrderVO getUniAppOrderDetail(String orderCode) { + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderBasicInfo == null) { + throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR); + } + UniAppOrderVO vo = new UniAppOrderVO(); + vo.setOrderCode(orderBasicInfo.getOrderCode()); + vo.setPileSn(orderBasicInfo.getPileSn()); + vo.setConnectorCode(orderBasicInfo.getConnectorCode()); + vo.setPileConnectorCode(orderBasicInfo.getPileSn() + orderBasicInfo.getConnectorCode()); + String orderStatus = orderBasicInfo.getOrderStatus(); + vo.setOrderStatus(orderStatus); + + // 璁㈠崟鐘舵佹弿杩 + String orderStatusDescribe; + if (StringUtils.equals(orderStatus, OrderStatusEnum.NOT_START.getValue())) { + // 鏈惎鍔ㄨ繕鏈変袱绉嶆儏鍐 寰呮敮浠 / 鏀粯鎴愬姛 + String payStatus = orderBasicInfo.getPayStatus(); + if (StringUtils.equals(payStatus, OrderPayStatusEnum.paid.getValue())) { + // 鏀粯鎴愬姛锛屾湭鍚姩 + orderStatusDescribe = OrderPayStatusEnum.paid.getLabel() + ", " + OrderStatusEnum.getOrderStatus(orderStatus); + } else { + // 寰呮敮浠 + orderStatusDescribe = OrderPayStatusEnum.unpaid.getLabel(); + } + } else { + orderStatusDescribe = OrderStatusEnum.getOrderStatus(orderStatus); + } + vo.setOrderStatusDescribe(orderStatusDescribe); + + // 鑾峰彇鍏呯數妗╂灙鍙d俊鎭 + PileConnectorDetailVO pileConnectorDetailVO = pileService.queryPileConnectorDetail(vo.getPileConnectorCode()); + if (pileConnectorDetailVO != null) { + vo.setPileConnectorStatus(pileConnectorDetailVO.getConnectorStatus()); + } + + // 鑾峰彇璁㈠崟鍏呯數鏁版嵁 + List monitorDataList = orderBasicInfoService.getChargingRealTimeData(orderCode); + if (CollectionUtils.isNotEmpty(monitorDataList)) { + List chargingDataList = Lists.newArrayList(); + UniAppOrderVO.ChargingData data = null; + for (int i = 0; i < monitorDataList.size(); i++) { + RealTimeMonitorData monitorData = monitorDataList.get(i); + data = new UniAppOrderVO.ChargingData(); + data.setDateTime(monitorData.getDateTime()); + String outputVoltage = monitorData.getOutputVoltage(); + data.setOutputVoltage(outputVoltage); + String outputCurrent = monitorData.getOutputCurrent(); + data.setOutputCurrent(outputCurrent); + BigDecimal power = new BigDecimal(outputCurrent).multiply(new BigDecimal(outputVoltage)) + .divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP); + data.setPower(power.toString()); + data.setSOC(monitorData.getSOC()); + data.setBatteryMaxTemperature(monitorData.getBatteryMaxTemperature()); + chargingDataList.add(data); + // vo涓殑瀹炴椂鏁版嵁锛屾渶鏂颁竴鏉″氨鍙杕onitorDataList绗竴涓 + if (i == 0) { + vo.setBatteryMaxTemperature(data.getBatteryMaxTemperature()); + vo.setOutputPower(data.getPower()); + vo.setOutputCurrent(data.getOutputCurrent()); + vo.setOutputVoltage(data.getOutputVoltage()); + vo.setSOC(data.getSOC()); + BigDecimal chargingAmount = new BigDecimal(monitorData.getChargingAmount()).setScale(2, BigDecimal.ROUND_HALF_UP); // 鍏呯數閲戦 + vo.setChargingAmount(chargingAmount.toString()); + BigDecimal chargingDegree = new BigDecimal(monitorData.getChargingDegree()).setScale(2, BigDecimal.ROUND_HALF_UP); // 鍏呯數搴︽暟 + vo.setChargingDegree(chargingDegree.toString()); + vo.setSumChargingTime(monitorData.getSumChargingTime()); + vo.setTimeRemaining(monitorData.getTimeRemaining()); + } + } + // monitorDataList鏄寜鐓ф椂闂村掑簭鐨勶紝chargingDataList闇瑕佹寜鐓ф椂闂存搴 + Collections.reverse(chargingDataList); + vo.setChargingDataList(chargingDataList); + } + return vo; + } + + /** + * 鏍规嵁璁㈠崟鍙锋煡璇㈠厖鐢垫々鍚姩鐘舵 + * @param orderCode + * @return + */ + public String selectPileStarterStatus(String orderCode) { + List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderCode); + // 鍙湁鍏呯數妗╀笂浼犵殑瀹炴椂鏁版嵁涓殑鐘舵佷负鍏呯數锛屾墠鑳芥煡鍒板疄鏃舵暟鎹垪琛 + return CollectionUtils.isNotEmpty(chargingRealTimeData) ? Constants.ONE : Constants.ZERO; + } + + public void closeStartFailedOrder(QueryOrderDTO dto) { + orderBasicInfoService.closeStartFailedOrder(dto.getStartTime(), dto.getEndTime()); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/service/PileRemoteService.java b/jsowell-admin/src/main/java/com/jsowell/service/PileRemoteService.java new file mode 100644 index 000000000..89de66332 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/service/PileRemoteService.java @@ -0,0 +1,203 @@ +package com.jsowell.service; + +import com.google.common.collect.Lists; +import com.jsowell.common.util.StringUtils; +import com.jsowell.netty.command.ykc.GetRealTimeMonitorDataCommand; +import com.jsowell.netty.command.ykc.IssueQRCodeCommand; +import com.jsowell.netty.command.ykc.ProofreadTimeCommand; +import com.jsowell.netty.command.ykc.PublishPileBillingTemplateCommand; +import com.jsowell.netty.command.ykc.RebootCommand; +import com.jsowell.netty.command.ykc.StartChargingCommand; +import com.jsowell.netty.command.ykc.StopChargingCommand; +import com.jsowell.netty.command.ykc.UpdateFileCommand; +import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; +import com.jsowell.pile.domain.PileBillingRelation; +import com.jsowell.pile.domain.PileBillingTemplate; +import com.jsowell.pile.dto.PublishBillingTemplateDTO; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileBillingTemplateService; +import com.jsowell.pile.vo.web.PileDetailVO; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +@Service +public class PileRemoteService { + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + /** + * 鑾峰彇鍏呯數妗╁疄鏃舵暟鎹俊鎭 + * + * @param pileSn 鍏呯數妗﹕n + * @param connectorCode 鏋彛鍙 + */ + public void getRealTimeMonitorData(String pileSn, String connectorCode) { + if (StringUtils.isNotEmpty(pileSn) || StringUtils.isNotEmpty(connectorCode)) { + GetRealTimeMonitorDataCommand command = GetRealTimeMonitorDataCommand.builder() + .pileSn(pileSn) + .connectorCode(connectorCode) + .build(); + ykcPushCommandService.pushGetRealTimeMonitorDataCommand(command); + } + + } + + /** + * 閲嶅惎鎸囦护 + * + * @param pileSn 鍏呯數妗﹕n + */ + public void reboot(String pileSn) { + RebootCommand command = RebootCommand.builder().pileSn(pileSn).build(); + ykcPushCommandService.pushRebootCommand(command); + } + + /** + * 杩滅▼鍚姩鍏呯數 0x34 + * + * @param pileSn 鍏呯數妗﹕n + */ + // public void remoteStartCharging(String orderCode, String pileSn, String connectorCode, BigDecimal accountBalance) { + // // String s = "550314127823050120180619144446808800000000000101000000100000057300000000D14B0A54A0860100"; + // if (StringUtils.isEmpty(pileSn) || StringUtils.isEmpty(connectorCode)) { + // log.warn("杩滅▼鍚姩鍏呯數, 鍏呯數妗╃紪鍙峰拰鏋彛鍙蜂笉鑳戒负绌"); + // return; + // } + // log.info("=====骞冲彴涓嬪彂鎸囦护=====: 杩滅▼鍚姩鍏呯數, 妗╁彿锛歿}, 鏋彛鍙凤細{}", pileSn, connectorCode); + // StartChargingCommand startChargingCommand = StartChargingCommand.builder() + // .pileSn(pileSn) + // .connectorCode(connectorCode) + // .orderCode(orderCode) + // .chargeAmount(accountBalance) + // .build(); + // ykcPushCommandService.pushStartChargingCommand(startChargingCommand); + // } + + /** + * 杩滅▼鍋滄鍏呯數 + */ + public void remoteStopCharging(String pileSn, String connectorCode) { + StopChargingCommand command = StopChargingCommand.builder() + .pileSn(pileSn) + .connectorCode(connectorCode) + .build(); + ykcPushCommandService.pushStopChargingCommand(command); + } + + /** + * 涓嬪彂鍏呯數妗╀簩缁寸爜 + * + * @param pileSn 鍏呯數妗﹕n + */ + public void issueQRCode(String pileSn) { + IssueQRCodeCommand command = IssueQRCodeCommand.builder().pileSn(pileSn).build(); + ykcPushCommandService.pushIssueQRCodeCommand(command); + + } + + /** + * 鍏呯數妗╁鏃 + * + * @param pileSn 鍏呯數妗﹕n + */ + public void proofreadTime(String pileSn) { + + ProofreadTimeCommand command = ProofreadTimeCommand.builder().pileSn(pileSn).build(); + ykcPushCommandService.pushProofreadTimeCommand(command); + } + + /** + * 涓嬪彂鍏呯數妗╄璐规ā鍨 + */ + public void publishPileBillingTemplate(String pileSn, BillingTemplateVO billingTemplateVO) { + + PublishPileBillingTemplateCommand command = PublishPileBillingTemplateCommand.builder() + .billingTemplateVO(billingTemplateVO) + .pileSn(pileSn) + .build(); + ykcPushCommandService.pushPublishPileBillingTemplate(command); + } + + /** + * 涓嬪彂璁¤垂妯℃澘 + * @param dto + * @return + */ + public boolean publishBillingTemplate(PublishBillingTemplateDTO dto) { + // 鑾峰彇璁¤垂妯℃澘淇℃伅 + BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateByTemplateId(dto.getTemplateId()); + if (billingTemplateVO == null) { + log.warn("鑾峰彇璁¤垂妯℃澘淇℃伅, 閫氳繃妯℃澘id:{}鏌ヨ璁¤垂妯℃澘涓簄ull", dto.getTemplateId()); + return false; + } + // 鏇存柊璁¤垂妯℃澘鐨勫彂甯冩椂闂 + PileBillingTemplate pileBillingTemplate = new PileBillingTemplate(); + pileBillingTemplate.setId(Long.valueOf(billingTemplateVO.getTemplateId())); + pileBillingTemplate.setPublishTime(new Date()); + pileBillingTemplateService.updatePileBillingTemplate(pileBillingTemplate); + + // 鑾峰彇鍒扮珯鐐逛笅鎵鏈夌殑妗 + List pileList = pileBasicInfoService.selectPileListByStationIds(Lists.newArrayList(Long.valueOf(dto.getStationId()))); + if (CollectionUtils.isEmpty(pileList)) { + log.warn("鑾峰彇鍒扮珯鐐逛笅鎵鏈夌殑妗, 閫氳繃绔欑偣id:{}鏌ヨ鍏呯數妗╁垪琛ㄤ负绌", dto.getStationId()); + return false; + } + + // 淇濆瓨璁¤垂妯℃澘鍜屾々鐨勫叧绯 + List relationList = Lists.newArrayList(); + for (PileDetailVO pileInfoVO : pileList) { + // push + publishPileBillingTemplate(pileInfoVO.getPileSn(), billingTemplateVO); + + // 鍏ュ簱 + relationList.add(PileBillingRelation.builder() + .pileSn(pileInfoVO.getPileSn()) + .billingTemplateCode(billingTemplateVO.getTemplateCode()) + .stationId(dto.getStationId()) + .build()); + } + + if (CollectionUtils.isNotEmpty(relationList)) { + pileBillingTemplateService.insertPileBillingRelation(relationList); + } + return true; + } + + public static void main(String[] args) { + /*Date date = new Date(); + String encodeCP56Time2a = DateUtils.encodeCP56Time2a(date); + System.out.println(encodeCP56Time2a); + System.out.println(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date)); + + String decodeCP56Time2a = DateUtils.decodeCP56Time2a(encodeCP56Time2a); + System.out.println(decodeCP56Time2a);*/ + + } + + /** + * 杩滅▼鏇存柊 + * + * @param pileSns 鍓嶅彴浼犵殑妗╁彿闆嗗悎 + */ + public void updateFile(List pileSns) { + // + UpdateFileCommand command = UpdateFileCommand.builder().pileSnList(pileSns).build(); + ykcPushCommandService.pushUpdateFileCommand(command); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/service/PileService.java b/jsowell-admin/src/main/java/com/jsowell/service/PileService.java new file mode 100644 index 000000000..68f3798ac --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/service/PileService.java @@ -0,0 +1,438 @@ +package com.jsowell.service; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.google.common.collect.Lists; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.enums.ykc.BusinessTypeEnum; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.SnUtils; +import com.jsowell.pile.domain.*; +import com.jsowell.pile.dto.BatchCreatePileDTO; +import com.jsowell.pile.dto.MemberRegisterAndLoginDTO; +import com.jsowell.pile.dto.PileMemberBindingDTO; +import com.jsowell.pile.dto.QueryPersonPileDTO; +import com.jsowell.pile.service.*; +import com.jsowell.pile.transaction.dto.PileTransactionDTO; +import com.jsowell.pile.transaction.service.TransactionService; +import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.base.MerchantInfoVO; +import com.jsowell.pile.vo.base.PileInfoVO; +import com.jsowell.pile.vo.uniapp.*; +import com.jsowell.pile.vo.web.PileStationVO; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +@Service +public class PileService { + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private TransactionService pileTransactionService; + + @Resource + private SnUtils snUtils; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + @Autowired + private IPileStationInfoService pileStationInfoService; + + @Autowired + private IPileMerchantInfoService pileMerchantInfoService; + + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private IPileMemberRelationService pileMemberRelationService; + + @Autowired + private IMemberBasicInfoService memberBasicInfoService; + + @Autowired + private MemberService memberService; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + /** + * 鏌ヨ璁惧淇℃伅 + * + * @param pileConnectorCode 鍏呯數鏋紪鍙 880000000000000101 + * @return 璁惧淇℃伅闆嗗悎 + */ + public PileConnectorDetailVO queryPileConnectorDetail(String pileConnectorCode) { + return pileBasicInfoService.queryPileConnectorDetail(pileConnectorCode); + } + + /** + * 鏌ヨ璁惧淇℃伅 + * + * @param pileSn 鍏呯數鏋紪鍙 8800000000000001 + * @param connectorCode 鍏呯數鏋彛鍙 01 + * @return 璁惧淇℃伅闆嗗悎 + */ + public PileConnectorDetailVO queryPileConnectorDetail(String pileSn, String connectorCode) { + return queryPileConnectorDetail(pileSn + connectorCode); + } + + public int batchCreatePile(BatchCreatePileDTO dto) { + // 鎵归噺鐢熸垚sn鍙 + List snList = snUtils.generateSN(dto.getNum()); + + // + List basicInfoList = Lists.newArrayList(); + List connectorInfoList = Lists.newArrayList(); + PileBasicInfo basicInfo = null; + PileConnectorInfo connectorInfo = null; + for (String sn : snList) { + // 缁勮pile_basic_info琛ㄦ暟鎹 + basicInfo = new PileBasicInfo(); + basicInfo.setSn(sn); // sn鍙 + basicInfo.setBusinessType(BusinessTypeEnum.OPERATING_PILE.getValue()); // 缁忚惀绫诲瀷 榛樿杩愯惀妗 + basicInfo.setSoftwareProtocol(dto.getSoftwareProtocol()); // 杞欢鍗忚 + basicInfo.setMerchantId(Long.valueOf(dto.getMerchantId())); // 杩愯惀鍟唅d + basicInfo.setStationId(Long.valueOf(dto.getStationId())); // 绔欑偣id + basicInfo.setModelId(Long.valueOf(dto.getModelId())); // 鍨嬪彿id + basicInfo.setProductionDate(dto.getProductionDate()); // 鐢熶骇鏃ユ湡 + basicInfo.setLicenceId(null); // TODO 璇佷功缂栧彿 + basicInfo.setSimId(null); // TODO sim鍗 + basicInfo.setRemark(dto.getRemark()); // 澶囨敞 + basicInfo.setCreateBy(SecurityUtils.getUsername()); // 鍒涘缓浜 + basicInfo.setDelFlag(Constants.DEL_FLAG_NORMAL); // 鍒犻櫎鏍囪瘑 + basicInfoList.add(basicInfo); + + for (int i = 1; i < dto.getConnectorNum() + 1; i++) { + // 缁勮pile_connector_info琛ㄦ暟鎹 + connectorInfo = new PileConnectorInfo(); + connectorInfo.setPileSn(sn); // sn鍙 + String connectorCode = String.format("%1$02d", i); + connectorInfo.setPileConnectorCode(sn + connectorCode); // 鏋彛鍙 + connectorInfo.setStatus(Constants.ZERO); //鐘舵侊紝榛樿 0-绂荤綉 + connectorInfo.setCreateBy(SecurityUtils.getUsername()); // 鍒涘缓浜 + connectorInfo.setDelFlag(Constants.DEL_FLAG_NORMAL); // 鍒犻櫎鏍囪瘑 + connectorInfoList.add(connectorInfo); + } + } + + // 鎵归噺鍏ュ簱 + PileTransactionDTO transactionDTO = PileTransactionDTO.builder() + .pileBasicInfoList(basicInfoList) + .pileConnectorInfoList(connectorInfoList) + .build(); + return pileTransactionService.doCreatePileTransaction(transactionDTO); + } + + /** + * 鍓嶇鎵爜璺宠浆鎺ュ彛 + */ + public PileConnectorVO getPileDetailByPileSn(String param) throws ExecutionException, InterruptedException { + if (StringUtils.isBlank(param)) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + String pileSn; + if (param.length() == 16) { + pileSn = StringUtils.substring(param, 0, param.length() - 2); + } else { + pileSn = param; + } + // 鏌ヨ鍏呯數妗╀俊鎭 + PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn); + if (pileInfoVO == null) { + return null; + } + + // 鏌ヨ鍏呯數妗╀笅鏋彛淇℃伅 + CompletableFuture> connectorInfoListFuture = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.selectConnectorInfoList(pileSn)); + + // 鏌ヨ璐规ā鏉夸俊鎭 + CompletableFuture> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId())); + + // 鏌ヨ绔欑偣淇℃伅 + CompletableFuture pileStationVOFuture = CompletableFuture.supplyAsync(() -> pileStationInfoService.getStationInfo(pileInfoVO.getStationId())); + + // 鏌ヨ杩愯惀鍟嗕俊鎭 + CompletableFuture merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfo(pileInfoVO.getMerchantId())); + + CompletableFuture all = CompletableFuture.allOf(connectorInfoListFuture, pileStationVOFuture, merchantInfoVOFuture, billingPriceFuture); + // .join()鍜.get()閮戒細闃诲骞惰幏鍙栫嚎绋嬬殑鎵ц鎯呭喌 + // .join()浼氭姏鍑烘湭缁忔鏌ョ殑寮傚父锛屼笉浼氬己鍒跺紑鍙戣呭鐞嗗紓甯 .get()浼氭姏鍑烘鏌ュ紓甯革紝闇瑕佸紑鍙戣呭鐞 + all.join(); + all.get(); + List connectorInfoList = connectorInfoListFuture.get(); + PileStationVO pileStationVO = pileStationVOFuture.get(); + MerchantInfoVO merchantInfoVO = merchantInfoVOFuture.get(); + List billingPriceVOS = billingPriceFuture.get(); + + PileConnectorVO vo = PileConnectorVO.builder() + .pileInfo(pileInfoVO) + .connectorInfoList(connectorInfoList) + .merchantInfo(merchantInfoVO) + .stationInfo(pileStationVO) + .billingPriceList(billingPriceVOS) + .build(); + return vo; + } + + public PileConnectorVO getConnectorDetail(String pileConnectorCode) throws ExecutionException, InterruptedException { + PileConnectorDetailVO pileConnectorDetailVO = queryPileConnectorDetail(pileConnectorCode); + if (pileConnectorDetailVO == null) { + return null; + } + String pileSn = pileConnectorDetailVO.getPileSn(); + PileConnectorVO resultVO = getPileDetailByPileSn(pileSn); + List connectorInfoList = resultVO.getConnectorInfoList(); + if (connectorInfoList.size() > 1) { + List list = Lists.newArrayList(); + // 鏋彛澶т簬1涓紝姝ゅ厖鐢垫々闈炲崟鏋澶囷紝鏍规嵁鍙傛暟灞曠ず瀵瑰簲鏋彛鐨勪俊鎭 + for (ConnectorInfoVO connectorInfoVO : connectorInfoList) { + if (StringUtils.equals(pileConnectorCode, pileSn + connectorInfoVO.getConnectorCode())) { + list.add(connectorInfoVO); + } + } + resultVO.setConnectorInfoList(list); + } + return resultVO; + } + + public PileInfoVO selectPileInfoBySn(String pileSn) { + return pileBasicInfoService.selectPileInfoBySn(pileSn); + } + + /** + * 鐢ㄦ埛缁戝畾涓汉妗 + * + * @param dto + * @return + */ + public int pileMemberBinding(PileMemberBindingDTO dto){ + // 鏍¢獙鐭俊楠岃瘉鐮 + MemberRegisterAndLoginDTO registerAndLoginDTO = MemberRegisterAndLoginDTO.builder() + .mobileNumber(dto.getPhoneNumber()) + .verificationCode(dto.getVerificationCode()) + .build(); + memberService.checkVerificationCode(registerAndLoginDTO); + + // 妫鏌ユ々鏄惁宸茬粡琚粦瀹 + PileMemberRelation pileMemberRelation = new PileMemberRelation(); + pileMemberRelation.setPileSn(dto.getPileSn()); + List list = pileMemberRelationService.selectPileMemberRelationList(pileMemberRelation); + if (CollectionUtils.isNotEmpty(list)){ + // 璇存槑宸茬粡琚粦瀹氳繃锛屾姏鍑哄紓甯 + throw new BusinessException(ReturnCodeEnum.CODE_PILE_HAS_BEEN_BINDING_ERROR); + } + // 濡傛灉娌¤缁戝畾锛屽垯姝ょ敤鎴蜂负绠$悊鍛 + pileMemberRelation.setMemberId(dto.getMemberId()); + pileMemberRelation.setType("1"); // 1-绠$悊鍛 + return pileMemberRelationService.insertPileMemberRelation(pileMemberRelation); + } + + /** + * 涓汉妗╃鐞嗗憳涓嬪彂缁欏叾浠栫敤鎴蜂娇鐢 + * + * @param dto + */ + public void adminIssuePile(PileMemberBindingDTO dto) { + List relationList = pileMemberRelationService.selectPileMemberRelationByPileSn(dto.getPileSn()); + if (CollectionUtils.isEmpty(relationList)) { + // 鍏呯數妗╂病鏈夌粦瀹氫换浣曚汉 + } + + List adminList = relationList.stream() + .filter(x -> x.getType().equals("1")) + .map(PileMemberRelation::getMemberId) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(adminList)) { + // 娌℃湁绠$悊鍛 + } + + // 鏍¢獙韬唤 + if (!adminList.contains(dto.getMemberId())) { + // 濡傛灉涓虹┖锛岃鏄庢鐢ㄦ埛韬唤鏈夎锛屼笉鏄鐞嗗憳锛屾姏鍑哄紓甯 + throw new BusinessException(ReturnCodeEnum.CODE_AUTHENTICATION_ERROR); + } + + List userList = relationList.stream() + .filter(x -> !x.getType().equals("1")) + .map(PileMemberRelation::getMemberId) + .collect(Collectors.toList()); + + + // 閫氳繃鍓嶇浼犵殑鎵嬫満鍙锋煡璇㈡槸鍚︽湁姝ょ敤鎴 + MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMobileNumber(dto.getPhoneNumber()); + if (memberBasicInfo == null) { + // 涓虹┖璇存槑姝ょ敤鎴锋湭娉ㄥ唽骞冲彴璐﹀彿 + throw new BusinessException(ReturnCodeEnum.CODE_USER_IS_NOT_REGISTER); + } + + if (userList.contains(memberBasicInfo.getMemberId())) { + // 涓嶄负绌鸿鏄庡凡缁戝畾 + throw new BusinessException(ReturnCodeEnum.CODE_USER_HAS_BEEN_THIS_PILE); + } else { + // 杩涜缁戝畾锛屾鐢ㄦ埛涓烘櫘閫氱敤鎴 + PileMemberRelation info = new PileMemberRelation(); + info.setPileSn(dto.getPileSn()); + info.setMemberId(memberBasicInfo.getMemberId()); + info.setType("2"); + pileMemberRelationService.insertPileMemberRelation(info); + } + } + + /** + * 鑾峰彇鏋彛瀹炴椂鏁版嵁 + * @param dto + * @return + */ + public PersonPileRealTimeVO getConnectorRealTimeInfo(QueryPersonPileDTO dto) { + // 鏍规嵁memberId鏌ュ嚭璇ョ敤鎴 姝e湪鍏呯數銆佷釜浜烘々鍚姩锛堢櫧鍚嶅崟鏀粯鏂瑰紡锛夌殑璁㈠崟鍙 + OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder() + .memberId(dto.getMemberId()) + .orderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue()) + .pileConnectorCode(dto.getPileConnectorCode()) + .startMode("3") // 3- 鐧藉悕鍗曟敮浠 + .build(); + OrderBasicInfo basicInfo = orderBasicInfoService.getOrderBasicInfo(orderBasicInfo); + if (basicInfo == null){ + throw new BusinessException(ReturnCodeEnum.CODE_NO_CHARGING_ORDER_ERROR); + } + String orderCode = basicInfo.getOrderCode(); + // 鏍规嵁璁㈠崟鍙蜂粠redis涓幏鍙栧疄鏃舵暟鎹俊鎭(榛樿鏃堕棿鍊掑彊鎺掑垪锛屾墍浠ュ彇绗竴鏉) + List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderCode); + if (CollectionUtils.isEmpty(chargingRealTimeData)) { + throw new BusinessException(ReturnCodeEnum.CODE_NO_REAL_TIME_INFO); + } + RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0); + // 灏嗛渶瑕佺殑鏁版嵁set + PersonPileRealTimeVO vo = PersonPileRealTimeVO.builder() + .chargingDegree(realTimeMonitorData.getChargingDegree()) + .chargingTime(realTimeMonitorData.getSumChargingTime()) + .startTime(DateUtils.formatDateTime(orderBasicInfo.getChargeStartTime())) + .instantCurrent(realTimeMonitorData.getOutputCurrent()) + .instantVoltage(realTimeMonitorData.getOutputVoltage()) + .instantPower(realTimeMonitorData.getOutputPower()) + .build(); + return vo; + } + + /** + * 鑾峰彇鏌愭灙鍙f煇娈垫椂闂村唴绱淇℃伅 + * @param dto + * @return + */ + public PersonPileConnectorSumInfoVO getAccumulativeInfo(QueryPersonPileDTO dto) { + List accumulativeInfo = orderBasicInfoService.getAccumulativeInfo(dto); + if (CollectionUtils.isEmpty(accumulativeInfo)) { + throw new BusinessException("00400011", "鏈煡鍒扮浉鍏宠鍗曚俊鎭紒"); + } + // BigDecimal sumChargingTime = BigDecimal.ZERO; + // BigDecimal sumUsedElectricity = BigDecimal.ZERO; + // // 灏嗚繑鍥炵殑缁撴灉杩涜for寰幆锛屽皢鎬诲厖鐢甸噺銆佹诲厖鐢垫椂闀胯繘琛岀疮鍔狅紙鍏呯數鏃堕暱闇瑕侀氳繃 鍏呯數寮濮嬫椂闂 鍜 鍏呯數缁撴潫鏃堕棿 杩涜璁$畻锛 + // for (PersonPileConnectorSumInfoVO personPileConnectorSumInfoVO : accumulativeInfo) { + // if (StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeStartTime()) && StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeEndTime())){ + // long longChargingTime = DateUtils.intervalTime(personPileConnectorSumInfoVO.getChargeStartTime(), personPileConnectorSumInfoVO.getChargeEndTime()); + // BigDecimal chargingTime = new BigDecimal(String.valueOf(longChargingTime)); + // sumChargingTime = sumChargingTime.add(chargingTime); + // } + // BigDecimal chargingDegree = StringUtils.isBlank(personPileConnectorSumInfoVO.getSumChargingDegree()) + // ? BigDecimal.ZERO + // : new BigDecimal(personPileConnectorSumInfoVO.getSumChargingDegree()); + // sumUsedElectricity = sumUsedElectricity.add(chargingDegree); + // } + Map sumInfo = getSumInfo(accumulativeInfo); + // set 瀵硅薄 + PersonPileConnectorSumInfoVO vo = new PersonPileConnectorSumInfoVO(); + vo.setStartTime(dto.getStartTime()); + vo.setEndTime(dto.getEndTime()); + vo.setMemberId(dto.getMemberId()); + vo.setSumChargingDegree(sumInfo.get("sumUsedElectricity")); + vo.setSumChargingTime(sumInfo.get("sumChargingTime")); + return vo; + } + + /** + * 鑾峰彇鍏呯數璁板綍锛堥粯璁30澶╋級 + * + * @param dto + */ + public PageResponse getChargingRecord(QueryPersonPileDTO dto) { + int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum(); + int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize(); + // 鑾峰彇涓夊崄澶╁墠鐨勬暟鎹 + Date date = DateUtils.addMonths(new Date(), -1); + String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date); + dto.setStartTime(dateStr); + dto.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date())); + + // 鍒嗛〉鏌ヨ + PageHelper.startPage(pageNum, pageSize); + List accumulativeInfo = orderBasicInfoService.getAccumulativeInfo(dto); + if (CollectionUtils.isEmpty(accumulativeInfo)) { + throw new BusinessException("00400011", "鏈煡鍒扮浉鍏宠鍗曚俊鎭紒"); + } + PageInfo pageInfo = new PageInfo<>(accumulativeInfo); + for (PersonPileConnectorSumInfoVO personPileConnectorSumInfoVO : pageInfo.getList()) { + if (StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeStartTime()) && StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeEndTime())){ + String datePoor = DateUtils.getDatePoor(DateUtils.parseDate(personPileConnectorSumInfoVO.getChargeEndTime()), + DateUtils.parseDate(personPileConnectorSumInfoVO.getChargeStartTime())); + personPileConnectorSumInfoVO.setSumChargingTime(datePoor); + } + } + return PageResponse.builder() + .pageNum(pageInfo.getPageNum()) + .pageSize(pageInfo.getPageSize()) + .list(pageInfo.getList()) + .pages(pageInfo.getPages()) + .total(pageInfo.getTotal()) + .build(); + } + + /** + * 鑾峰彇鎬诲厖鐢垫椂闀裤佹诲厖鐢甸噺 + * + * @param accumulativeInfo + * @return + */ + private Map getSumInfo(List accumulativeInfo){ + Map resultMap = new HashMap<>(); + BigDecimal sumChargingTime = BigDecimal.ZERO; + BigDecimal sumUsedElectricity = BigDecimal.ZERO; + // 灏嗚繑鍥炵殑缁撴灉杩涜for寰幆锛屽皢鎬诲厖鐢甸噺銆佹诲厖鐢垫椂闀胯繘琛岀疮鍔狅紙鍏呯數鏃堕暱闇瑕侀氳繃 鍏呯數寮濮嬫椂闂 鍜 鍏呯數缁撴潫鏃堕棿 杩涜璁$畻锛 + for (PersonPileConnectorSumInfoVO personPileConnectorSumInfoVO : accumulativeInfo) { + if (StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeStartTime()) && StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeEndTime())){ + long longChargingTime = DateUtils.intervalTime(personPileConnectorSumInfoVO.getChargeStartTime(), personPileConnectorSumInfoVO.getChargeEndTime()); + BigDecimal chargingTime = new BigDecimal(String.valueOf(longChargingTime)); + sumChargingTime = sumChargingTime.add(chargingTime); + } + BigDecimal chargingDegree = StringUtils.isBlank(personPileConnectorSumInfoVO.getSumChargingDegree()) + ? BigDecimal.ZERO + : new BigDecimal(personPileConnectorSumInfoVO.getSumChargingDegree()); + sumUsedElectricity = sumUsedElectricity.add(chargingDegree); + } + resultMap.put("sumChargingTime", String.valueOf(sumChargingTime)); + resultMap.put("sumUsedElectricity", String.valueOf(sumUsedElectricity)); + return resultMap; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/common/CaptchaController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/common/CaptchaController.java new file mode 100644 index 000000000..ab6cf0260 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/common/CaptchaController.java @@ -0,0 +1,91 @@ +package com.jsowell.web.controller.common; + +import com.google.code.kaptcha.Producer; +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.util.sign.Base64; +import com.jsowell.common.util.id.IdUtils; +import com.jsowell.system.service.SysConfigService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.FastByteArrayOutputStream; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletResponse; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * 楠岃瘉鐮佹搷浣滃鐞 + * + * @author jsowell + */ +@RestController +public class CaptchaController { + @Resource(name = "captchaProducer") + private Producer captchaProducer; + + @Resource(name = "captchaProducerMath") + private Producer captchaProducerMath; + + @Autowired + private RedisCache redisCache; + + @Autowired + private SysConfigService configService; + + Logger log = LoggerFactory.getLogger(CaptchaController.class); + + /** + * 鐢熸垚楠岃瘉鐮 + */ + @GetMapping("/captchaImage") + public AjaxResult getCode(HttpServletResponse response) throws IOException { + AjaxResult ajax = AjaxResult.success(); + boolean captchaEnabled = configService.selectCaptchaEnabled(); + ajax.put("captchaEnabled", captchaEnabled); + if (!captchaEnabled) { + return ajax; + } + + // 淇濆瓨楠岃瘉鐮佷俊鎭 + String uuid = IdUtils.simpleUUID(); + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; + + String capStr = null, code = null; + BufferedImage image = null; + + // 鐢熸垚楠岃瘉鐮 + String captchaType = JsowellConfig.getCaptchaType(); + if ("math".equals(captchaType)) { + String capText = captchaProducerMath.createText(); + capStr = capText.substring(0, capText.lastIndexOf("@")); + code = capText.substring(capText.lastIndexOf("@") + 1); + image = captchaProducerMath.createImage(capStr); + } else if ("char".equals(captchaType)) { + capStr = code = captchaProducer.createText(); + image = captchaProducer.createImage(capStr); + } + log.info("鑾峰彇楠岃瘉鐮 uuid:{}, captcha:{}", uuid, capStr); + redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); + // 杞崲娴佷俊鎭啓鍑 + FastByteArrayOutputStream os = new FastByteArrayOutputStream(); + try { + ImageIO.write(image, "jpg", os); + } catch (IOException e) { + return AjaxResult.error(e.getMessage()); + } + + ajax.put("uuid", uuid); + ajax.put("img", Base64.encode(os.toByteArray())); + return ajax; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/common/CommonController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/common/CommonController.java new file mode 100644 index 000000000..edf07688c --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/common/CommonController.java @@ -0,0 +1,143 @@ +package com.jsowell.web.controller.common; + +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.file.FileUploadUtils; +import com.jsowell.common.util.file.FileUtils; +import com.jsowell.framework.config.ServerConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; + +/** + * 閫氱敤璇锋眰澶勭悊 + * + * @author jsowell + */ +@RestController +@RequestMapping("/common") +public class CommonController { + private static final Logger log = LoggerFactory.getLogger(CommonController.class); + + @Autowired + private ServerConfig serverConfig; + + private static final String FILE_DELIMETER = ","; + + /** + * 閫氱敤涓嬭浇璇锋眰 + * + * @param fileName 鏂囦欢鍚嶇О + * @param delete 鏄惁鍒犻櫎 + */ + @GetMapping("/download") + public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { + try { + if (!FileUtils.checkAllowDownload(fileName)) { + throw new Exception(StringUtils.format("鏂囦欢鍚嶇О({})闈炴硶锛屼笉鍏佽涓嬭浇銆 ", fileName)); + } + String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); + String filePath = JsowellConfig.getDownloadPath() + fileName; + + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + FileUtils.setAttachmentResponseHeader(response, realFileName); + FileUtils.writeBytes(filePath, response.getOutputStream()); + if (delete) { + FileUtils.deleteFile(filePath); + } + } catch (Exception e) { + log.error("涓嬭浇鏂囦欢澶辫触", e); + } + } + + /** + * 閫氱敤涓婁紶璇锋眰锛堝崟涓級 + */ + @PostMapping("/upload") + public AjaxResult uploadFile(MultipartFile file) throws Exception { + try { + // 涓婁紶鏂囦欢璺緞 + String filePath = JsowellConfig.getUploadPath(); + // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О + String fileName = FileUploadUtils.upload(filePath, file); + String url = serverConfig.getUrl() + fileName; + AjaxResult ajax = AjaxResult.success(); + ajax.put("url", url); + ajax.put("fileName", fileName); + ajax.put("newFileName", FileUtils.getName(fileName)); + ajax.put("originalFilename", file.getOriginalFilename()); + return ajax; + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); + } + } + + /** + * 閫氱敤涓婁紶璇锋眰锛堝涓級 + */ + @PostMapping("/uploads") + public AjaxResult uploadFiles(List files) throws Exception { + try { + // 涓婁紶鏂囦欢璺緞 + String filePath = JsowellConfig.getUploadPath(); + List urls = new ArrayList(); + List fileNames = new ArrayList(); + List newFileNames = new ArrayList(); + List originalFilenames = new ArrayList(); + for (MultipartFile file : files) { + // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О + String fileName = FileUploadUtils.upload(filePath, file); + String url = serverConfig.getUrl() + fileName; + urls.add(url); + fileNames.add(fileName); + newFileNames.add(FileUtils.getName(fileName)); + originalFilenames.add(file.getOriginalFilename()); + } + AjaxResult ajax = AjaxResult.success(); + ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER)); + ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); + ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); + ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); + return ajax; + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); + } + } + + /** + * 鏈湴璧勬簮閫氱敤涓嬭浇 + */ + @GetMapping("/download/resource") + public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + if (!FileUtils.checkAllowDownload(resource)) { + throw new Exception(StringUtils.format("璧勬簮鏂囦欢({})闈炴硶锛屼笉鍏佽涓嬭浇銆 ", resource)); + } + // 鏈湴璧勬簮璺緞 + String localPath = JsowellConfig.getProfile(); + // 鏁版嵁搴撹祫婧愬湴鍧 + String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX); + // 涓嬭浇鍚嶇О + String downloadName = StringUtils.substringAfterLast(downloadPath, "/"); + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + FileUtils.setAttachmentResponseHeader(response, downloadName); + FileUtils.writeBytes(downloadPath, response.getOutputStream()); + } catch (Exception e) { + log.error("涓嬭浇鏂囦欢澶辫触", e); + } + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/index/indexController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/index/indexController.java new file mode 100644 index 000000000..04e2efc7c --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/index/indexController.java @@ -0,0 +1,71 @@ +package com.jsowell.web.controller.index; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.vo.web.IndexGeneralSituationVO; +import com.jsowell.pile.dto.IndexQueryDTO; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.vo.web.IndexOrderInfoVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 棣栭〉鏁版嵁灞曠ずController + * + * @author JS-ZZA + * @date 2023/2/3 10:11 + */ +@RestController +@RequestMapping("/index") +public class indexController extends BaseController { + @Autowired + IPileBasicInfoService pileBasicInfoService; + + @Autowired + IOrderBasicInfoService orderBasicInfoService; + + @PostMapping("/getGeneralSituation") + public RestApiResponse getGeneralSituation(@RequestBody IndexQueryDTO dto) { + logger.info("棣栭〉鍩虹鏁版嵁鏌ヨ param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response; + try { + IndexGeneralSituationVO generalSituation = pileBasicInfoService.getGeneralSituation(dto); + response = new RestApiResponse<>(generalSituation); + }catch (Exception e) { + logger.error("棣栭〉鏁版嵁鏌ヨ閿欒:{}", e.getMessage()); + response = new RestApiResponse<>("00200001", "棣栭〉鍩虹鏁版嵁鏌ヨ閿欒"); + } + logger.info("棣栭〉鏁版嵁鏌ヨ result:{}", JSONObject.toJSONString(response)); + return response; + } + + /** + * 棣栭〉璁㈠崟鏁版嵁姹囨讳俊鎭 + * + * @param dto + * @return + */ + @PostMapping("/getOrderInfo") + public RestApiResponse getOrderInfo(@RequestBody IndexQueryDTO dto) { + logger.info("棣栭〉璁㈠崟鐩稿叧淇℃伅鏌ヨ param:{}", JSONObject.toJSONString(dto)); + RestApiResponse response; + try { + List indexOrderInfo = orderBasicInfoService.getIndexOrderInfo(dto); + response = new RestApiResponse<>(indexOrderInfo); + } catch (Exception e) { + logger.error("棣栭〉璁㈠崟鐩稿叧淇℃伅鏌ヨ閿欒锛亄}", e.getMessage()); + response = new RestApiResponse<>("00200002", "棣栭〉璁㈠崟鏁版嵁鏌ヨ閿欒"); + } + logger.info("棣栭〉璁㈠崟鐩稿叧淇℃伅鏌ヨ result:{}", JSONObject.toJSONString(response)); + return response; + } + + +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/CacheController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/CacheController.java new file mode 100644 index 000000000..58c46e9bf --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/CacheController.java @@ -0,0 +1,114 @@ +package com.jsowell.web.controller.monitor; + +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.domain.SysCache; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisCallback; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +/** + * 缂撳瓨鐩戞帶 + * + * @author jsowell + */ +@RestController +@RequestMapping("/monitor/cache") +public class CacheController { + @Autowired + private RedisTemplate redisTemplate; + + private final static List caches = new ArrayList(); + + { + caches.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "鐢ㄦ埛淇℃伅")); + caches.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "閰嶇疆淇℃伅")); + caches.add(new SysCache(CacheConstants.SYS_DICT_KEY, "鏁版嵁瀛楀吀")); + caches.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "楠岃瘉鐮")); + caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "闃查噸鎻愪氦")); + caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "闄愭祦澶勭悊")); + caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "瀵嗙爜閿欒娆℃暟")); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping() + public AjaxResult getInfo() throws Exception { + Properties info = (Properties) redisTemplate.execute((RedisCallback) connection -> connection.info()); + Properties commandStats = (Properties) redisTemplate.execute((RedisCallback) connection -> connection.info("commandstats")); + Object dbSize = redisTemplate.execute((RedisCallback) connection -> connection.dbSize()); + + Map result = new HashMap<>(3); + result.put("info", info); + result.put("dbSize", dbSize); + + List> pieList = new ArrayList<>(); + commandStats.stringPropertyNames().forEach(key -> { + Map data = new HashMap<>(2); + String property = commandStats.getProperty(key); + data.put("name", StringUtils.removeStart(key, "cmdstat_")); + data.put("value", StringUtils.substringBetween(property, "calls=", ",usec")); + pieList.add(data); + }); + result.put("commandStats", pieList); + return AjaxResult.success(result); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping("/getNames") + public AjaxResult cache() { + return AjaxResult.success(caches); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping("/getKeys/{cacheName}") + public AjaxResult getCacheKeys(@PathVariable String cacheName) { + Set cacheKeys = redisTemplate.keys(cacheName + "*"); + return AjaxResult.success(cacheKeys); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping("/getValue/{cacheName}/{cacheKey}") + public AjaxResult getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey) { + String cacheValue = redisTemplate.opsForValue().get(cacheKey); + SysCache sysCache = new SysCache(cacheName, cacheKey, cacheValue); + return AjaxResult.success(sysCache); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @DeleteMapping("/clearCacheName/{cacheName}") + public AjaxResult clearCacheName(@PathVariable String cacheName) { + Collection cacheKeys = redisTemplate.keys(cacheName + "*"); + redisTemplate.delete(cacheKeys); + return AjaxResult.success(); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @DeleteMapping("/clearCacheKey/{cacheKey}") + public AjaxResult clearCacheKey(@PathVariable String cacheKey) { + redisTemplate.delete(cacheKey); + return AjaxResult.success(); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @DeleteMapping("/clearCacheAll") + public AjaxResult clearCacheAll() { + Collection cacheKeys = redisTemplate.keys("*"); + redisTemplate.delete(cacheKeys); + return AjaxResult.success(); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/ServerController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/ServerController.java new file mode 100644 index 000000000..8e64d3b76 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/ServerController.java @@ -0,0 +1,25 @@ +package com.jsowell.web.controller.monitor; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.framework.web.domain.Server; + +/** + * 鏈嶅姟鍣ㄧ洃鎺 + * + * @author jsowell + */ +@RestController +@RequestMapping("/monitor/server") +public class ServerController { + @PreAuthorize("@ss.hasPermi('monitor:server:list')") + @GetMapping() + public AjaxResult getInfo() throws Exception { + Server server = new Server(); + server.copyTo(); + return AjaxResult.success(server); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysLogininforController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysLogininforController.java new file mode 100644 index 000000000..8c6cc1982 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysLogininforController.java @@ -0,0 +1,72 @@ +package com.jsowell.web.controller.monitor; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.framework.web.service.SysPasswordService; +import com.jsowell.system.domain.SysLogininfor; +import com.jsowell.system.service.SysLogininforService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 绯荤粺璁块棶璁板綍 + * + * @author jsowell + */ +@RestController +@RequestMapping("/monitor/logininfor") +public class SysLogininforController extends BaseController { + @Autowired + private SysLogininforService logininforService; + + @Autowired + private SysPasswordService passwordService; + + @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')") + @GetMapping("/list") + public TableDataInfo list(SysLogininfor logininfor) { + startPage(); + List list = logininforService.selectLogininforList(logininfor); + return getDataTable(list); + } + + @Log(title = "鐧诲綍鏃ュ織", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysLogininfor logininfor) { + List list = logininforService.selectLogininforList(logininfor); + ExcelUtil util = new ExcelUtil(SysLogininfor.class); + util.exportExcel(response, list, "鐧诲綍鏃ュ織"); + } + + @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')") + @Log(title = "鐧诲綍鏃ュ織", businessType = BusinessType.DELETE) + @DeleteMapping("/{infoIds}") + public AjaxResult remove(@PathVariable Long[] infoIds) { + return toAjax(logininforService.deleteLogininforByIds(infoIds)); + } + + @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')") + @Log(title = "鐧诲綍鏃ュ織", businessType = BusinessType.CLEAN) + @DeleteMapping("/clean") + public AjaxResult clean() { + logininforService.cleanLogininfor(); + return success(); + } + + @PreAuthorize("@ss.hasPermi('monitor:logininfor:unlock')") + @Log(title = "璐︽埛瑙i攣", businessType = BusinessType.OTHER) + @GetMapping("/unlock/{userName}") + public AjaxResult unlock(@PathVariable("userName") String userName) { + passwordService.clearLoginRecordCache(userName); + return success(); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysOperlogController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysOperlogController.java new file mode 100644 index 000000000..21e95c2a8 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysOperlogController.java @@ -0,0 +1,65 @@ +package com.jsowell.web.controller.monitor; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.system.domain.SysOperLog; +import com.jsowell.system.service.SysOperLogService; + +/** + * 鎿嶄綔鏃ュ織璁板綍 + * + * @author jsowell + */ +@RestController +@RequestMapping("/monitor/operlog") +public class SysOperlogController extends BaseController { + @Autowired + private SysOperLogService operLogService; + + @PreAuthorize("@ss.hasPermi('monitor:operlog:list')") + @GetMapping("/list") + public TableDataInfo list(SysOperLog operLog) { + startPage(); + List list = operLogService.selectOperLogList(operLog); + return getDataTable(list); + } + + @Log(title = "鎿嶄綔鏃ュ織", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('monitor:operlog:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysOperLog operLog) { + List list = operLogService.selectOperLogList(operLog); + ExcelUtil util = new ExcelUtil(SysOperLog.class); + util.exportExcel(response, list, "鎿嶄綔鏃ュ織"); + } + + @Log(title = "鎿嶄綔鏃ュ織", businessType = BusinessType.DELETE) + @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')") + @DeleteMapping("/{operIds}") + public AjaxResult remove(@PathVariable Long[] operIds) { + return toAjax(operLogService.deleteOperLogByIds(operIds)); + } + + @Log(title = "鎿嶄綔鏃ュ織", businessType = BusinessType.CLEAN) + @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')") + @DeleteMapping("/clean") + public AjaxResult clean() { + operLogService.cleanOperLog(); + return AjaxResult.success(); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysUserOnlineController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysUserOnlineController.java new file mode 100644 index 000000000..f7a112583 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/monitor/SysUserOnlineController.java @@ -0,0 +1,75 @@ +package com.jsowell.web.controller.monitor; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.domain.SysUserOnline; +import com.jsowell.system.service.SysUserOnlineService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * 鍦ㄧ嚎鐢ㄦ埛鐩戞帶 + * + * @author jsowell + */ +@RestController +@RequestMapping("/monitor/online") +public class SysUserOnlineController extends BaseController { + @Autowired + private SysUserOnlineService userOnlineService; + + @Autowired + private RedisCache redisCache; + + @PreAuthorize("@ss.hasPermi('monitor:online:list')") + @GetMapping("/list") + public TableDataInfo list(String ipaddr, String userName) { + Collection keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); + List userOnlineList = new ArrayList(); + for (String key : keys) { + LoginUser user = redisCache.getCacheObject(key); + if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) { + if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) { + userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); + } + } else if (StringUtils.isNotEmpty(ipaddr)) { + if (StringUtils.equals(ipaddr, user.getIpaddr())) { + userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user)); + } + } else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser())) { + if (StringUtils.equals(userName, user.getUsername())) { + userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); + } + } else { + userOnlineList.add(userOnlineService.loginUserToUserOnline(user)); + } + } + Collections.reverse(userOnlineList); + userOnlineList.removeAll(Collections.singleton(null)); + return getDataTable(userOnlineList); + } + + /** + * 寮洪鐢ㄦ埛 + */ + @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')") + @Log(title = "鍦ㄧ嚎鐢ㄦ埛", businessType = BusinessType.FORCE) + @DeleteMapping("/{tokenId}") + public AjaxResult forceLogout(@PathVariable String tokenId) { + redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId); + return AjaxResult.success(); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/MemberBasicInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/MemberBasicInfoController.java new file mode 100644 index 000000000..938958346 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/MemberBasicInfoController.java @@ -0,0 +1,159 @@ +package com.jsowell.web.controller.pile; + +import com.github.pagehelper.PageHelper; +import com.google.common.collect.Lists; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.enums.uniapp.BalanceChangesEnum; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.MemberBasicInfo; +import com.jsowell.pile.dto.UniAppQueryMemberBalanceDTO; +import com.jsowell.pile.service.IMemberBasicInfoService; +import com.jsowell.pile.service.IMemberTransactionRecordService; +import com.jsowell.pile.vo.uniapp.MemberVO; +import com.jsowell.pile.vo.uniapp.MemberWalletLogVO; +import com.jsowell.pile.vo.web.MemberTransactionVO; +import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 浼氬憳鍩虹淇℃伅Controller + * + * @author jsowell + * @date 2022-10-12 + */ +@RestController +@RequestMapping("/member/info") +public class MemberBasicInfoController extends BaseController { + @Autowired + private IMemberBasicInfoService memberBasicInfoService; + + @Autowired + private IMemberTransactionRecordService memberTransactionRecordService; + + /** + * 鏌ヨ浼氬憳鍩虹淇℃伅鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('member:info:list')") + @GetMapping("/list") + public TableDataInfo list(MemberBasicInfo memberBasicInfo) { + startPage(); + List list = memberBasicInfoService.selectMemberList(memberBasicInfo.getMobileNumber(), memberBasicInfo.getNickName()); + return getDataTable(list); + } + + /** + * 瀵煎嚭浼氬憳鍩虹淇℃伅鍒楄〃 + */ + /*@PreAuthorize("@ss.hasPermi('member:info:export')") + @Log(title = "浼氬憳鍩虹淇℃伅", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, MemberBasicInfo memberBasicInfo) { + List list = memberBasicInfoService.selectMemberBasicInfoList(memberBasicInfo); + ExcelUtil util = new ExcelUtil(MemberBasicInfo.class); + util.exportExcel(response, list, "浼氬憳鍩虹淇℃伅鏁版嵁"); + }*/ + + /** + * 鑾峰彇浼氬憳鍩虹淇℃伅璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('member:info:query')") + @GetMapping(value = "/{memberId}") + public AjaxResult getInfo(@PathVariable("memberId") String memberId) { + return AjaxResult.success(memberBasicInfoService.queryMemberInfoByMemberId(memberId)); + } + + @PreAuthorize("@ss.hasPermi('member:info:query')") + @GetMapping(value = "/getMemberPersonPileInfo/{memberId}") + public AjaxResult getMemberPersonPileInfo(@PathVariable("memberId") String memberId){ + return AjaxResult.success(memberBasicInfoService.getMemberPersonPileInfo(memberId)); + } + + /** + * 鏂板浼氬憳鍩虹淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('member:info:add')") + @Log(title = "浼氬憳鍩虹淇℃伅", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody MemberBasicInfo memberBasicInfo) { + return toAjax(memberBasicInfoService.insertMemberBasicInfo(memberBasicInfo)); + } + + /** + * 淇敼浼氬憳鍩虹淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('member:info:edit')") + @Log(title = "浼氬憳鍩虹淇℃伅", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody MemberBasicInfo memberBasicInfo) { + return toAjax(memberBasicInfoService.updateMemberBasicInfo(memberBasicInfo)); + } + + /** + * 鍒犻櫎浼氬憳鍩虹淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('member:info:remove')") + @Log(title = "浼氬憳鍩虹淇℃伅", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Integer[] ids) { + return toAjax(memberBasicInfoService.deleteMemberBasicInfoByIds(Lists.newArrayList(ids))); + } + + /** + * 鍏呭/鎵f浣欓 + */ + @PreAuthorize("@ss.hasPermi('member:balance:update')") + @Log(title = "浼氬憳鍏呭/鎵f浣欓", businessType = BusinessType.UPDATE) + @PutMapping("/updateGiftBalance") + public AjaxResult updateGiftBalance(@RequestBody UpdateMemberBalanceDTO dto) { + logger.info("鍚庣鍏呭/鎵f浣欓 param:{}", dto.toString()); + // 鍒ゆ柇鍏ュ弬 + return toAjax(memberBasicInfoService.updateMemberBalance(dto)); + } + + /** + * 鏌ヨ浼氬憳閽卞寘娴佹按 + */ + @PostMapping("/queryMemberBalanceChanges") + public TableDataInfo queryMemberBalanceChanges(@RequestBody UniAppQueryMemberBalanceDTO dto) { + String type = dto.getType(); + if (!StringUtils.equals("1", type) && !StringUtils.equals("2", type)) { + type = ""; + } + PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); + List list = memberBasicInfoService.getMemberBalanceChanges(dto.getMemberId(), type); + for (MemberWalletLogVO walletLogVO : list) { + String subType = walletLogVO.getSubType(); + String subTypeValue = BalanceChangesEnum.getValueByCode(subType); + if (StringUtils.isNotBlank(subTypeValue)) { + walletLogVO.setSubType(subTypeValue); + } + } + return getDataTable(list); + } + + /** + * 鏌ヨ浼氬憳浜ゆ槗娴佹按 + * IMemberTransactionRecordService + */ + @PostMapping("/selectMemberTransactionRecordList") + public TableDataInfo selectMemberTransactionRecordList(@RequestBody UniAppQueryMemberBalanceDTO dto) { + startPage(); + List list = memberTransactionRecordService.selectMemberTransactionRecordList(dto.getMemberId()); + return getDataTable(list); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/OrderAbnormalRecordController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/OrderAbnormalRecordController.java new file mode 100644 index 000000000..7baa776e6 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/OrderAbnormalRecordController.java @@ -0,0 +1,98 @@ +package com.jsowell.web.controller.pile; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.OrderAbnormalRecord; +import com.jsowell.pile.service.IOrderAbnormalRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 璁㈠崟寮傚父璁板綍Controller + * + * @author jsowell + * @date 2023-02-13 + */ +@RestController +@RequestMapping("/order/abnormalRecord") +public class OrderAbnormalRecordController extends BaseController { + @Autowired + private IOrderAbnormalRecordService orderAbnormalRecordService; + + /** + * 鏌ヨ璁㈠崟寮傚父璁板綍鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('order:abnormalRecord:list')") + @GetMapping("/list") + public TableDataInfo list(OrderAbnormalRecord orderAbnormalRecord) { + startPage(); + List list = orderAbnormalRecordService.selectOrderAbnormalRecordList(orderAbnormalRecord); + return getDataTable(list); + } + + /** + * 瀵煎嚭璁㈠崟寮傚父璁板綍鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('order:abnormalRecord:export')") + @Log(title = "璁㈠崟寮傚父璁板綍", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, OrderAbnormalRecord orderAbnormalRecord) { + List list = orderAbnormalRecordService.selectOrderAbnormalRecordList(orderAbnormalRecord); + ExcelUtil util = new ExcelUtil(OrderAbnormalRecord.class); + util.exportExcel(response, list, "璁㈠崟寮傚父璁板綍鏁版嵁"); + } + + /** + * 鑾峰彇璁㈠崟寮傚父璁板綍璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('order:abnormalRecord:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Integer id) { + return AjaxResult.success(orderAbnormalRecordService.selectOrderAbnormalRecordById(id)); + } + + /** + * 鏂板璁㈠崟寮傚父璁板綍 + */ + @PreAuthorize("@ss.hasPermi('order:abnormalRecord:add')") + @Log(title = "璁㈠崟寮傚父璁板綍", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody OrderAbnormalRecord orderAbnormalRecord) { + return toAjax(orderAbnormalRecordService.insertOrderAbnormalRecord(orderAbnormalRecord)); + } + + /** + * 淇敼璁㈠崟寮傚父璁板綍 + */ + @PreAuthorize("@ss.hasPermi('order:abnormalRecord:edit')") + @Log(title = "璁㈠崟寮傚父璁板綍", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody OrderAbnormalRecord orderAbnormalRecord) { + return toAjax(orderAbnormalRecordService.updateOrderAbnormalRecord(orderAbnormalRecord)); + } + + /** + * 鍒犻櫎璁㈠崟寮傚父璁板綍 + */ + @PreAuthorize("@ss.hasPermi('order:abnormalRecord:remove')") + @Log(title = "璁㈠崟寮傚父璁板綍", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Integer[] ids) { + return toAjax(orderAbnormalRecordService.deleteOrderAbnormalRecordByIds(ids)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/OrderBasicInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/OrderBasicInfoController.java new file mode 100644 index 000000000..458a4dbc8 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/OrderBasicInfoController.java @@ -0,0 +1,104 @@ +package com.jsowell.web.controller.pile; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.dto.QueryOrderDTO; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.vo.web.OrderListVO; +import com.jsowell.service.OrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 璁㈠崟Controller + * + * @author jsowell + * @date 2022-09-30 + */ +@RestController +@RequestMapping("/order") +public class OrderBasicInfoController extends BaseController { + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Autowired + private OrderService orderService; + + /** + * 鏌ヨ璁㈠崟鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('order:order:list')") + @GetMapping("/order/list") + public TableDataInfo list(QueryOrderDTO orderBasicInfo) { + startPage(); + List list = orderBasicInfoService.selectOrderBasicInfoList(orderBasicInfo); + return getDataTable(list); + } + + /** + * 鏍规嵁鍙傛暟鏌ヨ鐢ㄧ數搴︽暟鍜屾秷璐归噾棰 + */ + @PreAuthorize("@ss.hasPermi('order:order:list')") + @GetMapping("/order/totalData") + public AjaxResult getOrderTotalData(QueryOrderDTO orderBasicInfo) { + return AjaxResult.success(orderBasicInfoService.getOrderTotalData(orderBasicInfo)); + } + + /** + * 瀵煎嚭璁㈠崟鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('order:order:export')") + @Log(title = "璁㈠崟", businessType = BusinessType.EXPORT) + @PostMapping("/order/export") + public void export(HttpServletResponse response, QueryOrderDTO orderBasicInfo) { + List list = orderBasicInfoService.selectOrderBasicInfoList(orderBasicInfo); + ExcelUtil util = new ExcelUtil(OrderListVO.class); + util.exportExcel(response, list, "璁㈠崟鏁版嵁"); + } + + /** + * 鑾峰彇璁㈠崟璇︾粏淇℃伅 + * http://localhost:8080/order/orderDetail/88000000000001012211161342359448 + */ + @PreAuthorize("@ss.hasPermi('order:order:query')") + @GetMapping(value = "/orderDetail/{orderCode}") + public AjaxResult getInfo(@PathVariable("orderCode") String orderCode) { + return AjaxResult.success(orderService.queryOrderDetailInfo(orderCode)); + } + + /** + * 淇敼璁㈠崟 鍚庣璋冪敤 + */ + @PreAuthorize("@ss.hasPermi('order:order:edit')") + @Log(title = "璁㈠崟", businessType = BusinessType.UPDATE) + @PutMapping("/order") + public AjaxResult edit(@RequestBody OrderBasicInfo orderBasicInfo) { + return toAjax(orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo)); + } + + /** + * 鍒犻櫎璁㈠崟 + */ + @PreAuthorize("@ss.hasPermi('order:order:remove')") + @Log(title = "璁㈠崟", businessType = BusinessType.DELETE) + @DeleteMapping("/order/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(orderBasicInfoService.deleteOrderBasicInfoByIds(ids)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBasicInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBasicInfoController.java new file mode 100644 index 000000000..47bd1abef --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBasicInfoController.java @@ -0,0 +1,163 @@ +package com.jsowell.web.controller.pile; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.PileBasicInfo; +import com.jsowell.pile.dto.BatchCreatePileDTO; +import com.jsowell.pile.dto.QueryPileDTO; +import com.jsowell.pile.dto.ReplaceMerchantStationDTO; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileMsgRecordService; +import com.jsowell.pile.vo.web.PileDetailVO; +import com.jsowell.service.PileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 璁惧绠$悊Controller + * + * @author jsowell + * @date 2022-08-26 + */ +@RestController +@RequestMapping("/pile/basic") +public class PileBasicInfoController extends BaseController { + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private PileService pileService; + + @Autowired + private IPileMsgRecordService pileMsgRecordService; + /** + * 鏌ヨ璁惧绠$悊鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('pile:basic:list')") + @GetMapping("/list") + public TableDataInfo list(QueryPileDTO queryPileDTO) { + // startPage(); // 鍦ㄦ柟娉曚腑鍒嗛〉 + List list = pileBasicInfoService.queryPileInfos(queryPileDTO); + return getDataTable(list); + } + + /** + * 瀵煎嚭璁惧绠$悊鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('pile:basic:export')") + @Log(title = "璁惧绠$悊", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, PileBasicInfo pileBasicInfo) { + List list = pileBasicInfoService.selectPileBasicInfoList(pileBasicInfo); + ExcelUtil util = new ExcelUtil(PileBasicInfo.class); + util.exportExcel(response, list, "璁惧绠$悊鏁版嵁"); + } + + /** + * 鑾峰彇璁惧绠$悊璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('pile:basic:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) { + return AjaxResult.success(pileBasicInfoService.selectPileBasicInfoById(id)); + } + + /** + * 鏂板璁惧绠$悊 + */ + @PreAuthorize("@ss.hasPermi('pile:basic:add')") + @Log(title = "璁惧绠$悊", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody PileBasicInfo pileBasicInfo) { + return toAjax(pileBasicInfoService.insertPileBasicInfo(pileBasicInfo)); + } + + /** + * 鎵归噺鐢熸垚鍏呯數妗 + * @param dto + * @return + */ + @PreAuthorize("@ss.hasPermi('pile:basic:add')") + @Log(title = "璁惧绠$悊", businessType = BusinessType.INSERT) + @PostMapping("/batchAdd") + public AjaxResult batchAdd(@RequestBody BatchCreatePileDTO dto) { + logger.info("鎵归噺鐢熸垚鍏呯數妗 param:{}", JSONObject.toJSONString(dto)); + return toAjax(pileService.batchCreatePile(dto)); + } + + /** + * 淇敼璁惧绠$悊 + */ + @PreAuthorize("@ss.hasPermi('pile:basic:edit')") + @Log(title = "璁惧绠$悊", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody PileBasicInfo pileBasicInfo) { + return toAjax(pileBasicInfoService.updatePileBasicInfo(pileBasicInfo)); + } + + /** + * 鍒犻櫎璁惧绠$悊 + */ + @PreAuthorize("@ss.hasPermi('pile:basic:remove')") + @Log(title = "璁惧绠$悊", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(pileBasicInfoService.deletePileBasicInfoByIds(ids)); + } + + /** + * 鎵归噺鏇存柊鍏呯數妗 + * 杩愯惀鍟 绔欑偣 + */ + @PostMapping("/batchUpdatePileList") + public AjaxResult batchUpdatePileList( @RequestBody ReplaceMerchantStationDTO dto) { + logger.info("鎵归噺鏇存柊鍏呯數妗 param:{}", JSONObject.toJSONString(dto)); + return toAjax(pileBasicInfoService.replaceMerchantStationByPileIds(dto)); + } + + /** + * 鏌ヨ鍏呯數妗╄鎯 + * @return + */ + @PostMapping("/getPileDetailById") + public AjaxResult getPileDetailById(@RequestBody QueryPileDTO queryPileDTO) { + logger.info("鏌ヨ鍏呯數妗╄鎯 param:{}", JSONObject.toJSONString(queryPileDTO)); + if (StringUtils.isBlank(queryPileDTO.getPileId())) { + return AjaxResult.error("鍏呯數妗﹊d涓嶈兘涓虹┖"); + } + return AjaxResult.success(pileBasicInfoService.selectBasicInfoById(Long.valueOf(queryPileDTO.getPileId()))); + } + + /** + * 鏌ヨ鍏呯數妗╅氳鏃ュ織 + * + * @param dto + * @return + */ + @PostMapping("/getPileFeedList") + public AjaxResult getPileFeedList(@RequestBody QueryPileDTO dto) { + // logger.info("鏌ヨ鍏呯數妗╅氫俊鏃ュ織 param:{}", dto.getPileSn()); + if (StringUtils.isBlank(dto.getPileSn())) { + return AjaxResult.error("鍏呯數妗㏒n涓嶈兘涓虹┖"); + } + return AjaxResult.success(pileMsgRecordService.getPileFeedList(dto)); + } + +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBillingTemplateController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBillingTemplateController.java new file mode 100644 index 000000000..991c473a0 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBillingTemplateController.java @@ -0,0 +1,167 @@ +package com.jsowell.web.controller.pile; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.PileBillingTemplate; +import com.jsowell.pile.dto.CreateOrUpdateBillingTemplateDTO; +import com.jsowell.pile.dto.ImportBillingTemplateDTO; +import com.jsowell.pile.dto.PublishBillingTemplateDTO; +import com.jsowell.pile.service.IPileBillingTemplateService; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import com.jsowell.service.PileRemoteService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 璁¤垂妯℃澘Controller + * + * @author jsowell + * @date 2022-09-20 + */ +@Api(value = "璁¤垂妯℃澘Controller", tags = { "璁¤垂妯℃澘" }) +@RestController +@RequestMapping("/billing/template") +public class PileBillingTemplateController extends BaseController { + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private PileRemoteService pileRemoteService; + + /** + * 鏌ヨ璁¤垂妯℃澘鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('billing:template:list')") + @GetMapping("/list") + public TableDataInfo list(PileBillingTemplate pileBillingTemplate) { + startPage(); + // 鍙煡璇㈠叕鍏辩殑 + pileBillingTemplate.setPublicFlag(Constants.ONE); + List list = pileBillingTemplateService.selectPileBillingTemplateList(pileBillingTemplate); + return getDataTable(list); + } + + /** + * 瀵煎嚭璁¤垂妯℃澘鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('billing:template:export')") + @Log(title = "璁¤垂妯℃澘", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, PileBillingTemplate pileBillingTemplate) { + List list = pileBillingTemplateService.selectPileBillingTemplateList(pileBillingTemplate); + ExcelUtil util = new ExcelUtil(PileBillingTemplate.class); + util.exportExcel(response, list, "璁¤垂妯℃澘鏁版嵁"); + } + + /** + * 鑾峰彇璁¤垂妯℃澘璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('billing:template:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfoById(@PathVariable("id") Long id) { + return AjaxResult.success(pileBillingTemplateService.queryPileBillingTemplateById(id)); + } + + /** + * 淇敼璁¤垂妯℃澘 + */ + @PreAuthorize("@ss.hasPermi('billing:template:edit')") + @Log(title = "璁¤垂妯℃澘", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody PileBillingTemplate pileBillingTemplate) { + return toAjax(pileBillingTemplateService.updatePileBillingTemplate(pileBillingTemplate)); + } + + /** + * 鍒犻櫎璁¤垂妯℃澘 + */ + @PreAuthorize("@ss.hasPermi('billing:template:remove')") + @Log(title = "璁¤垂妯℃澘", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(pileBillingTemplateService.deletePileBillingTemplateByIds(ids)); + } + + /** + * 鏂板璁¤垂妯℃澘 + * http://localhost:8080/billing/template/createBillingTemplate + */ + @ApiOperation("鏂板璁¤垂妯℃澘") + @PreAuthorize("@ss.hasPermi('billing:template:add')") + @Log(title = "璁¤垂妯℃澘", businessType = BusinessType.INSERT) + @PostMapping("/createBillingTemplate") + public AjaxResult createBillingTemplate(@RequestBody CreateOrUpdateBillingTemplateDTO dto) { + logger.info("鏂板璁¤垂妯℃澘 param:{}", JSONObject.toJSONString(dto)); + pileBillingTemplateService.createBillingTemplate(dto); + return AjaxResult.success(); + } + + /** + * 鏇存柊璁¤垂妯℃澘 鍓嶇 + * @param dto + * @return + */ + @PostMapping("/updateBillingTemplate") + public AjaxResult updateBillingTemplate(@RequestBody CreateOrUpdateBillingTemplateDTO dto) { + logger.info("淇敼璁¤垂妯℃澘 param:{}", JSONObject.toJSONString(dto)); + pileBillingTemplateService.updateBillingTemplate(dto); + return AjaxResult.success(); + } + + /** + * 鏌ヨ鍏叡璁¤垂妯℃澘 + */ + @GetMapping("/queryPublicBillingTemplateList") + public TableDataInfo queryPublicBillingTemplateList() { + List list = pileBillingTemplateService.queryPublicBillingTemplateList(); + return getDataTable(list); + } + + /** + * 绔欑偣瀵煎叆璁¤垂妯℃澘鎺ュ彛 + * http://localhost:8080/billing/template/stationImportBillingTemplate + */ + @PostMapping("/stationImportBillingTemplate") + public AjaxResult stationImportBillingTemplate(@RequestBody ImportBillingTemplateDTO dto) { + logger.info("绔欑偣瀵煎叆璁¤垂妯℃澘 param:{}", JSONObject.toJSONString(dto)); + return toAjax(pileBillingTemplateService.stationImportBillingTemplate(dto)); + } + + /** + * 鏌ヨ绔欑偣璁¤垂妯℃澘 + */ + @GetMapping("/queryStationBillingTemplateList/{stationId}") + public TableDataInfo queryStationBillingTemplateList(@PathVariable("stationId") String stationId) { + logger.info("鏌ヨ绔欑偣璁¤垂妯℃澘 param:{}", stationId); + List list = pileBillingTemplateService.queryStationBillingTemplateList(stationId); + logger.info("鏌ヨ绔欑偣璁¤垂妯℃澘 result锛歿}", JSONObject.toJSONString(list)); + return getDataTable(list); + } + + /** + * 鍙戝竷璁¤垂妯℃澘 + */ + @PostMapping("/publishBillingTemplate") + public AjaxResult publishBillingTemplate(@RequestBody PublishBillingTemplateDTO dto) { + return toAjax(pileRemoteService.publishBillingTemplate(dto)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileConnectorInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileConnectorInfoController.java new file mode 100644 index 000000000..5e88c03b5 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileConnectorInfoController.java @@ -0,0 +1,113 @@ +package com.jsowell.web.controller.pile; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.PileConnectorInfo; +import com.jsowell.pile.dto.QueryConnectorDTO; +import com.jsowell.pile.dto.QueryConnectorListDTO; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 鍏呯數妗╂灙鍙d俊鎭疌ontroller + * + * @author jsowell + * @date 2022-08-31 + */ +@RestController +@RequestMapping("/pile/connector") +public class PileConnectorInfoController extends BaseController { + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + /** + * 鏌ヨ鍏呯數妗╂灙鍙d俊鎭垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:connector:list')") + @GetMapping("/list") + public TableDataInfo list(QueryConnectorDTO queryConnectorDTO) { + startPage(); + List list = pileConnectorInfoService.getConnectorInfoListByParams(queryConnectorDTO); + return getDataTable(list); + } + + /** + * 瀵煎嚭鍏呯數妗╂灙鍙d俊鎭垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:connector:export')") + @Log(title = "鍏呯數妗╂灙鍙d俊鎭", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, PileConnectorInfo pileConnectorInfo) { + List list = pileConnectorInfoService.selectPileConnectorInfoList(pileConnectorInfo); + ExcelUtil util = new ExcelUtil(PileConnectorInfo.class); + util.exportExcel(response, list, "鍏呯數妗╂灙鍙d俊鎭暟鎹"); + } + + /** + * 閫氳繃鍏ュ弬 鏌ヨ鎺ュ彛鍒楄〃 + * http://localhost:8080/pile/connector/getConnectorInfoListByParams?pileIds=1,2 + * 澶歩d浣跨敤閫楀彿鎷兼帴 + */ + @PostMapping("/getConnectorInfoListByParams") + public TableDataInfo getConnectorInfoListByParams(@RequestBody QueryConnectorListDTO dto) { + logger.info("鏌ヨ鎺ュ彛鍒楄〃 param:{}", JSONObject.toJSONString(dto)); + List list = pileConnectorInfoService.getConnectorInfoListByParams(dto); + logger.info("鏌ヨ鎺ュ彛鍒楄〃 result:{}", JSONObject.toJSONString(list)); + return getDataTable(list); + } + + /** + * 鑾峰彇鍏呯數妗╂灙鍙d俊鎭缁嗕俊鎭 + */ + // @PreAuthorize("@ss.hasPermi('pile:connector:query')") + // @GetMapping(value = "/{id}") + // public AjaxResult getInfo(@PathVariable("id") Integer id) { + // return AjaxResult.success(pileConnectorInfoService.selectPileConnectorInfoById(id)); + // } + + /** + * 鏂板鍏呯數妗╂灙鍙d俊鎭 + */ + // @PreAuthorize("@ss.hasPermi('pile:connector:add')") + // @Log(title = "鍏呯數妗╂灙鍙d俊鎭", businessType = BusinessType.INSERT) + // @PostMapping + // public AjaxResult add(@RequestBody PileConnectorInfo pileConnectorInfo) { + // return toAjax(pileConnectorInfoService.insertPileConnectorInfo(pileConnectorInfo)); + // } + + /** + * 淇敼鍏呯數妗╂灙鍙d俊鎭 + */ + // @PreAuthorize("@ss.hasPermi('pile:connector:edit')") + // @Log(title = "鍏呯數妗╂灙鍙d俊鎭", businessType = BusinessType.UPDATE) + // @PutMapping + // public AjaxResult edit(@RequestBody PileConnectorInfo pileConnectorInfo) { + // return toAjax(pileConnectorInfoService.updatePileConnectorInfo(pileConnectorInfo)); + // } + + /** + * 鍒犻櫎鍏呯數妗╂灙鍙d俊鎭 + */ + // @PreAuthorize("@ss.hasPermi('pile:connector:remove')") + // @Log(title = "鍏呯數妗╂灙鍙d俊鎭", businessType = BusinessType.DELETE) + // @DeleteMapping("/{ids}") + // public AjaxResult remove(@PathVariable Integer[] ids) { + // return toAjax(pileConnectorInfoService.deletePileConnectorInfoByIds(ids)); + // } + + +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileLicenceInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileLicenceInfoController.java new file mode 100644 index 000000000..714e6da88 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileLicenceInfoController.java @@ -0,0 +1,98 @@ +package com.jsowell.web.controller.pile; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.PileLicenceInfo; +import com.jsowell.pile.service.IPileLicenceInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 鍏呯數妗╄瘉涔︿俊鎭疌ontroller + * + * @author jsowell + * @date 2022-08-27 + */ +@RestController +@RequestMapping("/pile/licence") +public class PileLicenceInfoController extends BaseController +{ + @Autowired + private IPileLicenceInfoService pileLicenceInfoService; + + /** + * 鏌ヨ鍏呯數妗╄瘉涔︿俊鎭垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:licence:list')") + @GetMapping("/list") + public TableDataInfo list(PileLicenceInfo pileLicenceInfo) + { + startPage(); + List list = pileLicenceInfoService.selectPileLicenceInfoList(pileLicenceInfo); + return getDataTable(list); + } + + /** + * 瀵煎嚭鍏呯數妗╄瘉涔︿俊鎭垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:licence:export')") + @Log(title = "鍏呯數妗╄瘉涔︿俊鎭", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, PileLicenceInfo pileLicenceInfo) + { + List list = pileLicenceInfoService.selectPileLicenceInfoList(pileLicenceInfo); + ExcelUtil util = new ExcelUtil(PileLicenceInfo.class); + util.exportExcel(response, list, "鍏呯數妗╄瘉涔︿俊鎭暟鎹"); + } + + /** + * 鑾峰彇鍏呯數妗╄瘉涔︿俊鎭缁嗕俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:licence:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return AjaxResult.success(pileLicenceInfoService.selectPileLicenceInfoById(id)); + } + + /** + * 鏂板鍏呯數妗╄瘉涔︿俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:licence:add')") + @Log(title = "鍏呯數妗╄瘉涔︿俊鎭", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody PileLicenceInfo pileLicenceInfo) + { + return toAjax(pileLicenceInfoService.insertPileLicenceInfo(pileLicenceInfo)); + } + + /** + * 淇敼鍏呯數妗╄瘉涔︿俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:licence:edit')") + @Log(title = "鍏呯數妗╄瘉涔︿俊鎭", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody PileLicenceInfo pileLicenceInfo) + { + return toAjax(pileLicenceInfoService.updatePileLicenceInfo(pileLicenceInfo)); + } + + /** + * 鍒犻櫎鍏呯數妗╄瘉涔︿俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:licence:remove')") + @Log(title = "鍏呯數妗╄瘉涔︿俊鎭", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(pileLicenceInfoService.deletePileLicenceInfoByIds(ids)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileMerchantInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileMerchantInfoController.java new file mode 100644 index 000000000..9ad7e4e44 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileMerchantInfoController.java @@ -0,0 +1,103 @@ +package com.jsowell.web.controller.pile; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.PileMerchantInfo; +import com.jsowell.pile.service.IPileMerchantInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 鍏呯數妗╄繍钀ュ晢淇℃伅Controller + * + * @author jsowell + * @date 2022-08-27 + */ +@RestController +@RequestMapping("/pile/merchant") +public class PileMerchantInfoController extends BaseController { + @Autowired + private IPileMerchantInfoService pileMerchantInfoService; + + /** + * 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('pile:merchant:list')") + @GetMapping("/list") + public TableDataInfo list(PileMerchantInfo pileMerchantInfo) { + startPage(); + List list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo); + return getDataTable(list); + } + + /** + * 鑾峰彇杩愯惀鍟嗗垪琛 涓嶅垎椤 + * @param pileMerchantInfo + * @return + */ + @PreAuthorize("@ss.hasPermi('pile:merchant:list')") + @GetMapping("/getMerchantList") + public TableDataInfo getMerchantList(PileMerchantInfo pileMerchantInfo) { + List list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo); + return getDataTable(list); + } + + /** + * 瀵煎嚭鍏呯數妗╄繍钀ュ晢淇℃伅鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('pile:merchant:export')") + @Log(title = "鍏呯數妗╄繍钀ュ晢淇℃伅", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, PileMerchantInfo pileMerchantInfo) { + List list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo); + ExcelUtil util = new ExcelUtil(PileMerchantInfo.class); + util.exportExcel(response, list, "鍏呯數妗╄繍钀ュ晢淇℃伅鏁版嵁"); + } + + /** + * 鑾峰彇鍏呯數妗╄繍钀ュ晢淇℃伅璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('pile:merchant:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) { + return AjaxResult.success(pileMerchantInfoService.selectPileMerchantInfoById(id)); + } + + /** + * 鏂板鍏呯數妗╄繍钀ュ晢淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('pile:merchant:add')") + @Log(title = "鍏呯數妗╄繍钀ュ晢淇℃伅", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody PileMerchantInfo pileMerchantInfo) { + return toAjax(pileMerchantInfoService.insertPileMerchantInfo(pileMerchantInfo)); + } + + /** + * 淇敼鍏呯數妗╄繍钀ュ晢淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('pile:merchant:edit')") + @Log(title = "鍏呯數妗╄繍钀ュ晢淇℃伅", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody PileMerchantInfo pileMerchantInfo) { + return toAjax(pileMerchantInfoService.updatePileMerchantInfo(pileMerchantInfo)); + } + + /** + * 鍒犻櫎鍏呯數妗╄繍钀ュ晢淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('pile:merchant:remove')") + @Log(title = "鍏呯數妗╄繍钀ュ晢淇℃伅", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(pileMerchantInfoService.deletePileMerchantInfoByIds(ids)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileModelInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileModelInfoController.java new file mode 100644 index 000000000..6ae56c102 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileModelInfoController.java @@ -0,0 +1,91 @@ +package com.jsowell.web.controller.pile; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.PileModelInfo; +import com.jsowell.pile.service.IPileModelInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 鍏呯數妗╁瀷鍙蜂俊鎭疌ontroller + * + * @author jsowell + * @date 2022-08-26 + */ +@RestController +@RequestMapping("/pile/model") +public class PileModelInfoController extends BaseController { + @Autowired + private IPileModelInfoService pileModelInfoService; + + /** + * 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭垪琛 + */ + // @PreAuthorize("@ss.hasPermi('pile:model:list')") + @GetMapping("/list") + public TableDataInfo list(PileModelInfo pileModelInfo) { + startPage(); + List list = pileModelInfoService.selectPileModelInfoList(pileModelInfo); + return getDataTable(list); + } + + /** + * 瀵煎嚭鍏呯數妗╁瀷鍙蜂俊鎭垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:model:export')") + @Log(title = "鍏呯數妗╁瀷鍙蜂俊鎭", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, PileModelInfo pileModelInfo) { + List list = pileModelInfoService.selectPileModelInfoList(pileModelInfo); + ExcelUtil util = new ExcelUtil(PileModelInfo.class); + util.exportExcel(response, list, "鍏呯數妗╁瀷鍙蜂俊鎭暟鎹"); + } + + /** + * 鑾峰彇鍏呯數妗╁瀷鍙蜂俊鎭缁嗕俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:model:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) { + return AjaxResult.success(pileModelInfoService.selectPileModelInfoById(id)); + } + + /** + * 鏂板鍏呯數妗╁瀷鍙蜂俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:model:add')") + @Log(title = "鍏呯數妗╁瀷鍙蜂俊鎭", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody PileModelInfo pileModelInfo) { + return toAjax(pileModelInfoService.insertPileModelInfo(pileModelInfo)); + } + + /** + * 淇敼鍏呯數妗╁瀷鍙蜂俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:model:edit')") + @Log(title = "鍏呯數妗╁瀷鍙蜂俊鎭", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody PileModelInfo pileModelInfo) { + return toAjax(pileModelInfoService.updatePileModelInfo(pileModelInfo)); + } + + /** + * 鍒犻櫎鍏呯數妗╁瀷鍙蜂俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:model:remove')") + @Log(title = "鍏呯數妗╁瀷鍙蜂俊鎭", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(pileModelInfoService.deletePileModelInfoByIds(ids)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileRemoteController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileRemoteController.java new file mode 100644 index 000000000..94fef4183 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileRemoteController.java @@ -0,0 +1,109 @@ +package com.jsowell.web.controller.pile; + +import com.google.common.collect.ImmutableMap; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.pile.dto.GenerateOrderDTO; +import com.jsowell.pile.dto.QueryPileDTO; +import com.jsowell.service.OrderService; +import com.jsowell.service.PileRemoteService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 杩滅▼鎺у埗controller + */ +@RestController +@RequestMapping("/remote") +public class PileRemoteController { + + @Autowired + private PileRemoteService pileRemoteService; + + @Autowired + private OrderService orderService; + + /** + * 鑾峰彇瀹炴椂涓婁紶鏁版嵁 + * http://localhost:8080/remote/getRealTimeMonitorData + * @return + */ + @PostMapping("/getRealTimeMonitorData") + public AjaxResult getRealTimeMonitorData(@RequestBody QueryPileDTO queryPileDTO) { + pileRemoteService.getRealTimeMonitorData(queryPileDTO.getPileSn(), queryPileDTO.getConnectorCode()); + return AjaxResult.success(); + } + + /** + * 杩滅▼閲嶅惎 + * http://localhost:8080/remote/reboot + * @return + */ + @PostMapping("/reboot") + public AjaxResult reboot(@RequestBody QueryPileDTO queryPileDTO) { + pileRemoteService.reboot(queryPileDTO.getPileSn()); + return AjaxResult.success(); + } + + /** + * 鍚庣-杩滅▼鍚姩鍏呯數 + * http://localhost:8080/remote/remoteStartChargingForWeb + */ + @PostMapping("/remoteStartChargingForWeb") + public AjaxResult remoteStartCharging(@RequestBody GenerateOrderDTO dto) { + // pileRemoteService.remoteStartCharging(queryPileDTO.getPileSn(), queryPileDTO.getConnectorCode()); + // 鐢熸垚璁㈠崟骞惰繙绋嬪惎鍔ㄥ厖鐢 + dto.setStartMode(Constants.ZERO); + String orderCode = orderService.generateOrder(dto); + return AjaxResult.success(ImmutableMap.of("orderCode", orderCode)); + } + + /** + * 杩滅▼鍋滄鍏呯數 + * http://localhost:8080/remote/remoteStopCharging + * @param dto + * @return + */ + @PostMapping("/remoteStopCharging") + public AjaxResult remoteStopCharging(@RequestBody QueryPileDTO dto) { + pileRemoteService.remoteStopCharging(dto.getPileSn(), dto.getConnectorCode()); + return AjaxResult.success(); + } + + /** + * 杩滅▼涓嬪彂浜岀淮鐮 + * http://localhost:8080/remote/issueQRCode + */ + @PostMapping("/issueQRCode") + public AjaxResult issueQRCode(@RequestBody QueryPileDTO queryPileDTO) { + pileRemoteService.issueQRCode(queryPileDTO.getPileSn()); + return AjaxResult.success(); + } + + /** + * 瀵规椂 + * http://localhost:8080/remote/proofreadTime + */ + @PostMapping("/proofreadTime") + public AjaxResult proofreadTime(@RequestBody QueryPileDTO queryPileDTO) { + pileRemoteService.proofreadTime(queryPileDTO.getPileSn()); + return AjaxResult.success(); + } + + /** + * 杩滅▼鍗囩骇 + * http://localhost:8080/remote/updateFile + * @return + */ + @PostMapping("/updateFile") + public AjaxResult updateFile(@RequestBody QueryPileDTO queryPileDTO) { + pileRemoteService.updateFile(queryPileDTO.getPileSns()); + return AjaxResult.success(); + } + +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileSimInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileSimInfoController.java new file mode 100644 index 000000000..3c37a5d21 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileSimInfoController.java @@ -0,0 +1,142 @@ +package com.jsowell.web.controller.pile; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.PileSimInfo; +import com.jsowell.pile.dto.QuerySimInfoDTO; +import com.jsowell.pile.dto.SimRenewDTO; +import com.jsowell.pile.service.IPileSimInfoService; +import com.jsowell.pile.service.SimCardService; +import com.jsowell.pile.vo.web.SimCardInfoVO; +import com.jsowell.pile.vo.web.SimRenewResultVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 鍏呯數妗㏒IM鍗′俊鎭疌ontroller + * + * @author jsowell + * @date 2022-08-26 + */ +@RestController +@RequestMapping("/pile/sim") +public class PileSimInfoController extends BaseController { + @Autowired + private IPileSimInfoService pileSimInfoService; + + @Autowired + private SimCardService simCardService; + + /** + * 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:sim:list')") + @GetMapping("/list") + public TableDataInfo list(PileSimInfo pileSimInfo) { + startPage(); + List list = pileSimInfoService.selectPileSimInfoList(pileSimInfo); + + // List list = pileSimInfoService.getSimInfoList(pileSimInfo); + return getDataTable(list); + } + + @PreAuthorize("@ss.hasPermi('pile:sim:list')") + @PostMapping("/getSimInfo") + public TableDataInfo getSimInfo(QuerySimInfoDTO dto) { + startPage(); + List simInfoList = pileSimInfoService.getSimInfoList(dto); + return getDataTable(simInfoList); + } + /** + * 瀵煎嚭鍏呯數妗㏒IM鍗′俊鎭垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:sim:export')") + @Log(title = "鍏呯數妗㏒IM鍗′俊鎭", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, PileSimInfo pileSimInfo) { + List list = pileSimInfoService.selectPileSimInfoList(pileSimInfo); + ExcelUtil util = new ExcelUtil(PileSimInfo.class); + util.exportExcel(response, list, "鍏呯數妗㏒IM鍗′俊鎭暟鎹"); + } + + /** + * 鑾峰彇鍏呯數妗㏒IM鍗′俊鎭缁嗕俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:sim:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) { + return AjaxResult.success(pileSimInfoService.selectPileSimInfoById(id)); + } + + /** + * 鏂板鍏呯數妗㏒IM鍗′俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:sim:add')") + @Log(title = "鍏呯數妗㏒IM鍗′俊鎭", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody PileSimInfo pileSimInfo) { + return toAjax(pileSimInfoService.insertPileSimInfo(pileSimInfo)); + } + + /** + * 淇敼鍏呯數妗㏒IM鍗′俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:sim:edit')") + @Log(title = "鍏呯數妗㏒IM鍗′俊鎭", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody PileSimInfo pileSimInfo) { + return toAjax(pileSimInfoService.updatePileSimInfo(pileSimInfo)); + } + + /** + * 鍒犻櫎鍏呯數妗㏒IM鍗′俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:sim:remove')") + @Log(title = "鍏呯數妗㏒IM鍗′俊鎭", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(pileSimInfoService.deletePileSimInfoByIds(ids)); + } + + + /** + * 缁垂sim鍗″懆鏈 + * @param dto + * @return + */ + @PreAuthorize("@ss.hasPermi('pile:sim:edit')") + @PostMapping("/simRenew") + public AjaxResult simRenew(@RequestBody SimRenewDTO dto) { + List list = simCardService.renewSimByLoop(dto.getIccIds(), dto.getCycleNumber()); + return AjaxResult.success(list); + + + // AjaxResult result; + // try { + // List list = simCardService.renewSimByLoop(dto.getIccIds(), dto.getCycleNumber()); + // result = AjaxResult. + // } catch (BusinessException e) { + // result = AjaxResult.error(Integer.parseInt(e.getCode()), e.getMessage()); + // } catch (Exception e) { + // result = AjaxResult.error(); + // } + // return result; + } + +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileStationInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileStationInfoController.java new file mode 100644 index 000000000..2bba1aefe --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileStationInfoController.java @@ -0,0 +1,148 @@ +package com.jsowell.web.controller.pile; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.pile.domain.PileStationInfo; +import com.jsowell.pile.dto.FastCreateStationDTO; +import com.jsowell.pile.dto.QueryStationDTO; +import com.jsowell.pile.service.IPileStationInfoService; +import com.jsowell.pile.vo.web.PileStationVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 鍏呯數绔欎俊鎭疌ontroller + * + * @author jsowell + * @date 2022-08-30 + */ +@RestController +@RequestMapping("/pile/station") +public class PileStationInfoController extends BaseController { + @Autowired + private IPileStationInfoService pileStationInfoService; + + + /** + * 鏌ヨ鍏呯數绔欎俊鎭垪琛∟EW + */ + @PreAuthorize("@ss.hasPermi('pile:station:list')") + @GetMapping("/list") + public TableDataInfo list(QueryStationDTO queryStationDTO) { + startPage(); + // List list = pileStationInfoService.selectPileStationInfoList(pileStationInfo); + List list = pileStationInfoService.queryStationInfos(queryStationDTO); + return getDataTable(list); + } + + /** + * 蹇熷缓绔欐帴鍙 + */ + // @PreAuthorize("@ss.hasPermi('pile:station:add')") + @PostMapping("/fastCreateStation") + public AjaxResult fastCreateStation(@RequestBody FastCreateStationDTO dto) { + logger.info("蹇熷缓绔欐帴鍙 param:{}", JSONObject.toJSONString(dto)); + int i = 0; + try { + i = pileStationInfoService.fastCreateStation(dto); + } catch (BusinessException e) { + logger.warn("蹇熷缓绔欐帴鍙 warn", e); + } catch (Exception e) { + logger.error("蹇熷缓绔欐帴鍙 error", e); + } + return toAjax(i); + } + + + /** + * 鏌ヨ鍏呯數绔欎俊鎭垪琛 + */ + /*@PreAuthorize("@ss.hasPermi('pile:station:list')") + @GetMapping("/list") + public TableDataInfo list(PileStationInfo pileStationInfo) { + startPage(); + List list = pileStationInfoService.selectPileStationInfoList(pileStationInfo); + return getDataTable(list); + }*/ + + /** + * 瀵煎嚭鍏呯數绔欎俊鎭垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:station:export')") + @Log(title = "鍏呯數绔欎俊鎭", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, PileStationInfo pileStationInfo) { + List list = pileStationInfoService.selectPileStationInfoList(pileStationInfo); + ExcelUtil util = new ExcelUtil(PileStationInfo.class); + util.exportExcel(response, list, "鍏呯數绔欎俊鎭暟鎹"); + } + + /** + * 鑾峰彇鍏呯數绔欎俊鎭缁嗕俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:station:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) { + return AjaxResult.success(pileStationInfoService.selectPileStationInfoById(id)); + } + + /** + * 鍚庣绔欑偣鍩烘湰璧勬枡椤甸潰 + * @return + */ + @PreAuthorize("@ss.hasPermi('pile:station:query')") + @GetMapping(value = "/getStationInfo/{stationId}") + public AjaxResult getStationInfo(@PathVariable("stationId") String stationId) { + return AjaxResult.success(pileStationInfoService.getStationInfo(stationId)); + } + + /** + * 鏂板鍏呯數绔欎俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:station:add')") + @Log(title = "鍏呯數绔欎俊鎭", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody PileStationInfo pileStationInfo) { + return toAjax(pileStationInfoService.insertPileStationInfo(pileStationInfo)); + } + + /** + * 淇敼鍏呯數绔欎俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:station:edit')") + @Log(title = "鍏呯數绔欎俊鎭", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody PileStationInfo pileStationInfo) { + logger.info("淇敼鍏呯數绔欎俊鎭 param:{}", pileStationInfo.toString()); + return toAjax(pileStationInfoService.updatePileStationInfo(pileStationInfo)); + } + + /** + * 鍒犻櫎鍏呯數绔欎俊鎭 + */ + @PreAuthorize("@ss.hasPermi('pile:station:remove')") + @Log(title = "鍏呯數绔欎俊鎭", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(pileStationInfoService.deletePileStationInfoByIds(ids)); + } + + /** + * 鏍规嵁杩愯惀鍟唅d鑾峰彇鍏呯數绔欏垪琛 + */ + @PreAuthorize("@ss.hasPermi('pile:station:query')") + @PostMapping(value = "/selectStationListByMerchantId") + public AjaxResult selectStationListByMerchantId(@RequestBody QueryStationDTO dto) { + return AjaxResult.success(pileStationInfoService.selectStationListByMerchantId(Long.valueOf(dto.getMerchantId()))); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysConfigController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysConfigController.java new file mode 100644 index 000000000..5200055d5 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysConfigController.java @@ -0,0 +1,124 @@ +package com.jsowell.web.controller.system; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.system.domain.SysConfig; +import com.jsowell.system.service.SysConfigService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 鍙傛暟閰嶇疆 淇℃伅鎿嶄綔澶勭悊 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/config") +public class SysConfigController extends BaseController { + @Autowired + private SysConfigService configService; + + /** + * 鑾峰彇鍙傛暟閰嶇疆鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('system:config:list')") + @GetMapping("/list") + public TableDataInfo list(SysConfig config) { + startPage(); + List list = configService.selectConfigList(config); + return getDataTable(list); + } + + @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:config:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysConfig config) { + List list = configService.selectConfigList(config); + ExcelUtil util = new ExcelUtil(SysConfig.class); + util.exportExcel(response, list, "鍙傛暟鏁版嵁"); + } + + /** + * 鏍规嵁鍙傛暟缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('system:config:query')") + @GetMapping(value = "/{configId}") + public AjaxResult getInfo(@PathVariable Long configId) { + return AjaxResult.success(configService.selectConfigById(configId)); + } + + /** + * 鏍规嵁鍙傛暟閿悕鏌ヨ鍙傛暟鍊 + */ + @GetMapping(value = "/configKey/{configKey}") + public AjaxResult getConfigKey(@PathVariable String configKey) { + return AjaxResult.success(configService.selectConfigByKey(configKey)); + } + + /** + * 鏂板鍙傛暟閰嶇疆 + */ + @PreAuthorize("@ss.hasPermi('system:config:add')") + @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysConfig config) { + if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) { + return AjaxResult.error("鏂板鍙傛暟'" + config.getConfigName() + "'澶辫触锛屽弬鏁伴敭鍚嶅凡瀛樺湪"); + } + config.setCreateBy(getUsername()); + return toAjax(configService.insertConfig(config)); + } + + /** + * 淇敼鍙傛暟閰嶇疆 + */ + @PreAuthorize("@ss.hasPermi('system:config:edit')") + @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysConfig config) { + if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) { + return AjaxResult.error("淇敼鍙傛暟'" + config.getConfigName() + "'澶辫触锛屽弬鏁伴敭鍚嶅凡瀛樺湪"); + } + config.setUpdateBy(getUsername()); + return toAjax(configService.updateConfig(config)); + } + + /** + * 鍒犻櫎鍙傛暟閰嶇疆 + */ + @PreAuthorize("@ss.hasPermi('system:config:remove')") + @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.DELETE) + @DeleteMapping("/{configIds}") + public AjaxResult remove(@PathVariable Long[] configIds) { + configService.deleteConfigByIds(configIds); + return success(); + } + + /** + * 鍒锋柊鍙傛暟缂撳瓨 + */ + @PreAuthorize("@ss.hasPermi('system:config:remove')") + @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.CLEAN) + @DeleteMapping("/refreshCache") + public AjaxResult refreshCache() { + configService.resetConfigCache(); + return AjaxResult.success(); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDeptController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDeptController.java new file mode 100644 index 000000000..1fe2860b0 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDeptController.java @@ -0,0 +1,140 @@ +package com.jsowell.web.controller.system; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.entity.SysDept; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.service.SysDeptService; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.Iterator; +import java.util.List; + +/** + * 閮ㄩ棬淇℃伅 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/dept") +public class SysDeptController extends BaseController { + @Autowired + private SysDeptService deptService; + + /** + * 鑾峰彇閮ㄩ棬鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('system:dept:list')") + @GetMapping("/list") + public AjaxResult list(SysDept dept) { + List depts = deptService.selectDeptList(dept); + return AjaxResult.success(depts); + } + + /** + * 鏌ヨ閮ㄩ棬鍒楄〃锛堟帓闄よ妭鐐癸級 + */ + @PreAuthorize("@ss.hasPermi('system:dept:list')") + @GetMapping("/list/exclude/{deptId}") + public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) { + List depts = deptService.selectDeptList(new SysDept()); + Iterator it = depts.iterator(); + while (it.hasNext()) { + SysDept d = (SysDept) it.next(); + if (d.getDeptId().intValue() == deptId + || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")) { + it.remove(); + } + } + return AjaxResult.success(depts); + } + + /** + * 鏍规嵁閮ㄩ棬缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('system:dept:query')") + @GetMapping(value = "/{deptId}") + public AjaxResult getInfo(@PathVariable Long deptId) { + deptService.checkDeptDataScope(deptId); + return AjaxResult.success(deptService.selectDeptById(deptId)); + } + + /** + * 鑾峰彇閮ㄩ棬涓嬫媺鏍戝垪琛 + */ + @GetMapping("/treeselect") + public AjaxResult treeselect(SysDept dept) { + List depts = deptService.selectDeptList(dept); + return AjaxResult.success(deptService.buildDeptTreeSelect(depts)); + } + + /** + * 鍔犺浇瀵瑰簲瑙掕壊閮ㄩ棬鍒楄〃鏍 + */ + @GetMapping(value = "/roleDeptTreeselect/{roleId}") + public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) { + List depts = deptService.selectDeptList(new SysDept()); + AjaxResult ajax = AjaxResult.success(); + ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); + ajax.put("depts", deptService.buildDeptTreeSelect(depts)); + return ajax; + } + + /** + * 鏂板閮ㄩ棬 + */ + @PreAuthorize("@ss.hasPermi('system:dept:add')") + @Log(title = "閮ㄩ棬绠$悊", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysDept dept) { + if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) { + return AjaxResult.error("鏂板閮ㄩ棬'" + dept.getDeptName() + "'澶辫触锛岄儴闂ㄥ悕绉板凡瀛樺湪"); + } + dept.setCreateBy(getUsername()); + return toAjax(deptService.insertDept(dept)); + } + + /** + * 淇敼閮ㄩ棬 + */ + @PreAuthorize("@ss.hasPermi('system:dept:edit')") + @Log(title = "閮ㄩ棬绠$悊", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysDept dept) { + Long deptId = dept.getDeptId(); + deptService.checkDeptDataScope(deptId); + if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) { + return AjaxResult.error("淇敼閮ㄩ棬'" + dept.getDeptName() + "'澶辫触锛岄儴闂ㄥ悕绉板凡瀛樺湪"); + } else if (dept.getParentId().equals(deptId)) { + return AjaxResult.error("淇敼閮ㄩ棬'" + dept.getDeptName() + "'澶辫触锛屼笂绾ч儴闂ㄤ笉鑳芥槸鑷繁"); + } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) { + return AjaxResult.error("璇ラ儴闂ㄥ寘鍚湭鍋滅敤鐨勫瓙閮ㄩ棬锛"); + } + dept.setUpdateBy(getUsername()); + return toAjax(deptService.updateDept(dept)); + } + + /** + * 鍒犻櫎閮ㄩ棬 + */ + @PreAuthorize("@ss.hasPermi('system:dept:remove')") + @Log(title = "閮ㄩ棬绠$悊", businessType = BusinessType.DELETE) + @DeleteMapping("/{deptId}") + public AjaxResult remove(@PathVariable Long deptId) { + if (deptService.hasChildByDeptId(deptId)) { + return AjaxResult.error("瀛樺湪涓嬬骇閮ㄩ棬,涓嶅厑璁稿垹闄"); + } + if (deptService.checkDeptExistUser(deptId)) { + return AjaxResult.error("閮ㄩ棬瀛樺湪鐢ㄦ埛,涓嶅厑璁稿垹闄"); + } + deptService.checkDeptDataScope(deptId); + return toAjax(deptService.deleteDeptById(deptId)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDictDataController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDictDataController.java new file mode 100644 index 000000000..92b0ef994 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDictDataController.java @@ -0,0 +1,113 @@ +package com.jsowell.web.controller.system; + +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.entity.SysDictData; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.system.service.SysDictDataService; +import com.jsowell.system.service.SysDictTypeService; + +/** + * 鏁版嵁瀛楀吀淇℃伅 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/dict/data") +public class SysDictDataController extends BaseController { + @Autowired + private SysDictDataService dictDataService; + + @Autowired + private SysDictTypeService dictTypeService; + + @PreAuthorize("@ss.hasPermi('system:dict:list')") + @GetMapping("/list") + public TableDataInfo list(SysDictData dictData) { + startPage(); + List list = dictDataService.selectDictDataList(dictData); + return getDataTable(list); + } + + @Log(title = "瀛楀吀鏁版嵁", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:dict:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysDictData dictData) { + List list = dictDataService.selectDictDataList(dictData); + ExcelUtil util = new ExcelUtil(SysDictData.class); + util.exportExcel(response, list, "瀛楀吀鏁版嵁"); + } + + /** + * 鏌ヨ瀛楀吀鏁版嵁璇︾粏 + */ + @PreAuthorize("@ss.hasPermi('system:dict:query')") + @GetMapping(value = "/{dictCode}") + public AjaxResult getInfo(@PathVariable Long dictCode) { + return AjaxResult.success(dictDataService.selectDictDataById(dictCode)); + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁淇℃伅 + */ + @GetMapping(value = "/type/{dictType}") + public AjaxResult dictType(@PathVariable String dictType) { + List data = dictTypeService.selectDictDataByType(dictType); + if (StringUtils.isNull(data)) { + data = new ArrayList(); + } + return AjaxResult.success(data); + } + + /** + * 鏂板瀛楀吀绫诲瀷 + */ + @PreAuthorize("@ss.hasPermi('system:dict:add')") + @Log(title = "瀛楀吀鏁版嵁", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysDictData dict) { + dict.setCreateBy(getUsername()); + return toAjax(dictDataService.insertDictData(dict)); + } + + /** + * 淇敼淇濆瓨瀛楀吀绫诲瀷 + */ + @PreAuthorize("@ss.hasPermi('system:dict:edit')") + @Log(title = "瀛楀吀鏁版嵁", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysDictData dict) { + dict.setUpdateBy(getUsername()); + return toAjax(dictDataService.updateDictData(dict)); + } + + /** + * 鍒犻櫎瀛楀吀绫诲瀷 + */ + @PreAuthorize("@ss.hasPermi('system:dict:remove')") + @Log(title = "瀛楀吀绫诲瀷", businessType = BusinessType.DELETE) + @DeleteMapping("/{dictCodes}") + public AjaxResult remove(@PathVariable Long[] dictCodes) { + dictDataService.deleteDictDataByIds(dictCodes); + return success(); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDictTypeController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDictTypeController.java new file mode 100644 index 000000000..b848f6b6b --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysDictTypeController.java @@ -0,0 +1,122 @@ +package com.jsowell.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.entity.SysDictType; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.system.service.SysDictTypeService; + +/** + * 鏁版嵁瀛楀吀淇℃伅 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/dict/type") +public class SysDictTypeController extends BaseController { + @Autowired + private SysDictTypeService dictTypeService; + + @PreAuthorize("@ss.hasPermi('system:dict:list')") + @GetMapping("/list") + public TableDataInfo list(SysDictType dictType) { + startPage(); + List list = dictTypeService.selectDictTypeList(dictType); + return getDataTable(list); + } + + @Log(title = "瀛楀吀绫诲瀷", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:dict:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysDictType dictType) { + List list = dictTypeService.selectDictTypeList(dictType); + ExcelUtil util = new ExcelUtil(SysDictType.class); + util.exportExcel(response, list, "瀛楀吀绫诲瀷"); + } + + /** + * 鏌ヨ瀛楀吀绫诲瀷璇︾粏 + */ + @PreAuthorize("@ss.hasPermi('system:dict:query')") + @GetMapping(value = "/{dictId}") + public AjaxResult getInfo(@PathVariable Long dictId) { + return AjaxResult.success(dictTypeService.selectDictTypeById(dictId)); + } + + /** + * 鏂板瀛楀吀绫诲瀷 + */ + @PreAuthorize("@ss.hasPermi('system:dict:add')") + @Log(title = "瀛楀吀绫诲瀷", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysDictType dict) { + if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) { + return AjaxResult.error("鏂板瀛楀吀'" + dict.getDictName() + "'澶辫触锛屽瓧鍏哥被鍨嬪凡瀛樺湪"); + } + dict.setCreateBy(getUsername()); + return toAjax(dictTypeService.insertDictType(dict)); + } + + /** + * 淇敼瀛楀吀绫诲瀷 + */ + @PreAuthorize("@ss.hasPermi('system:dict:edit')") + @Log(title = "瀛楀吀绫诲瀷", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysDictType dict) { + if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) { + return AjaxResult.error("淇敼瀛楀吀'" + dict.getDictName() + "'澶辫触锛屽瓧鍏哥被鍨嬪凡瀛樺湪"); + } + dict.setUpdateBy(getUsername()); + return toAjax(dictTypeService.updateDictType(dict)); + } + + /** + * 鍒犻櫎瀛楀吀绫诲瀷 + */ + @PreAuthorize("@ss.hasPermi('system:dict:remove')") + @Log(title = "瀛楀吀绫诲瀷", businessType = BusinessType.DELETE) + @DeleteMapping("/{dictIds}") + public AjaxResult remove(@PathVariable Long[] dictIds) { + dictTypeService.deleteDictTypeByIds(dictIds); + return success(); + } + + /** + * 鍒锋柊瀛楀吀缂撳瓨 + */ + @PreAuthorize("@ss.hasPermi('system:dict:remove')") + @Log(title = "瀛楀吀绫诲瀷", businessType = BusinessType.CLEAN) + @DeleteMapping("/refreshCache") + public AjaxResult refreshCache() { + dictTypeService.resetDictCache(); + return AjaxResult.success(); + } + + /** + * 鑾峰彇瀛楀吀閫夋嫨妗嗗垪琛 + */ + @GetMapping("/optionselect") + public AjaxResult optionselect() { + List dictTypes = dictTypeService.selectDictTypeAll(); + return AjaxResult.success(dictTypes); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysIndexController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysIndexController.java new file mode 100644 index 000000000..60001e5e5 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysIndexController.java @@ -0,0 +1,29 @@ +package com.jsowell.web.controller.system; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.util.StringUtils; + +/** + * 棣栭〉 + * + * @author jsowell + */ +@RestController +public class SysIndexController { + /** + * 绯荤粺鍩虹閰嶇疆 + */ + @Autowired + private JsowellConfig jsowellConfig; + + /** + * 璁块棶棣栭〉锛屾彁绀鸿 + */ + @RequestMapping("/") + public String index() { + return StringUtils.format("娆㈣繋浣跨敤{}鍚庡彴绠$悊妗嗘灦锛屽綋鍓嶇増鏈細v{}锛岃閫氳繃鍓嶇鍦板潃璁块棶銆", jsowellConfig.getName(), jsowellConfig.getVersion()); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysLoginController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysLoginController.java new file mode 100644 index 000000000..f36f9f043 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysLoginController.java @@ -0,0 +1,90 @@ +package com.jsowell.web.controller.system; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.entity.SysMenu; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.domain.model.LoginBody; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.framework.web.service.SysLoginService; +import com.jsowell.framework.web.service.SysPermissionService; +import com.jsowell.system.service.SysMenuService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Set; + +/** + * 鐧诲綍楠岃瘉 + * + * @author jsowell + */ +@RestController +public class SysLoginController { + Logger logs = LoggerFactory.getLogger(this.getClass()); + @Autowired + private SysLoginService loginService; + + @Autowired + private SysMenuService menuService; + + @Autowired + private SysPermissionService permissionService; + + /** + * 鐧诲綍鏂规硶 + * + * @param loginBody 鐧诲綍淇℃伅 + * @return 缁撴灉 + */ + @PostMapping("/login") + public AjaxResult login(@RequestBody LoginBody loginBody) { + logs.info("鐧诲綍param锛歿}", JSONObject.toJSONString(loginBody)); + AjaxResult ajax = AjaxResult.success(); + // 鐢熸垚浠ょ墝 + String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), + loginBody.getUuid()); + ajax.put(Constants.TOKEN, token); + logs.info("鐧诲綍 result:{}", ajax.toString()); + return ajax; + } + + /** + * 鑾峰彇鐢ㄦ埛淇℃伅 + * + * @return 鐢ㄦ埛淇℃伅 + */ + @GetMapping("getInfo") + public AjaxResult getInfo() { + SysUser user = SecurityUtils.getLoginUser().getUser(); + // 瑙掕壊闆嗗悎 + Set roles = permissionService.getRolePermission(user); + // 鏉冮檺闆嗗悎 + Set permissions = permissionService.getMenuPermission(user); + AjaxResult ajax = AjaxResult.success(); + ajax.put("user" , user); + ajax.put("roles" , roles); + ajax.put("permissions" , permissions); + return ajax; + } + + /** + * 鑾峰彇璺敱淇℃伅 + * + * @return 璺敱淇℃伅 + */ + @GetMapping("getRouters") + public AjaxResult getRouters() { + Long userId = SecurityUtils.getUserId(); + List menus = menuService.selectMenuTreeByUserId(userId); + logs.info("鑾峰彇璺敱淇℃伅userId:{}, menus:{}, 鑿滃崟鏁伴噺:{}", userId, menus, menus.size()); + return AjaxResult.success(menuService.buildMenus(menus)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysMenuController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysMenuController.java new file mode 100644 index 000000000..90e3dcf9f --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysMenuController.java @@ -0,0 +1,125 @@ +package com.jsowell.web.controller.system; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.entity.SysMenu; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.service.SysMenuService; + +/** + * 鑿滃崟淇℃伅 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/menu") +public class SysMenuController extends BaseController { + @Autowired + private SysMenuService menuService; + + /** + * 鑾峰彇鑿滃崟鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('system:menu:list')") + @GetMapping("/list") + public AjaxResult list(SysMenu menu) { + List menus = menuService.selectMenuList(menu, getUserId()); + return AjaxResult.success(menus); + } + + /** + * 鏍规嵁鑿滃崟缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('system:menu:query')") + @GetMapping(value = "/{menuId}") + public AjaxResult getInfo(@PathVariable Long menuId) { + return AjaxResult.success(menuService.selectMenuById(menuId)); + } + + /** + * 鑾峰彇鑿滃崟涓嬫媺鏍戝垪琛 + */ + @GetMapping("/treeselect") + public AjaxResult treeselect(SysMenu menu) { + List menus = menuService.selectMenuList(menu, getUserId()); + return AjaxResult.success(menuService.buildMenuTreeSelect(menus)); + } + + /** + * 鍔犺浇瀵瑰簲瑙掕壊鑿滃崟鍒楄〃鏍 + */ + @GetMapping(value = "/roleMenuTreeselect/{roleId}") + public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) { + List menus = menuService.selectMenuList(getUserId()); + AjaxResult ajax = AjaxResult.success(); + ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); + ajax.put("menus", menuService.buildMenuTreeSelect(menus)); + return ajax; + } + + /** + * 鏂板鑿滃崟 + */ + @PreAuthorize("@ss.hasPermi('system:menu:add')") + @Log(title = "鑿滃崟绠$悊", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysMenu menu) { + if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) { + return AjaxResult.error("鏂板鑿滃崟'" + menu.getMenuName() + "'澶辫触锛岃彍鍗曞悕绉板凡瀛樺湪"); + } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.isHttp(menu.getPath())) { + return AjaxResult.error("鏂板鑿滃崟'" + menu.getMenuName() + "'澶辫触锛屽湴鍧蹇呴』浠ttp(s)://寮澶"); + } + menu.setCreateBy(getUsername()); + return toAjax(menuService.insertMenu(menu)); + } + + /** + * 淇敼鑿滃崟 + */ + @PreAuthorize("@ss.hasPermi('system:menu:edit')") + @Log(title = "鑿滃崟绠$悊", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysMenu menu) { + if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) { + return AjaxResult.error("淇敼鑿滃崟'" + menu.getMenuName() + "'澶辫触锛岃彍鍗曞悕绉板凡瀛樺湪"); + } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.isHttp(menu.getPath())) { + return AjaxResult.error("淇敼鑿滃崟'" + menu.getMenuName() + "'澶辫触锛屽湴鍧蹇呴』浠ttp(s)://寮澶"); + } else if (menu.getMenuId().equals(menu.getParentId())) { + return AjaxResult.error("淇敼鑿滃崟'" + menu.getMenuName() + "'澶辫触锛屼笂绾ц彍鍗曚笉鑳介夋嫨鑷繁"); + } + menu.setUpdateBy(getUsername()); + return toAjax(menuService.updateMenu(menu)); + } + + /** + * 鍒犻櫎鑿滃崟 + */ + @PreAuthorize("@ss.hasPermi('system:menu:remove')") + @Log(title = "鑿滃崟绠$悊", businessType = BusinessType.DELETE) + @DeleteMapping("/{menuId}") + public AjaxResult remove(@PathVariable("menuId") Long menuId) { + if (menuService.hasChildByMenuId(menuId)) { + return AjaxResult.error("瀛樺湪瀛愯彍鍗,涓嶅厑璁稿垹闄"); + } + if (menuService.checkMenuExistRole(menuId)) { + return AjaxResult.error("鑿滃崟宸插垎閰,涓嶅厑璁稿垹闄"); + } + return toAjax(menuService.deleteMenuById(menuId)); + } +} \ No newline at end of file diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysNoticeController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysNoticeController.java new file mode 100644 index 000000000..e9bdc130d --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysNoticeController.java @@ -0,0 +1,86 @@ +package com.jsowell.web.controller.system; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.system.domain.SysNotice; +import com.jsowell.system.service.SysNoticeService; + +/** + * 鍏憡 淇℃伅鎿嶄綔澶勭悊 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/notice") +public class SysNoticeController extends BaseController { + @Autowired + private SysNoticeService noticeService; + + /** + * 鑾峰彇閫氱煡鍏憡鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('system:notice:list')") + @GetMapping("/list") + public TableDataInfo list(SysNotice notice) { + startPage(); + List list = noticeService.selectNoticeList(notice); + return getDataTable(list); + } + + /** + * 鏍规嵁閫氱煡鍏憡缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('system:notice:query')") + @GetMapping(value = "/{noticeId}") + public AjaxResult getInfo(@PathVariable Long noticeId) { + return AjaxResult.success(noticeService.selectNoticeById(noticeId)); + } + + /** + * 鏂板閫氱煡鍏憡 + */ + @PreAuthorize("@ss.hasPermi('system:notice:add')") + @Log(title = "閫氱煡鍏憡", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysNotice notice) { + notice.setCreateBy(getUsername()); + return toAjax(noticeService.insertNotice(notice)); + } + + /** + * 淇敼閫氱煡鍏憡 + */ + @PreAuthorize("@ss.hasPermi('system:notice:edit')") + @Log(title = "閫氱煡鍏憡", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysNotice notice) { + notice.setUpdateBy(getUsername()); + return toAjax(noticeService.updateNotice(notice)); + } + + /** + * 鍒犻櫎閫氱煡鍏憡 + */ + @PreAuthorize("@ss.hasPermi('system:notice:remove')") + @Log(title = "閫氱煡鍏憡", businessType = BusinessType.DELETE) + @DeleteMapping("/{noticeIds}") + public AjaxResult remove(@PathVariable Long[] noticeIds) { + return toAjax(noticeService.deleteNoticeByIds(noticeIds)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysPostController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysPostController.java new file mode 100644 index 000000000..9bf17a0c4 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysPostController.java @@ -0,0 +1,117 @@ +package com.jsowell.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.system.domain.SysPost; +import com.jsowell.system.service.SysPostService; + +/** + * 宀椾綅淇℃伅鎿嶄綔澶勭悊 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/post") +public class SysPostController extends BaseController { + @Autowired + private SysPostService postService; + + /** + * 鑾峰彇宀椾綅鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('system:post:list')") + @GetMapping("/list") + public TableDataInfo list(SysPost post) { + startPage(); + List list = postService.selectPostList(post); + return getDataTable(list); + } + + @Log(title = "宀椾綅绠$悊", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:post:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysPost post) { + List list = postService.selectPostList(post); + ExcelUtil util = new ExcelUtil(SysPost.class); + util.exportExcel(response, list, "宀椾綅鏁版嵁"); + } + + /** + * 鏍规嵁宀椾綅缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('system:post:query')") + @GetMapping(value = "/{postId}") + public AjaxResult getInfo(@PathVariable Long postId) { + return AjaxResult.success(postService.selectPostById(postId)); + } + + /** + * 鏂板宀椾綅 + */ + @PreAuthorize("@ss.hasPermi('system:post:add')") + @Log(title = "宀椾綅绠$悊", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysPost post) { + if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) { + return AjaxResult.error("鏂板宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶅悕绉板凡瀛樺湪"); + } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) { + return AjaxResult.error("鏂板宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶇紪鐮佸凡瀛樺湪"); + } + post.setCreateBy(getUsername()); + return toAjax(postService.insertPost(post)); + } + + /** + * 淇敼宀椾綅 + */ + @PreAuthorize("@ss.hasPermi('system:post:edit')") + @Log(title = "宀椾綅绠$悊", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysPost post) { + if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) { + return AjaxResult.error("淇敼宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶅悕绉板凡瀛樺湪"); + } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) { + return AjaxResult.error("淇敼宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶇紪鐮佸凡瀛樺湪"); + } + post.setUpdateBy(getUsername()); + return toAjax(postService.updatePost(post)); + } + + /** + * 鍒犻櫎宀椾綅 + */ + @PreAuthorize("@ss.hasPermi('system:post:remove')") + @Log(title = "宀椾綅绠$悊", businessType = BusinessType.DELETE) + @DeleteMapping("/{postIds}") + public AjaxResult remove(@PathVariable Long[] postIds) { + return toAjax(postService.deletePostByIds(postIds)); + } + + /** + * 鑾峰彇宀椾綅閫夋嫨妗嗗垪琛 + */ + @GetMapping("/optionselect") + public AjaxResult optionselect() { + List posts = postService.selectPostAll(); + return AjaxResult.success(posts); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysProfileController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysProfileController.java new file mode 100644 index 000000000..066d598ea --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysProfileController.java @@ -0,0 +1,131 @@ +package com.jsowell.web.controller.system; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.file.FileUploadUtils; +import com.jsowell.common.util.file.MimeTypeUtils; +import com.jsowell.framework.web.service.TokenService; +import com.jsowell.system.service.SysUserService; + +/** + * 涓汉淇℃伅 涓氬姟澶勭悊 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/user/profile") +public class SysProfileController extends BaseController { + @Autowired + private SysUserService userService; + + @Autowired + private TokenService tokenService; + + /** + * 涓汉淇℃伅 + */ + @GetMapping + public AjaxResult profile() { + LoginUser loginUser = getLoginUser(); + SysUser user = loginUser.getUser(); + AjaxResult ajax = AjaxResult.success(user); + ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); + ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername())); + return ajax; + } + + /** + * 淇敼鐢ㄦ埛 + */ + @Log(title = "涓汉淇℃伅", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult updateProfile(@RequestBody SysUser user) { + LoginUser loginUser = getLoginUser(); + SysUser sysUser = loginUser.getUser(); + user.setUserName(sysUser.getUserName()); + if (StringUtils.isNotEmpty(user.getPhone()) + && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { + return AjaxResult.error("淇敼鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛屾墜鏈哄彿鐮佸凡瀛樺湪"); + } + if (StringUtils.isNotEmpty(user.getEmail()) + && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) { + return AjaxResult.error("淇敼鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛岄偖绠辫处鍙峰凡瀛樺湪"); + } + user.setUserId(sysUser.getUserId()); + user.setPassword(null); + user.setAvatar(null); + user.setDeptId(null); + if (userService.updateUserProfile(user) > 0) { + // 鏇存柊缂撳瓨鐢ㄦ埛淇℃伅 + sysUser.setNickName(user.getNickName()); + sysUser.setPhone(user.getPhone()); + sysUser.setEmail(user.getEmail()); + sysUser.setSex(user.getSex()); + tokenService.setLoginUser(loginUser); + return AjaxResult.success(); + } + return AjaxResult.error("淇敼涓汉淇℃伅寮傚父锛岃鑱旂郴绠$悊鍛"); + } + + /** + * 閲嶇疆瀵嗙爜 + */ + @Log(title = "涓汉淇℃伅", businessType = BusinessType.UPDATE) + @PutMapping("/updatePwd") + public AjaxResult updatePwd(String oldPassword, String newPassword) { + LoginUser loginUser = getLoginUser(); + String userName = loginUser.getUsername(); + String password = loginUser.getPassword(); + if (!SecurityUtils.matchesPassword(oldPassword, password)) { + return AjaxResult.error("淇敼瀵嗙爜澶辫触锛屾棫瀵嗙爜閿欒"); + } + if (SecurityUtils.matchesPassword(newPassword, password)) { + return AjaxResult.error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚"); + } + if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0) { + // 鏇存柊缂撳瓨鐢ㄦ埛瀵嗙爜 + loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword)); + tokenService.setLoginUser(loginUser); + return AjaxResult.success(); + } + return AjaxResult.error("淇敼瀵嗙爜寮傚父锛岃鑱旂郴绠$悊鍛"); + } + + /** + * 澶村儚涓婁紶 + */ + @Log(title = "鐢ㄦ埛澶村儚", businessType = BusinessType.UPDATE) + @PostMapping("/avatar") + public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception { + if (!file.isEmpty()) { + LoginUser loginUser = getLoginUser(); + String avatar = FileUploadUtils.upload(JsowellConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION); + if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) { + AjaxResult ajax = AjaxResult.success(); + ajax.put("imgUrl", avatar); + // 鏇存柊缂撳瓨鐢ㄦ埛澶村儚 + loginUser.getUser().setAvatar(avatar); + tokenService.setLoginUser(loginUser); + return ajax; + } + } + return AjaxResult.error("涓婁紶鍥剧墖寮傚父锛岃鑱旂郴绠$悊鍛"); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysRegisterController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysRegisterController.java new file mode 100644 index 000000000..92617f352 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysRegisterController.java @@ -0,0 +1,35 @@ +package com.jsowell.web.controller.system; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.model.RegisterBody; +import com.jsowell.common.util.StringUtils; +import com.jsowell.framework.web.service.SysRegisterService; +import com.jsowell.system.service.SysConfigService; + +/** + * 娉ㄥ唽楠岃瘉 + * + * @author jsowell + */ +@RestController +public class SysRegisterController extends BaseController { + @Autowired + private SysRegisterService registerService; + + @Autowired + private SysConfigService configService; + + @PostMapping("/register") + public AjaxResult register(@RequestBody RegisterBody user) { + if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) { + return error("褰撳墠绯荤粺娌℃湁寮鍚敞鍐屽姛鑳斤紒"); + } + String msg = registerService.register(user); + return StringUtils.isEmpty(msg) ? success() : error(msg); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysRoleController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysRoleController.java new file mode 100644 index 000000000..0bb385491 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysRoleController.java @@ -0,0 +1,223 @@ +package com.jsowell.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.framework.web.service.SysPermissionService; +import com.jsowell.framework.web.service.TokenService; +import com.jsowell.system.domain.SysUserRole; +import com.jsowell.system.service.SysRoleService; +import com.jsowell.system.service.SysUserService; + +/** + * 瑙掕壊淇℃伅 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/role") +public class SysRoleController extends BaseController { + @Autowired + private SysRoleService roleService; + + @Autowired + private TokenService tokenService; + + @Autowired + private SysPermissionService permissionService; + + @Autowired + private SysUserService userService; + + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/list") + public TableDataInfo list(SysRole role) { + startPage(); + List list = roleService.selectRoleList(role); + return getDataTable(list); + } + + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:role:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysRole role) { + List list = roleService.selectRoleList(role); + ExcelUtil util = new ExcelUtil(SysRole.class); + util.exportExcel(response, list, "瑙掕壊鏁版嵁"); + } + + /** + * 鏍规嵁瑙掕壊缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('system:role:query')") + @GetMapping(value = "/{roleId}") + public AjaxResult getInfo(@PathVariable Long roleId) { + roleService.checkRoleDataScope(roleId); + return AjaxResult.success(roleService.selectRoleById(roleId)); + } + + /** + * 鏂板瑙掕壊 + */ + @PreAuthorize("@ss.hasPermi('system:role:add')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysRole role) { + if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) { + return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪"); + } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) { + return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪"); + } + role.setCreateBy(getUsername()); + return toAjax(roleService.insertRole(role)); + + } + + /** + * 淇敼淇濆瓨瑙掕壊 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysRole role) { + roleService.checkRoleAllowed(role); + roleService.checkRoleDataScope(role.getRoleId()); + if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) { + return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪"); + } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) { + return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪"); + } + role.setUpdateBy(getUsername()); + + if (roleService.updateRole(role) > 0) { + // 鏇存柊缂撳瓨鐢ㄦ埛鏉冮檺 + LoginUser loginUser = getLoginUser(); + if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) { + loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); + loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName())); + tokenService.setLoginUser(loginUser); + } + return AjaxResult.success(); + } + return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑱旂郴绠$悊鍛"); + } + + /** + * 淇敼淇濆瓨鏁版嵁鏉冮檺 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) + @PutMapping("/dataScope") + public AjaxResult dataScope(@RequestBody SysRole role) { + roleService.checkRoleAllowed(role); + roleService.checkRoleDataScope(role.getRoleId()); + return toAjax(roleService.authDataScope(role)); + } + + /** + * 鐘舵佷慨鏀 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) + @PutMapping("/changeStatus") + public AjaxResult changeStatus(@RequestBody SysRole role) { + roleService.checkRoleAllowed(role); + roleService.checkRoleDataScope(role.getRoleId()); + role.setUpdateBy(getUsername()); + return toAjax(roleService.updateRoleStatus(role)); + } + + /** + * 鍒犻櫎瑙掕壊 + */ + @PreAuthorize("@ss.hasPermi('system:role:remove')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.DELETE) + @DeleteMapping("/{roleIds}") + public AjaxResult remove(@PathVariable Long[] roleIds) { + return toAjax(roleService.deleteRoleByIds(roleIds)); + } + + /** + * 鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛 + */ + @PreAuthorize("@ss.hasPermi('system:role:query')") + @GetMapping("/optionselect") + public AjaxResult optionselect() { + return AjaxResult.success(roleService.selectRoleAll()); + } + + /** + * 鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛 + */ + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/authUser/allocatedList") + public TableDataInfo allocatedList(SysUser user) { + startPage(); + List list = userService.selectAllocatedList(user); + return getDataTable(list); + } + + /** + * 鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛 + */ + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/authUser/unallocatedList") + public TableDataInfo unallocatedList(SysUser user) { + startPage(); + List list = userService.selectUnallocatedList(user); + return getDataTable(list); + } + + /** + * 鍙栨秷鎺堟潈鐢ㄦ埛 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancel") + public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) { + return toAjax(roleService.deleteAuthUser(userRole)); + } + + /** + * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancelAll") + public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) { + return toAjax(roleService.deleteAuthUsers(roleId, userIds)); + } + + /** + * 鎵归噺閫夋嫨鐢ㄦ埛鎺堟潈 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/selectAll") + public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) { + roleService.checkRoleDataScope(roleId); + return toAjax(roleService.insertAuthUsers(roleId, userIds)); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysUserController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysUserController.java new file mode 100644 index 000000000..085786949 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/system/SysUserController.java @@ -0,0 +1,212 @@ +package com.jsowell.web.controller.system; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.system.service.SysPostService; +import com.jsowell.system.service.SysRoleService; +import com.jsowell.system.service.SysUserService; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 鐢ㄦ埛淇℃伅 + * + * @author jsowell + */ +@RestController +@RequestMapping("/system/user") +public class SysUserController extends BaseController { + @Autowired + private SysUserService userService; + + @Autowired + private SysRoleService roleService; + + @Autowired + private SysPostService postService; + + /** + * 鑾峰彇鐢ㄦ埛鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('system:user:list')") + @GetMapping("/list") + public TableDataInfo list(SysUser user) { + startPage(); + List list = userService.selectUserList(user); + return getDataTable(list); + } + + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:user:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysUser user) { + List list = userService.selectUserList(user); + ExcelUtil util = new ExcelUtil(SysUser.class); + util.exportExcel(response, list, "鐢ㄦ埛鏁版嵁"); + } + + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.IMPORT) + @PreAuthorize("@ss.hasPermi('system:user:import')") + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil(SysUser.class); + List userList = util.importExcel(file.getInputStream()); + String operName = getUsername(); + String message = userService.importUser(userList, updateSupport, operName); + return AjaxResult.success(message); + } + + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) { + ExcelUtil util = new ExcelUtil(SysUser.class); + util.importTemplateExcel(response, "鐢ㄦ埛鏁版嵁"); + } + + /** + * 鏍规嵁鐢ㄦ埛缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('system:user:query')") + @GetMapping(value = {"/", "/{userId}"}) + public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) { + userService.checkUserDataScope(userId); + AjaxResult ajax = AjaxResult.success(); + List roles = roleService.selectRoleAll(); + ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); + ajax.put("posts", postService.selectPostAll()); + if (StringUtils.isNotNull(userId)) { + SysUser sysUser = userService.selectUserById(userId); + ajax.put(AjaxResult.DATA_TAG, sysUser); + ajax.put("postIds", postService.selectPostListByUserId(userId)); + ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList())); + } + return ajax; + } + + /** + * 鏂板鐢ㄦ埛 + */ + @PreAuthorize("@ss.hasPermi('system:user:add')") + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysUser user) { + if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) { + return AjaxResult.error("鏂板鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛岀櫥褰曡处鍙峰凡瀛樺湪"); + } else if (StringUtils.isNotEmpty(user.getPhone()) + && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { + return AjaxResult.error("鏂板鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛屾墜鏈哄彿鐮佸凡瀛樺湪"); + } else if (StringUtils.isNotEmpty(user.getEmail()) + && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) { + return AjaxResult.error("鏂板鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛岄偖绠辫处鍙峰凡瀛樺湪"); + } + user.setCreateBy(getUsername()); + user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + return toAjax(userService.insertUser(user)); + } + + /** + * 淇敼鐢ㄦ埛 + */ + @PreAuthorize("@ss.hasPermi('system:user:edit')") + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysUser user) { + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getUserId()); + if (StringUtils.isNotEmpty(user.getPhone()) + && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { + return AjaxResult.error("淇敼鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛屾墜鏈哄彿鐮佸凡瀛樺湪"); + } else if (StringUtils.isNotEmpty(user.getEmail()) + && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) { + return AjaxResult.error("淇敼鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛岄偖绠辫处鍙峰凡瀛樺湪"); + } + user.setUpdateBy(getUsername()); + return toAjax(userService.updateUser(user)); + } + + /** + * 鍒犻櫎鐢ㄦ埛 + */ + @PreAuthorize("@ss.hasPermi('system:user:remove')") + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.DELETE) + @DeleteMapping("/{userIds}") + public AjaxResult remove(@PathVariable Long[] userIds) { + if (ArrayUtils.contains(userIds, getUserId())) { + return error("褰撳墠鐢ㄦ埛涓嶈兘鍒犻櫎"); + } + return toAjax(userService.deleteUserByIds(userIds)); + } + + /** + * 閲嶇疆瀵嗙爜 + */ + @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.UPDATE) + @PutMapping("/resetPwd") + public AjaxResult resetPwd(@RequestBody SysUser user) { + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getUserId()); + user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + user.setUpdateBy(getUsername()); + return toAjax(userService.resetPwd(user)); + } + + /** + * 鐘舵佷慨鏀 + */ + @PreAuthorize("@ss.hasPermi('system:user:edit')") + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.UPDATE) + @PutMapping("/changeStatus") + public AjaxResult changeStatus(@RequestBody SysUser user) { + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getUserId()); + user.setUpdateBy(getUsername()); + return toAjax(userService.updateUserStatus(user)); + } + + /** + * 鏍规嵁鐢ㄦ埛缂栧彿鑾峰彇鎺堟潈瑙掕壊 + */ + @PreAuthorize("@ss.hasPermi('system:user:query')") + @GetMapping("/authRole/{userId}") + public AjaxResult authRole(@PathVariable("userId") Long userId) { + AjaxResult ajax = AjaxResult.success(); + SysUser user = userService.selectUserById(userId); + List roles = roleService.selectRolesByUserId(userId); + ajax.put("user", user); + ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); + return ajax; + } + + /** + * 鐢ㄦ埛鎺堟潈瑙掕壊 + */ + @PreAuthorize("@ss.hasPermi('system:user:edit')") + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authRole") + public AjaxResult insertAuthRole(Long userId, Long[] roleIds) { + userService.checkUserDataScope(userId); + userService.insertUserAuth(userId, roleIds); + return success(); + } + + public static void main(String[] args) { + System.out.println(SecurityUtils.encryptPassword("admin123")); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/tool/SwaggerController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/tool/SwaggerController.java new file mode 100644 index 000000000..fafddca0a --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/tool/SwaggerController.java @@ -0,0 +1,23 @@ +package com.jsowell.web.controller.tool; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import com.jsowell.common.core.controller.BaseController; + +/** + * swagger 鎺ュ彛 + * + * @author jsowell + */ +@Controller +@RequestMapping("/tool/swagger") +public class SwaggerController extends BaseController { + + @PreAuthorize("@ss.hasPermi('tool:swagger:view')") + @GetMapping() + public String index() { + return redirect("/swagger-ui.html"); + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/tool/TestController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/tool/TestController.java new file mode 100644 index 000000000..a23dffe1f --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/tool/TestController.java @@ -0,0 +1,147 @@ +package com.jsowell.web.controller.tool; + +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.R; +import com.jsowell.common.util.StringUtils; +import io.swagger.annotations.*; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * swagger 鐢ㄦ埛娴嬭瘯鏂规硶 + * + * @author jsowell + */ +@Api("鐢ㄦ埛淇℃伅绠$悊123") +@RestController +@RequestMapping("/test/user") +public class TestController extends BaseController { + private final static Map users = new LinkedHashMap(); + + { + users.put(1, new UserEntity(1, "thinkgem" , "admin123" , "15888888888")); + users.put(2, new UserEntity(2, "jsowell-test" , "admin123" , "15666666666")); + } + + @ApiOperation("鑾峰彇鐢ㄦ埛鍒楄〃") + @GetMapping("/list") + public R> userList() { + List userList = new ArrayList(users.values()); + return R.ok(userList); + } + + @ApiOperation("鑾峰彇鐢ㄦ埛璇︾粏123") + @ApiImplicitParam(name = "userId" , value = "鐢ㄦ埛ID" , required = true, dataType = "int" , paramType = "path" , dataTypeClass = Integer.class) + @GetMapping("/{userId}") + public R getUser(@PathVariable Integer userId) { + if (!users.isEmpty() && users.containsKey(userId)) { + return R.ok(users.get(userId)); + } else { + return R.fail("鐢ㄦ埛涓嶅瓨鍦"); + } + } + + @ApiOperation("鏂板鐢ㄦ埛") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userId" , value = "鐢ㄦ埛id" , dataType = "Integer" , dataTypeClass = Integer.class), + @ApiImplicitParam(name = "username" , value = "鐢ㄦ埛鍚嶇О" , dataType = "String" , dataTypeClass = String.class), + @ApiImplicitParam(name = "password" , value = "鐢ㄦ埛瀵嗙爜" , dataType = "String" , dataTypeClass = String.class), + @ApiImplicitParam(name = "mobile" , value = "鐢ㄦ埛鎵嬫満" , dataType = "String" , dataTypeClass = String.class) + }) + @PostMapping("/save") + public R save(UserEntity user) { + if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) { + return R.fail("鐢ㄦ埛ID涓嶈兘涓虹┖"); + } + users.put(user.getUserId(), user); + return R.ok(); + } + + @ApiOperation("鏇存柊鐢ㄦ埛") + @PutMapping("/update") + public R update(@RequestBody UserEntity user) { + if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) { + return R.fail("鐢ㄦ埛ID涓嶈兘涓虹┖"); + } + if (users.isEmpty() || !users.containsKey(user.getUserId())) { + return R.fail("鐢ㄦ埛涓嶅瓨鍦"); + } + users.remove(user.getUserId()); + users.put(user.getUserId(), user); + return R.ok(); + } + + @ApiOperation("鍒犻櫎鐢ㄦ埛淇℃伅") + @ApiImplicitParam(name = "userId" , value = "鐢ㄦ埛ID" , required = true, dataType = "int" , paramType = "path" , dataTypeClass = Integer.class) + @DeleteMapping("/{userId}") + public R delete(@PathVariable Integer userId) { + if (!users.isEmpty() && users.containsKey(userId)) { + users.remove(userId); + return R.ok(); + } else { + return R.fail("鐢ㄦ埛涓嶅瓨鍦"); + } + } +} + +@ApiModel(value = "UserEntity" , description = "鐢ㄦ埛瀹炰綋") +class UserEntity { + @ApiModelProperty("鐢ㄦ埛ID") + private Integer userId; + + @ApiModelProperty("鐢ㄦ埛鍚嶇О") + private String username; + + @ApiModelProperty("鐢ㄦ埛瀵嗙爜") + private String password; + + @ApiModelProperty("鐢ㄦ埛鎵嬫満") + private String mobile; + + public UserEntity() { + + } + + public UserEntity(Integer userId, String username, String password, String mobile) { + this.userId = userId; + this.username = username; + this.password = password; + this.mobile = mobile; + } + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } +} diff --git a/jsowell-admin/src/main/java/com/jsowell/web/core/config/SwaggerConfig.java b/jsowell-admin/src/main/java/com/jsowell/web/core/config/SwaggerConfig.java new file mode 100644 index 000000000..31a8df346 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/core/config/SwaggerConfig.java @@ -0,0 +1,122 @@ +package com.jsowell.web.core.config; + +import com.jsowell.common.config.JsowellConfig; +import io.swagger.annotations.ApiOperation; +import io.swagger.models.auth.In; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.*; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; +import springfox.documentation.spring.web.plugins.Docket; + +import java.util.ArrayList; +import java.util.List; + +/** + * Swagger2鐨勬帴鍙i厤缃 + * + * @author jsowell + */ +@Configuration +public class SwaggerConfig { + /** + * 绯荤粺鍩虹閰嶇疆 + */ + @Autowired + private JsowellConfig jsowellConfig; + + /** + * 鏄惁寮鍚痵wagger + */ + @Value("${swagger.enabled}") + private boolean enabled; + + /** + * 璁剧疆璇锋眰鐨勭粺涓鍓嶇紑 + */ + @Value("${swagger.pathMapping}") + private String pathMapping; + + /** + * 鍒涘缓API + */ + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.OAS_30) + // 鏄惁鍚敤Swagger + .enable(enabled) + // 鐢ㄦ潵鍒涘缓璇PI鐨勫熀鏈俊鎭紝灞曠ず鍦ㄦ枃妗g殑椤甸潰涓紙鑷畾涔夊睍绀虹殑淇℃伅锛 + .apiInfo(apiInfo()) + // 璁剧疆鍝簺鎺ュ彛鏆撮湶缁橲wagger灞曠ず + .select() + // 鎵弿鎵鏈夋湁娉ㄨВ鐨刟pi锛岀敤杩欑鏂瑰紡鏇寸伒娲 + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + // 鎵弿鎸囧畾鍖呬腑鐨剆wagger娉ㄨВ + // .apis(RequestHandlerSelectors.basePackage("com.jsowell.project.tool.swagger")) + // 鎵弿鎵鏈 + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build() + /* 璁剧疆瀹夊叏妯″紡锛宻wagger鍙互璁剧疆璁块棶token */ + .securitySchemes(securitySchemes()) + .securityContexts(securityContexts()) + .pathMapping(pathMapping); + } + + /** + * 瀹夊叏妯″紡锛岃繖閲屾寚瀹歵oken閫氳繃Authorization澶磋姹傚ご浼犻 + */ + private List securitySchemes() { + List apiKeyList = new ArrayList(); + apiKeyList.add(new ApiKey("Authorization" , "Authorization" , In.HEADER.toValue())); + return apiKeyList; + } + + /** + * 瀹夊叏涓婁笅鏂 + */ + private List securityContexts() { + List securityContexts = new ArrayList<>(); + securityContexts.add( + SecurityContext.builder() + .securityReferences(defaultAuth()) + .operationSelector(o -> o.requestMappingPattern().matches("/.*")) + .build()); + return securityContexts; + } + + /** + * 榛樿鐨勫畨鍏ㄤ笂寮曠敤 + */ + private List defaultAuth() { + AuthorizationScope authorizationScope = new AuthorizationScope("global" , "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + List securityReferences = new ArrayList<>(); + securityReferences.add(new SecurityReference("Authorization" , authorizationScopes)); + return securityReferences; + } + + /** + * 娣诲姞鎽樿淇℃伅 + */ + private ApiInfo apiInfo() { + // 鐢ˋpiInfoBuilder杩涜瀹氬埗 + return new ApiInfoBuilder() + // 璁剧疆鏍囬 + .title("鏍囬锛氫妇瑙嗗悗鍙扮鐞嗙郴缁焈鎺ュ彛鏂囨。") + // 鎻忚堪 + // .description("鎻忚堪锛氱敤浜庣鐞嗛泦鍥㈡棗涓嬪叕鍙哥殑浜哄憳淇℃伅,鍏蜂綋鍖呮嫭XXX,XXX妯″潡...") + // 浣滆呬俊鎭 + .contact(new Contact(jsowellConfig.getName(), null, null)) + // 鐗堟湰 + .version("鐗堟湰鍙:" + jsowellConfig.getVersion()) + .build(); + } +} diff --git a/jsowell-admin/src/main/resources/META-INF/spring-devtools.properties b/jsowell-admin/src/main/resources/META-INF/spring-devtools.properties new file mode 100644 index 000000000..2b23f85a3 --- /dev/null +++ b/jsowell-admin/src/main/resources/META-INF/spring-devtools.properties @@ -0,0 +1 @@ +restart.include.json=/com.alibaba.fastjson.*.jar \ No newline at end of file diff --git a/jsowell-admin/src/main/resources/application-dev.yml b/jsowell-admin/src/main/resources/application-dev.yml new file mode 100644 index 000000000..4d22c90c8 --- /dev/null +++ b/jsowell-admin/src/main/resources/application-dev.yml @@ -0,0 +1,132 @@ +# 鏁版嵁婧愰厤缃 +spring: + # redis 閰嶇疆 + redis: + # 鍦板潃 + host: 192.168.2.2 + # 绔彛锛岄粯璁や负6379 + port: 6379 + # 鏁版嵁搴撶储寮 + database: 0 + # 瀵嗙爜 + password: + # 杩炴帴瓒呮椂鏃堕棿 + timeout: 10s + lettuce: + pool: + # 杩炴帴姹犱腑鐨勬渶灏忕┖闂茶繛鎺 + min-idle: 0 + # 杩炴帴姹犱腑鐨勬渶澶х┖闂茶繛鎺 + max-idle: 8 + # 杩炴帴姹犵殑鏈澶ф暟鎹簱杩炴帴鏁 + max-active: 8 + # #杩炴帴姹犳渶澶ч樆濉炵瓑寰呮椂闂达紙浣跨敤璐熷艰〃绀烘病鏈夐檺鍒讹級 + max-wait: -1ms + + # 鏁版嵁婧愰厤缃 + datasource: + type: com.alibaba.druid.pool.DruidDataSource + driverClassName: com.mysql.cj.jdbc.Driver + druid: + # 涓诲簱鏁版嵁婧 + master: + url: jdbc:mysql://192.168.2.2:3306/jsowell_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: root + password: 123456 + # 浠庡簱鏁版嵁婧 + slave: + # 浠庢暟鎹簮寮鍏/榛樿鍏抽棴 + enabled: false + url: + username: + password: + # 鍒濆杩炴帴鏁 + initialSize: 10 + # 鏈灏忚繛鎺ユ睜鏁伴噺 + minIdle: 10 + # 鏈澶ц繛鎺ユ睜鏁伴噺 + maxActive: 20 + # 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂 + maxWait: 60000 + # 閰嶇疆闂撮殧澶氫箙鎵嶈繘琛屼竴娆℃娴嬶紝妫娴嬮渶瑕佸叧闂殑绌洪棽杩炴帴锛屽崟浣嶆槸姣 + timeBetweenEvictionRunsMillis: 60000 + # 閰嶇疆涓涓繛鎺ュ湪姹犱腑鏈灏忕敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 + minEvictableIdleTimeMillis: 300000 + # 閰嶇疆涓涓繛鎺ュ湪姹犱腑鏈澶х敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 + maxEvictableIdleTimeMillis: 900000 + # 閰嶇疆妫娴嬭繛鎺ユ槸鍚︽湁鏁 + validationQuery: SELECT 1 FROM DUAL + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + webStatFilter: + enabled: true + statViewServlet: + enabled: true + # 璁剧疆鐧藉悕鍗曪紝涓嶅~鍒欏厑璁告墍鏈夎闂 + allow: + url-pattern: /druid/* + # 鎺у埗鍙扮鐞嗙敤鎴峰悕鍜屽瘑鐮 + login-username: jsowell + login-password: 123456 + filter: + stat: + enabled: true + # 鎱QL璁板綍 + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true + +# Swagger閰嶇疆 +swagger: + # 鏄惁寮鍚痵wagger + enabled: true + # 璇锋眰鍓嶇紑 + pathMapping: /dev-api + +# 鏃ュ織閰嶇疆 +logging: + level: + com.jsowell: debug + org.springframework: warn + +# 浜岀淮鐮佸墠缂 +qrcodeurl: + prefix: https://api.jsowellcloud.com + + +########################寰俊鏀粯鍙傛暟####################################### +#寰俊鍟嗘埛鍙 +wechat: + mchId: 1632405339 + #鍟嗗API璇佷功搴忓垪鍙 + mchSerialNo: 7596EF543159D21D25F199F82B9045FB9A82D7E0 + #鍟嗘埛鍦ㄥ井淇″叕浼楀钩鍙扮敵璇锋湇鍔″彿瀵瑰簲鐨凙PPID + appId: wxbb3e0d474569481d + #鍥炶皟鎶ユ枃瑙e瘑V3瀵嗛挜key + v3Key: bbac689f4654b209de4d6944808ec80b + #寰俊鑾峰彇骞冲彴璇佷功鍒楄〃鍦板潃 + certificates: + url: https://api.mch.weixin.qq.com/v3/certificates + #寰俊缁熶竴涓嬪崟Navtive鐨凙PI鍦板潃锛岀敤浜庝簩缁寸爜鏀粯 + unifiedOrder: + url: https://api.mch.weixin.qq.com/v3/pay/transactions/native + #寰俊缁熶竴涓嬪崟JSAPI鐨凙PI鍦板潃锛岀敤浜庡井淇″皬绋嬪簭 + jsurl: https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi + # 鐢宠閫娆続PI + refund: + jsurl: https://api.mch.weixin.qq.com/v3/refund/domestic/refunds + #寮傛鎺ユ敹寰俊鏀粯缁撴灉閫氱煡鐨勫洖璋冨湴鍧 + callback: https://api.jsowellcloud.com/uniapp/pay/wechatPayCallback + #寮傛鎺ユ敹寰俊閫娆剧粨鏋滈氱煡鐨勫洖璋冨湴鍧 + refundCallback: https://api.jsowellcloud.com/uniapp/pay/wechatPayRefundCallback + #鍟嗘埛璇佷功绉侀挜璺緞 + key: + path: D:/WechatCert/apiclient_key.pem +########################寰俊鏀粯鍙傛暟####################################### +# C:/Users/autum/Desktop/work/1632405339_20221125_cert/apiclient_key.pem +# E://key/1632405339_20221125_cert/apiclient_key.pem + diff --git a/jsowell-admin/src/main/resources/application-prd.yml b/jsowell-admin/src/main/resources/application-prd.yml new file mode 100644 index 000000000..25e5b52f5 --- /dev/null +++ b/jsowell-admin/src/main/resources/application-prd.yml @@ -0,0 +1,130 @@ +# 鏁版嵁婧愰厤缃 +spring: + # redis 閰嶇疆 + redis: + # 鍦板潃 + host: r-uf6k0uet7mihr5z78f.redis.rds.aliyuncs.com + # 绔彛锛岄粯璁や负6379 + port: 6379 + # 鏁版嵁搴撶储寮 + database: 0 + # 璐﹀彿 + username: jsowell + # 瀵嗙爜 + password: js@160829 + # 杩炴帴瓒呮椂鏃堕棿 + timeout: 10s + lettuce: + pool: + # 杩炴帴姹犱腑鐨勬渶灏忕┖闂茶繛鎺 + min-idle: 0 + # 杩炴帴姹犱腑鐨勬渶澶х┖闂茶繛鎺 + max-idle: 8 + # 杩炴帴姹犵殑鏈澶ф暟鎹簱杩炴帴鏁 + max-active: 8 + # #杩炴帴姹犳渶澶ч樆濉炵瓑寰呮椂闂达紙浣跨敤璐熷艰〃绀烘病鏈夐檺鍒讹級 + max-wait: -1ms + + datasource: + type: com.alibaba.druid.pool.DruidDataSource + driverClassName: com.mysql.cj.jdbc.Driver + druid: + # 涓诲簱鏁版嵁婧 + master: + url: jdbc:mysql://rm-uf6ra51u33dc3798l.mysql.rds.aliyuncs.com:3306/jsowell_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: jsowell + password: js@160829 + # 浠庡簱鏁版嵁婧 + slave: + # 浠庢暟鎹簮寮鍏/榛樿鍏抽棴 + enabled: false + url: + username: + password: + # 鍒濆杩炴帴鏁 + initialSize: 5 + # 鏈灏忚繛鎺ユ睜鏁伴噺 + minIdle: 10 + # 鏈澶ц繛鎺ユ睜鏁伴噺 + maxActive: 20 + # 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂 + maxWait: 60000 + # 閰嶇疆闂撮殧澶氫箙鎵嶈繘琛屼竴娆℃娴嬶紝妫娴嬮渶瑕佸叧闂殑绌洪棽杩炴帴锛屽崟浣嶆槸姣 + timeBetweenEvictionRunsMillis: 60000 + # 閰嶇疆涓涓繛鎺ュ湪姹犱腑鏈灏忕敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 + minEvictableIdleTimeMillis: 300000 + # 閰嶇疆涓涓繛鎺ュ湪姹犱腑鏈澶х敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 + maxEvictableIdleTimeMillis: 900000 + # 閰嶇疆妫娴嬭繛鎺ユ槸鍚︽湁鏁 + validationQuery: SELECT 1 FROM DUAL + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + webStatFilter: + enabled: true + statViewServlet: + enabled: true + # 璁剧疆鐧藉悕鍗曪紝涓嶅~鍒欏厑璁告墍鏈夎闂 + allow: + url-pattern: /druid/* + # 鎺у埗鍙扮鐞嗙敤鎴峰悕鍜屽瘑鐮 + login-username: jsowell + login-password: 123456 + filter: + stat: + enabled: true + # 鎱QL璁板綍 + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true + +# Swagger閰嶇疆 +swagger: + # 鏄惁寮鍚痵wagger + enabled: false + # 璇锋眰鍓嶇紑 + pathMapping: /dev-api + +# 鏃ュ織閰嶇疆 +logging: + level: + com.jsowell: info + org.springframework: warn + + +# 浜岀淮鐮佸墠缂 +qrcodeurl: + prefix: https://api.jsowellcloud.com + +########################寰俊鏀粯鍙傛暟####################################### +#寰俊鍟嗘埛鍙 +wechat: + mchId: 1632405339 + #鍟嗗API璇佷功搴忓垪鍙 + mchSerialNo: 7596EF543159D21D25F199F82B9045FB9A82D7E0 + #鍟嗘埛鍦ㄥ井淇″叕浼楀钩鍙扮敵璇锋湇鍔″彿瀵瑰簲鐨凙PPID + appId: wxbb3e0d474569481d + #鍥炶皟鎶ユ枃瑙e瘑V3瀵嗛挜key + v3Key: bbac689f4654b209de4d6944808ec80b + #寰俊鑾峰彇骞冲彴璇佷功鍒楄〃鍦板潃 + certificates: + url: https://api.mch.weixin.qq.com/v3/certificates + #寰俊缁熶竴涓嬪崟Navtive鐨凙PI鍦板潃锛岀敤浜庝簩缁寸爜鏀粯 + unifiedOrder: + url: https://api.mch.weixin.qq.com/v3/pay/transactions/native + #寰俊缁熶竴涓嬪崟JSAPI鐨凙PI鍦板潃锛岀敤浜庡井淇″皬绋嬪簭 + jsurl: https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi + # 鐢宠閫娆続PI + refund: + jsurl: https://api.mch.weixin.qq.com/v3/refund/domestic/refunds + #寮傛鎺ユ敹寰俊鏀粯缁撴灉閫氱煡鐨勫洖璋冨湴鍧 + callback: https://api.jsowellcloud.com/uniapp/pay/wechatPayCallback + #寮傛鎺ユ敹寰俊閫娆剧粨鏋滈氱煡鐨勫洖璋冨湴鍧 + refundCallback: https://api.jsowellcloud.com/uniapp/pay/wechatPayRefundCallback + #鍟嗘埛璇佷功绉侀挜璺緞 + key: + path: /usr/local/1632405339_20221125_cert/apiclient_key.pem +########################寰俊鏀粯鍙傛暟####################################### diff --git a/jsowell-admin/src/main/resources/application.yml b/jsowell-admin/src/main/resources/application.yml new file mode 100644 index 000000000..209b2d56e --- /dev/null +++ b/jsowell-admin/src/main/resources/application.yml @@ -0,0 +1,128 @@ +# 椤圭洰鐩稿叧閰嶇疆 +jsowell: + # 鍚嶇О + name: jsowell-service + # 鐗堟湰 + version: 1.0.0 + # 鐗堟潈骞翠唤 + copyrightYear: 2022 + # 瀹炰緥婕旂ず寮鍏 + demoEnabled: true + # 鏂囦欢璺緞 绀轰緥锛 Windows閰嶇疆D:/jsowell/uploadPath锛孡inux閰嶇疆 /home/jsowell/uploadPath锛 + profile: D:/jsowell/uploadPath + # 鑾峰彇ip鍦板潃寮鍏 + addressEnabled: false + # 楠岃瘉鐮佺被鍨 math 鏁扮粍璁$畻 char 瀛楃楠岃瘉 + captchaType: char + +# 寮鍙戠幆澧冮厤缃 +server: + # 鏈嶅姟鍣ㄧ殑HTTP绔彛锛岄粯璁や负8080 + port: 8080 + servlet: + # 搴旂敤鐨勮闂矾寰 + context-path: / + tomcat: + # tomcat鐨刄RI缂栫爜 + uri-encoding: UTF-8 + # 杩炴帴鏁版弧鍚庣殑鎺掗槦鏁帮紝榛樿涓100 + accept-count: 1000 + threads: + # tomcat鏈澶х嚎绋嬫暟锛岄粯璁や负200 + max: 800 + # Tomcat鍚姩鍒濆鍖栫殑绾跨▼鏁帮紝榛樿鍊10 + min-spare: 100 +# token閰嶇疆 +token: + # 浠ょ墝鑷畾涔夋爣璇 + header: Authorization + # 浠ょ墝瀵嗛挜 + secret: cdnflglzjoxjovuusklsqjtuup + # 浠ょ墝鏈夋晥鏈燂紙榛樿300鍒嗛挓锛 + expireTime: 300 + # 鎺ュ彛浠ょ墝鏈夋晥鏈 涓涓湀 + serviceExpireTime: 43200 + +# 鐢ㄦ埛閰嶇疆 +user: + password: + # 瀵嗙爜鏈澶ч敊璇鏁 + maxRetryCount: 5 + # 瀵嗙爜閿佸畾鏃堕棿锛堥粯璁10鍒嗛挓锛 + lockTime: 10 + +# Spring閰嶇疆 +spring: + # 璧勬簮淇℃伅 + messages: + # 鍥介檯鍖栬祫婧愭枃浠惰矾寰 + basename: i18n/messages + profiles: + active: { profile } + # 鏂囦欢涓婁紶 + servlet: + multipart: + # 鍗曚釜鏂囦欢澶у皬 + max-file-size: 10MB + # 璁剧疆鎬讳笂浼犵殑鏂囦欢澶у皬 + max-request-size: 20MB + + # 鏈嶅姟妯″潡 + devtools: + restart: + # 鐑儴缃插紑鍏 + enabled: true + +# MyBatis閰嶇疆 +mybatis: + # 鎼滅储鎸囧畾鍖呭埆鍚 + typeAliasesPackage: com.jsowell.**.domain + # 閰嶇疆mapper鐨勬壂鎻忥紝鎵惧埌鎵鏈夌殑mapper.xml鏄犲皠鏂囦欢 + mapperLocations: classpath*:mapper/**/*Mapper.xml + # 鍔犺浇鍏ㄥ眬鐨勯厤缃枃浠 + configLocation: classpath:mybatis/mybatis-config.xml + +# PageHelper鍒嗛〉鎻掍欢 +pagehelper: + helperDialect: mysql + supportMethodsArguments: true + params: count=countSql + +# 闃叉XSS鏀诲嚮 +xss: + # 杩囨护寮鍏 + enabled: true + # 鎺掗櫎閾炬帴锛堝涓敤閫楀彿鍒嗛殧锛 + excludes: /system/notice + # 鍖归厤閾炬帴 + urlPatterns: /system/*,/monitor/*,/tool/* + +# 寰俊鐧诲綍鐩稿叧 +weixin: + login: + # gateway: https://api.weixin.qq.com/sns/oauth2/access_token + gateway: https://api.weixin.qq.com/sns/jscode2session + appid: wxbb3e0d474569481d + appsecret: bbac689f4654b209de4d6944808ec80b + redirectUrl: http://www.kuangstudy.com/login/api/wx/callback + sendMsg: + startChargingTmpId: BGgZe98QHr0I1S1GrtGps5_rLX6n9cW1AsXhL4YkHHc + stopChargingTmpId: UyBPbADlZfsCj89rh_xvfZGlxTW5J5KURpZtt9CNFrY + +#Sim鍗′俊鎭 +xunzhong: + apiId: 1126135385835987 + apiSecret: 9dT9iz0bfYx6UljzKj3pJEodjTvjd1lF + sim: + getSimCardDetailURL: https://iot.commchina.net/api/customer/v1/sim_cards/get_sim_card_detail + renewURL: https://iot.commchina.net/api/customer/v1/sim_cards/renew + trafficPool: + poolListURL: https://iot.commchina.net/api/customer/v1/traffic_pools/pool_list + +wulian: + appId: 23178072739 + appSecret: 9cf4e28037ca5ea1a8ea8e63959d454b + getWay: https://api.wl1688.net/iotc/getway + name: + getSimInfo: api.v2.card.info + WuLianSimRenew: api.v2.order.renew \ No newline at end of file diff --git a/jsowell-admin/src/main/resources/banner.txt b/jsowell-admin/src/main/resources/banner.txt new file mode 100644 index 000000000..3c39b64a3 --- /dev/null +++ b/jsowell-admin/src/main/resources/banner.txt @@ -0,0 +1,9 @@ + _ _____ ______ ________ _ _ + | |/ ____|/ __ \ \ / / ____| | | | + | | (___ | | | \ \ /\ / /| |__ | | | | + _ | |\___ \| | | |\ \/ \/ / | __| | | | | + | |__| |____) | |__| | \ /\ / | |____| |____| |____ + \____/|_____/ \____/ \/ \/ |______|______|______| + +Application Version: ${jsowell.version} +Spring Boot Version: ${spring-boot.version} \ No newline at end of file diff --git a/jsowell-admin/src/main/resources/i18n/messages.properties b/jsowell-admin/src/main/resources/i18n/messages.properties new file mode 100644 index 000000000..4098fc92c --- /dev/null +++ b/jsowell-admin/src/main/resources/i18n/messages.properties @@ -0,0 +1,37 @@ +#閿欒娑堟伅 +not.null=* 蹇呴』濉啓 +user.jcaptcha.error=楠岃瘉鐮侀敊璇 +user.jcaptcha.expire=楠岃瘉鐮佸凡澶辨晥 +user.not.exists=鐢ㄦ埛涓嶅瓨鍦/瀵嗙爜閿欒 +user.password.not.match=鐢ㄦ埛涓嶅瓨鍦/瀵嗙爜閿欒 +user.password.retry.limit.count=瀵嗙爜杈撳叆閿欒{0}娆 +user.password.retry.limit.exceed=瀵嗙爜杈撳叆閿欒{0}娆★紝甯愭埛閿佸畾{1}鍒嗛挓 +user.password.delete=瀵逛笉璧凤紝鎮ㄧ殑璐﹀彿宸茶鍒犻櫎 +user.blocked=鐢ㄦ埛宸插皝绂侊紝璇疯仈绯荤鐞嗗憳 +role.blocked=瑙掕壊宸插皝绂侊紝璇疯仈绯荤鐞嗗憳 +user.logout.success=閫鍑烘垚鍔 + +length.not.valid=闀垮害蹇呴』鍦▄min}鍒皗max}涓瓧绗︿箣闂 + +user.username.not.valid=* 2鍒20涓眽瀛椼佸瓧姣嶃佹暟瀛楁垨涓嬪垝绾跨粍鎴愶紝涓斿繀椤讳互闈炴暟瀛楀紑澶 +user.password.not.valid=* 5-50涓瓧绗 + +user.email.not.valid=閭鏍煎紡閿欒 +user.mobile.phone.number.not.valid=鎵嬫満鍙锋牸寮忛敊璇 +user.login.success=鐧诲綍鎴愬姛 +user.register.success=娉ㄥ唽鎴愬姛 +user.notfound=璇烽噸鏂扮櫥褰 +user.forcelogout=绠$悊鍛樺己鍒堕鍑猴紝璇烽噸鏂扮櫥褰 +user.unknown.error=鏈煡閿欒锛岃閲嶆柊鐧诲綍 + +##鏂囦欢涓婁紶娑堟伅 +upload.exceed.maxSize=涓婁紶鐨勬枃浠跺ぇ灏忚秴鍑洪檺鍒剁殑鏂囦欢澶у皬锛
鍏佽鐨勬枃浠舵渶澶уぇ灏忔槸锛歿0}MB锛 +upload.filename.exceed.length=涓婁紶鐨勬枃浠跺悕鏈闀縶0}涓瓧绗 + +##鏉冮檺 +no.permission=鎮ㄦ病鏈夋暟鎹殑鏉冮檺锛岃鑱旂郴绠$悊鍛樻坊鍔犳潈闄 [{0}] +no.create.permission=鎮ㄦ病鏈夊垱寤烘暟鎹殑鏉冮檺锛岃鑱旂郴绠$悊鍛樻坊鍔犳潈闄 [{0}] +no.update.permission=鎮ㄦ病鏈変慨鏀规暟鎹殑鏉冮檺锛岃鑱旂郴绠$悊鍛樻坊鍔犳潈闄 [{0}] +no.delete.permission=鎮ㄦ病鏈夊垹闄ゆ暟鎹殑鏉冮檺锛岃鑱旂郴绠$悊鍛樻坊鍔犳潈闄 [{0}] +no.export.permission=鎮ㄦ病鏈夊鍑烘暟鎹殑鏉冮檺锛岃鑱旂郴绠$悊鍛樻坊鍔犳潈闄 [{0}] +no.view.permission=鎮ㄦ病鏈夋煡鐪嬫暟鎹殑鏉冮檺锛岃鑱旂郴绠$悊鍛樻坊鍔犳潈闄 [{0}] diff --git a/jsowell-admin/src/main/resources/logback.xml b/jsowell-admin/src/main/resources/logback.xml new file mode 100644 index 000000000..3abfdc498 --- /dev/null +++ b/jsowell-admin/src/main/resources/logback.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/sys-info.log + + + + ${log.path}/sys-info.%d{yyyy-MM-dd}.log + + ${maxHistory} + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + + ${log.path}/netty9011.log + + + + ${log.path}/netty9011.%d{yyyy-MM-dd}.log + + ${maxHistory} + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + + ${log.path}/sys-error.log + + + + ${log.path}/sys-error.%d{yyyy-MM-dd}.log + + ${maxHistory} + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + ${log.path}/sys-user.log + + + ${log.path}/sys-user.%d{yyyy-MM-dd}.log + + ${maxHistory} + + + ${log.pattern} + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jsowell-admin/src/main/resources/mybatis/mybatis-config.xml b/jsowell-admin/src/main/resources/mybatis/mybatis-config.xml new file mode 100644 index 000000000..9e14908f2 --- /dev/null +++ b/jsowell-admin/src/main/resources/mybatis/mybatis-config.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java new file mode 100644 index 000000000..f12eda1a2 --- /dev/null +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -0,0 +1,688 @@ +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.collect.ImmutableMap; +import com.jsowell.JsowellApplication; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.LoginRequestData; +import com.jsowell.common.core.domain.ykc.TransactionRecordsData; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.*; +import com.jsowell.common.util.id.SnUtils; +import com.jsowell.common.util.id.SnowflakeIdWorker; +import com.jsowell.common.util.ip.AddressUtils; +import com.jsowell.netty.command.ykc.IssueQRCodeCommand; +import com.jsowell.netty.command.ykc.ProofreadTimeCommand; +import com.jsowell.netty.handler.HeartbeatRequestHandler; +import com.jsowell.netty.service.yunkuaichong.YKCBusinessService; +import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.domain.PileBillingDetail; +import com.jsowell.pile.domain.PileBillingTemplate; +import com.jsowell.pile.domain.PileStationInfo; +import com.jsowell.pile.domain.WxpayCallbackRecord; +import com.jsowell.pile.dto.BasicPileDTO; +import com.jsowell.pile.dto.BatchCreatePileDTO; +import com.jsowell.pile.dto.ImportBillingTemplateDTO; +import com.jsowell.pile.dto.QueryOrderDTO; +import com.jsowell.pile.dto.QueryPileDTO; +import com.jsowell.pile.dto.QueryStationDTO; +import com.jsowell.pile.dto.WeixinPayDTO; +import com.jsowell.pile.mapper.MemberBasicInfoMapper; +import com.jsowell.pile.mapper.PileBillingTemplateMapper; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileBillingTemplateService; +import com.jsowell.pile.service.IPileMsgRecordService; +import com.jsowell.pile.service.IPileStationInfoService; +import com.jsowell.pile.service.SimCardService; +import com.jsowell.pile.service.WechatPayService; +import com.jsowell.pile.service.WxpayCallbackRecordService; +import com.jsowell.pile.vo.web.*; +import com.jsowell.service.MemberService; +import com.jsowell.service.OrderService; +import com.jsowell.service.PileRemoteService; +import com.jsowell.service.PileService; +import com.jsowell.wxpay.common.WeChatPayParameter; +import com.jsowell.wxpay.dto.AppletTemplateMessageSendDTO; +import com.jsowell.wxpay.dto.WeChatRefundDTO; +import com.jsowell.wxpay.response.WechatPayRefundRequest; +import com.jsowell.wxpay.service.WxAppletRemoteService; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.StopWatch; + +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@ActiveProfiles("dev") +@SpringBootTest(classes = JsowellApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@RunWith(SpringRunner.class) +public class SpringBootTestController { + + private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @Autowired + private SnUtils snUtils; + + @Autowired + private PileService pileService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Autowired + private IPileMsgRecordService pileMsgRecordService; + + @Autowired + private IPileStationInfoService pileStationInfoService; + + @Autowired + private YKCPushCommandService ykcPushBusinessService; + + @Autowired + private HeartbeatRequestHandler heartbeatRequestHandler; + + @Autowired + private YKCBusinessService ykcBusinessService; + + @Autowired + private PileBillingTemplateMapper pileBillingTemplateMapper; + + @Autowired + private PileRemoteService pileRemoteService; + + @Autowired + private MemberService memberService; + + @Autowired + private OrderService orderService; + + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private MemberBasicInfoMapper memberBasicInfoMapper; + + @Autowired + private SimCardService simCardService; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private WechatPayService wechatPayService; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Autowired + private WxpayCallbackRecordService wxpayCallbackRecordService; + + @Autowired + private WxAppletRemoteService wxAppletRemoteService; + + @Autowired + private RedisCache redisCache; + + @Test + public void testCloseStartFailedOrder() { + String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addDays(new Date(), -2)); + String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date()); + orderBasicInfoService.closeStartFailedOrder(startTime, endTime); + } + + @Test + public void testRedisSaveRealTimeData() { + String pileSn = "88000000000001"; + String connectorCode = "01"; + String orderCode = "88000000000001012211161342359448"; + + String pileConnectorCode = pileSn + connectorCode; + String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + pileConnectorCode + "_" + orderCode; + + // for (int i = 0; i < 10; i++) { + // try { + // Thread.sleep(10000); + // } catch (InterruptedException e) { + // e.printStackTrace(); + // } + // Date now = new Date(); + // redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", now), i + ":" + DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", now)); + // } + + orderBasicInfoService.getChargingRealTimeData(orderCode); + } + + @Test + public void testuniformMessageSend() { + AppletTemplateMessageSendDTO appletTemplateMessageSendDTO = new AppletTemplateMessageSendDTO(); + // String openId = wxAppletRemoteService.getOpenIdByCode("0537u2100jTXsP1Y0Y300j426t47u210"); + // System.out.println("openId:" + openId); + + appletTemplateMessageSendDTO.setTouser("o4REX5MprZfTaLnVNxfdOY-wnwGI"); // openid + + String templateId = "UyBPbADlZfsCj89rh_xvfZGlxTW5J5KURpZtt9CNFrY"; + appletTemplateMessageSendDTO.setTemplate_id(templateId); + // appletTemplateMessageSendDTO.setPage("璺宠浆鐨勯〉闈"); + Map map = new HashMap<>(); + map.put("amount17", ImmutableMap.of("value", "锟100")); // 缁撴潫鏃堕棿 + map.put("time3", ImmutableMap.of("value", "2022-12-30")); // 缁撴潫鏃堕棿 + map.put("thing7", ImmutableMap.of("value", "thing7")); // 缁撴潫鍘熷洜 + + // map.put("thing5", ImmutableMap.of("value", "thing5")); // 缁撴潫鍘熷洜 + // map.put("time2", ImmutableMap.of("value", "time2")); // 缁撴潫鍘熷洜 + appletTemplateMessageSendDTO.setData(map); + + wxAppletRemoteService.uniformMessageSend(appletTemplateMessageSendDTO); + } + + @Test + public void testWeChatRefund() { + WeChatRefundDTO dto = new WeChatRefundDTO(); + dto.setRefundType("2"); + dto.setMemberId("82100864"); + dto.setRefundAmount(new BigDecimal("1.23")); + orderBasicInfoService.weChatRefund(dto); + } + + @Test + public void testSelectBalanceRechargeRecord() { + List list = wxpayCallbackRecordService.queryBalanceRechargeRecordOfTheLatestYear("82100864"); + System.out.println(list); + } + + @Test + public void testSelectOrderBasicInfoList() { + QueryOrderDTO orderBasicInfo = new QueryOrderDTO(); + orderBasicInfo.setPileSn("88000000000001"); + orderBasicInfo.setOrderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue()); + List orderListVOS = orderBasicInfoService.selectOrderBasicInfoList(orderBasicInfo); + System.out.println(orderListVOS); + for (OrderListVO orderListVO : orderListVOS) { + if (StringUtils.equals(orderListVO.getOrderStatus(), OrderStatusEnum.IN_THE_CHARGING.getValue())) { + // 淇敼鏁版嵁搴撹鍗曠姸鎬 + OrderBasicInfo info = OrderBasicInfo.builder() + .id(Long.parseLong(orderListVO.getId())) + .orderStatus(OrderStatusEnum.ABNORMAL.getValue()) + .build(); + orderBasicInfoService.updateOrderBasicInfo(info); + } + } + } + + @Test + public void testWechatRefund() throws JsonProcessingException { + WechatPayRefundRequest request = new WechatPayRefundRequest(); + request.setTransaction_id("4200001656202212302746036536"); // 寰俊鏀粯鍗曞彿 + request.setOut_trade_no("768677222373363712"); // 鍟嗘埛璁㈠崟鍙 + // 鐢熸垚閫娆惧崟鍙 + request.setOut_refund_no(SnowflakeIdWorker.getSnowflakeId()); // 鍟嗘埛閫娆惧崟鍙 + request.setNotify_url(WeChatPayParameter.refundNotifyUrl); // 鍥炶皟鎺ュ彛 + WechatPayRefundRequest.Amount amount = new WechatPayRefundRequest.Amount(); + amount.setRefund(10 * 100); // 閫娆鹃噾棰 + amount.setTotal(10 * 100); // 鍘熻鍗曢噾棰 + request.setAmount(amount); + request.setReason("缁撶畻閫娆"); + request.setFunds_account("AVAILABLE"); + + wechatPayService.ApplyForWechatPayRefundV3(request); + + // 閫娆炬柟娉 + + } + + @Test + public void testUpdatePileSimInfo() { + String pileSn = "88000000000001"; + String iccid = "898604940121C1385725"; + pileBasicInfoService.updatePileSimInfo(pileSn, iccid); + } + + @Test + public void testPay() { + String code = "081zIoGa11GamE0iVVIa1aaJ4G0zIoGE"; + String openId = memberService.getOpenIdByCode(code); + Map pay = null; + try { + WeixinPayDTO dto = new WeixinPayDTO(); + dto.setOpenId(openId); + dto.setAmount("0.01"); + pay = orderService.weixinPayV3(dto); + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println(JSONObject.toJSONString(pay)); + } + + @Test + public void testMemberRegisterAndLogin() { + // String phone = "18512341234"; + // String merchantId = "18512341234"; + // String token = memberService.memberRegisterAndLogin(phone, merchantId); + // System.out.println(token); + // String memberId = JWTUtils.getMemberId(token); + // System.out.println(memberId); + } + + @Test + public void testMemberBasicInfoMapper() { + // String memberId = "21772870"; + // BigDecimal principalBalance = new BigDecimal("-10"); + // BigDecimal giftBalance = new BigDecimal("-110"); + // Integer version = 2; + // int i = memberBasicInfoMapper.updateMemberBalance(memberId, principalBalance, giftBalance, version); + // if (i == 1) { + // System.out.println("鏇存柊浣欓鎴愬姛"); + // } else { + // System.out.println("鏇存柊浣欓澶辫触"); + // } + } + + @Test + public void testGenerateBillingTemplateMsgBody() { + String pileSn = "88000000000001"; + // 鏍规嵁妗╁彿鏌ヨ璁¤垂妯℃澘 + BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn); + + byte[] messageBody = pileBillingTemplateService.generateBillingTemplateMsgBody(pileSn, billingTemplateVO); + System.out.println(BytesUtil.binary(messageBody, 16)); + } + + @Test + public void testAnalysisPileParameter() { + BasicPileDTO dto = new BasicPileDTO(); + // 3涓兘涓嶄紶鐨勬儏鍐 + try { + System.out.println("3涓兘涓嶄紶鐨勬儏鍐"); + dto.setPileSn(""); + dto.setConnectorCode(""); + dto.setPileConnectorCode(""); + orderService.analysisPileParameter(dto); + System.out.println("鏁版嵁姝g‘"); + } catch (BusinessException e) { + System.out.println(e.getMessage()); + } + System.out.println(); + + // 鍙紶sn鐨勬儏鍐 + try { + System.out.println("鍙紶sn鐨勬儏鍐"); + dto.setConnectorCode(""); + dto.setPileConnectorCode(""); + dto.setPileSn("88000000000001"); + orderService.analysisPileParameter(dto); + System.out.println("鏁版嵁姝g‘"); + } catch (BusinessException e) { + System.out.println(e.getMessage()); + } + System.out.println(); + + // + try { + System.out.println("鍙┛鏋彛鍙风殑鎯呭喌"); + dto.setConnectorCode("01"); + dto.setPileConnectorCode(""); + dto.setPileSn(""); + orderService.analysisPileParameter(dto); + System.out.println("鏁版嵁姝g‘"); + } catch (BusinessException e) { + System.out.println(e.getMessage()); + } + System.out.println(); + + // 鍙紶鍏呯數妗╂灙鍙g紪鍙风殑鎯呭喌 + try { + System.out.println("鍙紶鍏呯數妗╂灙鍙g紪鍙风殑鎯呭喌"); + dto.setPileConnectorCode("8800000000000101"); + dto.setConnectorCode(""); + dto.setPileSn(""); + orderService.analysisPileParameter(dto); + System.out.println("鏁版嵁姝g‘"); + } catch (BusinessException e) { + System.out.println(e.getMessage()); + } + + try { + System.out.println(); + System.out.println("浼犲厖鐢垫々鏋猻n+鏋彛鍙风殑鎯呭喌"); + dto.setPileConnectorCode(""); + dto.setConnectorCode("01"); + dto.setPileSn("88000000000001"); + orderService.analysisPileParameter(dto); + System.out.println("鏁版嵁姝g‘"); + } catch (BusinessException e) { + System.out.println(e.getMessage()); + } + } + + @Test + public void testImportBillingTemplate() { + ImportBillingTemplateDTO dto = new ImportBillingTemplateDTO(); + dto.setBillingTemplateId("1"); + // 鏌ヨ鍏叡璁¤垂妯℃澘鏄惁瀛樺湪 + PileBillingTemplate pileBillingTemplate = pileBillingTemplateMapper.selectPileBillingTemplateById(Long.valueOf(dto.getBillingTemplateId())); + if (pileBillingTemplate == null) { + + } + List billingDetailList = pileBillingTemplate.getPileBillingDetailList(); + } + + @Test + public void testProcess() { + // 62 68 + String msgString = "680da300000388000000000001010020d06840a40000130000000000000000000000000000000088000000000001010202000000000000000000000000000000000000000000000000000000000000000000001516"; + byte[] msg = BytesUtil.str2Bcd(msgString); + boolean b = YKCUtils.checkMsg(msg); + // ykcBusinessService.process(msg, null); + } + + @Test + public void testHeartbeat() { + // heartbeatRequestHandler.updateStatus("88000000000001", "01", "0"); + + // heartbeatRequestHandler.updateStatus("88000000000001", "02", "0"); + } + + @Test + public void testPush() { + byte[] msg = new byte[]{}; + String pileSn = "88000000000001"; + // ykcPushBusinessService.push(msg, pileSn, YKCFrameTypeCode.READ_REAL_TIME_MONITOR_DATA_CODE); + } + + @Test + public void TestMapUtils() { + String address = "娣灞辨箹闀囬粍娴︽睙鍗楄矾278鍙"; + String areaCode = "320000,320500,320583"; + Map longitudeAndLatitude = AddressUtils.getLongitudeAndLatitude(areaCode, address); + System.out.println(longitudeAndLatitude); + } + + @Test + public void testCreatePile() { + BatchCreatePileDTO dto = BatchCreatePileDTO.builder() + .merchantId("1") + .stationId("1") + .softwareProtocol("1") + // .connectorNum(1) + // .num(10) + // .productionDate(new Date()) + .build(); + pileService.batchCreatePile(dto); + } + + @Test + public void testGetIncre() { + StopWatch stopWatch = new StopWatch(); + + // 鐢熸垚100涓 + stopWatch.start("鐢熸垚100涓猻n鍙"); + List list2 = snUtils.generateSN(1); + stopWatch.stop(); + System.out.println(list2); + + System.out.println(stopWatch.getLastTaskTimeMillis()); + } + + @Test + public void testDict() { + String dictValue = DictUtils.getDictValue("query_pile_info", "url"); + String station_type = DictUtils.getDictLabel("station_type", "1"); + System.out.println(station_type); + System.out.println("123"); + + } + + @Test + public void testSelectByMerchantId() { + List list = pileStationInfoService.selectStationListByMerchantId(Long.valueOf(Constants.ONE)); + System.out.println(list); + } + + @Test + public void testStr2Bcd() { + String logicCardNum = "00000000"; + byte[] logicCardNumByteArr = BytesUtil.str2Bcd(logicCardNum); + System.out.println(Arrays.toString(logicCardNumByteArr)); + } + + @Test + public void testBigDecimalMultiply() { + BigDecimal a = new BigDecimal("216.5"); + BigDecimal b = new BigDecimal("11.5"); + + BigDecimal result = a.multiply(b).setScale(2, BigDecimal.ROUND_HALF_UP); + System.out.println(result); + } + + @Test + public void testRemoteUpdate() { + ArrayList list = new ArrayList<>(); + list.add("88000000000001"); + pileRemoteService.updateFile(list); + } + + @Test + public void testGetUserPhoneNum() { + String code = "0e5394cfa4eb41c6181ed257f2368a86dfe4ebdac0a4fac85df63657637e6cc3"; + wxAppletRemoteService.getMobileNumberByCode(code); + } + + @Test + public void testDistance() { + QueryStationDTO dto = new QueryStationDTO(); + dto.setStationLat("123.2222"); + dto.setStationLng("55.6232"); + + // pileStationInfoService.uniAppQueryStationInfos(dto); + } + + /** + * 鐢熸垚鑻辨枃瀛楁瘝闅忔満鏁 RandomStringUtils.randomAlphabetic(10); + * 鐢熸垚鏁板瓧闅忔満鏁 RandomStringUtils.randomNumeric(10); + * 瀛楁瘝+鏁板瓧缁撳悎 RandomStringUtils.randomAlphanumeric(10); + */ + @Test + public void Test() throws ParseException { + /*String s = RandomStringUtils.randomAlphanumeric(32); + System.out.println(s); // PuLe4Tyyg1jSFNPhF5d2Ts9ejRn6E8KQ + String str = "JS160829"; + System.out.println(Md5Utils.hash(str).toUpperCase(Locale.ROOT)); +*/ + + Date startTimeDate = sdf.parse("2022-11-26 10:44:11"); + Date endTimeDate = sdf.parse("2022-11-27 12:45:11"); + + System.out.println(DateUtils.getDatePoor(endTimeDate, startTimeDate)); // 1澶2灏忔椂1鍒嗛挓 + + + + + /*String stra = "sp_mchid=1632405339&sub_mchid=1632405339&out_trade_no=1217752501201407033233368318&sp_appid=wxbb3e0d474569481d&sub_appid=wxbb3e0d474569481d" + + "bbac689f4654b209de4d6944808ec80b"; + System.out.println(Md5Utils.hash(stra).toUpperCase(Locale.ROOT));*/ + } + + @Test + public void testSimCard() throws ParseException { + ArrayList list = Lists.newArrayList(); + Collections.addAll(list, "898607B9102090253556", "898607B9102090253560"); + // String s = list.toString().replaceAll("(?:\\[|null|\\]| +)", ""); + // System.out.println(s); + // List simCardVOList = simCardService.selectSimCardInfoByIccId(list); + // System.out.println(simCardVOList.toString()); + + // simCardService.XunZhongSimRenewal(list, 12); + // System.out.println(s); + + // SimCardVO simCardVO = simCardService.searchByLoop("898607B9102090253556"); + // + // System.out.println(simCardVO.toString()); + + simCardService.WuLianSimRenew(list, 1); + + + } + + @Test + public void testRefund() { + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode("88000000000001012212171045412218"); + orderInfo.setReason("鍏呯數寮傚父涓锛屾ュ仠寮鍏"); + + TransactionRecordsData data = TransactionRecordsData.builder() + .orderCode("88000000000001012212171045412218") + .consumptionAmount(String.valueOf(0.00)) + .stopReasonMsg(orderInfo.getReason()) + .totalElectricity("0") + .sharpUsedElectricity("0") + .peakUsedElectricity("0") + .flatUsedElectricity("0") + .valleyUsedElectricity("0") + .build(); + + orderBasicInfoService.settleOrder(data, orderInfo); + } + + + @Test + public void testLoginHandler() { + String msg = "8800000000001001010f63362d333000000000898604b319227036282200"; + byte[] msgBody = BytesUtil.str2Bcd(msg); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鐮 + byte[] pileSnByte = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.binary(pileSnByte, 16); + // log.info("妗╁彿锛歿}", pileSn); + + + // 妗╃被鍨 0 琛ㄧず鐩存祦妗╋紝 1 琛ㄧず浜ゆ祦妗 + startIndex += length; + length = 1; + byte[] pileTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileType = BytesUtil.bcd2Str(pileTypeByteArr); + + // 鍏呯數鏋暟閲 + startIndex += length; + byte[] connectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorNum = BytesUtil.bcd2Str(connectorNumByteArr); + + // 閫氫俊鍗忚鐗堟湰 鐗堟湰鍙蜂箻 10锛寁1.0 琛ㄧず 0x0A + startIndex += length; + byte[] communicationVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + // int i = Integer.parseInt(BytesUtil.bcd2Str(communicationVersionByteArr)); // 0F --> 15 + BigDecimal bigDecimal = new BigDecimal(BytesUtil.bcd2Str(communicationVersionByteArr)); + BigDecimal communicationVersionTemp = bigDecimal.divide(new BigDecimal(10)); + String communicationVersion = "v" + communicationVersionTemp; + + // 绋嬪簭鐗堟湰 + startIndex += length; + length = 8; + byte[] programVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String programVersion = BytesUtil.bcd2Str(programVersionByteArr); + + // 缃戠粶杩炴帴绫诲瀷 0x00 SIM 鍗 0x01 LAN 0x02 WAN 0x03 鍏朵粬 + startIndex += length; + length = 1; + byte[] internetConnectionTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String internetConnection = BytesUtil.bcd2Str(internetConnectionTypeByteArr); + + // sim鍗 + startIndex += length; + length = 10; + byte[] simCardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String iccid = BytesUtil.bin2HexStr(simCardNumByteArr); + + // 杩愯惀鍟 0x00 绉诲姩 0x02 鐢典俊 0x03 鑱旈 0x04 鍏朵粬 + startIndex += length; + length = 1; + byte[] businessTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String business = BytesUtil.bcd2Str(businessTypeByteArr); + + LoginRequestData loginRequestData = LoginRequestData.builder() + .pileSn(pileSn) + .pileType(pileType) + .connectorNum(connectorNum) + .communicationVersion(communicationVersion) + .programVersion(programVersion) + .internetConnection(internetConnection) + .iccid(iccid) + .business(business) + .build(); + + // 缁撴灉锛堥粯璁 0x01:鐧诲綍澶辫触锛 + byte[] flag = Constants.oneByteArray; + + // 閫氳繃妗╃紪鐮丼N鏌ヨ鏁版嵁搴擄紝濡傛灉鏈夋暟鎹紝鍒欑櫥褰曟垚鍔燂紝鍚﹀垯鐧诲綍澶辫触 + QueryPileDTO dto = new QueryPileDTO(); + dto.setPileSn(pileSn); + List list = pileBasicInfoService.queryPileInfos(dto); + if (CollectionUtils.isNotEmpty(list)) { + flag = Constants.zeroByteArray; + // 鐧诲綍鎴愬姛锛屼繚瀛樻々鍙峰拰channel鐨勫叧绯 + + // PileChannelEntity.put(pileSn, channel); + // 鏇存敼妗╁拰璇ユ々涓嬬殑鏋彛鐘舵佸垎鍒负 鍦ㄧ嚎銆佺┖闂 + // pileBasicInfoService.updatePileStatus(pileSn, PileStatusEnum.ON_LINE.getValue()); + // pileConnectorInfoService.updateConnectorStatusByPileSn(pileSn, PileConnectorDataBaseStatusEnum.FREE.getValue()); + + // 瀵规椂 + ProofreadTimeCommand command = ProofreadTimeCommand.builder().pileSn(pileSn).build(); + ykcPushCommandService.pushProofreadTimeCommand(command); + + // 鍏叡鏂规硶淇敼鐘舵 + pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(new byte[]{0x01}), pileSn, null, null, null); + + + // 涓嬪彂浜岀淮鐮 + IssueQRCodeCommand issueQRCodeCommand = IssueQRCodeCommand.builder().pileSn(pileSn).build(); + ykcPushCommandService.pushIssueQRCodeCommand(issueQRCodeCommand); + + } + + + // 鍏呯數妗╀娇鐢ㄧ殑sim鍗★紝鎶婁俊鎭瓨搴 + if (StringUtils.equals("00", internetConnection)) { + try { + pileBasicInfoService.updatePileSimInfo(pileSn, iccid); + } catch (Exception e) { + // log.error("鏇存柊鍏呯數妗﹕im鍗′俊鎭け璐", e); + System.out.println(e.getMessage()); + } + } + + // 淇濆瓨鎶ユ枃 + String jsonMsg = JSONObject.toJSONString(loginRequestData); + // pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ykcDataProtocol.getHEXString()); + + // // 娑堟伅浣 + // byte[] messageBody = Bytes.concat(pileSnByte, flag); + // return getResult(ykcDataProtocol, messageBody); + } + + @Test + public void testGetMemberToken(){ + String memberId = JWTUtils.getMemberId("eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzY1MTY5MzgsImV4cCI6MTY3OTEwODkzOH0.4MwhZIOpnCfQloR7zEm2hwPOh2yyI2qxbBbTcv_SnZ4"); + System.out.println(memberId); + } + +} diff --git a/jsowell-common/pom.xml b/jsowell-common/pom.xml new file mode 100644 index 000000000..03605d687 --- /dev/null +++ b/jsowell-common/pom.xml @@ -0,0 +1,181 @@ + + + 4.0.0 + + com.jsowell + jsowell-charger-web + 1.0.0 + + + jsowell-common + + + common閫氱敤宸ュ叿 + + + + + + + org.springframework + spring-context-support + + + + + org.springframework + spring-web + + + + + org.springframework.boot + spring-boot-starter-security + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter-validation + + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + + + com.fasterxml.jackson.core + jackson-databind + + + + + com.alibaba.fastjson2 + fastjson2 + + + + + commons-io + commons-io + + + + + commons-fileupload + commons-fileupload + + + + + org.apache.poi + poi-ooxml + + + + + org.yaml + snakeyaml + + + + + io.jsonwebtoken + jjwt + + + + + javax.xml.bind + jaxb-api + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + org.apache.commons + commons-pool2 + + + + + eu.bitwalker + UserAgentUtils + + + + + javax.servlet + javax.servlet-api + + + + + org.projectlombok + lombok + + + + + com.google.guava + guava + + + + com.tencentcloudapi + tencentcloud-sdk-java + + + com.github.qcloudsms + qcloudsms + + + + com.thoughtworks.xstream + xstream + + + + cn.hutool + hutool-all + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + /src/test/** + + utf-8 + + + + + + + \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/Anonymous.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/Anonymous.java new file mode 100644 index 000000000..a3d3cd235 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/Anonymous.java @@ -0,0 +1,18 @@ +package com.jsowell.common.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 鍖垮悕璁块棶涓嶉壌鏉冩敞瑙 + * + * @author jsowell + */ +@Target({ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Anonymous { +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/DataScope.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/DataScope.java new file mode 100644 index 000000000..beb2c9259 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/DataScope.java @@ -0,0 +1,27 @@ +package com.jsowell.common.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 鏁版嵁鏉冮檺杩囨护娉ㄨВ + * + * @author jsowell + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface DataScope { + /** + * 閮ㄩ棬琛ㄧ殑鍒悕 + */ + public String deptAlias() default ""; + + /** + * 鐢ㄦ埛琛ㄧ殑鍒悕 + */ + public String userAlias() default ""; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/DataSource.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/DataSource.java new file mode 100644 index 000000000..5444f4135 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/DataSource.java @@ -0,0 +1,28 @@ +package com.jsowell.common.annotation; + +import com.jsowell.common.enums.DataSourceType; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 鑷畾涔夊鏁版嵁婧愬垏鎹㈡敞瑙 + *

+ * 浼樺厛绾э細鍏堟柟娉曪紝鍚庣被锛屽鏋滄柟娉曡鐩栦簡绫讳笂鐨勬暟鎹簮绫诲瀷锛屼互鏂规硶鐨勪负鍑嗭紝鍚﹀垯浠ョ被涓婄殑涓哄噯 + * + * @author jsowell + */ +@Target({ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface DataSource { + /** + * 鍒囨崲鏁版嵁婧愬悕绉 + */ + public DataSourceType value() default DataSourceType.MASTER; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/Excel.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/Excel.java new file mode 100644 index 000000000..04ca36e64 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/Excel.java @@ -0,0 +1,181 @@ +package com.jsowell.common.annotation; + +import com.jsowell.common.util.poi.ExcelHandlerAdapter; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.IndexedColors; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.math.BigDecimal; + +/** + * 鑷畾涔夊鍑篍xcel鏁版嵁娉ㄨВ + * + * @author jsowell + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Excel { + /** + * 瀵煎嚭鏃跺湪excel涓帓搴 + */ + public int sort() default Integer.MAX_VALUE; + + /** + * 瀵煎嚭鍒癊xcel涓殑鍚嶅瓧. + */ + public String name() default ""; + + /** + * 鏃ユ湡鏍煎紡, 濡: yyyy-MM-dd + */ + public String dateFormat() default ""; + + /** + * 濡傛灉鏄瓧鍏哥被鍨嬶紝璇疯缃瓧鍏哥殑type鍊 (濡: sys_user_sex) + */ + public String dictType() default ""; + + /** + * 璇诲彇鍐呭杞〃杈惧紡 (濡: 0=鐢,1=濂,2=鏈煡) + */ + public String readConverterExp() default ""; + + /** + * 鍒嗛殧绗︼紝璇诲彇瀛楃涓茬粍鍐呭 + */ + public String separator() default ","; + + /** + * BigDecimal 绮惧害 榛樿:-1(榛樿涓嶅紑鍚疊igDecimal鏍煎紡鍖) + */ + public int scale() default -1; + + /** + * BigDecimal 鑸嶅叆瑙勫垯 榛樿:BigDecimal.ROUND_HALF_EVEN + */ + public int roundingMode() default BigDecimal.ROUND_HALF_EVEN; + + /** + * 瀵煎嚭鏃跺湪excel涓瘡涓垪鐨勯珮搴 鍗曚綅涓哄瓧绗 + */ + public double height() default 14; + + /** + * 瀵煎嚭鏃跺湪excel涓瘡涓垪鐨勫 鍗曚綅涓哄瓧绗 + */ + public double width() default 16; + + /** + * 鏂囧瓧鍚庣紑,濡% 90 鍙樻垚90% + */ + public String suffix() default ""; + + /** + * 褰撳间负绌烘椂,瀛楁鐨勯粯璁ゅ + */ + public String defaultValue() default ""; + + /** + * 鎻愮ず淇℃伅 + */ + public String prompt() default ""; + + /** + * 璁剧疆鍙兘閫夋嫨涓嶈兘杈撳叆鐨勫垪鍐呭. + */ + public String[] combo() default {}; + + /** + * 鏄惁闇瑕佺旱鍚戝悎骞跺崟鍏冩牸,搴斿闇姹:鍚湁list闆嗗悎鍗曞厓鏍) + */ + public boolean needMerge() default false; + + /** + * 鏄惁瀵煎嚭鏁版嵁,搴斿闇姹:鏈夋椂鎴戜滑闇瑕佸鍑轰竴浠芥ā鏉,杩欐槸鏍囬闇瑕佷絾鍐呭闇瑕佺敤鎴锋墜宸ュ~鍐. + */ + public boolean isExport() default true; + + /** + * 鍙︿竴涓被涓殑灞炴у悕绉,鏀寔澶氱骇鑾峰彇,浠ュ皬鏁扮偣闅斿紑 + */ + public String targetAttr() default ""; + + /** + * 鏄惁鑷姩缁熻鏁版嵁,鍦ㄦ渶鍚庤拷鍔犱竴琛岀粺璁℃暟鎹诲拰 + */ + public boolean isStatistics() default false; + + /** + * 瀵煎嚭绫诲瀷锛0鏁板瓧 1瀛楃涓 2鍥剧墖锛 + */ + public ColumnType cellType() default ColumnType.STRING; + + /** + * 瀵煎嚭鍒楀ご鑳屾櫙鑹 + */ + public IndexedColors headerBackgroundColor() default IndexedColors.GREY_50_PERCENT; + + /** + * 瀵煎嚭鍒楀ご瀛椾綋棰滆壊 + */ + public IndexedColors headerColor() default IndexedColors.WHITE; + + /** + * 瀵煎嚭鍗曞厓鏍艰儗鏅壊 + */ + public IndexedColors backgroundColor() default IndexedColors.WHITE; + + /** + * 瀵煎嚭鍗曞厓鏍煎瓧浣撻鑹 + */ + public IndexedColors color() default IndexedColors.BLACK; + + /** + * 瀵煎嚭瀛楁瀵归綈鏂瑰紡 + */ + public HorizontalAlignment align() default HorizontalAlignment.CENTER; + + /** + * 鑷畾涔夋暟鎹鐞嗗櫒 + */ + public Class handler() default ExcelHandlerAdapter.class; + + /** + * 鑷畾涔夋暟鎹鐞嗗櫒鍙傛暟 + */ + public String[] args() default {}; + + /** + * 瀛楁绫诲瀷锛0锛氬鍑哄鍏ワ紱1锛氫粎瀵煎嚭锛2锛氫粎瀵煎叆锛 + */ + Type type() default Type.ALL; + + public enum Type { + ALL(0), EXPORT(1), IMPORT(2); + private final int value; + + Type(int value) { + this.value = value; + } + + public int value() { + return this.value; + } + } + + public enum ColumnType { + NUMERIC(0), STRING(1), IMAGE(2); + private final int value; + + ColumnType(int value) { + this.value = value; + } + + public int value() { + return this.value; + } + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/Excels.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/Excels.java new file mode 100644 index 000000000..a8a8bd048 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/Excels.java @@ -0,0 +1,17 @@ +package com.jsowell.common.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Excel娉ㄨВ闆 + * + * @author jsowell + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Excels { + public Excel[] value(); +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/Log.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/Log.java new file mode 100644 index 000000000..cf872cc8e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/Log.java @@ -0,0 +1,41 @@ +package com.jsowell.common.annotation; + +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.enums.OperatorType; + +import java.lang.annotation.*; + +/** + * 鑷畾涔夋搷浣滄棩蹇楄褰曟敞瑙 + * + * @author jsowell + */ +@Target({ElementType.PARAMETER, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Log { + /** + * 妯″潡 + */ + public String title() default ""; + + /** + * 鍔熻兘 + */ + public BusinessType businessType() default BusinessType.OTHER; + + /** + * 鎿嶄綔浜虹被鍒 + */ + public OperatorType operatorType() default OperatorType.MANAGE; + + /** + * 鏄惁淇濆瓨璇锋眰鐨勫弬鏁 + */ + public boolean isSaveRequestData() default true; + + /** + * 鏄惁淇濆瓨鍝嶅簲鐨勫弬鏁 + */ + public boolean isSaveResponseData() default true; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/RateLimiter.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/RateLimiter.java new file mode 100644 index 000000000..8310351d0 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/RateLimiter.java @@ -0,0 +1,40 @@ +package com.jsowell.common.annotation; + +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.enums.LimitType; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 闄愭祦娉ㄨВ + * + * @author jsowell + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface RateLimiter { + /** + * 闄愭祦key + */ + public String key() default CacheConstants.RATE_LIMIT_KEY; + + /** + * 闄愭祦鏃堕棿,鍗曚綅绉 + */ + public int time() default 60; + + /** + * 闄愭祦娆℃暟 + */ + public int count() default 100; + + /** + * 闄愭祦绫诲瀷 + */ + public LimitType limitType() default LimitType.DEFAULT; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/RepeatSubmit.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/RepeatSubmit.java new file mode 100644 index 000000000..f7a879efa --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/RepeatSubmit.java @@ -0,0 +1,29 @@ +package com.jsowell.common.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 鑷畾涔夋敞瑙i槻姝㈣〃鍗曢噸澶嶆彁浜 + * + * @author jsowell + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface RepeatSubmit { + /** + * 闂撮殧鏃堕棿(ms)锛屽皬浜庢鏃堕棿瑙嗕负閲嶅鎻愪氦 + */ + public int interval() default 5000; + + /** + * 鎻愮ず娑堟伅 + */ + public String message() default "涓嶅厑璁搁噸澶嶆彁浜わ紝璇风◢鍊欏啀璇"; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/config/JsowellConfig.java b/jsowell-common/src/main/java/com/jsowell/common/config/JsowellConfig.java new file mode 100644 index 000000000..eeafd2d84 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/config/JsowellConfig.java @@ -0,0 +1,132 @@ +package com.jsowell.common.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * 璇诲彇椤圭洰鐩稿叧閰嶇疆 + * + * @author jsowell + */ +@Component +@ConfigurationProperties(prefix = "jsowell") +public class JsowellConfig { + /** + * 椤圭洰鍚嶇О + */ + private String name; + + /** + * 鐗堟湰 + */ + private String version; + + /** + * 鐗堟潈骞翠唤 + */ + private String copyrightYear; + + /** + * 瀹炰緥婕旂ず寮鍏 + */ + private boolean demoEnabled; + + /** + * 涓婁紶璺緞 + */ + private static String profile; + + /** + * 鑾峰彇鍦板潃寮鍏 + */ + private static boolean addressEnabled; + + /** + * 楠岃瘉鐮佺被鍨 + */ + private static String captchaType; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getCopyrightYear() { + return copyrightYear; + } + + public void setCopyrightYear(String copyrightYear) { + this.copyrightYear = copyrightYear; + } + + public boolean isDemoEnabled() { + return demoEnabled; + } + + public void setDemoEnabled(boolean demoEnabled) { + this.demoEnabled = demoEnabled; + } + + public static String getProfile() { + return profile; + } + + public void setProfile(String profile) { + JsowellConfig.profile = profile; + } + + public static boolean isAddressEnabled() { + return addressEnabled; + } + + public void setAddressEnabled(boolean addressEnabled) { + JsowellConfig.addressEnabled = addressEnabled; + } + + public static String getCaptchaType() { + return captchaType; + } + + public void setCaptchaType(String captchaType) { + JsowellConfig.captchaType = captchaType; + } + + /** + * 鑾峰彇瀵煎叆涓婁紶璺緞 + */ + public static String getImportPath() { + return getProfile() + "/import"; + } + + /** + * 鑾峰彇澶村儚涓婁紶璺緞 + */ + public static String getAvatarPath() { + return getProfile() + "/avatar"; + } + + /** + * 鑾峰彇涓嬭浇璺緞 + */ + public static String getDownloadPath() { + return getProfile() + "/download/"; + } + + /** + * 鑾峰彇涓婁紶璺緞 + */ + public static String getUploadPath() { + return getProfile() + "/upload"; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java new file mode 100644 index 000000000..992e73874 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java @@ -0,0 +1,102 @@ +package com.jsowell.common.constant; + +/** + * 缂撳瓨鐨刱ey 甯搁噺 + * + * @author jsowell + */ +public class CacheConstants { + /** + * + */ + + + public static final int cache_expire_time_1m = 60; + + public static final int cache_expire_time_5m = 60 * 5; + + public static final int cache_expire_time_10m = 60 * 10; + + public static final int cache_expire_time_1h = 60 * 60; + + public static final int cache_expire_time_12h = 60 * 60 * 12; + + public static final int cache_expire_time_1d = 60 * 60 * 24; + + public static final String PILE_PROGRAM_VERSION = "pile_program_version"; + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曚俊鎭疜ey + */ + public static final String GET_ORDER_INFO_BY_ORDER_CODE = "get_order_info_by_order_code:"; + + /** + * 鍏呯數鏋彛瀹炴椂鐩戞帶鏁版嵁 + */ + public static final String PILE_REAL_TIME_MONITOR_DATA = "pile_real_time_monitor_data:"; + + /** + * 鍏呯數妗╂渶鍚庤繛鎺ユ椂闂 + */ + public static final String PILE_LAST_CONNECTION = "pile_last_connection:"; + + /** + * 鏌ヨ鏋彛淇℃伅鍒楄〃鍓嶇紑 + */ + public static final String SELECT_PILE_CONNECTOR_INFO_LIST = "select_pile_connector_info_list:"; + + /** + * 鍏呯數妗╂灙鍙g姸鎬佸墠缂 + */ + public static final String PILE_CONNECTOR_STATUS_KEY = "pile_connector_status:"; + + /** + * 鍏呯數妗﹕n鐢熸垚 key + */ + public static final String PILE_SN_GENERATE_KEY = "pile_sn_generate_"; + + /** + * 鍏呯數妗╄鎯卥ey + */ + public static final String PILE_DETAIL_KEY = "pile_detail:"; + + /** + * 鐧诲綍鐢ㄦ埛 redis key + */ + public static final String LOGIN_TOKEN_KEY = "login_tokens:"; + + /** + * 楠岃瘉鐮 redis key + */ + public static final String CAPTCHA_CODE_KEY = "captcha_codes:"; + + /** + * 鍙傛暟绠$悊 cache key + */ + public static final String SYS_CONFIG_KEY = "sys_config:"; + + /** + * 瀛楀吀绠$悊 cache key + */ + public static final String SYS_DICT_KEY = "sys_dict:"; + + /** + * 闃查噸鎻愪氦 redis key + */ + public static final String REPEAT_SUBMIT_KEY = "repeat_submit:"; + + /** + * 闄愭祦 redis key + */ + public static final String RATE_LIMIT_KEY = "rate_limit:"; + + /** + * 鐧诲綍璐︽埛瀵嗙爜閿欒娆℃暟 redis key + */ + public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:"; + + /** + * 楠岃瘉鐮佹湁鏁堟湡鏃堕暱 redis key + */ + public static final String SMS_VERIFICATION_CODE_KEY = "sms_verification_code:"; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/Constants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/Constants.java new file mode 100644 index 000000000..9943ac46e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/Constants.java @@ -0,0 +1,210 @@ +package com.jsowell.common.constant; + +import io.jsonwebtoken.Claims; + +/** + * 閫氱敤甯搁噺淇℃伅 + * + * @author jsowell + */ +public class Constants { + // 鍏呯數妗﹕n鍙烽暱搴 + public static final int PILE_SN_LENGTH = 14; + + // 鍏呯數妗╂灙鍙e彿闀垮害 + public static final int CONNECTOR_CODE_LENGTH = 2; + + // 鍏呯數妗╂灙鍙g紪鍙烽暱搴 + public static final int PILE_CONNECTOR_CODE_LENGTH = PILE_SN_LENGTH + CONNECTOR_CODE_LENGTH; + + public static final String SOCKET_IP = "127.0.0.1"; + public static final Integer SOCKET_PORT = 9011; + + public static final String updateServerIP = "192.168.2.5"; + public static final int port = 0x15; + + public static final byte[] updateServerPort = new byte[]{port}; + + public static final String updateServerUserName = "ftpuser"; + + public static final String updateServerPassword = "ftp123456"; + + public static final String filePath = "/pile/test.bin"; + + public static final String partnerId = "1632405339"; // 鍟嗘埛鍙稩d + + // public static final String APP_ID = "wxbb3e0d474569481d"; // 涓捐鍏呯數缃 wxbb3e0d474569481d + // + // public static final String APP_SECRET = "bbac689f4654b209de4d6944808ec80b"; // 涓捐鍏呯數缃 bbac689f4654b209de4d6944808ec80b + + public static final String ZERO = "0"; + + public static final String ONE = "1"; + + public static final String TWO = "2"; + + public static final String THREE = "3"; + + public static final int zero = 0; + + public static final int one = 1; + + public static final byte zeroByte = 0x00; + + public static final byte[] zeroByteArray = new byte[]{zeroByte}; + + public static final byte oneByte = 0x01; + + public static final byte[] oneByteArray = new byte[]{oneByte}; + + public static final byte twoByte = 0x02; + + public static final byte[] twoByteArray = new byte[]{twoByte}; + + public static final String FAULT_CODE = "255"; + + public static final String DOUBLE_ZERO = "00"; + + public static final String ZERO_ONE = "01"; + + public static final String ZERO_THREE = "03"; + /** + * 鍒犻櫎鏍囪瘑 0鏍囪瘑姝e父 + */ + public static final String DEL_FLAG_NORMAL = "0"; + + /** + * 鍒犻櫎鏍囪瘑 1鏍囪瘑琚垹闄 + */ + public static final String DEL_FLAG_DELETE = "1"; + /** + * UTF-8 瀛楃闆 + */ + public static final String UTF8 = "UTF-8"; + + /** + * GBK 瀛楃闆 + */ + public static final String GBK = "GBK"; + + /** + * http璇锋眰 + */ + public static final String HTTP = "http://"; + + /** + * https璇锋眰 + */ + public static final String HTTPS = "https://"; + + /** + * 閫氱敤鎴愬姛鏍囪瘑 + */ + public static final String SUCCESS = "0"; + + /** + * 閫氱敤澶辫触鏍囪瘑 + */ + public static final String FAIL = "1"; + + /** + * 鐧诲綍鎴愬姛 + */ + public static final String LOGIN_SUCCESS = "Success"; + + /** + * 娉ㄩ攢 + */ + public static final String LOGOUT = "Logout"; + + /** + * 娉ㄥ唽 + */ + public static final String REGISTER = "Register"; + + /** + * 鐧诲綍澶辫触 + */ + public static final String LOGIN_FAIL = "Error"; + + /** + * 鐧诲綍楠岃瘉鐮佹湁鏁堟湡 + */ + public static final Integer VERIFICATION_CODE_EXPIRATION_TIME = 10; + + /** + * 楠岃瘉鐮佹湁鏁堟湡锛堝垎閽燂級 + */ + public static final Integer CAPTCHA_EXPIRATION = 2; + + /** + * 浠ょ墝 + */ + public static final String TOKEN = "token"; + + /** + * 浠ょ墝鍓嶇紑 + */ + public static final String TOKEN_PREFIX = "Bearer"; + + /** + * 浠ょ墝鍓嶇紑 + */ + public static final String LOGIN_USER_KEY = "login_user_key"; + + /** + * 鐢ㄦ埛ID + */ + public static final String JWT_USERID = "userid"; + + /** + * 鐢ㄦ埛鍚嶇О + */ + public static final String JWT_USERNAME = Claims.SUBJECT; + + /** + * 鐢ㄦ埛澶村儚 + */ + public static final String JWT_AVATAR = "avatar"; + + /** + * 鍒涘缓鏃堕棿 + */ + public static final String JWT_CREATED = "created"; + + /** + * 鐢ㄦ埛鏉冮檺 + */ + public static final String JWT_AUTHORITIES = "authorities"; + + /** + * 璧勬簮鏄犲皠璺緞 鍓嶇紑 + */ + public static final String RESOURCE_PREFIX = "/profile"; + + /** + * RMI 杩滅▼鏂规硶璋冪敤 + */ + public static final String LOOKUP_RMI = "rmi:"; + + /** + * LDAP 杩滅▼鏂规硶璋冪敤 + */ + public static final String LOOKUP_LDAP = "ldap:"; + + /** + * LDAPS 杩滅▼鏂规硶璋冪敤 + */ + public static final String LOOKUP_LDAPS = "ldaps:"; + + /** + * 瀹氭椂浠诲姟鐧藉悕鍗曢厤缃紙浠呭厑璁歌闂殑鍖呭悕锛屽鍏朵粬闇瑕佸彲浠ヨ嚜琛屾坊鍔狅級 + */ + public static final String[] JOB_WHITELIST_STR = {"com.jsowell"}; + + /** + * 瀹氭椂浠诲姟杩濊鐨勫瓧绗 + */ + public static final String[] JOB_ERROR_STR = {"java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", + "org.springframework", "org.apache", "com.jsowell.common.util.file"}; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/GenConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/GenConstants.java new file mode 100644 index 000000000..378d9555d --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/GenConstants.java @@ -0,0 +1,186 @@ +package com.jsowell.common.constant; + +/** + * 浠g爜鐢熸垚閫氱敤甯搁噺 + * + * @author jsowell + */ +public class GenConstants { + /** + * 鍗曡〃锛堝鍒犳敼鏌ワ級 + */ + public static final String TPL_CRUD = "crud"; + + /** + * 鏍戣〃锛堝鍒犳敼鏌ワ級 + */ + public static final String TPL_TREE = "tree"; + + /** + * 涓诲瓙琛紙澧炲垹鏀规煡锛 + */ + public static final String TPL_SUB = "sub"; + + /** + * 鏍戠紪鐮佸瓧娈 + */ + public static final String TREE_CODE = "treeCode"; + + /** + * 鏍戠埗缂栫爜瀛楁 + */ + public static final String TREE_PARENT_CODE = "treeParentCode"; + + /** + * 鏍戝悕绉板瓧娈 + */ + public static final String TREE_NAME = "treeName"; + + /** + * 涓婄骇鑿滃崟ID瀛楁 + */ + public static final String PARENT_MENU_ID = "parentMenuId"; + + /** + * 涓婄骇鑿滃崟鍚嶇О瀛楁 + */ + public static final String PARENT_MENU_NAME = "parentMenuName"; + + /** + * 鏁版嵁搴撳瓧绗︿覆绫诲瀷 + */ + public static final String[] COLUMNTYPE_STR = {"char", "varchar", "nvarchar", "varchar2"}; + + /** + * 鏁版嵁搴撴枃鏈被鍨 + */ + public static final String[] COLUMNTYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext"}; + + /** + * 鏁版嵁搴撴椂闂寸被鍨 + */ + public static final String[] COLUMNTYPE_TIME = {"datetime", "time", "date", "timestamp"}; + + /** + * 鏁版嵁搴撴暟瀛楃被鍨 + */ + public static final String[] COLUMNTYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer", + "bit", "bigint", "float", "double", "decimal"}; + + /** + * 椤甸潰涓嶉渶瑕佺紪杈戝瓧娈 + */ + public static final String[] COLUMNNAME_NOT_EDIT = {"id", "create_by", "create_time", "del_flag"}; + + /** + * 椤甸潰涓嶉渶瑕佹樉绀虹殑鍒楄〃瀛楁 + */ + public static final String[] COLUMNNAME_NOT_LIST = {"id", "create_by", "create_time", "del_flag", "update_by", + "update_time"}; + + /** + * 椤甸潰涓嶉渶瑕佹煡璇㈠瓧娈 + */ + public static final String[] COLUMNNAME_NOT_QUERY = {"id", "create_by", "create_time", "del_flag", "update_by", + "update_time", "remark"}; + + /** + * Entity鍩虹被瀛楁 + */ + public static final String[] BASE_ENTITY = {"createBy", "createTime", "updateBy", "updateTime", "remark"}; + + /** + * Tree鍩虹被瀛楁 + */ + public static final String[] TREE_ENTITY = {"parentName", "parentId", "orderNum", "ancestors", "children"}; + + /** + * 鏂囨湰妗 + */ + public static final String HTML_INPUT = "input"; + + /** + * 鏂囨湰鍩 + */ + public static final String HTML_TEXTAREA = "textarea"; + + /** + * 涓嬫媺妗 + */ + public static final String HTML_SELECT = "select"; + + /** + * 鍗曢夋 + */ + public static final String HTML_RADIO = "radio"; + + /** + * 澶嶉夋 + */ + public static final String HTML_CHECKBOX = "checkbox"; + + /** + * 鏃ユ湡鎺т欢 + */ + public static final String HTML_DATETIME = "datetime"; + + /** + * 鍥剧墖涓婁紶鎺т欢 + */ + public static final String HTML_IMAGE_UPLOAD = "imageUpload"; + + /** + * 鏂囦欢涓婁紶鎺т欢 + */ + public static final String HTML_FILE_UPLOAD = "fileUpload"; + + /** + * 瀵屾枃鏈帶浠 + */ + public static final String HTML_EDITOR = "editor"; + + /** + * 瀛楃涓茬被鍨 + */ + public static final String TYPE_STRING = "String"; + + /** + * 鏁村瀷 + */ + public static final String TYPE_INTEGER = "Integer"; + + /** + * 闀挎暣鍨 + */ + public static final String TYPE_LONG = "Long"; + + /** + * 娴偣鍨 + */ + public static final String TYPE_DOUBLE = "Double"; + + /** + * 楂樼簿搴﹁绠楃被鍨 + */ + public static final String TYPE_BIGDECIMAL = "BigDecimal"; + + /** + * 鏃堕棿绫诲瀷 + */ + public static final String TYPE_DATE = "Date"; + + /** + * 妯$硦鏌ヨ + */ + public static final String QUERY_LIKE = "LIKE"; + + /** + * 鐩哥瓑鏌ヨ + */ + public static final String QUERY_EQ = "EQ"; + + /** + * 闇瑕 + */ + public static final String REQUIRE = "1"; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/HttpStatus.java b/jsowell-common/src/main/java/com/jsowell/common/constant/HttpStatus.java new file mode 100644 index 000000000..4e6b8a78b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/HttpStatus.java @@ -0,0 +1,88 @@ +package com.jsowell.common.constant; + +/** + * 杩斿洖鐘舵佺爜 + * + * @author jsowell + */ +public class HttpStatus { + /** + * 鎿嶄綔鎴愬姛 + */ + public static final int SUCCESS = 200; + + /** + * 瀵硅薄鍒涘缓鎴愬姛 + */ + public static final int CREATED = 201; + + /** + * 璇锋眰宸茬粡琚帴鍙 + */ + public static final int ACCEPTED = 202; + + /** + * 鎿嶄綔宸茬粡鎵ц鎴愬姛锛屼絾鏄病鏈夎繑鍥炴暟鎹 + */ + public static final int NO_CONTENT = 204; + + /** + * 璧勬簮宸茶绉婚櫎 + */ + public static final int MOVED_PERM = 301; + + /** + * 閲嶅畾鍚 + */ + public static final int SEE_OTHER = 303; + + /** + * 璧勬簮娌℃湁琚慨鏀 + */ + public static final int NOT_MODIFIED = 304; + + /** + * 鍙傛暟鍒楄〃閿欒锛堢己灏戯紝鏍煎紡涓嶅尮閰嶏級 + */ + public static final int BAD_REQUEST = 400; + + /** + * 鏈巿鏉 + */ + public static final int UNAUTHORIZED = 401; + + /** + * 璁块棶鍙楅檺锛屾巿鏉冭繃鏈 + */ + public static final int FORBIDDEN = 403; + + /** + * 璧勬簮锛屾湇鍔℃湭鎵惧埌 + */ + public static final int NOT_FOUND = 404; + + /** + * 涓嶅厑璁哥殑http鏂规硶 + */ + public static final int BAD_METHOD = 405; + + /** + * 璧勬簮鍐茬獊锛屾垨鑰呰祫婧愯閿 + */ + public static final int CONFLICT = 409; + + /** + * 涓嶆敮鎸佺殑鏁版嵁锛屽獟浣撶被鍨 + */ + public static final int UNSUPPORTED_TYPE = 415; + + /** + * 绯荤粺鍐呴儴閿欒 + */ + public static final int ERROR = 500; + + /** + * 鎺ュ彛鏈疄鐜 + */ + public static final int NOT_IMPLEMENTED = 501; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/ScheduleConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/ScheduleConstants.java new file mode 100644 index 000000000..d0f53afcd --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/ScheduleConstants.java @@ -0,0 +1,56 @@ +package com.jsowell.common.constant; + +/** + * 浠诲姟璋冨害閫氱敤甯搁噺 + * + * @author jsowell + */ +public class ScheduleConstants { + public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; + + /** + * 鎵ц鐩爣key + */ + public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; + + /** + * 榛樿 + */ + public static final String MISFIRE_DEFAULT = "0"; + + /** + * 绔嬪嵆瑙﹀彂鎵ц + */ + public static final String MISFIRE_IGNORE_MISFIRES = "1"; + + /** + * 瑙﹀彂涓娆℃墽琛 + */ + public static final String MISFIRE_FIRE_AND_PROCEED = "2"; + + /** + * 涓嶈Е鍙戠珛鍗虫墽琛 + */ + public static final String MISFIRE_DO_NOTHING = "3"; + + public enum Status { + /** + * 姝e父 + */ + NORMAL("0"), + /** + * 鏆傚仠 + */ + PAUSE("1"); + + private String value; + + private Status(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/UserConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/UserConstants.java new file mode 100644 index 000000000..d7c2bc32b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/UserConstants.java @@ -0,0 +1,111 @@ +package com.jsowell.common.constant; + +/** + * 鐢ㄦ埛甯搁噺淇℃伅 + * + * @author jsowell + */ +public class UserConstants { + /** + * 骞冲彴鍐呯郴缁熺敤鎴风殑鍞竴鏍囧織 + */ + public static final String SYS_USER = "SYS_USER"; + + /** + * 姝e父鐘舵 + */ + public static final String NORMAL = "0"; + + /** + * 寮傚父鐘舵 + */ + public static final String EXCEPTION = "1"; + + /** + * 鐢ㄦ埛灏佺鐘舵 + */ + public static final String USER_DISABLE = "1"; + + /** + * 瑙掕壊灏佺鐘舵 + */ + public static final String ROLE_DISABLE = "1"; + + /** + * 閮ㄩ棬姝e父鐘舵 + */ + public static final String DEPT_NORMAL = "0"; + + /** + * 閮ㄩ棬鍋滅敤鐘舵 + */ + public static final String DEPT_DISABLE = "1"; + + /** + * 瀛楀吀姝e父鐘舵 + */ + public static final String DICT_NORMAL = "0"; + + /** + * 鏄惁涓虹郴缁熼粯璁わ紙鏄級 + */ + public static final String YES = "Y"; + + /** + * 鏄惁鑿滃崟澶栭摼锛堟槸锛 + */ + public static final String YES_FRAME = "0"; + + /** + * 鏄惁鑿滃崟澶栭摼锛堝惁锛 + */ + public static final String NO_FRAME = "1"; + + /** + * 鑿滃崟绫诲瀷锛堢洰褰曪級 + */ + public static final String TYPE_DIR = "M"; + + /** + * 鑿滃崟绫诲瀷锛堣彍鍗曪級 + */ + public static final String TYPE_MENU = "C"; + + /** + * 鑿滃崟绫诲瀷锛堟寜閽級 + */ + public static final String TYPE_BUTTON = "F"; + + /** + * Layout缁勪欢鏍囪瘑 + */ + public final static String LAYOUT = "Layout"; + + /** + * ParentView缁勪欢鏍囪瘑 + */ + public final static String PARENT_VIEW = "ParentView"; + + /** + * InnerLink缁勪欢鏍囪瘑 + */ + public final static String INNER_LINK = "InnerLink"; + + /** + * 鏍¢獙杩斿洖缁撴灉鐮 + */ + public final static String UNIQUE = "0"; + public final static String NOT_UNIQUE = "1"; + + /** + * 鐢ㄦ埛鍚嶉暱搴﹂檺鍒 + */ + public static final int USERNAME_MIN_LENGTH = 2; + public static final int USERNAME_MAX_LENGTH = 20; + + /** + * 瀵嗙爜闀垮害闄愬埗 + */ + public static final int PASSWORD_MIN_LENGTH = 5; + public static final int PASSWORD_MAX_LENGTH = 20; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/WeiXinConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/WeiXinConstants.java new file mode 100644 index 000000000..083375ae0 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/WeiXinConstants.java @@ -0,0 +1,64 @@ +package com.jsowell.common.constant; + +/** + * 寰俊鏀粯甯搁噺 + * WeiXinConstants
+ * 鍒涘缓浜:灏忓▉
+ * 鏃堕棿锛2015骞10鏈19鏃-涓嬪崍7:14:15
+ * + * @version 1.0.0 + */ +public class WeiXinConstants { + + + public static final String URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";//缁熶竴涓嬪崟url + + public static final String MCH_URL = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing";//缁熶竴鍒嗚处url + + public static final String MCH_URL_MULTIPRO = "https://api.mch.weixin.qq.com/secapi/pay/multiprofitsharing";//缁熶竴鍒嗚处url(澶氭鍒嗚处) + + public static final String PROFIT_SHARING_QUERY = "https://api.mch.weixin.qq.com/pay/profitsharingquery"; //缁熶竴鍒嗚处缁撴灉鏌ヨ + + public static final String MCH_URL_FINISH = "https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish";//缁熶竴鍒嗚处url + + public static final String MCH_STATUS_URL = "https://api.mch.weixin.qq.com/pay/profitsharingquery";//缁熶竴鍒嗚处鏌ヨurl + + public static final String MCH_ADD_RELATION_URL = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver";//鍒嗚处鍏崇郴缁戝畾鍦板潃 + + public static final String REFUND = "https://api.mch.weixin.qq.com/secapi/pay/refund";//閫娆 + + + public static final String RETURN_CODE = "return_code"; // SUCCESS/FAIL 姝ゅ瓧娈垫槸閫氫俊鏍囪瘑锛岄潪浜ゆ槗鏍囪瘑 + + public static final String SUCCESS = "SUCCESS"; // SUCCESS/FAIL 姝ゅ瓧娈垫槸閫氫俊鏍囪瘑锛岄潪浜ゆ槗鏍囪瘑 + + public static final int WIDTH = 200;//浜岀淮鐮佸搴 + + public static final int HEIGHT = 200;//浜岀淮鐮侀珮搴 + + public static final String RESULT = "result_code";//杩斿洖缁撴灉 + + public static final String ORDER_PAID = "orderPaid";//宸茬粡鏀粯 + + public static final String WEIXINPAY = "weixinPay";//鍙互鏀粯 + + public static final String CODE_URL = "code_url";//寰俊鏀粯url + + public static final String ERROR_CODE = "err_code";//閿欒鐮 + + public static final String ATTACH = "attach";//鍟嗗鏁版嵁鍖 + + public static final String BODY = "body";//鍟嗗搧鍚嶇О + + public static final String NOTIFY_URL = "notify_url";//寮傛鍥炶皟鍦板潃 + + public static final String OUT_TRADE_NO = "out_trade_no";//鍟嗗璁㈠崟鍙 + + public static final String TRANSACTION_ID = "transaction_id";//寰俊璁㈠崟鍙 + + public static final String PRODUCT_ID = "product_id";//鍟嗗搧ID + + public static final String SPBILL_CREATE_IP = "spbill_create_ip";//鏀粯鐢ㄦ埛IP鍦板潃 + + public static final String TOTAL_FEE = "total_fee";//鏀粯閲戦 +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/controller/BaseController.java b/jsowell-common/src/main/java/com/jsowell/common/core/controller/BaseController.java new file mode 100644 index 000000000..427a84b23 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/controller/BaseController.java @@ -0,0 +1,187 @@ +package com.jsowell.common.core.controller; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.jsowell.common.constant.HttpStatus; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.core.page.PageDomain; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.core.page.TableSupport; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.JWTUtils; +import com.jsowell.common.util.PageUtils; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.sql.SqlUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; + +import javax.servlet.http.HttpServletRequest; +import java.beans.PropertyEditorSupport; +import java.util.Date; +import java.util.List; + +/** + * web灞傞氱敤鏁版嵁澶勭悊 + * + * @author jsowell + */ +public class BaseController { + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + + /** + * 灏嗗墠鍙颁紶閫掕繃鏉ョ殑鏃ユ湡鏍煎紡鐨勫瓧绗︿覆锛岃嚜鍔ㄨ浆鍖栦负Date绫诲瀷 + */ + @InitBinder + public void initBinder(WebDataBinder binder) { + // Date 绫诲瀷杞崲 + binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { + @Override + public void setAsText(String text) { + setValue(DateUtils.parseDate(text)); + } + }); + } + + /** + * 璁剧疆璇锋眰鍒嗛〉鏁版嵁 + */ + protected void startPage() { + PageUtils.startPage(); + } + + /** + * 璁剧疆璇锋眰鎺掑簭鏁版嵁 + */ + protected void startOrderBy() { + PageDomain pageDomain = TableSupport.buildPageRequest(); + if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) { + String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); + PageHelper.orderBy(orderBy); + } + } + + /** + * 娓呯悊鍒嗛〉鐨勭嚎绋嬪彉閲 + */ + protected void clearPage() { + PageUtils.clearPage(); + } + + /** + * 鍝嶅簲璇锋眰鍒嗛〉鏁版嵁 + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + protected TableDataInfo getDataTable(List list) { + TableDataInfo rspData = new TableDataInfo(); + rspData.setCode(HttpStatus.SUCCESS); + rspData.setMsg("鏌ヨ鎴愬姛"); + rspData.setRows(list); + rspData.setTotal(new PageInfo(list).getTotal()); + return rspData; + } + + /** + * 杩斿洖鎴愬姛 + */ + public AjaxResult success() { + return AjaxResult.success(); + } + + /** + * 杩斿洖澶辫触娑堟伅 + */ + public AjaxResult error() { + return AjaxResult.error(); + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + */ + public AjaxResult success(String message) { + return AjaxResult.success(message); + } + + /** + * 杩斿洖澶辫触娑堟伅 + */ + public AjaxResult error(String message) { + return AjaxResult.error(message); + } + + /** + * 鍝嶅簲杩斿洖缁撴灉 + * + * @param rows 褰卞搷琛屾暟 + * @return 鎿嶄綔缁撴灉 + */ + protected AjaxResult toAjax(int rows) { + return rows > 0 ? AjaxResult.success() : AjaxResult.error(); + } + + /** + * 鍝嶅簲杩斿洖缁撴灉 + * + * @param result 缁撴灉 + * @return 鎿嶄綔缁撴灉 + */ + protected AjaxResult toAjax(boolean result) { + return result ? success() : error(); + } + + /** + * 椤甸潰璺宠浆 + */ + public String redirect(String url) { + return StringUtils.format("redirect:{}", url); + } + + /** + * 鑾峰彇鐢ㄦ埛缂撳瓨淇℃伅 + */ + public LoginUser getLoginUser() { + return SecurityUtils.getLoginUser(); + } + + /** + * 鑾峰彇鐧诲綍鐢ㄦ埛id + */ + public Long getUserId() { + return getLoginUser().getUserId(); + } + + /** + * 鑾峰彇鐧诲綍閮ㄩ棬id + */ + public Long getDeptId() { + return getLoginUser().getDeptId(); + } + + /** + * 鑾峰彇鐧诲綍鐢ㄦ埛鍚 + */ + public String getUsername() { + return getLoginUser().getUsername(); + } + + public String getMemberIdByAuthorization(String authorization) { + if (StringUtils.isBlank(authorization)) { + throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); + } + String memberId = JWTUtils.getMemberId(authorization); + if (StringUtils.isBlank(memberId)) { + throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); + } + // logger.info("authorization:{}, memberId:{}", authorization, memberId); + return memberId; + } + + public String getMemberIdByAuthorization(HttpServletRequest request) { + return getMemberIdByAuthorization(request.getHeader("Authorization")); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/AjaxResult.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/AjaxResult.java new file mode 100644 index 000000000..5265a9988 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/AjaxResult.java @@ -0,0 +1,155 @@ +package com.jsowell.common.core.domain; + +import com.jsowell.common.constant.HttpStatus; +import com.jsowell.common.util.StringUtils; + +import java.util.HashMap; + +/** + * 鎿嶄綔娑堟伅鎻愰啋 + * + * @author jsowell + */ +public class AjaxResult extends HashMap { + private static final long serialVersionUID = 1L; + + /** + * 鐘舵佺爜 + */ + public static final String CODE_TAG = "code"; + + /** + * 杩斿洖鍐呭 + */ + public static final String MSG_TAG = "msg"; + + /** + * 鏁版嵁瀵硅薄 + */ + public static final String DATA_TAG = "data"; + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨 AjaxResult 瀵硅薄锛屼娇鍏惰〃绀轰竴涓┖娑堟伅銆 + */ + public AjaxResult() { + } + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨 AjaxResult 瀵硅薄 + * + * @param code 鐘舵佺爜 + * @param msg 杩斿洖鍐呭 + */ + public AjaxResult(int code, String msg) { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + } + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨 AjaxResult 瀵硅薄 + * + * @param code 鐘舵佺爜 + * @param msg 杩斿洖鍐呭 + * @param data 鏁版嵁瀵硅薄 + */ + public AjaxResult(int code, String msg, Object data) { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + if (StringUtils.isNotNull(data)) { + super.put(DATA_TAG, data); + } + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @return 鎴愬姛娑堟伅 + */ + public static AjaxResult success() { + return AjaxResult.success("鎿嶄綔鎴愬姛"); + } + + /** + * 杩斿洖鎴愬姛鏁版嵁 + * + * @return 鎴愬姛娑堟伅 + */ + public static AjaxResult success(Object data) { + return AjaxResult.success("鎿嶄綔鎴愬姛", data); + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @return 鎴愬姛娑堟伅 + */ + public static AjaxResult success(String msg) { + return AjaxResult.success(msg, null); + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @param data 鏁版嵁瀵硅薄 + * @return 鎴愬姛娑堟伅 + */ + public static AjaxResult success(String msg, Object data) { + return new AjaxResult(HttpStatus.SUCCESS, msg, data); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @return + */ + public static AjaxResult error() { + return AjaxResult.error("鎿嶄綔澶辫触"); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @return 璀﹀憡娑堟伅 + */ + public static AjaxResult error(String msg) { + return AjaxResult.error(msg, null); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @param data 鏁版嵁瀵硅薄 + * @return 璀﹀憡娑堟伅 + */ + public static AjaxResult error(String msg, Object data) { + return new AjaxResult(HttpStatus.ERROR, msg, data); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param code 鐘舵佺爜 + * @param msg 杩斿洖鍐呭 + * @return 璀﹀憡娑堟伅 + */ + public static AjaxResult error(int code, String msg) { + return new AjaxResult(code, msg, null); + } + + /** + * 鏂逛究閾惧紡璋冪敤 + * + * @param key 閿 + * @param value 鍊 + * @return 鏁版嵁瀵硅薄 + */ + @Override + public AjaxResult put(String key, Object value) { + super.put(key, value); + return this; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/BaseEntity.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/BaseEntity.java new file mode 100644 index 000000000..96702d497 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/BaseEntity.java @@ -0,0 +1,114 @@ +package com.jsowell.common.core.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.io.Serializable; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * Entity鍩虹被 + * + * @author jsowell + */ + +public class BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鎼滅储鍊 + */ + private String searchValue; + + /** + * 鍒涘缓鑰 + */ + private String createBy; + + /** + * 鍒涘缓鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + + /** + * 鏇存柊鑰 + */ + private String updateBy; + + /** + * 鏇存柊鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateTime; + + /** + * 澶囨敞 + */ + private String remark; + + /** + * 璇锋眰鍙傛暟 + */ + private Map params; + + public String getSearchValue() { + return searchValue; + } + + public void setSearchValue(String searchValue) { + this.searchValue = searchValue; + } + + public String getCreateBy() { + return createBy; + } + + public void setCreateBy(String createBy) { + this.createBy = createBy; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public String getUpdateBy() { + return updateBy; + } + + public void setUpdateBy(String updateBy) { + this.updateBy = updateBy; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public Map getParams() { + if (params == null) { + params = new HashMap<>(); + } + return params; + } + + public void setParams(Map params) { + this.params = params; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/R.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/R.java new file mode 100644 index 000000000..9b858d8d5 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/R.java @@ -0,0 +1,94 @@ +package com.jsowell.common.core.domain; + +import com.jsowell.common.constant.HttpStatus; + +import java.io.Serializable; + +/** + * 鍝嶅簲淇℃伅涓讳綋 + * + * @author jsowell + */ +public class R implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鎴愬姛 + */ + public static final int SUCCESS = HttpStatus.SUCCESS; + + /** + * 澶辫触 + */ + public static final int FAIL = HttpStatus.ERROR; + + private int code; + + private String msg; + + private T data; + + public static R ok() { + return restResult(null, SUCCESS, "鎿嶄綔鎴愬姛"); + } + + public static R ok(T data) { + return restResult(data, SUCCESS, "鎿嶄綔鎴愬姛"); + } + + public static R ok(T data, String msg) { + return restResult(data, SUCCESS, msg); + } + + public static R fail() { + return restResult(null, FAIL, "鎿嶄綔澶辫触"); + } + + public static R fail(String msg) { + return restResult(null, FAIL, msg); + } + + public static R fail(T data) { + return restResult(data, FAIL, "鎿嶄綔澶辫触"); + } + + public static R fail(T data, String msg) { + return restResult(data, FAIL, msg); + } + + public static R fail(int code, String msg) { + return restResult(null, code, msg); + } + + private static R restResult(T data, int code, String msg) { + R apiResult = new R<>(); + apiResult.setCode(code); + apiResult.setData(data); + apiResult.setMsg(msg); + return apiResult; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/TreeEntity.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/TreeEntity.java new file mode 100644 index 000000000..3a38ec8cb --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/TreeEntity.java @@ -0,0 +1,78 @@ +package com.jsowell.common.core.domain; + +import java.util.ArrayList; +import java.util.List; + +/** + * Tree鍩虹被 + * + * @author jsowell + */ +public class TreeEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 鐖惰彍鍗曞悕绉 + */ + private String parentName; + + /** + * 鐖惰彍鍗旾D + */ + private Long parentId; + + /** + * 鏄剧ず椤哄簭 + */ + private Integer orderNum; + + /** + * 绁栫骇鍒楄〃 + */ + private String ancestors; + + /** + * 瀛愰儴闂 + */ + private List children = new ArrayList<>(); + + public String getParentName() { + return parentName; + } + + public void setParentName(String parentName) { + this.parentName = parentName; + } + + public Long getParentId() { + return parentId; + } + + public void setParentId(Long parentId) { + this.parentId = parentId; + } + + public Integer getOrderNum() { + return orderNum; + } + + public void setOrderNum(Integer orderNum) { + this.orderNum = orderNum; + } + + public String getAncestors() { + return ancestors; + } + + public void setAncestors(String ancestors) { + this.ancestors = ancestors; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/TreeSelect.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/TreeSelect.java new file mode 100644 index 000000000..6a32b5622 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/TreeSelect.java @@ -0,0 +1,74 @@ +package com.jsowell.common.core.domain; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.jsowell.common.core.domain.entity.SysDept; +import com.jsowell.common.core.domain.entity.SysMenu; + +import java.io.Serializable; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Treeselect鏍戠粨鏋勫疄浣撶被 + * + * @author jsowell + */ +public class TreeSelect implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鑺傜偣ID + */ + private Long id; + + /** + * 鑺傜偣鍚嶇О + */ + private String label; + + /** + * 瀛愯妭鐐 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children; + + public TreeSelect() { + + } + + public TreeSelect(SysDept dept) { + this.id = dept.getDeptId(); + this.label = dept.getDeptName(); + this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + public TreeSelect(SysMenu menu) { + this.id = menu.getMenuId(); + this.label = menu.getMenuName(); + this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDept.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDept.java new file mode 100644 index 000000000..4ed76ea6b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDept.java @@ -0,0 +1,203 @@ +package com.jsowell.common.core.domain.entity; + +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.ArrayList; +import java.util.List; + +/** + * 閮ㄩ棬琛 sys_dept + * + * @author jsowell + */ +public class SysDept extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 閮ㄩ棬ID + */ + private Long deptId; + + /** + * 鐖堕儴闂↖D + */ + private Long parentId; + + /** + * 绁栫骇鍒楄〃 + */ + private String ancestors; + + /** + * 閮ㄩ棬鍚嶇О + */ + private String deptName; + + /** + * 鏄剧ず椤哄簭 + */ + private Integer orderNum; + + /** + * 璐熻矗浜 + */ + private String leader; + + /** + * 鑱旂郴鐢佃瘽 + */ + private String phone; + + /** + * 閭 + */ + private String email; + + /** + * 閮ㄩ棬鐘舵:0姝e父,1鍋滅敤 + */ + private String status; + + /** + * 鍒犻櫎鏍囧織锛0浠h〃瀛樺湪 2浠h〃鍒犻櫎锛 + */ + private String delFlag; + + /** + * 鐖堕儴闂ㄥ悕绉 + */ + private String parentName; + + /** + * 瀛愰儴闂 + */ + private List children = new ArrayList(); + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } + + public Long getParentId() { + return parentId; + } + + public void setParentId(Long parentId) { + this.parentId = parentId; + } + + public String getAncestors() { + return ancestors; + } + + public void setAncestors(String ancestors) { + this.ancestors = ancestors; + } + + @NotBlank(message = "閮ㄩ棬鍚嶇О涓嶈兘涓虹┖") + @Size(min = 0, max = 30, message = "閮ㄩ棬鍚嶇О闀垮害涓嶈兘瓒呰繃30涓瓧绗") + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + @NotNull(message = "鏄剧ず椤哄簭涓嶈兘涓虹┖") + public Integer getOrderNum() { + return orderNum; + } + + public void setOrderNum(Integer orderNum) { + this.orderNum = orderNum; + } + + public String getLeader() { + return leader; + } + + public void setLeader(String leader) { + this.leader = leader; + } + + @Size(min = 0, max = 11, message = "鑱旂郴鐢佃瘽闀垮害涓嶈兘瓒呰繃11涓瓧绗") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @Email(message = "閭鏍煎紡涓嶆纭") + @Size(min = 0, max = 50, message = "閭闀垮害涓嶈兘瓒呰繃50涓瓧绗") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getDelFlag() { + return delFlag; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public String getParentName() { + return parentName; + } + + public void setParentName(String parentName) { + this.parentName = parentName; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("deptId", getDeptId()) + .append("parentId", getParentId()) + .append("ancestors", getAncestors()) + .append("deptName", getDeptName()) + .append("orderNum", getOrderNum()) + .append("leader", getLeader()) + .append("phone", getPhone()) + .append("email", getEmail()) + .append("status", getStatus()) + .append("delFlag", getDelFlag()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDictData.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDictData.java new file mode 100644 index 000000000..f7d1e7ed2 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDictData.java @@ -0,0 +1,175 @@ +package com.jsowell.common.core.domain.entity; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +/** + * 瀛楀吀鏁版嵁琛 sys_dict_data + * + * @author jsowell + */ +public class SysDictData extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 瀛楀吀缂栫爜 + */ + @Excel(name = "瀛楀吀缂栫爜", cellType = ColumnType.NUMERIC) + private Long dictCode; + + /** + * 瀛楀吀鎺掑簭 + */ + @Excel(name = "瀛楀吀鎺掑簭", cellType = ColumnType.NUMERIC) + private Long dictSort; + + /** + * 瀛楀吀鏍囩 + */ + @Excel(name = "瀛楀吀鏍囩") + private String dictLabel; + + /** + * 瀛楀吀閿 + */ + @Excel(name = "瀛楀吀閿") + private String dictValue; + + /** + * 瀛楀吀绫诲瀷 + */ + @Excel(name = "瀛楀吀绫诲瀷") + private String dictType; + + /** + * 鏍峰紡灞炴э紙鍏朵粬鏍峰紡鎵╁睍锛 + */ + private String cssClass; + + /** + * 琛ㄦ牸瀛楀吀鏍峰紡 + */ + private String listClass; + + /** + * 鏄惁榛樿锛圷鏄 N鍚︼級 + */ + @Excel(name = "鏄惁榛樿", readConverterExp = "Y=鏄,N=鍚") + private String isDefault; + + /** + * 鐘舵侊紙0姝e父 1鍋滅敤锛 + */ + @Excel(name = "鐘舵", readConverterExp = "0=姝e父,1=鍋滅敤") + private String status; + + public Long getDictCode() { + return dictCode; + } + + public void setDictCode(Long dictCode) { + this.dictCode = dictCode; + } + + public Long getDictSort() { + return dictSort; + } + + public void setDictSort(Long dictSort) { + this.dictSort = dictSort; + } + + @NotBlank(message = "瀛楀吀鏍囩涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "瀛楀吀鏍囩闀垮害涓嶈兘瓒呰繃100涓瓧绗") + public String getDictLabel() { + return dictLabel; + } + + public void setDictLabel(String dictLabel) { + this.dictLabel = dictLabel; + } + + @NotBlank(message = "瀛楀吀閿间笉鑳戒负绌") + @Size(min = 0, max = 100, message = "瀛楀吀閿奸暱搴︿笉鑳借秴杩100涓瓧绗") + public String getDictValue() { + return dictValue; + } + + public void setDictValue(String dictValue) { + this.dictValue = dictValue; + } + + @NotBlank(message = "瀛楀吀绫诲瀷涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "瀛楀吀绫诲瀷闀垮害涓嶈兘瓒呰繃100涓瓧绗") + public String getDictType() { + return dictType; + } + + public void setDictType(String dictType) { + this.dictType = dictType; + } + + @Size(min = 0, max = 100, message = "鏍峰紡灞炴ч暱搴︿笉鑳借秴杩100涓瓧绗") + public String getCssClass() { + return cssClass; + } + + public void setCssClass(String cssClass) { + this.cssClass = cssClass; + } + + public String getListClass() { + return listClass; + } + + public void setListClass(String listClass) { + this.listClass = listClass; + } + + public boolean getDefault() { + return UserConstants.YES.equals(this.isDefault) ? true : false; + } + + public String getIsDefault() { + return isDefault; + } + + public void setIsDefault(String isDefault) { + this.isDefault = isDefault; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("dictCode", getDictCode()) + .append("dictSort", getDictSort()) + .append("dictLabel", getDictLabel()) + .append("dictValue", getDictValue()) + .append("dictType", getDictType()) + .append("cssClass", getCssClass()) + .append("listClass", getListClass()) + .append("isDefault", getIsDefault()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDictType.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDictType.java new file mode 100644 index 000000000..bd758809e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysDictType.java @@ -0,0 +1,96 @@ +package com.jsowell.common.core.domain.entity; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; + +/** + * 瀛楀吀绫诲瀷琛 sys_dict_type + * + * @author jsowell + */ +public class SysDictType extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 瀛楀吀涓婚敭 + */ + @Excel(name = "瀛楀吀涓婚敭", cellType = ColumnType.NUMERIC) + private Long dictId; + + /** + * 瀛楀吀鍚嶇О + */ + @Excel(name = "瀛楀吀鍚嶇О") + private String dictName; + + /** + * 瀛楀吀绫诲瀷 + */ + @Excel(name = "瀛楀吀绫诲瀷") + private String dictType; + + /** + * 鐘舵侊紙0姝e父 1鍋滅敤锛 + */ + @Excel(name = "鐘舵", readConverterExp = "0=姝e父,1=鍋滅敤") + private String status; + + public Long getDictId() { + return dictId; + } + + public void setDictId(Long dictId) { + this.dictId = dictId; + } + + @NotBlank(message = "瀛楀吀鍚嶇О涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "瀛楀吀绫诲瀷鍚嶇О闀垮害涓嶈兘瓒呰繃100涓瓧绗") + public String getDictName() { + return dictName; + } + + public void setDictName(String dictName) { + this.dictName = dictName; + } + + @NotBlank(message = "瀛楀吀绫诲瀷涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "瀛楀吀绫诲瀷绫诲瀷闀垮害涓嶈兘瓒呰繃100涓瓧绗") + @Pattern(regexp = "^[a-z][a-z0-9_]*$", message = "瀛楀吀绫诲瀷蹇呴』浠ュ瓧姣嶅紑澶达紝涓斿彧鑳戒负锛堝皬鍐欏瓧姣嶏紝鏁板瓧锛屼笅婊戠嚎锛") + public String getDictType() { + return dictType; + } + + public void setDictType(String dictType) { + this.dictType = dictType; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("dictId", getDictId()) + .append("dictName", getDictName()) + .append("dictType", getDictType()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysMenu.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysMenu.java new file mode 100644 index 000000000..9645c4a53 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysMenu.java @@ -0,0 +1,259 @@ +package com.jsowell.common.core.domain.entity; + +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.ArrayList; +import java.util.List; + +/** + * 鑿滃崟鏉冮檺琛 sys_menu + * + * @author jsowell + */ +public class SysMenu extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 鑿滃崟ID + */ + private Long menuId; + + /** + * 鑿滃崟鍚嶇О + */ + private String menuName; + + /** + * 鐖惰彍鍗曞悕绉 + */ + private String parentName; + + /** + * 鐖惰彍鍗旾D + */ + private Long parentId; + + /** + * 鏄剧ず椤哄簭 + */ + private Integer orderNum; + + /** + * 璺敱鍦板潃 + */ + private String path; + + /** + * 缁勪欢璺緞 + */ + private String component; + + /** + * 璺敱鍙傛暟 + */ + private String query; + + /** + * 鏄惁涓哄閾撅紙0鏄 1鍚︼級 + */ + private String isFrame; + + /** + * 鏄惁缂撳瓨锛0缂撳瓨 1涓嶇紦瀛橈級 + */ + private String isCache; + + /** + * 绫诲瀷锛圡鐩綍 C鑿滃崟 F鎸夐挳锛 + */ + private String menuType; + + /** + * 鏄剧ず鐘舵侊紙0鏄剧ず 1闅愯棌锛 + */ + private String visible; + + /** + * 鑿滃崟鐘舵侊紙0鏄剧ず 1闅愯棌锛 + */ + private String status; + + /** + * 鏉冮檺瀛楃涓 + */ + private String perms; + + /** + * 鑿滃崟鍥炬爣 + */ + private String icon; + + /** + * 瀛愯彍鍗 + */ + private List children = new ArrayList(); + + public Long getMenuId() { + return menuId; + } + + public void setMenuId(Long menuId) { + this.menuId = menuId; + } + + @NotBlank(message = "鑿滃崟鍚嶇О涓嶈兘涓虹┖") + @Size(min = 0, max = 50, message = "鑿滃崟鍚嶇О闀垮害涓嶈兘瓒呰繃50涓瓧绗") + public String getMenuName() { + return menuName; + } + + public void setMenuName(String menuName) { + this.menuName = menuName; + } + + public String getParentName() { + return parentName; + } + + public void setParentName(String parentName) { + this.parentName = parentName; + } + + public Long getParentId() { + return parentId; + } + + public void setParentId(Long parentId) { + this.parentId = parentId; + } + + @NotNull(message = "鏄剧ず椤哄簭涓嶈兘涓虹┖") + public Integer getOrderNum() { + return orderNum; + } + + public void setOrderNum(Integer orderNum) { + this.orderNum = orderNum; + } + + @Size(min = 0, max = 200, message = "璺敱鍦板潃涓嶈兘瓒呰繃200涓瓧绗") + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + @Size(min = 0, max = 200, message = "缁勪欢璺緞涓嶈兘瓒呰繃255涓瓧绗") + public String getComponent() { + return component; + } + + public void setComponent(String component) { + this.component = component; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public String getIsFrame() { + return isFrame; + } + + public void setIsFrame(String isFrame) { + this.isFrame = isFrame; + } + + public String getIsCache() { + return isCache; + } + + public void setIsCache(String isCache) { + this.isCache = isCache; + } + + @NotBlank(message = "鑿滃崟绫诲瀷涓嶈兘涓虹┖") + public String getMenuType() { + return menuType; + } + + public void setMenuType(String menuType) { + this.menuType = menuType; + } + + public String getVisible() { + return visible; + } + + public void setVisible(String visible) { + this.visible = visible; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Size(min = 0, max = 100, message = "鏉冮檺鏍囪瘑闀垮害涓嶈兘瓒呰繃100涓瓧绗") + public String getPerms() { + return perms; + } + + public void setPerms(String perms) { + this.perms = perms; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("menuId", getMenuId()) + .append("menuName", getMenuName()) + .append("parentId", getParentId()) + .append("orderNum", getOrderNum()) + .append("path", getPath()) + .append("component", getComponent()) + .append("isFrame", getIsFrame()) + .append("IsCache", getIsCache()) + .append("menuType", getMenuType()) + .append("visible", getVisible()) + .append("status ", getStatus()) + .append("perms", getPerms()) + .append("icon", getIcon()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysRole.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysRole.java new file mode 100644 index 000000000..56606008e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysRole.java @@ -0,0 +1,222 @@ +package com.jsowell.common.core.domain.entity; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +/** + * 瑙掕壊琛 sys_role + * + * @author jsowell + */ +public class SysRole extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 瑙掕壊ID + */ + @Excel(name = "瑙掕壊搴忓彿", cellType = ColumnType.NUMERIC) + private Long roleId; + + /** + * 瑙掕壊鍚嶇О + */ + @Excel(name = "瑙掕壊鍚嶇О") + private String roleName; + + /** + * 瑙掕壊鏉冮檺 + */ + @Excel(name = "瑙掕壊鏉冮檺") + private String roleKey; + + /** + * 瑙掕壊鎺掑簭 + */ + @Excel(name = "瑙掕壊鎺掑簭") + private String roleSort; + + /** + * 鏁版嵁鑼冨洿锛1锛氭墍鏈夋暟鎹潈闄愶紱2锛氳嚜瀹氫箟鏁版嵁鏉冮檺锛3锛氭湰閮ㄩ棬鏁版嵁鏉冮檺锛4锛氭湰閮ㄩ棬鍙婁互涓嬫暟鎹潈闄愶紱5锛氫粎鏈汉鏁版嵁鏉冮檺锛 + */ + @Excel(name = "鏁版嵁鑼冨洿", readConverterExp = "1=鎵鏈夋暟鎹潈闄,2=鑷畾涔夋暟鎹潈闄,3=鏈儴闂ㄦ暟鎹潈闄,4=鏈儴闂ㄥ強浠ヤ笅鏁版嵁鏉冮檺,5=浠呮湰浜烘暟鎹潈闄") + private String dataScope; + + /** + * 鑿滃崟鏍戦夋嫨椤规槸鍚﹀叧鑱旀樉绀猴紙 0锛氱埗瀛愪笉浜掔浉鍏宠仈鏄剧ず 1锛氱埗瀛愪簰鐩稿叧鑱旀樉绀猴級 + */ + private boolean menuCheckStrictly; + + /** + * 閮ㄩ棬鏍戦夋嫨椤规槸鍚﹀叧鑱旀樉绀猴紙0锛氱埗瀛愪笉浜掔浉鍏宠仈鏄剧ず 1锛氱埗瀛愪簰鐩稿叧鑱旀樉绀 锛 + */ + private boolean deptCheckStrictly; + + /** + * 瑙掕壊鐘舵侊紙0姝e父 1鍋滅敤锛 + */ + @Excel(name = "瑙掕壊鐘舵", readConverterExp = "0=姝e父,1=鍋滅敤") + private String status; + + /** + * 鍒犻櫎鏍囧織锛0浠h〃瀛樺湪 2浠h〃鍒犻櫎锛 + */ + private String delFlag; + + /** + * 鐢ㄦ埛鏄惁瀛樺湪姝よ鑹叉爣璇 榛樿涓嶅瓨鍦 + */ + private boolean flag = false; + + /** + * 鑿滃崟缁 + */ + private Long[] menuIds; + + /** + * 閮ㄩ棬缁勶紙鏁版嵁鏉冮檺锛 + */ + private Long[] deptIds; + + public SysRole() { + + } + + public SysRole(Long roleId) { + this.roleId = roleId; + } + + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + public boolean isAdmin() { + return isAdmin(this.roleId); + } + + public static boolean isAdmin(Long roleId) { + return roleId != null && 1L == roleId; + } + + @NotBlank(message = "瑙掕壊鍚嶇О涓嶈兘涓虹┖") + @Size(min = 0, max = 30, message = "瑙掕壊鍚嶇О闀垮害涓嶈兘瓒呰繃30涓瓧绗") + public String getRoleName() { + return roleName; + } + + public void setRoleName(String roleName) { + this.roleName = roleName; + } + + @NotBlank(message = "鏉冮檺瀛楃涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "鏉冮檺瀛楃闀垮害涓嶈兘瓒呰繃100涓瓧绗") + public String getRoleKey() { + return roleKey; + } + + public void setRoleKey(String roleKey) { + this.roleKey = roleKey; + } + + @NotBlank(message = "鏄剧ず椤哄簭涓嶈兘涓虹┖") + public String getRoleSort() { + return roleSort; + } + + public void setRoleSort(String roleSort) { + this.roleSort = roleSort; + } + + public String getDataScope() { + return dataScope; + } + + public void setDataScope(String dataScope) { + this.dataScope = dataScope; + } + + public boolean isMenuCheckStrictly() { + return menuCheckStrictly; + } + + public void setMenuCheckStrictly(boolean menuCheckStrictly) { + this.menuCheckStrictly = menuCheckStrictly; + } + + public boolean isDeptCheckStrictly() { + return deptCheckStrictly; + } + + public void setDeptCheckStrictly(boolean deptCheckStrictly) { + this.deptCheckStrictly = deptCheckStrictly; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getDelFlag() { + return delFlag; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public boolean isFlag() { + return flag; + } + + public void setFlag(boolean flag) { + this.flag = flag; + } + + public Long[] getMenuIds() { + return menuIds; + } + + public void setMenuIds(Long[] menuIds) { + this.menuIds = menuIds; + } + + public Long[] getDeptIds() { + return deptIds; + } + + public void setDeptIds(Long[] deptIds) { + this.deptIds = deptIds; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("roleId", getRoleId()) + .append("roleName", getRoleName()) + .append("roleKey", getRoleKey()) + .append("roleSort", getRoleSort()) + .append("dataScope", getDataScope()) + .append("menuCheckStrictly", isMenuCheckStrictly()) + .append("deptCheckStrictly", isDeptCheckStrictly()) + .append("status", getStatus()) + .append("delFlag", getDelFlag()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysUser.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysUser.java new file mode 100644 index 000000000..f1a163685 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/entity/SysUser.java @@ -0,0 +1,322 @@ +package com.jsowell.common.core.domain.entity; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.annotation.Excel.Type; +import com.jsowell.common.annotation.Excels; +import com.jsowell.common.core.domain.BaseEntity; +import com.jsowell.common.xss.Xss; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import java.util.Date; +import java.util.List; + +/** + * 鐢ㄦ埛瀵硅薄 sys_user + * + * @author jsowell + */ +public class SysUser extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 鐢ㄦ埛ID + */ + @Excel(name = "鐢ㄦ埛搴忓彿", cellType = ColumnType.NUMERIC, prompt = "鐢ㄦ埛缂栧彿") + private Long userId; + + /** + * 閮ㄩ棬ID + */ + @Excel(name = "閮ㄩ棬缂栧彿", type = Type.IMPORT) + private Long deptId; + + /** + * 鐢ㄦ埛璐﹀彿 + */ + @Excel(name = "鐧诲綍鍚嶇О") + private String userName; + + /** + * 鐢ㄦ埛鏄电О + */ + @Excel(name = "鐢ㄦ埛鍚嶇О") + private String nickName; + + /** + * 鐢ㄦ埛閭 + */ + @Excel(name = "鐢ㄦ埛閭") + private String email; + + /** + * 鎵嬫満鍙风爜 + */ + @Excel(name = "鎵嬫満鍙风爜") + private String phone; + + /** + * 鐢ㄦ埛鎬у埆 + */ + @Excel(name = "鐢ㄦ埛鎬у埆", readConverterExp = "0=鐢,1=濂,2=鏈煡") + private String sex; + + /** + * 鐢ㄦ埛澶村儚 + */ + private String avatar; + + /** + * 瀵嗙爜 + */ + private String password; + + /** + * 甯愬彿鐘舵侊紙0姝e父 1鍋滅敤锛 + */ + @Excel(name = "甯愬彿鐘舵", readConverterExp = "0=姝e父,1=鍋滅敤") + private String status; + + /** + * 鍒犻櫎鏍囧織锛0浠h〃瀛樺湪 2浠h〃鍒犻櫎锛 + */ + private String delFlag; + + /** + * 鏈鍚庣櫥褰旾P + */ + @Excel(name = "鏈鍚庣櫥褰旾P", type = Type.EXPORT) + private String loginIp; + + /** + * 鏈鍚庣櫥褰曟椂闂 + */ + @Excel(name = "鏈鍚庣櫥褰曟椂闂", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT) + private Date loginDate; + + /** + * 閮ㄩ棬瀵硅薄 + */ + @Excels({ + @Excel(name = "閮ㄩ棬鍚嶇О", targetAttr = "deptName", type = Type.EXPORT), + @Excel(name = "閮ㄩ棬璐熻矗浜", targetAttr = "leader", type = Type.EXPORT) + }) + private SysDept dept; + + /** + * 瑙掕壊瀵硅薄 + */ + private List roles; + + /** + * 瑙掕壊缁 + */ + private Long[] roleIds; + + /** + * 宀椾綅缁 + */ + private Long[] postIds; + + /** + * 瑙掕壊ID + */ + private Long roleId; + + public SysUser() { + + } + + public SysUser(Long userId) { + this.userId = userId; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public boolean isAdmin() { + return isAdmin(this.userId); + } + + public static boolean isAdmin(Long userId) { + return userId != null && 1L == userId; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } + + @Xss(message = "鐢ㄦ埛鏄电О涓嶈兘鍖呭惈鑴氭湰瀛楃") + @Size(min = 0, max = 30, message = "鐢ㄦ埛鏄电О闀垮害涓嶈兘瓒呰繃30涓瓧绗") + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + + @Xss(message = "鐢ㄦ埛璐﹀彿涓嶈兘鍖呭惈鑴氭湰瀛楃") + @NotBlank(message = "鐢ㄦ埛璐﹀彿涓嶈兘涓虹┖") + @Size(min = 0, max = 30, message = "鐢ㄦ埛璐﹀彿闀垮害涓嶈兘瓒呰繃30涓瓧绗") + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + @Email(message = "閭鏍煎紡涓嶆纭") + @Size(min = 0, max = 50, message = "閭闀垮害涓嶈兘瓒呰繃50涓瓧绗") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @Size(min = 0, max = 11, message = "鎵嬫満鍙风爜闀垮害涓嶈兘瓒呰繃11涓瓧绗") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getDelFlag() { + return delFlag; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public String getLoginIp() { + return loginIp; + } + + public void setLoginIp(String loginIp) { + this.loginIp = loginIp; + } + + public Date getLoginDate() { + return loginDate; + } + + public void setLoginDate(Date loginDate) { + this.loginDate = loginDate; + } + + public SysDept getDept() { + return dept; + } + + public void setDept(SysDept dept) { + this.dept = dept; + } + + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + public Long[] getRoleIds() { + return roleIds; + } + + public void setRoleIds(Long[] roleIds) { + this.roleIds = roleIds; + } + + public Long[] getPostIds() { + return postIds; + } + + public void setPostIds(Long[] postIds) { + this.postIds = postIds; + } + + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("userId", getUserId()) + .append("deptId", getDeptId()) + .append("userName", getUserName()) + .append("nickName", getNickName()) + .append("email", getEmail()) + .append("phone", getPhone()) + .append("sex", getSex()) + .append("avatar", getAvatar()) + .append("password", getPassword()) + .append("status", getStatus()) + .append("delFlag", getDelFlag()) + .append("loginIp", getLoginIp()) + .append("loginDate", getLoginDate()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .append("dept", getDept()) + .toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/LoginBody.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/LoginBody.java new file mode 100644 index 000000000..694786212 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/LoginBody.java @@ -0,0 +1,32 @@ +package com.jsowell.common.core.domain.model; + +import lombok.Data; + +/** + * 鐢ㄦ埛鐧诲綍瀵硅薄 + * + * @author jsowell + */ +@Data +public class LoginBody { + /** + * 鐢ㄦ埛鍚 + */ + private String username; + + /** + * 鐢ㄦ埛瀵嗙爜 + */ + private String password; + + /** + * 楠岃瘉鐮 + */ + private String code; + + /** + * 鍞竴鏍囪瘑 + */ + private String uuid; + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/LoginUser.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/LoginUser.java new file mode 100644 index 000000000..017688080 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/LoginUser.java @@ -0,0 +1,234 @@ +package com.jsowell.common.core.domain.model; + +import com.alibaba.fastjson2.annotation.JSONField; +import com.jsowell.common.core.domain.entity.SysUser; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; +import java.util.Set; + +/** + * 鐧诲綍鐢ㄦ埛韬唤鏉冮檺 + * + * @author jsowell + */ +public class LoginUser implements UserDetails { + private static final long serialVersionUID = 1L; + + /** + * 鐢ㄦ埛ID + */ + private Long userId; + + /** + * 閮ㄩ棬ID + */ + private Long deptId; + + /** + * 鐢ㄦ埛鍞竴鏍囪瘑 + */ + private String token; + + /** + * 鐧诲綍鏃堕棿 + */ + private Long loginTime; + + /** + * 杩囨湡鏃堕棿 + */ + private Long expireTime; + + /** + * 鐧诲綍IP鍦板潃 + */ + private String ipaddr; + + /** + * 鐧诲綍鍦扮偣 + */ + private String loginLocation; + + /** + * 娴忚鍣ㄧ被鍨 + */ + private String browser; + + /** + * 鎿嶄綔绯荤粺 + */ + private String os; + + /** + * 鏉冮檺鍒楄〃 + */ + private Set permissions; + + /** + * 鐢ㄦ埛淇℃伅 + */ + private SysUser user; + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public LoginUser() { + } + + public LoginUser(SysUser user, Set permissions) { + this.user = user; + this.permissions = permissions; + } + + public LoginUser(Long userId, Long deptId, SysUser user, Set permissions) { + this.userId = userId; + this.deptId = deptId; + this.user = user; + this.permissions = permissions; + } + + @JSONField(serialize = false) + @Override + public String getPassword() { + return user.getPassword(); + } + + @Override + public String getUsername() { + return user.getUserName(); + } + + /** + * 璐︽埛鏄惁鏈繃鏈,杩囨湡鏃犳硶楠岃瘉 + */ + @JSONField(serialize = false) + @Override + public boolean isAccountNonExpired() { + return true; + } + + /** + * 鎸囧畾鐢ㄦ埛鏄惁瑙i攣,閿佸畾鐨勭敤鎴锋棤娉曡繘琛岃韩浠介獙璇 + * + * @return + */ + @JSONField(serialize = false) + @Override + public boolean isAccountNonLocked() { + return true; + } + + /** + * 鎸囩ず鏄惁宸茶繃鏈熺殑鐢ㄦ埛鐨勫嚟鎹(瀵嗙爜),杩囨湡鐨勫嚟鎹槻姝㈣璇 + * + * @return + */ + @JSONField(serialize = false) + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + /** + * 鏄惁鍙敤 ,绂佺敤鐨勭敤鎴蜂笉鑳借韩浠介獙璇 + * + * @return + */ + @JSONField(serialize = false) + @Override + public boolean isEnabled() { + return true; + } + + public Long getLoginTime() { + return loginTime; + } + + public void setLoginTime(Long loginTime) { + this.loginTime = loginTime; + } + + public String getIpaddr() { + return ipaddr; + } + + public void setIpaddr(String ipaddr) { + this.ipaddr = ipaddr; + } + + public String getLoginLocation() { + return loginLocation; + } + + public void setLoginLocation(String loginLocation) { + this.loginLocation = loginLocation; + } + + public String getBrowser() { + return browser; + } + + public void setBrowser(String browser) { + this.browser = browser; + } + + public String getOs() { + return os; + } + + public void setOs(String os) { + this.os = os; + } + + public Long getExpireTime() { + return expireTime; + } + + public void setExpireTime(Long expireTime) { + this.expireTime = expireTime; + } + + public Set getPermissions() { + return permissions; + } + + public void setPermissions(Set permissions) { + this.permissions = permissions; + } + + public SysUser getUser() { + return user; + } + + public void setUser(SysUser user) { + this.user = user; + } + + @Override + public Collection getAuthorities() { + return null; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/RegisterBody.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/RegisterBody.java new file mode 100644 index 000000000..77d57be26 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/model/RegisterBody.java @@ -0,0 +1,10 @@ +package com.jsowell.common.core.domain.model; + +/** + * 鐢ㄦ埛娉ㄥ唽瀵硅薄 + * + * @author jsowell + */ +public class RegisterBody extends LoginBody { + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/LoginRequestData.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/LoginRequestData.java new file mode 100644 index 000000000..f3dd51468 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/LoginRequestData.java @@ -0,0 +1,58 @@ +package com.jsowell.common.core.domain.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class LoginRequestData { + /** + * 妗╃紪鐮 BCD 鐮 7 涓嶈冻 7 浣嶈ˉ 0 + */ + private String pileSn; + + /** + * 妗╃被鍨 BIN 鐮 1 0 琛ㄧず鐩存祦妗╋紝 1 琛ㄧず浜ゆ祦妗 + */ + private String pileType; + + /** + * 鍏呯數鏋暟閲 BIN 鐮 1 + */ + private String connectorNum; + + /** + * 閫氫俊鍗忚鐗堟湰 BIN 鐮 1 鐗堟湰鍙蜂箻 10锛寁1.0 琛ㄧず 0x0A + */ + private String communicationVersion; + + /** + * 绋嬪簭鐗堟湰 ASCII 鐮 8 涓嶈冻 8 浣嶈ˉ闆 + */ + private String programVersion; + + /** + * 缃戠粶閾炬帴绫诲瀷 BIN 鐮 1 0x00 SIM 鍗 + * 0x01 LAN + * 0x02 WAN + * 0x03 鍏朵粬 + */ + private String internetConnection; + + /** + * Sim 鍗 BCD 鐮 10 涓嶈冻 10 浣嶈ˉ闆讹紝鍙栦笉鍒扮疆闆 + */ + private String iccid; + + /** + * 杩愯惀鍟 BIN 鐮 1 0x00 绉诲姩 + * 0x02 鐢典俊 + * 0x03 鑱旈 + * 0x04 鍏朵粬 + */ + private String business; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/RealTimeMonitorData.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/RealTimeMonitorData.java new file mode 100644 index 000000000..6788ff5dd --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/RealTimeMonitorData.java @@ -0,0 +1,124 @@ +package com.jsowell.common.core.domain.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 瀹炴椂鐩戞祴鏁版嵁 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class RealTimeMonitorData { + /** + * 浜ゆ槗娴佹按鍙 + */ + private String orderCode; + + /** + * 妗╃紪鍙 + */ + private String pileSn; + + /** + * 鏋彛缂栧彿 + */ + private String connectorCode; + + /** + * 鐘舵 + */ + private String connectorStatus; + + /** + * 鏋槸鍚﹀綊浣 + */ + private String homingFlag; + + /** + * 鍏呯數鏋紪鍙 + */ + private String pileConnectorCode; + + /** + * 鏄惁鎻掓灙 0x00锛氬惁 0x01锛氭槸 + */ + private String putGunType; + + /** + * 杈撳嚭鐢靛帇 + */ + private String outputVoltage; + + /** + * 杈撳嚭鐢垫祦 + */ + private String outputCurrent; + + /** + * 杈撳嚭鍔熺巼锛堢敱杈撳嚭鐢靛帇锛岃緭鍑虹數娴佽绠楀緱鍑猴級 + */ + private String outputPower; + + /** + * 鏋嚎娓╁害 + */ + private String gunLineTemperature; + + /** + * 鏋嚎缂栫爜 娌℃湁缃浂 + */ + private String gunLineCode; + + /** + * SOC 寰呮満缃浂锛涗氦娴佹々缃浂 + */ + private String SOC; + + /** + * 鐢垫睜缁勬渶楂樻俯搴 + */ + private String batteryMaxTemperature; + + /** + * 绱鍏呯數鏃堕棿 鍗曚綅锛 min锛涘緟鏈虹疆闆 + */ + private String sumChargingTime; + + /** + * 鍓╀綑鏃堕棿 鍗曚綅锛 min锛涘緟鏈虹疆闆躲佷氦娴佹々缃浂 + */ + private String timeRemaining; + + /** + * 鍏呯數搴︽暟 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紱寰呮満缃浂 + */ + private String chargingDegree; + + /** + * 璁℃崯鍏呯數搴︽暟 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紱寰呮満缃浂 鏈缃鎹熸瘮渚嬫椂绛変簬鍏呯數搴︽暟 + */ + private String lossDegree; + + /** + * 宸插厖閲戦 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紱寰呮満缃浂 锛堢數璐+鏈嶅姟璐癸級 *璁℃崯鍏呯數搴︽暟 + */ + private String chargingAmount; + + /** + * 纭欢鏁呴殰 + */ + private String hardwareFault; + + /** + * 鏃堕棿 + */ + private String dateTime; + + public String getPileConnectorCode() { + return this.pileSn + this.getConnectorCode(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/TransactionRecordsData.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/TransactionRecordsData.java new file mode 100644 index 000000000..4557b4090 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/TransactionRecordsData.java @@ -0,0 +1,157 @@ +package com.jsowell.common.core.domain.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 浜ゆ槗璁板綍鏁版嵁瀵硅薄 + * + * @author JS-ZZA + * @date 2022/11/16 15:01 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TransactionRecordsData { + + // 浜ゆ槗娴佹按鍙 + private String orderCode; + + // 妗╃紪鐮 + private String pileSn; + + // 鏋彿 + private String connectorCode; + + // 寮濮嬫椂闂 CP56Time2a 鏍煎紡 + private String startTime; + + // 缁撴潫鏃堕棿 + private String endTime; + + // 灏栧崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙灏栫數璐+灏栨湇鍔¤垂锛岃璐圭巼甯э級 + private String sharpPrice; + + // 灏栫數閲 绮剧‘鍒板皬鏁扮偣鍚庡洓浣 + private String sharpUsedElectricity; + + // 璁℃崯灏栫數閲 + private String sharpPlanLossElectricity; + + // 灏栭噾棰 + private String sharpAmount; + + // 宄板崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙宄扮數璐+宄版湇鍔¤垂锛 + private String peakPrice; + + // 宄扮數閲 + private String peakUsedElectricity; + + // 璁℃崯宄扮數閲 + private String peakPlanLossElectricity; + + // 宄伴噾棰 + private String peakAmount; + + // 骞冲崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙骞崇數璐+骞虫湇鍔¤垂锛 + private String flatPrice; + + // 骞崇數閲 + private String flatUsedElectricity; + + // 璁℃崯骞崇數閲 + private String flatPlanLossElectricity; + + // 骞抽噾棰 + private String flatAmount; + + // 璋峰崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙璋风數璐+璋 鏈嶅姟璐癸級 + private String valleyPrice; + + // 璋风數閲 + private String valleyUsedElectricity; + + // 璁℃崯璋风數閲 + private String valleyPlanLossElectricity; + + // 璋烽噾棰 + private String valleyAmount; + + // 鐢佃〃鎬昏捣鍊 + private String ammeterTotalStart; + + // 鐢佃〃鎬绘鍊 + private String ammeterTotalEnd; + + // 鎬荤數閲 + private String totalElectricity; + + // 璁℃崯鎬荤數閲 + private String planLossTotalElectricity; + + // 娑堣垂閲戦 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紝鍖呭惈鐢佃垂銆 鏈嶅姟璐 + private String consumptionAmount; + + // VIN 鐮 VIN 鐮侊紝姝ゅ VIN 鐮佸拰鍏呯數鏃 VIN 鐮佷笉鍚岋紝 姝e簭鐩存帴涓婁紶锛 鏃犻渶琛 0 鍜屽弽搴 + private String vinCode; + + /** order_anomaly_record + * 浜ゆ槗鏍囪瘑 + * 0x01锛 app 鍚姩 + * 0x02锛氬崱鍚姩 + * 0x04锛氱绾垮崱鍚姩 + * 0x05: vin 鐮佸惎鍔ㄥ厖鐢 + */ + private String transactionIdentifier; + + // 浜ゆ槗鏃堕棿 CP56Time2a 鏍煎紡 + private String transactionTime; + + // 鍋滄鍘熷洜 + private String stopReasonMsg; + + // 鐗╃悊鍗″彿 涓嶈冻 8 浣嶈ˉ 0 + private String logicCard; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("orderCode", orderCode) + .append("pileSn", pileSn) + .append("connectorCode", connectorCode) + .append("startTime", startTime) + .append("endTime", endTime) + .append("sharpPrice", sharpPrice) + .append("sharpUsedElectricity", sharpUsedElectricity) + .append("sharpPlanLossElectricity", sharpPlanLossElectricity) + .append("sharpAmount", sharpAmount) + .append("peakPrice", peakPrice) + .append("peakUsedElectricity", peakUsedElectricity) + .append("peakPlanLossElectricity", peakPlanLossElectricity) + .append("peakAmount", peakAmount) + .append("flatPrice", flatPrice) + .append("flatUsedElectricity", flatUsedElectricity) + .append("flatPlanLossElectricity", flatPlanLossElectricity) + .append("flatAmount", flatAmount) + .append("valleyPrice", valleyPrice) + .append("valleyUsedElectricity", valleyUsedElectricity) + .append("valleyPlanLossElectricity", valleyPlanLossElectricity) + .append("valleyAmount", valleyAmount) + .append("ammeterTotalStart", ammeterTotalStart) + .append("ammeterTotalEnd", ammeterTotalEnd) + .append("totalElectricity", totalElectricity) + .append("planLossTotalElectricity", planLossTotalElectricity) + .append("consumptionAmount", consumptionAmount) + .append("vinCode", vinCode) + .append("transactionIdentifier", transactionIdentifier) + .append("transactionTime", transactionTime) + .append("stopReasonMsg", stopReasonMsg) + .append("logicCard", logicCard) + .toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/YKCDataProtocol.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/YKCDataProtocol.java new file mode 100644 index 000000000..67de4b837 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/YKCDataProtocol.java @@ -0,0 +1,73 @@ +package com.jsowell.common.core.domain.ykc; + +import com.google.common.primitives.Bytes; +import com.jsowell.common.util.BytesUtil; +import lombok.Data; + +/** + * 浜戝揩鍏呮暟鎹ā鏉 + */ +@Data +public class YKCDataProtocol { + /** + * 璧峰鏍囧織 1瀛楄妭 + */ + private byte[] head; + + /** + * 鏁版嵁闀垮害 1瀛楄妭 + */ + private byte[] length; + + /** + * 搴忓垪鍙峰煙 2瀛楄妭 + */ + private byte[] serialNumber; + + /** + * 鍔犲瘑鏍囧織 1 瀛楄妭 + */ + private byte[] encryptFlag; + + /** + * 甯х被鍨嬫爣蹇 1 瀛楄妭 + */ + private byte[] frameType; + + /** + * 娑堟伅浣 N瀛楄妭 + */ + private byte[] msgBody; + + /** + * 甯ф牎楠屽煙 2瀛楄妭 + */ + private byte[] crcByte; + + public YKCDataProtocol(byte[] msg) { + // 璧峰鏍囧織 + this.head = BytesUtil.copyBytes(msg, 0, 1); + // 鏁版嵁闀垮害 + this.length = BytesUtil.copyBytes(msg, 1, 1); + // 搴忓垪鍙峰煙 + this.serialNumber = BytesUtil.copyBytes(msg, 2, 2); + // 鍔犲瘑鏍囧織 + this.encryptFlag = BytesUtil.copyBytes(msg, 4, 1); + // 甯х被鍨嬫爣蹇 + this.frameType = BytesUtil.copyBytes(msg, 5, 1); + // 娑堟伅浣 + this.msgBody = BytesUtil.copyBytes(msg, 6, msg.length - 8); + // 甯ф牎楠屽煙 + this.crcByte = new byte[]{msg[msg.length - 2], msg[msg.length - 1]}; + } + + /** + * 杞崲涓哄崄鍏繘鍒跺瓧绗︿覆 + * + * @return 鎶ユ枃 + */ + public String getHEXString() { + byte[] bytes = Bytes.concat(this.head, this.length, this.serialNumber, this.encryptFlag, this.frameType, this.msgBody, this.crcByte); + return BytesUtil.binary(bytes, 16); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/YKCFrameTypeCode.java b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/YKCFrameTypeCode.java new file mode 100644 index 000000000..4e8c5a4e2 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/domain/ykc/YKCFrameTypeCode.java @@ -0,0 +1,203 @@ +package com.jsowell.common.core.domain.ykc; + +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; + +/** + * 浜戝揩鍏 甯х被鍨嬬爜 + * FrameTypeCode + * frame + */ +public enum YKCFrameTypeCode { + + LOGIN_CODE(0x01, "鍏呯數妗╃櫥褰曡璇"), + LOGIN_ANSWER_CODE(0x02, "鐧诲綍璁よ瘉搴旂瓟"), + + HEART_BEAT_CODE(0x03, "鍏呯數妗╁績璺冲寘"), + HEART_BEAT_ANSWER_CODE(0x04, "蹇冭烦鍖呭簲绛"), + + BILLING_TEMPLATE_VALIDATE_CODE(0x05, "璁¤垂妯″瀷楠岃瘉璇锋眰"), + BILLING_TEMPLATE_VALIDATE_ANSWER_CODE(0x06, "璁¤垂妯″瀷楠岃瘉璇锋眰搴旂瓟"), + + BILLING_TEMPLATE_CODE(0x09, "鍏呯數妗╄璐规ā鍨嬭姹"), + BILLING_TEMPLATE_ANSWER_CODE(0x0A, "璁¤垂妯″瀷璇锋眰搴旂瓟"), + + UPLOAD_REAL_TIME_MONITOR_DATA_OLD_VERSION_CODE(0x11, "涓婁紶瀹炴椂鐩戞祴鏁版嵁V1.3"), + READ_REAL_TIME_MONITOR_DATA_CODE(0x12, "璇诲彇瀹炴椂鐩戞祴鏁版嵁"), + UPLOAD_REAL_TIME_MONITOR_DATA_CODE(0x13, "涓婁紶瀹炴椂鐩戞祴鏁版嵁"), + + CHARGING_HANDSHAKE_CODE(0x15, "鍏呯數鎻℃墜"), + PARAMETER_CONFIGURATION_CODE(0x17, "鍙傛暟閰嶇疆"), + CHARGE_END_CODE(0X19, "鍏呯數缁撴潫"), + ERROR_MESSAGE_CODE(0x1B, "閿欒鎶ユ枃"), + BMS_ABORT_DURING_CHARGING_PHASE_CODE(0x1D, "鍏呯數闃舵BMS涓"), + THE_CHARGER_IS_ABORTED_DURING_THE_CHARGING_PHASE_CODE(0X21, "鍏呯數闃舵鍏呯數鏈轰腑姝"), + CHARGING_PROCESS_BMS_DEMAND_AND_CHARGER_OUTPUT_CODE(0X23, "鍏呯數杩囩▼ BMS 闇姹備笌鍏呯數鏈鸿緭鍑"), + CHARGING_PROCESS_BMS_INFORMATION_CODE(0X25, "鍏呯數杩囩▼ BMS 淇℃伅"), + + REQUEST_START_CHARGING_CODE(0x31, "鍏呯數妗╀富鍔ㄧ敵璇峰惎鍔ㄥ厖鐢"), + CONFIRM_START_CHARGING_CODE(0x32, "杩愯惀骞冲彴纭鍚姩鍏呯數"), + + REMOTE_START_CHARGING_ANSWER_CODE(0x33, "杩滅▼鍚姩鍏呯數鍛戒护鍥炲"), + REMOTE_CONTROL_START_CODE(0x34, "杩愯惀骞冲彴杩滅▼鎺у埗鍚満"), + + REMOTE_STOP_CHARGING_ANSWER_CODE(0x35, "杩滅▼鍋滄満鍛戒护鍥炲"), + REMOTE_STOP_CHARGING_CODE(0x36, "杩愯惀骞冲彴杩滅▼鍋滄満"), + + + TRANSACTION_RECORDS_CODE(0x3B, "浜ゆ槗璁板綍"), + TRANSACTION_RECORDS_OLD_VERSION_CODE(0x39, "浜ゆ槗璁板綍V1.3"), + TRANSACTION_RECORDS_CONFIRM_CODE(0x40, "浜ゆ槗璁板綍纭"), + + REMOTE_ACCOUNT_BALANCE_UPDATE_CODE(0x42, "杩滅▼璐︽埛浣欓鏇存柊"), + REMOTE_ACCOUNT_BALANCE_UPDATE_ANSWER_CODE(0x41, "浣欓鏇存柊搴旂瓟"), + + OFFLINE_CARD_DATA_SYNCHRONIZATION_CODE(0x44, "绂荤嚎鍗℃暟鎹悓姝"), + OFFLINE_CARD_DATA_SYNCHRONIZATION_ANSWER_CODE(0x43, "绂荤嚎鍗℃暟鎹悓姝ュ簲绛"), + + OFFLINE_CARD_DATA_CLEANING_CODE(0x46, "绂荤嚎鍗℃暟鎹竻闄"), + OFFLINE_CARD_DATA_CLEANING_ANSWER_CODE(0x45, "绂荤嚎鍗℃暟鎹竻闄ゅ簲绛"), + + OFFLINE_CARD_DATA_QUERY_CODE(0x48, "绂荤嚎鍗℃暟鎹煡璇"), + OFFLINE_CARD_DATA_QUERY_ANSWER_CODE(0x47, "绂荤嚎鍗℃暟鎹煡璇㈠簲绛"), + + CHARGING_PILE_WORKING_PARAMETER_SETTING_CODE(0x52, "鍏呯數妗╁伐浣滃弬鏁拌缃"), + CHARGING_PILE_WORKING_PARAMETER_SETTING_ANSWER_CODE(0x51, "鍏呯數妗╁伐浣滃弬鏁拌缃簲绛"), + + TIME_CHECK_SETTING_CODE(0x56, "瀵规椂璁剧疆"), + TIME_CHECK_SETTING_ANSWER_CODE(0x55, "瀵规椂璁剧疆搴旂瓟"), + + BILLING_TEMPLATE_SETTING_CODE(0x58, "璁¤垂妯″瀷璁剧疆"), + BILLING_TEMPLATE_SETTING_ANSWER_CODE(0x57, "璁¤垂妯″瀷璁剧疆搴旂瓟"), + + GROUND_LOCK_DATA_UPLOAD_CODE(0x61, "鍦伴攣鏁版嵁涓婇"), + REMOTE_CONTROL_GROUND_LOCK_LIFTING_CODE(0x62, "閬ユ帶鍦伴攣鍗囬檷"), + CHARGING_PILE_RESPOND_GROUND_LOCK_LIFTING_CODE(0X63, "鍏呯數妗╁搷搴斿湴閿佸崌闄嶆暟鎹"), + + REMOTE_RESTART_CODE(0x92, "杩滅▼閲嶅惎"), + REMOTE_RESTART_ANSWER_CODE(0x91, "杩滅▼閲嶅惎搴旂瓟"), + + REMOTE_UPDATE_CODE(0x94, "杩滅▼鏇存柊"), + REMOTE_UPDATE_ANSWER_CODE(0x93, "杩滅▼鏇存柊搴旂瓟"), + + REMOTE_ISSUE_QRCODE_CODE(0xF0, "鍚庡彴杩滅▼涓嬪彂浜岀淮鐮佸墠缂鎸囦护"), + REMOTE_ISSUE_QRCODE_ANSWER_CODE(0xF1, "妗╁簲绛旇繙绋嬩笅鍙戜簩缁寸爜鍓嶇紑鎸囦护"), + + // 鑷畾涔塅rameType + PILE_LOG_OUT(9999, "鍏呯數妗╅鍑"), + + + ; + + YKCFrameTypeCode(int code, String value) { + this.code = code; + this.value = value; + } + + private int code; + private String value; + + public int getCode() { + return code; + } + + public String getValue() { + return value; + } + + public byte[] getBytes() { + return BytesUtil.intToBytesLittle(code, 1); + } + + public static void main(String[] args) { + byte[] bytes = BytesUtil.intToBytesLittle(9999, 1); + System.out.println(YKCUtils.frameType2Str(bytes)); + } + + public static YKCFrameTypeCode fromCode(byte code) { + for (YKCFrameTypeCode item : YKCFrameTypeCode.values()) { + if (item.getCode() == code) { + return item; + } + } + return null; + } + + public static String getFrameTypeStr(String frameType) { + for (YKCFrameTypeCode item : YKCFrameTypeCode.values()) { + String str = YKCUtils.frameType2Str(item.getBytes()); + if (StringUtils.equals(frameType, str)) { + return item.getValue(); + } + } + return ""; + } + + /** + * 璇锋眰搴旂瓟 甯х被鍨嬪叧绯 + */ + public enum ResponseRelation { + // 鐧诲綍 + LOGIN(LOGIN_CODE.getCode(), LOGIN_ANSWER_CODE.getCode()), + // 蹇冭烦 + HEART_BEAT(HEART_BEAT_CODE.getCode(), HEART_BEAT_ANSWER_CODE.getCode()), + // 璁¤垂妯℃澘楠岃瘉 + BILLING_TEMPLATE_VALIDATE(BILLING_TEMPLATE_VALIDATE_CODE.getCode(), BILLING_TEMPLATE_VALIDATE_ANSWER_CODE.getCode()), + // 璁¤垂妯℃澘璇锋眰 + BILLING_TEMPLATE(BILLING_TEMPLATE_CODE.getCode(), BILLING_TEMPLATE_ANSWER_CODE.getCode()), + // 璇锋眰寮濮嬪厖鐢 + START_CHARGING(REQUEST_START_CHARGING_CODE.getCode(), CONFIRM_START_CHARGING_CODE.getCode()), + // 杩滅▼璇锋眰鍏呯數 + REMOTE_START_CHARGING(REMOTE_CONTROL_START_CODE.getCode(), REMOTE_START_CHARGING_ANSWER_CODE.getCode()), + // 杩滅▼鍋滄鍏呯數 + REMOTE_STOP_CHARGING(REMOTE_STOP_CHARGING_CODE.getCode(), REMOTE_STOP_CHARGING_ANSWER_CODE.getCode()), + // 浜ゆ槗璁板綍 + TRANSACTION_RECORDS(TRANSACTION_RECORDS_CODE.getCode(), TRANSACTION_RECORDS_CONFIRM_CODE.getCode()), + // 杩滅▼璐︽埛鏇存柊 + REMOTE_ACCOUNT_BALANCE_UPDATE(REMOTE_ACCOUNT_BALANCE_UPDATE_CODE.getCode(), REMOTE_ACCOUNT_BALANCE_UPDATE_ANSWER_CODE.getCode()); + + // 璇锋眰甯х被鍨 + private int requestFrameType; + + // 鍝嶅簲甯х被鍨 + private int responseFrameType; + + public int getRequestFrameType() { + return requestFrameType; + } + + public void setRequestFrameType(int requestFrameType) { + this.requestFrameType = requestFrameType; + } + + public int getResponseFrameType() { + return responseFrameType; + } + + public void setResponseFrameType(int responseFrameType) { + this.responseFrameType = responseFrameType; + } + + ResponseRelation(int requestFrameType, int responseFrameType) { + this.requestFrameType = requestFrameType; + this.responseFrameType = responseFrameType; + } + + // 鏍规嵁璇锋眰甯х被鍨 鑾峰彇搴旂瓟甯х被鍨 + public static int getResponseFrameType(int requestFrameType) { + for (ResponseRelation responseRelation : ResponseRelation.values()) { + if (responseRelation.getRequestFrameType() == requestFrameType) { + return responseRelation.getResponseFrameType(); + } + } + return 0; + } + + public static byte[] getResponseFrameType(byte[] requestFrameType) { + int frameType = BytesUtil.bytesToInt(requestFrameType); + return BytesUtil.intToBytes(getResponseFrameType(frameType), 1); + } + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/page/PageDomain.java b/jsowell-common/src/main/java/com/jsowell/common/core/page/PageDomain.java new file mode 100644 index 000000000..4af749f79 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/page/PageDomain.java @@ -0,0 +1,93 @@ +package com.jsowell.common.core.page; + +import com.jsowell.common.util.StringUtils; + +/** + * 鍒嗛〉鏁版嵁 + * + * @author jsowell + */ +public class PageDomain { + /** + * 褰撳墠璁板綍璧峰绱㈠紩 + */ + private Integer pageNum; + + /** + * 姣忛〉鏄剧ず璁板綍鏁 + */ + private Integer pageSize; + + /** + * 鎺掑簭鍒 + */ + private String orderByColumn; + + /** + * 鎺掑簭鐨勬柟鍚慸esc鎴栬卆sc + */ + private String isAsc = "asc"; + + /** + * 鍒嗛〉鍙傛暟鍚堢悊鍖 + */ + private Boolean reasonable = true; + + public String getOrderBy() { + if (StringUtils.isEmpty(orderByColumn)) { + return ""; + } + return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc; + } + + public Integer getPageNum() { + return pageNum; + } + + public void setPageNum(Integer pageNum) { + this.pageNum = pageNum; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public String getOrderByColumn() { + return orderByColumn; + } + + public void setOrderByColumn(String orderByColumn) { + this.orderByColumn = orderByColumn; + } + + public String getIsAsc() { + return isAsc; + } + + public void setIsAsc(String isAsc) { + if (StringUtils.isNotEmpty(isAsc)) { + // 鍏煎鍓嶇鎺掑簭绫诲瀷 + if ("ascending".equals(isAsc)) { + isAsc = "asc"; + } else if ("descending".equals(isAsc)) { + isAsc = "desc"; + } + this.isAsc = isAsc; + } + } + + public Boolean getReasonable() { + if (StringUtils.isNull(reasonable)) { + return Boolean.TRUE; + } + return reasonable; + } + + public void setReasonable(Boolean reasonable) { + this.reasonable = reasonable; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/page/PageResponse.java b/jsowell-common/src/main/java/com/jsowell/common/core/page/PageResponse.java new file mode 100644 index 000000000..3d5496e0c --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/page/PageResponse.java @@ -0,0 +1,42 @@ +package com.jsowell.common.core.page; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PageResponse implements Serializable { + private static final long serialVersionUID = -8561048121257788971L; + + /** + * 椤电爜 + */ + private int pageNum; + + /** + * 姣忛〉鏁伴噺 + */ + private int pageSize; + + /** + * 鏁版嵁闆嗗悎 + */ + private List list; + + /** + * 缁撴灉鎬绘暟 + */ + private long total; + + /** + * 缁撴灉鎬婚〉鏁 + */ + private int pages; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/page/TableDataInfo.java b/jsowell-common/src/main/java/com/jsowell/common/core/page/TableDataInfo.java new file mode 100644 index 000000000..36c7e551d --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/page/TableDataInfo.java @@ -0,0 +1,82 @@ +package com.jsowell.common.core.page; + +import java.io.Serializable; +import java.util.List; + +/** + * 琛ㄦ牸鍒嗛〉鏁版嵁瀵硅薄 + * + * @author jsowell + */ +public class TableDataInfo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鎬昏褰曟暟 + */ + private long total; + + /** + * 鍒楄〃鏁版嵁 + */ + private List rows; + + /** + * 娑堟伅鐘舵佺爜 + */ + private int code; + + /** + * 娑堟伅鍐呭 + */ + private String msg; + + /** + * 琛ㄦ牸鏁版嵁瀵硅薄 + */ + public TableDataInfo() { + } + + /** + * 鍒嗛〉 + * + * @param list 鍒楄〃鏁版嵁 + * @param total 鎬昏褰曟暟 + */ + public TableDataInfo(List list, int total) { + this.rows = list; + this.total = total; + } + + public long getTotal() { + return total; + } + + public void setTotal(long total) { + this.total = total; + } + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/page/TableSupport.java b/jsowell-common/src/main/java/com/jsowell/common/core/page/TableSupport.java new file mode 100644 index 000000000..630c2f733 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/page/TableSupport.java @@ -0,0 +1,53 @@ +package com.jsowell.common.core.page; + +import com.jsowell.common.core.text.Convert; +import com.jsowell.common.util.ServletUtils; + +/** + * 琛ㄦ牸鏁版嵁澶勭悊 + * + * @author jsowell + */ +public class TableSupport { + /** + * 褰撳墠璁板綍璧峰绱㈠紩 + */ + public static final String PAGE_NUM = "pageNum"; + + /** + * 姣忛〉鏄剧ず璁板綍鏁 + */ + public static final String PAGE_SIZE = "pageSize"; + + /** + * 鎺掑簭鍒 + */ + public static final String ORDER_BY_COLUMN = "orderByColumn"; + + /** + * 鎺掑簭鐨勬柟鍚 "desc" 鎴栬 "asc". + */ + public static final String IS_ASC = "isAsc"; + + /** + * 鍒嗛〉鍙傛暟鍚堢悊鍖 + */ + public static final String REASONABLE = "reasonable"; + + /** + * 灏佽鍒嗛〉瀵硅薄 + */ + public static PageDomain getPageDomain() { + PageDomain pageDomain = new PageDomain(); + pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1)); + pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10)); + pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN)); + pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC)); + pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE)); + return pageDomain; + } + + public static PageDomain buildPageRequest() { + return getPageDomain(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java new file mode 100644 index 000000000..b355af15c --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java @@ -0,0 +1,504 @@ +package com.jsowell.common.core.redis; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.BoundSetOperations; +import org.springframework.data.redis.core.Cursor; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisCallback; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ScanOptions; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * spring redis 宸ュ叿绫 + * + * @author jsowell + **/ +@SuppressWarnings(value = {"unchecked", "rawtypes"}) +@Component +public class RedisCache { + + Logger logger = LoggerFactory.getLogger(RedisCache.class); + + @Autowired + public RedisTemplate redisTemplate; + + // redis閿佽幏鍙栬秴鏃舵椂闂 + private long timeout = 500l; + + /** + * 缂撳瓨鍩烘湰鐨勫璞★紝Integer銆丼tring銆佸疄浣撶被绛 + * + * @param key 缂撳瓨鐨勯敭鍊 + * @param value 缂撳瓨鐨勫 + */ + public void setCacheObject(final String key, final T value) { + redisTemplate.opsForValue().set(key, value); + } + + /** + * 璁剧疆缂撳瓨 + * + * @param key 缂撳瓨鐨勯敭鍊 + * @param value 缂撳瓨鐨勫 + * @param timeout 瓒呮椂鏃堕棿 鍗曚綅绉 + */ + public void setCacheObject(final String key, final T value, final Integer timeout) { + // redisTemplate.opsForValue().set(key, value, timeout, timeUnit); + setCacheObject(key, value, timeout, TimeUnit.SECONDS); + } + + /** + * 缂撳瓨鍩烘湰鐨勫璞★紝Integer銆丼tring銆佸疄浣撶被绛 + * + * @param key 缂撳瓨鐨勯敭鍊 + * @param value 缂撳瓨鐨勫 + * @param timeout 鏃堕棿 + * @param timeUnit 鏃堕棿棰楃矑搴 + */ + public void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) { + redisTemplate.opsForValue().set(key, value, timeout, timeUnit); + } + + /** + * 璁剧疆鏈夋晥鏃堕棿 + * + * @param key Redis閿 + * @param timeout 瓒呮椂鏃堕棿 + * @return true=璁剧疆鎴愬姛锛沠alse=璁剧疆澶辫触 + */ + public boolean expire(final String key, final long timeout) { + return expire(key, timeout, TimeUnit.SECONDS); + } + + /** + * 璁剧疆鏈夋晥鏃堕棿 + * + * @param key Redis閿 + * @param timeout 瓒呮椂鏃堕棿 + * @param unit 鏃堕棿鍗曚綅 + * @return true=璁剧疆鎴愬姛锛沠alse=璁剧疆澶辫触 + */ + public boolean expire(final String key, final long timeout, final TimeUnit unit) { + return redisTemplate.expire(key, timeout, unit); + } + + /** + * 鑾峰彇鏈夋晥鏃堕棿 + * + * @param key Redis閿 + * @return 鏈夋晥鏃堕棿 + */ + public long getExpire(final String key) { + return redisTemplate.getExpire(key); + } + + /** + * 鍒ゆ柇 key鏄惁瀛樺湪 + * + * @param key 閿 + * @return true 瀛樺湪 false涓嶅瓨鍦 + */ + public Boolean hasKey(String key) { + return redisTemplate.hasKey(key); + } + + /** + * 鑾峰緱缂撳瓨鐨勫熀鏈璞° + * + * @param key 缂撳瓨閿 + * @return 缂撳瓨閿煎搴旂殑鏁版嵁 + */ + public T getCacheObject(final String key) { + ValueOperations operation = redisTemplate.opsForValue(); + return operation.get(key); + } + + /** + * 鍒犻櫎鍗曚釜瀵硅薄 + * + * @param key + */ + public boolean deleteObject(final String key) { + return redisTemplate.delete(key); + } + + /** + * 鍒犻櫎闆嗗悎瀵硅薄 + * + * @param collection 澶氫釜瀵硅薄 + * @return + */ + public long deleteObject(final Collection collection) { + return redisTemplate.delete(collection); + } + + /** + * 缂撳瓨List鏁版嵁 + * + * @param key 缂撳瓨鐨勯敭鍊 + * @param dataList 寰呯紦瀛樼殑List鏁版嵁 + * @return 缂撳瓨鐨勫璞 + */ + public long setCacheList(final String key, final List dataList) { + Long count = redisTemplate.opsForList().rightPushAll(key, dataList); + return count == null ? 0 : count; + } + + /** + * 鑾峰緱缂撳瓨鐨刲ist瀵硅薄 + * + * @param key 缂撳瓨鐨勯敭鍊 + * @return 缂撳瓨閿煎搴旂殑鏁版嵁 + */ + public List getCacheList(final String key) { + return redisTemplate.opsForList().range(key, 0, -1); + } + + /** + * 鎵归噺鑾峰彇缂撳瓨 + * + * @param keys + * @param + * @return + */ + public List multiGet(final List keys) { + return redisTemplate.opsForValue().multiGet(keys); + } + + /** + * 缂撳瓨Set + * + * @param key 缂撳瓨閿 + * @param dataSet 缂撳瓨鐨勬暟鎹 + * @return 缂撳瓨鏁版嵁鐨勫璞 + */ + public BoundSetOperations setCacheSet(final String key, final Set dataSet) { + BoundSetOperations setOperation = redisTemplate.boundSetOps(key); + Iterator it = dataSet.iterator(); + while (it.hasNext()) { + setOperation.add(it.next()); + } + return setOperation; + } + + /** + * 鑾峰緱缂撳瓨鐨剆et + * + * @param key + * @return + */ + public Set getCacheSet(final String key) { + return redisTemplate.opsForSet().members(key); + } + + /** + * 缂撳瓨Map + * + * @param key + * @param dataMap + */ + public void setCacheMap(final String key, final Map dataMap) { + if (dataMap != null) { + redisTemplate.opsForHash().putAll(key, dataMap); + } + } + + /** + * 鑾峰緱缂撳瓨鐨凪ap + * + * @param key + * @return + */ + public Map getCacheMap(final String key) { + return redisTemplate.opsForHash().entries(key); + } + + /** + * 寰Hash涓瓨鍏ユ暟鎹 + * + * @param key Redis閿 + * @param hKey Hash閿 + * @param value 鍊 + */ + public void setCacheMapValue(final String key, final String hKey, final T value) { + redisTemplate.opsForHash().put(key, hKey, value); + } + + /** + * 鑾峰彇Hash涓殑鏁版嵁 + * + * @param key Redis閿 + * @param hKey Hash閿 + * @return Hash涓殑瀵硅薄 + */ + public T getCacheMapValue(final String key, final String hKey) { + HashOperations opsForHash = redisTemplate.opsForHash(); + return opsForHash.get(key, hKey); + } + + /** + * 鍒犻櫎Hash涓殑鏁版嵁 + * + * @param key + * @param hKey + */ + public void delCacheMapValue(final String key, final String hKey) { + HashOperations hashOperations = redisTemplate.opsForHash(); + hashOperations.delete(key, hKey); + } + + /** + * 鑾峰彇澶氫釜Hash涓殑鏁版嵁 + * + * @param key Redis閿 + * @param hKeys Hash閿泦鍚 + * @return Hash瀵硅薄闆嗗悎 + */ + public List getMultiCacheMapValue(final String key, final Collection hKeys) { + return redisTemplate.opsForHash().multiGet(key, hKeys); + } + + /** + * 鍒犻櫎Hash涓殑鏌愭潯鏁版嵁 + * + * @param key Redis閿 + * @param hKey Hash閿 + * @return 鏄惁鎴愬姛 + */ + public boolean deleteCacheMapValue(final String key, final String hKey) { + return Boolean.TRUE.equals(redisTemplate.opsForHash().delete(key, hKey)); + } + + /** + * 鑾峰緱缂撳瓨鐨勫熀鏈璞″垪琛 + * + * @param pattern 瀛楃涓插墠缂 + * @return 瀵硅薄鍒楄〃 + */ + public Collection keys(final String pattern) { + return redisTemplate.keys(pattern); + } + + public Long increment(final String key, final long delta) { + return redisTemplate.opsForValue().increment(key, delta); + } + + /** + * scan 瀹炵幇 + * + * @param pattern 琛ㄨ揪寮忥紝濡傦細abc*锛屾壘鍑烘墍鏈変互abc寮濮嬬殑閿 + */ + public Set scan(String pattern) { + return (Set) redisTemplate.execute((RedisCallback>) connection -> { + Set keysTmp = new HashSet<>(); + try (Cursor cursor = connection.scan(new ScanOptions.ScanOptionsBuilder() + .match(pattern) + .count(10000).build())) { + + while (cursor.hasNext()) { + keysTmp.add(new String(cursor.next(), "Utf-8")); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RuntimeException(e); + } + return keysTmp; + }); + } + + /** + * 鍔犻攣锛屾棤闃诲 + * + * @param lockKey 閿 + * @param requestId 璇锋眰鏍囪瘑 + * @param expireTime 瓒呮湡鏃堕棿 + * @return 鏄惁鑾峰彇鎴愬姛 + */ + public Boolean lock(String lockKey, String requestId, long expireTime) { + Long start = System.currentTimeMillis(); + //鍦ㄤ竴瀹氭椂闂村唴鑾峰彇閿侊紝瓒呮椂鍒欒繑鍥為敊璇 + for (; ; ) { + //Set鍛戒护杩斿洖OK锛屽垯璇佹槑鑾峰彇閿佹垚鍔 + Boolean ret = redisTemplate.opsForValue().setIfAbsent(lockKey, requestId, expireTime, TimeUnit.SECONDS); + if (ret != null && ret) { + return true; + } + //鍚﹀垯寰幆绛夊緟锛屽湪timeout鏃堕棿鍐呬粛鏈幏鍙栧埌閿侊紝鍒欒幏鍙栧け璐 + long end = System.currentTimeMillis() - start; + if (end >= timeout) { + return false; + } + } + } + + /** + * 鏍规嵁key'鍒犻櫎閿 + * + * @param lockKey + */ + public void unLock(String lockKey) { + // 鍒犻櫎key鍗冲彲閲婃斁閿 + redisTemplate.delete(lockKey); + } + + // ================================Map================================= + + /** + * HashGet + * + * @param key 閿 涓嶈兘涓簄ull + * @param item 椤 涓嶈兘涓簄ull + */ + public Object hget(String key, String item) { + return redisTemplate.opsForHash().get(key, item); + } + + /** + * 鑾峰彇hashKey瀵瑰簲鐨勬墍鏈夐敭鍊 + * + * @param key 閿 + * @return 瀵瑰簲鐨勫涓敭鍊 + */ + public Map hmget(String key) { + return redisTemplate.opsForHash().entries(key); + } + + /** + * HashSet + * + * @param key 閿 + * @param map 瀵瑰簲澶氫釜閿 + */ + public boolean hmset(String key, Map map) { + try { + redisTemplate.opsForHash().putAll(key, map); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + + /** + * HashSet 骞惰缃椂闂 + * + * @param key 閿 + * @param map 瀵瑰簲澶氫釜閿 + * @param time 鏃堕棿(绉) + * @return true鎴愬姛 false澶辫触 + */ + public boolean hmset(String key, Map map, long time, TimeUnit timeUnit) { + try { + redisTemplate.opsForHash().putAll(key, map); + if (time > 0) { + expire(key, time, timeUnit); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + + /** + * 鍚戜竴寮爃ash琛ㄤ腑鏀惧叆鏁版嵁,濡傛灉涓嶅瓨鍦ㄥ皢鍒涘缓 + * + * @param key 閿 + * @param item 椤 + * @param value 鍊 + * @return true 鎴愬姛 false澶辫触 + */ + public boolean hset(String key, String item, Object value) { + try { + redisTemplate.opsForHash().put(key, item, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 鍚戜竴寮爃ash琛ㄤ腑鏀惧叆鏁版嵁,濡傛灉涓嶅瓨鍦ㄥ皢鍒涘缓 + * + * @param key 閿 + * @param item 椤 + * @param value 鍊 + * @param time 鏃堕棿(绉) 娉ㄦ剰:濡傛灉宸插瓨鍦ㄧ殑hash琛ㄦ湁鏃堕棿,杩欓噷灏嗕細鏇挎崲鍘熸湁鐨勬椂闂 + * @return true 鎴愬姛 false澶辫触 + */ + public boolean hset(String key, String item, Object value, long time, TimeUnit timeUnit) { + try { + redisTemplate.opsForHash().put(key, item, value); + if (time > 0) { + expire(key, time, timeUnit); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + + /** + * 鍒犻櫎hash琛ㄤ腑鐨勫 + * + * @param key 閿 涓嶈兘涓簄ull + * @param item 椤 鍙互浣垮涓 涓嶈兘涓簄ull + */ + public void hdel(String key, Object... item) { + redisTemplate.opsForHash().delete(key, item); + } + + + /** + * 鍒ゆ柇hash琛ㄤ腑鏄惁鏈夎椤圭殑鍊 + * + * @param key 閿 涓嶈兘涓簄ull + * @param item 椤 涓嶈兘涓簄ull + * @return true 瀛樺湪 false涓嶅瓨鍦 + */ + public boolean hHasKey(String key, String item) { + return redisTemplate.opsForHash().hasKey(key, item); + } + + + /** + * hash閫掑 濡傛灉涓嶅瓨鍦,灏变細鍒涘缓涓涓 骞舵妸鏂板鍚庣殑鍊艰繑鍥 + * + * @param key 閿 + * @param item 椤 + * @param by 瑕佸鍔犲嚑(澶т簬0) + */ + public double hincr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, by); + } + + + /** + * hash閫掑噺 + * + * @param key 閿 + * @param item 椤 + * @param by 瑕佸噺灏戣(灏忎簬0) + */ + public double hdecr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, -by); + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/text/CharsetKit.java b/jsowell-common/src/main/java/com/jsowell/common/core/text/CharsetKit.java new file mode 100644 index 000000000..f065ee589 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/text/CharsetKit.java @@ -0,0 +1,91 @@ +package com.jsowell.common.core.text; + +import com.jsowell.common.util.StringUtils; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +/** + * 瀛楃闆嗗伐鍏风被 + * + * @author jsowell + */ +public class CharsetKit { + /** + * ISO-8859-1 + */ + public static final String ISO_8859_1 = "ISO-8859-1"; + /** + * UTF-8 + */ + public static final String UTF_8 = "UTF-8"; + /** + * GBK + */ + public static final String GBK = "GBK"; + + /** + * ISO-8859-1 + */ + public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1); + /** + * UTF-8 + */ + public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8); + /** + * GBK + */ + public static final Charset CHARSET_GBK = Charset.forName(GBK); + + /** + * 杞崲涓篊harset瀵硅薄 + * + * @param charset 瀛楃闆嗭紝涓虹┖鍒欒繑鍥為粯璁ゅ瓧绗﹂泦 + * @return Charset + */ + public static Charset charset(String charset) { + return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); + } + + /** + * 杞崲瀛楃涓茬殑瀛楃闆嗙紪鐮 + * + * @param source 瀛楃涓 + * @param srcCharset 婧愬瓧绗﹂泦锛岄粯璁SO-8859-1 + * @param destCharset 鐩爣瀛楃闆嗭紝榛樿UTF-8 + * @return 杞崲鍚庣殑瀛楃闆 + */ + public static String convert(String source, String srcCharset, String destCharset) { + return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset)); + } + + /** + * 杞崲瀛楃涓茬殑瀛楃闆嗙紪鐮 + * + * @param source 瀛楃涓 + * @param srcCharset 婧愬瓧绗﹂泦锛岄粯璁SO-8859-1 + * @param destCharset 鐩爣瀛楃闆嗭紝榛樿UTF-8 + * @return 杞崲鍚庣殑瀛楃闆 + */ + public static String convert(String source, Charset srcCharset, Charset destCharset) { + if (null == srcCharset) { + srcCharset = StandardCharsets.ISO_8859_1; + } + + if (null == destCharset) { + destCharset = StandardCharsets.UTF_8; + } + + if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset)) { + return source; + } + return new String(source.getBytes(srcCharset), destCharset); + } + + /** + * @return 绯荤粺瀛楃闆嗙紪鐮 + */ + public static String systemCharset() { + return Charset.defaultCharset().name(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/text/Convert.java b/jsowell-common/src/main/java/com/jsowell/common/core/text/Convert.java new file mode 100644 index 000000000..66c5da536 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/text/Convert.java @@ -0,0 +1,849 @@ +package com.jsowell.common.core.text; + +import com.jsowell.common.util.StringUtils; +import org.apache.commons.lang3.ArrayUtils; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.text.NumberFormat; +import java.util.Set; + +/** + * 绫诲瀷杞崲鍣 + * + * @author jsowell + */ +public class Convert { + /** + * 杞崲涓哄瓧绗︿覆
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static String toStr(Object value, String defaultValue) { + if (null == value) { + return defaultValue; + } + if (value instanceof String) { + return (String) value; + } + return value.toString(); + } + + /** + * 杞崲涓哄瓧绗︿覆
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static String toStr(Object value) { + return toStr(value, null); + } + + /** + * 杞崲涓哄瓧绗
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Character toChar(Object value, Character defaultValue) { + if (null == value) { + return defaultValue; + } + if (value instanceof Character) { + return (Character) value; + } + + final String valueStr = toStr(value, null); + return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0); + } + + /** + * 杞崲涓哄瓧绗
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Character toChar(Object value) { + return toChar(value, null); + } + + /** + * 杞崲涓篵yte
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Byte toByte(Object value, Byte defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Byte) { + return (Byte) value; + } + if (value instanceof Number) { + return ((Number) value).byteValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Byte.parseByte(valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篵yte
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Byte toByte(Object value) { + return toByte(value, null); + } + + /** + * 杞崲涓篠hort
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Short toShort(Object value, Short defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Short) { + return (Short) value; + } + if (value instanceof Number) { + return ((Number) value).shortValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Short.parseShort(valueStr.trim()); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篠hort
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Short toShort(Object value) { + return toShort(value, null); + } + + /** + * 杞崲涓篘umber
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Number toNumber(Object value, Number defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Number) { + return (Number) value; + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return NumberFormat.getInstance().parse(valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篘umber
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Number toNumber(Object value) { + return toNumber(value, null); + } + + /** + * 杞崲涓篿nt
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Integer toInt(Object value, Integer defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Integer) { + return (Integer) value; + } + if (value instanceof Number) { + return ((Number) value).intValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Integer.parseInt(valueStr.trim()); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篿nt
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Integer toInt(Object value) { + return toInt(value, null); + } + + /** + * 杞崲涓篒nteger鏁扮粍
+ * + * @param str 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Integer[] toIntArray(String str) { + return toIntArray(",", str); + } + + /** + * 杞崲涓篖ong鏁扮粍
+ * + * @param str 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Long[] toLongArray(String str) { + return toLongArray(",", str); + } + + /** + * 杞崲涓篒nteger鏁扮粍
+ * + * @param split 鍒嗛殧绗 + * @param split 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Integer[] toIntArray(String split, String str) { + if (StringUtils.isEmpty(str)) { + return new Integer[]{}; + } + String[] arr = str.split(split); + final Integer[] ints = new Integer[arr.length]; + for (int i = 0; i < arr.length; i++) { + final Integer v = toInt(arr[i], 0); + ints[i] = v; + } + return ints; + } + + /** + * 杞崲涓篖ong鏁扮粍
+ * + * @param split 鍒嗛殧绗 + * @param str 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Long[] toLongArray(String split, String str) { + if (StringUtils.isEmpty(str)) { + return new Long[]{}; + } + String[] arr = str.split(split); + final Long[] longs = new Long[arr.length]; + for (int i = 0; i < arr.length; i++) { + final Long v = toLong(arr[i], null); + longs[i] = v; + } + return longs; + } + + /** + * 杞崲涓篠tring鏁扮粍
+ * + * @param str 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static String[] toStrArray(String str) { + return toStrArray(",", str); + } + + /** + * 杞崲涓篠tring鏁扮粍
+ * + * @param split 鍒嗛殧绗 + * @param split 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static String[] toStrArray(String split, String str) { + return str.split(split); + } + + /** + * 杞崲涓簂ong
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Long toLong(Object value, Long defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Long) { + return (Long) value; + } + if (value instanceof Number) { + return ((Number) value).longValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + // 鏀寔绉戝璁℃暟娉 + return new BigDecimal(valueStr.trim()).longValue(); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓簂ong
+ * 濡傛灉缁欏畾鐨勫间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Long toLong(Object value) { + return toLong(value, null); + } + + /** + * 杞崲涓篸ouble
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Double toDouble(Object value, Double defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Double) { + return (Double) value; + } + if (value instanceof Number) { + return ((Number) value).doubleValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + // 鏀寔绉戝璁℃暟娉 + return new BigDecimal(valueStr.trim()).doubleValue(); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篸ouble
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Double toDouble(Object value) { + return toDouble(value, null); + } + + /** + * 杞崲涓篎loat
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Float toFloat(Object value, Float defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Float) { + return (Float) value; + } + if (value instanceof Number) { + return ((Number) value).floatValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Float.parseFloat(valueStr.trim()); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篎loat
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Float toFloat(Object value) { + return toFloat(value, null); + } + + /** + * 杞崲涓篵oolean
+ * String鏀寔鐨勫间负锛歵rue銆乫alse銆亂es銆乷k銆乶o锛1,0 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static Boolean toBool(Object value, Boolean defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Boolean) { + return (Boolean) value; + } + String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + valueStr = valueStr.trim().toLowerCase(); + switch (valueStr) { + case "true": + case "yes": + case "ok": + case "1": + return true; + case "false": + case "no": + case "0": + return false; + default: + return defaultValue; + } + } + + /** + * 杞崲涓篵oolean
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static Boolean toBool(Object value) { + return toBool(value, null); + } + + /** + * 杞崲涓篍num瀵硅薄
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * + * @param clazz Enum鐨凜lass + * @param value 鍊 + * @param defaultValue 榛樿鍊 + * @return Enum + */ + public static > E toEnum(Class clazz, Object value, E defaultValue) { + if (value == null) { + return defaultValue; + } + if (clazz.isAssignableFrom(value.getClass())) { + @SuppressWarnings("unchecked") + E myE = (E) value; + return myE; + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Enum.valueOf(clazz, valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篍num瀵硅薄
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * + * @param clazz Enum鐨凜lass + * @param value 鍊 + * @return Enum + */ + public static > E toEnum(Class clazz, Object value) { + return toEnum(clazz, value, null); + } + + /** + * 杞崲涓築igInteger
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static BigInteger toBigInteger(Object value, BigInteger defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof BigInteger) { + return (BigInteger) value; + } + if (value instanceof Long) { + return BigInteger.valueOf((Long) value); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return new BigInteger(valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓築igInteger
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊null
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static BigInteger toBigInteger(Object value) { + return toBigInteger(value, null); + } + + /** + * 杞崲涓築igDecimal
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊 + * @return 缁撴灉 + */ + public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof BigDecimal) { + return (BigDecimal) value; + } + if (value instanceof Long) { + return new BigDecimal((Long) value); + } + if (value instanceof Double) { + return new BigDecimal((Double) value); + } + if (value instanceof Integer) { + return new BigDecimal((Integer) value); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return new BigDecimal(valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓築igDecimal
+ * 濡傛灉缁欏畾鐨勫间负绌猴紝鎴栬呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊
+ * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊 + * @return 缁撴灉 + */ + public static BigDecimal toBigDecimal(Object value) { + return toBigDecimal(value, null); + } + + /** + * 灏嗗璞¤浆涓哄瓧绗︿覆
+ * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 + * + * @param obj 瀵硅薄 + * @return 瀛楃涓 + */ + public static String utf8Str(Object obj) { + return str(obj, CharsetKit.CHARSET_UTF_8); + } + + /** + * 灏嗗璞¤浆涓哄瓧绗︿覆
+ * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 + * + * @param obj 瀵硅薄 + * @param charsetName 瀛楃闆 + * @return 瀛楃涓 + */ + public static String str(Object obj, String charsetName) { + return str(obj, Charset.forName(charsetName)); + } + + /** + * 灏嗗璞¤浆涓哄瓧绗︿覆
+ * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 + * + * @param obj 瀵硅薄 + * @param charset 瀛楃闆 + * @return 瀛楃涓 + */ + public static String str(Object obj, Charset charset) { + if (null == obj) { + return null; + } + + if (obj instanceof String) { + return (String) obj; + } else if (obj instanceof byte[]) { + return str((byte[]) obj, charset); + } else if (obj instanceof Byte[]) { + byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj); + return str(bytes, charset); + } else if (obj instanceof ByteBuffer) { + return str((ByteBuffer) obj, charset); + } + return obj.toString(); + } + + /** + * 灏哹yte鏁扮粍杞负瀛楃涓 + * + * @param bytes byte鏁扮粍 + * @param charset 瀛楃闆 + * @return 瀛楃涓 + */ + public static String str(byte[] bytes, String charset) { + return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset)); + } + + /** + * 瑙g爜瀛楄妭鐮 + * + * @param data 瀛楃涓 + * @param charset 瀛楃闆嗭紝濡傛灉姝ゅ瓧娈典负绌猴紝鍒欒В鐮佺殑缁撴灉鍙栧喅浜庡钩鍙 + * @return 瑙g爜鍚庣殑瀛楃涓 + */ + public static String str(byte[] data, Charset charset) { + if (data == null) { + return null; + } + + if (null == charset) { + return new String(data); + } + return new String(data, charset); + } + + /** + * 灏嗙紪鐮佺殑byteBuffer鏁版嵁杞崲涓哄瓧绗︿覆 + * + * @param data 鏁版嵁 + * @param charset 瀛楃闆嗭紝濡傛灉涓虹┖浣跨敤褰撳墠绯荤粺瀛楃闆 + * @return 瀛楃涓 + */ + public static String str(ByteBuffer data, String charset) { + if (data == null) { + return null; + } + + return str(data, Charset.forName(charset)); + } + + /** + * 灏嗙紪鐮佺殑byteBuffer鏁版嵁杞崲涓哄瓧绗︿覆 + * + * @param data 鏁版嵁 + * @param charset 瀛楃闆嗭紝濡傛灉涓虹┖浣跨敤褰撳墠绯荤粺瀛楃闆 + * @return 瀛楃涓 + */ + public static String str(ByteBuffer data, Charset charset) { + if (null == charset) { + charset = Charset.defaultCharset(); + } + return charset.decode(data).toString(); + } + + // ----------------------------------------------------------------------- 鍏ㄨ鍗婅杞崲 + + /** + * 鍗婅杞叏瑙 + * + * @param input String. + * @return 鍏ㄨ瀛楃涓. + */ + public static String toSBC(String input) { + return toSBC(input, null); + } + + /** + * 鍗婅杞叏瑙 + * + * @param input String + * @param notConvertSet 涓嶆浛鎹㈢殑瀛楃闆嗗悎 + * @return 鍏ㄨ瀛楃涓. + */ + public static String toSBC(String input, Set notConvertSet) { + char[] c = input.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (null != notConvertSet && notConvertSet.contains(c[i])) { + // 璺宠繃涓嶆浛鎹㈢殑瀛楃 + continue; + } + + if (c[i] == ' ') { + c[i] = '\u3000'; + } else if (c[i] < '\177') { + c[i] = (char) (c[i] + 65248); + + } + } + return new String(c); + } + + /** + * 鍏ㄨ杞崐瑙 + * + * @param input String. + * @return 鍗婅瀛楃涓 + */ + public static String toDBC(String input) { + return toDBC(input, null); + } + + /** + * 鏇挎崲鍏ㄨ涓哄崐瑙 + * + * @param text 鏂囨湰 + * @param notConvertSet 涓嶆浛鎹㈢殑瀛楃闆嗗悎 + * @return 鏇挎崲鍚庣殑瀛楃 + */ + public static String toDBC(String text, Set notConvertSet) { + char[] c = text.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (null != notConvertSet && notConvertSet.contains(c[i])) { + // 璺宠繃涓嶆浛鎹㈢殑瀛楃 + continue; + } + + if (c[i] == '\u3000') { + c[i] = ' '; + } else if (c[i] > '\uFF00' && c[i] < '\uFF5F') { + c[i] = (char) (c[i] - 65248); + } + } + String returnString = new String(c); + + return returnString; + } + + /** + * 鏁板瓧閲戦澶у啓杞崲 鍏堝啓涓畬鏁寸殑鐒跺悗灏嗗闆舵嬀鏇挎崲鎴愰浂 + * + * @param n 鏁板瓧 + * @return 涓枃澶у啓鏁板瓧 + */ + public static String digitUppercase(double n) { + String[] fraction = {"瑙", "鍒"}; + String[] digit = {"闆", "澹", "璐", "鍙", "鑲", "浼", "闄", "鏌", "鎹", "鐜"}; + String[][] unit = {{"鍏", "涓", "浜"}, {"", "鎷", "浣", "浠"}}; + + String head = n < 0 ? "璐" : ""; + n = Math.abs(n); + + String s = ""; + for (int i = 0; i < fraction.length; i++) { + s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(闆.)+", ""); + } + if (s.length() < 1) { + s = "鏁"; + } + int integerPart = (int) Math.floor(n); + + for (int i = 0; i < unit[0].length && integerPart > 0; i++) { + String p = ""; + for (int j = 0; j < unit[1].length && n > 0; j++) { + p = digit[integerPart % 10] + unit[1][j] + p; + integerPart = integerPart / 10; + } + s = p.replaceAll("(闆.)*闆$", "").replaceAll("^$", "闆") + unit[0][i] + s; + } + return head + s.replaceAll("(闆.)*闆跺厓", "鍏").replaceFirst("(闆.)+", "").replaceAll("(闆.)+", "闆").replaceAll("^鏁$", "闆跺厓鏁"); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/text/StrFormatter.java b/jsowell-common/src/main/java/com/jsowell/common/core/text/StrFormatter.java new file mode 100644 index 000000000..cf24adeae --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/core/text/StrFormatter.java @@ -0,0 +1,76 @@ +package com.jsowell.common.core.text; + +import com.jsowell.common.util.StringUtils; + +/** + * 瀛楃涓叉牸寮忓寲 + * + * @author jsowell + */ +public class StrFormatter { + public static final String EMPTY_JSON = "{}"; + public static final char C_BACKSLASH = '\\'; + public static final char C_DELIM_START = '{'; + public static final char C_DELIM_END = '}'; + + /** + * 鏍煎紡鍖栧瓧绗︿覆
+ * 姝ゆ柟娉曞彧鏄畝鍗曞皢鍗犱綅绗 {} 鎸夌収椤哄簭鏇挎崲涓哄弬鏁
+ * 濡傛灉鎯宠緭鍑 {} 浣跨敤 \\杞箟 { 鍗冲彲锛屽鏋滄兂杈撳嚭 {} 涔嬪墠鐨 \ 浣跨敤鍙岃浆涔夌 \\\\ 鍗冲彲
+ * 渚嬶細
+ * 閫氬父浣跨敤锛歠ormat("this is {} for {}", "a", "b") -> this is a for b
+ * 杞箟{}锛 format("this is \\{} for {}", "a", "b") -> this is \{} for a
+ * 杞箟\锛 format("this is \\\\{} for {}", "a", "b") -> this is \a for b
+ * + * @param strPattern 瀛楃涓叉ā鏉 + * @param argArray 鍙傛暟鍒楄〃 + * @return 缁撴灉 + */ + public static String format(final String strPattern, final Object... argArray) { + if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) { + return strPattern; + } + final int strPatternLength = strPattern.length(); + + // 鍒濆鍖栧畾涔夊ソ鐨勯暱搴︿互鑾峰緱鏇村ソ鐨勬ц兘 + StringBuilder sbuf = new StringBuilder(strPatternLength + 50); + + int handledPosition = 0; + int delimIndex;// 鍗犱綅绗︽墍鍦ㄤ綅缃 + for (int argIndex = 0; argIndex < argArray.length; argIndex++) { + delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); + if (delimIndex == -1) { + if (handledPosition == 0) { + return strPattern; + } else { // 瀛楃涓叉ā鏉垮墿浣欓儴鍒嗕笉鍐嶅寘鍚崰浣嶇锛屽姞鍏ュ墿浣欓儴鍒嗗悗杩斿洖缁撴灉 + sbuf.append(strPattern, handledPosition, strPatternLength); + return sbuf.toString(); + } + } else { + if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) { + if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) { + // 杞箟绗︿箣鍓嶈繕鏈変竴涓浆涔夌锛屽崰浣嶇渚濇棫鏈夋晥 + sbuf.append(strPattern, handledPosition, delimIndex - 1); + sbuf.append(Convert.utf8Str(argArray[argIndex])); + handledPosition = delimIndex + 2; + } else { + // 鍗犱綅绗﹁杞箟 + argIndex--; + sbuf.append(strPattern, handledPosition, delimIndex - 1); + sbuf.append(C_DELIM_START); + handledPosition = delimIndex + 1; + } + } else { + // 姝e父鍗犱綅绗 + sbuf.append(strPattern, handledPosition, delimIndex); + sbuf.append(Convert.utf8Str(argArray[argIndex])); + handledPosition = delimIndex + 2; + } + } + } + // 鍔犲叆鏈鍚庝竴涓崰浣嶇鍚庢墍鏈夌殑瀛楃 + sbuf.append(strPattern, handledPosition, strPattern.length()); + + return sbuf.toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/BusinessStatus.java b/jsowell-common/src/main/java/com/jsowell/common/enums/BusinessStatus.java new file mode 100644 index 000000000..40bc4746f --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/BusinessStatus.java @@ -0,0 +1,18 @@ +package com.jsowell.common.enums; + +/** + * 鎿嶄綔鐘舵 + * + * @author jsowell + */ +public enum BusinessStatus { + /** + * 鎴愬姛 + */ + SUCCESS, + + /** + * 澶辫触 + */ + FAIL, +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/BusinessType.java b/jsowell-common/src/main/java/com/jsowell/common/enums/BusinessType.java new file mode 100644 index 000000000..140836eeb --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/BusinessType.java @@ -0,0 +1,58 @@ +package com.jsowell.common.enums; + +/** + * 涓氬姟鎿嶄綔绫诲瀷 + * + * @author jsowell + */ +public enum BusinessType { + /** + * 鍏跺畠 + */ + OTHER, + + /** + * 鏂板 + */ + INSERT, + + /** + * 淇敼 + */ + UPDATE, + + /** + * 鍒犻櫎 + */ + DELETE, + + /** + * 鎺堟潈 + */ + GRANT, + + /** + * 瀵煎嚭 + */ + EXPORT, + + /** + * 瀵煎叆 + */ + IMPORT, + + /** + * 寮洪 + */ + FORCE, + + /** + * 鐢熸垚浠g爜 + */ + GENCODE, + + /** + * 娓呯┖鏁版嵁 + */ + CLEAN, +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/DataSourceType.java b/jsowell-common/src/main/java/com/jsowell/common/enums/DataSourceType.java new file mode 100644 index 000000000..7ad89880e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/DataSourceType.java @@ -0,0 +1,18 @@ +package com.jsowell.common.enums; + +/** + * 鏁版嵁婧 + * + * @author jsowell + */ +public enum DataSourceType { + /** + * 涓诲簱 + */ + MASTER, + + /** + * 浠庡簱 + */ + SLAVE +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/DelFlagEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/DelFlagEnum.java new file mode 100644 index 000000000..35d02c237 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/DelFlagEnum.java @@ -0,0 +1,34 @@ +package com.jsowell.common.enums; + +/** + * 鍒犻櫎鏍囪瘑鏋氫妇 + */ +public enum DelFlagEnum { + normal("0", "姝e父"), + delete("1", "鍒犻櫎"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + DelFlagEnum(String value, String label) { + this.value = value; + this.label = label; + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/HttpMethod.java b/jsowell-common/src/main/java/com/jsowell/common/enums/HttpMethod.java new file mode 100644 index 000000000..990234282 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/HttpMethod.java @@ -0,0 +1,32 @@ +package com.jsowell.common.enums; + +import org.springframework.lang.Nullable; + +import java.util.HashMap; +import java.util.Map; + +/** + * 璇锋眰鏂瑰紡 + * + * @author jsowell + */ +public enum HttpMethod { + GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; + + private static final Map mappings = new HashMap<>(16); + + static { + for (HttpMethod httpMethod : values()) { + mappings.put(httpMethod.name(), httpMethod); + } + } + + @Nullable + public static HttpMethod resolve(@Nullable String method) { + return (method != null ? mappings.get(method) : null); + } + + public boolean matches(String method) { + return (this == resolve(method)); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/LimitType.java b/jsowell-common/src/main/java/com/jsowell/common/enums/LimitType.java new file mode 100644 index 000000000..f138ac610 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/LimitType.java @@ -0,0 +1,19 @@ +package com.jsowell.common.enums; + +/** + * 闄愭祦绫诲瀷 + * + * @author jsowell + */ + +public enum LimitType { + /** + * 榛樿绛栫暐鍏ㄥ眬闄愭祦 + */ + DEFAULT, + + /** + * 鏍规嵁璇锋眰鑰匢P杩涜闄愭祦 + */ + IP +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/MemberWalletEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/MemberWalletEnum.java new file mode 100644 index 000000000..2babb195f --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/MemberWalletEnum.java @@ -0,0 +1,53 @@ +package com.jsowell.common.enums; + +/** + * 浼氬憳閽卞寘enum + */ +public enum MemberWalletEnum { + + /** + * 鏇存柊绫诲瀷 + * 1-杩涜处锛2-鍑鸿处 + */ + TYPE_IN("1", "杩涜处"), + TYPE_OUT("2", "鍑鸿处"), + + /** + * 瀛愮被鍨 + * 杩涜处锛10-鍏呭, 11-璧犻, 12-璁㈠崟缁撶畻閫娆 + * 鍑鸿处锛20-鍚庣鎵f, 21-璁㈠崟浠樻, 22-鐢ㄦ埛閫娆 + */ + SUBTYPE_TOP_UP("10", "鍏呭"), + SUBTYPE_GIVING("11", "璧犻"), + SUBTYPE_ORDER_SETTLEMENT_REFUND("12", "璁㈠崟缁撶畻閫娆"), + + SUBTYPE_WEB_DEDUCT_MONEY("20", "鍚庣鎵f"), + SUBTYPE_PAYMENT_FOR_ORDER("21", "璁㈠崟浠樻"), + SUBTYPE_USER_REFUND("22", "鐢ㄦ埛閫娆"), + + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + MemberWalletEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/OperatorType.java b/jsowell-common/src/main/java/com/jsowell/common/enums/OperatorType.java new file mode 100644 index 000000000..3f15ea2ea --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/OperatorType.java @@ -0,0 +1,23 @@ +package com.jsowell.common.enums; + +/** + * 鎿嶄綔浜虹被鍒 + * + * @author jsowell + */ +public enum OperatorType { + /** + * 鍏跺畠 + */ + OTHER, + + /** + * 鍚庡彴鐢ㄦ埛 + */ + MANAGE, + + /** + * 鎵嬫満绔敤鎴 + */ + MOBILE +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/SoftwareProtocolEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/SoftwareProtocolEnum.java new file mode 100644 index 000000000..53181d50f --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/SoftwareProtocolEnum.java @@ -0,0 +1,34 @@ +package com.jsowell.common.enums; + +/** + * 杞欢鍗忚enum + */ +public enum SoftwareProtocolEnum { + YUN_KUAI_CHONG("1", "浜戝揩鍏"), + YONG_LIAN("2", "姘歌仈"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + SoftwareProtocolEnum(String value, String label) { + this.value = value; + this.label = label; + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/UserStatus.java b/jsowell-common/src/main/java/com/jsowell/common/enums/UserStatus.java new file mode 100644 index 000000000..3503df188 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/UserStatus.java @@ -0,0 +1,28 @@ +package com.jsowell.common.enums; + +/** + * 鐢ㄦ埛鐘舵 + * + * @author jsowell + */ +public enum UserStatus { + OK("0" , "姝e父"), + DISABLE("1" , "鍋滅敤"), + DELETED("2" , "鍒犻櫎"); + + private final String code; + private final String info; + + UserStatus(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getInfo() { + return info; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/sim/SimCardStatusCorrespondEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/sim/SimCardStatusCorrespondEnum.java new file mode 100644 index 000000000..150b2fcd3 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/sim/SimCardStatusCorrespondEnum.java @@ -0,0 +1,80 @@ +package com.jsowell.common.enums.sim; + + +/** + * Sim鍗$姸鎬佸搴擡num + * 锛圵uLian锛 + * + * @author JS-ZZA + * @date 2023/1/5 10:59 + */ +public enum SimCardStatusCorrespondEnum { + // 姝e父 + NORMAL("9", "0"), + + // 鏂綉 + OFFLINE("5", "1"), + + // 閿鍗 + PIN_CARD("99", "6"), + + // 鏈嶅姟缁撴潫 + SERVICE_FINISHED("20", "1"), + + // 鏈紑鍗 + NOT_OPEN_CARD("0", "7"), + + // 娌夐粯鏈 + SILENCE_PERIOD("2", "8"), + + // 宸插仠鏈 + SHUT_DOWN_CARD("4", "9"), + + // 寰呮縺娲 + INACTIVE_CARD("8", "10"), + + // 宸插洖鏀 + RECYCLE_CARD("21", "11"), + + // 鏈煡 + UN_KNOW("80", "99"), + + ; + private String WuLianCardStatus; + private String dataBaseCardStatus; + + public String getWuLianCardStatus() { + return WuLianCardStatus; + } + + public void setWuLianCardStatus(String wuLianCardStatus) { + WuLianCardStatus = wuLianCardStatus; + } + + public String getDataBaseCardStatus() { + return dataBaseCardStatus; + } + + public void setDataBaseCardStatus(String dataBaseCardStatus) { + this.dataBaseCardStatus = dataBaseCardStatus; + } + + SimCardStatusCorrespondEnum(String wuLianCardStatus, String dataBaseCardStatus) { + WuLianCardStatus = wuLianCardStatus; + this.dataBaseCardStatus = dataBaseCardStatus; + } + + /** + * 鏍规嵁 WuLianCardStatus 鑾峰彇 dataBaseCardStatus + * @param WuLianCardStatus + * @return + */ + public static String getDataBaseCardStatus(String WuLianCardStatus) { + for (SimCardStatusCorrespondEnum item : SimCardStatusCorrespondEnum.values()) { + if (item.getWuLianCardStatus().equals(WuLianCardStatus)) { + return item.getDataBaseCardStatus(); + } + } + return null; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/sim/SimSupplierEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/sim/SimSupplierEnum.java new file mode 100644 index 000000000..95132c5e3 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/sim/SimSupplierEnum.java @@ -0,0 +1,53 @@ +package com.jsowell.common.enums.sim; + + +/** + * Sim鍗″晢 + * + * @author JS-ZZA + * @date 2022/12/17 14:30 + */ +public enum SimSupplierEnum { + XUN_ZHONG("1", "璁紬鐗╄仈"), + WU_LIAN_INTERNET("2", "鐗╄仈缃戞櫤鑳戒簯骞冲彴") + + + ; + private String code; + private String name; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + SimSupplierEnum(String code, String name) { + this.code = code; + this.name = name; + } + + /** + * 鏍规嵁code鑾峰彇name + * @param code + * @return + */ + public static String getNameByCode(String code) { + for (SimSupplierEnum item : SimSupplierEnum.values()) { + if (item.getCode().equals(code)) { + return item.getName(); + } + } + return null; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/uniapp/BalanceChangesEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/uniapp/BalanceChangesEnum.java new file mode 100644 index 000000000..238708f9b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/uniapp/BalanceChangesEnum.java @@ -0,0 +1,70 @@ +package com.jsowell.common.enums.uniapp; + +import com.jsowell.common.enums.ykc.StopChargingFailedReasonEnum; + +/** + * 鐢ㄦ埛璐︽埛浣欓Enum + * + * @author JS-ZZA + * @date 2022/11/26 11:34 + */ +public enum BalanceChangesEnum { + /** + * 杩涜处 + */ + CODE_RECHARGE("10", "鍏呭"), + + CODE_PRESENTED("11", "璧犻"), + + CODE_ORDER_SETTLEMENT_REFUND("12", "璁㈠崟缁撶畻閫娆"), + + + /** + * 鍑鸿处 + */ + CODE_SYSTEM_DEDUCTIONS("20", "鍚庣鎵f"), + + CODE_ORDER_PAYMENT("21", "璁㈠崟浠樻"), + + CODE_USER_REFUND("22", "鐢ㄦ埛閫娆"), + ; + private String code; + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + BalanceChangesEnum(String code, String value) { + this.value = value; + this.code = code; + } + + /** + * 鏍规嵁code鑾峰彇value + * @param code + * @return + */ + public static String getValueByCode(String code) { + for (BalanceChangesEnum item : BalanceChangesEnum.values()) { + if (item.getCode().equals(code)) { + return item.getValue(); + } + } + return null; + } + + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/BusinessType.java b/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/BusinessType.java new file mode 100644 index 000000000..d3c48f853 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/BusinessType.java @@ -0,0 +1,34 @@ +package com.jsowell.common.enums.weixin; + +/** + * 涓氬姟绫诲瀷 + * + * @author xiaojiewen + */ + +public enum BusinessType { + + CLIENT("瀹㈡埛绔", 6L), + DISTRIBUTOR("鍒嗛攢鍟", 2L), + MERCHANT("鏈嶅姟鍟", 3L), + OTHER("鍏朵粬", 0L) + + ; + + private String type; + + private Long enumType; + + BusinessType(String type, Long enumType) { + this.type = type; + this.enumType = enumType; + } + + public Long getEnumType() { + return enumType; + } + + public String getType() { + return type; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/WeiXinPayParam.java b/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/WeiXinPayParam.java new file mode 100644 index 000000000..127b90500 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/WeiXinPayParam.java @@ -0,0 +1,43 @@ +package com.jsowell.common.enums.weixin; + +/** + * 寰俊鏀粯鍙傛暟 + * WeiXinPayParam
+ * 鍒涘缓浜:灏忓▉
+ * 鏃堕棿锛2015骞12鏈1鏃-涓嬪崍4:41:02
+ * + * @version 1.0.0 + */ +public enum WeiXinPayParam { + + WEIXIN_PAY_DATA("data", "寰俊鏀粯鏁版嵁"), + WEIXIN_PAY_ID("id", "缂撳瓨id"), + WEIXIN_PAY_ORDERID("orderId", "璁㈠崟id"), + WEIXIN_PAY_MONEY("money", "鏀粯浠锋牸"); + + + private String value; + private String desc; + + WeiXinPayParam(String value, String desc) { + this.value = value; + this.desc = desc; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/WeiXinPayTradeStatus.java b/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/WeiXinPayTradeStatus.java new file mode 100644 index 000000000..8f20d844f --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/weixin/WeiXinPayTradeStatus.java @@ -0,0 +1,38 @@ +package com.jsowell.common.enums.weixin; + +/** + * 寰俊鏀粯浜ゆ槗鐘舵 + * WeiXinPayTradeStatus
+ * 鍒涘缓浜:灏忓▉
+ * 鏃堕棿锛2015骞12鏈1鏃-涓嬪崍4:37:55
+ * + * @version 1.0.0 + */ +public enum WeiXinPayTradeStatus { + SUCCESS("SUCCESS", "浜ゆ槗鎴愬姛"), + FAIL("FAIL", "浜ゆ槗澶辫触"); + private String value; + private String desc; + + WeiXinPayTradeStatus(String value, String desc) { + this.value = value; + this.desc = desc; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ActionTypeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ActionTypeEnum.java new file mode 100644 index 000000000..f0a6f6a96 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ActionTypeEnum.java @@ -0,0 +1,33 @@ +package com.jsowell.common.enums.ykc; + +/** + * 鎿嶄綔绫诲瀷鏋氫妇 + */ +public enum ActionTypeEnum { + FORWARD("forward", "姝e悜"), + REVERSE("reverse", "閫嗗悜"), + ; + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + ActionTypeEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/BillingTimeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/BillingTimeEnum.java new file mode 100644 index 000000000..581502f9b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/BillingTimeEnum.java @@ -0,0 +1,37 @@ +package com.jsowell.common.enums.ykc; + +/** + * 璁¤垂妯℃澘 鏃堕棿绫诲瀷 + * 锛1-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂锛 + */ +public enum BillingTimeEnum { + SHARP("1", "灏栨椂"), + PEAK("2", "宄版椂"), + FLAT("3", "骞虫椂"), + VALLEY("4", "璋锋椂"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + BillingTimeEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/BusinessTypeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/BusinessTypeEnum.java new file mode 100644 index 000000000..73c40f63c --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/BusinessTypeEnum.java @@ -0,0 +1,31 @@ +package com.jsowell.common.enums.ykc; + +public enum BusinessTypeEnum { + OPERATING_PILE("1", "杩愯惀妗"), + INDIVIDUAL_PILE("2", "涓汉妗"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + BusinessTypeEnum(String value, String label) { + this.value = value; + this.label = label; + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ChargingFailedReasonEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ChargingFailedReasonEnum.java new file mode 100644 index 000000000..69442758d --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ChargingFailedReasonEnum.java @@ -0,0 +1,56 @@ +package com.jsowell.common.enums.ykc; + +/** + * 鍚姩鍏呯數澶辫触鍘熷洜 + * + * @author JS-ZZA + * @date 2022/11/16 14:32 + */ +public enum ChargingFailedReasonEnum { + NULL(0x00, "鏃"), + EQUIPMENT_PILE_SN_NOT_MATCH(0x01, "璁惧妗╁彿涓嶅尮閰"), + CONNECTOR_IS_CHARGING(0x02, "鏋凡鍦ㄥ厖鐢"), + EQUIPMENT_BREAKDOWN(0x03, "璁惧鏁呴殰"), + EQUIPMENT_OFFLINE(0x04, "璁惧绂荤嚎"), + UNPLUGGED_GUN(0x05, "鏈彃鏋"), + + ; + private int code; + private String msg; + + ChargingFailedReasonEnum(int code, String msg) { + this.code = code; + this.msg = msg; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + /** + * 鏍规嵁code鑾峰彇鍋滄鍘熷洜鎻忚堪 + * + * @param code 缂栫爜 + * @return 鍋滄鍘熷洜鎻忚堪 + */ + public static String getMsgByCode(int code) { + for (ChargingFailedReasonEnum item : ChargingFailedReasonEnum.values()) { + if (item.getCode() == code) { + return item.getMsg(); + } + } + return null; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayModeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayModeEnum.java new file mode 100644 index 000000000..11cfb0457 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayModeEnum.java @@ -0,0 +1,47 @@ +package com.jsowell.common.enums.ykc; + +/** + * 璁㈠崟鏀粯鏂瑰紡enum + * 鍓嶇缁欑殑鍙傛暟 + */ +public enum OrderPayModeEnum { + + PAYMENT_OF_BALANCE("1", "浣欓鏀粯"), + PAYMENT_OF_WHITELIST("3", "鐧藉悕鍗曟敮浠"), + PAYMENT_OF_WECHATPAY("4", "寰俊鏀粯"), + PAYMENT_OF_ALIPAY("5", "鏀粯瀹濇敮浠"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public static String getPayModeDescription(String value) { + for (OrderPayModeEnum orderPayModeEnum : OrderPayModeEnum.values()) { + if (orderPayModeEnum.getValue().equals(value)) { + return orderPayModeEnum.getLabel(); + } + } + return ""; + } + + OrderPayModeEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayRecordEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayRecordEnum.java new file mode 100644 index 000000000..b15b61afc --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayRecordEnum.java @@ -0,0 +1,48 @@ +package com.jsowell.common.enums.ykc; + +/** + * order_pay_record琛╬ay_mode瀛楁 + * 鏀粯鏂瑰紡锛1-鏈噾浣欓鏀粯锛2-璧犻佷綑棰濇敮浠橈紱3-鐧藉悕鍗曟敮浠橈紱4-寰俊鏀粯锛5-鏀粯瀹濇敮浠橈級 + * 鍚庣鏁版嵁搴 + */ +public enum OrderPayRecordEnum { + PRINCIPAL_BALANCE_PAYMENT("1", "鏈噾浣欓鏀粯"), + GIFT_BALANCE_PAYMENT("2", "璧犻佷綑棰濇敮浠"), + WHITELIST_PAYMENT("3", "鐧藉悕鍗曟敮浠"), + WECHATPAY_PAYMENT("4", "寰俊鏀粯"), + ALIPAY_PAYMENT("5", "鏀粯瀹濇敮浠"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public static String getPayModeDescription(String value) { + for (OrderPayRecordEnum orderPayModeEnum : OrderPayRecordEnum.values()) { + if (orderPayModeEnum.getValue().equals(value)) { + return orderPayModeEnum.getLabel(); + } + } + return ""; + } + + OrderPayRecordEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayStatusEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayStatusEnum.java new file mode 100644 index 000000000..ca0e90787 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderPayStatusEnum.java @@ -0,0 +1,35 @@ +package com.jsowell.common.enums.ykc; + +/** + * 璁㈠崟鏀粯鐘舵 + */ +public enum OrderPayStatusEnum { + unpaid("0", "寰呮敮浠"), + paid("1", "鏀粯瀹屾垚"), + + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + OrderPayStatusEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderStatusEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderStatusEnum.java new file mode 100644 index 000000000..6aa5e83c4 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/OrderStatusEnum.java @@ -0,0 +1,51 @@ +package com.jsowell.common.enums.ykc; + +/** + * order_basic_info琛 order_status瀛楁 + * 璁㈠崟鐘舵(0-鏈惎鍔紱1-鍏呯數涓紱2-寰呯粨绠楋紱3-寰呰ˉ缂达紱4-寮傚父锛5-鍙枒锛6-璁㈠崟瀹屾垚锛7-瓒呮椂鍏抽棴) + */ +public enum OrderStatusEnum { + + NOT_START("0", "鏈惎鍔"), + IN_THE_CHARGING("1", "鍏呯數涓"), + STAY_SETTLEMENT("2", "寰呯粨绠"), + STAY_RETROACTIVE_AMOUNT("3", "寰呰ˉ缂"), + ABNORMAL("4", "寮傚父"), + SUSPICIOUS("5", "鍙枒"), + ORDER_COMPLETE("6", "璁㈠崟瀹屾垚"), + ORDER_CLOSE_TIMEOUT("7", "瓒呮椂鍏抽棴"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + OrderStatusEnum(String value, String label) { + this.value = value; + this.label = label; + } + + public static String getOrderStatus(String value) { + for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) { + if (orderStatusEnum.getValue().equals(value)) { + return orderStatusEnum.getLabel(); + } + } + return ""; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PayModeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PayModeEnum.java new file mode 100644 index 000000000..a0ce0637e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PayModeEnum.java @@ -0,0 +1,32 @@ +package com.jsowell.common.enums.ykc; + +public enum PayModeEnum { + PAYMENT_OF_BALANCE("balance", "浣欓鏀粯"), + PAYMENT_OF_WHITELIST("whitelist", "鐧藉悕鍗曟敮浠"), + PAYMENT_OF_WECHATPAY("wechatpay", "寰俊鏀粯"), + PAYMENT_OF_ALIPAY("alipay", "鏀粯瀹濇敮浠"), + ; + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + PayModeEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileChannelEntity.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileChannelEntity.java new file mode 100644 index 000000000..755f70cac --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileChannelEntity.java @@ -0,0 +1,55 @@ +package com.jsowell.common.enums.ykc; + +import io.netty.channel.Channel; + +import java.util.HashMap; + +/** + * 妗╃紪鍙峰拰channel鐨勫叧鑱斿叧绯诲鐞 entity + */ +public class PileChannelEntity { + + private static HashMap manager = new HashMap<>(); + + public static void put(String pileSn, Channel channel) { + manager.put(pileSn, channel); + } + + /** + * 閫氳繃妗╃紪鍙疯幏鍙朿hannel閾炬帴淇℃伅 + * @param pileSn + * @return + */ + public static Channel getChannelByPileSn(String pileSn) { + return manager.get(pileSn); + } + + /** + * 閫氳繃channelId鑾峰彇妗╃紪鍙 + * @param channelId + * @return + */ + public static String getPileSnByChannelId(String channelId) { + for (HashMap.Entry entry : manager.entrySet()) { + if (entry.getValue().id().asLongText().equals(channelId)) { + return entry.getKey(); + } + } + return null; + } + + /** + * 鎵撳嵃 + */ + public static void output() { + for (HashMap.Entry entry : manager.entrySet()) { + System.out.println("pileSn:" + entry.getKey() + + ",ChannelId:" + entry.getValue().id().asLongText()); + } + } + + public static void removeByPileSn(String pileSn){ + manager.remove(pileSn); + } + +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileConnectorDataBaseStatusEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileConnectorDataBaseStatusEnum.java new file mode 100644 index 000000000..f0ca2dc0b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileConnectorDataBaseStatusEnum.java @@ -0,0 +1,48 @@ +package com.jsowell.common.enums.ykc; + +/** + * 鍏呯數鏋彛鏁版嵁搴撶姸鎬 + */ +public enum PileConnectorDataBaseStatusEnum { + + OFF_NETWORK("0", "绂荤嚎"), + FREE("1", "绌洪棽"), + OCCUPIED_NOT_CHARGED("2", "鍗犵敤锛堟湭鍏呯數锛"), + OCCUPIED_CHARGING("3", "鍗犵敤锛堝厖鐢典腑锛"), + OCCUPIED_APPOINTMENT_LOCK("4", "鍗犵敤锛堥绾﹂攣瀹氾級"), + FAULT("255", "鏁呴殰") + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + PileConnectorDataBaseStatusEnum(String value, String label) { + this.value = value; + this.label = label; + } + + public static String getStatusDescription(String value) { + for (PileConnectorDataBaseStatusEnum statusEnum : PileConnectorDataBaseStatusEnum.values()) { + if (statusEnum.getValue().equals(value)) { + return statusEnum.getLabel(); + } + } + return ""; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileConnectorStatusEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileConnectorStatusEnum.java new file mode 100644 index 000000000..e288acf69 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileConnectorStatusEnum.java @@ -0,0 +1,36 @@ +package com.jsowell.common.enums.ykc; + +/** + * 鍏呯數鎺ュ彛鐘舵 + * 妗╀紶杩囨潵鐨勬灙鍙g姸鎬侊細 0x00锛氱绾 0x01锛氭晠闅 0x02锛氱┖闂 0x03锛氬厖鐢 + */ +public enum PileConnectorStatusEnum { + OFF_NETWORK("00", "绂荤嚎"), + FAULT("01", "鏁呴殰"), + FREE("02", "绌洪棽"), + OCCUPIED_CHARGING("03", "鍏呯數"), + ; + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + PileConnectorStatusEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileStatusEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileStatusEnum.java new file mode 100644 index 000000000..b70bab00e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileStatusEnum.java @@ -0,0 +1,45 @@ +package com.jsowell.common.enums.ykc; + +/** + * 鍏呯數妗╃姸鎬乪num + */ +public enum PileStatusEnum { + UNKNOWN("0", "鏈煡"), + ON_LINE("1", "鍦ㄧ嚎"), + OFF_LINE("2","绂荤嚎"), + FAULT("3", "鏁呴殰"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + PileStatusEnum(String value, String label) { + this.value = value; + this.label = label; + } + + public static String getStatusDescription(String status) { + for (PileStatusEnum pileStatusEnum : PileStatusEnum.values()) { + if (pileStatusEnum.getValue().equals(status)) { + return pileStatusEnum.getLabel(); + } + } + return ""; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ReturnCodeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ReturnCodeEnum.java new file mode 100644 index 000000000..1ef1b7c3f --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ReturnCodeEnum.java @@ -0,0 +1,138 @@ +package com.jsowell.common.enums.ykc; + +public enum ReturnCodeEnum { + /** + * 鎴愬姛 + */ + CODE_SUCCESS("00100000", "鎿嶄綔鎴愬姛"), + + CODE_TOKEN_ERROR("00100002", "韬唤楠岃瘉澶辫触锛岃閲嶆柊鐧诲綍"), + + CODE_PARAM_NOT_NULL_ERROR("00100003", "鍙傛暟涓嶈兘涓虹┖"), + + CODE_VERIFICATION_CODE_ERROR("00100004", "楠岃瘉鐮侀敊璇"), + + CODE_VERIFICATION_CODE_TIMEOUT_ERROR("00100005", "楠岃瘉鐮佽秴鏃"), + + CODE_SEND_SMS_ERROR("00100006", "鍙戦佺煭淇¢獙璇佺爜閿欒"), + + CODE_MEMBER_REGISTER_AND_LOGIN_ERROR("00100007", "浼氬憳鐧诲綍娉ㄥ唽鎺ュ彛寮傚父"), + + CODE_WECHAT_LOGIN_ERROR("00100008", "寰俊鐧诲綍寮傚父"), + + CODE_GET_MEMBER_PHONE_NUMBER_ERROR("00100009", "鑾峰彇鐢ㄦ埛鎵嬫満鍙峰紓甯"), + + CODE_HANDLE_USER_INFO_ERROR("00100010", "澶勭悊鐢ㄦ埛淇℃伅寮傚父"), + + CODE_GET_PILE_STATION_INFO_ERROR("00100011", "鏌ヨ鍏呯數绔欎俊鎭垪琛ㄥ紓甯"), + + CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR("00100012", "閫氳繃绔欑偣id鏌ヨ鍏呯數鏋彛鍒楄〃寮傚父"), + + CODE_PILE_CONNECTOR_STATUS_ERROR("00100013", "璇ユ灙鍙g姸鎬佷笉姝g‘"), + + CODE_GENERATE_ORDER_ERROR("00100014", "鐢熸垚璁㈠崟澶辫触"), + + CODE_CONNECTOR_INFO_NULL_ERROR("00100015", "鍏呯數鏋彛涓虹┖"), + + CODE_BILLING_TEMPLATE_NULL_ERROR("00100016", "鏌ヨ鍏呯數妗╃殑璁¤垂妯℃澘涓虹┖"), + + CODE_DATA_LENGTH_ERROR("00100017", "鏁版嵁闀垮害涓嶆纭"), + + CODE_SETTLE_ORDER_ERROR("00100018", "璁㈠崟缁撶畻寮傚父"), + + CODE_ORDER_INFO_ERROR("00100019", "璁㈠崟淇℃伅鏈夎"), + + CODE_QUERY_ORDER_NULL_ERROR("00100020", "鏌ヨ璁㈠崟涓虹┖"), + + CODE_ORDER_PILE_MAPPING_ERROR("00100021", "璁㈠崟涓庡綋鍓嶆々涓嶅尮閰"), + + CODE_GET_MEMBER_ACCOUNT_AMOUNT_ERROR("00100022", "鏌ヨ鐢ㄦ埛璐︽埛鎬讳綑棰濆紓甯"), + + CODE_BALANCE_IS_INSUFFICIENT("00100023", "璐︽埛浣欓涓嶈冻"), + + CODE_GET_MOBILE_NUMBER_BY_CODE_ERROR("00100024", "鑾峰彇寰俊鐧诲綍鎵嬫満鍙峰け璐"), + + CODE_GET_MERCHANT_ID_BY_APP_ID_ERROR("00100024", "鑾峰彇鍟嗘埛id澶辫触"), + + CODE_GET_ORDER_INFO_BY_MEMBER_ID_ERROR("00100025", "閫氳繃浼氬憳Id鏌ヨ鏌愮姸鎬佽鍗曞け璐"), + + CODE_GET_OPEN_ID_BY_CODE_ERROR("00100026", "鑾峰彇openid澶辫触"), + + CODE_GET_WECHAT_PAY_PARAMETER_ERROR("00100027", "鑾峰彇寰俊鏀粯鍙傛暟澶辫触"), + + CODE_GET_BALANCE_CHANGES_ERROR("00100028", "鏌ヨ鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅寮傚父"), + + CODE_ORDER_PAY_ERROR("00100029", "璁㈠崟鏀粯澶辫触"), + + CODE_ORDER_PAY_CALLBACK_ERROR("00100030", "鏀粯鍥炶皟澶辫触"), + + CODE_ORDER_IS_NOT_TO_BE_PAID_ERROR("00100031", "璁㈠崟涓嶆槸寰呮敮浠樼姸鎬"), + + CODE_ORDER_MEMBER_NOT_MATCH_ERROR("00100032", "璁㈠崟涓庝細鍛樹俊鎭笉鍖归厤"), + + CODE_STOP_CHARGING_ERROR("00100033", "鍋滄鍏呯數澶辫触"), + + CODE_ORDER_IS_NOT_STAY_SETTLEMENT_ERROR("00100034", "璁㈠崟涓嶆槸寰呯粨绠楃姸鎬"), + + CODE_GET_PILE_DETAIL_ERROR("00100035", "鏌ヨ鍏呯數妗╄鎯呭け璐"), + + CODE_WEIXIN_REFUND_ERROR("00100036", "寰俊閫娆炬帴鍙eけ璐"), + + CODE_REFUND_ORDER_AMOUNT_ERROR("00100037", "璁㈠崟閫娆鹃噾棰濅笉鑳藉ぇ浜庡彲閫閲戦"), + + CODE_REFUND_ORDER_CALLBACK_RECORD_ERROR("00100038", "璁㈠崟閫娆惧鐞嗛昏緫, 鏌ヨ璁㈠崟寰俊鏀粯璁板綍涓虹┖!"), + + CODE_SELECT_MEMBER_NULL_ERROR("00100039", "娌℃湁鏌ヨ鍒颁細鍛樹俊鎭"), + + CODE_REFUND_MEMBER_BALANCE_ERROR("00100040", "閫娆鹃噾棰濅笉鑳藉ぇ浜庢湰閲戦噾棰"), + + CODE_GET_ORDER_DETAIL_ERROR("00100041", "灏忕▼搴忚幏鍙栬鍗曡鎯呭け璐"), + + CODE_SELECT_PILE_STARTER_STATUS("00100042", "鏍规嵁璁㈠崟鍙锋煡璇㈠厖鐢垫々鍚姩鐘舵佸け璐"), + + CODE_PILE_HAS_BEEN_BINDING_ERROR("00400001", "姝ゆ々宸茶缁戝畾锛岃鑱旂郴绠$悊鍛橈紒"), + + CODE_AUTHENTICATION_ERROR("00400002", "鎮ㄧ殑韬唤淇℃伅楠岃瘉鏈夎锛岃閲嶈瘯锛"), + + CODE_USER_IS_NOT_REGISTER("00400003", "姝ょ敤鎴锋湭娉ㄥ唽骞冲彴璐﹀彿锛岃鏍稿疄韬唤锛"), + + CODE_USER_HAS_BEEN_THIS_PILE("00400004", "姝ょ敤鎴峰凡缁戝畾璇ユ々锛岃妫鏌ワ紒"), + + CODE_NO_CHARGING_ORDER_ERROR("00400005", "褰撳墠鏃犳鍦ㄥ厖鐢电殑璁㈠崟"), + + CODE_NO_REAL_TIME_INFO("00400006", "鏈煡鍒板厖鐢垫灙鍙e疄鏃朵俊鎭"), + + CODE_BINDING_PERSONAL_PILE_ERROR("00400007", "鑾峰彇涓汉妗╂灙鍙e疄鏃舵暟鎹紓甯"), + + CODE_ADMIN_ISSUE_ERROR("00400008", "妗╃鐞嗗憳涓嬪彂涓汉妗╁紓甯"), + + CODE_GET_PERSONAL_PILE_BY_MEMBER_ID_ERROR("00400009", "閫氳繃memberId鏌ヤ釜浜烘々鍒楄〃寮傚父"), + + CODE_GET_PERSONAL_PILE_CONNECTOR_INFO_ERROR("00400010", "鑾峰彇涓汉妗╂灙鍙e疄鏃舵暟鎹紓甯"), + ; + + private String value; + + private String label; + + private ReturnCodeEnum(String value, String label) { + this.value = value; + this.label = label; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ScenarioEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ScenarioEnum.java new file mode 100644 index 000000000..9d7dfe828 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ScenarioEnum.java @@ -0,0 +1,35 @@ +package com.jsowell.common.enums.ykc; + +/** + * 鏀粯鍦烘櫙鏋氫妇 + */ +public enum ScenarioEnum { + ORDER("order", "鏀粯璁㈠崟"), + + BALANCE("balance", "鏀粯浣欓"), + ; + + private String value; + private String label; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + ScenarioEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/StopChargingFailedReasonEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/StopChargingFailedReasonEnum.java new file mode 100644 index 000000000..81f94e6da --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/StopChargingFailedReasonEnum.java @@ -0,0 +1,55 @@ +package com.jsowell.common.enums.ykc; + +/** + * 杩滅▼鍋滄鍏呯數澶辫触鍘熷洜enum + * + * @author JS-ZZA + * @date 2022/11/16 8:31 + */ +public enum StopChargingFailedReasonEnum { + NULL("00", "鏃"), + EQUIPMENT_CODE_NOT_MATCH("01", "璁惧缂栧彿涓嶅尮閰"), + CONNECTOR_NOT_IN_CHARGING("02", "鏋湭澶勪簬鍏呯數鐘舵"), + OTHER("03","鍏朵粬"), + + + ; + private String code; + private String msg; + + StopChargingFailedReasonEnum(String code, String msg) { + this.code = code; + this.msg = msg; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + /** + * 鏍规嵁code鑾峰彇msg + * @param code + * @return + */ + public static String getMsgByCode(String code) { + for (StopChargingFailedReasonEnum item : StopChargingFailedReasonEnum.values()) { + if (item.getCode().equals(code)) { + return item.getMsg(); + } + } + return null; + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/YKCChargingStopReasonEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/YKCChargingStopReasonEnum.java new file mode 100644 index 000000000..c9a0f2e29 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/YKCChargingStopReasonEnum.java @@ -0,0 +1,167 @@ +package com.jsowell.common.enums.ykc; + +import com.jsowell.common.util.BytesUtil; + +/** + * 浜戝揩鍏呭厖鐢靛仠姝㈠師鍥爀num + * + * @author JS-ZZA + * @date 2022/11/4 16:46 + */ +public enum YKCChargingStopReasonEnum { + /** + * 鍏呯數瀹屾垚 + */ + APP_REMOTE_STOP(0x40, "缁撴潫鍏呯數锛孉PP杩滅▼鍋滄"), + SOC_FULL(0x41, "缁撴潫鍏呯數锛孲OC 杈惧埌 100%"), + CHARGING_ELECTRICITY_ELIGIBLE(0x42, "缁撴潫鍏呯數锛屽厖鐢电數閲忔弧瓒宠瀹氭潯浠"), + CHARGING_AMOUNT_ELIGIBLE(0x43, "缁撴潫鍏呯數锛屽厖鐢甸噾棰濇弧瓒宠瀹氭潯浠"), + CHARGING_TIME_ELIGIBLE(0x44, "缁撴潫鍏呯數锛屽厖鐢垫椂闂存弧瓒宠瀹氭潯浠"), + MANUALLY_STOP_CHARGING(0x45, "缁撴潫鍏呯數锛屾墜鍔ㄥ仠姝㈠厖鐢"), + + OTHER_FORTY_SIX(0x46, "鍏朵粬鏂瑰紡锛堥鐣欙級"), + OTHER_FORTY_SEVEN(0x47, "鍏朵粬鏂瑰紡锛堥鐣欙級"), + OTHER_FORTY_EIGHT(0x48, "鍏朵粬鏂瑰紡锛堥鐣欙級"), + OTHER_FORTY_NINE(0x49, "鍏朵粬鏂瑰紡锛堥鐣欙級"), + + /** + * 鍏呯數鍚姩澶辫触 + */ + PILE_CONTROL_SYSTEM_FAULT(0x4A, "鍏呯數鍚姩澶辫触锛屽厖鐢垫々鎺у埗绯荤粺鏁呴殰(闇瑕侀噸鍚垨鑷姩鎭㈠)"), + CONTROL_GUIDANCE_BREAK(0x4B, "鍏呯數鍚姩澶辫触锛屾帶鍒跺寮曟柇寮"), + CIRCUIT_BREAKER_TRIP(0x4C, "鍏呯數鍚姩澶辫触锛屾柇璺櫒璺充綅"), + AMMETER_COMMUNICATION_BREAK(0x4D, "鍏呯數鍚姩澶辫触锛岀數琛ㄩ氫俊涓柇"), + LACK_OF_BALANCE(0x4E, "鍏呯數鍚姩澶辫触锛屼綑棰濅笉瓒"), + CHARGING_MODEL_FAULT(0x4F, "鍏呯數鍚姩澶辫触锛屽厖鐢垫ā鍧楁晠闅"), + EMERGENCY_STOP_FAULT(0x50, "鍏呯數鍚姩澶辫触锛屾ュ仠寮鍏"), + SPD_ABNORMAL(0x51, "鍏呯數鍚姩澶辫触锛岄槻闆峰櫒寮傚父"), + BMS_UNREADY(0x52, "鍏呯數鍚姩澶辫触锛 BMS 鏈氨缁"), + TEMPERATURE_ABNORMAL(0x53, "鍏呯數鍚姩澶辫触锛屾俯搴﹀紓甯"), + BATTERY_REVERSE_CONNECT_FAULT(0x54, "鍏呯數鍚姩澶辫触锛岀數姹犲弽鎺ユ晠闅"), + ELECTRICITY_LOCK_FAULT(0x55, "鍏呯數鍚姩澶辫触锛岀數瀛愰攣寮傚父"), + FAIL_CLOSE_ACT(0x56, "鍏呯數鍚姩澶辫触锛屽悎闂稿け璐"), + INSULATION_FAULT(0x57, "鍏呯數鍚姩澶辫触锛岀粷缂樺紓甯"), + RESERVED_FIFTY_EIGHT(0x58, "棰勭暀"), + RECEIVED_BMS_HANDSHAKE_REPORT_TIMEOUT(0x59, "鍏呯數鍚姩澶辫触锛屾帴鏀 BMS 鎻℃墜鎶ユ枃 BHM 瓒呮椂"), + RECEIVED_BMS_AND_CAR_IDENTIFY_REPORT_TIMEOUT(0x5A, "鍏呯數鍚姩澶辫触锛屾帴鏀 BMS 鍜岃溅杈嗙殑杈ㄨ瘑鎶ユ枃瓒呮椂 BRM"), + RECEIVED_BATTERY_CHARGING_DATA_TIMEOUT(0x5B, "鍏呯數鍚姩澶辫触锛屾帴鏀剁數姹犲厖鐢靛弬鏁版姤鏂囪秴鏃 BCP"), + RECEIVED_CHARGING_COMPLETE_REPORT_TIMEOUT(0x5C, "鍏呯數鍚姩澶辫触锛屾帴鏀 BMS 瀹屾垚鍏呯數鍑嗗鎶ユ枃瓒呮椂 BRO AA"), + RECEIVED_CHARGING_STATUS_REPORT_TIMEOUT(0x5D, "鍏呯數鍚姩澶辫触锛屾帴鏀剁數姹犲厖鐢垫荤姸鎬佹姤鏂囪秴鏃 BCS"), + RECEIVED_CHARGING_REQUEST_REPORT_TIMEOUT(0x5E, "鍏呯數鍚姩澶辫触锛屾帴鏀剁數姹犲厖鐢佃姹傛姤鏂囪秴鏃 BCL"), + RECEIVED_BATTERY_STATUS_TIMEOUT(0x5F, "鍏呯數鍚姩澶辫触锛屾帴鏀剁數姹犵姸鎬佷俊鎭姤鏂囪秴鏃 BSM"), + GB_2015_PROHIBIT_CHARGING_AT_BHM(0x60, "鍏呯數鍚姩澶辫触锛 GB2015 鐢垫睜鍦 BHM 闃舵鏈夌數鍘嬩笉鍏佽鍏呯數"), + GB_2015_BATTERY_VOLTAGE_GAP(0x61, "鍏呯數鍚姩澶辫触锛 GB2015 杈ㄨ瘑闃舵鍦 BRO_AA 鏃跺欑數姹犲疄闄呯數鍘 涓 BCP 鎶ユ枃鐢垫睜鐢靛帇宸窛澶т簬 5%"), + B_2015_CHARGER_BRO_AA_TO_BRO_OO(0x62, "鍏呯數鍚姩澶辫触锛 B2015 鍏呯數鏈哄湪棰勫厖鐢甸樁娈典粠 BRO_AA 鍙樻垚 BRO_00 鐘舵"), + RECEIVED_HOST_CONFIG_REPORT_TIMEOUT(0x63, "鍏呯數鍚姩澶辫触锛屾帴鏀朵富鏈洪厤缃姤鏂囪秴鏃"), + CHARGER_UNREADY(0x64, "鍏呯數鍚姩澶辫触锛屽厖鐢垫満鏈噯澶囧氨缁,鎴戜滑娌℃湁鍥 CRO AA锛屽搴 鑰佸浗鏍"), + + OTHER_SIXTY_FIVE(0x65, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_SIXTY_SIX(0x66, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_SIXTY_SEVEN(0x67, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_SIXTY_EIGHT(0x68, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_SIXTY_NINE(0x69, "锛堝叾浠栧師鍥狅級棰勭暀"), + + /** + * 鍏呯數寮傚父涓 + */ + SYSTEM_CLOSE_LOCK(0x6A, "鍏呯數寮傚父涓锛岀郴缁熼棴閿"), + GUIDANCE_BREAK(0x6B, "鍏呯數寮傚父涓锛屽寮曟柇寮"), + BREAKER_TRIP(0x6C, "鍏呯數寮傚父涓锛屾柇璺櫒璺充綅"), + AMMETER_COMMUNICATION_INTERRUPT(0x6D, "鍏呯數寮傚父涓锛岀數琛ㄩ氫俊涓柇"), + NOT_SUFFICIENT_FUNDS(0x6E, "鍏呯數寮傚父涓锛屼綑棰濅笉瓒"), + AC_PROTECT_ACTION(0x6F, "鍏呯數寮傚父涓锛屼氦娴佷繚鎶ゅ姩浣"), + DC_PROTECT_ACTION(0x70, "鍏呯數寮傚父涓锛岀洿娴佷繚鎶ゅ姩浣"), + CHARGE_MODEL_UNUSUAL(0x71, "鍏呯數寮傚父涓锛屽厖鐢垫ā鍧楁晠闅"), + FETCH_UP_UNUSUAL(0x72, "鍏呯數寮傚父涓锛屾ュ仠寮鍏"), + SPD_UNUSUAL(0x73, "鍏呯數寮傚父涓锛岄槻闆峰櫒寮傚父"), + TEMPERATURE_UNUSUAL(0x74, "鍏呯數寮傚父涓锛屾俯搴﹀紓甯"), + OUTPUT_UNUSUAL(0x75, "鍏呯數寮傚父涓锛岃緭鍑哄紓甯"), + CHARGING_NO_CURRENT(0x76, "鍏呯數寮傚父涓锛屽厖鐢垫棤娴"), + ELECTRICITY_LOCK_UNUSUAL(0x77, "鍏呯數寮傚父涓锛岀數瀛愰攣寮傚父"), + + OTHER_SEVENTY_EIGHT(0x78, "棰勭暀"), + + TOTAL_CHARGING_VOLTAGE_UNUSUAL(0x79, "鍏呯數寮傚父涓锛屾诲厖鐢电數鍘嬪紓甯"), + TOTAL_CHARGING_CURRENT_UNUSUAL(0x7A, "鍏呯數寮傚父涓锛屾诲厖鐢电數娴佸紓甯"), + SINGLE_CHARGING_VOLTAGE_UNUSUAL(0x7B, "鍏呯數寮傚父涓锛屽崟浣撳厖鐢电數鍘嬪紓甯"), + BATTERY_TEMPERATURE_TOO_HIGH(0x7C, "鍏呯數寮傚父涓锛岀數姹犵粍杩囨俯"), + HIGHEST_SINGLE_CHARGING_VOLTAGE_UNUSUAL(0x7D, "鍏呯數寮傚父涓锛屾渶楂樺崟浣撳厖鐢电數鍘嬪紓甯"), + HIGHEST_BATTERY_TEMPERATURE_TOO_HIGH(0x7E, "鍏呯數寮傚父涓锛屾渶楂樼數姹犵粍杩囨俯"), + BMV_SINGLE_CHARGING_VOLTAGE_UNUSUAL(0x7F, "鍏呯數寮傚父涓锛 BMV 鍗曚綋鍏呯數鐢靛帇寮傚父"), + BMT_BATTERY_TEMPERATURE_TOO_HIGH(0x80, "鍏呯數寮傚父涓锛 BMT 鐢垫睜缁勮繃娓"), + BATTERY_STATUS_UNUSUAL_STOP_CHARGING(0x81, "鍏呯數寮傚父涓锛岀數姹犵姸鎬佸紓甯稿仠姝㈠厖鐢"), + CAR_SEND_REPORT_FORBID_CHARGING(0x82, "鍏呯數寮傚父涓锛岃溅杈嗗彂鎶ユ枃绂佹鍏呯數"), + CHARGING_PILE_OUTAGE(0x83, "鍏呯數寮傚父涓锛屽厖鐢垫々鏂數"), + RECEIVED_BATTERY_CHARGING_STATUS_TIMEOUT(0x84, "鍏呯數寮傚父涓锛屾帴鏀剁數姹犲厖鐢垫荤姸鎬佹姤鏂囪秴鏃"), + RECEIVED_BATTERY_CHARGING_REQUEST_TIMEOUT(0x85, "鍏呯數寮傚父涓锛屾帴鏀剁數姹犲厖鐢佃姹傛姤鏂囪秴鏃"), + RECEIVED_BATTERY_STATUS_DATA_TIMEOUT(0x86, "鍏呯數寮傚父涓锛屾帴鏀剁數姹犵姸鎬佷俊鎭姤鏂囪秴鏃"), + RECEIVED_BMS_STOP_CHARGING_TIMEOUT(0x87, "鍏呯數寮傚父涓锛屾帴鏀 BMS 涓鍏呯數鎶ユ枃瓒呮椂"), + RECEIVED_BMS_CHARGING_STATISTICAL_TIMEOUT(0x88, "鍏呯數寮傚父涓锛屾帴鏀 BMS 鍏呯數缁熻鎶ユ枃瓒呮椂"), + RECEIVED_CCS_TIMEOUT(0x89, "鍏呯數寮傚父涓锛屾帴鏀跺渚 CCS 鎶ユ枃瓒呮椂"), + + OTHER_EIGHTY_A(0x8A, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_EIGHTY_B(0x8B, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_EIGHTY_C(0x8C, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_EIGHTY_D(0x8D, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_EIGHTY_E(0x8E, "锛堝叾浠栧師鍥狅級棰勭暀"), + OTHER_EIGHTY_F(0x8F, "锛堝叾浠栧師鍥狅級棰勭暀"), + + + /** + * 鏈煡鍘熷洜鍋滄 + */ + UNKNOWN_REASON_STOP_CHARGING(0x90, "鏈煡鍘熷洜鍋滄"), + + ; + + + + private int code; + private String msg; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + YKCChargingStopReasonEnum(int code, String msg) { + this.code = code; + this.msg = msg; + } + + /** + * 鏍规嵁code鑾峰彇鍋滄鍘熷洜鎻忚堪 + * + * @param code 缂栫爜 + * @return 鍋滄鍘熷洜鎻忚堪 + */ + public static String getMsgByCode(int code) { + for (YKCChargingStopReasonEnum item : YKCChargingStopReasonEnum.values()) { + if (item.getCode() == code) { + return item.getMsg(); + } + } + return null; + } + + public static void main(String[] args) { + String stopReason = "6B"; + byte[] stopReasonByteArr = new byte[]{0x6B}; + String s = BytesUtil.bin2HexStr(stopReasonByteArr); + + int i = Integer.parseInt(stopReason, 16); + String stopReasonMsg = YKCChargingStopReasonEnum.getMsgByCode(i); + System.out.println(stopReasonMsg); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/YKCPileFaultReasonEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/YKCPileFaultReasonEnum.java new file mode 100644 index 000000000..1799716e9 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/YKCPileFaultReasonEnum.java @@ -0,0 +1,64 @@ +package com.jsowell.common.enums.ykc; + +/** + * 鍏呯數妗╂晠闅滃師鍥爀num + * + * @author JS-ZZA + * @date 2022/10/17 9:03 + */ +public enum YKCPileFaultReasonEnum { + + STOP_BUTTON_FAULT(1, "鎬ュ仠鎸夐挳鍔ㄤ綔鏁呴殰"), + NO_CAN_USE_RECTIFICATION_MODEL_FAULT(2, "鏃犲彲鐢ㄦ暣娴佹ā鍧"), + OUTLET_TEMPERATURE_TOO_HIGH_FAULT(3, "鍑洪鍙f俯搴﹁繃楂"), + ALTERNATING_LIGHTING_PROTECTION_FAULT(4, "浜ゆ祦闃查浄鏁呴殰"), + DC20_COMMUNICATION_INTERRUPT_FAULT(5, "浜ょ洿娴佹ā鍧 DC20 閫氫俊涓柇"), + FC08_COMMUNICATION_INTERRUPT_FAULT(6, "浜ょ洿娴佹ā鍧 FC08 閫氫俊涓柇"), + WATT_HOUR_METER_COMMUNICATION_INTERRUPT_FAULT(7, "鐢靛害琛ㄩ氫俊涓柇"), + CARD_READER_COMMUNICATION_INTERRUPT_FAULT(8, "璇诲崱鍣ㄩ氫俊涓柇"), + RC10_COMMUNICATION_INTERRUPT_FAULT(9, "RC10 閫氫俊涓柇"), + FAN_SPEED_CONTROL_FAULT(10, "椋庢墖璋冮熸澘鏁呴殰"), + DC_FUSE_FAULT(11, "鐩存祦鐔旀柇鍣ㄦ晠闅"), + HIGH_PRESSURE_CONTACTOR_FAULT(12, "楂樺帇鎺ヨЕ鍣ㄦ晠闅"), + DOOR_OPEN_FAULT(13, "闂ㄦ墦寮"), + ; + + /** + * 鏍规嵁code鑾峰彇鏁呴殰鎻忚堪 + * + * @param code 鏁呴殰缂栫爜 + * @return 鏁呴殰鎻忚堪 + */ + public static String getValueByCode(int code) { + for (YKCPileFaultReasonEnum item : YKCPileFaultReasonEnum.values()) { + if (item.getCode() == code) { + return item.getValue(); + } + } + return null; + } + + private int code; + private String value; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + YKCPileFaultReasonEnum(int code, String value) { + this.code = code; + this.value = value; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/BusinessException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/BusinessException.java new file mode 100644 index 000000000..e55b9cdb0 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/BusinessException.java @@ -0,0 +1,29 @@ +package com.jsowell.common.exception; + +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import lombok.Data; + +@Data +public class BusinessException extends RuntimeException{ + private static final long serialVersionUID = 1L; + + /** + * 閿欒鐮 + */ + private String code; + + /** + * 閿欒鎻愮ず + */ + private String message; + + public BusinessException(ReturnCodeEnum returnCodeEnum) { + this.code = returnCodeEnum.getValue(); + this.message = returnCodeEnum.getLabel(); + } + + public BusinessException(String code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/DemoModeException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/DemoModeException.java new file mode 100644 index 000000000..d1dfd53d9 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/DemoModeException.java @@ -0,0 +1,13 @@ +package com.jsowell.common.exception; + +/** + * 婕旂ず妯″紡寮傚父 + * + * @author jsowell + */ +public class DemoModeException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public DemoModeException() { + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/GlobalException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/GlobalException.java new file mode 100644 index 000000000..46b893228 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/GlobalException.java @@ -0,0 +1,51 @@ +package com.jsowell.common.exception; + +/** + * 鍏ㄥ眬寮傚父 + * + * @author jsowell + */ +public class GlobalException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * 閿欒鎻愮ず + */ + private String message; + + /** + * 閿欒鏄庣粏锛屽唴閮ㄨ皟璇曢敊璇 + *

+ * 鍜 {@link CommonResult#getDetailMessage()} 涓鑷寸殑璁捐 + */ + private String detailMessage; + + /** + * 绌烘瀯閫犳柟娉曪紝閬垮厤鍙嶅簭鍒楀寲闂 + */ + public GlobalException() { + } + + public GlobalException(String message) { + this.message = message; + } + + public String getDetailMessage() { + return detailMessage; + } + + public GlobalException setDetailMessage(String detailMessage) { + this.detailMessage = detailMessage; + return this; + } + + @Override + public String getMessage() { + return message; + } + + public GlobalException setMessage(String message) { + this.message = message; + return this; + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/ServiceException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/ServiceException.java new file mode 100644 index 000000000..153a48329 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/ServiceException.java @@ -0,0 +1,65 @@ +package com.jsowell.common.exception; + +/** + * 涓氬姟寮傚父 + * + * @author jsowell + */ +public final class ServiceException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * 閿欒鐮 + */ + private Integer code; + + /** + * 閿欒鎻愮ず + */ + private String message; + + /** + * 閿欒鏄庣粏锛屽唴閮ㄨ皟璇曢敊璇 + *

+ * 鍜 {@link CommonResult#getDetailMessage()} 涓鑷寸殑璁捐 + */ + private String detailMessage; + + /** + * 绌烘瀯閫犳柟娉曪紝閬垮厤鍙嶅簭鍒楀寲闂 + */ + public ServiceException() { + } + + public ServiceException(String message) { + this.message = message; + } + + public ServiceException(String message, Integer code) { + this.message = message; + this.code = code; + } + + public String getDetailMessage() { + return detailMessage; + } + + @Override + public String getMessage() { + return message; + } + + public Integer getCode() { + return code; + } + + public ServiceException setMessage(String message) { + this.message = message; + return this; + } + + public ServiceException setDetailMessage(String detailMessage) { + this.detailMessage = detailMessage; + return this; + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/UtilException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/UtilException.java new file mode 100644 index 000000000..fa48fb4e0 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/UtilException.java @@ -0,0 +1,22 @@ +package com.jsowell.common.exception; + +/** + * 宸ュ叿绫诲紓甯 + * + * @author jsowell + */ +public class UtilException extends RuntimeException { + private static final long serialVersionUID = 8247610319171014183L; + + public UtilException(Throwable e) { + super(e.getMessage(), e); + } + + public UtilException(String message) { + super(message); + } + + public UtilException(String message, Throwable throwable) { + super(message, throwable); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/base/BaseException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/base/BaseException.java new file mode 100644 index 000000000..2439e1af4 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/base/BaseException.java @@ -0,0 +1,84 @@ +package com.jsowell.common.exception.base; + +import com.jsowell.common.util.MessageUtils; +import com.jsowell.common.util.StringUtils; + +/** + * 鍩虹寮傚父 + * + * @author jsowell + */ +public class BaseException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * 鎵灞炴ā鍧 + */ + private String module; + + /** + * 閿欒鐮 + */ + private String code; + + /** + * 閿欒鐮佸搴旂殑鍙傛暟 + */ + private Object[] args; + + /** + * 閿欒娑堟伅 + */ + private String defaultMessage; + + public BaseException(String module, String code, Object[] args, String defaultMessage) { + this.module = module; + this.code = code; + this.args = args; + this.defaultMessage = defaultMessage; + } + + public BaseException(String module, String code, Object[] args) { + this(module, code, args, null); + } + + public BaseException(String module, String defaultMessage) { + this(module, null, null, defaultMessage); + } + + public BaseException(String code, Object[] args) { + this(null, code, args, null); + } + + public BaseException(String defaultMessage) { + this(null, null, null, defaultMessage); + } + + @Override + public String getMessage() { + String message = null; + if (!StringUtils.isEmpty(code)) { + message = MessageUtils.message(code, args); + } + if (message == null) { + message = defaultMessage; + } + return message; + } + + public String getModule() { + return module; + } + + public String getCode() { + return code; + } + + public Object[] getArgs() { + return args; + } + + public String getDefaultMessage() { + return defaultMessage; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileException.java new file mode 100644 index 000000000..582c71ead --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileException.java @@ -0,0 +1,17 @@ +package com.jsowell.common.exception.file; + +import com.jsowell.common.exception.base.BaseException; + +/** + * 鏂囦欢淇℃伅寮傚父绫 + * + * @author jsowell + */ +public class FileException extends BaseException { + private static final long serialVersionUID = 1L; + + public FileException(String code, Object[] args) { + super("file", code, args, null); + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileNameLengthLimitExceededException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileNameLengthLimitExceededException.java new file mode 100644 index 000000000..91ba7a2cb --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileNameLengthLimitExceededException.java @@ -0,0 +1,14 @@ +package com.jsowell.common.exception.file; + +/** + * 鏂囦欢鍚嶇О瓒呴暱闄愬埗寮傚父绫 + * + * @author jsowell + */ +public class FileNameLengthLimitExceededException extends FileException { + private static final long serialVersionUID = 1L; + + public FileNameLengthLimitExceededException(int defaultFileNameLength) { + super("upload.filename.exceed.length", new Object[]{defaultFileNameLength}); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileSizeLimitExceededException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileSizeLimitExceededException.java new file mode 100644 index 000000000..c9c89f761 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/file/FileSizeLimitExceededException.java @@ -0,0 +1,14 @@ +package com.jsowell.common.exception.file; + +/** + * 鏂囦欢鍚嶅ぇ灏忛檺鍒跺紓甯哥被 + * + * @author jsowell + */ +public class FileSizeLimitExceededException extends FileException { + private static final long serialVersionUID = 1L; + + public FileSizeLimitExceededException(long defaultMaxSize) { + super("upload.exceed.maxSize", new Object[]{defaultMaxSize}); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/file/InvalidExtensionException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/file/InvalidExtensionException.java new file mode 100644 index 000000000..51a9b0aa8 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/file/InvalidExtensionException.java @@ -0,0 +1,69 @@ +package com.jsowell.common.exception.file; + +import org.apache.commons.fileupload.FileUploadException; + +import java.util.Arrays; + +/** + * 鏂囦欢涓婁紶 璇紓甯哥被 + * + * @author jsowell + */ +public class InvalidExtensionException extends FileUploadException { + private static final long serialVersionUID = 1L; + + private String[] allowedExtension; + private String extension; + private String filename; + + public InvalidExtensionException(String[] allowedExtension, String extension, String filename) { + super("鏂囦欢[" + filename + "]鍚庣紑[" + extension + "]涓嶆纭紝璇蜂笂浼" + Arrays.toString(allowedExtension) + "鏍煎紡"); + this.allowedExtension = allowedExtension; + this.extension = extension; + this.filename = filename; + } + + public String[] getAllowedExtension() { + return allowedExtension; + } + + public String getExtension() { + return extension; + } + + public String getFilename() { + return filename; + } + + public static class InvalidImageExtensionException extends InvalidExtensionException { + private static final long serialVersionUID = 1L; + + public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename) { + super(allowedExtension, extension, filename); + } + } + + public static class InvalidFlashExtensionException extends InvalidExtensionException { + private static final long serialVersionUID = 1L; + + public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename) { + super(allowedExtension, extension, filename); + } + } + + public static class InvalidMediaExtensionException extends InvalidExtensionException { + private static final long serialVersionUID = 1L; + + public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename) { + super(allowedExtension, extension, filename); + } + } + + public static class InvalidVideoExtensionException extends InvalidExtensionException { + private static final long serialVersionUID = 1L; + + public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename) { + super(allowedExtension, extension, filename); + } + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/job/TaskException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/job/TaskException.java new file mode 100644 index 000000000..8bf5a49af --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/job/TaskException.java @@ -0,0 +1,29 @@ +package com.jsowell.common.exception.job; + +/** + * 璁″垝绛栫暐寮傚父 + * + * @author jsowell + */ +public class TaskException extends Exception { + private static final long serialVersionUID = 1L; + + private Code code; + + public TaskException(String msg, Code code) { + this(msg, code, null); + } + + public TaskException(String msg, Code code, Exception nestedEx) { + super(msg, nestedEx); + this.code = code; + } + + public Code getCode() { + return code; + } + + public enum Code { + TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/user/CaptchaException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/user/CaptchaException.java new file mode 100644 index 000000000..e8e411616 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/user/CaptchaException.java @@ -0,0 +1,14 @@ +package com.jsowell.common.exception.user; + +/** + * 楠岃瘉鐮侀敊璇紓甯哥被 + * + * @author jsowell + */ +public class CaptchaException extends UserException { + private static final long serialVersionUID = 1L; + + public CaptchaException() { + super("user.jcaptcha.error", null); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/user/CaptchaExpireException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/user/CaptchaExpireException.java new file mode 100644 index 000000000..7cfcd66a0 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/user/CaptchaExpireException.java @@ -0,0 +1,14 @@ +package com.jsowell.common.exception.user; + +/** + * 楠岃瘉鐮佸け鏁堝紓甯哥被 + * + * @author jsowell + */ +public class CaptchaExpireException extends UserException { + private static final long serialVersionUID = 1L; + + public CaptchaExpireException() { + super("user.jcaptcha.expire", null); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserException.java new file mode 100644 index 000000000..807c84575 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserException.java @@ -0,0 +1,16 @@ +package com.jsowell.common.exception.user; + +import com.jsowell.common.exception.base.BaseException; + +/** + * 鐢ㄦ埛淇℃伅寮傚父绫 + * + * @author jsowell + */ +public class UserException extends BaseException { + private static final long serialVersionUID = 1L; + + public UserException(String code, Object[] args) { + super("user", code, args, null); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserPasswordNotMatchException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserPasswordNotMatchException.java new file mode 100644 index 000000000..001ad00e2 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserPasswordNotMatchException.java @@ -0,0 +1,14 @@ +package com.jsowell.common.exception.user; + +/** + * 鐢ㄦ埛瀵嗙爜涓嶆纭垨涓嶇鍚堣鑼冨紓甯哥被 + * + * @author jsowell + */ +public class UserPasswordNotMatchException extends UserException { + private static final long serialVersionUID = 1L; + + public UserPasswordNotMatchException() { + super("user.password.not.match", null); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserPasswordRetryLimitExceedException.java b/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserPasswordRetryLimitExceedException.java new file mode 100644 index 000000000..6d117c8df --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/exception/user/UserPasswordRetryLimitExceedException.java @@ -0,0 +1,14 @@ +package com.jsowell.common.exception.user; + +/** + * 鐢ㄦ埛閿欒鏈澶ф鏁板紓甯哥被 + * + * @author jsowell + */ +public class UserPasswordRetryLimitExceedException extends UserException { + private static final long serialVersionUID = 1L; + + public UserPasswordRetryLimitExceedException(int retryLimitCount, int lockTime) { + super("user.password.retry.limit.exceed", new Object[]{retryLimitCount, lockTime}); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/filter/PropertyPreExcludeFilter.java b/jsowell-common/src/main/java/com/jsowell/common/filter/PropertyPreExcludeFilter.java new file mode 100644 index 000000000..f17fdcc3f --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/filter/PropertyPreExcludeFilter.java @@ -0,0 +1,20 @@ +package com.jsowell.common.filter; + +import com.alibaba.fastjson2.filter.SimplePropertyPreFilter; + +/** + * 鎺掗櫎JSON鏁忔劅灞炴 + * + * @author jsowell + */ +public class PropertyPreExcludeFilter extends SimplePropertyPreFilter { + public PropertyPreExcludeFilter() { + } + + public PropertyPreExcludeFilter addExcludes(String... filters) { + for (int i = 0; i < filters.length; i++) { + this.getExcludes().add(filters[i]); + } + return this; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/filter/RepeatableFilter.java b/jsowell-common/src/main/java/com/jsowell/common/filter/RepeatableFilter.java new file mode 100644 index 000000000..ae154f099 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/filter/RepeatableFilter.java @@ -0,0 +1,40 @@ +package com.jsowell.common.filter; + +import com.jsowell.common.util.StringUtils; +import org.springframework.http.MediaType; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +/** + * Repeatable 杩囨护鍣 + * + * @author jsowell + */ +public class RepeatableFilter implements Filter { + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + ServletRequest requestWrapper = null; + if (request instanceof HttpServletRequest + && StringUtils.startsWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE)) { + requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); + } + if (null == requestWrapper) { + chain.doFilter(request, response); + } else { + chain.doFilter(requestWrapper, response); + } + } + + @Override + public void destroy() { + + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/filter/RepeatedlyRequestWrapper.java b/jsowell-common/src/main/java/com/jsowell/common/filter/RepeatedlyRequestWrapper.java new file mode 100644 index 000000000..921793758 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/filter/RepeatedlyRequestWrapper.java @@ -0,0 +1,67 @@ +package com.jsowell.common.filter; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.util.http.HttpHelper; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * 鏋勫缓鍙噸澶嶈鍙杋nputStream鐨剅equest + * + * @author jsowell + */ +public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper { + private final byte[] body; + + public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException { + super(request); + request.setCharacterEncoding(Constants.UTF8); + response.setCharacterEncoding(Constants.UTF8); + + body = HttpHelper.getBodyString(request).getBytes(Constants.UTF8); + } + + @Override + public BufferedReader getReader() throws IOException { + return new BufferedReader(new InputStreamReader(getInputStream())); + } + + @Override + public ServletInputStream getInputStream() throws IOException { + final ByteArrayInputStream bais = new ByteArrayInputStream(body); + return new ServletInputStream() { + @Override + public int read() throws IOException { + return bais.read(); + } + + @Override + public int available() throws IOException { + return body.length; + } + + @Override + public boolean isFinished() { + return false; + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setReadListener(ReadListener readListener) { + + } + }; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/filter/XssFilter.java b/jsowell-common/src/main/java/com/jsowell/common/filter/XssFilter.java new file mode 100644 index 000000000..5a364c0aa --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/filter/XssFilter.java @@ -0,0 +1,62 @@ +package com.jsowell.common.filter; + +import com.jsowell.common.enums.HttpMethod; +import com.jsowell.common.util.StringUtils; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * 闃叉XSS鏀诲嚮鐨勮繃婊ゅ櫒 + * + * @author jsowell + */ +public class XssFilter implements Filter { + /** + * 鎺掗櫎閾炬帴 + */ + public List excludes = new ArrayList<>(); + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + String tempExcludes = filterConfig.getInitParameter("excludes"); + if (StringUtils.isNotEmpty(tempExcludes)) { + String[] url = tempExcludes.split(","); + for (int i = 0; url != null && i < url.length; i++) { + excludes.add(url[i]); + } + } + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + HttpServletRequest req = (HttpServletRequest) request; + HttpServletResponse resp = (HttpServletResponse) response; + if (handleExcludeURL(req, resp)) { + chain.doFilter(request, response); + return; + } + XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request); + chain.doFilter(xssRequest, response); + } + + private boolean handleExcludeURL(HttpServletRequest request, HttpServletResponse response) { + String url = request.getServletPath(); + String method = request.getMethod(); + // GET DELETE 涓嶈繃婊 + if (method == null || HttpMethod.GET.matches(method) || HttpMethod.DELETE.matches(method)) { + return true; + } + return StringUtils.matches(url, excludes); + } + + @Override + public void destroy() { + + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/filter/XssHttpServletRequestWrapper.java b/jsowell-common/src/main/java/com/jsowell/common/filter/XssHttpServletRequestWrapper.java new file mode 100644 index 000000000..de20af9bd --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/filter/XssHttpServletRequestWrapper.java @@ -0,0 +1,97 @@ +package com.jsowell.common.filter; + +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.html.EscapeUtil; +import org.apache.commons.io.IOUtils; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +/** + * XSS杩囨护澶勭悊 + * + * @author jsowell + */ +public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { + /** + * @param request + */ + public XssHttpServletRequestWrapper(HttpServletRequest request) { + super(request); + } + + @Override + public String[] getParameterValues(String name) { + String[] values = super.getParameterValues(name); + if (values != null) { + int length = values.length; + String[] escapseValues = new String[length]; + for (int i = 0; i < length; i++) { + // 闃瞲ss鏀诲嚮鍜岃繃婊ゅ墠鍚庣┖鏍 + escapseValues[i] = EscapeUtil.clean(values[i]).trim(); + } + return escapseValues; + } + return super.getParameterValues(name); + } + + @Override + public ServletInputStream getInputStream() throws IOException { + // 闈瀓son绫诲瀷锛岀洿鎺ヨ繑鍥 + if (!isJsonRequest()) { + return super.getInputStream(); + } + + // 涓虹┖锛岀洿鎺ヨ繑鍥 + String json = IOUtils.toString(super.getInputStream(), "utf-8"); + if (StringUtils.isEmpty(json)) { + return super.getInputStream(); + } + + // xss杩囨护 + json = EscapeUtil.clean(json).trim(); + byte[] jsonBytes = json.getBytes("utf-8"); + final ByteArrayInputStream bis = new ByteArrayInputStream(jsonBytes); + return new ServletInputStream() { + @Override + public boolean isFinished() { + return true; + } + + @Override + public boolean isReady() { + return true; + } + + @Override + public int available() throws IOException { + return jsonBytes.length; + } + + @Override + public void setReadListener(ReadListener readListener) { + } + + @Override + public int read() throws IOException { + return bis.read(); + } + }; + } + + /** + * 鏄惁鏄疛son璇锋眰 + * + * @param request + */ + public boolean isJsonRequest() { + String header = super.getHeader(HttpHeaders.CONTENT_TYPE); + return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/response/RestApiResponse.java b/jsowell-common/src/main/java/com/jsowell/common/response/RestApiResponse.java new file mode 100644 index 000000000..7ec0312f8 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/response/RestApiResponse.java @@ -0,0 +1,43 @@ +package com.jsowell.common.response; + +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import lombok.Data; + +@Data +public class RestApiResponse { + /** + * 杩斿洖鐮 + */ + private String resCode; + + /** + * 淇℃伅 + */ + private String msg; + + /** + * 鏁版嵁 + */ + private T obj; + + public RestApiResponse() { + this.resCode = ReturnCodeEnum.CODE_SUCCESS.getValue(); + this.msg = ReturnCodeEnum.CODE_SUCCESS.getLabel(); + } + + public RestApiResponse(T t) { + this.resCode = ReturnCodeEnum.CODE_SUCCESS.getValue(); + this.msg = ReturnCodeEnum.CODE_SUCCESS.getLabel(); + this.obj = t; + } + + public RestApiResponse(String resCode, String msg) { + this.resCode = resCode; + this.msg = msg; + } + + public RestApiResponse(ReturnCodeEnum returnCodeEnum) { + this.resCode = returnCodeEnum.getValue(); + this.msg = returnCodeEnum.getLabel(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/AESUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/AESUtil.java new file mode 100644 index 000000000..29892f7d6 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/AESUtil.java @@ -0,0 +1,176 @@ +package com.jsowell.common.util; + +import org.apache.commons.lang3.RandomStringUtils; +import sun.misc.BASE64Decoder; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.security.NoSuchAlgorithmException; + +/** + * Copyright (c) 2019-present ShenBao + * + * @author ShenBao + * @homepage https://github.com/ShenBao/rsa-aes-utils + */ +public class AESUtil { + /** + * 闅忔満鐢熸垚绉橀挜 + * + * @return String + */ + public static String createAesKey() { + try { + KeyGenerator kg = KeyGenerator.getInstance("AES"); + kg.init(128); + //瑕佺敓鎴愬灏戜綅锛屽彧闇瑕佷慨鏀硅繖閲屽嵆鍙 128, 192 鎴 256 + SecretKey sk = kg.generateKey(); + byte[] b = sk.getEncoded(); + String k = byteToHexString(b); + return k; + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return null; + } + } + + /** + * 闅忔満鐢熸垚 IV + * + * @return String + */ + public static String createAesIv() { + String iv = RandomStringUtils.randomAlphanumeric(16); + return iv.toLowerCase(); + } + + /** + * byte 鏁扮粍杞寲涓 16 杩涘埗瀛楃涓 + * + * @param bytes + * @return String + */ + public static String byteToHexString(byte[] bytes) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < bytes.length; i++) { + String strHex = Integer.toHexString(bytes[i]); + if (strHex.length() > 3) { + sb.append(strHex.substring(6)); + } else { + if (strHex.length() < 2) { + sb.append("0" + strHex); + } else { + sb.append(strHex); + } + } + } + return sb.toString(); + } + + /** + * 鍔犲瘑 CBC + * + * @param data String + * @param key String + * @param iv String + * @return String + */ + public static String encryptByCBC(String data, String key, String iv) throws Exception { + try { + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); + int blockSize = cipher.getBlockSize(); + byte[] dataBytes = data.getBytes(); + int plaintextLength = dataBytes.length; + if (plaintextLength % blockSize != 0) { + plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize)); + } + byte[] plaintext = new byte[plaintextLength]; + System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length); + SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); + IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes()); + cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec); + byte[] encrypted = cipher.doFinal(plaintext); + return new sun.misc.BASE64Encoder().encode(encrypted); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 瑙e瘑 CBC + * + * @param data String + * @param key String + * @param iv String + * @return String + */ + public static String decryptByCBC(String data, String key, String iv) throws Exception { + try { + byte[] encrypted1 = new BASE64Decoder().decodeBuffer(data); + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); + SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); + IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes()); + cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec); + byte[] original = cipher.doFinal(encrypted1); + String originalString = new String(original); + return originalString.trim(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 鍔犲瘑 ECB + * + * @param data String + * @param key String + * @return String + */ + public static String encryptByECB(String data, String key) throws Exception { + try { + Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding"); + int blockSize = cipher.getBlockSize(); + byte[] dataBytes = data.getBytes(); + int plaintextLength = dataBytes.length; + if (plaintextLength % blockSize != 0) { + plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize)); + } + byte[] plaintext = new byte[plaintextLength]; + System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length); + SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); + cipher.init(Cipher.ENCRYPT_MODE, keyspec); + byte[] encrypted = cipher.doFinal(plaintext); + return new sun.misc.BASE64Encoder().encode(encrypted); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 瑙e瘑 ECB + * + * @param data String + * @param key String + * @return String + */ + public static String decryptByECB(String data, String key) throws Exception { + try { + byte[] encrypted1 = new BASE64Decoder().decodeBuffer(data); + Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding"); + SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); + cipher.init(Cipher.DECRYPT_MODE, keyspec); + byte[] original = cipher.doFinal(encrypted1); + String originalString = new String(original); + return originalString.trim(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/Arith.java b/jsowell-common/src/main/java/com/jsowell/common/util/Arith.java new file mode 100644 index 000000000..4620d447a --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/Arith.java @@ -0,0 +1,113 @@ +package com.jsowell.common.util; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +/** + * 绮剧‘鐨勬诞鐐规暟杩愮畻 + * + * @author jsowell + */ +public class Arith { + + /** + * 榛樿闄ゆ硶杩愮畻绮惧害 + */ + private static final int DEF_DIV_SCALE = 10; + + /** + * 杩欎釜绫讳笉鑳藉疄渚嬪寲 + */ + private Arith() { + } + + /** + * 鎻愪緵绮剧‘鐨勫姞娉曡繍绠椼 + * + * @param v1 琚姞鏁 + * @param v2 鍔犳暟 + * @return 涓や釜鍙傛暟鐨勫拰 + */ + public static double add(double v1, double v2) { + BigDecimal b1 = new BigDecimal(Double.toString(v1)); + BigDecimal b2 = new BigDecimal(Double.toString(v2)); + return b1.add(b2).doubleValue(); + } + + /** + * 鎻愪緵绮剧‘鐨勫噺娉曡繍绠椼 + * + * @param v1 琚噺鏁 + * @param v2 鍑忔暟 + * @return 涓や釜鍙傛暟鐨勫樊 + */ + public static double sub(double v1, double v2) { + BigDecimal b1 = new BigDecimal(Double.toString(v1)); + BigDecimal b2 = new BigDecimal(Double.toString(v2)); + return b1.subtract(b2).doubleValue(); + } + + /** + * 鎻愪緵绮剧‘鐨勪箻娉曡繍绠椼 + * + * @param v1 琚箻鏁 + * @param v2 涔樻暟 + * @return 涓や釜鍙傛暟鐨勭Н + */ + public static double mul(double v1, double v2) { + BigDecimal b1 = new BigDecimal(Double.toString(v1)); + BigDecimal b2 = new BigDecimal(Double.toString(v2)); + return b1.multiply(b2).doubleValue(); + } + + /** + * 鎻愪緵锛堢浉瀵癸級绮剧‘鐨勯櫎娉曡繍绠楋紝褰撳彂鐢熼櫎涓嶅敖鐨勬儏鍐垫椂锛岀簿纭埌 + * 灏忔暟鐐逛互鍚10浣嶏紝浠ュ悗鐨勬暟瀛楀洓鑸嶄簲鍏ャ + * + * @param v1 琚櫎鏁 + * @param v2 闄ゆ暟 + * @return 涓や釜鍙傛暟鐨勫晢 + */ + public static double div(double v1, double v2) { + return div(v1, v2, DEF_DIV_SCALE); + } + + /** + * 鎻愪緵锛堢浉瀵癸級绮剧‘鐨勯櫎娉曡繍绠椼傚綋鍙戠敓闄や笉灏界殑鎯呭喌鏃讹紝鐢眘cale鍙傛暟鎸 + * 瀹氱簿搴︼紝浠ュ悗鐨勬暟瀛楀洓鑸嶄簲鍏ャ + * + * @param v1 琚櫎鏁 + * @param v2 闄ゆ暟 + * @param scale 琛ㄧず琛ㄧず闇瑕佺簿纭埌灏忔暟鐐逛互鍚庡嚑浣嶃 + * @return 涓や釜鍙傛暟鐨勫晢 + */ + public static double div(double v1, double v2, int scale) { + if (scale < 0) { + throw new IllegalArgumentException( + "The scale must be a positive integer or zero"); + } + BigDecimal b1 = new BigDecimal(Double.toString(v1)); + BigDecimal b2 = new BigDecimal(Double.toString(v2)); + if (b1.compareTo(BigDecimal.ZERO) == 0) { + return BigDecimal.ZERO.doubleValue(); + } + return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue(); + } + + /** + * 鎻愪緵绮剧‘鐨勫皬鏁颁綅鍥涜垗浜斿叆澶勭悊銆 + * + * @param v 闇瑕佸洓鑸嶄簲鍏ョ殑鏁板瓧 + * @param scale 灏忔暟鐐瑰悗淇濈暀鍑犱綅 + * @return 鍥涜垗浜斿叆鍚庣殑缁撴灉 + */ + public static double round(double v, int scale) { + if (scale < 0) { + throw new IllegalArgumentException( + "The scale must be a positive integer or zero"); + } + BigDecimal b = new BigDecimal(Double.toString(v)); + BigDecimal one = BigDecimal.ONE; + return b.divide(one, scale, RoundingMode.HALF_UP).doubleValue(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/BytesUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/BytesUtil.java new file mode 100644 index 000000000..ce07711cd --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/BytesUtil.java @@ -0,0 +1,706 @@ +package com.jsowell.common.util; + +import com.google.common.primitives.Bytes; + +import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.Stack; + +public class BytesUtil { + + static final long fx = 0xffl; + + /** + * 灏唅nt鏁板艰浆鎹负鍗犱袱涓瓧鑺傜殑byte鏁扮粍锛屾湰鏂规硶閫傜敤浜(楂樹綅鍦ㄥ墠锛屼綆浣嶅湪鍚)鐨勯『搴忋 + */ + public static byte[] intToBytes(int value) { + //limit 浼犲叆2 + return intToBytes(value, 2); + } + + public static byte[] intToBytes(int value, int limit) { + byte[] src = new byte[limit]; + for (int i = 0; i < limit; i++) { + int x = 8 * (limit - i - 1); + if (x == 0) { + src[i] = (byte) (value & 0xFF); + } else { + src[i] = (byte) ((value >> x) & 0xFF); + } + } + return src; + } + + public static int bytesToInt(byte[] src) { + return bytesToInt(src, 0); + } + + /** + * byte鏁扮粍涓彇int鏁板硷紝鏈柟娉曢傜敤浜(浣庝綅鍦ㄥ悗锛岄珮浣嶅湪鍓)鐨勯『搴忋 + */ + public static int bytesToInt(byte[] src, int offset) { + if (src == null) { + return 0; + } + while (src.length > 0 && src[0] == 0x00) { + src = BytesUtil.copyBytes(src, 1, src.length - 1); + } + if (src.length == 0) { + return 0; + } + int len = src.length; + if (len == 0) { + return 0; + } + int value = 0; + for (int i = 0; i < len; i++) { + if (i == (len - 1)) { + value = value | ((src[i] & 0xFF)); + } + value = value | ((src[i] & 0xFF) << (8 * (len - i - 1))); + } + return value; + } + + /** + * long杞瓧鑺傦紝澶х妯″紡 + * + * @param number + * @return + */ + public static byte[] long2Byte(long number) { + long temp = number; + byte[] b = new byte[8]; + for (int i = (b.length - 1); i >= 0; i--) { + b[i] = new Long(temp & 0xff).byteValue();// + //灏嗘渶浣庝綅淇濆瓨鍦ㄦ渶浣庝綅 + temp = temp >> 8;// 鍚戝彸绉8浣 + } + return b; + } + + /** + * 瀛楄妭杞琹ong 澶х妯″紡 + * + * @param b + * @return + */ + public static long byte2Long(byte[] b) { + long s = 0; + long s0 = b[7] & 0xff; + long s1 = b[6] & 0xff; + long s2 = b[5] & 0xff; + long s3 = b[4] & 0xff; + long s4 = b[3] & 0xff; + long s5 = b[2] & 0xff; + long s6 = b[1] & 0xff; + long s7 = b[0] & 0xff; + + // s0涓嶅彉 + s1 <<= 8; + s2 <<= 16; + s3 <<= 24; + s4 <<= 8 * 4; + s5 <<= 8 * 5; + s6 <<= 8 * 6; + s7 <<= 8 * 7; + s = s0 | s1 | s2 | s3 | s4 | s5 | s6 | s7; + return s; + } + + /** + * 浠庝竴涓猙yte鏁扮粍涓嫹璐濅竴閮ㄥ垎鍑烘潵 + * + * @param oriBytes + * @param startIndex + * @param length + * @return + */ + public static byte[] copyBytes(byte[] oriBytes, int startIndex, int length) { + int endIndex = startIndex + length; + byte[] bts = new byte[length]; + int index = 0; + for (int i = 0; i < oriBytes.length; i++) { + if (i >= startIndex && i < endIndex) { + bts[index] = oriBytes[i]; + index++; + } + } + return bts; + } + + /** + * 灏哹yte[]杞负鍚勭杩涘埗鐨勫瓧绗︿覆 + * + * @param bytes byte[] + * @param radix 鍩烘暟鍙互杞崲杩涘埗鐨勮寖鍥达紝浠嶤haracter.MIN_RADIX鍒癈haracter.MAX_RADIX锛岃秴鍑鸿寖鍥村悗鍙樹负10杩涘埗 + * @return 杞崲鍚庣殑瀛楃涓 + */ + public static String binary(byte[] bytes, int radix) { + return new BigInteger(1, bytes).toString(radix);// 杩欓噷鐨1浠h〃姝f暟 + } + + /** + * @鍑芥暟鍔熻兘: BCD鐮佽浆涓10杩涘埗涓(闃挎媺浼暟鎹) + * @杈撳叆鍙傛暟: BCD鐮 + * @杈撳嚭缁撴灉: 10杩涘埗涓 + */ + public static String bcd2Str(byte[] bytes) { + StringBuffer temp = new StringBuffer(bytes.length * 2); + for (int i = 0; i < bytes.length; i++) { + temp.append((byte) ((bytes[i] & 0xf0) >>> 4)); + temp.append((byte) (bytes[i] & 0x0f)); + } + return temp.toString(); + } + + public static String bcd2StrContainA(byte[] bytes) { + char temp[] = new char[bytes.length * 2], val; + for (int i = 0; i < bytes.length; i++) { + val = (char) (((bytes[i] & 0xf0) >> 4) & 0x0f); + temp[i * 2] = (char) (val > 9 ? val + 'A' - 10 : val + '0'); + val = (char) (bytes[i] & 0x0f); + temp[i * 2 + 1] = (char) (val > 9 ? val + 'A' - 10 : val + '0'); + } + return new String(temp); + } + + /** + * @鍑芥暟鍔熻兘: BCD鐮佽浆涓10杩涘埗涓(闃挎媺浼暟鎹) 灏忕妯″紡 + * @杈撳叆鍙傛暟: BCD鐮 + * @杈撳嚭缁撴灉: 10杩涘埗涓 + */ + public static String bcd2StrLittle(byte[] bytes) { + Stack strings = new Stack<>(); + String temp = bcd2Str(bytes); + for (int i = 0; i < temp.length(); i = i + 2) { + strings.push(temp.substring(i, i + 2)); + } + StringBuilder stringBuilder = new StringBuilder(); + while (!strings.isEmpty()) { + stringBuilder.append(strings.pop()); + } + return stringBuilder.toString(); + } + + /** + * @鍑芥暟鍔熻兘: BCD鐮佽浆涓10杩涘埗涓(闃挎媺浼暟鎹) 灏忕妯″紡 + * @杈撳叆鍙傛暟: BCD鐮 + * @杈撳嚭缁撴灉: 10杩涘埗涓 + */ + public static String bcd2StrLittleContainA(byte[] bytes) { + Stack strings = new Stack<>(); + String temp = bcd2StrContainA(bytes); + for (int i = 0; i < temp.length(); i = i + 2) { + strings.push(temp.substring(i, i + 2)); + } + StringBuilder stringBuilder = new StringBuilder(); + while (!strings.isEmpty()) { + stringBuilder.append(strings.pop()); + } + return stringBuilder.toString(); + } + + /** + * @鍑芥暟鍔熻兘: 10杩涘埗涓茶浆涓築CD鐮 + * @杈撳叆鍙傛暟: 10杩涘埗涓 + * @杈撳嚭缁撴灉: BCD鐮 + */ + public static byte[] str2Bcd(String asc) { + if (asc == null) { + asc = ""; + } + int len = asc.length(); + int mod = len % 2; + if (mod != 0) { + asc = "0" + asc; + len = asc.length(); + } + byte abt[] = new byte[len]; + if (len >= 2) { + len = len / 2; + } + byte bbt[] = new byte[len]; + abt = asc.getBytes(); + int j, k; + for (int p = 0; p < asc.length() / 2; p++) { + if ((abt[2 * p] >= '0') && (abt[2 * p] <= '9')) { + j = abt[2 * p] - '0'; + } else if ((abt[2 * p] >= 'a') && (abt[2 * p] <= 'z')) { + j = abt[2 * p] - 'a' + 0x0a; + } else { + j = abt[2 * p] - 'A' + 0x0a; + } + if ((abt[2 * p + 1] >= '0') && (abt[2 * p + 1] <= '9')) { + k = abt[2 * p + 1] - '0'; + } else if ((abt[2 * p + 1] >= 'a') && (abt[2 * p + 1] <= 'z')) { + k = abt[2 * p + 1] - 'a' + 0x0a; + } else { + k = abt[2 * p + 1] - 'A' + 0x0a; + } + int a = (j << 4) + k; + byte b = (byte) a; + bbt[p] = b; + } + return bbt; + } + + /** + * @鍑芥暟鍔熻兘: 10杩涘埗涓茶浆涓築CD鐮 + * @杈撳叆鍙傛暟: 10杩涘埗涓 + * @杈撳嚭缁撴灉: BCD鐮 + */ + public static byte[] str2BcdLittle(String asc) { + byte[] temp = str2Bcd(asc); + return revert(temp); + } + + /** + * 灏唅nt杞负byte 灏忕妯″紡 + * + * @param value int鍊 + * @return + */ + public static byte[] intToBytesLittle(int value) { + //limit 浼犲叆2 + return intToBytes(value, 2); + } + + /** + * 灏唅nt杞崲byte 灏忕妯″紡 + * + * @param value int鍊 + * @param limit 淇濈暀闀垮害 + * @return + */ + public static byte[] intToBytesLittle(int value, int limit) { + byte[] src = new byte[limit]; + for (int i = 0; i < limit; i++) { + int x = 8 * i; + if (x == 0) { + src[i] = (byte) (value & 0xFF); + } else { + src[i] = (byte) ((value >> x) & 0xFF); + } + } + return src; + } + + /** + * byte鏁扮粍涓彇int鏁板硷紝鏈柟娉曢傜敤浜(浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚 )鐨勯『搴忋傚皬绔ā寮 + */ + public static int bytesToIntLittle(byte[] src) { + if (src == null) { + return 0; + } + int len = src.length; + if (len == 0) { + return 0; + } + int value = 0; + for (int i = 0; i < len; i++) { + value = value | ((src[i] & 0xFF) << (8 * i)); + } + return value; + } + + /** + * long杞瓧鑺傦紝灏忕妯″紡 + * + * @param number + * @param limit 淇濈暀瀛楄妭浣 + * @return + */ + public static byte[] long2ByteLittle(long number, int limit) { + long temp = number; + byte[] b = new byte[limit]; + for (int i = 0; i < b.length; i++) { + b[i] = new Long(temp & 0xff).byteValue();// + //灏嗘渶浣庝綅淇濆瓨鍦ㄦ渶鍓嶉潰 + temp = temp >> 8;// 鍚戝彸绉8浣 + } + return b; + } + + + /** + * 瀛楄妭杞琹ong 灏忕妯″紡 + * + * @param src + * @return + */ + public static long byte2LongLittle(byte[] src) { + long s = 0; + for (int i = 0; i < src.length; i++) { + //闃叉杞负int + long si = src[i] & 0xFF; + si = si << (8 * i); + s = s | si; + } + return s; + } + + /** + * 浣跨敤瀛楄妭鏁扮粍鏇挎崲鐩爣鏁扮粍浠庢寚瀹氫綅缃紑濮嬫浛鎹㈠瓧鑺 + * + * @param target 琚浛鎹㈢殑鏁扮粍 + * @param startIndex 寮濮嬩綅缃 + * @param replace 鐢ㄤ簬鏇挎崲鐨勬暟缁 + */ + public static void replaceBytes(byte[] target, int startIndex, byte[] replace) { + // 鏆傛椂鐢卞鐣屼繚璇佷笉浼氬嚭鏁扮粍瓒婄晫鐨勫紓甯 + for (int i = 0; i < replace.length; i++) { + int targetIndex = startIndex + i; + target[targetIndex] = replace[i]; + } + } + + /** + * 鍒涘缓鏁扮粍 + * + * @param bytes 鐢ㄤ簬鏇挎崲鐨勬暟缁 + */ + public static byte[] createByteArray(byte... bytes) { + byte[] temp = new byte[bytes.length]; + for (int i = 0; i < bytes.length; i++) { + temp[i] = bytes[i]; + } + return temp; + } + + public static byte[] rightPadBytes(byte[] target, int len, byte b) { + int length = target.length; + if (len <= length) { + return target; + } + int addedLen = len - length; + byte[] added = new byte[addedLen]; + for (int i = 0; i < addedLen; i++) { + added[i] = b; + } + return Bytes.concat(target, added); + } + + public static byte[] rightPadBytes(String targetStr, int len, byte b) { + if (targetStr == null) { + targetStr = ""; + } + byte[] target = targetStr.getBytes(); + return rightPadBytes(target, len, b); + } + + public static String ascii2StrLittle(byte[] ascs) { + byte[] data = revert(ascs); + String asciiStr = null; + try { + asciiStr = new String(data, "ISO8859-1"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return asciiStr; + } + + public static String ascii2Str(byte[] ascs) { + byte[] data = ascs; + String asciiStr = null; + try { + asciiStr = new String(data, "ISO8859-1"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return asciiStr; + } + + public static byte[] str2AscLittle(String str) { + return revert(str2Asc(str)); + } + + public static byte[] str2Asc(String str) { + byte[] bytes = null; + try { + bytes = str.getBytes("ISO8859-1"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return bytes; + } + + /** + * 鍙嶈浆byte鏁扮粍 + * + * @param temp + * @return + */ + public static byte[] revert(byte[] temp) { + byte[] ret = new byte[temp.length]; + for (int i = 0; i < temp.length; i++) { + ret[temp.length - i - 1] = temp[i]; + } + return ret; + } + + /** + * cp56time2a 鏍煎紡杞琩ate鏍煎紡 + */ + public static Date byteCp2Date(byte[] bytes) { + if (bytes == null || bytes.length != 7) { + return null; + } + int ms = bytesToIntLittle(copyBytes(bytes, 0, 2)); + int min = bytesToIntLittle(copyBytes(bytes, 2, 1)); + int hour = bytesToIntLittle(copyBytes(bytes, 3, 1)); + int day = bytesToIntLittle(copyBytes(bytes, 4, 1)); + int month = bytesToIntLittle(copyBytes(bytes, 5, 1)); + int year = bytesToIntLittle(copyBytes(bytes, 6, 1)); + if (month == 0 || day == 0 || year == 0) { + return null; + } + LocalDateTime localDateTime = LocalDateTime.of(year + 2000, month, day, hour, min, ms / 1000); + Date date = DateUtils.localDateTime2Date(localDateTime); + return date; + } + + private static String hexStr = "0123456789ABCDEF"; + private static String[] binaryArray = { + "0000", "0001", "0010", "0011", + "0100", "0101", "0110", "0111", + "1000", "1001", "1010", "1011", + "1100", "1101", "1110", "1111" + }; + + /** + * @param bArray + * @return 浜岃繘鍒舵暟缁勮浆鎹负浜岃繘鍒跺瓧绗︿覆 2-2 + */ + public static String bytes2BinStr(byte[] bArray) { + String outStr = ""; + int pos = 0; + for (byte b : bArray) { + //楂樺洓浣 + pos = (b & 0xF0) >> 4; + outStr += binaryArray[pos]; + //浣庡洓浣 + pos = b & 0x0F; + outStr += binaryArray[pos]; + } + return outStr; + } + + /** + * @param bytes + * @return 灏嗕簩杩涘埗鏁扮粍杞崲涓哄崄鍏繘鍒跺瓧绗︿覆 2-16 + */ + public static String bin2HexStr(byte[] bytes) { + String result = ""; + String hex = ""; + for (byte aByte : bytes) { + //瀛楄妭楂4浣 + hex = String.valueOf(hexStr.charAt((aByte & 0xF0) >> 4)); + //瀛楄妭浣4浣 + hex += String.valueOf(hexStr.charAt(aByte & 0x0F)); + result += hex; //+" " + } + return result; + } + + public static void main(String[] args) { + // byte[] a = new byte[] {0x0C, 0x00, 0x00, 0x00, 0x02, 0x20, 0x22, 0x12, 0x14, 0x00, 0x00, 0x01, 0x00}; + // byte[] bytes = intToBytes(CRC16Util.calcCrc16(a)); + // String binary = binary(bytes, 16); + // System.out.println(binary); + + // String a = "10"; + // byte[] bytes = bigDecimal2Bcd(new BigDecimal(a)); + // + // System.out.println(bytes); + + // byte[] startTimeByteArr = new byte[] {(byte) 0x98, (byte) 0xB7, 0x0E, 0x11, 0x10, 0x03, 0x14}; + // String binary = binary(startTimeByteArr, 16); + // String s = DateUtils.decodeCP56Time2a(binary); + // System.out.println(s); + + BigDecimal chargeAmount = new BigDecimal("10.5").setScale(2, BigDecimal.ROUND_HALF_UP); + byte[] accountBalanceByteArr = BytesUtil.getFloatBytes(chargeAmount.floatValue()); + + float aFloat = BytesUtil.getFloat(accountBalanceByteArr); + + System.out.println(aFloat); + + } + + /** + * @param hexString + * @return 灏嗗崄鍏繘鍒惰浆鎹负浜岃繘鍒跺瓧鑺傛暟缁 16-2 + */ + public static byte[] hexStr2BinArr(String hexString) { + //hexString鐨勯暱搴﹀2鍙栨暣锛屼綔涓篵ytes鐨勯暱搴 + int len = hexString.length() / 2; + byte[] bytes = new byte[len]; + byte high = 0;//瀛楄妭楂樺洓浣 + byte low = 0;//瀛楄妭浣庡洓浣 + for (int i = 0; i < len; i++) { + //鍙崇Щ鍥涗綅寰楀埌楂樹綅 + high = (byte) ((hexStr.indexOf(hexString.charAt(2 * i))) << 4); + low = (byte) hexStr.indexOf(hexString.charAt(2 * i + 1)); + bytes[i] = (byte) (high | low);//楂樺湴浣嶅仛鎴栬繍绠 + } + return bytes; + } + + /** + * @param src 16杩涘埗瀛楃涓 + * @return 瀛楄妭鏁扮粍 + * @Title hexString2Bytes + * @Description 16杩涘埗瀛楃涓茶浆瀛楄妭鏁扮粍 + */ + public static byte[] hexString2Bytes(String src) { + int l = src.length() / 2; + byte[] ret = new byte[l]; + for (int i = 0; i < l; i++) { + ret[i] = (byte) Integer.valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue(); + } + return ret; + } + + /** + * @param hexString + * @return 灏嗗崄鍏繘鍒惰浆鎹负浜岃繘鍒跺瓧绗︿覆 16-2 + */ + public static String hexStr2BinStr(String hexString) { + return bytes2BinStr(hexStr2BinArr(hexString)); + } + + /** + * 鏍¢獙鏁版嵁闀垮害鏄惁杈惧埌瑕佹眰,濡傛灉澶熼暱锛屽氨鐩存帴杩斿洖锛屽鏋滀笉澶燂紝鍒欏湪鏁版嵁 鍚庤ˉ0 鐩磋嚦鍒拌揪璇ラ暱搴 + * + * @param msg byte绫诲瀷鏁扮粍 + * @parm length 闇瑕佹楠岀殑鏁版嵁闀垮害锛堜负瀹為檯瀛楄妭鏁帮級 + */ + public static byte[] checkLengthAndBehindAppendZero(byte[] msg, int length) { + String s = BytesUtil.binary(msg, 16); + int msgLen = msg.length; + if (msgLen < length) { + while (msgLen < length) { + StringBuffer sb = new StringBuffer(); + // 鍚庤ˉ闆 + sb.append(s).append("0"); + s = sb.toString(); + msgLen = s.length(); + } + } else { + return msg; + } + return BytesUtil.str2Bcd(s); + } + + /** + * 鏍¢獙鏁版嵁闀垮害鏄惁杈惧埌瑕佹眰,濡傛灉澶熼暱锛屽氨鐩存帴杩斿洖锛屽鏋滀笉澶燂紝鍒欏湪鏁版嵁 鍓嶈ˉ0 鐩磋嚦鍒拌揪璇ラ暱搴 + * + * @param msg byte绫诲瀷鏁扮粍 + * @parm length 闇瑕佹楠岀殑鏁版嵁闀垮害锛堜负瀹為檯瀛楄妭鏁帮級 + */ + public static byte[] checkLengthAndFrontAppendZero(byte[] msg, int length) { + String s = BytesUtil.binary(msg, 16); + int msgLen = msg.length; + if (msgLen < length) { + while (msgLen < length) { + StringBuffer sb = new StringBuffer(); + // 鍓嶈ˉ闆 + sb.append("0").append(s); + s = sb.toString(); + msgLen = s.length(); + } + } else { + return msg; + } + return BytesUtil.str2Bcd(s); + } + + /** + * 灏嗛噾棰濊浆鎹㈡垚BCD鏁扮粍 + * + * @param bigDecimal + * @return + */ + public static byte[] bigDecimal2Bcd(BigDecimal bigDecimal) { + int i = Float.floatToIntBits(bigDecimal.floatValue()); + String hexString = Integer.toHexString(i); + return hexString2Bytes(hexString); + + } + + /** + * int 杞 byte[] + * 灏忕 + * + * @param data + * @return + */ + public static byte[] getIntBytes(int data) { + int length = 4; + byte[] bytes = new byte[length]; + for (int i = 0; i < length; i++) { + bytes[i] = (byte) ((data >> (i * 8)) & fx); + } + return bytes; + } + + /** + * float 杞 byte[] + * 灏忕 + * + * @param data + * @return + */ + public static byte[] getFloatBytes(float data) { + int intBits = Float.floatToIntBits(data); + + byte[] bytes = getIntBytes(intBits); + + return bytes; + } + + /** + * byte[] 杞 int + * + * @param bytes + * @return + */ + public static int getInt(byte[] bytes) { + int result = (int) ((fx & bytes[0]) + | ((fx & bytes[1]) << 8) + | ((fx & bytes[2]) << 16) + | ((fx & bytes[3]) << 24)); + + return result; + } + + /** + * byte[] 杞 float + * + * @param b + * @return + */ + public static float getFloat(byte[] b) { + int l = getInt(b); + return Float.intBitsToFloat(l); + } + + /** + * 灏哠tring杞崲涓篵yte[] + * + * @param s String + * @return byte[] + */ + public static byte[] hexStringToByteArray(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); + } + return data; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/CRC16Util.java b/jsowell-common/src/main/java/com/jsowell/common/util/CRC16Util.java new file mode 100644 index 000000000..c9f3d820b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/CRC16Util.java @@ -0,0 +1,235 @@ +package com.jsowell.common.util; + +import com.google.common.primitives.Bytes; + +/** + * CRC16鐩稿叧璁$畻 + *

+ * encode: utf-8 + */ +public class CRC16Util { + + private static byte[] crc16_tab_h = { + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, + (byte) 0x01, (byte) 0xc0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xc1, (byte) 0x81, (byte) 0x40 + + }; + + private static byte[] crc16_tab_l = { + 0x00, (byte) 0xc0, (byte) 0xc1, (byte) 0x01, (byte) 0xc3, (byte) 0x03, (byte) 0x02, (byte) 0xc2, (byte) 0xc6, (byte) 0x06, (byte) + 0x07, (byte) 0xc7, (byte) 0x05, (byte) 0xc5, (byte) 0xc4, (byte) 0x04, (byte) 0xcc, (byte) 0x0c, (byte) 0x0d, (byte) 0xcd, (byte) + 0x0f, (byte) 0xcf, (byte) 0xce, (byte) 0x0e, (byte) 0x0a, (byte) 0xca, (byte) 0xcb, (byte) 0x0b, (byte) 0xc9, (byte) 0x09, (byte) + 0x08, (byte) 0xc8, (byte) 0xd8, (byte) 0x18, (byte) 0x19, (byte) 0xd9, (byte) 0x1b, (byte) 0xdb, (byte) 0xda, (byte) 0x1a, (byte) + 0x1e, (byte) 0xde, (byte) 0xdf, (byte) 0x1f, (byte) 0xdd, (byte) 0x1d, (byte) 0x1c, (byte) 0xdc, (byte) 0x14, (byte) 0xd4, (byte) + 0xd5, (byte) 0x15, (byte) 0xd7, (byte) 0x17, (byte) 0x16, (byte) 0xd6, (byte) 0xd2, (byte) 0x12, (byte) 0x13, (byte) 0xd3, (byte) + 0x11, (byte) 0xd1, (byte) 0xd0, (byte) 0x10, (byte) 0xf0, (byte) 0x30, (byte) 0x31, (byte) 0xf1, (byte) 0x33, (byte) 0xf3, (byte) + 0xf2, (byte) 0x32, (byte) 0x36, (byte) 0xf6, (byte) 0xf7, (byte) 0x37, (byte) 0xf5, (byte) 0x35, (byte) 0x34, (byte) 0xf4, (byte) + 0x3c, (byte) 0xfc, (byte) 0xfd, (byte) 0x3d, (byte) 0xff, (byte) 0x3f, (byte) 0x3e, (byte) 0xfe, (byte) 0xfa, (byte) 0x3a, (byte) + 0x3b, (byte) 0xfb, (byte) 0x39, (byte) 0xf9, (byte) 0xf8, (byte) 0x38, (byte) 0x28, (byte) 0xe8, (byte) 0xe9, (byte) 0x29, (byte) + 0xeb, (byte) 0x2b, (byte) 0x2a, (byte) 0xea, (byte) 0xee, (byte) 0x2e, (byte) 0x2f, (byte) 0xef, (byte) 0x2d, (byte) 0xed, (byte) + 0xec, (byte) 0x2c, (byte) 0xe4, (byte) 0x24, (byte) 0x25, (byte) 0xe5, (byte) 0x27, (byte) 0xe7, (byte) 0xe6, (byte) 0x26, (byte) + 0x22, (byte) 0xe2, (byte) 0xe3, (byte) 0x23, (byte) 0xe1, (byte) 0x21, (byte) 0x20, (byte) 0xe0, (byte) 0xa0, (byte) 0x60, (byte) + 0x61, (byte) 0xa1, (byte) 0x63, (byte) 0xa3, (byte) 0xa2, (byte) 0x62, (byte) 0x66, (byte) 0xa6, (byte) 0xa7, (byte) 0x67, (byte) + 0xa5, (byte) 0x65, (byte) 0x64, (byte) 0xa4, (byte) 0x6c, (byte) 0xac, (byte) 0xad, (byte) 0x6d, (byte) 0xaf, (byte) 0x6f, (byte) + 0x6e, (byte) 0xae, (byte) 0xaa, (byte) 0x6a, (byte) 0x6b, (byte) 0xab, (byte) 0x69, (byte) 0xa9, (byte) 0xa8, (byte) 0x68, (byte) + 0x78, (byte) 0xb8, (byte) 0xb9, (byte) 0x79, (byte) 0xbb, (byte) 0x7b, (byte) 0x7a, (byte) 0xba, (byte) 0xbe, (byte) 0x7e, (byte) + 0x7f, (byte) 0xbf, (byte) 0x7d, (byte) 0xbd, (byte) 0xbc, (byte) 0x7c, (byte) 0xb4, (byte) 0x74, (byte) 0x75, (byte) 0xb5, (byte) + 0x77, (byte) 0xb7, (byte) 0xb6, (byte) 0x76, (byte) 0x72, (byte) 0xb2, (byte) 0xb3, (byte) 0x73, (byte) 0xb1, (byte) 0x71, (byte) + 0x70, (byte) 0xb0, (byte) 0x50, (byte) 0x90, (byte) 0x91, (byte) 0x51, (byte) 0x93, (byte) 0x53, (byte) 0x52, (byte) 0x92, (byte) + 0x96, (byte) 0x56, (byte) 0x57, (byte) 0x97, (byte) 0x55, (byte) 0x95, (byte) 0x94, (byte) 0x54, (byte) 0x9c, (byte) 0x5c, (byte) + 0x5d, (byte) 0x9d, (byte) 0x5f, (byte) 0x9f, (byte) 0x9e, (byte) 0x5e, (byte) 0x5a, (byte) 0x9a, (byte) 0x9b, (byte) 0x5b, (byte) + 0x99, (byte) 0x59, (byte) 0x58, (byte) 0x98, (byte) 0x88, (byte) 0x48, (byte) 0x49, (byte) 0x89, (byte) 0x4b, (byte) 0x8b, (byte) + 0x8a, (byte) 0x4a, (byte) 0x4e, (byte) 0x8e, (byte) 0x8f, (byte) 0x4f, (byte) 0x8d, (byte) 0x4d, (byte) 0x4c, (byte) 0x8c, (byte) + 0x44, (byte) 0x84, (byte) 0x85, (byte) 0x45, (byte) 0x87, (byte) 0x47, (byte) 0x46, (byte) 0x86, (byte) 0x82, (byte) 0x42, (byte) + 0x43, (byte) 0x83, (byte) 0x41, (byte) 0x81, (byte) 0x80, (byte) 0x40 + }; + + private static byte[] crc16_tab_l_old = { + 0x00, (byte) 0xc0, (byte) 0xc1, (byte) 0x01, (byte) 0xc3, (byte) 0x03, (byte) 0x02, (byte) 0xc2, (byte) 0xc6, (byte) 0x06, (byte) + 0x07, (byte) 0xc7, (byte) 0x05, (byte) 0xc5, (byte) 0xc4, (byte) 0x04, (byte) 0xcc, (byte) 0x0c, (byte) 0x0d, (byte) 0xcd, (byte) + 0x0f, (byte) 0xcf, (byte) 0xce, (byte) 0x0e, (byte) 0x0a, (byte) 0xca, (byte) 0xcb, (byte) 0x0b, (byte) 0xc9, (byte) 0x09, (byte) + 0x08, (byte) 0xc8, (byte) 0xd8, (byte) 0x18, (byte) 0x19, (byte) 0xd9, (byte) 0x1b, (byte) 0xdb, (byte) 0xda, (byte) 0x1a, (byte) + 0x1e, (byte) 0xde, (byte) 0xdf, (byte) 0x1f, (byte) 0xdd, (byte) 0x1d, (byte) 0x1c, (byte) 0xdc, (byte) 0x14, (byte) 0xd4, (byte) + 0xd5, (byte) 0x15, (byte) 0xd7, (byte) 0x17, (byte) 0x16, (byte) 0xd6, (byte) 0xd2, (byte) 0x12, (byte) 0x13, (byte) 0xd3, (byte) + 0x11, (byte) 0xd1, (byte) 0xd0, (byte) 0x10, (byte) 0xf0, (byte) 0x30, (byte) 0x31, (byte) 0xf1, (byte) 0x33, (byte) 0xf3, (byte) + 0xf2, (byte) 0x32, (byte) 0x36, (byte) 0xf6, (byte) 0xf7, (byte) 0x37, (byte) 0xf5, (byte) 0x35, (byte) 0x34, (byte) 0xf4, (byte) + 0x3c, (byte) 0xfc, (byte) 0xfd, (byte) 0x3d, (byte) 0xff, (byte) 0x3f, (byte) 0x3e, (byte) 0xfe, (byte) 0xfa, (byte) 0x3a, (byte) + 0x3b, (byte) 0xfb, (byte) 0x39, (byte) 0xf9, (byte) 0xf8, (byte) 0x40, (byte) 0x28, (byte) 0xe8, (byte) 0xe9, (byte) 0x29, (byte) + 0xeb, (byte) 0x2b, (byte) 0x2a, (byte) 0xea, (byte) 0xee, (byte) 0x2e, (byte) 0x2f, (byte) 0xef, (byte) 0x2d, (byte) 0xed, (byte) + 0xec, (byte) 0x2c, (byte) 0xe4, (byte) 0x24, (byte) 0x25, (byte) 0xe5, (byte) 0x27, (byte) 0xe7, (byte) 0xe6, (byte) 0x26, (byte) + 0x22, (byte) 0xe2, (byte) 0xe3, (byte) 0x23, (byte) 0xe1, (byte) 0x21, (byte) 0x20, (byte) 0xe0, (byte) 0xa0, (byte) 0x60, (byte) + 0x61, (byte) 0xa1, (byte) 0x63, (byte) 0xa3, (byte) 0xa2, (byte) 0x62, (byte) 0x66, (byte) 0xa6, (byte) 0xa7, (byte) 0x67, (byte) + 0xa5, (byte) 0x65, (byte) 0x64, (byte) 0xa4, (byte) 0x6c, (byte) 0xac, (byte) 0xad, (byte) 0x6d, (byte) 0xaf, (byte) 0x6f, (byte) + 0x6e, (byte) 0xae, (byte) 0xaa, (byte) 0x6a, (byte) 0x6b, (byte) 0xab, (byte) 0x69, (byte) 0xa9, (byte) 0xa8, (byte) 0x68, (byte) + 0x78, (byte) 0xb8, (byte) 0xb9, (byte) 0x79, (byte) 0xbb, (byte) 0x7b, (byte) 0x7a, (byte) 0xba, (byte) 0xbe, (byte) 0x7e, (byte) + 0x7f, (byte) 0xbf, (byte) 0x7d, (byte) 0xbd, (byte) 0xbc, (byte) 0x7c, (byte) 0xb4, (byte) 0x74, (byte) 0x75, (byte) 0xb5, (byte) + 0x77, (byte) 0xb7, (byte) 0xb6, (byte) 0x76, (byte) 0x72, (byte) 0xb2, (byte) 0xb3, (byte) 0x73, (byte) 0xb1, (byte) 0x71, (byte) + 0x70, (byte) 0xb0, (byte) 0x50, (byte) 0x90, (byte) 0x91, (byte) 0x51, (byte) 0x93, (byte) 0x53, (byte) 0x52, (byte) 0x92, (byte) + 0x96, (byte) 0x56, (byte) 0x57, (byte) 0x97, (byte) 0x55, (byte) 0x95, (byte) 0x94, (byte) 0x54, (byte) 0x9c, (byte) 0x5c, (byte) + 0x5d, (byte) 0x9d, (byte) 0x5f, (byte) 0x9f, (byte) 0x9e, (byte) 0x5e, (byte) 0x5a, (byte) 0x9a, (byte) 0x9b, (byte) 0x5b, (byte) + 0x99, (byte) 0x59, (byte) 0x58, (byte) 0x98, (byte) 0x88, (byte) 0x48, (byte) 0x49, (byte) 0x89, (byte) 0x4b, (byte) 0x8b, (byte) + 0x8a, (byte) 0x4a, (byte) 0x4e, (byte) 0x8e, (byte) 0x8f, (byte) 0x4f, (byte) 0x8d, (byte) 0x4d, (byte) 0x4c, (byte) 0x8c, (byte) + 0x44, (byte) 0x84, (byte) 0x85, (byte) 0x45, (byte) 0x87, (byte) 0x47, (byte) 0x46, (byte) 0x86, (byte) 0x82, (byte) 0x42, (byte) + 0x43, (byte) 0x83, (byte) 0x41, (byte) 0x81, (byte) 0x80, (byte) 0x40 + }; + + /** + * 涓涓瓧鑺傚寘鍚綅鐨勬暟閲 8 + */ + private static final int BITS_OF_BYTE = 8; + + /** + * 澶氶」寮 + */ + private static final int POLYNOMIAL = 0x180D; + + /** + * 鍒濆鍊 + */ + private static final int INITIAL_VALUE = 0xFFFF; + + // 娴嬭瘯 + public static void main(String[] args) { + // 搴忓垪鍙峰煙 + byte[] serialNumber = BytesUtil.str2Bcd("3c40"); + + // 鍔犲瘑鏍囧織 + byte[] encryptFlag = BytesUtil.str2Bcd("00"); + + // 甯х被鍨嬫爣蹇 + byte[] frameType = BytesUtil.str2Bcd("03"); + + // 娑堟伅浣 + byte[] msgBody = BytesUtil.str2Bcd("880000000000270100"); + + byte[] data = Bytes.concat(serialNumber, encryptFlag, frameType, msgBody); + + String old_crc = String.format("%04x", CRC16Util.calcCrc16Old(data)); + String crc = String.format("%04x", CRC16Util.calcCrc16(data)); + + System.out.println("old_浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚:" + old_crc); + System.out.println("new_浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚:" + crc); + } + + /** + * @param bytes 缂栫爜鍐呭 + * @return 缂栫爜缁撴灉 + * @function CRC16 缂栫爜 + */ + public static int crc16(int[] bytes) { + int res = INITIAL_VALUE; + for (int data : bytes) { + res = res ^ data; + for (int i = 0; i < BITS_OF_BYTE; i++) { + res = (res & 0x0001) == 1 ? (res >> 1) ^ POLYNOMIAL : res >> 1; + } + } + return revert(res); + } + + /** + * @param src 缈昏浆鏁板瓧 + * @return 缈昏浆缁撴灉 + * @function 缈昏浆16浣嶇殑楂樺叓浣嶅拰浣庡叓浣嶅瓧鑺傦紝浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚 + */ + public static int revert(int src) { + int lowByte = (src & 0xFF00) >> 8; + int highByte = (src & 0x00FF) << 8; + return lowByte | highByte; + } + + /*浠ヤ笅鏂规硶寰楀嚭鐨勬牎楠屼綅锛氫綆浣嶅湪鍓嶏紝楂樹綅鍦ㄥ悗*/ + + /** + * @param data 闇瑕佽绠楃殑鏁扮粍 + * @return CRC16鏍¢獙鍊 + * @function 璁$畻CRC16鏍¢獙 + */ + public static int calcCrc16(byte[] data) { + return calcCrc16(data, 0, data.length); + } + + /** + * @param data 闇瑕佽绠楃殑鏁扮粍 + * @param offset 璧峰浣嶇疆 + * @param len 闀垮害 + * @return CRC16鏍¢獙鍊 + * @function 璁$畻CRC16鏍¢獙 + */ + public static int calcCrc16(byte[] data, int offset, int len) { + return calcCrc16(data, offset, len, 0xffff); + } + + /** + * @param data 闇瑕佽绠楃殑鏁扮粍 + * @param offset 璧峰浣嶇疆 + * @param len 闀垮害 + * @param preval 涔嬪墠鐨勬牎楠屽 + * @return CRC16鏍¢獙鍊 + * @function 璁$畻CRC16鏍¢獙 + */ + public static int calcCrc16(byte[] data, int offset, int len, int preval) { + int ucCRCHi = (preval & 0xff00) >> 8; + int ucCRCLo = preval & 0x00ff; + int iIndex; + for (int i = 0; i < len; ++i) { + iIndex = (ucCRCLo ^ data[offset + i]) & 0x00ff; + ucCRCLo = ucCRCHi ^ crc16_tab_h[iIndex]; + ucCRCHi = crc16_tab_l[iIndex]; + } + return revert(((ucCRCHi & 0x00ff) << 8) | (ucCRCLo & 0x00ff) & 0xffff); + } + + /////////////////////////浣跨敤鑰佸崗璁腑鐨勪綆浣嶇爜琛//////////////////////////////////////////////////////// + + public static int calcCrc16Old(byte[] data) { + return calcCrc16Old(data, 0, data.length); + } + + public static int calcCrc16Old(byte[] data, int offset, int len) { + return calcCrc16Old(data, offset, len, 0xffff); + } + + public static int calcCrc16Old(byte[] data, int offset, int len, int preval) { + int ucCRCHi = (preval & 0xff00) >> 8; + int ucCRCLo = preval & 0x00ff; + int iIndex; + for (int i = 0; i < len; ++i) { + iIndex = (ucCRCLo ^ data[offset + i]) & 0x00ff; + ucCRCLo = ucCRCHi ^ crc16_tab_h[iIndex]; + ucCRCHi = crc16_tab_l_old[iIndex]; + } + return revert(((ucCRCHi & 0x00ff) << 8) | (ucCRCLo & 0x00ff) & 0xffff); + } + +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/Cp56Time2a/Cp56Time2aUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/Cp56Time2a/Cp56Time2aUtil.java new file mode 100644 index 000000000..a8bad6f1e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/Cp56Time2a/Cp56Time2aUtil.java @@ -0,0 +1,91 @@ +package com.jsowell.common.util.Cp56Time2a; + +import java.io.ByteArrayOutputStream; +import java.util.Calendar; +import java.util.Date; + +/** + * TODO + * + * @author JS-ZZA + * @date 2023/2/28 16:50 + */ +public class Cp56Time2aUtil { + + /** + * int 杞崲鎴 byte鏁扮粍 + */ + public static byte[] intToByteArray(int i) { + byte[] result = new byte[4]; + result[0] = (byte) ((i >> 24) & 0xFF); + result[1] = (byte) ((i >> 16) & 0xFF); + result[2] = (byte) ((i >> 8) & 0xFF); + result[3] = (byte) (i & 0xFF); + return result; + } + + /** + * 鏃ユ湡杞崲鎴 CP56Time2a + * + * @param date Date绫诲瀷鏃ユ湡 + * @return {@link Byte} + */ + public static byte[] date2Hbyte(Date date) { + ByteArrayOutputStream bOutput = new ByteArrayOutputStream(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + // 姣闇瑕佽浆鎹㈡垚涓や釜瀛楄妭鍏朵腑 浣庝綅鍦ㄥ墠楂樹綅鍦ㄥ悗 + // 鍏堣浆鎹㈡垚short + int millisecond = calendar.get(Calendar.SECOND) * 1000 + calendar.get(Calendar.MILLISECOND); + + // 榛樿鐨勯珮浣嶅湪鍓 + byte[] millisecondByte = intToByteArray(millisecond); + bOutput.write(millisecondByte[3]); + bOutput.write(millisecondByte[2]); + + // 鍒嗛挓 鍙崰6涓瘮鐗逛綅 闇瑕佹妸鍓嶄袱浣嶇疆涓洪浂 + bOutput.write((byte) calendar.get(Calendar.MINUTE)); + // 灏忔椂闇瑕佹妸鍓嶄笁浣嶇疆闆 + bOutput.write((byte) calendar.get(Calendar.HOUR_OF_DAY)); + // 鏄熸湡鏃ョ殑鏃跺 week 鏄0 + int week = 0; + // if (week == Calendar.SUNDAY) { + // week = 7; + // } else { + // week--; + // } + // 鍓嶄笁涓瓧鑺傛槸 鏄熸湡 鍥犳闇瑕佸皢鏄熸湡鍚戝乏绉5浣 鍚庝簲涓瓧鑺傛槸鏃ユ湡 闇瑕佸皢涓や釜鏁板瓧鐩稿姞 鐩稿姞涔嬪墠闇瑕佸厛灏嗗墠涓変綅缃浂 + bOutput.write((byte) (week << 5) + (calendar.get(Calendar.DAY_OF_MONTH))); + // 鍓嶅洓瀛楄妭缃浂 + bOutput.write((byte) ((byte) calendar.get(Calendar.MONTH) + 1)); + bOutput.write((byte) (calendar.get(Calendar.YEAR) - 2000)); + return bOutput.toByteArray(); + } + + /** + * CP56Time2a杞崲鎴 鏃堕棿 + * + * @param dataByte 鏁版嵁鎶ユ枃 + */ + public static Date byte2Hdate(byte[] dataByte) { + int year = (dataByte[6] & 0x7F) + 2000; + int month = dataByte[5] & 0x0F; + int day = dataByte[4] & 0x1F; + int hour = dataByte[3] & 0x1F; + int minute = dataByte[2] & 0x3F; + int second = dataByte[1] > 0 ? dataByte[1] : (dataByte[1] & 0xff); + int millisecond = dataByte[0] > 0 ? dataByte[0] : (dataByte[0] & 0xff); + millisecond = (second << 8) + millisecond; + second = millisecond / 1000; + millisecond = millisecond % 1000; + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month); + calendar.set(Calendar.DAY_OF_MONTH, day); + calendar.set(Calendar.HOUR_OF_DAY, hour); + calendar.set(Calendar.MINUTE, minute); + calendar.set(Calendar.SECOND, second); + calendar.set(Calendar.MILLISECOND, millisecond); + return calendar.getTime(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/DateUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/DateUtils.java new file mode 100644 index 000000000..b6631ead0 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/DateUtils.java @@ -0,0 +1,813 @@ +package com.jsowell.common.util; + +import com.google.common.collect.Lists; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.management.ManagementFactory; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * 鏃堕棿宸ュ叿绫 + * + * @author jsowell + */ +public class DateUtils extends org.apache.commons.lang3.time.DateUtils { + static Logger log = LoggerFactory.getLogger(DateUtils.class); + + public static String YYYY = "yyyy"; + + public static String YYYY_MM = "yyyy-MM"; + + public static String YYYY_MM_DD = "yyyy-MM-dd"; + + public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; + + public static String YYYYMMDDHHMM = "yyyyMMddHHmm"; + + public static String YYMMDDHHMMSS = "yyMMddHHmmss"; + + public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; + + public static String RFC3339 = "yyyy-MM-dd'T'HH:mm:ssXXX"; + + private static String[] parsePatterns = { + "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", + "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", + "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; + + /** + * 鑾峰彇褰撳墠Date鍨嬫棩鏈 + * + * @return Date() 褰撳墠鏃ユ湡 + */ + public static Date getNowDate() { + return new Date(); + } + + /** + * 鑾峰彇褰撳墠鏃ユ湡, 榛樿鏍煎紡涓簓yyy-MM-dd + * + * @return String + */ + public static String getDate() { + return dateTimeNow(YYYY_MM_DD); + } + + public static String getTime() { + return dateTimeNow(YYYY_MM_DD_HH_MM_SS); + } + + public static String dateTimeNow() { + return dateTimeNow(YYYYMMDDHHMMSS); + } + + public static String dateTimeNow(final String format) { + return parseDateToStr(format, new Date()); + } + + public static String dateTime(final Date date) { + return parseDateToStr(YYYY_MM_DD, date); + } + + public static String parseDateToStr(final String format, final Date date) { + return new SimpleDateFormat(format).format(date); + } + + + public static String timeStampToRfc3339(long timeStamp) { + Date date = new Date(timeStamp); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(RFC3339); + String formatDate = simpleDateFormat.format(date); + return formatDate; + } + + public static LocalDateTime toLocalDateTime(String str, String format) { + if (StringUtils.isBlank(str)) { + return null; + } + if (StringUtils.isBlank(format)) { + format = YYYY_MM_DD_HH_MM_SS; + } + DateTimeFormatter df = DateTimeFormatter.ofPattern(format); + return LocalDateTime.parse(str, df); + } + + public static Date dateTime(final String format, final String ts) { + try { + return new SimpleDateFormat(format).parse(ts); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + /** + * 鏃ユ湡璺緞 鍗冲勾/鏈/鏃 濡2018/08/08 + */ + public static String datePath() { + Date now = new Date(); + return DateFormatUtils.format(now, "yyyy/MM/dd"); + } + + /** + * 鏃ユ湡璺緞 鍗冲勾/鏈/鏃 濡20180808 + */ + public static String dateTime() { + Date now = new Date(); + return DateFormatUtils.format(now, "yyyyMMdd"); + } + + /** + * 鏃ユ湡鍨嬪瓧绗︿覆杞寲涓烘棩鏈 鏍煎紡 + */ + public static Date parseDate(Object str) { + if (str == null) { + return null; + } + try { + return parseDate(str.toString(), parsePatterns); + } catch (ParseException e) { + return null; + } + } + + public static void main(String[] args) { + // String str = "2023-01-07 11:17:12"; + // Date date = parseDate(str); + // String str1 = parseDateToStr(YYYY_MM_DD_HH_MM_SS, date); + // System.out.println(str1); + // + // + // Date date1 = addMinute(new Date(), -15); + // String s = parseDateToStr(YYYY_MM_DD_HH_MM_SS, date1); + // System.out.println(s); + // + // String time = getDate(); + // System.out.println(time); + // + // System.out.println(dateTimeNow("yyyy-MM-dd HH:mm")); + + // String s2 = formatDateTime(new Date()); + // System.out.println(s2); + + String time = DateUtils.getTime(); + System.out.println(time); + + System.out.println(DateUtils.getDate()); + // String s = date2HexStr(new Date()); + // String s = BytesUtil.binary(bytes, 16); + // System.out.println(s); + + String hexString = "9401270a1b0217"; + byte[] bytes1 = BytesUtil.hexStringToByteArray(hexString); + // String s1 = toDateString(bytes1); + // Date date = CP56Time2aToDate(bytes1); + // System.out.println(s1); + + // String encodeCP56Time2a = DateUtils.encodeCP56Time2a(new Date()); + // byte[] bytes = BytesUtil.hexString2Bytes(encodeCP56Time2a); + // String s4 = CP56Time2aToDateStr(bytes); + // // byte[] msg = BytesUtil.str2Bcd("88000000000021" + encodeCP56Time2a); + // // Date date1 = toDate(bytes); + // // String s3 = formatDateTime(date1); + // // System.out.println(s3); + // System.out.println(s4); + long chargingTime = DateUtils.intervalTime("2023-02-24 16:00:00", "2023-02-24 17:03:06"); + System.out.println(chargingTime); + + } + + /** + * 鑾峰彇鏈嶅姟鍣ㄥ惎鍔ㄦ椂闂 + */ + public static Date getServerStartDate() { + long time = ManagementFactory.getRuntimeMXBean().getStartTime(); + return new Date(time); + } + + /** + * 璁$畻鐩稿樊澶╂暟 + */ + public static int differentDaysByMillisecond(Date date1, Date date2) { + return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24))); + } + + /** + * 璁$畻涓や釜鏃堕棿宸 + */ + public static String getDatePoor(Date endDate, Date nowDate) { + long nd = 1000 * 24 * 60 * 60; + long nh = 1000 * 60 * 60; + long nm = 1000 * 60; + long ns = 1000; + // 鑾峰緱涓や釜鏃堕棿鐨勬绉掓椂闂村樊寮 + long diff = endDate.getTime() - nowDate.getTime(); + // 璁$畻宸灏戝ぉ + long day = diff / nd; + // 璁$畻宸灏戝皬鏃 + long hour = diff % nd / nh; + // 璁$畻宸灏戝垎閽 + long min = diff % nd % nh / nm; + // 璁$畻宸灏戠//杈撳嚭缁撴灉 + long sec = diff % nd % nh % nm / ns; + + StringBuilder sb = new StringBuilder(); + if (day != 0) { + sb.append(day).append("澶"); + } + if (hour != 0) { + sb.append(hour).append("灏忔椂"); + } + if (min != 0) { + sb.append(min).append("鍒"); + } + if (sec != 0) { + sb.append(sec).append("绉"); + } + return sb.toString(); + } + + /** + * LocalDateTime杞珼ate + * + * @param localDateTime + * @return + */ + public static Date localDateTime2Date(LocalDateTime localDateTime) { + if (localDateTime == null) { + return null; + } + ZoneId zone = ZoneId.systemDefault(); + Instant instant = localDateTime.atZone(zone).toInstant(); + return Date.from(instant); + } + + public static Date localDate2Date(LocalDate localDate) { + if (localDate == null) { + return null; + } + LocalDateTime localDateTime = LocalDateTime.of(localDate, LocalTime.of(0, 0, 0)); + return localDateTime2Date(localDateTime); + } + + /** + * Date杞琇ocalDateTime + */ + public static LocalDateTime date2LocalDateTime(Date date) { + if (date == null) { + return null; + } + return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + } + + /** + * 鑾峰彇浜戝揩鍏呭崗璁墍闇鏃堕棿娈 + * 0锛 00锝0锛 30 鏃舵璐圭巼鍙 + * 0锛 30锝1锛 00 鏃舵璐圭巼鍙 + * 鈥︹ + * 23锛 00锝23锛 30 鏃舵璐圭巼鍙 + * 23锛 30锝0锛 00 鏃舵璐圭巼鍙 + */ + public static List getPeriodOfTime() { + int intervalMinutes = 30; + // 缁撴灉闆 + List resultList = Lists.newArrayList(); + LocalTime startTime = LocalTime.of(0, 0); + + LocalTime tempStartDateTime = startTime; + LocalTime tempEndDateTime = null; + while (true) { + // 鑾峰彇鍔爄ntervalMinutes鍒嗛挓鍚庣殑鏃堕棿 + tempEndDateTime = tempStartDateTime.plusMinutes(intervalMinutes); + resultList.add(tempStartDateTime.format(DateTimeFormatter.ofPattern("HH:mm:ss")) + + "-" + tempEndDateTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"))); + // 涓嬫鐨勫紑濮嬫椂闂达紝涓轰笂娆$殑缁撴潫鏃堕棿 + tempStartDateTime = tempEndDateTime; + // 褰搕empStartDateTime绛変簬startTime鏃讹紝鍋滄 + if (tempStartDateTime.compareTo(startTime) == 0) { + break; + } + } + // 鐗规畩澶勭悊 + resultList = resultList.subList(0, resultList.size() - 1); + // 姣忓ぉ鐨勬渶鍚庡崐灏忔椂 + resultList.add("23:30:00-23:59:59"); + return resultList; + } + + /** + * 鏃跺垎绉掕浆LocalTime + * 鍙互鏄 10:10:23 鎴栬 10:10 + * + * @param time + * @return + */ + public static LocalTime getLocalTime(String time) { + if (StringUtils.equals("24:00", time)) { + // System.out.println("time涓24:00, 杞崲涓23:59"); + time = "23:59"; + } + List list = Lists.newArrayList(time.split(":")); + if (CollectionUtils.isNotEmpty(list)) { + if (list.size() == 2) { + return LocalTime.of(Integer.parseInt(list.get(0)), Integer.parseInt(list.get(1))); + } else if (list.size() == 3) { + return LocalTime.of(Integer.parseInt(list.get(0)), Integer.parseInt(list.get(1)), Integer.parseInt(list.get(2))); + } + } + return null; + } + + public enum IntervalType { + DAY, + HOUR, + MINUTE, + SECOND, + ; + } + + /** + * 鏃堕棿鍒囧壊 + * + * @param startTime 琚垏鍓茬殑寮濮嬫椂闂 + * @param endTime 琚垏鍓茬殑缁撴潫鏃堕棿 + * @param intervalType + * @param interval >0 + * @return + */ + public static List splitDate(Date startTime, Date endTime, IntervalType intervalType, int interval) { + if (interval < 0) { + return null; + } + if (endTime.getTime() <= startTime.getTime()) { + return null; + } + + if (intervalType == IntervalType.DAY) { + return splitByDay(startTime, endTime, interval); + } + if (intervalType == IntervalType.HOUR) { + return splitByHour(startTime, endTime, interval); + } + if (intervalType == IntervalType.MINUTE) { + return splitByMinute(startTime, endTime, interval); + } + if (intervalType == IntervalType.SECOND) { + return splitBySecond(startTime, endTime, interval); + } + return null; + } + + /** + * 鎸夌収灏忔椂鍒囧壊鏃堕棿鍖洪棿 + */ + public static List splitByHour(Date startTime, Date endTime, int intervalHours) { + if (endTime.getTime() <= startTime.getTime()) { + return null; + } + + List dateSplits = new ArrayList<>(256); + + DateSplit param = new DateSplit(); + param.setStartDateTime(startTime); + param.setEndDateTime(endTime); + param.setEndDateTime(addHour(startTime, intervalHours)); + while (true) { + param.setStartDateTime(startTime); + Date tempEndTime = addHour(startTime, intervalHours); + if (tempEndTime.getTime() >= endTime.getTime()) { + tempEndTime = endTime; + } + param.setEndDateTime(tempEndTime); + + dateSplits.add(new DateSplit(param.getStartDateTime(), param.getEndDateTime())); + + startTime = addHour(startTime, intervalHours); + if (startTime.getTime() >= endTime.getTime()) { + break; + } + if (param.getEndDateTime().getTime() >= endTime.getTime()) { + break; + } + } + return dateSplits; + } + + /** + * 鎸夌収绉掑垏鍓叉椂闂村尯闂 + * getRealTimeDetectionData + */ + public static List splitBySecond(Date startTime, Date endTime, int intervalSeconds) { + if (endTime.getTime() <= startTime.getTime()) { + return null; + } + List dateSplits = new ArrayList<>(256); + + DateSplit param = new DateSplit(); + param.setStartDateTime(startTime); + param.setEndDateTime(endTime); + param.setEndDateTime(addSecond(startTime, intervalSeconds)); + while (true) { + param.setStartDateTime(startTime); + Date tempEndTime = addSecond(startTime, intervalSeconds); + if (tempEndTime.getTime() >= endTime.getTime()) { + tempEndTime = endTime; + } + param.setEndDateTime(tempEndTime); + + dateSplits.add(new DateSplit(param.getStartDateTime(), param.getEndDateTime())); + + startTime = addSecond(startTime, intervalSeconds); + if (startTime.getTime() >= endTime.getTime()) { + break; + } + if (param.getEndDateTime().getTime() >= endTime.getTime()) { + break; + } + } + return dateSplits; + } + + /** + * 鎸夌収澶╁垏鍓叉椂闂村尯闂 + */ + public static List splitByDay(Date startTime, Date endTime, int intervalDays) { + if (endTime.getTime() <= startTime.getTime()) { + return null; + } + List dateSplits = new ArrayList<>(256); + + DateSplit param = new DateSplit(); + param.setStartDateTime(startTime); + param.setEndDateTime(endTime); + param.setEndDateTime(addDay(startTime, intervalDays)); + while (true) { + param.setStartDateTime(startTime); + Date tempEndTime = addDay(startTime, intervalDays); + if (tempEndTime.getTime() >= endTime.getTime()) { + tempEndTime = endTime; + } + param.setEndDateTime(tempEndTime); + + dateSplits.add(new DateSplit(param.getStartDateTime(), param.getEndDateTime())); + + startTime = addDay(startTime, intervalDays); + if (startTime.getTime() >= endTime.getTime()) { + break; + } + if (param.getEndDateTime().getTime() >= endTime.getTime()) { + break; + } + } + return dateSplits; + } + + + /** + * 鎸夌収鍒嗛挓鍒囧壊鏃堕棿鍖洪棿 + * + * @param startTime + * @param endTime + * @param intervalMinutes + * @return + */ + public static List splitByMinute(Date startTime, Date endTime, int intervalMinutes) { + if (endTime.getTime() <= startTime.getTime()) { + return null; + } + List dateSplits = new ArrayList<>(256); + + DateSplit param = new DateSplit(); + param.setStartDateTime(startTime); + param.setEndDateTime(endTime); + param.setEndDateTime(addMinute(startTime, intervalMinutes)); + while (true) { + param.setStartDateTime(startTime); + Date tempEndTime = addMinute(startTime, intervalMinutes); + if (tempEndTime.getTime() >= endTime.getTime()) { + tempEndTime = endTime; + } + param.setEndDateTime(tempEndTime); + + dateSplits.add(new DateSplit(param.getStartDateTime(), param.getEndDateTime())); + + startTime = addMinute(startTime, intervalMinutes); + if (startTime.getTime() >= endTime.getTime()) { + break; + } + if (param.getEndDateTime().getTime() >= endTime.getTime()) { + break; + } + } + return dateSplits; + } + + private static Date addDay(Date date, int days) { + return add(date, Calendar.DAY_OF_MONTH, days); + } + + private static Date addHour(Date date, int hours) { + return add(date, Calendar.HOUR_OF_DAY, hours); + } + + public static Date addMinute(Date date, int minute) { + return add(date, Calendar.MINUTE, minute); + } + + private static Date addSecond(Date date, int second) { + return add(date, Calendar.SECOND, second); + } + + private static Date add(final Date date, final int calendarField, final int amount) { + final Calendar c = Calendar.getInstance(); + c.setTime(date); + c.add(calendarField, amount); + return c.getTime(); + } + + public static String formatDateTime(Date date) { + if (date == null) { + return ""; + } + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS); + return simpleDateFormat.format(date); + } + + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class DateSplit { + private Date startDateTime; + private Date endDateTime; + + public String getStartDateTimeStr() { + return formatDateTime(startDateTime); + } + + public String getEndDateTimeStr() { + return formatDateTime(endDateTime); + } + } + + /** + * CP56Time2a 杞 鏃ユ湡瀛楃涓 + * 0x3b浜ゆ槗璁板綍 浼氫娇鐢ㄨ繖涓柟娉曪紝瑙f瀽寮濮嬫椂闂 缁撴潫鏃堕棿 浜ゆ槗鏃堕棿 + * @param bytes + * @return + */ + // public static String CP56Time2aToDateStr(byte[] bytes) { + // Date date = CP56Time2aToDate(bytes); + // if (date == null) { + // return null; + // } + // return DateUtils.formatDateTime(date); + // } + // public static String toDateString(byte[] bytes) { + // return Cp56Time2aUtil.toDateString(bytes); + // } + + /** + * cp56time2a 鏍煎紡杞琩ate鏍煎紡 + */ + // public static Date CP56Time2aToDate(byte[] bytes) { + // if (bytes == null || bytes.length != 7) { + // return null; + // } + // int ms = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(bytes, 0, 2)); + // int min = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(bytes, 2, 1)); + // int hour = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(bytes, 3, 1)); + // int day = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(bytes, 4, 1)); + // int month = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(bytes, 5, 1)); + // int year = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(bytes, 6, 1)); + // if (month == 0 || day == 0 || year == 0) { + // return null; + // } + // LocalDateTime localDateTime = LocalDateTime.of(year + 2000, month, day, hour, min, ms / 1000); + // Date date = DateUtils.localDateTime2Date(localDateTime); + // return date; + // } + + // public static Date CP56Time2aToDate(byte[] bytes) { + // return Cp56Time2aUtil.toDate(bytes); + // } + + /** + * 鏃堕棿杞16杩涘埗瀛楃涓 + * Date杞垚CP56Time2a + * 鍙戦佸鏃惰姹傦紝浼氱敤鍒拌繖涓柟娉 + */ + // public static String encodeCP56Time2a(Date date) { + // // Calendar calendar = Calendar.getInstance(); + // // calendar.setTime(date); + // // StringBuilder builder = new StringBuilder(); + // // String milliSecond = String.format("%04X", (calendar.get(Calendar.SECOND) * 1000) + calendar.get(Calendar.MILLISECOND)); + // // builder.append(milliSecond.substring(2, 4)); + // // builder.append(milliSecond.substring(0, 2)); + // // builder.append(String.format("%02X", calendar.get(Calendar.MINUTE) & 0x3F)); + // // builder.append(String.format("%02X", calendar.get(Calendar.HOUR_OF_DAY) & 0x1F)); + // // int week = calendar.get(Calendar.DAY_OF_WEEK); + // // if (week == Calendar.SUNDAY) + // // week = 7; + // // else week--; + // // builder.append(String.format("%02X", (week << 5) + (calendar.get(Calendar.DAY_OF_MONTH) & 0x1F))); + // // builder.append(String.format("%02X", calendar.get(Calendar.MONTH) + 1)); + // // builder.append(String.format("%02X", calendar.get(Calendar.YEAR) - 2000)); + // // return builder.toString(); + // + // byte[] result = new byte[7]; + // final Calendar aTime = Calendar.getInstance(); + // aTime.setTime(date); + // final int milliseconds = aTime.get(Calendar.MILLISECOND); + // result[0] = (byte) (milliseconds % 256); + // result[1] = (byte) (milliseconds / 256); + // result[2] = (byte) aTime.get(Calendar.MINUTE); + // result[3] = (byte) aTime.get(Calendar.HOUR_OF_DAY); + // result[4] = (byte) aTime.get(Calendar.DAY_OF_MONTH); + // result[5] = (byte) (aTime.get(Calendar.MONTH) + 1); + // result[6] = (byte) (aTime.get(Calendar.YEAR) % 100); + // System.out.println("Year->" + aTime.get(Calendar.YEAR)); + // return BytesUtil.binary(result, 16); + // } + // public static String date2HexStr(Date date) { + // return Cp56Time2aUtil.date2HexStr(date); + // } + + + /** + * 鑾峰彇涓や釜鏃堕棿鐨勯棿闅旀椂闂 + * + * @return 闂撮殧鏃堕棿 鍗曚綅锛氬垎閽 + */ + public static long intervalTime(String begin, String end) { + return intervalTime(parseDate(begin), parseDate(end)); + } + + /** + * 鑾峰彇涓や釜鏃堕棿鐨勯棿闅旀椂闂 + * + * @return 闂撮殧鏃堕棿 鍗曚綅锛氬垎閽 + */ + public static long intervalTime(Date begin, Date end) { + return intervalTime(date2LocalDateTime(begin), date2LocalDateTime(end)); + } + + /** + * 鑾峰彇涓や釜鏃堕棿鐨勯棿闅旀椂闂 + * + * @return 闂撮殧鏃堕棿 鍗曚綅锛氬垎閽 + */ + public static long intervalTime(LocalDateTime begin, LocalDateTime end) { + return ChronoUnit.MINUTES.between(begin, end); + } + + /** + * 鍒ゆ柇2涓椂闂存鏄惁鏈夐噸鍙狅紙浜ら泦锛 + * + * @param startDate1 鏃堕棿娈1寮濮嬫椂闂存埑 + * @param endDate1 鏃堕棿娈1缁撴潫鏃堕棿鎴 + * @param startDate2 鏃堕棿娈2寮濮嬫椂闂存埑 + * @param endDate2 鏃堕棿娈2缁撴潫鏃堕棿鎴 + * @param isStrict 鏄惁涓ユ牸閲嶅彔锛宼rue 涓ユ牸锛屾病鏈変换浣曠浉浜ゆ垨鐩哥瓑锛沠alse 涓嶄弗鏍硷紝鍙互棣栧熬鐩哥瓑锛屾瘮濡2021/5/29-2021/5/31鍜2021/5/31-2021/6/1锛屼笉閲嶅彔銆 + * @return 杩斿洖鏄惁閲嶅彔 + */ + public static boolean isOverlap(long startDate1, long endDate1, long startDate2, long endDate2, boolean isStrict) { + if (isStrict) { + if (!(endDate1 < startDate2 || startDate1 > endDate2)) { + return true; + } + } else { + if (!(endDate1 <= startDate2 || startDate1 >= endDate2)) { + return true; + } + } + return false; + } + + /** + * @param time1 17:02:00 - 17:02:00 + * @param time2 00:00-06:30 + * @return + */ + public static boolean checkTime(String time1, String time2) { + String[] split = time1.split("-"); + LocalTime startTime1 = DateUtils.getLocalTime(split[0]); + LocalTime endTime1 = DateUtils.getLocalTime(split[1]); + String[] split2 = time2.split("-"); + LocalTime startTime2 = DateUtils.getLocalTime(split2[0]); + LocalTime endTime2 = DateUtils.getLocalTime(split2[1]); + return DateUtils.isOverlap(startTime1, endTime1, startTime2, endTime2, false); + } + + /** + * 鍒ゆ柇鏃堕棿娈垫槸鍚﹂噸鍙 + * + * @param startDate1 + * @param endDate1 + * @param startDate2 + * @param endDate2 + * @param isStrict + * @return + */ + public static boolean isOverlap(LocalTime startDate1, LocalTime endDate1, LocalTime startDate2, LocalTime endDate2, boolean isStrict) { + if (startDate1 == null || endDate1 == null || startDate2 == null || endDate2 == null) { + log.warn("鍒ゆ柇鏃堕棿娈垫槸鍚﹂噸鍙犵己灏戝弬鏁帮紝杩斿洖false"); + return false; + } + boolean result = false; + if (isStrict) { + if (!(endDate1.isBefore(startDate2) || startDate1.isAfter(endDate2))) { + result = true; + } + } else { + if (!((endDate1.isBefore(startDate2) || endDate1.equals(startDate2)) || (startDate1.isAfter(endDate2) || startDate1.equals(endDate2)))) { + result = true; + } + } + // log.info("鏃堕棿娈1={}, 鏃堕棿娈2={}, 缁撴灉:{}", startDate1 + "-" + endDate1, startDate2 + "-" + endDate2, result); + return result; + } + + /** + * 鍒ゆ柇2涓椂闂存鏄惁鏈夐噸鍙狅紙浜ら泦锛 + * + * @param startDate1 鏃堕棿娈1寮濮嬫椂闂 + * @param endDate1 鏃堕棿娈1缁撴潫鏃堕棿 + * @param startDate2 鏃堕棿娈2寮濮嬫椂闂 + * @param endDate2 鏃堕棿娈2缁撴潫鏃堕棿 + * @param isStrict 鏄惁涓ユ牸閲嶅彔锛宼rue 涓ユ牸锛屾病鏈変换浣曠浉浜ゆ垨鐩哥瓑锛沠alse 涓嶄弗鏍硷紝鍙互棣栧熬鐩哥瓑锛屾瘮濡2021-05-29鍒2021-05-31鍜2021-05-31鍒2021-06-01锛屼笉閲嶅彔銆 + * @return 杩斿洖鏄惁閲嶅彔 + */ + public static boolean isOverlap(Date startDate1, Date endDate1, Date startDate2, Date endDate2, boolean isStrict) { + Objects.requireNonNull(startDate1, "startDate1"); + Objects.requireNonNull(endDate1, "endDate1"); + Objects.requireNonNull(startDate2, "startDate2"); + Objects.requireNonNull(endDate2, "endDate2"); + return isOverlap(startDate1.getTime(), endDate1.getTime(), startDate2.getTime(), endDate2.getTime(), isStrict); + } + + /** + * 绉 杞 澶╂椂鍒嗙 + * + * @param mss 绉掓暟 + * @return xx澶﹛x灏忔椂xx鍒嗛挓xx绉 + */ + public static String formatDateTime(long mss) { + String DateTimes = null; + long days = mss / (60 * 60 * 24); + long hours = (mss % (60 * 60 * 24)) / (60 * 60); + long minutes = (mss % (60 * 60)) / 60; + long seconds = mss % 60; + if (days > 0) { + DateTimes = days + "澶" + hours + "灏忔椂" + minutes + "鍒嗛挓" + + seconds + "绉"; + } else if (hours > 0) { + DateTimes = hours + "灏忔椂" + minutes + "鍒嗛挓" + + seconds + "绉"; + } else if (minutes > 0) { + DateTimes = minutes + "鍒嗛挓" + + seconds + "绉"; + } else { + DateTimes = seconds + "绉"; + } + + return DateTimes; + } + + /** + * 褰撳墠鏃堕棿鏄惁鍦ㄦ椂闂存寚瀹氳寖鍥村唴
+ * + * @param time 琚鏌ョ殑鏃堕棿 + * @param beginTime 璧峰鏃堕棿 + * @param endTime 缁撴潫鏃堕棿 + * @return 鏄惁鍦ㄨ寖鍥村唴 + * @since 3.0.8 + */ + public static boolean isIn(LocalTime time, LocalTime beginTime, LocalTime endTime) { + // 鍒ゆ柇鏄惁鍦ㄨ寖鍥村唴 鍖呭惈寮濮嬬粨鏉熸椂闂 + if (time.compareTo(beginTime) == 0 || time.compareTo(endTime) == 0) { + return true; + } + if (beginTime.isBefore(time) && endTime.isAfter(time)){ + return true; + } + return false; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/DictUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/DictUtils.java new file mode 100644 index 000000000..f00518ec5 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/DictUtils.java @@ -0,0 +1,159 @@ +package com.jsowell.common.util; + +import com.alibaba.fastjson2.JSONArray; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.domain.entity.SysDictData; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.util.spring.SpringUtils; + +import java.util.Collection; +import java.util.List; + +/** + * 瀛楀吀宸ュ叿绫 + * + * @author jsowell + */ +public class DictUtils { + /** + * 鍒嗛殧绗 + */ + public static final String SEPARATOR = ","; + + /** + * 璁剧疆瀛楀吀缂撳瓨 + * + * @param key 鍙傛暟閿 + * @param dictDatas 瀛楀吀鏁版嵁鍒楄〃 + */ + public static void setDictCache(String key, List dictDatas) { + SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas); + } + + /** + * 鑾峰彇瀛楀吀缂撳瓨 + * + * @param key 鍙傛暟閿 + * @return dictDatas 瀛楀吀鏁版嵁鍒楄〃 + */ + public static List getDictCache(String key) { + JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); + if (StringUtils.isNotNull(arrayCache)) { + return arrayCache.toList(SysDictData.class); + } + return null; + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷鍜屽瓧鍏稿艰幏鍙栧瓧鍏告爣绛 + * + * @param dictType 瀛楀吀绫诲瀷 + * @param dictValue 瀛楀吀鍊 + * @return 瀛楀吀鏍囩 + */ + public static String getDictLabel(String dictType, String dictValue) { + return getDictLabel(dictType, dictValue, SEPARATOR); + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷鍜屽瓧鍏告爣绛捐幏鍙栧瓧鍏稿 + * + * @param dictType 瀛楀吀绫诲瀷 + * @param dictLabel 瀛楀吀鏍囩 + * @return 瀛楀吀鍊 + */ + public static String getDictValue(String dictType, String dictLabel) { + return getDictValue(dictType, dictLabel, SEPARATOR); + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷鍜屽瓧鍏稿艰幏鍙栧瓧鍏告爣绛 + * + * @param dictType 瀛楀吀绫诲瀷 + * @param dictValue 瀛楀吀鍊 + * @param separator 鍒嗛殧绗 + * @return 瀛楀吀鏍囩 + */ + public static String getDictLabel(String dictType, String dictValue, String separator) { + StringBuilder propertyString = new StringBuilder(); + List datas = getDictCache(dictType); + + if (StringUtils.isNotNull(datas)) { + if (StringUtils.containsAny(separator, dictValue)) { + for (SysDictData dict : datas) { + for (String value : dictValue.split(separator)) { + if (value.equals(dict.getDictValue())) { + propertyString.append(dict.getDictLabel()).append(separator); + break; + } + } + } + } else { + for (SysDictData dict : datas) { + if (dictValue.equals(dict.getDictValue())) { + return dict.getDictLabel(); + } + } + } + } + return StringUtils.stripEnd(propertyString.toString(), separator); + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷鍜屽瓧鍏告爣绛捐幏鍙栧瓧鍏稿 + * + * @param dictType 瀛楀吀绫诲瀷 + * @param dictLabel 瀛楀吀鏍囩 + * @param separator 鍒嗛殧绗 + * @return 瀛楀吀鍊 + */ + public static String getDictValue(String dictType, String dictLabel, String separator) { + StringBuilder propertyString = new StringBuilder(); + List datas = getDictCache(dictType); + + if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas)) { + for (SysDictData dict : datas) { + for (String label : dictLabel.split(separator)) { + if (label.equals(dict.getDictLabel())) { + propertyString.append(dict.getDictValue()).append(separator); + break; + } + } + } + } else { + for (SysDictData dict : datas) { + if (dictLabel.equals(dict.getDictLabel())) { + return dict.getDictValue(); + } + } + } + return StringUtils.stripEnd(propertyString.toString(), separator); + } + + /** + * 鍒犻櫎鎸囧畾瀛楀吀缂撳瓨 + * + * @param key 瀛楀吀閿 + */ + public static void removeDictCache(String key) { + SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); + } + + /** + * 娓呯┖瀛楀吀缂撳瓨 + */ + public static void clearDictCache() { + Collection keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*"); + SpringUtils.getBean(RedisCache.class).deleteObject(keys); + } + + /** + * 璁剧疆cache key + * + * @param configKey 鍙傛暟閿 + * @return 缂撳瓨閿甼ey + */ + public static String getCacheKey(String configKey) { + return CacheConstants.SYS_DICT_KEY + configKey; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/DistanceUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/DistanceUtils.java new file mode 100644 index 000000000..a41a700d2 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/DistanceUtils.java @@ -0,0 +1,42 @@ +package com.jsowell.common.util; + +public final class DistanceUtils { + + /** + * 鍦扮悆鍗婂緞,鍗曚綅 km + */ + private static final double EARTH_RADIUS = 6378.137; + + /** + * 鏍规嵁缁忕含搴︼紝璁$畻涓ょ偣闂寸殑璺濈 + * + * @param longitude1 绗竴涓偣鐨勭粡搴 + * @param latitude1 绗竴涓偣鐨勭含搴 + * @param longitude2 绗簩涓偣鐨勭粡搴 + * @param latitude2 绗簩涓偣鐨勭含搴 + * @return 杩斿洖璺濈 鍗曚綅鍗冪背 + */ + public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) { + // 绾害 + double lat1 = Math.toRadians(latitude1); + double lat2 = Math.toRadians(latitude2); + // 缁忓害 + double lng1 = Math.toRadians(longitude1); + double lng2 = Math.toRadians(longitude2); + // 绾害涔嬪樊 + double a = lat1 - lat2; + // 缁忓害涔嬪樊 + double b = lng1 - lng2; + // 璁$畻涓ょ偣璺濈鐨勫叕寮 + double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2))); + // 寮ч暱涔樺湴鐞冨崐寰, 杩斿洖鍗曚綅: 鍗冪背 + s = s * EARTH_RADIUS; + return s; + } + + public static void main(String[] args) { + double d = getDistance(116.308479, 39.983171, 116.353454, 39.996059); + System.out.println(d); + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/ExceptionUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/ExceptionUtil.java new file mode 100644 index 000000000..5433bf2d6 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/ExceptionUtil.java @@ -0,0 +1,33 @@ +package com.jsowell.common.util; + +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * 閿欒淇℃伅澶勭悊绫汇 + * + * @author jsowell + */ +public class ExceptionUtil { + /** + * 鑾峰彇exception鐨勮缁嗛敊璇俊鎭 + */ + public static String getExceptionMessage(Throwable e) { + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw, true)); + return sw.toString(); + } + + public static String getRootErrorMessage(Exception e) { + Throwable root = org.apache.commons.lang3.exception.ExceptionUtils.getRootCause(e); + root = (root == null ? e : root); + if (root == null) { + return ""; + } + String msg = root.getMessage(); + if (msg == null) { + return "null"; + } + return StringUtils.defaultString(msg); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java new file mode 100644 index 000000000..8a4c33f10 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java @@ -0,0 +1,135 @@ +package com.jsowell.common.util; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.JwtBuilder; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.crypto.spec.SecretKeySpec; +import javax.xml.bind.DatatypeConverter; +import java.security.Key; +import java.util.Date; + +@Component +public class JWTUtils { + // 浠ょ墝鑷畾涔夋爣璇 + private static String header; + + @Value("${token.header}") + public void setHeader(String header) { + JWTUtils.header = header; + } + + // 浠ょ墝绉橀挜 + private static String secret; + + @Value("${token.secret}") + public void setSecret(String secret) { + JWTUtils.secret = secret; + } + + // 鎺ュ彛鏈嶅姟 浠ょ墝鏈夋晥鏈 + private static int serviceExpireTime; + + @Value("${token.serviceExpireTime}") + public void setServiceExpireTime(int serviceExpireTime) { + JWTUtils.serviceExpireTime = serviceExpireTime; + } + + protected static final long MILLIS_SECOND = 1000; + + protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; + + private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L; + + /** + * 鐢熸垚Jwt鐨勬柟娉 + * + * @param id 鐢ㄦ埛ID + * @param subject 鐢ㄦ埛鏄电О + * @param ttlMillis 杩囨湡鏃堕棿 姣 + * @return Token String 鍑瘉 + */ + private static String createToken(String id, String subject, long ttlMillis) { + // 绛惧悕鏂规硶 HS256 + SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; + + // 鐢熸垚Jwt鐨勬椂闂 + long nowMillis = System.currentTimeMillis(); + Date now = new Date(nowMillis); + + // 鐢熸垚绉橀挜 + byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(secret); + Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName()); + + // 璁剧疆JWT鎵瀛樺偍鐨勪俊鎭 + JwtBuilder builder = Jwts.builder().setId(id).setIssuedAt(now).setSubject(subject).signWith(signatureAlgorithm, signingKey); + + //builder.claim("name", "value"); //瀛樺偍鑷畾涔変俊鎭 + + // 璁剧疆杩囨湡鏃堕棿 + if (ttlMillis >= 0) { + long expMillis = nowMillis + ttlMillis * MILLIS_MINUTE; + Date exp = new Date(expMillis); + builder.setExpiration(exp); + } + + // 鏋勫缓JWT骞跺皢鍏跺簭鍒楀寲涓虹揣鍑戠殑URL瀹夊叏瀛楃涓 + return builder.compact(); + } + + /** + * 浠庝护鐗屼腑鑾峰彇鏁版嵁澹版槑 + * + * @param token 浠ょ墝 + * @return 鏁版嵁澹版槑 + */ + private static Claims parseToken(String token) { + return Jwts.parser() + .setSigningKey(secret) + .parseClaimsJws(token) + .getBody(); + } + + /** + * 鑾峰彇浼氬憳token + * + * @return + */ + public static String createMemberToken(String memberId, String nickName) { + return createToken(memberId, nickName, serviceExpireTime); + } + + /** + * 鑾峰彇浼氬憳id + * + * @param memberToken + * @return + */ + public static String getMemberId(String memberToken) { + memberToken = getToken(memberToken); + if (StringUtils.isBlank(memberToken)) { + throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); + } + Claims claims = parseToken(memberToken); + return claims.getId(); + } + + /** + * 鏇挎崲Bearer + * + * @param memberToken 浼氬憳token + * @return + */ + private static String getToken(String memberToken) { + if (StringUtils.isNotEmpty(memberToken) && memberToken.startsWith(Constants.TOKEN_PREFIX)) { + memberToken = memberToken.replace(Constants.TOKEN_PREFIX, "").trim(); + } + return memberToken; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/LogUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/LogUtils.java new file mode 100644 index 000000000..7d7a0f0c2 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/LogUtils.java @@ -0,0 +1,15 @@ +package com.jsowell.common.util; + +/** + * 澶勭悊骞惰褰曟棩蹇楁枃浠 + * + * @author jsowell + */ +public class LogUtils { + public static String getBlock(Object msg) { + if (msg == null) { + msg = ""; + } + return "[" + msg.toString() + "]"; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/MessageUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/MessageUtils.java new file mode 100644 index 000000000..709bf7d07 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/MessageUtils.java @@ -0,0 +1,24 @@ +package com.jsowell.common.util; + +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; +import com.jsowell.common.util.spring.SpringUtils; + +/** + * 鑾峰彇i18n璧勬簮鏂囦欢 + * + * @author jsowell + */ +public class MessageUtils { + /** + * 鏍规嵁娑堟伅閿拰鍙傛暟 鑾峰彇娑堟伅 濮旀墭缁檚pring messageSource + * + * @param code 娑堟伅閿 + * @param args 鍙傛暟 + * @return 鑾峰彇鍥介檯鍖栫炕璇戝 + */ + public static String message(String code, Object... args) { + MessageSource messageSource = SpringUtils.getBean(MessageSource.class); + return messageSource.getMessage(code, args, LocaleContextHolder.getLocale()); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/PageUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/PageUtils.java new file mode 100644 index 000000000..aa681c08a --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/PageUtils.java @@ -0,0 +1,32 @@ +package com.jsowell.common.util; + +import com.github.pagehelper.PageHelper; +import com.jsowell.common.core.page.PageDomain; +import com.jsowell.common.core.page.TableSupport; +import com.jsowell.common.util.sql.SqlUtil; + +/** + * 鍒嗛〉宸ュ叿绫 + * + * @author jsowell + */ +public class PageUtils extends PageHelper { + /** + * 璁剧疆璇锋眰鍒嗛〉鏁版嵁 + */ + public static void startPage() { + PageDomain pageDomain = TableSupport.buildPageRequest(); + Integer pageNum = pageDomain.getPageNum(); + Integer pageSize = pageDomain.getPageSize(); + String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); + Boolean reasonable = pageDomain.getReasonable(); + PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable); + } + + /** + * 娓呯悊鍒嗛〉鐨勭嚎绋嬪彉閲 + */ + public static void clearPage() { + PageHelper.clearPage(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/RandomUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/RandomUtil.java new file mode 100644 index 000000000..4c7a56ab4 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/RandomUtil.java @@ -0,0 +1,84 @@ +package com.jsowell.common.util; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +import java.security.SecureRandom; +import java.util.List; +import java.util.Random; +import java.util.Set; + +/** + * 鑾峰彇闅忔満鏁扮殑宸ュ叿绫 + */ +public class RandomUtil { + private static final String SYMBOLS_NUM = "0123456789"; // 绾暟瀛 + //濡傛灉闇鍔犲叆瀛楁瘝灏辨敼鎴0123456789abcdefg........... + private static final String SYMBOLS_NUM_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789"; + + private static final Random RANDOM = new SecureRandom(); + + /** + * 鑾峰彇6浣嶇殑鐭俊楠岃瘉鐮 绾暟瀛 + * + * @return 闅忔満鏁板瓧 + */ + public static String getSMSVerificationCode() { + return getRandomNumber(6); + } + + /** + * 鑾峰彇鎸囧畾闀垮害闅忔満鏁 + * + * @param length 闇瑕佺殑闀垮害 + * @return 闅忔満鏁 + */ + public static String getRandomNumber(int length) { + char[] nonceChars = new char[length]; //鎸囧畾闀垮害锛岃嚜宸卞彲浠ヨ缃 + for (int index = 0; index < nonceChars.length; ++index) { + nonceChars[index] = SYMBOLS_NUM.charAt(RANDOM.nextInt(SYMBOLS_NUM.length())); + } + return new String(nonceChars); + } + + /** + * 鑾峰彇涓缁勪笉閲嶅鐨6浣嶆暟闅忔満鏁 + * + * @param num 鏁伴噺 + * @return + */ + public static List getRandomNumberList(int num) { + List list = Lists.newArrayList(); + for (int i = 0; i < num; i++) { + String code = getNotRepeatCode(list); + // System.out.println(code); + list.add(code); + } + return list; + } + + + /** + * 鑾峰彇涓缁勪笉閲嶅鐨6浣嶆暟闅忔満鏁 + */ + private static String getNotRepeatCode(List list) { + // 鑾峰彇闅忔満楠岃瘉鐮 + String code = RandomUtil.getSMSVerificationCode(); + // 鍒ゆ柇list涓槸鍚﹀瓨鍦 + boolean contains = list.contains(code); + if (contains) { + // 宸茬粡瀛樺湪锛岄噸鏂拌幏鍙栦竴涓 + code = getNotRepeatCode(list); + } + return code; + } + + + public static void main(String[] args) { + List randomNumberList = getRandomNumberList(100000); + Set set = Sets.newHashSet(randomNumberList); + System.out.println("list闀垮害锛" + randomNumberList.size()); + System.out.println("set闀垮害锛" + set.size()); + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/SMSUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/SMSUtil.java new file mode 100644 index 000000000..ec3dc4d9e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/SMSUtil.java @@ -0,0 +1,68 @@ +package com.jsowell.common.util; + +import com.github.qcloudsms.SmsSingleSender; +import com.github.qcloudsms.SmsSingleSenderResult; +import com.github.qcloudsms.httpclient.HTTPException; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.redis.RedisCache; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +/** + * 鍙戦佺煭淇¢獙璇佺爜宸ュ叿绫 + */ +@Component +public class SMSUtil { + + private static RedisCache redisCache; + + @Autowired + public void setRedisCache(RedisCache redisCache) { + SMSUtil.redisCache = redisCache; + } + + + // 鐭俊搴旂敤SDK AppKey + private static final String APP_KEY = "8ebcf52de98416814b440891350cd594"; + + // 鐭俊妯℃澘ID锛岄渶瑕佸湪鐭俊搴旂敤涓敵璇 + private static final int TEMPLATE_ID = 1002460; + + // 鐭俊搴旂敤SDK AppID 1400寮澶 + private static final int APP_ID = 1400536771; + + // 绛惧悕锛屼娇鐢ㄧ殑鏄鍚嶅唴瀹癸紝鑰屼笉鏄鍚岻D + private static final String SMS_SIGN = "涓捐鏂拌兘婧"; + + // 鍥藉鐮 濡 86 涓轰腑鍥 + private static final String NATION_CODE = "86"; + + public static String sendSMS(HttpServletRequest request, String phoneNumber) throws HTTPException, IOException { + String reStr = "success"; //瀹氫箟杩斿洖鍊 + //闅忔満鐢熸垚鍏綅楠岃瘉鐮 + String code = RandomUtil.getSMSVerificationCode(); + //鍙傛暟锛屼竴瀹氳瀵瑰簲鐭俊妯℃澘涓殑鍙傛暟椤哄簭鍜屼釜鏁帮紝 + String[] params = {code}; + //鍒涘缓ssender瀵硅薄 + SmsSingleSender ssender = new SmsSingleSender(APP_ID, APP_KEY); + //鍙戦 + SmsSingleSenderResult result = ssender.sendWithParam(NATION_CODE, phoneNumber, TEMPLATE_ID, params, SMS_SIGN, "", ""); + if (result.result != 0) { + reStr = "error"; + } else { + // 鏀逛负淇濆瓨redis + String redisKey = CacheConstants.SMS_VERIFICATION_CODE_KEY + phoneNumber; + redisCache.setCacheObject(redisKey, code, CacheConstants.cache_expire_time_10m); + } + return reStr; + } + + + public static void main(String[] args) { + System.out.println(); + } + +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/SecurityUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/SecurityUtils.java new file mode 100644 index 000000000..a63c8cfd5 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/SecurityUtils.java @@ -0,0 +1,99 @@ +package com.jsowell.common.util; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import com.jsowell.common.constant.HttpStatus; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.exception.ServiceException; + +/** + * 瀹夊叏鏈嶅姟宸ュ叿绫 + * + * @author jsowell + */ +public class SecurityUtils { + /** + * 鐢ㄦ埛ID + **/ + public static Long getUserId() { + try { + return getLoginUser().getUserId(); + } catch (Exception e) { + throw new ServiceException("鑾峰彇鐢ㄦ埛ID寮傚父", HttpStatus.UNAUTHORIZED); + } + } + + /** + * 鑾峰彇閮ㄩ棬ID + **/ + public static Long getDeptId() { + try { + return getLoginUser().getDeptId(); + } catch (Exception e) { + throw new ServiceException("鑾峰彇閮ㄩ棬ID寮傚父", HttpStatus.UNAUTHORIZED); + } + } + + /** + * 鑾峰彇鐢ㄦ埛璐︽埛 + **/ + public static String getUsername() { + try { + return getLoginUser().getUsername(); + } catch (Exception e) { + throw new ServiceException("鑾峰彇鐢ㄦ埛璐︽埛寮傚父", HttpStatus.UNAUTHORIZED); + } + } + + /** + * 鑾峰彇鐢ㄦ埛 + **/ + public static LoginUser getLoginUser() { + try { + return (LoginUser) getAuthentication().getPrincipal(); + } catch (Exception e) { + throw new ServiceException("鑾峰彇鐢ㄦ埛淇℃伅寮傚父", HttpStatus.UNAUTHORIZED); + } + } + + /** + * 鑾峰彇Authentication + */ + public static Authentication getAuthentication() { + return SecurityContextHolder.getContext().getAuthentication(); + } + + /** + * 鐢熸垚BCryptPasswordEncoder瀵嗙爜 + * + * @param password 瀵嗙爜 + * @return 鍔犲瘑瀛楃涓 + */ + public static String encryptPassword(String password) { + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + return passwordEncoder.encode(password); + } + + /** + * 鍒ゆ柇瀵嗙爜鏄惁鐩稿悓 + * + * @param rawPassword 鐪熷疄瀵嗙爜 + * @param encodedPassword 鍔犲瘑鍚庡瓧绗 + * @return 缁撴灉 + */ + public static boolean matchesPassword(String rawPassword, String encodedPassword) { + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + return passwordEncoder.matches(rawPassword, encodedPassword); + } + + /** + * 鏄惁涓虹鐞嗗憳 + * + * @param userId 鐢ㄦ埛ID + * @return 缁撴灉 + */ + public static boolean isAdmin(Long userId) { + return userId != null && 1L == userId; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/ServletUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/ServletUtils.java new file mode 100644 index 000000000..2b0e7ba6f --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/ServletUtils.java @@ -0,0 +1,160 @@ +package com.jsowell.common.util; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.text.Convert; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; + +/** + * 瀹㈡埛绔伐鍏风被 + * + * @author jsowell + */ +public class ServletUtils { + /** + * 鑾峰彇String鍙傛暟 + */ + public static String getParameter(String name) { + return getRequest().getParameter(name); + } + + /** + * 鑾峰彇String鍙傛暟 + */ + public static String getParameter(String name, String defaultValue) { + return Convert.toStr(getRequest().getParameter(name), defaultValue); + } + + /** + * 鑾峰彇Integer鍙傛暟 + */ + public static Integer getParameterToInt(String name) { + return Convert.toInt(getRequest().getParameter(name)); + } + + /** + * 鑾峰彇Integer鍙傛暟 + */ + public static Integer getParameterToInt(String name, Integer defaultValue) { + return Convert.toInt(getRequest().getParameter(name), defaultValue); + } + + /** + * 鑾峰彇Boolean鍙傛暟 + */ + public static Boolean getParameterToBool(String name) { + return Convert.toBool(getRequest().getParameter(name)); + } + + /** + * 鑾峰彇Boolean鍙傛暟 + */ + public static Boolean getParameterToBool(String name, Boolean defaultValue) { + return Convert.toBool(getRequest().getParameter(name), defaultValue); + } + + /** + * 鑾峰彇request + */ + public static HttpServletRequest getRequest() { + return getRequestAttributes().getRequest(); + } + + /** + * 鑾峰彇response + */ + public static HttpServletResponse getResponse() { + return getRequestAttributes().getResponse(); + } + + /** + * 鑾峰彇session + */ + public static HttpSession getSession() { + return getRequest().getSession(); + } + + public static ServletRequestAttributes getRequestAttributes() { + RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); + return (ServletRequestAttributes) attributes; + } + + /** + * 灏嗗瓧绗︿覆娓叉煋鍒板鎴风 + * + * @param response 娓叉煋瀵硅薄 + * @param string 寰呮覆鏌撶殑瀛楃涓 + */ + public static void renderString(HttpServletResponse response, String string) { + try { + response.setStatus(200); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + response.getWriter().print(string); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 鏄惁鏄疉jax寮傛璇锋眰 + * + * @param request + */ + public static boolean isAjaxRequest(HttpServletRequest request) { + String accept = request.getHeader("accept"); + if (accept != null && accept.contains("application/json")) { + return true; + } + + String xRequestedWith = request.getHeader("X-Requested-With"); + if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) { + return true; + } + + String uri = request.getRequestURI(); + if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml")) { + return true; + } + + String ajax = request.getParameter("__ajax"); + return StringUtils.inStringIgnoreCase(ajax, "json", "xml"); + } + + /** + * 鍐呭缂栫爜 + * + * @param str 鍐呭 + * @return 缂栫爜鍚庣殑鍐呭 + */ + public static String urlEncode(String str) { + try { + return URLEncoder.encode(str, Constants.UTF8); + } catch (UnsupportedEncodingException e) { + return StringUtils.EMPTY; + } + } + + /** + * 鍐呭瑙g爜 + * + * @param str 鍐呭 + * @return 瑙g爜鍚庣殑鍐呭 + */ + public static String urlDecode(String str) { + try { + return URLDecoder.decode(str, Constants.UTF8); + } catch (UnsupportedEncodingException e) { + return StringUtils.EMPTY; + } + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/StringUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/StringUtils.java new file mode 100644 index 000000000..bd10649d7 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/StringUtils.java @@ -0,0 +1,561 @@ +package com.jsowell.common.util; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.text.StrFormatter; +import org.springframework.util.AntPathMatcher; + +import java.util.*; + +/** + * 瀛楃涓插伐鍏风被 + * + * @author jsowell + */ +public class StringUtils extends org.apache.commons.lang3.StringUtils { + /** + * 绌哄瓧绗︿覆 + */ + private static final String NULL_STR = ""; + + /** + * 涓嬪垝绾 + */ + private static final char SEPARATOR = '_'; + + /** + * 鑾峰彇鍙傛暟涓嶄负绌哄 + * + * @param value defaultValue 瑕佸垽鏂殑value + * @return value 杩斿洖鍊 + */ + public static T nvl(T value, T defaultValue) { + return value != null ? value : defaultValue; + } + + /** + * * 鍒ゆ柇涓涓狢ollection鏄惁涓虹┖锛 鍖呭惈List锛孲et锛孮ueue + * + * @param coll 瑕佸垽鏂殑Collection + * @return true锛氫负绌 false锛氶潪绌 + */ + public static boolean isEmpty(Collection coll) { + return isNull(coll) || coll.isEmpty(); + } + + /** + * * 鍒ゆ柇涓涓狢ollection鏄惁闈炵┖锛屽寘鍚獿ist锛孲et锛孮ueue + * + * @param coll 瑕佸垽鏂殑Collection + * @return true锛氶潪绌 false锛氱┖ + */ + public static boolean isNotEmpty(Collection coll) { + return !isEmpty(coll); + } + + /** + * * 鍒ゆ柇涓涓璞℃暟缁勬槸鍚︿负绌 + * + * @param objects 瑕佸垽鏂殑瀵硅薄鏁扮粍 + * * @return true锛氫负绌 false锛氶潪绌 + */ + public static boolean isEmpty(Object[] objects) { + return isNull(objects) || (objects.length == 0); + } + + /** + * * 鍒ゆ柇涓涓璞℃暟缁勬槸鍚﹂潪绌 + * + * @param objects 瑕佸垽鏂殑瀵硅薄鏁扮粍 + * @return true锛氶潪绌 false锛氱┖ + */ + public static boolean isNotEmpty(Object[] objects) { + return !isEmpty(objects); + } + + /** + * * 鍒ゆ柇涓涓狹ap鏄惁涓虹┖ + * + * @param map 瑕佸垽鏂殑Map + * @return true锛氫负绌 false锛氶潪绌 + */ + public static boolean isEmpty(Map map) { + return isNull(map) || map.isEmpty(); + } + + /** + * * 鍒ゆ柇涓涓狹ap鏄惁涓虹┖ + * + * @param map 瑕佸垽鏂殑Map + * @return true锛氶潪绌 false锛氱┖ + */ + public static boolean isNotEmpty(Map map) { + return !isEmpty(map); + } + + /** + * * 鍒ゆ柇涓涓瓧绗︿覆鏄惁涓虹┖涓 + * + * @param str String + * @return true锛氫负绌 false锛氶潪绌 + */ + public static boolean isEmpty(String str) { + return isNull(str) || NULL_STR.equals(str.trim()); + } + + /** + * * 鍒ゆ柇涓涓瓧绗︿覆鏄惁涓洪潪绌轰覆 + * + * @param str String + * @return true锛氶潪绌轰覆 false锛氱┖涓 + */ + public static boolean isNotEmpty(String str) { + return !isEmpty(str); + } + + /** + * * 鍒ゆ柇涓涓璞℃槸鍚︿负绌 + * + * @param object Object + * @return true锛氫负绌 false锛氶潪绌 + */ + public static boolean isNull(Object object) { + return object == null; + } + + /** + * * 鍒ゆ柇涓涓璞℃槸鍚﹂潪绌 + * + * @param object Object + * @return true锛氶潪绌 false锛氱┖ + */ + public static boolean isNotNull(Object object) { + return !isNull(object); + } + + /** + * 鍘荤┖鏍 + */ + public static String trim(String str) { + return (str == null ? "" : str.trim()); + } + + /** + * 鎴彇瀛楃涓 + * + * @param str 瀛楃涓 + * @param start 寮濮 + * @return 缁撴灉 + */ + public static String substring(final String str, int start) { + if (str == null) { + return NULL_STR; + } + if (start < 0) { + start = str.length() + start; + } + if (start < 0) { + start = 0; + } + if (start > str.length()) { + return NULL_STR; + } + return str.substring(start); + } + + /** + * 鎴彇瀛楃涓 + * + * @param str 瀛楃涓 + * @param start 寮濮 + * @param end 缁撴潫 + * @return 缁撴灉 + */ + public static String substring(final String str, int start, int end) { + if (str == null) { + return NULL_STR; + } + if (end < 0) { + end = str.length() + end; + } + if (start < 0) { + start = str.length() + start; + } + if (end > str.length()) { + end = str.length(); + } + if (start > end) { + return NULL_STR; + } + if (start < 0) { + start = 0; + } + if (end < 0) { + end = 0; + } + return str.substring(start, end); + } + + /** + * 鏍煎紡鍖栨枃鏈, {} 琛ㄧず鍗犱綅绗
+ * 姝ゆ柟娉曞彧鏄畝鍗曞皢鍗犱綅绗 {} 鎸夌収椤哄簭鏇挎崲涓哄弬鏁
+ * 濡傛灉鎯宠緭鍑 {} 浣跨敤 \\杞箟 { 鍗冲彲锛屽鏋滄兂杈撳嚭 {} 涔嬪墠鐨 \ 浣跨敤鍙岃浆涔夌 \\\\ 鍗冲彲
+ * 渚嬶細
+ * 閫氬父浣跨敤锛歠ormat("this is {} for {}", "a", "b") -> this is a for b
+ * 杞箟{}锛 format("this is \\{} for {}", "a", "b") -> this is \{} for a
+ * 杞箟\锛 format("this is \\\\{} for {}", "a", "b") -> this is \a for b
+ * + * @param template 鏂囨湰妯℃澘锛岃鏇挎崲鐨勯儴鍒嗙敤 {} 琛ㄧず + * @param params 鍙傛暟鍊 + * @return 鏍煎紡鍖栧悗鐨勬枃鏈 + */ + public static String format(String template, Object... params) { + if (isEmpty(params) || isEmpty(template)) { + return template; + } + return StrFormatter.format(template, params); + } + + /** + * 鏄惁涓篽ttp(s)://寮澶 + * + * @param link 閾炬帴 + * @return 缁撴灉 + */ + public static boolean isHttp(String link) { + return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS); + } + + /** + * 瀛楃涓茶浆set + * + * @param str 瀛楃涓 + * @param sep 鍒嗛殧绗 + * @return set闆嗗悎 + */ + public static Set str2Set(String str, String sep) { + return new HashSet(str2List(str, sep, true, false)); + } + + /** + * 瀛楃涓茶浆list + * + * @param str 瀛楃涓 + * @param sep 鍒嗛殧绗 + * @param filterBlank 杩囨护绾┖鐧 + * @param trim 鍘绘帀棣栧熬绌虹櫧 + * @return list闆嗗悎 + */ + public static List str2List(String str, String sep, boolean filterBlank, boolean trim) { + List list = new ArrayList(); + if (StringUtils.isEmpty(str)) { + return list; + } + + // 杩囨护绌虹櫧瀛楃涓 + if (filterBlank && StringUtils.isBlank(str)) { + return list; + } + String[] split = str.split(sep); + for (String string : split) { + if (filterBlank && StringUtils.isBlank(string)) { + continue; + } + if (trim) { + string = string.trim(); + } + list.add(string); + } + + return list; + } + + /** + * 鏌ユ壘鎸囧畾瀛楃涓叉槸鍚﹀寘鍚寚瀹氬瓧绗︿覆鍒楄〃涓殑浠绘剰涓涓瓧绗︿覆鍚屾椂涓插拷鐣ュぇ灏忓啓 + * + * @param cs 鎸囧畾瀛楃涓 + * @param searchCharSequences 闇瑕佹鏌ョ殑瀛楃涓叉暟缁 + * @return 鏄惁鍖呭惈浠绘剰涓涓瓧绗︿覆 + */ + public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) { + if (isEmpty(cs) || isEmpty(searchCharSequences)) { + return false; + } + for (CharSequence testStr : searchCharSequences) { + if (containsIgnoreCase(cs, testStr)) { + return true; + } + } + return false; + } + + /** + * 椹煎嘲杞笅鍒掔嚎鍛藉悕 + */ + public static String toUnderScoreCase(String str) { + if (str == null) { + return null; + } + StringBuilder sb = new StringBuilder(); + // 鍓嶇疆瀛楃鏄惁澶у啓 + boolean preCharIsUpperCase = true; + // 褰撳墠瀛楃鏄惁澶у啓 + boolean curreCharIsUpperCase = true; + // 涓嬩竴瀛楃鏄惁澶у啓 + boolean nexteCharIsUpperCase = true; + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + if (i > 0) { + preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1)); + } else { + preCharIsUpperCase = false; + } + curreCharIsUpperCase = Character.isUpperCase(c); + if (i < (str.length() - 1)) { + nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); + } + if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) { + sb.append(SEPARATOR); + } else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) { + sb.append(SEPARATOR); + } + sb.append(Character.toLowerCase(c)); + } + + return sb.toString(); + } + + /** + * 鏄惁鍖呭惈瀛楃涓 + * + * @param str 楠岃瘉瀛楃涓 + * @param strs 瀛楃涓茬粍 + * @return 鍖呭惈杩斿洖true + */ + public static boolean inStringIgnoreCase(String str, String... strs) { + if (str != null && strs != null) { + for (String s : strs) { + if (str.equalsIgnoreCase(trim(s))) { + return true; + } + } + } + return false; + } + + /** + * 灏嗕笅鍒掔嚎澶у啓鏂瑰紡鍛藉悕鐨勫瓧绗︿覆杞崲涓洪┘宄板紡銆傚鏋滆浆鎹㈠墠鐨勪笅鍒掔嚎澶у啓鏂瑰紡鍛藉悕鐨勫瓧绗︿覆涓虹┖锛屽垯杩斿洖绌哄瓧绗︿覆銆 渚嬪锛欻ELLO_WORLD->HelloWorld + * + * @param name 杞崲鍓嶇殑涓嬪垝绾垮ぇ鍐欐柟寮忓懡鍚嶇殑瀛楃涓 + * @return 杞崲鍚庣殑椹煎嘲寮忓懡鍚嶇殑瀛楃涓 + */ + public static String convertToCamelCase(String name) { + StringBuilder result = new StringBuilder(); + // 蹇熸鏌 + if (name == null || name.isEmpty()) { + // 娌″繀瑕佽浆鎹 + return ""; + } else if (!name.contains("_")) { + // 涓嶅惈涓嬪垝绾匡紝浠呭皢棣栧瓧姣嶅ぇ鍐 + return name.substring(0, 1).toUpperCase() + name.substring(1); + } + // 鐢ㄤ笅鍒掔嚎灏嗗師濮嬪瓧绗︿覆鍒嗗壊 + String[] camels = name.split("_"); + for (String camel : camels) { + // 璺宠繃鍘熷瀛楃涓蹭腑寮澶淬佺粨灏剧殑涓嬫崲绾挎垨鍙岄噸涓嬪垝绾 + if (camel.isEmpty()) { + continue; + } + // 棣栧瓧姣嶅ぇ鍐 + result.append(camel.substring(0, 1).toUpperCase()); + result.append(camel.substring(1).toLowerCase()); + } + return result.toString(); + } + + /** + * 椹煎嘲寮忓懡鍚嶆硶 渚嬪锛歶ser_name->userName + */ + public static String toCamelCase(String s) { + if (s == null) { + return null; + } + s = s.toLowerCase(); + StringBuilder sb = new StringBuilder(s.length()); + boolean upperCase = false; + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + + if (c == SEPARATOR) { + upperCase = true; + } else if (upperCase) { + sb.append(Character.toUpperCase(c)); + upperCase = false; + } else { + sb.append(c); + } + } + return sb.toString(); + } + + /** + * 鏌ユ壘鎸囧畾瀛楃涓叉槸鍚﹀尮閰嶆寚瀹氬瓧绗︿覆鍒楄〃涓殑浠绘剰涓涓瓧绗︿覆 + * + * @param str 鎸囧畾瀛楃涓 + * @param strs 闇瑕佹鏌ョ殑瀛楃涓叉暟缁 + * @return 鏄惁鍖归厤 + */ + public static boolean matches(String str, List strs) { + if (isEmpty(str) || isEmpty(strs)) { + return false; + } + for (String pattern : strs) { + if (isMatch(pattern, str)) { + return true; + } + } + return false; + } + + /** + * 鍒ゆ柇url鏄惁涓庤鍒欓厤缃: + * ? 琛ㄧず鍗曚釜瀛楃; + * * 琛ㄧず涓灞傝矾寰勫唴鐨勪换鎰忓瓧绗︿覆锛屼笉鍙法灞傜骇; + * ** 琛ㄧず浠绘剰灞傝矾寰; + * + * @param pattern 鍖归厤瑙勫垯 + * @param url 闇瑕佸尮閰嶇殑url + * @return + */ + public static boolean isMatch(String pattern, String url) { + AntPathMatcher matcher = new AntPathMatcher(); + return matcher.match(pattern, url); + } + + @SuppressWarnings("unchecked") + public static T cast(Object obj) { + return (T) obj; + } + + /** + * 鏁板瓧宸﹁竟琛ラ綈0锛屼娇涔嬭揪鍒版寚瀹氶暱搴︺傛敞鎰忥紝濡傛灉鏁板瓧杞崲涓哄瓧绗︿覆鍚庯紝闀垮害澶т簬size锛屽垯鍙繚鐣 鏈鍚巗ize涓瓧绗︺ + * + * @param num 鏁板瓧瀵硅薄 + * @param size 瀛楃涓叉寚瀹氶暱搴 + * @return 杩斿洖鏁板瓧鐨勫瓧绗︿覆鏍煎紡锛岃瀛楃涓蹭负鎸囧畾闀垮害銆 + */ + public static String padl(final Number num, final int size) { + return padl(num.toString(), size, '0'); + } + + /** + * 瀛楃涓插乏琛ラ綈銆傚鏋滃師濮嬪瓧绗︿覆s闀垮害澶т簬size锛屽垯鍙繚鐣欐渶鍚巗ize涓瓧绗︺ + * + * @param s 鍘熷瀛楃涓 + * @param size 瀛楃涓叉寚瀹氶暱搴 + * @param c 鐢ㄤ簬琛ラ綈鐨勫瓧绗 + * @return 杩斿洖鎸囧畾闀垮害鐨勫瓧绗︿覆锛岀敱鍘熷瓧绗︿覆宸﹁ˉ榻愭垨鎴彇寰楀埌銆 + */ + public static String padl(final String s, final int size, final char c) { + final StringBuilder sb = new StringBuilder(size); + if (s != null) { + final int len = s.length(); + if (s.length() <= size) { + for (int i = size - len; i > 0; i--) { + sb.append(c); + } + sb.append(s); + } else { + return s.substring(len - size, len); + } + } else { + for (int i = size; i > 0; i--) { + sb.append(c); + } + } + return sb.toString(); + } + + /** + * 16杩涘埗琛ㄧず鐨勫瓧绗︿覆杞崲涓哄瓧鑺傛暟缁 + * + * @param s 16杩涘埗琛ㄧず鐨勫瓧绗︿覆 + * @return byte[] 瀛楄妭鏁扮粍 + */ + public static int[] hexStringToIntArray(String s) { + int len = s.length(); + int[] b = new int[len / 2]; + for (int i = 0; i < len; i += 2) { + // 涓や綅涓缁勶紝琛ㄧず涓涓瓧鑺,鎶婅繖鏍疯〃绀虹殑16杩涘埗瀛楃涓诧紝杩樺師鎴愪竴涓瓧鑺 + b[i / 2] = (int) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); + } + return b; + } + + /** + * int杞崲鎴16杩涘埗瀛楃涓 + * + * @param b 闇瑕佽浆鎹㈢殑int鍊 + * @return 16杩涘埗鐨凷tring + */ + public static String toHexString(int b) { + String hex = Integer.toHexString(b & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + return "0x" + hex.toUpperCase(); + } + + /** + * 瀛楄妭鏁扮粍杞崲鎴怱tring锛屾寚瀹氶暱搴﹁浆鎹㈤暱搴 + * + * @param arrBytes + * @param count 杞崲闀垮害 + * @param blank 瑕佷笉瑕佺┖鏍硷紙姣忎釜byte瀛楄妭锛屾渶鏄惁鐢ㄤ竴涓 鈥濋殧寮锛 + * @return "" | arrBytes鎹㈡垚鐨勫瓧绗︿覆锛堜笉瀛樺湪null锛 + */ + public static String byteArray2HexString(byte[] arrBytes, int count, boolean blank) { + String ret = ""; + if (arrBytes == null || arrBytes.length < 1) + return ret; + if (count > arrBytes.length) + count = arrBytes.length; + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < count; i++) { + ret = Integer.toHexString(arrBytes[i] & 0xFF).toUpperCase(); + if (ret.length() == 1) + builder.append("0").append(ret); + else + builder.append(ret); + if (blank) + builder.append(" "); + } + return builder.toString(); + } + + /** + * 灏嗗瓧鑺傛暟缁勮浆鎹㈡垚16杩涘埗瀛楃涓 + * + * @param array 闇瑕佽浆鎹㈢殑瀛楃涓(瀛楄妭闂存病鏈夊垎闅旂) + * @return 杞崲瀹屾垚鐨勫瓧绗︿覆 + */ + public static String byteArrayToHexString(byte[] array) { + return byteArray2HexString(array, Integer.MAX_VALUE, false); + } + + /** + * 灏嗕袱涓狝SCII瀛楃鍚堟垚涓涓瓧鑺傦紱 濡傦細"EF"--> 0xEF + * + * @param src0 byte + * @param src1 byte + * @return byte + */ + public static byte uniteBytes(byte src0, byte src1) { + byte _b0 = Byte.decode("0x" + new String(new byte[]{src0})); + _b0 = (byte) (_b0 << 4); + byte _b1 = Byte.decode("0x" + new String(new byte[]{src1})); + byte ret = (byte) (_b0 ^ _b1); + return ret; + } + +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/Threads.java b/jsowell-common/src/main/java/com/jsowell/common/util/Threads.java new file mode 100644 index 000000000..5300165d4 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/Threads.java @@ -0,0 +1,77 @@ +package com.jsowell.common.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +/** + * 绾跨▼鐩稿叧宸ュ叿绫. + * + * @author jsowell + */ +public class Threads { + private static final Logger logger = LoggerFactory.getLogger(Threads.class); + + /** + * sleep绛夊緟,鍗曚綅涓烘绉 + */ + public static void sleep(long milliseconds) { + try { + Thread.sleep(milliseconds); + } catch (InterruptedException e) { + return; + } + } + + /** + * 鍋滄绾跨▼姹 + * 鍏堜娇鐢╯hutdown, 鍋滄鎺ユ敹鏂颁换鍔″苟灏濊瘯瀹屾垚鎵鏈夊凡瀛樺湪浠诲姟. + * 濡傛灉瓒呮椂, 鍒欒皟鐢╯hutdownNow, 鍙栨秷鍦╳orkQueue涓璓ending鐨勪换鍔,骞朵腑鏂墍鏈夐樆濉炲嚱鏁. + * 濡傛灉浠嶇劧瓒呮檪锛屽墖寮峰埗閫鍑. + * 鍙﹀鍦╯hutdown鏃剁嚎绋嬫湰韬璋冪敤涓柇鍋氫簡澶勭悊. + */ + public static void shutdownAndAwaitTermination(ExecutorService pool) { + if (pool != null && !pool.isShutdown()) { + pool.shutdown(); + try { + if (!pool.awaitTermination(120, TimeUnit.SECONDS)) { + pool.shutdownNow(); + if (!pool.awaitTermination(120, TimeUnit.SECONDS)) { + logger.info("Pool did not terminate"); + } + } + } catch (InterruptedException ie) { + pool.shutdownNow(); + Thread.currentThread().interrupt(); + } + } + } + + /** + * 鎵撳嵃绾跨▼寮傚父淇℃伅 + */ + public static void printException(Runnable r, Throwable t) { + if (t == null && r instanceof Future) { + try { + Future future = (Future) r; + if (future.isDone()) { + future.get(); + } + } catch (CancellationException ce) { + t = ce; + } catch (ExecutionException ee) { + t = ee.getCause(); + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + } + } + if (t != null) { + logger.error(t.getMessage(), t); + } + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java new file mode 100644 index 000000000..d2bf30db6 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java @@ -0,0 +1,136 @@ +package com.jsowell.common.util; + +import com.google.common.primitives.Bytes; +import lombok.extern.slf4j.Slf4j; + +import javax.xml.bind.DatatypeConverter; +import java.math.BigDecimal; +import java.util.Arrays; + +@Slf4j +public class YKCUtils { + + private static final BigDecimal multiple = new BigDecimal("100000"); + + /** + * 鏍¢獙浜戝揩鍏呰姹傛暟鎹牸寮 + * + * @param msg 璇锋眰鎶ユ枃 + * @return + */ + public static boolean checkMsg(byte[] msg) { + // 璧峰鏍囧織 + byte[] head = BytesUtil.copyBytes(msg, 0, 1); + // 鏁版嵁闀垮害 + byte[] length = BytesUtil.copyBytes(msg, 1, 1); + // 搴忓垪鍙峰煙 + byte[] serialNumber = BytesUtil.copyBytes(msg, 2, 2); + // 鍔犲瘑鏍囧織 + byte[] encryptFlag = BytesUtil.copyBytes(msg, 4, 1); + // 甯х被鍨嬫爣蹇 + byte[] frameType = BytesUtil.copyBytes(msg, 5, 1); + // 娑堟伅浣 + byte[] msgBody = BytesUtil.copyBytes(msg, 6, msg.length - 8); + // 甯ф牎楠屽煙 + byte[] crcByte = new byte[]{msg[msg.length - 2], msg[msg.length - 1]}; + + //璧峰浣嶅繀椤绘槸0x68 + if (0x68 != head[0]) { + log.error("璧峰浣嶅繀椤绘槸0x68"); + return false; + } + // 搴忓垪鍙峰煙+鍔犲瘑鏍囧織+甯х被鍨嬫爣蹇+娑堟伅浣 + byte[] data = Bytes.concat(serialNumber, encryptFlag, frameType, msgBody); + // 鏍¢獙闀垮害 + if (data.length != BytesUtil.bytesToIntLittle(length)) { + log.error("鏁版嵁闀垮害涓嶆纭"); + return false; + } + // CRC鏍¢獙 source target + String sourceCRC = String.format("%04x", BytesUtil.bytesToInt(crcByte, 0)); + String targetCRC = String.format("%04x", CRC16Util.calcCrc16(data)); + String oldTargetCRC = String.format("%04x", CRC16Util.calcCrc16Old(data)); + if (!sourceCRC.equalsIgnoreCase(targetCRC)) { + log.error("CRC鏍¢獙涓嶉氳繃, 婧恈rc:{}, 璁$畻寰楀嚭crc:{}, 鑰乧rc璁$畻:{}, 甯х被鍨:{}, 鎶ユ枃锛歿}, msg:{}" + , sourceCRC, targetCRC, oldTargetCRC, YKCUtils.frameType2Str(frameType), BytesUtil.binary(msg, 16), Arrays.toString(msg)); + return false; + } + return true; + } + + /** + * 杞崲鐢靛帇鐢垫祦浠ュ強璧峰soc + * 绮剧‘鍒板皬鏁扮偣鍚庝竴浣嶏紱寰呮満缃浂 + * + * @param bytes + * @return + */ + public static String convertVoltageCurrent(byte[] bytes) { + // 杞崲涓篿nt 鏈鍚庝竴浣嶆槸灏忔暟浣 + int i = BytesUtil.bytesToIntLittle(bytes); + // 浣跨敤BigDecimal + BigDecimal bigDecimal = new BigDecimal(i); + BigDecimal divide = bigDecimal.divide(new BigDecimal(10), 1, BigDecimal.ROUND_UP); + return divide.toString(); + } + + /** + * 杞崲灏忔暟鐐 + * + * @param bytes + * @param scale 灏忔暟浣 + * @return + */ + public static String convertDecimalPoint(byte[] bytes, int scale) { + // 杞崲涓篿nt + int i = BytesUtil.bytesToIntLittle(bytes); + // 浣跨敤BigDecimal + BigDecimal bigDecimal = new BigDecimal(i); + BigDecimal divide = bigDecimal.divide(BigDecimal.valueOf(Math.pow(10d, scale)), scale, BigDecimal.ROUND_UP); + return divide.toString(); + } + + /** + * 鑾峰彇浠锋牸byte鏁扮粍 + * 浠锋牸杞崲涓篵yte鏁扮粍 + * @param price 瀹為檯浠锋牸锛屽崟浣嶅厓 + * @param scale 淇濈暀灏忔暟浣 + * @return + */ + public static byte[] getPriceByte(String price, int scale) { + // 淇濈暀灏忔暟浣 渚:淇濈暀5浣嶅皬鏁帮紝闇瑕佷箻浠10鐨5娆℃柟 + BigDecimal value = BigDecimal.valueOf(Math.pow(10d, scale)); + int i = new BigDecimal(price).multiply(value).intValue(); + return BytesUtil.intToBytesLittle(i, 4); + } + + /** + * byte杞抚绫诲瀷瀛楃涓 + * @param bytes + * @return + */ + public static String frameType2Str(byte[] bytes) { + String s = BytesUtil.bin2HexStr(bytes); + return "0x" + s; + } + + public static void main(String[] args) { + // String hexString = "681E0000003388000000000027012302081602434533880000000000270101008361"; + // byte[] byteArray = new byte[hexString.length() / 2]; + // for (int i = 0; i < byteArray.length; i++) { + // int index = i * 2; + // int j = Integer.parseInt(hexString.substring(index, index + 2), 16); + // byteArray[i] = (byte) j; + // } + // System.out.println(byteArray); + // String binary = BytesUtil.binary(byteArray, 16); + // String aaa = DatatypeConverter.printHexBinary(byteArray); + // System.out.println(binary); + // System.out.println(aaa); + + String hexString = "680d3c4000038800000000002701001568"; + byte[] bytes = BytesUtil.hexStringToByteArray(hexString); + System.out.println(checkMsg(bytes)); + + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/bean/BeanUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/bean/BeanUtils.java new file mode 100644 index 000000000..8a45b2f7c --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/bean/BeanUtils.java @@ -0,0 +1,104 @@ +package com.jsowell.common.util.bean; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Bean 宸ュ叿绫 + * + * @author jsowell + */ +public class BeanUtils extends org.springframework.beans.BeanUtils { + /** + * Bean鏂规硶鍚嶄腑灞炴у悕寮濮嬬殑涓嬫爣 + */ + private static final int BEAN_METHOD_PROP_INDEX = 3; + + /** + * 鍖归厤getter鏂规硶鐨勬鍒欒〃杈惧紡 + */ + private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)"); + + /** + * 鍖归厤setter鏂规硶鐨勬鍒欒〃杈惧紡 + */ + private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)"); + + /** + * Bean灞炴у鍒跺伐鍏锋柟娉曘 + * + * @param dest 鐩爣瀵硅薄 + * @param src 婧愬璞 + */ + public static void copyBeanProp(Object dest, Object src) { + try { + copyProperties(src, dest); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 鑾峰彇瀵硅薄鐨剆etter鏂规硶銆 + * + * @param obj 瀵硅薄 + * @return 瀵硅薄鐨剆etter鏂规硶鍒楄〃 + */ + public static List getSetterMethods(Object obj) { + // setter鏂规硶鍒楄〃 + List setterMethods = new ArrayList(); + + // 鑾峰彇鎵鏈夋柟娉 + Method[] methods = obj.getClass().getMethods(); + + // 鏌ユ壘setter鏂规硶 + + for (Method method : methods) { + Matcher m = SET_PATTERN.matcher(method.getName()); + if (m.matches() && (method.getParameterTypes().length == 1)) { + setterMethods.add(method); + } + } + // 杩斿洖setter鏂规硶鍒楄〃 + return setterMethods; + } + + /** + * 鑾峰彇瀵硅薄鐨刧etter鏂规硶銆 + * + * @param obj 瀵硅薄 + * @return 瀵硅薄鐨刧etter鏂规硶鍒楄〃 + */ + + public static List getGetterMethods(Object obj) { + // getter鏂规硶鍒楄〃 + List getterMethods = new ArrayList(); + // 鑾峰彇鎵鏈夋柟娉 + Method[] methods = obj.getClass().getMethods(); + // 鏌ユ壘getter鏂规硶 + for (Method method : methods) { + Matcher m = GET_PATTERN.matcher(method.getName()); + if (m.matches() && (method.getParameterTypes().length == 0)) { + getterMethods.add(method); + } + } + // 杩斿洖getter鏂规硶鍒楄〃 + return getterMethods; + } + + /** + * 妫鏌ean鏂规硶鍚嶄腑鐨勫睘鎬у悕鏄惁鐩哥瓑銆
+ * 濡俫etName()鍜宻etName()灞炴у悕涓鏍凤紝getName()鍜宻etAge()灞炴у悕涓嶄竴鏍枫 + * + * @param m1 鏂规硶鍚1 + * @param m2 鏂规硶鍚2 + * @return 灞炴у悕涓鏍疯繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse + */ + + public static boolean isMethodPropEquals(String m1, String m2) { + return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX)); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/bean/BeanValidators.java b/jsowell-common/src/main/java/com/jsowell/common/util/bean/BeanValidators.java new file mode 100644 index 000000000..5f425abfd --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/bean/BeanValidators.java @@ -0,0 +1,21 @@ +package com.jsowell.common.util.bean; + +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.validation.Validator; +import java.util.Set; + +/** + * bean瀵硅薄灞炴ч獙璇 + * + * @author jsowell + */ +public class BeanValidators { + public static void validateWithException(Validator validator, Object object, Class... groups) + throws ConstraintViolationException { + Set> constraintViolations = validator.validate(object, groups); + if (!constraintViolations.isEmpty()) { + throw new ConstraintViolationException(constraintViolations); + } + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/file/FileTypeUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/file/FileTypeUtils.java new file mode 100644 index 000000000..17d5f0a61 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/file/FileTypeUtils.java @@ -0,0 +1,64 @@ +package com.jsowell.common.util.file; + +import org.apache.commons.lang3.StringUtils; + +import java.io.File; + +/** + * 鏂囦欢绫诲瀷宸ュ叿绫 + * + * @author jsowell + */ +public class FileTypeUtils { + /** + * 鑾峰彇鏂囦欢绫诲瀷 + *

+ * 渚嬪: jsowell.txt, 杩斿洖: txt + * + * @param file 鏂囦欢鍚 + * @return 鍚庣紑锛堜笉鍚".") + */ + public static String getFileType(File file) { + if (null == file) { + return StringUtils.EMPTY; + } + return getFileType(file.getName()); + } + + /** + * 鑾峰彇鏂囦欢绫诲瀷 + *

+ * 渚嬪: jsowell.txt, 杩斿洖: txt + * + * @param fileName 鏂囦欢鍚 + * @return 鍚庣紑锛堜笉鍚".") + */ + public static String getFileType(String fileName) { + int separatorIndex = fileName.lastIndexOf("."); + if (separatorIndex < 0) { + return ""; + } + return fileName.substring(separatorIndex + 1).toLowerCase(); + } + + /** + * 鑾峰彇鏂囦欢绫诲瀷 + * + * @param photoByte 鏂囦欢瀛楄妭鐮 + * @return 鍚庣紑锛堜笉鍚".") + */ + public static String getFileExtendName(byte[] photoByte) { + String strFileExtendName = "JPG"; + if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56) + && ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97)) { + strFileExtendName = "GIF"; + } else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70)) { + strFileExtendName = "JPG"; + } else if ((photoByte[0] == 66) && (photoByte[1] == 77)) { + strFileExtendName = "BMP"; + } else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71)) { + strFileExtendName = "PNG"; + } + return strFileExtendName; + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/file/FileUploadUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/file/FileUploadUtils.java new file mode 100644 index 000000000..b5c961e9a --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/file/FileUploadUtils.java @@ -0,0 +1,198 @@ +package com.jsowell.common.util.file; + +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.exception.file.FileNameLengthLimitExceededException; +import com.jsowell.common.exception.file.FileSizeLimitExceededException; +import com.jsowell.common.exception.file.InvalidExtensionException; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.Seq; +import org.apache.commons.io.FilenameUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.Objects; + +/** + * 鏂囦欢涓婁紶宸ュ叿绫 + * + * @author jsowell + */ +public class FileUploadUtils { + /** + * 榛樿澶у皬 50M + */ + public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024; + + /** + * 榛樿鐨勬枃浠跺悕鏈澶ч暱搴 100 + */ + public static final int DEFAULT_FILE_NAME_LENGTH = 100; + + /** + * 榛樿涓婁紶鐨勫湴鍧 + */ + private static String defaultBaseDir = JsowellConfig.getProfile(); + + public static void setDefaultBaseDir(String defaultBaseDir) { + FileUploadUtils.defaultBaseDir = defaultBaseDir; + } + + public static String getDefaultBaseDir() { + return defaultBaseDir; + } + + /** + * 浠ラ粯璁ら厤缃繘琛屾枃浠朵笂浼 + * + * @param file 涓婁紶鐨勬枃浠 + * @return 鏂囦欢鍚嶇О + * @throws Exception + */ + public static final String upload(MultipartFile file) throws IOException { + try { + return upload(getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); + } catch (Exception e) { + throw new IOException(e.getMessage(), e); + } + } + + /** + * 鏍规嵁鏂囦欢璺緞涓婁紶 + * + * @param baseDir 鐩稿搴旂敤鐨勫熀鐩綍 + * @param file 涓婁紶鐨勬枃浠 + * @return 鏂囦欢鍚嶇О + * @throws IOException + */ + public static final String upload(String baseDir, MultipartFile file) throws IOException { + try { + return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); + } catch (Exception e) { + throw new IOException(e.getMessage(), e); + } + } + + /** + * 鏂囦欢涓婁紶 + * + * @param baseDir 鐩稿搴旂敤鐨勫熀鐩綍 + * @param file 涓婁紶鐨勬枃浠 + * @param allowedExtension 涓婁紶鏂囦欢绫诲瀷 + * @return 杩斿洖涓婁紶鎴愬姛鐨勬枃浠跺悕 + * @throws FileSizeLimitExceededException 濡傛灉瓒呭嚭鏈澶уぇ灏 + * @throws FileNameLengthLimitExceededException 鏂囦欢鍚嶅お闀 + * @throws IOException 姣斿璇诲啓鏂囦欢鍑洪敊鏃 + * @throws InvalidExtensionException 鏂囦欢鏍¢獙寮傚父 + */ + public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension) + throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, + InvalidExtensionException { + int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length(); + if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) { + throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH); + } + + assertAllowed(file, allowedExtension); + + String fileName = extractFilename(file); + + String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath(); + file.transferTo(Paths.get(absPath)); + return getPathFileName(baseDir, fileName); + } + + /** + * 缂栫爜鏂囦欢鍚 + */ + public static final String extractFilename(MultipartFile file) { + return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), + FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); + } + + public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException { + File desc = new File(uploadDir + File.separator + fileName); + + if (!desc.exists()) { + if (!desc.getParentFile().exists()) { + desc.getParentFile().mkdirs(); + } + } + return desc; + } + + public static final String getPathFileName(String uploadDir, String fileName) throws IOException { + int dirLastIndex = JsowellConfig.getProfile().length() + 1; + String currentDir = StringUtils.substring(uploadDir, dirLastIndex); + return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; + } + + /** + * 鏂囦欢澶у皬鏍¢獙 + * + * @param file 涓婁紶鐨勬枃浠 + * @return + * @throws FileSizeLimitExceededException 濡傛灉瓒呭嚭鏈澶уぇ灏 + * @throws InvalidExtensionException + */ + public static final void assertAllowed(MultipartFile file, String[] allowedExtension) + throws FileSizeLimitExceededException, InvalidExtensionException { + long size = file.getSize(); + if (size > DEFAULT_MAX_SIZE) { + throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024); + } + + String fileName = file.getOriginalFilename(); + String extension = getExtension(file); + if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) { + if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) { + throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension, + fileName); + } else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION) { + throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension, + fileName); + } else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION) { + throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension, + fileName); + } else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION) { + throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension, + fileName); + } else { + throw new InvalidExtensionException(allowedExtension, extension, fileName); + } + } + } + + /** + * 鍒ゆ柇MIME绫诲瀷鏄惁鏄厑璁哥殑MIME绫诲瀷 + * + * @param extension + * @param allowedExtension + * @return + */ + public static final boolean isAllowedExtension(String extension, String[] allowedExtension) { + for (String str : allowedExtension) { + if (str.equalsIgnoreCase(extension)) { + return true; + } + } + return false; + } + + /** + * 鑾峰彇鏂囦欢鍚嶇殑鍚庣紑 + * + * @param file 琛ㄥ崟鏂囦欢 + * @return 鍚庣紑鍚 + */ + public static final String getExtension(MultipartFile file) { + String extension = FilenameUtils.getExtension(file.getOriginalFilename()); + if (StringUtils.isEmpty(extension)) { + extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType())); + } + return extension; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/file/FileUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/file/FileUtils.java new file mode 100644 index 000000000..b8eaf04af --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/file/FileUtils.java @@ -0,0 +1,252 @@ +package com.jsowell.common.util.file; + +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.IdUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ArrayUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +/** + * 鏂囦欢澶勭悊宸ュ叿绫 + * + * @author jsowell + */ +public class FileUtils { + public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+"; + + /** + * 杈撳嚭鎸囧畾鏂囦欢鐨刡yte鏁扮粍 + * + * @param filePath 鏂囦欢璺緞 + * @param os 杈撳嚭娴 + * @return + */ + public static void writeBytes(String filePath, OutputStream os) throws IOException { + FileInputStream fis = null; + try { + File file = new File(filePath); + if (!file.exists()) { + throw new FileNotFoundException(filePath); + } + fis = new FileInputStream(file); + byte[] b = new byte[1024]; + int length; + while ((length = fis.read(b)) > 0) { + os.write(b, 0, length); + } + } catch (IOException e) { + throw e; + } finally { + IOUtils.close(os); + IOUtils.close(fis); + } + } + + /** + * 鍐欐暟鎹埌鏂囦欢涓 + * + * @param data 鏁版嵁 + * @return 鐩爣鏂囦欢 + * @throws IOException IO寮傚父 + */ + public static String writeImportBytes(byte[] data) throws IOException { + return writeBytes(data, JsowellConfig.getImportPath()); + } + + /** + * 鍐欐暟鎹埌鏂囦欢涓 + * + * @param data 鏁版嵁 + * @param uploadDir 鐩爣鏂囦欢 + * @return 鐩爣鏂囦欢 + * @throws IOException IO寮傚父 + */ + public static String writeBytes(byte[] data, String uploadDir) throws IOException { + FileOutputStream fos = null; + String pathName = ""; + try { + String extension = getFileExtendName(data); + pathName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; + File file = FileUploadUtils.getAbsoluteFile(uploadDir, pathName); + fos = new FileOutputStream(file); + fos.write(data); + } finally { + IOUtils.close(fos); + } + return FileUploadUtils.getPathFileName(uploadDir, pathName); + } + + /** + * 鍒犻櫎鏂囦欢 + * + * @param filePath 鏂囦欢 + * @return + */ + public static boolean deleteFile(String filePath) { + boolean flag = false; + File file = new File(filePath); + // 璺緞涓烘枃浠朵笖涓嶄负绌哄垯杩涜鍒犻櫎 + if (file.isFile() && file.exists()) { + file.delete(); + flag = true; + } + return flag; + } + + /** + * 鏂囦欢鍚嶇О楠岃瘉 + * + * @param filename 鏂囦欢鍚嶇О + * @return true 姝e父 false 闈炴硶 + */ + public static boolean isValidFilename(String filename) { + return filename.matches(FILENAME_PATTERN); + } + + /** + * 妫鏌ユ枃浠舵槸鍚﹀彲涓嬭浇 + * + * @param resource 闇瑕佷笅杞界殑鏂囦欢 + * @return true 姝e父 false 闈炴硶 + */ + public static boolean checkAllowDownload(String resource) { + // 绂佹鐩綍涓婅烦绾у埆 + if (StringUtils.contains(resource, "..")) { + return false; + } + + // 妫鏌ュ厑璁镐笅杞界殑鏂囦欢瑙勫垯 + if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource))) { + return true; + } + + // 涓嶅湪鍏佽涓嬭浇鐨勬枃浠惰鍒 + return false; + } + + /** + * 涓嬭浇鏂囦欢鍚嶉噸鏂扮紪鐮 + * + * @param request 璇锋眰瀵硅薄 + * @param fileName 鏂囦欢鍚 + * @return 缂栫爜鍚庣殑鏂囦欢鍚 + */ + public static String setFileDownloadHeader(HttpServletRequest request, String fileName) throws UnsupportedEncodingException { + final String agent = request.getHeader("USER-AGENT"); + String filename = fileName; + if (agent.contains("MSIE")) { + // IE娴忚鍣 + filename = URLEncoder.encode(filename, "utf-8"); + filename = filename.replace("+", " "); + } else if (agent.contains("Firefox")) { + // 鐏嫄娴忚鍣 + filename = new String(fileName.getBytes(), "ISO8859-1"); + } else if (agent.contains("Chrome")) { + // google娴忚鍣 + filename = URLEncoder.encode(filename, "utf-8"); + } else { + // 鍏跺畠娴忚鍣 + filename = URLEncoder.encode(filename, "utf-8"); + } + return filename; + } + + /** + * 涓嬭浇鏂囦欢鍚嶉噸鏂扮紪鐮 + * + * @param response 鍝嶅簲瀵硅薄 + * @param realFileName 鐪熷疄鏂囦欢鍚 + */ + public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException { + String percentEncodedFileName = percentEncode(realFileName); + + StringBuilder contentDispositionValue = new StringBuilder(); + contentDispositionValue.append("attachment; filename=") + .append(percentEncodedFileName) + .append(";") + .append("filename*=") + .append("utf-8''") + .append(percentEncodedFileName); + + response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename"); + response.setHeader("Content-disposition", contentDispositionValue.toString()); + response.setHeader("download-filename", percentEncodedFileName); + } + + /** + * 鐧惧垎鍙风紪鐮佸伐鍏锋柟娉 + * + * @param s 闇瑕佺櫨鍒嗗彿缂栫爜鐨勫瓧绗︿覆 + * @return 鐧惧垎鍙风紪鐮佸悗鐨勫瓧绗︿覆 + */ + public static String percentEncode(String s) throws UnsupportedEncodingException { + String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString()); + return encode.replaceAll("\\+", "%20"); + } + + /** + * 鑾峰彇鍥惧儚鍚庣紑 + * + * @param photoByte 鍥惧儚鏁版嵁 + * @return 鍚庣紑鍚 + */ + public static String getFileExtendName(byte[] photoByte) { + String strFileExtendName = "jpg"; + if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56) + && ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97)) { + strFileExtendName = "gif"; + } else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70)) { + strFileExtendName = "jpg"; + } else if ((photoByte[0] == 66) && (photoByte[1] == 77)) { + strFileExtendName = "bmp"; + } else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71)) { + strFileExtendName = "png"; + } + return strFileExtendName; + } + + /** + * 鑾峰彇鏂囦欢鍚嶇О /profile/upload/2022/04/16/jsowell.png -- jsowell.png + * + * @param fileName 璺緞鍚嶇О + * @return 娌℃湁鏂囦欢璺緞鐨勫悕绉 + */ + public static String getName(String fileName) { + if (fileName == null) { + return null; + } + int lastUnixPos = fileName.lastIndexOf('/'); + int lastWindowsPos = fileName.lastIndexOf('\\'); + int index = Math.max(lastUnixPos, lastWindowsPos); + return fileName.substring(index + 1); + } + + /** + * 鑾峰彇涓嶅甫鍚庣紑鏂囦欢鍚嶇О /profile/upload/2022/04/16/jsowell.png -- jsowell + * + * @param fileName 璺緞鍚嶇О + * @return 娌℃湁鏂囦欢璺緞鍜屽悗缂鐨勫悕绉 + */ + public static String getNameNotSuffix(String fileName) { + if (fileName == null) { + return null; + } + String baseName = FilenameUtils.getBaseName(fileName); + return baseName; + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/file/ImageUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/file/ImageUtils.java new file mode 100644 index 000000000..d48583bb4 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/file/ImageUtils.java @@ -0,0 +1,79 @@ +package com.jsowell.common.util.file; + +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.util.StringUtils; +import org.apache.poi.util.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.util.Arrays; + +/** + * 鍥剧墖澶勭悊宸ュ叿绫 + * + * @author jsowell + */ +public class ImageUtils { + private static final Logger log = LoggerFactory.getLogger(ImageUtils.class); + + public static byte[] getImage(String imagePath) { + InputStream is = getFile(imagePath); + try { + return IOUtils.toByteArray(is); + } catch (Exception e) { + log.error("鍥剧墖鍔犺浇寮傚父 {}", e); + return null; + } finally { + IOUtils.closeQuietly(is); + } + } + + public static InputStream getFile(String imagePath) { + try { + byte[] result = readFile(imagePath); + result = Arrays.copyOf(result, result.length); + return new ByteArrayInputStream(result); + } catch (Exception e) { + log.error("鑾峰彇鍥剧墖寮傚父 {}", e); + } + return null; + } + + /** + * 璇诲彇鏂囦欢涓哄瓧鑺傛暟鎹 + * + * @param url 鍦板潃 + * @return 瀛楄妭鏁版嵁 + */ + public static byte[] readFile(String url) { + InputStream in = null; + try { + if (url.startsWith("http")) { + // 缃戠粶鍦板潃 + URL urlObj = new URL(url); + URLConnection urlConnection = urlObj.openConnection(); + urlConnection.setConnectTimeout(30 * 1000); + urlConnection.setReadTimeout(60 * 1000); + urlConnection.setDoInput(true); + in = urlConnection.getInputStream(); + } else { + // 鏈満鍦板潃 + String localPath = JsowellConfig.getProfile(); + String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX); + in = new FileInputStream(downloadPath); + } + return IOUtils.toByteArray(in); + } catch (Exception e) { + log.error("鑾峰彇鏂囦欢璺緞寮傚父 {}", e); + return null; + } finally { + IOUtils.closeQuietly(in); + } + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/file/MimeTypeUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/file/MimeTypeUtils.java new file mode 100644 index 000000000..cea243d2a --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/file/MimeTypeUtils.java @@ -0,0 +1,56 @@ +package com.jsowell.common.util.file; + +/** + * 濯掍綋绫诲瀷宸ュ叿绫 + * + * @author jsowell + */ +public class MimeTypeUtils { + public static final String IMAGE_PNG = "image/png"; + + public static final String IMAGE_JPG = "image/jpg"; + + public static final String IMAGE_JPEG = "image/jpeg"; + + public static final String IMAGE_BMP = "image/bmp"; + + public static final String IMAGE_GIF = "image/gif"; + + public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"}; + + public static final String[] FLASH_EXTENSION = {"swf", "flv"}; + + public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", + "asf", "rm", "rmvb"}; + + public static final String[] VIDEO_EXTENSION = {"mp4", "avi", "rmvb"}; + + public static final String[] DEFAULT_ALLOWED_EXTENSION = { + // 鍥剧墖 + "bmp", "gif", "jpg", "jpeg", "png", + // word excel powerpoint + "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt", + // 鍘嬬缉鏂囦欢 + "rar", "zip", "gz", "bz2", + // 瑙嗛鏍煎紡 + "mp4", "avi", "rmvb", + // pdf + "pdf"}; + + public static String getExtension(String prefix) { + switch (prefix) { + case IMAGE_PNG: + return "png"; + case IMAGE_JPG: + return "jpg"; + case IMAGE_JPEG: + return "jpeg"; + case IMAGE_BMP: + return "bmp"; + case IMAGE_GIF: + return "gif"; + default: + return ""; + } + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/html/EscapeUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/html/EscapeUtil.java new file mode 100644 index 000000000..b2a2c6a68 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/html/EscapeUtil.java @@ -0,0 +1,140 @@ +package com.jsowell.common.util.html; + +import com.jsowell.common.util.StringUtils; + +/** + * 杞箟鍜屽弽杞箟宸ュ叿绫 + * + * @author jsowell + */ +public class EscapeUtil { + public static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)"; + + private static final char[][] TEXT = new char[64][]; + + static { + for (int i = 0; i < 64; i++) { + TEXT[i] = new char[]{(char) i}; + } + + // special HTML characters + TEXT['\''] = "'".toCharArray(); // 鍗曞紩鍙 + TEXT['"'] = """.toCharArray(); // 鍙屽紩鍙 + TEXT['&'] = "&".toCharArray(); // &绗 + TEXT['<'] = "<".toCharArray(); // 灏忎簬鍙 + TEXT['>'] = ">".toCharArray(); // 澶т簬鍙 + } + + /** + * 杞箟鏂囨湰涓殑HTML瀛楃涓哄畨鍏ㄧ殑瀛楃 + * + * @param text 琚浆涔夌殑鏂囨湰 + * @return 杞箟鍚庣殑鏂囨湰 + */ + public static String escape(String text) { + return encode(text); + } + + /** + * 杩樺師琚浆涔夌殑HTML鐗规畩瀛楃 + * + * @param content 鍖呭惈杞箟绗︾殑HTML鍐呭 + * @return 杞崲鍚庣殑瀛楃涓 + */ + public static String unescape(String content) { + return decode(content); + } + + /** + * 娓呴櫎鎵鏈塇TML鏍囩锛屼絾鏄笉鍒犻櫎鏍囩鍐呯殑鍐呭 + * + * @param content 鏂囨湰 + * @return 娓呴櫎鏍囩鍚庣殑鏂囨湰 + */ + public static String clean(String content) { + return new HTMLFilter().filter(content); + } + + /** + * Escape缂栫爜 + * + * @param text 琚紪鐮佺殑鏂囨湰 + * @return 缂栫爜鍚庣殑瀛楃 + */ + private static String encode(String text) { + if (StringUtils.isEmpty(text)) { + return StringUtils.EMPTY; + } + + final StringBuilder tmp = new StringBuilder(text.length() * 6); + char c; + for (int i = 0; i < text.length(); i++) { + c = text.charAt(i); + if (c < 256) { + tmp.append("%"); + if (c < 16) { + tmp.append("0"); + } + tmp.append(Integer.toString(c, 16)); + } else { + tmp.append("%u"); + if (c <= 0xfff) { + // issue#I49JU8@Gitee + tmp.append("0"); + } + tmp.append(Integer.toString(c, 16)); + } + } + return tmp.toString(); + } + + /** + * Escape瑙g爜 + * + * @param content 琚浆涔夌殑鍐呭 + * @return 瑙g爜鍚庣殑瀛楃涓 + */ + public static String decode(String content) { + if (StringUtils.isEmpty(content)) { + return content; + } + + StringBuilder tmp = new StringBuilder(content.length()); + int lastPos = 0, pos = 0; + char ch; + while (lastPos < content.length()) { + pos = content.indexOf("%", lastPos); + if (pos == lastPos) { + if (content.charAt(pos + 1) == 'u') { + ch = (char) Integer.parseInt(content.substring(pos + 2, pos + 6), 16); + tmp.append(ch); + lastPos = pos + 6; + } else { + ch = (char) Integer.parseInt(content.substring(pos + 1, pos + 3), 16); + tmp.append(ch); + lastPos = pos + 3; + } + } else { + if (pos == -1) { + tmp.append(content.substring(lastPos)); + lastPos = content.length(); + } else { + tmp.append(content.substring(lastPos, pos)); + lastPos = pos; + } + } + } + return tmp.toString(); + } + + public static void main(String[] args) { + String html = ""; + String escape = EscapeUtil.escape(html); + // String html = "ipt>alert(\"XSS\")ipt>"; + // String html = "<123"; + // String html = "123>"; + System.out.println("clean: " + EscapeUtil.clean(html)); + System.out.println("escape: " + escape); + System.out.println("unescape: " + EscapeUtil.unescape(escape)); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/html/HTMLFilter.java b/jsowell-common/src/main/java/com/jsowell/common/util/html/HTMLFilter.java new file mode 100644 index 000000000..9cfc903a8 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/html/HTMLFilter.java @@ -0,0 +1,501 @@ +package com.jsowell.common.util.html; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * HTML杩囨护鍣紝鐢ㄤ簬鍘婚櫎XSS婕忔礊闅愭偅銆 + * + * @author jsowell + */ +public final class HTMLFilter { + /** + * regex flag union representing /si modifiers in php + **/ + private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL; + private static final Pattern P_COMMENTS = Pattern.compile("", Pattern.DOTALL); + private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI); + private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL); + private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI); + private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI); + private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI); + private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI); + private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI); + private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?"); + private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?"); + private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?"); + private static final Pattern P_VALID_ENTITIES = Pattern.compile("&([^&;]*)(?=(;|&|$))"); + private static final Pattern P_VALID_QUOTES = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL); + private static final Pattern P_END_ARROW = Pattern.compile("^>"); + private static final Pattern P_BODY_TO_END = Pattern.compile("<([^>]*?)(?=<|$)"); + private static final Pattern P_XML_CONTENT = Pattern.compile("(^|>)([^<]*?)(?=>)"); + private static final Pattern P_STRAY_LEFT_ARROW = Pattern.compile("<([^>]*?)(?=<|$)"); + private static final Pattern P_STRAY_RIGHT_ARROW = Pattern.compile("(^|>)([^<]*?)(?=>)"); + private static final Pattern P_AMP = Pattern.compile("&"); + private static final Pattern P_QUOTE = Pattern.compile("\""); + private static final Pattern P_LEFT_ARROW = Pattern.compile("<"); + private static final Pattern P_RIGHT_ARROW = Pattern.compile(">"); + private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>"); + + // @xxx could grow large... maybe use sesat's ReferenceMap + private static final ConcurrentMap P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>(); + private static final ConcurrentMap P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>(); + + /** + * set of allowed html elements, along with allowed attributes for each element + **/ + private final Map> vAllowed; + /** + * counts of open tags for each (allowable) html element + **/ + private final Map vTagCounts = new HashMap<>(); + + /** + * html elements which must always be self-closing (e.g. "") + **/ + private final String[] vSelfClosingTags; + /** + * html elements which must always have separate opening and closing tags (e.g. "") + **/ + private final String[] vNeedClosingTags; + /** + * set of disallowed html elements + **/ + private final String[] vDisallowed; + /** + * attributes which should be checked for valid protocols + **/ + private final String[] vProtocolAtts; + /** + * allowed protocols + **/ + private final String[] vAllowedProtocols; + /** + * tags which should be removed if they contain no content (e.g. "" or "") + **/ + private final String[] vRemoveBlanks; + /** + * entities allowed within html markup + **/ + private final String[] vAllowedEntities; + /** + * flag determining whether comments are allowed in input String. + */ + private final boolean stripComment; + private final boolean encodeQuotes; + /** + * flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "" + * becomes " text "). If set to false, unbalanced angle brackets will be html escaped. + */ + private final boolean alwaysMakeTags; + + /** + * Default constructor. + */ + public HTMLFilter() { + vAllowed = new HashMap<>(); + + final ArrayList a_atts = new ArrayList<>(); + a_atts.add("href"); + a_atts.add("target"); + vAllowed.put("a", a_atts); + + final ArrayList img_atts = new ArrayList<>(); + img_atts.add("src"); + img_atts.add("width"); + img_atts.add("height"); + img_atts.add("alt"); + vAllowed.put("img", img_atts); + + final ArrayList no_atts = new ArrayList<>(); + vAllowed.put("b", no_atts); + vAllowed.put("strong", no_atts); + vAllowed.put("i", no_atts); + vAllowed.put("em", no_atts); + + vSelfClosingTags = new String[]{"img"}; + vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"}; + vDisallowed = new String[]{}; + vAllowedProtocols = new String[]{"http", "mailto", "https"}; // no ftp. + vProtocolAtts = new String[]{"src", "href"}; + vRemoveBlanks = new String[]{"a", "b", "strong", "i", "em"}; + vAllowedEntities = new String[]{"amp", "gt", "lt", "quot"}; + stripComment = true; + encodeQuotes = true; + alwaysMakeTags = false; + } + + /** + * Map-parameter configurable constructor. + * + * @param conf map containing configuration. keys match field names. + */ + @SuppressWarnings("unchecked") + public HTMLFilter(final Map conf) { + + assert conf.containsKey("vAllowed") : "configuration requires vAllowed"; + assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags"; + assert conf.containsKey("vNeedClosingTags") : "configuration requires vNeedClosingTags"; + assert conf.containsKey("vDisallowed") : "configuration requires vDisallowed"; + assert conf.containsKey("vAllowedProtocols") : "configuration requires vAllowedProtocols"; + assert conf.containsKey("vProtocolAtts") : "configuration requires vProtocolAtts"; + assert conf.containsKey("vRemoveBlanks") : "configuration requires vRemoveBlanks"; + assert conf.containsKey("vAllowedEntities") : "configuration requires vAllowedEntities"; + + vAllowed = Collections.unmodifiableMap((HashMap>) conf.get("vAllowed")); + vSelfClosingTags = (String[]) conf.get("vSelfClosingTags"); + vNeedClosingTags = (String[]) conf.get("vNeedClosingTags"); + vDisallowed = (String[]) conf.get("vDisallowed"); + vAllowedProtocols = (String[]) conf.get("vAllowedProtocols"); + vProtocolAtts = (String[]) conf.get("vProtocolAtts"); + vRemoveBlanks = (String[]) conf.get("vRemoveBlanks"); + vAllowedEntities = (String[]) conf.get("vAllowedEntities"); + stripComment = conf.containsKey("stripComment") ? (Boolean) conf.get("stripComment") : true; + encodeQuotes = conf.containsKey("encodeQuotes") ? (Boolean) conf.get("encodeQuotes") : true; + alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true; + } + + private void reset() { + vTagCounts.clear(); + } + + // --------------------------------------------------------------- + // my versions of some PHP library functions + public static String chr(final int decimal) { + return String.valueOf((char) decimal); + } + + public static String htmlSpecialChars(final String s) { + String result = s; + result = regexReplace(P_AMP, "&", result); + result = regexReplace(P_QUOTE, """, result); + result = regexReplace(P_LEFT_ARROW, "<", result); + result = regexReplace(P_RIGHT_ARROW, ">", result); + return result; + } + + // --------------------------------------------------------------- + + /** + * given a user submitted input String, filter out any invalid or restricted html. + * + * @param input text (i.e. submitted by a user) than may contain html + * @return "clean" version of input, with only valid, whitelisted html elements allowed + */ + public String filter(final String input) { + reset(); + String s = input; + + s = escapeComments(s); + + s = balanceHTML(s); + + s = checkTags(s); + + s = processRemoveBlanks(s); + + // s = validateEntities(s); + + return s; + } + + public boolean isAlwaysMakeTags() { + return alwaysMakeTags; + } + + public boolean isStripComments() { + return stripComment; + } + + private String escapeComments(final String s) { + final Matcher m = P_COMMENTS.matcher(s); + final StringBuffer buf = new StringBuffer(); + if (m.find()) { + final String match = m.group(1); // (.*?) + m.appendReplacement(buf, Matcher.quoteReplacement("")); + } + m.appendTail(buf); + + return buf.toString(); + } + + private String balanceHTML(String s) { + if (alwaysMakeTags) { + // + // try and form html + // + s = regexReplace(P_END_ARROW, "", s); + // 涓嶈拷鍔犵粨鏉熸爣绛 + s = regexReplace(P_BODY_TO_END, "<$1>", s); + s = regexReplace(P_XML_CONTENT, "$1<$2", s); + + } else { + // + // escape stray brackets + // + s = regexReplace(P_STRAY_LEFT_ARROW, "<$1", s); + s = regexReplace(P_STRAY_RIGHT_ARROW, "$1$2><", s); + + // + // the last regexp causes '<>' entities to appear + // (we need to do a lookahead assertion so that the last bracket can + // be used in the next pass of the regexp) + // + s = regexReplace(P_BOTH_ARROWS, "", s); + } + + return s; + } + + private String checkTags(String s) { + Matcher m = P_TAGS.matcher(s); + + final StringBuffer buf = new StringBuffer(); + while (m.find()) { + String replaceStr = m.group(1); + replaceStr = processTag(replaceStr); + m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr)); + } + m.appendTail(buf); + + // these get tallied in processTag + // (remember to reset before subsequent calls to filter method) + final StringBuilder sBuilder = new StringBuilder(buf.toString()); + for (String key : vTagCounts.keySet()) { + for (int ii = 0; ii < vTagCounts.get(key); ii++) { + sBuilder.append(""); + } + } + s = sBuilder.toString(); + + return s; + } + + private String processRemoveBlanks(final String s) { + String result = s; + for (String tag : vRemoveBlanks) { + if (!P_REMOVE_PAIR_BLANKS.containsKey(tag)) { + P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?>")); + } + result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result); + if (!P_REMOVE_SELF_BLANKS.containsKey(tag)) { + P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>")); + } + result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result); + } + + return result; + } + + private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s) { + Matcher m = regex_pattern.matcher(s); + return m.replaceAll(replacement); + } + + private String processTag(final String s) { + // ending tags + Matcher m = P_END_TAG.matcher(s); + if (m.find()) { + final String name = m.group(1).toLowerCase(); + if (allowed(name)) { + if (!inArray(name, vSelfClosingTags)) { + if (vTagCounts.containsKey(name)) { + vTagCounts.put(name, vTagCounts.get(name) - 1); + return ""; + } + } + } + } + + // starting tags + m = P_START_TAG.matcher(s); + if (m.find()) { + final String name = m.group(1).toLowerCase(); + final String body = m.group(2); + String ending = m.group(3); + + // debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" ); + if (allowed(name)) { + final StringBuilder params = new StringBuilder(); + + final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body); + final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body); + final List paramNames = new ArrayList<>(); + final List paramValues = new ArrayList<>(); + while (m2.find()) { + paramNames.add(m2.group(1)); // ([a-z0-9]+) + paramValues.add(m2.group(3)); // (.*?) + } + while (m3.find()) { + paramNames.add(m3.group(1)); // ([a-z0-9]+) + paramValues.add(m3.group(3)); // ([^\"\\s']+) + } + + String paramName, paramValue; + for (int ii = 0; ii < paramNames.size(); ii++) { + paramName = paramNames.get(ii).toLowerCase(); + paramValue = paramValues.get(ii); + + // debug( "paramName='" + paramName + "'" ); + // debug( "paramValue='" + paramValue + "'" ); + // debug( "allowed? " + vAllowed.get( name ).contains( paramName ) ); + + if (allowedAttribute(name, paramName)) { + if (inArray(paramName, vProtocolAtts)) { + paramValue = processParamProtocol(paramValue); + } + params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\\\""); + } + } + + if (inArray(name, vSelfClosingTags)) { + ending = " /"; + } + + if (inArray(name, vNeedClosingTags)) { + ending = ""; + } + + if (ending == null || ending.length() < 1) { + if (vTagCounts.containsKey(name)) { + vTagCounts.put(name, vTagCounts.get(name) + 1); + } else { + vTagCounts.put(name, 1); + } + } else { + ending = " /"; + } + return "<" + name + params + ending + ">"; + } else { + return ""; + } + } + + // comments + m = P_COMMENT.matcher(s); + if (!stripComment && m.find()) { + return "<" + m.group() + ">"; + } + + return ""; + } + + private String processParamProtocol(String s) { + s = decodeEntities(s); + final Matcher m = P_PROTOCOL.matcher(s); + if (m.find()) { + final String protocol = m.group(1); + if (!inArray(protocol, vAllowedProtocols)) { + // bad protocol, turn into local anchor link instead + s = "#" + s.substring(protocol.length() + 1); + if (s.startsWith("#//")) { + s = "#" + s.substring(3); + } + } + } + + return s; + } + + private String decodeEntities(String s) { + StringBuffer buf = new StringBuffer(); + + Matcher m = P_ENTITY.matcher(s); + while (m.find()) { + final String match = m.group(1); + final int decimal = Integer.decode(match).intValue(); + m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); + } + m.appendTail(buf); + s = buf.toString(); + + buf = new StringBuffer(); + m = P_ENTITY_UNICODE.matcher(s); + while (m.find()) { + final String match = m.group(1); + final int decimal = Integer.valueOf(match, 16).intValue(); + m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); + } + m.appendTail(buf); + s = buf.toString(); + + buf = new StringBuffer(); + m = P_ENCODE.matcher(s); + while (m.find()) { + final String match = m.group(1); + final int decimal = Integer.valueOf(match, 16).intValue(); + m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); + } + m.appendTail(buf); + s = buf.toString(); + + s = validateEntities(s); + return s; + } + + private String validateEntities(final String s) { + StringBuffer buf = new StringBuffer(); + + // validate entities throughout the string + Matcher m = P_VALID_ENTITIES.matcher(s); + while (m.find()) { + final String one = m.group(1); // ([^&;]*) + final String two = m.group(2); // (?=(;|&|$)) + m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two))); + } + m.appendTail(buf); + + return encodeQuotes(buf.toString()); + } + + private String encodeQuotes(final String s) { + if (encodeQuotes) { + StringBuffer buf = new StringBuffer(); + Matcher m = P_VALID_QUOTES.matcher(s); + while (m.find()) { + final String one = m.group(1); // (>|^) + final String two = m.group(2); // ([^<]+?) + final String three = m.group(3); // (<|$) + // 涓嶆浛鎹㈠弻寮曞彿涓"锛岄槻姝son鏍煎紡鏃犳晥 regexReplace(P_QUOTE, """, two) + m.appendReplacement(buf, Matcher.quoteReplacement(one + two + three)); + } + m.appendTail(buf); + return buf.toString(); + } else { + return s; + } + } + + private String checkEntity(final String preamble, final String term) { + + return ";".equals(term) && isValidEntity(preamble) ? '&' + preamble : "&" + preamble; + } + + private boolean isValidEntity(final String entity) { + return inArray(entity, vAllowedEntities); + } + + private static boolean inArray(final String s, final String[] array) { + for (String item : array) { + if (item != null && item.equals(s)) { + return true; + } + } + return false; + } + + private boolean allowed(final String name) { + return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed); + } + + private boolean allowedAttribute(final String name, final String paramName) { + return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName)); + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/http/HttpHelper.java b/jsowell-common/src/main/java/com/jsowell/common/util/http/HttpHelper.java new file mode 100644 index 000000000..7a23ea8b1 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/http/HttpHelper.java @@ -0,0 +1,44 @@ +package com.jsowell.common.util.http; + +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.ServletRequest; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +/** + * 閫氱敤http宸ュ叿灏佽 + * + * @author jsowell + */ +public class HttpHelper { + private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class); + + public static String getBodyString(ServletRequest request) { + StringBuilder sb = new StringBuilder(); + BufferedReader reader = null; + try (InputStream inputStream = request.getInputStream()) { + reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + String line = ""; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + } catch (IOException e) { + LOGGER.warn("getBodyString鍑虹幇闂锛"); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + LOGGER.error(ExceptionUtils.getMessage(e)); + } + } + } + return sb.toString(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/http/HttpUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/http/HttpUtils.java new file mode 100644 index 000000000..279afdb69 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/http/HttpUtils.java @@ -0,0 +1,277 @@ +package com.jsowell.common.util.http; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.ConnectException; +import java.net.SocketTimeoutException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.security.cert.X509Certificate; + +/** + * 閫氱敤http鍙戦佹柟娉 + * + * @author jsowell + */ +public class HttpUtils { + private static final Logger log = LoggerFactory.getLogger(HttpUtils.class); + + /** + * 鍚戞寚瀹 URL 鍙戦丟ET鏂规硶鐨勮姹 + * + * @param url 鍙戦佽姹傜殑 URL + * @return 鎵浠h〃杩滅▼璧勬簮鐨勫搷搴旂粨鏋 + */ + public static String sendGet(String url) { + return sendGet(url, StringUtils.EMPTY); + } + + /** + * 鍚戞寚瀹 URL 鍙戦丟ET鏂规硶鐨勮姹 + * + * @param url 鍙戦佽姹傜殑 URL + * @param param 璇锋眰鍙傛暟锛岃姹傚弬鏁板簲璇ユ槸 name1=value1&name2=value2 鐨勫舰寮忋 + * @return 鎵浠h〃杩滅▼璧勬簮鐨勫搷搴旂粨鏋 + */ + public static String sendGet(String url, String param) { + return sendGet(url, param, Constants.UTF8); + } + + /** + * 鍚戞寚瀹 URL 鍙戦丟ET鏂规硶鐨勮姹 + * + * @param url 鍙戦佽姹傜殑 URL + * @param param 璇锋眰鍙傛暟锛岃姹傚弬鏁板簲璇ユ槸 name1=value1&name2=value2 鐨勫舰寮忋 + * @param contentType 缂栫爜绫诲瀷 + * @return 鎵浠h〃杩滅▼璧勬簮鐨勫搷搴旂粨鏋 + */ + public static String sendGet(String url, String param, String contentType) { + StringBuilder result = new StringBuilder(); + BufferedReader in = null; + try { + String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url; + log.info("sendGet - {}", urlNameString); + URL realUrl = new URL(urlNameString); + URLConnection connection = realUrl.openConnection(); + connection.setRequestProperty("accept", "*/*"); + connection.setRequestProperty("connection", "Keep-Alive"); + connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + connection.connect(); + in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType)); + String line; + while ((line = in.readLine()) != null) { + result.append(line); + } + log.info("recv - {}", result); + } catch (ConnectException e) { + log.error("璋冪敤HttpUtils.sendGet ConnectException, url=" + url + ",param=" + param, e); + } catch (SocketTimeoutException e) { + log.error("璋冪敤HttpUtils.sendGet SocketTimeoutException, url=" + url + ",param=" + param, e); + } catch (IOException e) { + log.error("璋冪敤HttpUtils.sendGet IOException, url=" + url + ",param=" + param, e); + } catch (Exception e) { + log.error("璋冪敤HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (Exception ex) { + log.error("璋冪敤in.close Exception, url=" + url + ",param=" + param, ex); + } + } + return result.toString(); + } + + /** + * 鍚戞寚瀹 URL 鍙戦丳OST鏂规硶鐨勮姹 + * + * @param url 鍙戦佽姹傜殑 URL + * @param param 璇锋眰鍙傛暟锛岃姹傚弬鏁板簲璇ユ槸 name1=value1&name2=value2 鐨勫舰寮忋 + * @return 鎵浠h〃杩滅▼璧勬簮鐨勫搷搴旂粨鏋 + */ + public static String sendPost(String url, String param) { + PrintWriter out = null; + BufferedReader in = null; + StringBuilder result = new StringBuilder(); + try { + log.info("sendPost - {}", url); + URL realUrl = new URL(url); + URLConnection conn = realUrl.openConnection(); + conn.setRequestProperty("accept", "*/*"); + conn.setRequestProperty("connection", "Keep-Alive"); + conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + conn.setRequestProperty("Accept-Charset", "utf-8"); + conn.setRequestProperty("contentType", "utf-8"); + conn.setDoOutput(true); + conn.setDoInput(true); + out = new PrintWriter(conn.getOutputStream()); + out.print(param); + out.flush(); + in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); + String line; + while ((line = in.readLine()) != null) { + result.append(line); + } + log.info("recv - {}", result); + } catch (ConnectException e) { + log.error("璋冪敤HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e); + } catch (SocketTimeoutException e) { + log.error("璋冪敤HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e); + } catch (IOException e) { + log.error("璋冪敤HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e); + } catch (Exception e) { + log.error("璋冪敤HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e); + } finally { + try { + if (out != null) { + out.close(); + } + if (in != null) { + in.close(); + } + } catch (IOException ex) { + log.error("璋冪敤in.close Exception, url=" + url + ",param=" + param, ex); + } + } + return result.toString(); + } + + /** + * 鍚戞寚瀹 URL 鍙戦丳OST鏂规硶鐨勮姹 + * + * @param url 鍙戦佽姹傜殑 URL + * @param param 璇锋眰鍙傛暟锛岃姹傚弬鏁板簲璇ユ槸 name1=value1&name2=value2 鐨勫舰寮忋 + * @param contentType header涓殑contentType + * @return 鎵浠h〃杩滅▼璧勬簮鐨勫搷搴旂粨鏋 + */ + public static String sendPostContentType(String url, String param, String contentType) { + PrintWriter out = null; + BufferedReader in = null; + StringBuilder result = new StringBuilder(); + try { + log.info("sendPost - {}", url); + URL realUrl = new URL(url); + URLConnection conn = realUrl.openConnection(); + conn.setRequestProperty("accept", "*/*"); + conn.setRequestProperty("connection", "Keep-Alive"); + conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + conn.setRequestProperty("Accept-Charset", "utf-8"); + conn.setRequestProperty("Content-Type", contentType); + conn.setDoOutput(true); + conn.setDoInput(true); + out = new PrintWriter(conn.getOutputStream()); + out.print(param); + out.flush(); + in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); + String line; + while ((line = in.readLine()) != null) { + result.append(line); + } + log.info("recv - {}", result); + } catch (ConnectException e) { + log.error("璋冪敤HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e); + } catch (SocketTimeoutException e) { + log.error("璋冪敤HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e); + } catch (IOException e) { + log.error("璋冪敤HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e); + } catch (Exception e) { + log.error("璋冪敤HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e); + } finally { + try { + if (out != null) { + out.close(); + } + if (in != null) { + in.close(); + } + } catch (IOException ex) { + log.error("璋冪敤in.close Exception, url=" + url + ",param=" + param, ex); + } + } + return result.toString(); + } + + + + + public static String sendSSLPost(String url, String param) { + StringBuilder result = new StringBuilder(); + String urlNameString = url + "?" + param; + try { + log.info("sendSSLPost - {}", urlNameString); + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, new TrustManager[]{new TrustAnyTrustManager()}, new java.security.SecureRandom()); + URL console = new URL(urlNameString); + HttpsURLConnection conn = (HttpsURLConnection) console.openConnection(); + conn.setRequestProperty("accept", "*/*"); + conn.setRequestProperty("connection", "Keep-Alive"); + conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + conn.setRequestProperty("Accept-Charset", "utf-8"); + conn.setRequestProperty("contentType", "utf-8"); + conn.setDoOutput(true); + conn.setDoInput(true); + + conn.setSSLSocketFactory(sc.getSocketFactory()); + conn.setHostnameVerifier(new TrustAnyHostnameVerifier()); + conn.connect(); + InputStream is = conn.getInputStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String ret = ""; + while ((ret = br.readLine()) != null) { + if (ret != null && !"".equals(ret.trim())) { + result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)); + } + } + log.info("recv - {}", result); + conn.disconnect(); + br.close(); + } catch (ConnectException e) { + log.error("璋冪敤HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e); + } catch (SocketTimeoutException e) { + log.error("璋冪敤HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e); + } catch (IOException e) { + log.error("璋冪敤HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e); + } catch (Exception e) { + log.error("璋冪敤HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e); + } + return result.toString(); + } + + private static class TrustAnyTrustManager implements X509TrustManager { + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) { + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) { + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[]{}; + } + } + + private static class TrustAnyHostnameVerifier implements HostnameVerifier { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/id/IdUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/id/IdUtils.java new file mode 100644 index 000000000..2f432e749 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/id/IdUtils.java @@ -0,0 +1,101 @@ +package com.jsowell.common.util.id; + +import com.google.common.collect.Sets; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.RandomUtil; + +import java.util.Set; + +/** + * ID鐢熸垚鍣ㄥ伐鍏风被 + * + * @author jsowell + */ +public class IdUtils { + /** + * 鑾峰彇闅忔満UUID + * + * @return 闅忔満UUID + */ + public static String randomUUID() { + return UUID.randomUUID().toString(); + } + + /** + * 绠鍖栫殑UUID锛屽幓鎺変簡妯嚎 + * + * @return 绠鍖栫殑UUID锛屽幓鎺変簡妯嚎 + */ + public static String simpleUUID() { + return UUID.randomUUID().toString(true); + } + + /** + * 鑾峰彇闅忔満UUID锛屼娇鐢ㄦц兘鏇村ソ鐨凾hreadLocalRandom鐢熸垚UUID + * + * @return 闅忔満UUID + */ + public static String fastUUID() { + return UUID.fastUUID().toString(); + } + + /** + * 绠鍖栫殑UUID锛屽幓鎺変簡妯嚎锛屼娇鐢ㄦц兘鏇村ソ鐨凾hreadLocalRandom鐢熸垚UUID + * + * @return 绠鍖栫殑UUID锛屽幓鎺変簡妯嚎 + */ + public static String fastSimpleUUID() { + return UUID.fastUUID().toString(true); + } + + /** + * 鐢熸垚浜ゆ槗娴佹按鍙 + * + * @param pileSn 妗╃紪鍙 渚嬪锛32010600019236 + * @param connectorCode 鏋彛鍙 渚嬪锛01 + */ + public static String generateOrderCode(String pileSn, String connectorCode) { + return generateOrderCode(pileSn + connectorCode); + } + + /** + * 鐢熸垚浜ゆ槗娴佹按鍙 + * 鐢熸垚瑙勫垯涓 鏍煎紡妗╁彿锛7bytes锛 +鏋彿锛1byte锛 +骞存湀鏃ユ椂鍒嗙锛6bytes锛 +鑷 澧炲簭鍙凤紙2bytes锛夛紱 + * @param pileConnectorCode 涓哄凡缁忔嫾濂界殑鍏呯數妗╂灙鍙e彿 渚嬪锛3201060001923601 + * @return 浜ゆ槗娴佹按鍙 渚嬪锛32010600019236012001061803423060 + */ + public static String generateOrderCode(String pileConnectorCode) { + String timeNow = DateUtils.dateTimeNow(DateUtils.YYMMDDHHMMSS); + //闅忔満鐢熸垚涓涓洓浣嶆暣鏁 + String randomNumber = RandomUtil.getRandomNumber(4); + return pileConnectorCode + timeNow + randomNumber; + } + + public static void main(String[] args) { + Set set = Sets.newHashSet(); + for (int i = 0; i < 1000; i++) { + // String s = System.currentTimeMillis() + RandomUtil.getRandomNumber(6); + String id = SnowflakeIdWorker.getSnowflakeId(); + set.add(id); + System.out.println(id); + } + System.out.println("set size = " + set.size()); + } + + /** + * 鐢熸垚鍏綅浼氬憳id + */ + public static String getMemberId() { + long id = Long.parseLong(SnowflakeIdWorker.getSnowflakeId()); + StringBuilder sb = new StringBuilder(id + ""); + StringBuilder reverse = sb.reverse();//灏唅d缈昏浆锛氭垜浠彂鐜癷d寰堥暱锛屼笖楂樹綅寰堥暱閮ㄥ垎鏄竴鏍风殑鏁 + id = new Long(reverse.toString()) / 1000;//鍒囧幓閮ㄥ垎闀垮害 + while (id > 100000000) { + id /= 10; + } + Integer num = Integer.parseInt(id + ""); + return String.valueOf(num); + } + + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/id/Seq.java b/jsowell-common/src/main/java/com/jsowell/common/util/id/Seq.java new file mode 100644 index 000000000..573c2652c --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/id/Seq.java @@ -0,0 +1,80 @@ +package com.jsowell.common.util.id; + +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author jsowell 搴忓垪鐢熸垚绫 + */ +public class Seq { + // 閫氱敤搴忓垪绫诲瀷 + public static final String commSeqType = "COMMON"; + + // 涓婁紶搴忓垪绫诲瀷 + public static final String uploadSeqType = "UPLOAD"; + + // 閫氱敤鎺ュ彛搴忓垪鏁 + private static AtomicInteger commSeq = new AtomicInteger(1); + + // 涓婁紶鎺ュ彛搴忓垪鏁 + private static AtomicInteger uploadSeq = new AtomicInteger(1); + + // 鏈哄櫒鏍囪瘑 + private static String machineCode = "A"; + + /** + * 鑾峰彇閫氱敤搴忓垪鍙 + * + * @return 搴忓垪鍊 + */ + public static String getId() { + return getId(commSeqType); + } + + /** + * 榛樿16浣嶅簭鍒楀彿 yyMMddHHmmss + 涓浣嶆満鍣ㄦ爣璇 + 3闀垮害寰幆閫掑瀛楃涓 + * + * @return 搴忓垪鍊 + */ + public static String getId(String type) { + AtomicInteger atomicInt = commSeq; + if (uploadSeqType.equals(type)) { + atomicInt = uploadSeq; + } + return getId(atomicInt, 3); + } + + /** + * 閫氱敤鎺ュ彛搴忓垪鍙 yyMMddHHmmss + 涓浣嶆満鍣ㄦ爣璇 + length闀垮害寰幆閫掑瀛楃涓 + * + * @param atomicInt 搴忓垪鏁 + * @param length 鏁板奸暱搴 + * @return 搴忓垪鍊 + */ + public static String getId(AtomicInteger atomicInt, int length) { + String result = DateUtils.dateTimeNow(); + result += machineCode; + result += getSeq(atomicInt, length); + return result; + } + + /** + * 搴忓垪寰幆閫掑瀛楃涓瞇1, 10 鐨 (length)骞傛鏂), 鐢0宸﹁ˉ榻恖ength浣嶆暟 + * + * @return 搴忓垪鍊 + */ + private synchronized static String getSeq(AtomicInteger atomicInt, int length) { + // 鍏堝彇鍊煎啀+1 + int value = atomicInt.getAndIncrement(); + + // 濡傛灉鏇存柊鍚庡>=10 鐨 (length)骞傛鏂瑰垯閲嶇疆涓1 + int maxSeq = (int) Math.pow(10, length); + if (atomicInt.get() >= maxSeq) { + atomicInt.set(1); + } + // 杞瓧绗︿覆锛岀敤0宸﹁ˉ榻 + return StringUtils.padl(value, length); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/id/SnUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/id/SnUtils.java new file mode 100644 index 000000000..eb072840b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/id/SnUtils.java @@ -0,0 +1,77 @@ +package com.jsowell.common.util.id; + +import com.google.common.collect.Lists; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.redis.RedisCache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.util.List; + +/** + * 鐢熸垚sn鍙稶til + */ +@Component +public class SnUtils { + + private static Logger logger = LoggerFactory.getLogger(SnUtils.class); + + @Autowired + public RedisCache redisCache; + + private String prefix = "88"; + + /** + * 鑾峰彇閫掑鐨勫簭鍒楀彿 + * 鍏呯數妗╃紪鍙峰畾涔変负14浣: 鍥哄畾浣88 + 骞翠唤23 + 10浣嶈嚜澧炴暟瀛椾笉瓒宠ˉ0 + * @param prefix 鐢熸垚搴忓垪鍙风殑鍓嶇紑 + * @return + */ + private String getPileSn(String prefix) { + //搴忓垪鍙峰墠缂鍔犵壒瀹氭爣璇嗭紝濡傜郴缁熸ā鍧楀悕涔嬬被鐨 闃叉閲嶅 + String key = CacheConstants.PILE_SN_GENERATE_KEY + prefix; + String increResult = null; + try { + Long increNum = redisCache.increment(key, 1); + // 骞翠唤 + int year = LocalDate.now().getYear() - 2000; + //涓嶈冻琛ヤ綅 + increResult = prefix + year + String.format("%1$010d", increNum); + } catch (Exception e) { + logger.error("鑾峰彇搴忓垪鍙峰け璐", e); + } + return increResult; + } + + + + /** + * 鐢熸垚sn鍙 + * + * @return + */ + public List generateSN() { + return generateSN(1); + } + + /** + * 鎵归噺鐢熸垚sn鍙 + * + * @param size + * @return + */ + public List generateSN(int size) { + List resultList = Lists.newArrayList(); + if (size <= 0) { + return resultList; + } + for (int i = 0; i < size; i++) { + resultList.add(getPileSn(prefix)); + } + return resultList; + } + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/id/SnowflakeIdWorker.java b/jsowell-common/src/main/java/com/jsowell/common/util/id/SnowflakeIdWorker.java new file mode 100644 index 000000000..1ef5140c7 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/id/SnowflakeIdWorker.java @@ -0,0 +1,237 @@ +package com.jsowell.common.util.id; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; + +import java.net.Inet4Address; +import java.net.UnknownHostException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Twitter_Snowflake
+ * SnowFlake鐨勭粨鏋勫涓(姣忛儴鍒嗙敤-鍒嗗紑):
+ * 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000
+ * 1浣嶆爣璇嗭紝鐢变簬long鍩烘湰绫诲瀷鍦↗ava涓槸甯︾鍙风殑锛屾渶楂樹綅鏄鍙蜂綅锛屾鏁版槸0锛岃礋鏁版槸1锛屾墍浠d涓鑸槸姝f暟锛屾渶楂樹綅鏄0
+ * 41浣嶆椂闂存埅(姣绾)锛屾敞鎰忥紝41浣嶆椂闂存埅涓嶆槸瀛樺偍褰撳墠鏃堕棿鐨勬椂闂存埅锛岃屾槸瀛樺偍鏃堕棿鎴殑宸硷紙褰撳墠鏃堕棿鎴 - 寮濮嬫椂闂存埅) + * 寰楀埌鐨勫硷級锛岃繖閲岀殑鐨勫紑濮嬫椂闂存埅锛屼竴鑸槸鎴戜滑鐨刬d鐢熸垚鍣ㄥ紑濮嬩娇鐢ㄧ殑鏃堕棿锛岀敱鎴戜滑绋嬪簭鏉ユ寚瀹氱殑锛堝涓嬩笅闈㈢▼搴廔dWorker绫荤殑startTime灞炴э級銆41浣嶇殑鏃堕棿鎴紝鍙互浣跨敤69骞达紝骞碩 = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69
+ * 10浣嶇殑鏁版嵁鏈哄櫒浣嶏紝鍙互閮ㄧ讲鍦1024涓妭鐐癸紝鍖呮嫭5浣峝atacenterId鍜5浣峸orkerId
+ * 12浣嶅簭鍒楋紝姣鍐呯殑璁℃暟锛12浣嶇殑璁℃暟椤哄簭鍙锋敮鎸佹瘡涓妭鐐规瘡姣(鍚屼竴鏈哄櫒锛屽悓涓鏃堕棿鎴)浜х敓4096涓狪D搴忓彿
+ * 鍔犺捣鏉ュ垰濂64浣嶏紝涓轰竴涓狶ong鍨嬨
+ * SnowFlake鐨勪紭鐐规槸锛屾暣浣撲笂鎸夌収鏃堕棿鑷鎺掑簭锛屽苟涓旀暣涓垎甯冨紡绯荤粺鍐呬笉浼氫骇鐢烮D纰版挒(鐢辨暟鎹腑蹇僆D鍜屾満鍣↖D浣滃尯鍒)锛屽苟涓旀晥鐜囪緝楂橈紝缁忔祴璇曪紝SnowFlake姣忕鑳藉浜х敓26涓嘔D宸﹀彸銆 + */ +@Slf4j +public class SnowflakeIdWorker { + + // ==============================Fields=========================================== + + /** + * 鏈哄櫒id鎵鍗犵殑浣嶆暟 + */ + private final long workerIdBits = 5L; + + /** + * 鏁版嵁鏍囪瘑id鎵鍗犵殑浣嶆暟 + */ + private final long dataCenterIdBits = 5L; + + /** + * 宸ヤ綔鏈哄櫒ID(0~31) + */ + private final long workerId; + + /** + * 鏁版嵁涓績ID(0~31) + */ + private final long dataCenterId; + + /** + * 姣鍐呭簭鍒(0~4095) + */ + private long sequence = 0L; + + /** + * 涓婃鐢熸垚ID鐨勬椂闂存埅 + */ + private long lastTimestamp = -1L; + + private static final SnowflakeIdWorker idWorker; + + static { + idWorker = new SnowflakeIdWorker(getWorkId(), getDataCenterId()); + } + + //==============================Constructors===================================== + + /** + * 鏋勯犲嚱鏁 + * + * @param workerId 宸ヤ綔ID (0~31) + * @param dataCenterId 鏁版嵁涓績ID (0~31) + */ + public SnowflakeIdWorker(long workerId, long dataCenterId) { + /* + * 鏀寔鐨勬渶澶ф満鍣╥d锛岀粨鏋滄槸31 (杩欎釜绉讳綅绠楁硶鍙互寰堝揩鐨勮绠楀嚭鍑犱綅浜岃繘鍒舵暟鎵鑳借〃绀虹殑鏈澶у崄杩涘埗鏁) + */ + long maxWorkerId = ~(-1L << workerIdBits); + if (workerId > maxWorkerId || workerId < 0) { + throw new IllegalArgumentException(String.format("workerId can't be greater than %d or less than 0", maxWorkerId)); + } + /* + * 鏀寔鐨勬渶澶ф暟鎹爣璇唅d锛岀粨鏋滄槸31 + */ + long maxDataCenterId = ~(-1L << dataCenterIdBits); + if (dataCenterId > maxDataCenterId || dataCenterId < 0) { + throw new IllegalArgumentException(String.format("dataCenterId can't be greater than %d or less than 0", maxDataCenterId)); + } + this.workerId = workerId; + this.dataCenterId = dataCenterId; + } + + // ==============================Methods========================================== + + /** + * 鑾峰緱涓嬩竴涓狪D (璇ユ柟娉曟槸绾跨▼瀹夊叏鐨) + * + * @return SnowflakeId + */ + public synchronized long nextId() { + long timestamp = timeGen(); + + //濡傛灉褰撳墠鏃堕棿灏忎簬涓婁竴娆D鐢熸垚鐨勬椂闂存埑锛岃鏄庣郴缁熸椂閽熷洖閫杩囪繖涓椂鍊欏簲褰撴姏鍑哄紓甯 + if (timestamp < lastTimestamp) { + throw new RuntimeException( + String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); + } + + //濡傛灉鏄悓涓鏃堕棿鐢熸垚鐨勶紝鍒欒繘琛屾绉掑唴搴忓垪 + /* + * 搴忓垪鍦╥d涓崰鐨勪綅鏁 + */ + long sequenceBits = 12L; + if (lastTimestamp == timestamp) { + /* + * 鐢熸垚搴忓垪鐨勬帺鐮侊紝杩欓噷涓4095 (0b111111111111=0xfff=4095) + */ + long sequenceMask = ~(-1L << sequenceBits); + sequence = (sequence + 1) & sequenceMask; + //姣鍐呭簭鍒楁孩鍑 + if (sequence == 0) { + //闃诲鍒颁笅涓涓绉,鑾峰緱鏂扮殑鏃堕棿鎴 + timestamp = tilNextMillis(lastTimestamp); + } + } else { + //鏃堕棿鎴虫敼鍙橈紝姣鍐呭簭鍒楅噸缃 + sequence = 0L; + } + + //涓婃鐢熸垚ID鐨勬椂闂存埅 + lastTimestamp = timestamp; + + //绉讳綅骞堕氳繃鎴栬繍绠楁嫾鍒颁竴璧风粍鎴64浣嶇殑ID + /* + * 鏃堕棿鎴悜宸︾Щ22浣(5+5+12) + */ + long timestampLeftShift = sequenceBits + workerIdBits + dataCenterIdBits; + /* + * 鏁版嵁鏍囪瘑id鍚戝乏绉17浣(12+5) + */ + long dataCenterIdShift = sequenceBits + workerIdBits; + /* + * 鏈哄櫒ID鍚戝乏绉12浣 + */ + /* + * 寮濮嬫椂闂存埅 (2015-01-01) + */ + long twepoch = 1489111610226L; + return ((timestamp - twepoch) << timestampLeftShift) + | (dataCenterId << dataCenterIdShift) + | (workerId << sequenceBits) + | sequence; + } + + /** + * 闃诲鍒颁笅涓涓绉掞紝鐩村埌鑾峰緱鏂扮殑鏃堕棿鎴 + * + * @param lastTimestamp 涓婃鐢熸垚ID鐨勬椂闂存埅 + * @return 褰撳墠鏃堕棿鎴 + */ + protected long tilNextMillis(long lastTimestamp) { + long timestamp = timeGen(); + while (timestamp <= lastTimestamp) { + timestamp = timeGen(); + } + return timestamp; + } + + /** + * 杩斿洖浠ユ绉掍负鍗曚綅鐨勫綋鍓嶆椂闂 + * + * @return 褰撳墠鏃堕棿(姣) + */ + protected long timeGen() { + return System.currentTimeMillis(); + } + + private static Long getWorkId() { + try { + String hostAddress = Inet4Address.getLocalHost().getHostAddress(); + int[] ints = StringUtils.toCodePoints(hostAddress); + int sums = 0; + for (int b : ints) { + sums += b; + } + return (long) (sums % 32); + } catch (UnknownHostException e) { + // 濡傛灉鑾峰彇澶辫触锛屽垯浣跨敤闅忔満鏁板鐢 + return RandomUtils.nextLong(0, 31); + } + } + + private static Long getDataCenterId() { + int[] ints = StringUtils.toCodePoints(SystemUtils.getHostName()); + int sums = 0; + for (int i : ints) { + sums += i; + } + return (long) (sums % 32); + } + + + /** + * 闈欐佸伐鍏风被 + * 鐢熸垚18浣峣d + */ + public static String getSnowflakeId() { + return String.valueOf(idWorker.nextId()); + } + + //==============================Test============================================= + + /** + * 娴嬭瘯 + */ + public static void main(String[] args) throws InterruptedException { + //鍒ゆ柇鐢熸垚鐨勮褰曟槸鍚︽湁閲嶅璁板綍 + long beginTime = System.currentTimeMillis(); + Map map = new ConcurrentHashMap<>(); + for (int i = 0; i < 100; i++) { + new Thread(() -> { + for (int s = 0; s < 20000; s++) { + String snowFlakeId = SnowflakeIdWorker.getSnowflakeId(); + if (map.containsKey(snowFlakeId)) { + log.error("涓婚敭閲嶅:" + snowFlakeId); + } else { + map.put(snowFlakeId, snowFlakeId); + } + } + }).start(); + } + Thread.sleep(3000); + log.info("map.size():{}", map.size()); + log.info("鑰楁椂:" + (System.currentTimeMillis() - beginTime)); + } +} + diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/id/UUID.java b/jsowell-common/src/main/java/com/jsowell/common/util/id/UUID.java new file mode 100644 index 000000000..af53381b2 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/id/UUID.java @@ -0,0 +1,441 @@ +package com.jsowell.common.util.id; + +import com.jsowell.common.exception.UtilException; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +/** + * 鎻愪緵閫氱敤鍞竴璇嗗埆鐮侊紙universally unique identifier锛夛紙UUID锛夊疄鐜 + * + * @author jsowell + */ +public final class UUID implements java.io.Serializable, Comparable { + private static final long serialVersionUID = -1185015143654744140L; + + /** + * SecureRandom 鐨勫崟渚 + */ + private static class Holder { + static final SecureRandom numberGenerator = getSecureRandom(); + } + + /** + * 姝UID鐨勬渶楂64鏈夋晥浣 + */ + private final long mostSigBits; + + /** + * 姝UID鐨勬渶浣64鏈夋晥浣 + */ + private final long leastSigBits; + + /** + * 绉佹湁鏋勯 + * + * @param data 鏁版嵁 + */ + private UUID(byte[] data) { + long msb = 0; + long lsb = 0; + assert data.length == 16 : "data must be 16 bytes in length"; + for (int i = 0; i < 8; i++) { + msb = (msb << 8) | (data[i] & 0xff); + } + for (int i = 8; i < 16; i++) { + lsb = (lsb << 8) | (data[i] & 0xff); + } + this.mostSigBits = msb; + this.leastSigBits = lsb; + } + + /** + * 浣跨敤鎸囧畾鐨勬暟鎹瀯閫犳柊鐨 UUID銆 + * + * @param mostSigBits 鐢ㄤ簬 {@code UUID} 鐨勬渶楂樻湁鏁 64 浣 + * @param leastSigBits 鐢ㄤ簬 {@code UUID} 鐨勬渶浣庢湁鏁 64 浣 + */ + public UUID(long mostSigBits, long leastSigBits) { + this.mostSigBits = mostSigBits; + this.leastSigBits = leastSigBits; + } + + /** + * 鑾峰彇绫诲瀷 4锛堜吉闅忔満鐢熸垚鐨勶級UUID 鐨勯潤鎬佸伐鍘傘 浣跨敤鍔犲瘑鐨勬湰鍦扮嚎绋嬩吉闅忔満鏁扮敓鎴愬櫒鐢熸垚璇 UUID銆 + * + * @return 闅忔満鐢熸垚鐨 {@code UUID} + */ + public static UUID fastUUID() { + return randomUUID(false); + } + + /** + * 鑾峰彇绫诲瀷 4锛堜吉闅忔満鐢熸垚鐨勶級UUID 鐨勯潤鎬佸伐鍘傘 浣跨敤鍔犲瘑鐨勫己浼殢鏈烘暟鐢熸垚鍣ㄧ敓鎴愯 UUID銆 + * + * @return 闅忔満鐢熸垚鐨 {@code UUID} + */ + public static UUID randomUUID() { + return randomUUID(true); + } + + /** + * 鑾峰彇绫诲瀷 4锛堜吉闅忔満鐢熸垚鐨勶級UUID 鐨勯潤鎬佸伐鍘傘 浣跨敤鍔犲瘑鐨勫己浼殢鏈烘暟鐢熸垚鍣ㄧ敓鎴愯 UUID銆 + * + * @param isSecure 鏄惁浣跨敤{@link SecureRandom}濡傛灉鏄彲浠ヨ幏寰楁洿瀹夊叏鐨勯殢鏈虹爜锛屽惁鍒欏彲浠ュ緱鍒版洿濂界殑鎬ц兘 + * @return 闅忔満鐢熸垚鐨 {@code UUID} + */ + public static UUID randomUUID(boolean isSecure) { + final Random ng = isSecure ? Holder.numberGenerator : getRandom(); + + byte[] randomBytes = new byte[16]; + ng.nextBytes(randomBytes); + randomBytes[6] &= 0x0f; /* clear version */ + randomBytes[6] |= 0x40; /* set to version 4 */ + randomBytes[8] &= 0x3f; /* clear variant */ + randomBytes[8] |= 0x80; /* set to IETF variant */ + return new UUID(randomBytes); + } + + /** + * 鏍规嵁鎸囧畾鐨勫瓧鑺傛暟缁勮幏鍙栫被鍨 3锛堝熀浜庡悕绉扮殑锛塙UID 鐨勯潤鎬佸伐鍘傘 + * + * @param name 鐢ㄤ簬鏋勯 UUID 鐨勫瓧鑺傛暟缁勩 + * @return 鏍规嵁鎸囧畾鏁扮粍鐢熸垚鐨 {@code UUID} + */ + public static UUID nameUUIDFromBytes(byte[] name) { + MessageDigest md; + try { + md = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException nsae) { + throw new InternalError("MD5 not supported"); + } + byte[] md5Bytes = md.digest(name); + md5Bytes[6] &= 0x0f; /* clear version */ + md5Bytes[6] |= 0x30; /* set to version 3 */ + md5Bytes[8] &= 0x3f; /* clear variant */ + md5Bytes[8] |= 0x80; /* set to IETF variant */ + return new UUID(md5Bytes); + } + + /** + * 鏍规嵁 {@link #toString()} 鏂规硶涓弿杩扮殑瀛楃涓叉爣鍑嗚〃绀哄舰寮忓垱寤簕@code UUID}銆 + * + * @param name 鎸囧畾 {@code UUID} 瀛楃涓 + * @return 鍏锋湁鎸囧畾鍊肩殑 {@code UUID} + * @throws IllegalArgumentException 濡傛灉 name 涓 {@link #toString} 涓弿杩扮殑瀛楃涓茶〃绀哄舰寮忎笉绗︽姏鍑烘寮傚父 + */ + public static UUID fromString(String name) { + String[] components = name.split("-"); + if (components.length != 5) { + throw new IllegalArgumentException("Invalid UUID string: " + name); + } + for (int i = 0; i < 5; i++) { + components[i] = "0x" + components[i]; + } + + long mostSigBits = Long.decode(components[0]).longValue(); + mostSigBits <<= 16; + mostSigBits |= Long.decode(components[1]).longValue(); + mostSigBits <<= 16; + mostSigBits |= Long.decode(components[2]).longValue(); + + long leastSigBits = Long.decode(components[3]).longValue(); + leastSigBits <<= 48; + leastSigBits |= Long.decode(components[4]).longValue(); + + return new UUID(mostSigBits, leastSigBits); + } + + /** + * 杩斿洖姝 UUID 鐨 128 浣嶅间腑鐨勬渶浣庢湁鏁 64 浣嶃 + * + * @return 姝 UUID 鐨 128 浣嶅间腑鐨勬渶浣庢湁鏁 64 浣嶃 + */ + public long getLeastSignificantBits() { + return leastSigBits; + } + + /** + * 杩斿洖姝 UUID 鐨 128 浣嶅间腑鐨勬渶楂樻湁鏁 64 浣嶃 + * + * @return 姝 UUID 鐨 128 浣嶅间腑鏈楂樻湁鏁 64 浣嶃 + */ + public long getMostSignificantBits() { + return mostSigBits; + } + + /** + * 涓庢 {@code UUID} 鐩稿叧鑱旂殑鐗堟湰鍙. 鐗堟湰鍙锋弿杩版 {@code UUID} 鏄浣曠敓鎴愮殑銆 + *

+ * 鐗堟湰鍙峰叿鏈変互涓嬪惈鎰: + *

    + *
  • 1 鍩轰簬鏃堕棿鐨 UUID + *
  • 2 DCE 瀹夊叏 UUID + *
  • 3 鍩轰簬鍚嶇О鐨 UUID + *
  • 4 闅忔満鐢熸垚鐨 UUID + *
+ * + * @return 姝 {@code UUID} 鐨勭増鏈彿 + */ + public int version() { + // Version is bits masked by 0x000000000000F000 in MS long + return (int) ((mostSigBits >> 12) & 0x0f); + } + + /** + * 涓庢 {@code UUID} 鐩稿叧鑱旂殑鍙樹綋鍙枫傚彉浣撳彿鎻忚堪 {@code UUID} 鐨勫竷灞銆 + *

+ * 鍙樹綋鍙峰叿鏈変互涓嬪惈鎰忥細 + *

    + *
  • 0 涓 NCS 鍚戝悗鍏煎淇濈暀 + *
  • 2 IETF RFC 4122(Leach-Salz), 鐢ㄤ簬姝ょ被 + *
  • 6 淇濈暀锛屽井杞悜鍚庡吋瀹 + *
  • 7 淇濈暀渚涗互鍚庡畾涔変娇鐢 + *
+ * + * @return 姝 {@code UUID} 鐩稿叧鑱旂殑鍙樹綋鍙 + */ + public int variant() { + // This field is composed of a varying number of bits. + // 0 - - Reserved for NCS backward compatibility + // 1 0 - The IETF aka Leach-Salz variant (used by this class) + // 1 1 0 Reserved, Microsoft backward compatibility + // 1 1 1 Reserved for future definition. + return (int) ((leastSigBits >>> (64 - (leastSigBits >>> 62))) & (leastSigBits >> 63)); + } + + /** + * 涓庢 UUID 鐩稿叧鑱旂殑鏃堕棿鎴冲笺 + * + *

+ * 60 浣嶇殑鏃堕棿鎴冲兼牴鎹 {@code UUID} 鐨 time_low銆乼ime_mid 鍜 time_hi 瀛楁鏋勯犮
+ * 鎵寰楀埌鐨勬椂闂存埑浠 100 姣井绉掍负鍗曚綅锛屼粠 UTC锛堥氱敤鍗忚皟鏃堕棿锛 1582 骞 10 鏈 15 鏃ラ浂鏃跺紑濮嬨 + * + *

+ * 鏃堕棿鎴冲间粎鍦ㄥ湪鍩轰簬鏃堕棿鐨 UUID锛堝叾 version 绫诲瀷涓 1锛変腑鎵嶆湁鎰忎箟銆
+ * 濡傛灉姝 {@code UUID} 涓嶆槸鍩轰簬鏃堕棿鐨 UUID锛屽垯姝ゆ柟娉曟姏鍑 UnsupportedOperationException銆 + * + * @throws UnsupportedOperationException 濡傛灉姝 {@code UUID} 涓嶆槸 version 涓 1 鐨 UUID銆 + */ + public long timestamp() throws UnsupportedOperationException { + checkTimeBase(); + return (mostSigBits & 0x0FFFL) << 48// + | ((mostSigBits >> 16) & 0x0FFFFL) << 32// + | mostSigBits >>> 32; + } + + /** + * 涓庢 UUID 鐩稿叧鑱旂殑鏃堕挓搴忓垪鍊笺 + * + *

+ * 14 浣嶇殑鏃堕挓搴忓垪鍊兼牴鎹 UUID 鐨 clock_seq 瀛楁鏋勯犮俢lock_seq 瀛楁鐢ㄤ簬淇濊瘉鍦ㄥ熀浜庢椂闂寸殑 UUID 涓殑鏃堕棿鍞竴鎬с + *

+ * {@code clockSequence} 鍊间粎鍦ㄥ熀浜庢椂闂寸殑 UUID锛堝叾 version 绫诲瀷涓 1锛変腑鎵嶆湁鎰忎箟銆 濡傛灉姝 UUID 涓嶆槸鍩轰簬鏃堕棿鐨 UUID锛屽垯姝ゆ柟娉曟姏鍑 + * UnsupportedOperationException銆 + * + * @return 姝 {@code UUID} 鐨勬椂閽熷簭鍒 + * @throws UnsupportedOperationException 濡傛灉姝 UUID 鐨 version 涓嶄负 1 + */ + public int clockSequence() throws UnsupportedOperationException { + checkTimeBase(); + return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48); + } + + /** + * 涓庢 UUID 鐩稿叧鐨勮妭鐐瑰笺 + * + *

+ * 48 浣嶇殑鑺傜偣鍊兼牴鎹 UUID 鐨 node 瀛楁鏋勯犮傛瀛楁鏃ㄥ湪鐢ㄤ簬淇濆瓨鏈哄櫒鐨 IEEE 802 鍦板潃锛岃鍦板潃鐢ㄤ簬鐢熸垚姝 UUID 浠ヤ繚璇佺┖闂村敮涓鎬с + *

+ * 鑺傜偣鍊间粎鍦ㄥ熀浜庢椂闂寸殑 UUID锛堝叾 version 绫诲瀷涓 1锛変腑鎵嶆湁鎰忎箟銆
+ * 濡傛灉姝 UUID 涓嶆槸鍩轰簬鏃堕棿鐨 UUID锛屽垯姝ゆ柟娉曟姏鍑 UnsupportedOperationException銆 + * + * @return 姝 {@code UUID} 鐨勮妭鐐瑰 + * @throws UnsupportedOperationException 濡傛灉姝 UUID 鐨 version 涓嶄负 1 + */ + public long node() throws UnsupportedOperationException { + checkTimeBase(); + return leastSigBits & 0x0000FFFFFFFFFFFFL; + } + + /** + * 杩斿洖姝@code UUID} 鐨勫瓧绗︿覆琛ㄧ幇褰㈠紡銆 + * + *

+ * UUID 鐨勫瓧绗︿覆琛ㄧず褰㈠紡鐢辨 BNF 鎻忚堪锛 + * + *

+	 * {@code
+	 * UUID                   = ----
+	 * time_low               = 4*
+	 * time_mid               = 2*
+	 * time_high_and_version  = 2*
+	 * variant_and_sequence   = 2*
+	 * node                   = 6*
+	 * hexOctet               = 
+	 * hexDigit               = [0-9a-fA-F]
+	 * }
+	 * 
+ * + * + * + * @return 姝@code UUID} 鐨勫瓧绗︿覆琛ㄧ幇褰㈠紡 + * @see #toString(boolean) + */ + @Override + public String toString() { + return toString(false); + } + + /** + * 杩斿洖姝@code UUID} 鐨勫瓧绗︿覆琛ㄧ幇褰㈠紡銆 + * + *

+ * UUID 鐨勫瓧绗︿覆琛ㄧず褰㈠紡鐢辨 BNF 鎻忚堪锛 + * + *

+	 * {@code
+	 * UUID                   = ----
+	 * time_low               = 4*
+	 * time_mid               = 2*
+	 * time_high_and_version  = 2*
+	 * variant_and_sequence   = 2*
+	 * node                   = 6*
+	 * hexOctet               = 
+	 * hexDigit               = [0-9a-fA-F]
+	 * }
+	 * 
+ * + * + * + * @param isSimple 鏄惁绠鍗曟ā寮忥紝绠鍗曟ā寮忎负涓嶅甫'-'鐨刄UID瀛楃涓 + * @return 姝@code UUID} 鐨勫瓧绗︿覆琛ㄧ幇褰㈠紡 + */ + public String toString(boolean isSimple) { + final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36); + // time_low + builder.append(digits(mostSigBits >> 32, 8)); + if (!isSimple) { + builder.append('-'); + } + // time_mid + builder.append(digits(mostSigBits >> 16, 4)); + if (!isSimple) { + builder.append('-'); + } + // time_high_and_version + builder.append(digits(mostSigBits, 4)); + if (!isSimple) { + builder.append('-'); + } + // variant_and_sequence + builder.append(digits(leastSigBits >> 48, 4)); + if (!isSimple) { + builder.append('-'); + } + // node + builder.append(digits(leastSigBits, 12)); + + return builder.toString(); + } + + /** + * 杩斿洖姝 UUID 鐨勫搱甯岀爜銆 + * + * @return UUID 鐨勫搱甯岀爜鍊笺 + */ + @Override + public int hashCode() { + long hilo = mostSigBits ^ leastSigBits; + return ((int) (hilo >> 32)) ^ (int) hilo; + } + + /** + * 灏嗘瀵硅薄涓庢寚瀹氬璞℃瘮杈冦 + *

+ * 褰撲笖浠呭綋鍙傛暟涓嶄负 {@code null}銆佽屾槸涓涓 UUID 瀵硅薄銆佸叿鏈変笌姝 UUID 鐩稿悓鐨 varriant銆佸寘鍚浉鍚岀殑鍊硷紙姣忎竴浣嶅潎鐩稿悓锛夋椂锛岀粨鏋滄墠涓 {@code true}銆 + * + * @param obj 瑕佷笌涔嬫瘮杈冪殑瀵硅薄 + * @return 濡傛灉瀵硅薄鐩稿悓锛屽垯杩斿洖 {@code true}锛涘惁鍒欒繑鍥 {@code false} + */ + @Override + public boolean equals(Object obj) { + if ((null == obj) || (obj.getClass() != UUID.class)) { + return false; + } + UUID id = (UUID) obj; + return (mostSigBits == id.mostSigBits && leastSigBits == id.leastSigBits); + } + + // Comparison Operations + + /** + * 灏嗘 UUID 涓庢寚瀹氱殑 UUID 姣旇緝銆 + * + *

+ * 濡傛灉涓や釜 UUID 涓嶅悓锛屼笖绗竴涓 UUID 鐨勬渶楂樻湁鏁堝瓧娈靛ぇ浜庣浜屼釜 UUID 鐨勫搴斿瓧娈碉紝鍒欑涓涓 UUID 澶т簬绗簩涓 UUID銆 + * + * @param val 涓庢 UUID 姣旇緝鐨 UUID + * @return 鍦ㄦ UUID 灏忎簬銆佺瓑浜庢垨澶т簬 val 鏃讹紝鍒嗗埆杩斿洖 -1銆0 鎴 1銆 + */ + @Override + public int compareTo(UUID val) { + // The ordering is intentionally set up so that the UUIDs + // can simply be numerically compared as two numbers + return (this.mostSigBits < val.mostSigBits ? -1 : // + (this.mostSigBits > val.mostSigBits ? 1 : // + (this.leastSigBits < val.leastSigBits ? -1 : // + (this.leastSigBits > val.leastSigBits ? 1 : // + 0)))); + } + + // ------------------------------------------------------------------------------------------------------------------- + // Private method start + + /** + * 杩斿洖鎸囧畾鏁板瓧瀵瑰簲鐨刪ex鍊 + * + * @param val 鍊 + * @param digits 浣 + * @return 鍊 + */ + private static String digits(long val, int digits) { + long hi = 1L << (digits * 4); + return Long.toHexString(hi | (val & (hi - 1))).substring(1); + } + + /** + * 妫鏌ユ槸鍚︿负time-based鐗堟湰UUID + */ + private void checkTimeBase() { + if (version() != 1) { + throw new UnsupportedOperationException("Not a time-based UUID"); + } + } + + /** + * 鑾峰彇{@link SecureRandom}锛岀被鎻愪緵鍔犲瘑鐨勫己闅忔満鏁扮敓鎴愬櫒 (RNG) + * + * @return {@link SecureRandom} + */ + public static SecureRandom getSecureRandom() { + try { + return SecureRandom.getInstance("SHA1PRNG"); + } catch (NoSuchAlgorithmException e) { + throw new UtilException(e); + } + } + + /** + * 鑾峰彇闅忔満鏁扮敓鎴愬櫒瀵硅薄
+ * ThreadLocalRandom鏄疛DK 7涔嬪悗鎻愪緵骞跺彂浜х敓闅忔満鏁帮紝鑳藉瑙e喅澶氫釜绾跨▼鍙戠敓鐨勭珵浜変簤澶恒 + * + * @return {@link ThreadLocalRandom} + */ + public static ThreadLocalRandom getRandom() { + return ThreadLocalRandom.current(); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/ip/AddressUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/ip/AddressUtils.java new file mode 100644 index 000000000..d35b3cb4b --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/ip/AddressUtils.java @@ -0,0 +1,93 @@ +package com.jsowell.common.util.ip; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.Maps; +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.http.HttpUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + * 鑾峰彇鍦板潃绫 + * + * @author jsowell + */ +public class AddressUtils { + private static final Logger log = LoggerFactory.getLogger(AddressUtils.class); + + // IP鍦板潃鏌ヨ + public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp"; + + // 楂樺痉鏌ヨ鍦板潃api + public static final String AMAP_GET_LOCATION_URL = "https://restapi.amap.com/v3/geocode/geo"; + + // 楂樺痉搴旂敤key + private static final String AMAP_GET_LOCATION_KEY = "51e155ceb3ab2d4f3b6bd81ebaab20b3"; + + // 鏈煡鍦板潃 + public static final String UNKNOWN = "XX XX"; + + public static String getRealAddressByIP(String ip) { + // 鍐呯綉涓嶆煡璇 + if (IpUtils.internalIp(ip)) { + return "鍐呯綉IP"; + } + if (JsowellConfig.isAddressEnabled()) { + try { + String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK); + if (StringUtils.isEmpty(rspStr)) { + log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip); + return UNKNOWN; + } + JSONObject obj = JSON.parseObject(rspStr); + String region = obj.getString("pro"); + String city = obj.getString("city"); + return String.format("%s %s", region, city); + } catch (Exception e) { + log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip); + } + } + return UNKNOWN; + } + + /** + * 鍦板潃杞崲缁忕含搴 + * areaCode鍜宎ddress蹇呬紶鍙傛暟锛屼换鎰忎竴涓负绌哄垯杩斿洖null + * 楂樺痉api鍦板潃 https://lbs.amap.com/api/webservice/guide/api/georegeo + * + * @param areaCode 鍓嶇鍦板潃閫夋嫨鍣ㄨ幏鍙栧埌鐨勫尯鍩熺紪鐮 渚嬪锛"320000,320500,320583" + * @param address 璇︾粏鍦板潃 + * @return 閫楀彿鍒嗗壊鐨勭粡绾害瀛楃涓 + */ + public static Map getLongitudeAndLatitude(String areaCode, String address) { + if (StringUtils.isBlank(areaCode) || StringUtils.isBlank(address)) { + return null; + } + String[] split = StringUtils.split(areaCode, ","); + String param = "key=" + AMAP_GET_LOCATION_KEY + "&city=" + split[2] + "&address=" + address; + String resultStr = HttpUtils.sendGet(AMAP_GET_LOCATION_URL, param, Constants.UTF8); + if (StringUtils.isNotBlank(resultStr)) { + JSONObject resultObj = JSON.parseObject(resultStr); + // 鐘舵佷负1 鏌ヨ鎴愬姛 + if (StringUtils.equals(resultObj.getString("status"), Constants.ONE)) { + JSONArray geocodes = resultObj.getJSONArray("geocodes"); + if (geocodes != null && geocodes.size() > 0) { + Map map = Maps.newHashMap(); + JSONObject jsonObject = geocodes.getJSONObject(0); + String location = jsonObject.getString("location"); + String[] strArr = StringUtils.split(location, ","); + map.put("lng", strArr[0]); + map.put("lat", strArr[1]); + return map; + } + } + } + return null; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/ip/IpUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/ip/IpUtils.java new file mode 100644 index 000000000..b3fcdb8c8 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/ip/IpUtils.java @@ -0,0 +1,224 @@ +package com.jsowell.common.util.ip; + +import com.jsowell.common.util.StringUtils; + +import javax.servlet.http.HttpServletRequest; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** + * 鑾峰彇IP鏂规硶 + * + * @author jsowell + */ +public class IpUtils { + /** + * 鑾峰彇瀹㈡埛绔疘P + * + * @param request 璇锋眰瀵硅薄 + * @return IP鍦板潃 + */ + public static String getIpAddr(HttpServletRequest request) { + if (request == null) { + return "unknown"; + } + String ip = request.getHeader("x-forwarded-for"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("X-Forwarded-For"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("X-Real-IP"); + } + + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + + return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : getMultistageReverseProxyIp(ip); + } + + /** + * 妫鏌ユ槸鍚︿负鍐呴儴IP鍦板潃 + * + * @param ip IP鍦板潃 + * @return 缁撴灉 + */ + public static boolean internalIp(String ip) { + byte[] addr = textToNumericFormatV4(ip); + return internalIp(addr) || "127.0.0.1".equals(ip); + } + + /** + * 妫鏌ユ槸鍚︿负鍐呴儴IP鍦板潃 + * + * @param addr byte鍦板潃 + * @return 缁撴灉 + */ + private static boolean internalIp(byte[] addr) { + if (StringUtils.isNull(addr) || addr.length < 2) { + return true; + } + final byte b0 = addr[0]; + final byte b1 = addr[1]; + // 10.x.x.x/8 + final byte SECTION_1 = 0x0A; + // 172.16.x.x/12 + final byte SECTION_2 = (byte) 0xAC; + final byte SECTION_3 = (byte) 0x10; + final byte SECTION_4 = (byte) 0x1F; + // 192.168.x.x/16 + final byte SECTION_5 = (byte) 0xC0; + final byte SECTION_6 = (byte) 0xA8; + switch (b0) { + case SECTION_1: + return true; + case SECTION_2: + if (b1 >= SECTION_3 && b1 <= SECTION_4) { + return true; + } + case SECTION_5: + switch (b1) { + case SECTION_6: + return true; + } + default: + return false; + } + } + + /** + * 灏咺Pv4鍦板潃杞崲鎴愬瓧鑺 + * + * @param text IPv4鍦板潃 + * @return byte 瀛楄妭 + */ + public static byte[] textToNumericFormatV4(String text) { + if (text.length() == 0) { + return null; + } + + byte[] bytes = new byte[4]; + String[] elements = text.split("\\.", -1); + try { + long l; + int i; + switch (elements.length) { + case 1: + l = Long.parseLong(elements[0]); + if ((l < 0L) || (l > 4294967295L)) { + return null; + } + bytes[0] = (byte) (int) (l >> 24 & 0xFF); + bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF); + bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF); + bytes[3] = (byte) (int) (l & 0xFF); + break; + case 2: + l = Integer.parseInt(elements[0]); + if ((l < 0L) || (l > 255L)) { + return null; + } + bytes[0] = (byte) (int) (l & 0xFF); + l = Integer.parseInt(elements[1]); + if ((l < 0L) || (l > 16777215L)) { + return null; + } + bytes[1] = (byte) (int) (l >> 16 & 0xFF); + bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF); + bytes[3] = (byte) (int) (l & 0xFF); + break; + case 3: + for (i = 0; i < 2; ++i) { + l = Integer.parseInt(elements[i]); + if ((l < 0L) || (l > 255L)) { + return null; + } + bytes[i] = (byte) (int) (l & 0xFF); + } + l = Integer.parseInt(elements[2]); + if ((l < 0L) || (l > 65535L)) { + return null; + } + bytes[2] = (byte) (int) (l >> 8 & 0xFF); + bytes[3] = (byte) (int) (l & 0xFF); + break; + case 4: + for (i = 0; i < 4; ++i) { + l = Integer.parseInt(elements[i]); + if ((l < 0L) || (l > 255L)) { + return null; + } + bytes[i] = (byte) (int) (l & 0xFF); + } + break; + default: + return null; + } + } catch (NumberFormatException e) { + return null; + } + return bytes; + } + + /** + * 鑾峰彇IP鍦板潃 + * + * @return 鏈湴IP鍦板潃 + */ + public static String getHostIp() { + try { + return InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + } + return "127.0.0.1"; + } + + /** + * 鑾峰彇涓绘満鍚 + * + * @return 鏈湴涓绘満鍚 + */ + public static String getHostName() { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + } + return "鏈煡"; + } + + /** + * 浠庡绾у弽鍚戜唬鐞嗕腑鑾峰緱绗竴涓潪unknown IP鍦板潃 + * + * @param ip 鑾峰緱鐨処P鍦板潃 + * @return 绗竴涓潪unknown IP鍦板潃 + */ + public static String getMultistageReverseProxyIp(String ip) { + // 澶氱骇鍙嶅悜浠g悊妫娴 + if (ip != null && ip.indexOf(",") > 0) { + final String[] ips = ip.trim().split(","); + for (String subIp : ips) { + if (false == isUnknown(subIp)) { + ip = subIp; + break; + } + } + } + return ip; + } + + /** + * 妫娴嬬粰瀹氬瓧绗︿覆鏄惁涓烘湭鐭ワ紝澶氱敤浜庢娴婬TTP璇锋眰鐩稿叧 + * + * @param checkString 琚娴嬬殑瀛楃涓 + * @return 鏄惁鏈煡 + */ + public static boolean isUnknown(String checkString) { + return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString); + } +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/poi/ExcelHandlerAdapter.java b/jsowell-common/src/main/java/com/jsowell/common/util/poi/ExcelHandlerAdapter.java new file mode 100644 index 000000000..e43bec4d0 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/poi/ExcelHandlerAdapter.java @@ -0,0 +1,17 @@ +package com.jsowell.common.util.poi; + +/** + * Excel鏁版嵁鏍煎紡澶勭悊閫傞厤鍣 + * + * @author jsowell + */ +public interface ExcelHandlerAdapter { + /** + * 鏍煎紡鍖 + * + * @param value 鍗曞厓鏍兼暟鎹 + * @param args excel娉ㄨВargs鍙傛暟缁 + * @return 澶勭悊鍚庣殑鍊 + */ + Object format(Object value, String[] args); +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/poi/ExcelUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/poi/ExcelUtil.java new file mode 100644 index 000000000..f1d63f2fe --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/poi/ExcelUtil.java @@ -0,0 +1,1355 @@ +package com.jsowell.common.util.poi; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.annotation.Excel.Type; +import com.jsowell.common.annotation.Excels; +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.text.Convert; +import com.jsowell.common.exception.UtilException; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.DictUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.file.FileTypeUtils; +import com.jsowell.common.util.file.FileUtils; +import com.jsowell.common.util.file.ImageUtils; +import com.jsowell.common.util.reflect.ReflectUtils; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.RegExUtils; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ooxml.POIXMLDocumentPart; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.apache.poi.util.IOUtils; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.apache.poi.xssf.usermodel.*; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; + +/** + * Excel鐩稿叧澶勭悊 + * + * @author jsowell + */ +public class ExcelUtil { + private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class); + + public static final String FORMULA_REGEX_STR = "=|-|\\+|@"; + + public static final String[] FORMULA_STR = {"=", "-", "+", "@"}; + + /** + * Excel sheet鏈澶ц鏁帮紝榛樿65536 + */ + public static final int sheetSize = 65536; + + /** + * 宸ヤ綔琛ㄥ悕绉 + */ + private String sheetName; + + /** + * 瀵煎嚭绫诲瀷锛圗XPORT:瀵煎嚭鏁版嵁锛汭MPORT锛氬鍏ユā鏉匡級 + */ + private Type type; + + /** + * 宸ヤ綔钖勫璞 + */ + private Workbook wb; + + /** + * 宸ヤ綔琛ㄥ璞 + */ + private Sheet sheet; + + /** + * 鏍峰紡鍒楄〃 + */ + private Map styles; + + /** + * 瀵煎叆瀵煎嚭鏁版嵁鍒楄〃 + */ + private List list; + + /** + * 娉ㄨВ鍒楄〃 + */ + private List fields; + + /** + * 褰撳墠琛屽彿 + */ + private int rownum; + + /** + * 鏍囬 + */ + private String title; + + /** + * 鏈澶ч珮搴 + */ + private short maxHeight; + + /** + * 鍚堝苟鍚庢渶鍚庤鏁 + */ + private int subMergedLastRowNum = 0; + + /** + * 鍚堝苟鍚庡紑濮嬭鏁 + */ + private int subMergedFirstRowNum = 1; + + /** + * 瀵硅薄鐨勫瓙鍒楄〃鏂规硶 + */ + private Method subMethod; + + /** + * 瀵硅薄鐨勫瓙鍒楄〃灞炴 + */ + private List subFields; + + /** + * 缁熻鍒楄〃 + */ + private Map statistics = new HashMap(); + + /** + * 鏁板瓧鏍煎紡 + */ + private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00"); + + /** + * 瀹炰綋瀵硅薄 + */ + public Class clazz; + + /** + * 闇瑕佹帓闄ゅ垪灞炴 + */ + public String[] excludeFields; + + public ExcelUtil(Class clazz) { + this.clazz = clazz; + } + + /** + * 闅愯棌Excel涓垪灞炴 + * + * @param fields 鍒楀睘鎬у悕 绀轰緥[鍗曚釜"name"/澶氫釜"id","name"] + * @throws Exception + */ + public void hideColumn(String... fields) { + this.excludeFields = fields; + } + + public void init(List list, String sheetName, String title, Type type) { + if (list == null) { + list = new ArrayList(); + } + this.list = list; + this.sheetName = sheetName; + this.type = type; + this.title = title; + createExcelField(); + createWorkbook(); + createTitle(); + createSubHead(); + } + + /** + * 鍒涘缓excel绗竴琛屾爣棰 + */ + public void createTitle() { + if (StringUtils.isNotEmpty(title)) { + subMergedFirstRowNum++; + subMergedLastRowNum++; + int titleLastCol = this.fields.size() - 1; + if (isSubList()) { + titleLastCol = titleLastCol + subFields.size() - 1; + } + Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0); + titleRow.setHeightInPoints(30); + Cell titleCell = titleRow.createCell(0); + titleCell.setCellStyle(styles.get("title")); + titleCell.setCellValue(title); + sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), titleLastCol)); + } + } + + /** + * 鍒涘缓瀵硅薄鐨勫瓙鍒楄〃鍚嶇О + */ + public void createSubHead() { + if (isSubList()) { + subMergedFirstRowNum++; + subMergedLastRowNum++; + Row subRow = sheet.createRow(rownum); + int excelNum = 0; + for (Object[] objects : fields) { + Excel attr = (Excel) objects[1]; + Cell headCell1 = subRow.createCell(excelNum); + headCell1.setCellValue(attr.name()); + headCell1.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()))); + excelNum++; + } + int headFirstRow = excelNum - 1; + int headLastRow = headFirstRow + subFields.size() - 1; + if (headLastRow > headFirstRow) { + sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, headFirstRow, headLastRow)); + } + rownum++; + } + } + + /** + * 瀵筫xcel琛ㄥ崟榛樿绗竴涓储寮曞悕杞崲鎴恖ist + * + * @param is 杈撳叆娴 + * @return 杞崲鍚庨泦鍚 + */ + public List importExcel(InputStream is) throws Exception { + return importExcel(is, 0); + } + + /** + * 瀵筫xcel琛ㄥ崟榛樿绗竴涓储寮曞悕杞崲鎴恖ist + * + * @param is 杈撳叆娴 + * @param titleNum 鏍囬鍗犵敤琛屾暟 + * @return 杞崲鍚庨泦鍚 + */ + public List importExcel(InputStream is, int titleNum) throws Exception { + return importExcel(StringUtils.EMPTY, is, titleNum); + } + + /** + * 瀵筫xcel琛ㄥ崟鎸囧畾琛ㄦ牸绱㈠紩鍚嶈浆鎹㈡垚list + * + * @param sheetName 琛ㄦ牸绱㈠紩鍚 + * @param titleNum 鏍囬鍗犵敤琛屾暟 + * @param is 杈撳叆娴 + * @return 杞崲鍚庨泦鍚 + */ + public List importExcel(String sheetName, InputStream is, int titleNum) throws Exception { + this.type = Type.IMPORT; + this.wb = WorkbookFactory.create(is); + List list = new ArrayList(); + // 濡傛灉鎸囧畾sheet鍚,鍒欏彇鎸囧畾sheet涓殑鍐呭 鍚﹀垯榛樿鎸囧悜绗1涓猻heet + Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0); + if (sheet == null) { + throw new IOException("鏂囦欢sheet涓嶅瓨鍦"); + } + boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook); + Map pictures; + if (isXSSFWorkbook) { + pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb); + } else { + pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb); + } + // 鑾峰彇鏈鍚庝竴涓潪绌鸿鐨勮涓嬫爣锛屾瘮濡傛昏鏁颁负n锛屽垯杩斿洖鐨勪负n-1 + int rows = sheet.getLastRowNum(); + + if (rows > 0) { + // 瀹氫箟涓涓猰ap鐢ㄤ簬瀛樻斁excel鍒楃殑搴忓彿鍜宖ield. + Map cellMap = new HashMap(); + // 鑾峰彇琛ㄥご + Row heard = sheet.getRow(titleNum); + for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) { + Cell cell = heard.getCell(i); + if (StringUtils.isNotNull(cell)) { + String value = this.getCellValue(heard, i).toString(); + cellMap.put(value, i); + } else { + cellMap.put(null, i); + } + } + // 鏈夋暟鎹椂鎵嶅鐞 寰楀埌绫荤殑鎵鏈塮ield. + List fields = this.getFields(); + Map fieldsMap = new HashMap(); + for (Object[] objects : fields) { + Excel attr = (Excel) objects[1]; + Integer column = cellMap.get(attr.name()); + if (column != null) { + fieldsMap.put(column, objects); + } + } + for (int i = titleNum + 1; i <= rows; i++) { + // 浠庣2琛屽紑濮嬪彇鏁版嵁,榛樿绗竴琛屾槸琛ㄥご. + Row row = sheet.getRow(i); + // 鍒ゆ柇褰撳墠琛屾槸鍚︽槸绌鸿 + if (isRowEmpty(row)) { + continue; + } + T entity = null; + for (Map.Entry entry : fieldsMap.entrySet()) { + Object val = this.getCellValue(row, entry.getKey()); + + // 濡傛灉涓嶅瓨鍦ㄥ疄渚嬪垯鏂板缓. + entity = (entity == null ? clazz.newInstance() : entity); + // 浠巑ap涓緱鍒板搴斿垪鐨刦ield. + Field field = (Field) entry.getValue()[0]; + Excel attr = (Excel) entry.getValue()[1]; + // 鍙栧緱绫诲瀷,骞舵牴鎹璞$被鍨嬭缃. + Class fieldType = field.getType(); + if (String.class == fieldType) { + String s = Convert.toStr(val); + if (StringUtils.endsWith(s, ".0")) { + val = StringUtils.substringBefore(s, ".0"); + } else { + String dateFormat = field.getAnnotation(Excel.class).dateFormat(); + if (StringUtils.isNotEmpty(dateFormat)) { + val = parseDateToStr(dateFormat, val); + } else { + val = Convert.toStr(val); + } + } + } else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) { + val = Convert.toInt(val); + } else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) { + val = Convert.toLong(val); + } else if (Double.TYPE == fieldType || Double.class == fieldType) { + val = Convert.toDouble(val); + } else if (Float.TYPE == fieldType || Float.class == fieldType) { + val = Convert.toFloat(val); + } else if (BigDecimal.class == fieldType) { + val = Convert.toBigDecimal(val); + } else if (Date.class == fieldType) { + if (val instanceof String) { + val = DateUtils.parseDate(val); + } else if (val instanceof Double) { + val = DateUtil.getJavaDate((Double) val); + } + } else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) { + val = Convert.toBool(val, false); + } + if (StringUtils.isNotNull(fieldType)) { + String propertyName = field.getName(); + if (StringUtils.isNotEmpty(attr.targetAttr())) { + propertyName = field.getName() + "." + attr.targetAttr(); + } else if (StringUtils.isNotEmpty(attr.readConverterExp())) { + val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator()); + } else if (StringUtils.isNotEmpty(attr.dictType())) { + val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator()); + } else if (!attr.handler().equals(ExcelHandlerAdapter.class)) { + val = dataFormatHandlerAdapter(val, attr); + } else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures)) { + PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey()); + if (image == null) { + val = ""; + } else { + byte[] data = image.getData(); + val = FileUtils.writeImportBytes(data); + } + } + ReflectUtils.invokeSetter(entity, propertyName, val); + } + } + list.add(entity); + } + } + return list; + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @param list 瀵煎嚭鏁版嵁闆嗗悎 + * @param sheetName 宸ヤ綔琛ㄧ殑鍚嶇О + * @return 缁撴灉 + */ + public AjaxResult exportExcel(List list, String sheetName) { + return exportExcel(list, sheetName, StringUtils.EMPTY); + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @param list 瀵煎嚭鏁版嵁闆嗗悎 + * @param sheetName 宸ヤ綔琛ㄧ殑鍚嶇О + * @param title 鏍囬 + * @return 缁撴灉 + */ + public AjaxResult exportExcel(List list, String sheetName, String title) { + this.init(list, sheetName, title, Type.EXPORT); + return exportExcel(); + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @param response 杩斿洖鏁版嵁 + * @param list 瀵煎嚭鏁版嵁闆嗗悎 + * @param sheetName 宸ヤ綔琛ㄧ殑鍚嶇О + * @return 缁撴灉 + */ + public void exportExcel(HttpServletResponse response, List list, String sheetName) { + exportExcel(response, list, sheetName, StringUtils.EMPTY); + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @param response 杩斿洖鏁版嵁 + * @param list 瀵煎嚭鏁版嵁闆嗗悎 + * @param sheetName 宸ヤ綔琛ㄧ殑鍚嶇О + * @param title 鏍囬 + * @return 缁撴灉 + */ + public void exportExcel(HttpServletResponse response, List list, String sheetName, String title) { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + this.init(list, sheetName, title, Type.EXPORT); + exportExcel(response); + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @param sheetName 宸ヤ綔琛ㄧ殑鍚嶇О + * @return 缁撴灉 + */ + public AjaxResult importTemplateExcel(String sheetName) { + return importTemplateExcel(sheetName, StringUtils.EMPTY); + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @param sheetName 宸ヤ綔琛ㄧ殑鍚嶇О + * @param title 鏍囬 + * @return 缁撴灉 + */ + public AjaxResult importTemplateExcel(String sheetName, String title) { + this.init(null, sheetName, title, Type.IMPORT); + return exportExcel(); + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @param sheetName 宸ヤ綔琛ㄧ殑鍚嶇О + * @return 缁撴灉 + */ + public void importTemplateExcel(HttpServletResponse response, String sheetName) { + importTemplateExcel(response, sheetName, StringUtils.EMPTY); + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @param sheetName 宸ヤ綔琛ㄧ殑鍚嶇О + * @param title 鏍囬 + * @return 缁撴灉 + */ + public void importTemplateExcel(HttpServletResponse response, String sheetName, String title) { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + this.init(null, sheetName, title, Type.IMPORT); + exportExcel(response); + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @return 缁撴灉 + */ + public void exportExcel(HttpServletResponse response) { + try { + writeSheet(); + wb.write(response.getOutputStream()); + } catch (Exception e) { + log.error("瀵煎嚭Excel寮傚父{}", e.getMessage()); + } finally { + IOUtils.closeQuietly(wb); + } + } + + /** + * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟 + * + * @return 缁撴灉 + */ + public AjaxResult exportExcel() { + OutputStream out = null; + try { + writeSheet(); + String filename = encodingFilename(sheetName); + out = new FileOutputStream(getAbsoluteFile(filename)); + wb.write(out); + return AjaxResult.success(filename); + } catch (Exception e) { + log.error("瀵煎嚭Excel寮傚父{}", e.getMessage()); + throw new UtilException("瀵煎嚭Excel澶辫触锛岃鑱旂郴缃戠珯绠$悊鍛橈紒"); + } finally { + IOUtils.closeQuietly(wb); + IOUtils.closeQuietly(out); + } + } + + /** + * 鍒涘缓鍐欏叆鏁版嵁鍒癝heet + */ + public void writeSheet() { + // 鍙栧嚭涓鍏辨湁澶氬皯涓猻heet. + int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize)); + for (int index = 0; index < sheetNo; index++) { + createSheet(sheetNo, index); + + // 浜х敓涓琛 + Row row = sheet.createRow(rownum); + int column = 0; + // 鍐欏叆鍚勪釜瀛楁鐨勫垪澶村悕绉 + for (Object[] os : fields) { + Field field = (Field) os[0]; + Excel excel = (Excel) os[1]; + if (Collection.class.isAssignableFrom(field.getType())) { + for (Field subField : subFields) { + Excel subExcel = subField.getAnnotation(Excel.class); + this.createHeadCell(subExcel, row, column++); + } + } else { + this.createHeadCell(excel, row, column++); + } + } + if (Type.EXPORT.equals(type)) { + fillExcelData(index, row); + addStatisticsRow(); + } + } + } + + /** + * 濉厖excel鏁版嵁 + * + * @param index 搴忓彿 + * @param row 鍗曞厓鏍艰 + */ + @SuppressWarnings("unchecked") + public void fillExcelData(int index, Row row) { + int startNo = index * sheetSize; + int endNo = Math.min(startNo + sheetSize, list.size()); + int rowNo = (1 + rownum) - startNo; + for (int i = startNo; i < endNo; i++) { + rowNo = i > 1 ? rowNo + 1 : rowNo + i; + row = sheet.createRow(rowNo); + // 寰楀埌瀵煎嚭瀵硅薄. + T vo = (T) list.get(i); + Collection subList = null; + if (isSubListValue(vo)) { + subList = getListCellValue(vo); + subMergedLastRowNum = subMergedLastRowNum + subList.size(); + } + + int column = 0; + for (Object[] os : fields) { + Field field = (Field) os[0]; + Excel excel = (Excel) os[1]; + if (Collection.class.isAssignableFrom(field.getType()) && StringUtils.isNotNull(subList)) { + boolean subFirst = false; + for (Object obj : subList) { + if (subFirst) { + rowNo++; + row = sheet.createRow(rowNo); + } + List subFields = FieldUtils.getFieldsListWithAnnotation(obj.getClass(), Excel.class); + int subIndex = 0; + for (Field subField : subFields) { + if (subField.isAnnotationPresent(Excel.class)) { + subField.setAccessible(true); + Excel attr = subField.getAnnotation(Excel.class); + this.addCell(attr, row, (T) obj, subField, column + subIndex); + } + subIndex++; + } + subFirst = true; + } + this.subMergedFirstRowNum = this.subMergedFirstRowNum + subList.size(); + } else { + this.addCell(excel, row, vo, field, column++); + } + } + } + } + + /** + * 鍒涘缓琛ㄦ牸鏍峰紡 + * + * @param wb 宸ヤ綔钖勫璞 + * @return 鏍峰紡鍒楄〃 + */ + private Map createStyles(Workbook wb) { + // 鍐欏叆鍚勬潯璁板綍,姣忔潯璁板綍瀵瑰簲excel琛ㄤ腑鐨勪竴琛 + Map styles = new HashMap(); + CellStyle style = wb.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + Font titleFont = wb.createFont(); + titleFont.setFontName("Arial"); + titleFont.setFontHeightInPoints((short) 16); + titleFont.setBold(true); + style.setFont(titleFont); + styles.put("title", style); + + style = wb.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setBorderRight(BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderLeft(BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderTop(BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderBottom(BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + Font dataFont = wb.createFont(); + dataFont.setFontName("Arial"); + dataFont.setFontHeightInPoints((short) 10); + style.setFont(dataFont); + styles.put("data", style); + + style = wb.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + Font totalFont = wb.createFont(); + totalFont.setFontName("Arial"); + totalFont.setFontHeightInPoints((short) 10); + style.setFont(totalFont); + styles.put("total", style); + + styles.putAll(annotationHeaderStyles(wb, styles)); + + styles.putAll(annotationDataStyles(wb)); + + return styles; + } + + /** + * 鏍规嵁Excel娉ㄨВ鍒涘缓琛ㄦ牸澶存牱寮 + * + * @param wb 宸ヤ綔钖勫璞 + * @return 鑷畾涔夋牱寮忓垪琛 + */ + private Map annotationHeaderStyles(Workbook wb, Map styles) { + Map headerStyles = new HashMap(); + for (Object[] os : fields) { + Excel excel = (Excel) os[1]; + String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor()); + if (!headerStyles.containsKey(key)) { + CellStyle style = wb.createCellStyle(); + style = wb.createCellStyle(); + style.cloneStyleFrom(styles.get("data")); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setFillForegroundColor(excel.headerBackgroundColor().index); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + Font headerFont = wb.createFont(); + headerFont.setFontName("Arial"); + headerFont.setFontHeightInPoints((short) 10); + headerFont.setBold(true); + headerFont.setColor(excel.headerColor().index); + style.setFont(headerFont); + headerStyles.put(key, style); + } + } + return headerStyles; + } + + /** + * 鏍规嵁Excel娉ㄨВ鍒涘缓琛ㄦ牸鍒楁牱寮 + * + * @param wb 宸ヤ綔钖勫璞 + * @return 鑷畾涔夋牱寮忓垪琛 + */ + private Map annotationDataStyles(Workbook wb) { + Map styles = new HashMap(); + for (Object[] os : fields) { + Excel excel = (Excel) os[1]; + String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor()); + if (!styles.containsKey(key)) { + CellStyle style = wb.createCellStyle(); + style = wb.createCellStyle(); + style.setAlignment(excel.align()); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setBorderRight(BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderLeft(BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderTop(BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderBottom(BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + style.setFillForegroundColor(excel.backgroundColor().getIndex()); + Font dataFont = wb.createFont(); + dataFont.setFontName("Arial"); + dataFont.setFontHeightInPoints((short) 10); + dataFont.setColor(excel.color().index); + style.setFont(dataFont); + styles.put(key, style); + } + } + return styles; + } + + /** + * 鍒涘缓鍗曞厓鏍 + */ + public Cell createHeadCell(Excel attr, Row row, int column) { + // 鍒涘缓鍒 + Cell cell = row.createCell(column); + // 鍐欏叆鍒椾俊鎭 + cell.setCellValue(attr.name()); + setDataValidation(attr, row, column); + cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()))); + if (isSubList()) { + // 濉厖榛樿鏍峰紡锛岄槻姝㈠悎骞跺崟鍏冩牸鏍峰紡澶辨晥 + sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor()))); + if (attr.needMerge()) { + sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column)); + } + } + return cell; + } + + /** + * 璁剧疆鍗曞厓鏍间俊鎭 + * + * @param value 鍗曞厓鏍煎 + * @param attr 娉ㄨВ鐩稿叧 + * @param cell 鍗曞厓鏍间俊鎭 + */ + public void setCellVo(Object value, Excel attr, Cell cell) { + if (ColumnType.STRING == attr.cellType()) { + String cellValue = Convert.toStr(value); + // 瀵逛簬浠讳綍浠ヨ〃杈惧紡瑙﹀彂瀛楃 =-+@寮澶寸殑鍗曞厓鏍硷紝鐩存帴浣跨敤tab瀛楃浣滀负鍓嶇紑锛岄槻姝SV娉ㄥ叆銆 + if (StringUtils.startsWithAny(cellValue, FORMULA_STR)) { + cellValue = RegExUtils.replaceFirst(cellValue, FORMULA_REGEX_STR, "\t$0"); + } + cell.setCellValue(StringUtils.isNull(cellValue) ? attr.defaultValue() : cellValue + attr.suffix()); + } else if (ColumnType.NUMERIC == attr.cellType()) { + if (StringUtils.isNotNull(value)) { + cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); + } + } else if (ColumnType.IMAGE == attr.cellType()) { + ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); + String imagePath = Convert.toStr(value); + if (StringUtils.isNotEmpty(imagePath)) { + byte[] data = ImageUtils.getImage(imagePath); + getDrawingPatriarch(cell.getSheet()).createPicture(anchor, + cell.getSheet().getWorkbook().addPicture(data, getImageType(data))); + } + } + } + + /** + * 鑾峰彇鐢诲竷 + */ + public static Drawing getDrawingPatriarch(Sheet sheet) { + if (sheet.getDrawingPatriarch() == null) { + sheet.createDrawingPatriarch(); + } + return sheet.getDrawingPatriarch(); + } + + /** + * 鑾峰彇鍥剧墖绫诲瀷,璁剧疆鍥剧墖鎻掑叆绫诲瀷 + */ + public int getImageType(byte[] value) { + String type = FileTypeUtils.getFileExtendName(value); + if ("JPG".equalsIgnoreCase(type)) { + return Workbook.PICTURE_TYPE_JPEG; + } else if ("PNG".equalsIgnoreCase(type)) { + return Workbook.PICTURE_TYPE_PNG; + } + return Workbook.PICTURE_TYPE_JPEG; + } + + /** + * 鍒涘缓琛ㄦ牸鏍峰紡 + */ + public void setDataValidation(Excel attr, Row row, int column) { + if (attr.name().indexOf("娉細") >= 0) { + sheet.setColumnWidth(column, 6000); + } else { + // 璁剧疆鍒楀 + sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256)); + } + if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0) { + // 鎻愮ず淇℃伅鎴栧彧鑳介夋嫨涓嶈兘杈撳叆鐨勫垪鍐呭. + setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column); + } + } + + /** + * 娣诲姞鍗曞厓鏍 + */ + public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { + Cell cell = null; + try { + // 璁剧疆琛岄珮 + row.setHeight(maxHeight); + // 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑,鏈変簺鎯呭喌闇瑕佷繚鎸佷负绌,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒. + if (attr.isExport()) { + // 鍒涘缓cell + cell = row.createCell(column); + if (isSubListValue(vo) && getListCellValue(vo).size() > 1 && attr.needMerge()) { + CellRangeAddress cellAddress = new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column); + sheet.addMergedRegion(cellAddress); + } + cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor()))); + + // 鐢ㄤ簬璇诲彇瀵硅薄涓殑灞炴 + Object value = getTargetValue(vo, field, attr); + String dateFormat = attr.dateFormat(); + String readConverterExp = attr.readConverterExp(); + String separator = attr.separator(); + String dictType = attr.dictType(); + if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) { + cell.setCellValue(parseDateToStr(dateFormat, value)); + } else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) { + cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator)); + } else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value)) { + cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator)); + } else if (value instanceof BigDecimal && -1 != attr.scale()) { + cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue()); + } else if (!attr.handler().equals(ExcelHandlerAdapter.class)) { + cell.setCellValue(dataFormatHandlerAdapter(value, attr)); + } else { + // 璁剧疆鍒楃被鍨 + setCellVo(value, attr, cell); + } + addStatisticsData(column, Convert.toStr(value), attr); + } + } catch (Exception e) { + log.error("瀵煎嚭Excel澶辫触{}", e); + } + return cell; + } + + /** + * 璁剧疆 POI XSSFSheet 鍗曞厓鏍兼彁绀烘垨閫夋嫨妗 + * + * @param sheet 琛ㄥ崟 + * @param textlist 涓嬫媺妗嗘樉绀虹殑鍐呭 + * @param promptContent 鎻愮ず鍐呭 + * @param firstRow 寮濮嬭 + * @param endRow 缁撴潫琛 + * @param firstCol 寮濮嬪垪 + * @param endCol 缁撴潫鍒 + */ + public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, + int firstCol, int endCol) { + DataValidationHelper helper = sheet.getDataValidationHelper(); + DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1"); + CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); + DataValidation dataValidation = helper.createValidation(constraint, regions); + if (StringUtils.isNotEmpty(promptContent)) { + // 濡傛灉璁剧疆浜嗘彁绀轰俊鎭垯榧犳爣鏀句笂鍘绘彁绀 + dataValidation.createPromptBox("", promptContent); + dataValidation.setShowPromptBox(true); + } + // 澶勭悊Excel鍏煎鎬ч棶棰 + if (dataValidation instanceof XSSFDataValidation) { + dataValidation.setSuppressDropDownArrow(true); + dataValidation.setShowErrorBox(true); + } else { + dataValidation.setSuppressDropDownArrow(false); + } + sheet.addValidationData(dataValidation); + } + + /** + * 瑙f瀽瀵煎嚭鍊 0=鐢,1=濂,2=鏈煡 + * + * @param propertyValue 鍙傛暟鍊 + * @param converterExp 缈昏瘧娉ㄨВ + * @param separator 鍒嗛殧绗 + * @return 瑙f瀽鍚庡 + */ + public static String convertByExp(String propertyValue, String converterExp, String separator) { + StringBuilder propertyString = new StringBuilder(); + String[] convertSource = converterExp.split(","); + for (String item : convertSource) { + String[] itemArray = item.split("="); + if (StringUtils.containsAny(propertyValue, separator)) { + for (String value : propertyValue.split(separator)) { + if (itemArray[0].equals(value)) { + propertyString.append(itemArray[1] + separator); + break; + } + } + } else { + if (itemArray[0].equals(propertyValue)) { + return itemArray[1]; + } + } + } + return StringUtils.stripEnd(propertyString.toString(), separator); + } + + /** + * 鍙嶅悜瑙f瀽鍊 鐢=0,濂=1,鏈煡=2 + * + * @param propertyValue 鍙傛暟鍊 + * @param converterExp 缈昏瘧娉ㄨВ + * @param separator 鍒嗛殧绗 + * @return 瑙f瀽鍚庡 + */ + public static String reverseByExp(String propertyValue, String converterExp, String separator) { + StringBuilder propertyString = new StringBuilder(); + String[] convertSource = converterExp.split(","); + for (String item : convertSource) { + String[] itemArray = item.split("="); + if (StringUtils.containsAny(propertyValue, separator)) { + for (String value : propertyValue.split(separator)) { + if (itemArray[1].equals(value)) { + propertyString.append(itemArray[0] + separator); + break; + } + } + } else { + if (itemArray[1].equals(propertyValue)) { + return itemArray[0]; + } + } + } + return StringUtils.stripEnd(propertyString.toString(), separator); + } + + /** + * 瑙f瀽瀛楀吀鍊 + * + * @param dictValue 瀛楀吀鍊 + * @param dictType 瀛楀吀绫诲瀷 + * @param separator 鍒嗛殧绗 + * @return 瀛楀吀鏍囩 + */ + public static String convertDictByExp(String dictValue, String dictType, String separator) { + return DictUtils.getDictLabel(dictType, dictValue, separator); + } + + /** + * 鍙嶅悜瑙f瀽鍊煎瓧鍏稿 + * + * @param dictLabel 瀛楀吀鏍囩 + * @param dictType 瀛楀吀绫诲瀷 + * @param separator 鍒嗛殧绗 + * @return 瀛楀吀鍊 + */ + public static String reverseDictByExp(String dictLabel, String dictType, String separator) { + return DictUtils.getDictValue(dictType, dictLabel, separator); + } + + /** + * 鏁版嵁澶勭悊鍣 + * + * @param value 鏁版嵁鍊 + * @param excel 鏁版嵁娉ㄨВ + * @return + */ + public String dataFormatHandlerAdapter(Object value, Excel excel) { + try { + Object instance = excel.handler().newInstance(); + Method formatMethod = excel.handler().getMethod("format", new Class[]{Object.class, String[].class}); + value = formatMethod.invoke(instance, value, excel.args()); + } catch (Exception e) { + log.error("涓嶈兘鏍煎紡鍖栨暟鎹 " + excel.handler(), e.getMessage()); + } + return Convert.toStr(value); + } + + /** + * 鍚堣缁熻淇℃伅 + */ + private void addStatisticsData(Integer index, String text, Excel entity) { + if (entity != null && entity.isStatistics()) { + Double temp = 0D; + if (!statistics.containsKey(index)) { + statistics.put(index, temp); + } + try { + temp = Double.valueOf(text); + } catch (NumberFormatException e) { + } + statistics.put(index, statistics.get(index) + temp); + } + } + + /** + * 鍒涘缓缁熻琛 + */ + public void addStatisticsRow() { + if (statistics.size() > 0) { + Row row = sheet.createRow(sheet.getLastRowNum() + 1); + Set keys = statistics.keySet(); + Cell cell = row.createCell(0); + cell.setCellStyle(styles.get("total")); + cell.setCellValue("鍚堣"); + + for (Integer key : keys) { + cell = row.createCell(key); + cell.setCellStyle(styles.get("total")); + cell.setCellValue(DOUBLE_FORMAT.format(statistics.get(key))); + } + statistics.clear(); + } + } + + /** + * 缂栫爜鏂囦欢鍚 + */ + public String encodingFilename(String filename) { + filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx"; + return filename; + } + + /** + * 鑾峰彇涓嬭浇璺緞 + * + * @param filename 鏂囦欢鍚嶇О + */ + public String getAbsoluteFile(String filename) { + String downloadPath = JsowellConfig.getDownloadPath() + filename; + File desc = new File(downloadPath); + if (!desc.getParentFile().exists()) { + desc.getParentFile().mkdirs(); + } + return downloadPath; + } + + /** + * 鑾峰彇bean涓殑灞炴у + * + * @param vo 瀹炰綋瀵硅薄 + * @param field 瀛楁 + * @param excel 娉ㄨВ + * @return 鏈缁堢殑灞炴у + * @throws Exception + */ + private Object getTargetValue(T vo, Field field, Excel excel) throws Exception { + Object o = field.get(vo); + if (StringUtils.isNotEmpty(excel.targetAttr())) { + String target = excel.targetAttr(); + if (target.contains(".")) { + String[] targets = target.split("[.]"); + for (String name : targets) { + o = getValue(o, name); + } + } else { + o = getValue(o, target); + } + } + return o; + } + + /** + * 浠ョ被鐨勫睘鎬х殑get鏂规硶鏂规硶褰㈠紡鑾峰彇鍊 + * + * @param o + * @param name + * @return value + * @throws Exception + */ + private Object getValue(Object o, String name) throws Exception { + if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name)) { + Class clazz = o.getClass(); + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + o = field.get(o); + } + return o; + } + + /** + * 寰楀埌鎵鏈夊畾涔夊瓧娈 + */ + private void createExcelField() { + this.fields = getFields(); + this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList()); + this.maxHeight = getRowHeight(); + } + + /** + * 鑾峰彇瀛楁娉ㄨВ淇℃伅 + */ + public List getFields() { + List fields = new ArrayList(); + List tempFields = new ArrayList<>(); + tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); + tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); + for (Field field : tempFields) { + if (!ArrayUtils.contains(this.excludeFields, field.getName())) { + // 鍗曟敞瑙 + if (field.isAnnotationPresent(Excel.class)) { + Excel attr = field.getAnnotation(Excel.class); + if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) { + field.setAccessible(true); + fields.add(new Object[]{field, attr}); + } + if (Collection.class.isAssignableFrom(field.getType())) { + subMethod = getSubMethod(field.getName(), clazz); + ParameterizedType pt = (ParameterizedType) field.getGenericType(); + Class subClass = (Class) pt.getActualTypeArguments()[0]; + this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class); + } + } + + // 澶氭敞瑙 + if (field.isAnnotationPresent(Excels.class)) { + Excels attrs = field.getAnnotation(Excels.class); + Excel[] excels = attrs.value(); + for (Excel attr : excels) { + if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) { + field.setAccessible(true); + fields.add(new Object[]{field, attr}); + } + } + } + } + } + return fields; + } + + /** + * 鏍规嵁娉ㄨВ鑾峰彇鏈澶ц楂 + */ + public short getRowHeight() { + double maxHeight = 0; + for (Object[] os : this.fields) { + Excel excel = (Excel) os[1]; + maxHeight = Math.max(maxHeight, excel.height()); + } + return (short) (maxHeight * 20); + } + + /** + * 鍒涘缓涓涓伐浣滅翱 + */ + public void createWorkbook() { + this.wb = new SXSSFWorkbook(500); + this.sheet = wb.createSheet(); + wb.setSheetName(0, sheetName); + this.styles = createStyles(wb); + } + + /** + * 鍒涘缓宸ヤ綔琛 + * + * @param sheetNo sheet鏁伴噺 + * @param index 搴忓彿 + */ + public void createSheet(int sheetNo, int index) { + // 璁剧疆宸ヤ綔琛ㄧ殑鍚嶇О. + if (sheetNo > 1 && index > 0) { + this.sheet = wb.createSheet(); + this.createTitle(); + wb.setSheetName(index, sheetName + index); + } + } + + /** + * 鑾峰彇鍗曞厓鏍煎 + * + * @param row 鑾峰彇鐨勮 + * @param column 鑾峰彇鍗曞厓鏍煎垪鍙 + * @return 鍗曞厓鏍煎 + */ + public Object getCellValue(Row row, int column) { + if (row == null) { + return row; + } + Object val = ""; + try { + Cell cell = row.getCell(column); + if (StringUtils.isNotNull(cell)) { + if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA) { + val = cell.getNumericCellValue(); + if (DateUtil.isCellDateFormatted(cell)) { + val = DateUtil.getJavaDate((Double) val); // POI Excel 鏃ユ湡鏍煎紡杞崲 + } else { + if ((Double) val % 1 != 0) { + val = new BigDecimal(val.toString()); + } else { + val = new DecimalFormat("0").format(val); + } + } + } else if (cell.getCellType() == CellType.STRING) { + val = cell.getStringCellValue(); + } else if (cell.getCellType() == CellType.BOOLEAN) { + val = cell.getBooleanCellValue(); + } else if (cell.getCellType() == CellType.ERROR) { + val = cell.getErrorCellValue(); + } + + } + } catch (Exception e) { + return val; + } + return val; + } + + /** + * 鍒ゆ柇鏄惁鏄┖琛 + * + * @param row 鍒ゆ柇鐨勮 + * @return + */ + private boolean isRowEmpty(Row row) { + if (row == null) { + return true; + } + for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { + Cell cell = row.getCell(i); + if (cell != null && cell.getCellType() != CellType.BLANK) { + return false; + } + } + return true; + } + + /** + * 鑾峰彇Excel2003鍥剧墖 + * + * @param sheet 褰撳墠sheet瀵硅薄 + * @param workbook 宸ヤ綔绨垮璞 + * @return Map key:鍥剧墖鍗曞厓鏍肩储寮曪紙1_1锛塖tring锛寁alue:鍥剧墖娴丳ictureData + */ + public static Map getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook) { + Map sheetIndexPicMap = new HashMap(); + List pictures = workbook.getAllPictures(); + if (!pictures.isEmpty()) { + for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) { + HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor(); + if (shape instanceof HSSFPicture) { + HSSFPicture pic = (HSSFPicture) shape; + int pictureIndex = pic.getPictureIndex() - 1; + HSSFPictureData picData = pictures.get(pictureIndex); + String picIndex = String.valueOf(anchor.getRow1()) + "_" + String.valueOf(anchor.getCol1()); + sheetIndexPicMap.put(picIndex, picData); + } + } + return sheetIndexPicMap; + } else { + return sheetIndexPicMap; + } + } + + /** + * 鑾峰彇Excel2007鍥剧墖 + * + * @param sheet 褰撳墠sheet瀵硅薄 + * @param workbook 宸ヤ綔绨垮璞 + * @return Map key:鍥剧墖鍗曞厓鏍肩储寮曪紙1_1锛塖tring锛寁alue:鍥剧墖娴丳ictureData + */ + public static Map getSheetPictures07(XSSFSheet sheet, XSSFWorkbook workbook) { + Map sheetIndexPicMap = new HashMap(); + for (POIXMLDocumentPart dr : sheet.getRelations()) { + if (dr instanceof XSSFDrawing) { + XSSFDrawing drawing = (XSSFDrawing) dr; + List shapes = drawing.getShapes(); + for (XSSFShape shape : shapes) { + if (shape instanceof XSSFPicture) { + XSSFPicture pic = (XSSFPicture) shape; + XSSFClientAnchor anchor = pic.getPreferredSize(); + CTMarker ctMarker = anchor.getFrom(); + String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol(); + sheetIndexPicMap.put(picIndex, pic.getPictureData()); + } + } + } + } + return sheetIndexPicMap; + } + + /** + * 鏍煎紡鍖栦笉鍚岀被鍨嬬殑鏃ユ湡瀵硅薄 + * + * @param dateFormat 鏃ユ湡鏍煎紡 + * @param val 琚牸寮忓寲鐨勬棩鏈熷璞 + * @return 鏍煎紡鍖栧悗鐨勬棩鏈熷瓧绗 + */ + public String parseDateToStr(String dateFormat, Object val) { + if (val == null) { + return ""; + } + String str; + if (val instanceof Date) { + str = DateUtils.parseDateToStr(dateFormat, (Date) val); + } else if (val instanceof LocalDateTime) { + str = DateUtils.parseDateToStr(dateFormat, DateUtils.localDateTime2Date((LocalDateTime) val)); + } else if (val instanceof LocalDate) { + str = DateUtils.parseDateToStr(dateFormat, DateUtils.localDate2Date((LocalDate) val)); + } else { + str = val.toString(); + } + return str; + } + + /** + * 鏄惁鏈夊璞$殑瀛愬垪琛 + */ + public boolean isSubList() { + return StringUtils.isNotNull(subFields) && subFields.size() > 0; + } + + /** + * 鏄惁鏈夊璞$殑瀛愬垪琛紝闆嗗悎涓嶄负绌 + */ + public boolean isSubListValue(T vo) { + return StringUtils.isNotNull(subFields) && subFields.size() > 0 && StringUtils.isNotNull(getListCellValue(vo)) && getListCellValue(vo).size() > 0; + } + + /** + * 鑾峰彇闆嗗悎鐨勫 + */ + public Collection getListCellValue(Object obj) { + Object value; + try { + value = subMethod.invoke(obj, new Object[]{}); + } catch (Exception e) { + return new ArrayList(); + } + return (Collection) value; + } + + /** + * 鑾峰彇瀵硅薄鐨勫瓙鍒楄〃鏂规硶 + * + * @param name 鍚嶇О + * @param pojoClass 绫诲璞 + * @return 瀛愬垪琛ㄦ柟娉 + */ + public Method getSubMethod(String name, Class pojoClass) { + StringBuffer getMethodName = new StringBuffer("get"); + getMethodName.append(name.substring(0, 1).toUpperCase()); + getMethodName.append(name.substring(1)); + Method method = null; + try { + method = pojoClass.getMethod(getMethodName.toString(), new Class[]{}); + } catch (Exception e) { + log.error("鑾峰彇瀵硅薄寮傚父{}", e.getMessage()); + } + return method; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/reflect/ReflectUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/reflect/ReflectUtils.java new file mode 100644 index 000000000..1d9ff8910 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/reflect/ReflectUtils.java @@ -0,0 +1,329 @@ +package com.jsowell.common.util.reflect; + +import com.jsowell.common.core.text.Convert; +import com.jsowell.common.util.DateUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; +import org.apache.poi.ss.usermodel.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Date; + +/** + * 鍙嶅皠宸ュ叿绫. 鎻愪緵璋冪敤getter/setter鏂规硶, 璁块棶绉佹湁鍙橀噺, 璋冪敤绉佹湁鏂规硶, 鑾峰彇娉涘瀷绫诲瀷Class, 琚獳OP杩囩殑鐪熷疄绫荤瓑宸ュ叿鍑芥暟. + * + * @author jsowell + */ +@SuppressWarnings("rawtypes") +public class ReflectUtils { + private static final String SETTER_PREFIX = "set"; + + private static final String GETTER_PREFIX = "get"; + + private static final String CGLIB_CLASS_SEPARATOR = "$$"; + + private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class); + + /** + * 璋冪敤Getter鏂规硶. + * 鏀寔澶氱骇锛屽锛氬璞″悕.瀵硅薄鍚.鏂规硶 + */ + @SuppressWarnings("unchecked") + public static E invokeGetter(Object obj, String propertyName) { + Object object = obj; + for (String name : StringUtils.split(propertyName, ".")) { + String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name); + object = invokeMethod(object, getterMethodName, new Class[]{}, new Object[]{}); + } + return (E) object; + } + + /** + * 璋冪敤Setter鏂规硶, 浠呭尮閰嶆柟娉曞悕銆 + * 鏀寔澶氱骇锛屽锛氬璞″悕.瀵硅薄鍚.鏂规硶 + */ + public static void invokeSetter(Object obj, String propertyName, E value) { + Object object = obj; + String[] names = StringUtils.split(propertyName, "."); + for (int i = 0; i < names.length; i++) { + if (i < names.length - 1) { + String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]); + object = invokeMethod(object, getterMethodName, new Class[]{}, new Object[]{}); + } else { + String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]); + invokeMethodByName(object, setterMethodName, new Object[]{value}); + } + } + } + + /** + * 鐩存帴璇诲彇瀵硅薄灞炴у, 鏃犺private/protected淇グ绗, 涓嶇粡杩噂etter鍑芥暟. + */ + @SuppressWarnings("unchecked") + public static E getFieldValue(final Object obj, final String fieldName) { + Field field = getAccessibleField(obj, fieldName); + if (field == null) { + logger.debug("鍦 [" + obj.getClass() + "] 涓紝娌℃湁鎵惧埌 [" + fieldName + "] 瀛楁 "); + return null; + } + E result = null; + try { + result = (E) field.get(obj); + } catch (IllegalAccessException e) { + logger.error("涓嶅彲鑳芥姏鍑虹殑寮傚父{}", e.getMessage()); + } + return result; + } + + /** + * 鐩存帴璁剧疆瀵硅薄灞炴у, 鏃犺private/protected淇グ绗, 涓嶇粡杩噑etter鍑芥暟. + */ + public static void setFieldValue(final Object obj, final String fieldName, final E value) { + Field field = getAccessibleField(obj, fieldName); + if (field == null) { + // throw new IllegalArgumentException("鍦 [" + obj.getClass() + "] 涓紝娌℃湁鎵惧埌 [" + fieldName + "] 瀛楁 "); + logger.debug("鍦 [" + obj.getClass() + "] 涓紝娌℃湁鎵惧埌 [" + fieldName + "] 瀛楁 "); + return; + } + try { + field.set(obj, value); + } catch (IllegalAccessException e) { + logger.error("涓嶅彲鑳芥姏鍑虹殑寮傚父: {}", e.getMessage()); + } + } + + /** + * 鐩存帴璋冪敤瀵硅薄鏂规硶, 鏃犺private/protected淇グ绗. + * 鐢ㄤ簬涓娆℃ц皟鐢ㄧ殑鎯呭喌锛屽惁鍒欏簲浣跨敤getAccessibleMethod()鍑芥暟鑾峰緱Method鍚庡弽澶嶈皟鐢. + * 鍚屾椂鍖归厤鏂规硶鍚+鍙傛暟绫诲瀷锛 + */ + @SuppressWarnings("unchecked") + public static E invokeMethod(final Object obj, final String methodName, final Class[] parameterTypes, + final Object[] args) { + if (obj == null || methodName == null) { + return null; + } + Method method = getAccessibleMethod(obj, methodName, parameterTypes); + if (method == null) { + logger.debug("鍦 [" + obj.getClass() + "] 涓紝娌℃湁鎵惧埌 [" + methodName + "] 鏂规硶 "); + return null; + } + try { + return (E) method.invoke(obj, args); + } catch (Exception e) { + String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; + throw convertReflectionExceptionToUnchecked(msg, e); + } + } + + /** + * 鐩存帴璋冪敤瀵硅薄鏂规硶, 鏃犺private/protected淇グ绗︼紝 + * 鐢ㄤ簬涓娆℃ц皟鐢ㄧ殑鎯呭喌锛屽惁鍒欏簲浣跨敤getAccessibleMethodByName()鍑芥暟鑾峰緱Method鍚庡弽澶嶈皟鐢. + * 鍙尮閰嶅嚱鏁板悕锛屽鏋滄湁澶氫釜鍚屽悕鍑芥暟璋冪敤绗竴涓 + */ + @SuppressWarnings("unchecked") + public static E invokeMethodByName(final Object obj, final String methodName, final Object[] args) { + Method method = getAccessibleMethodByName(obj, methodName, args.length); + if (method == null) { + // 濡傛灉涓虹┖涓嶆姤閿欙紝鐩存帴杩斿洖绌恒 + logger.debug("鍦 [" + obj.getClass() + "] 涓紝娌℃湁鎵惧埌 [" + methodName + "] 鏂规硶 "); + return null; + } + try { + // 绫诲瀷杞崲锛堝皢鍙傛暟鏁版嵁绫诲瀷杞崲涓虹洰鏍囨柟娉曞弬鏁扮被鍨嬶級 + Class[] cs = method.getParameterTypes(); + for (int i = 0; i < cs.length; i++) { + if (args[i] != null && !args[i].getClass().equals(cs[i])) { + if (cs[i] == String.class) { + args[i] = Convert.toStr(args[i]); + if (StringUtils.endsWith((String) args[i], ".0")) { + args[i] = StringUtils.substringBefore((String) args[i], ".0"); + } + } else if (cs[i] == Integer.class) { + args[i] = Convert.toInt(args[i]); + } else if (cs[i] == Long.class) { + args[i] = Convert.toLong(args[i]); + } else if (cs[i] == Double.class) { + args[i] = Convert.toDouble(args[i]); + } else if (cs[i] == Float.class) { + args[i] = Convert.toFloat(args[i]); + } else if (cs[i] == Date.class) { + if (args[i] instanceof String) { + args[i] = DateUtils.parseDate(args[i]); + } else { + args[i] = DateUtil.getJavaDate((Double) args[i]); + } + } else if (cs[i] == boolean.class || cs[i] == Boolean.class) { + args[i] = Convert.toBool(args[i]); + } + } + } + return (E) method.invoke(obj, args); + } catch (Exception e) { + String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; + throw convertReflectionExceptionToUnchecked(msg, e); + } + } + + /** + * 寰幆鍚戜笂杞瀷, 鑾峰彇瀵硅薄鐨凞eclaredField, 骞跺己鍒惰缃负鍙闂. + * 濡傚悜涓婅浆鍨嬪埌Object浠嶆棤娉曟壘鍒, 杩斿洖null. + */ + public static Field getAccessibleField(final Object obj, final String fieldName) { + // 涓虹┖涓嶆姤閿欍傜洿鎺ヨ繑鍥 null + if (obj == null) { + return null; + } + Validate.notBlank(fieldName, "fieldName can't be blank"); + for (Class superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) { + try { + Field field = superClass.getDeclaredField(fieldName); + makeAccessible(field); + return field; + } catch (NoSuchFieldException e) { + continue; + } + } + return null; + } + + /** + * 寰幆鍚戜笂杞瀷, 鑾峰彇瀵硅薄鐨凞eclaredMethod,骞跺己鍒惰缃负鍙闂. + * 濡傚悜涓婅浆鍨嬪埌Object浠嶆棤娉曟壘鍒, 杩斿洖null. + * 鍖归厤鍑芥暟鍚+鍙傛暟绫诲瀷銆 + * 鐢ㄤ簬鏂规硶闇瑕佽澶氭璋冪敤鐨勬儏鍐. 鍏堜娇鐢ㄦ湰鍑芥暟鍏堝彇寰桵ethod,鐒跺悗璋冪敤Method.invoke(Object obj, Object... args) + */ + public static Method getAccessibleMethod(final Object obj, final String methodName, + final Class... parameterTypes) { + // 涓虹┖涓嶆姤閿欍傜洿鎺ヨ繑鍥 null + if (obj == null) { + return null; + } + Validate.notBlank(methodName, "methodName can't be blank"); + for (Class searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) { + try { + Method method = searchType.getDeclaredMethod(methodName, parameterTypes); + makeAccessible(method); + return method; + } catch (NoSuchMethodException e) { + continue; + } + } + return null; + } + + /** + * 寰幆鍚戜笂杞瀷, 鑾峰彇瀵硅薄鐨凞eclaredMethod,骞跺己鍒惰缃负鍙闂. + * 濡傚悜涓婅浆鍨嬪埌Object浠嶆棤娉曟壘鍒, 杩斿洖null. + * 鍙尮閰嶅嚱鏁板悕銆 + * 鐢ㄤ簬鏂规硶闇瑕佽澶氭璋冪敤鐨勬儏鍐. 鍏堜娇鐢ㄦ湰鍑芥暟鍏堝彇寰桵ethod,鐒跺悗璋冪敤Method.invoke(Object obj, Object... args) + */ + public static Method getAccessibleMethodByName(final Object obj, final String methodName, int argsNum) { + // 涓虹┖涓嶆姤閿欍傜洿鎺ヨ繑鍥 null + if (obj == null) { + return null; + } + Validate.notBlank(methodName, "methodName can't be blank"); + for (Class searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) { + Method[] methods = searchType.getDeclaredMethods(); + for (Method method : methods) { + if (method.getName().equals(methodName) && method.getParameterTypes().length == argsNum) { + makeAccessible(method); + return method; + } + } + } + return null; + } + + /** + * 鏀瑰彉private/protected鐨勬柟娉曚负public锛屽敖閲忎笉璋冪敤瀹為檯鏀瑰姩鐨勮鍙ワ紝閬垮厤JDK鐨凷ecurityManager鎶辨ㄣ + */ + public static void makeAccessible(Method method) { + if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) + && !method.isAccessible()) { + method.setAccessible(true); + } + } + + /** + * 鏀瑰彉private/protected鐨勬垚鍛樺彉閲忎负public锛屽敖閲忎笉璋冪敤瀹為檯鏀瑰姩鐨勮鍙ワ紝閬垮厤JDK鐨凷ecurityManager鎶辨ㄣ + */ + public static void makeAccessible(Field field) { + if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) + || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) { + field.setAccessible(true); + } + } + + /** + * 閫氳繃鍙嶅皠, 鑾峰緱Class瀹氫箟涓0鏄庣殑娉涘瀷鍙傛暟鐨勭被鍨, 娉ㄦ剰娉涘瀷蹇呴』瀹氫箟鍦ㄧ埗绫诲 + * 濡傛棤娉曟壘鍒, 杩斿洖Object.class. + */ + @SuppressWarnings("unchecked") + public static Class getClassGenricType(final Class clazz) { + return getClassGenricType(clazz, 0); + } + + /** + * 閫氳繃鍙嶅皠, 鑾峰緱Class瀹氫箟涓0鏄庣殑鐖剁被鐨勬硾鍨嬪弬鏁扮殑绫诲瀷. + * 濡傛棤娉曟壘鍒, 杩斿洖Object.class. + */ + public static Class getClassGenricType(final Class clazz, final int index) { + Type genType = clazz.getGenericSuperclass(); + + if (!(genType instanceof ParameterizedType)) { + logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType"); + return Object.class; + } + + Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); + + if (index >= params.length || index < 0) { + logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + + params.length); + return Object.class; + } + if (!(params[index] instanceof Class)) { + logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); + return Object.class; + } + + return (Class) params[index]; + } + + public static Class getUserClass(Object instance) { + if (instance == null) { + throw new RuntimeException("Instance must not be null"); + } + Class clazz = instance.getClass(); + if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) { + Class superClass = clazz.getSuperclass(); + if (superClass != null && !Object.class.equals(superClass)) { + return superClass; + } + } + return clazz; + + } + + /** + * 灏嗗弽灏勬椂鐨刢hecked exception杞崲涓簎nchecked exception. + */ + public static RuntimeException convertReflectionExceptionToUnchecked(String msg, Exception e) { + if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException + || e instanceof NoSuchMethodException) { + return new IllegalArgumentException(msg, e); + } else if (e instanceof InvocationTargetException) { + return new RuntimeException(msg, ((InvocationTargetException) e).getTargetException()); + } + return new RuntimeException(msg, e); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/sign/Base64.java b/jsowell-common/src/main/java/com/jsowell/common/util/sign/Base64.java new file mode 100644 index 000000000..f4da0faa7 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/sign/Base64.java @@ -0,0 +1,253 @@ +package com.jsowell.common.util.sign; + +/** + * Base64宸ュ叿绫 + * + * @author jsowell + */ +public final class Base64 { + static private final int BASELENGTH = 128; + static private final int LOOKUPLENGTH = 64; + static private final int TWENTYFOURBITGROUP = 24; + static private final int EIGHTBIT = 8; + static private final int SIXTEENBIT = 16; + static private final int FOURBYTE = 4; + static private final int SIGN = -128; + static private final char PAD = '='; + static final private byte[] base64Alphabet = new byte[BASELENGTH]; + static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; + + static { + for (int i = 0; i < BASELENGTH; ++i) { + base64Alphabet[i] = -1; + } + for (int i = 'Z'; i >= 'A'; i--) { + base64Alphabet[i] = (byte) (i - 'A'); + } + for (int i = 'z'; i >= 'a'; i--) { + base64Alphabet[i] = (byte) (i - 'a' + 26); + } + + for (int i = '9'; i >= '0'; i--) { + base64Alphabet[i] = (byte) (i - '0' + 52); + } + + base64Alphabet['+'] = 62; + base64Alphabet['/'] = 63; + + for (int i = 0; i <= 25; i++) { + lookUpBase64Alphabet[i] = (char) ('A' + i); + } + + for (int i = 26, j = 0; i <= 51; i++, j++) { + lookUpBase64Alphabet[i] = (char) ('a' + j); + } + + for (int i = 52, j = 0; i <= 61; i++, j++) { + lookUpBase64Alphabet[i] = (char) ('0' + j); + } + lookUpBase64Alphabet[62] = (char) '+'; + lookUpBase64Alphabet[63] = (char) '/'; + } + + private static boolean isWhiteSpace(char octect) { + return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); + } + + private static boolean isPad(char octect) { + return (octect == PAD); + } + + private static boolean isData(char octect) { + return (octect < BASELENGTH && base64Alphabet[octect] != -1); + } + + /** + * Encodes hex octects into Base64 + * + * @param binaryData Array containing binaryData + * @return Encoded Base64 array + */ + public static String encode(byte[] binaryData) { + if (binaryData == null) { + return null; + } + + int lengthDataBits = binaryData.length * EIGHTBIT; + if (lengthDataBits == 0) { + return ""; + } + + int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP; + int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP; + int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets; + char encodedData[] = null; + + encodedData = new char[numberQuartet * 4]; + + byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0; + + int encodedIndex = 0; + int dataIndex = 0; + + for (int i = 0; i < numberTriplets; i++) { + b1 = binaryData[dataIndex++]; + b2 = binaryData[dataIndex++]; + b3 = binaryData[dataIndex++]; + + l = (byte) (b2 & 0x0f); + k = (byte) (b1 & 0x03); + + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); + byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); + byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc); + + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f]; + } + + // form integral number of 6-bit groups + if (fewerThan24bits == EIGHTBIT) { + b1 = binaryData[dataIndex]; + k = (byte) (b1 & 0x03); + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4]; + encodedData[encodedIndex++] = PAD; + encodedData[encodedIndex++] = PAD; + } else if (fewerThan24bits == SIXTEENBIT) { + b1 = binaryData[dataIndex]; + b2 = binaryData[dataIndex + 1]; + l = (byte) (b2 & 0x0f); + k = (byte) (b1 & 0x03); + + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); + byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); + + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2]; + encodedData[encodedIndex++] = PAD; + } + return new String(encodedData); + } + + /** + * Decodes Base64 data into octects + * + * @param encoded string containing Base64 data + * @return Array containind decoded data. + */ + public static byte[] decode(String encoded) { + if (encoded == null) { + return null; + } + + char[] base64Data = encoded.toCharArray(); + // remove white spaces + int len = removeWhiteSpace(base64Data); + + if (len % FOURBYTE != 0) { + return null;// should be divisible by four + } + + int numberQuadruple = (len / FOURBYTE); + + if (numberQuadruple == 0) { + return new byte[0]; + } + + byte decodedData[] = null; + byte b1 = 0, b2 = 0, b3 = 0, b4 = 0; + char d1 = 0, d2 = 0, d3 = 0, d4 = 0; + + int i = 0; + int encodedIndex = 0; + int dataIndex = 0; + decodedData = new byte[(numberQuadruple) * 3]; + + for (; i < numberQuadruple - 1; i++) { + + if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])) + || !isData((d3 = base64Data[dataIndex++])) || !isData((d4 = base64Data[dataIndex++]))) { + return null; + } // if found "no data" just return null + + b1 = base64Alphabet[d1]; + b2 = base64Alphabet[d2]; + b3 = base64Alphabet[d3]; + b4 = base64Alphabet[d4]; + + decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); + decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); + decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); + } + + if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))) { + return null;// if found "no data" just return null + } + + b1 = base64Alphabet[d1]; + b2 = base64Alphabet[d2]; + + d3 = base64Data[dataIndex++]; + d4 = base64Data[dataIndex++]; + if (!isData((d3)) || !isData((d4))) {// Check if they are PAD characters + if (isPad(d3) && isPad(d4)) { + if ((b2 & 0xf) != 0)// last 4 bits should be zero + { + return null; + } + byte[] tmp = new byte[i * 3 + 1]; + System.arraycopy(decodedData, 0, tmp, 0, i * 3); + tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); + return tmp; + } else if (!isPad(d3) && isPad(d4)) { + b3 = base64Alphabet[d3]; + if ((b3 & 0x3) != 0)// last 2 bits should be zero + { + return null; + } + byte[] tmp = new byte[i * 3 + 2]; + System.arraycopy(decodedData, 0, tmp, 0, i * 3); + tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); + tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); + return tmp; + } else { + return null; + } + } else { // No PAD e.g 3cQl + b3 = base64Alphabet[d3]; + b4 = base64Alphabet[d4]; + decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); + decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); + decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); + + } + return decodedData; + } + + /** + * remove WhiteSpace from MIME containing encoded Base64 data. + * + * @param data the byte array of base64 data (with WS) + * @return the new length + */ + private static int removeWhiteSpace(char[] data) { + if (data == null) { + return 0; + } + + // count characters that's not whitespace + int newSize = 0; + int len = data.length; + for (int i = 0; i < len; i++) { + if (!isWhiteSpace(data[i])) { + data[newSize++] = data[i]; + } + } + return newSize; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/sign/MD5Util.java b/jsowell-common/src/main/java/com/jsowell/common/util/sign/MD5Util.java new file mode 100644 index 000000000..debed9993 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/sign/MD5Util.java @@ -0,0 +1,107 @@ +package com.jsowell.common.util.sign; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; + +public class MD5Util { + + private static final Logger log = LoggerFactory.getLogger(MD5Util.class); + + private static final String hexDigits[] = {"0", "1", "2", "3", "4", "5", + "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; + + private static String byteArrayToHexString(byte b[]) { + StringBuffer resultSb = new StringBuffer(); + for (int i = 0; i < b.length; i++) + resultSb.append(byteToHexString(b[i])); + + return resultSb.toString(); + } + + private static String byteToHexString(byte b) { + int n = b; + if (n < 0) + n += 256; + int d1 = n / 16; + int d2 = n % 16; + return hexDigits[d1] + hexDigits[d2]; + } + + public static String MD5Encode(String origin, String charsetname) { + String resultString = null; + try { + resultString = new String(origin); + MessageDigest md = MessageDigest.getInstance("MD5"); + if (charsetname == null || "".equals(charsetname)) + resultString = byteArrayToHexString(md.digest(resultString + .getBytes())); + else + resultString = byteArrayToHexString(md.digest(resultString + .getBytes(charsetname))); + } catch (Exception exception) { + } + return resultString; + } + + /** + * MD5缂栫爜 + * + * @param origin 鍘熷瀛楃涓 + * @return 缁忚繃MD5鍔犲瘑涔嬪悗鐨勭粨鏋 + */ + public static String MD5Encode(String origin) { + String resultString = null; + try { + resultString = origin; + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(resultString.getBytes("UTF-8")); + resultString = byteArrayToHexString(md.digest()); + } catch (Exception e) { + e.printStackTrace(); + } + return resultString; + } + + private static byte[] md5(String s) { + MessageDigest algorithm; + try { + algorithm = MessageDigest.getInstance("MD5"); + algorithm.reset(); + algorithm.update(s.getBytes(StandardCharsets.UTF_8)); + byte[] messageDigest = algorithm.digest(); + return messageDigest; + } catch (Exception e) { + log.error("MD5 Error...", e); + } + return null; + } + + private static String toHex(byte[] hash) { + if (hash == null) { + return null; + } + StringBuilder buf = new StringBuilder(hash.length * 2); + int i; + + for (i = 0; i < hash.length; i++) { + if ((hash[i] & 0xff) < 0x10) { + buf.append("0"); + } + buf.append(Long.toString(hash[i] & 0xff, 16)); + } + return buf.toString(); + } + + public static String hash(String s) { + try { + return new String(toHex(md5(s)).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8); + } catch (Exception e) { + log.error("not supported charset...", e); + return s; + } + } + +} \ No newline at end of file diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/sim/SimCardUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/sim/SimCardUtils.java new file mode 100644 index 000000000..ebe762248 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/sim/SimCardUtils.java @@ -0,0 +1,43 @@ +package com.jsowell.common.util.sim; + +import java.math.BigDecimal; +import java.text.DecimalFormat; + +/** + * sim鍗$浉鍏冲伐鍏风被 + * + * @author JS-ZZA + * @date 2022/12/7 10:25 + */ +public class SimCardUtils { + + /** + * 灏咾B杞负瀵瑰簲鐨凪B鎴朑B + * + * @param size 闇杩涜杞寲鐨勫(KB) + * @return 杞崲鍚庣殑鍊硷紝鑷甫鍗曚綅 + */ + public static String kb2MbOrGb(int size) { + int GB = 1024 * 1024; // 瀹氫箟GB鐨勮绠楀父閲 + int MB = 1024; // 瀹氫箟MB鐨勮绠楀父閲 + DecimalFormat df = new DecimalFormat("0.00");//鏍煎紡鍖栧皬鏁 + String resultSize = ""; + if (size / GB >= 1) { + //濡傛灉褰撳墠Byte鐨勫煎ぇ浜庣瓑浜1GB + resultSize = df.format(size / (float) GB); + } else if (size / MB >= 1) { + //濡傛灉褰撳墠Byte鐨勫煎ぇ浜庣瓑浜1MB + resultSize = df.format(size / (float) MB); + } else { + resultSize = String.valueOf(size); + } + return resultSize; + } + + public static void main(String[] args) { + int a = 13320; + String str = "11874.95"; + BigDecimal bigDecimal = new BigDecimal(str); + System.out.println(kb2MbOrGb(bigDecimal.intValue())); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/sim/XunZhongSimUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/sim/XunZhongSimUtils.java new file mode 100644 index 000000000..1253ad191 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/sim/XunZhongSimUtils.java @@ -0,0 +1,125 @@ +package com.jsowell.common.util.sim; + +import cn.hutool.http.HttpRequest; +import org.apache.commons.codec.binary.Base64; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Hashtable; +import java.util.List; + +/** + * 璁紬鐗╄仈Sim鍗″晢宸ュ叿绫 + * + * @author JS-ZZA + * @date 2022/12/6 15:47 + */ +@Component +public class XunZhongSimUtils { + + private static String API_SECRET; + + @Value("${xunzhong.apiSecret}") + public void setAPI_SECRET(String API_SECRET) { + XunZhongSimUtils.API_SECRET = API_SECRET; + } + + // Base 64 鍔犲瘑 + private static String encode(final byte[] bytes) { + return new String(Base64.encodeBase64(bytes)); + } + + // SHA 256 鍔犲瘑 + private static String SHA256(final String strText) { + return SHA(strText, "SHA-256"); + } + + /** + * SHA绠楁硶鍔犲瘑 + * @param strText + * @param strType + * @return + */ + private static String SHA(final String strText, final String strType) { + // 杩斿洖鍊 + String strResult = null; + // 鏄惁鏄湁鏁堝瓧绗︿覆 + if (strText != null && strText.length() > 0) { + try { + // SHA 鍔犲瘑寮濮 + MessageDigest messageDigest = MessageDigest.getInstance(strType); + // 浼犫紛瑕佸姞瀵嗙殑瀛楃涓 + messageDigest.update(strText.getBytes()); + // 寰楀埌 byte 缁撴灉 + byte[] byteBuffer = messageDigest.digest(); + // 灏 byte 杞崲 string + StringBuilder strHexString = new StringBuilder(); + // 閬嶅巻 byte buffer + for (byte b : byteBuffer) { + String hex = Integer.toHexString(0xff & b); + if (hex.length() == 1) { + strHexString.append('0'); + } + strHexString.append(hex); + } + strResult = strHexString.toString(); + } + // 寰楀埌杩斿洖绲愭灉 + catch(NoSuchAlgorithmException e){ + e.printStackTrace(); + } + } + + return strResult; + } + + + /** + * 鐢熸垚signStr + * @param params + * @return + */ + public static String getSignStr(Hashtable params) { + // 鍙傛暟鎸 key 鎺掑簭 + List keys = new ArrayList<>(params.keySet()); + Collections.sort(keys); + + StringBuilder sign = new StringBuilder(); + + for (String key : keys) { + Object obj = params.get(key); + if (!sign.toString().equals("")) { + sign.append("&"); + } + sign.append(key).append("=").append(obj); + } + // 饨f垚 sign + sign.append(API_SECRET); + // 娣诲姞鍔犲瘑鐨 sign + String signStr = SHA256(encode(sign.toString().getBytes())); + + return signStr; + } + + /** + * 閾惧紡鏋勫缓璇锋眰锛屽紩鍏utool + * @param url + * @param params + * @return + */ + public static String sendPost(String url, Hashtable params) { + String postResult = HttpRequest.post(url) + .header("Content-type", "application/x-www-form-urlencoded;charset=utf-8") + .form(params) + .timeout(20000)//瓒呮椂锛屾绉 + .execute().body(); + + return postResult; + } + + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/spring/SpringUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/spring/SpringUtils.java new file mode 100644 index 000000000..3ba1dbe56 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/spring/SpringUtils.java @@ -0,0 +1,141 @@ +package com.jsowell.common.util.spring; + +import org.springframework.aop.framework.AopContext; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; +import com.jsowell.common.util.StringUtils; + +/** + * spring宸ュ叿绫 鏂逛究鍦ㄩ潪spring绠$悊鐜涓幏鍙朾ean + * + * @author jsowell + */ +@Component +public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware { + /** + * Spring搴旂敤涓婁笅鏂囩幆澧 + */ + private static ConfigurableListableBeanFactory beanFactory; + + private static ApplicationContext applicationContext; + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + SpringUtils.beanFactory = beanFactory; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + SpringUtils.applicationContext = applicationContext; + } + + /** + * 鑾峰彇瀵硅薄 + * + * @param name + * @return Object 涓涓互鎵缁欏悕瀛楁敞鍐岀殑bean鐨勫疄渚 + * @throws org.springframework.beans.BeansException + */ + @SuppressWarnings("unchecked") + public static T getBean(String name) throws BeansException { + return (T) beanFactory.getBean(name); + } + + /** + * 鑾峰彇绫诲瀷涓簉equiredType鐨勫璞 + * + * @param clz + * @return + * @throws org.springframework.beans.BeansException + */ + public static T getBean(Class clz) throws BeansException { + T result = (T) beanFactory.getBean(clz); + return result; + } + + /** + * 濡傛灉BeanFactory鍖呭惈涓涓笌鎵缁欏悕绉板尮閰嶇殑bean瀹氫箟锛屽垯杩斿洖true + * + * @param name + * @return boolean + */ + public static boolean containsBean(String name) { + return beanFactory.containsBean(name); + } + + /** + * 鍒ゆ柇浠ョ粰瀹氬悕瀛楁敞鍐岀殑bean瀹氫箟鏄竴涓猻ingleton杩樻槸涓涓猵rototype銆 濡傛灉涓庣粰瀹氬悕瀛楃浉搴旂殑bean瀹氫箟娌℃湁琚壘鍒帮紝灏嗕細鎶涘嚭涓涓紓甯革紙NoSuchBeanDefinitionException锛 + * + * @param name + * @return boolean + * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException + */ + public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException { + return beanFactory.isSingleton(name); + } + + /** + * @param name + * @return Class 娉ㄥ唽瀵硅薄鐨勭被鍨 + * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException + */ + public static Class getType(String name) throws NoSuchBeanDefinitionException { + return beanFactory.getType(name); + } + + /** + * 濡傛灉缁欏畾鐨刡ean鍚嶅瓧鍦╞ean瀹氫箟涓湁鍒悕锛屽垯杩斿洖杩欎簺鍒悕 + * + * @param name + * @return + * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException + */ + public static String[] getAliases(String name) throws NoSuchBeanDefinitionException { + return beanFactory.getAliases(name); + } + + /** + * 鑾峰彇aop浠g悊瀵硅薄 + * + * @param invoker + * @return + */ + @SuppressWarnings("unchecked") + public static T getAopProxy(T invoker) { + return (T) AopContext.currentProxy(); + } + + /** + * 鑾峰彇褰撳墠鐨勭幆澧冮厤缃紝鏃犻厤缃繑鍥瀗ull + * + * @return 褰撳墠鐨勭幆澧冮厤缃 + */ + public static String[] getActiveProfiles() { + return applicationContext.getEnvironment().getActiveProfiles(); + } + + /** + * 鑾峰彇褰撳墠鐨勭幆澧冮厤缃紝褰撴湁澶氫釜鐜閰嶇疆鏃讹紝鍙幏鍙栫涓涓 + * + * @return 褰撳墠鐨勭幆澧冮厤缃 + */ + public static String getActiveProfile() { + final String[] activeProfiles = getActiveProfiles(); + return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null; + } + + /** + * 鑾峰彇閰嶇疆鏂囦欢涓殑鍊 + * + * @param key 閰嶇疆鏂囦欢鐨刱ey + * @return 褰撳墠鐨勯厤缃枃浠剁殑鍊 + */ + public static String getRequiredProperty(String key) { + return applicationContext.getEnvironment().getRequiredProperty(key); + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/sql/SqlUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/sql/SqlUtil.java new file mode 100644 index 000000000..3f59a9092 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/util/sql/SqlUtil.java @@ -0,0 +1,53 @@ +package com.jsowell.common.util.sql; + +import com.jsowell.common.exception.UtilException; +import com.jsowell.common.util.StringUtils; + +/** + * sql鎿嶄綔宸ュ叿绫 + * + * @author jsowell + */ +public class SqlUtil { + /** + * 瀹氫箟甯哥敤鐨 sql鍏抽敭瀛 + */ + public static String SQL_REGEX = "select |insert |delete |update |drop |count |exec |chr |mid |master |truncate |char |and |declare "; + + /** + * 浠呮敮鎸佸瓧姣嶃佹暟瀛椼佷笅鍒掔嚎銆佺┖鏍笺侀楀彿銆佸皬鏁扮偣锛堟敮鎸佸涓瓧娈垫帓搴忥級 + */ + public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+"; + + /** + * 妫鏌ュ瓧绗︼紝闃叉娉ㄥ叆缁曡繃 + */ + public static String escapeOrderBySql(String value) { + if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) { + throw new UtilException("鍙傛暟涓嶇鍚堣鑼冿紝涓嶈兘杩涜鏌ヨ"); + } + return value; + } + + /** + * 楠岃瘉 order by 璇硶鏄惁绗﹀悎瑙勮寖 + */ + public static boolean isValidOrderBySql(String value) { + return value.matches(SQL_PATTERN); + } + + /** + * SQL鍏抽敭瀛楁鏌 + */ + public static void filterKeyword(String value) { + if (StringUtils.isEmpty(value)) { + return; + } + String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|"); + for (String sqlKeyword : sqlKeywords) { + if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1) { + throw new UtilException("鍙傛暟瀛樺湪SQL娉ㄥ叆椋庨櫓"); + } + } + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/xss/Xss.java b/jsowell-common/src/main/java/com/jsowell/common/xss/Xss.java new file mode 100644 index 000000000..faee4ca4e --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/xss/Xss.java @@ -0,0 +1,26 @@ +package com.jsowell.common.xss; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 鑷畾涔墄ss鏍¢獙娉ㄨВ + * + * @author jsowell + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(value = { ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER }) +@Constraint(validatedBy = { XssValidator.class }) +public @interface Xss{ + String message() + + default "涓嶅厑璁镐换浣曡剼鏈繍琛"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/xss/XssValidator.java b/jsowell-common/src/main/java/com/jsowell/common/xss/XssValidator.java new file mode 100644 index 000000000..aa05ae6d5 --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/xss/XssValidator.java @@ -0,0 +1,31 @@ +package com.jsowell.common.xss; + +import com.jsowell.common.util.StringUtils; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 鑷畾涔墄ss鏍¢獙娉ㄨВ瀹炵幇 + * + * @author jsowell + */ +public class XssValidator implements ConstraintValidator { + private static final String HTML_PATTERN = "<(\\S*?)[^>]*>.*?|<.*? />"; + + @Override + public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { + if (StringUtils.isBlank(value)) { + return true; + } + return !containsHtml(value); + } + + public static boolean containsHtml(String value) { + Pattern pattern = Pattern.compile(HTML_PATTERN); + Matcher matcher = pattern.matcher(value); + return matcher.matches(); + } +} \ No newline at end of file diff --git a/jsowell-framework/pom.xml b/jsowell-framework/pom.xml new file mode 100644 index 000000000..ba1d8ade9 --- /dev/null +++ b/jsowell-framework/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + com.jsowell + jsowell-charger-web + 1.0.0 + + + jsowell-framework + + + framework妗嗘灦鏍稿績 + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-aop + + + + + com.alibaba + druid-spring-boot-starter + + + + + com.github.penggle + kaptcha + + + javax.servlet-api + javax.servlet + + + + + + + com.github.oshi + oshi-core + + + + + com.jsowell + jsowell-system + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + /src/test/** + + utf-8 + + + + + + + \ No newline at end of file diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/DataScopeAspect.java b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/DataScopeAspect.java new file mode 100644 index 000000000..df6a4f442 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/DataScopeAspect.java @@ -0,0 +1,135 @@ +package com.jsowell.framework.aspectj; + +import com.jsowell.common.annotation.DataScope; +import com.jsowell.common.core.domain.BaseEntity; +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +/** + * 鏁版嵁杩囨护澶勭悊 + * + * @author jsowell + */ +@Aspect +@Component +public class DataScopeAspect { + /** + * 鍏ㄩ儴鏁版嵁鏉冮檺 + */ + public static final String DATA_SCOPE_ALL = "1"; + + /** + * 鑷畾鏁版嵁鏉冮檺 + */ + public static final String DATA_SCOPE_CUSTOM = "2"; + + /** + * 閮ㄩ棬鏁版嵁鏉冮檺 + */ + public static final String DATA_SCOPE_DEPT = "3"; + + /** + * 閮ㄩ棬鍙婁互涓嬫暟鎹潈闄 + */ + public static final String DATA_SCOPE_DEPT_AND_CHILD = "4"; + + /** + * 浠呮湰浜烘暟鎹潈闄 + */ + public static final String DATA_SCOPE_SELF = "5"; + + /** + * 鏁版嵁鏉冮檺杩囨护鍏抽敭瀛 + */ + public static final String DATA_SCOPE = "dataScope"; + + @Before("@annotation(controllerDataScope)") + public void doBefore(JoinPoint point, DataScope controllerDataScope) throws Throwable { + clearDataScope(point); + handleDataScope(point, controllerDataScope); + } + + protected void handleDataScope(final JoinPoint joinPoint, DataScope controllerDataScope) { + // 鑾峰彇褰撳墠鐨勭敤鎴 + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (StringUtils.isNotNull(loginUser)) { + SysUser currentUser = loginUser.getUser(); + // 濡傛灉鏄秴绾х鐞嗗憳锛屽垯涓嶈繃婊ゆ暟鎹 + if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) { + dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), + controllerDataScope.userAlias()); + } + } + } + + /** + * 鏁版嵁鑼冨洿杩囨护 + * + * @param joinPoint 鍒囩偣 + * @param user 鐢ㄦ埛 + * @param deptAlias 閮ㄩ棬鍒悕 + * @param userAlias 鐢ㄦ埛鍒悕 + */ + public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) { + StringBuilder sqlString = new StringBuilder(); + List conditions = new ArrayList(); + + for (SysRole role : user.getRoles()) { + String dataScope = role.getDataScope(); + if (!DATA_SCOPE_CUSTOM.equals(dataScope) && conditions.contains(dataScope)) { + continue; + } + if (DATA_SCOPE_ALL.equals(dataScope)) { + sqlString = new StringBuilder(); + break; + } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) { + sqlString.append(StringUtils.format( + " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, + role.getRoleId())); + } else if (DATA_SCOPE_DEPT.equals(dataScope)) { + sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId())); + } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) { + sqlString.append(StringUtils.format( + " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", + deptAlias, user.getDeptId(), user.getDeptId())); + } else if (DATA_SCOPE_SELF.equals(dataScope)) { + if (StringUtils.isNotBlank(userAlias)) { + sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); + } else { + // 鏁版嵁鏉冮檺涓轰粎鏈汉涓旀病鏈塽serAlias鍒悕涓嶆煡璇换浣曟暟鎹 + sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias)); + } + } + conditions.add(dataScope); + } + + if (StringUtils.isNotBlank(sqlString.toString())) { + Object params = joinPoint.getArgs()[0]; + if (StringUtils.isNotNull(params) && params instanceof BaseEntity) { + BaseEntity baseEntity = (BaseEntity) params; + baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); + } + } + } + + /** + * 鎷兼帴鏉冮檺sql鍓嶅厛娓呯┖params.dataScope鍙傛暟闃叉娉ㄥ叆 + */ + private void clearDataScope(final JoinPoint joinPoint) { + Object params = joinPoint.getArgs()[0]; + if (StringUtils.isNotNull(params) && params instanceof BaseEntity) { + BaseEntity baseEntity = (BaseEntity) params; + baseEntity.getParams().put(DATA_SCOPE, ""); + } + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/DataSourceAspect.java b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/DataSourceAspect.java new file mode 100644 index 000000000..1d580a979 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/DataSourceAspect.java @@ -0,0 +1,64 @@ +package com.jsowell.framework.aspectj; + +import com.jsowell.common.annotation.DataSource; +import com.jsowell.common.util.StringUtils; +import com.jsowell.framework.datasource.DynamicDataSourceContextHolder; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +/** + * 澶氭暟鎹簮澶勭悊 + * + * @author jsowell + */ +@Aspect +@Order(1) +@Component +public class DataSourceAspect { + protected Logger logger = LoggerFactory.getLogger(getClass()); + + @Pointcut("@annotation(com.jsowell.common.annotation.DataSource)" + + "|| @within(com.jsowell.common.annotation.DataSource)") + public void dsPointCut() { + + } + + @Around("dsPointCut()") + public Object around(ProceedingJoinPoint point) throws Throwable { + DataSource dataSource = getDataSource(point); + + if (StringUtils.isNotNull(dataSource)) { + DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name()); + } + + try { + return point.proceed(); + } finally { + // 閿姣佹暟鎹簮 鍦ㄦ墽琛屾柟娉曚箣鍚 + DynamicDataSourceContextHolder.clearDataSourceType(); + } + } + + /** + * 鑾峰彇闇瑕佸垏鎹㈢殑鏁版嵁婧 + */ + public DataSource getDataSource(ProceedingJoinPoint point) { + MethodSignature signature = (MethodSignature) point.getSignature(); + DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class); + if (Objects.nonNull(dataSource)) { + return dataSource; + } + + return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/LogAspect.java b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/LogAspect.java new file mode 100644 index 000000000..8d9ed795b --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/LogAspect.java @@ -0,0 +1,200 @@ +package com.jsowell.framework.aspectj; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.enums.BusinessStatus; +import com.jsowell.common.enums.HttpMethod; +import com.jsowell.common.filter.PropertyPreExcludeFilter; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.ServletUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.ip.IpUtils; +import com.jsowell.framework.manager.AsyncManager; +import com.jsowell.framework.manager.factory.AsyncFactory; +import com.jsowell.system.domain.SysOperLog; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.AfterThrowing; +import org.aspectj.lang.annotation.Aspect; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.validation.BindingResult; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.HandlerMapping; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Collection; +import java.util.Map; + +/** + * 鎿嶄綔鏃ュ織璁板綍澶勭悊 + * + * @author jsowell + */ +@Aspect +@Component +public class LogAspect { + private static final Logger log = LoggerFactory.getLogger(LogAspect.class); + + /** + * 鎺掗櫎鏁忔劅灞炴у瓧娈 + */ + public static final String[] EXCLUDE_PROPERTIES = {"password", "oldPassword", "newPassword", "confirmPassword"}; + + /** + * 澶勭悊瀹岃姹傚悗鎵ц + * + * @param joinPoint 鍒囩偣 + */ + @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult") + public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) { + handleLog(joinPoint, controllerLog, null, jsonResult); + } + + /** + * 鎷︽埅寮傚父鎿嶄綔 + * + * @param joinPoint 鍒囩偣 + * @param e 寮傚父 + */ + @AfterThrowing(value = "@annotation(controllerLog)", throwing = "e") + public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) { + handleLog(joinPoint, controllerLog, e, null); + } + + protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) { + try { + // 鑾峰彇褰撳墠鐨勭敤鎴 + LoginUser loginUser = SecurityUtils.getLoginUser(); + + // *========鏁版嵁搴撴棩蹇=========*// + SysOperLog operLog = new SysOperLog(); + operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); + // 璇锋眰鐨勫湴鍧 + String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); + operLog.setOperIp(ip); + operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); + if (loginUser != null) { + operLog.setOperName(loginUser.getUsername()); + } + + if (e != null) { + operLog.setStatus(BusinessStatus.FAIL.ordinal()); + operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); + } + // 璁剧疆鏂规硶鍚嶇О + String className = joinPoint.getTarget().getClass().getName(); + String methodName = joinPoint.getSignature().getName(); + operLog.setMethod(className + "." + methodName + "()"); + // 璁剧疆璇锋眰鏂瑰紡 + operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); + // 澶勭悊璁剧疆娉ㄨВ涓婄殑鍙傛暟 + getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); + // 淇濆瓨鏁版嵁搴 + AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); + } catch (Exception exp) { + // 璁板綍鏈湴寮傚父鏃ュ織 + log.error("==鍓嶇疆閫氱煡寮傚父=="); + log.error("寮傚父淇℃伅:{}", exp.getMessage()); + exp.printStackTrace(); + } + } + + /** + * 鑾峰彇娉ㄨВ涓鏂规硶鐨勬弿杩颁俊鎭 鐢ㄤ簬Controller灞傛敞瑙 + * + * @param log 鏃ュ織 + * @param operLog 鎿嶄綔鏃ュ織 + * @throws Exception + */ + public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception { + // 璁剧疆action鍔ㄤ綔 + operLog.setBusinessType(log.businessType().ordinal()); + // 璁剧疆鏍囬 + operLog.setTitle(log.title()); + // 璁剧疆鎿嶄綔浜虹被鍒 + operLog.setOperatorType(log.operatorType().ordinal()); + // 鏄惁闇瑕佷繚瀛榬equest锛屽弬鏁板拰鍊 + if (log.isSaveRequestData()) { + // 鑾峰彇鍙傛暟鐨勪俊鎭紝浼犲叆鍒版暟鎹簱涓 + setRequestValue(joinPoint, operLog); + } + // 鏄惁闇瑕佷繚瀛榬esponse锛屽弬鏁板拰鍊 + if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) { + operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000)); + } + } + + /** + * 鑾峰彇璇锋眰鐨勫弬鏁帮紝鏀惧埌log涓 + * + * @param operLog 鎿嶄綔鏃ュ織 + * @throws Exception 寮傚父 + */ + private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception { + String requestMethod = operLog.getRequestMethod(); + if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) { + String params = argsArrayToString(joinPoint.getArgs()); + operLog.setOperParam(StringUtils.substring(params, 0, 2000)); + } else { + Map paramsMap = (Map) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); + operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000)); + } + } + + /** + * 鍙傛暟鎷艰 + */ + private String argsArrayToString(Object[] paramsArray) { + String params = ""; + if (paramsArray != null && paramsArray.length > 0) { + for (Object o : paramsArray) { + if (StringUtils.isNotNull(o) && !isFilterObject(o)) { + try { + String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter()); + params += jsonObj.toString() + " "; + } catch (Exception e) { + } + } + } + } + return params.trim(); + } + + /** + * 蹇界暐鏁忔劅灞炴 + */ + public PropertyPreExcludeFilter excludePropertyPreFilter() { + return new PropertyPreExcludeFilter().addExcludes(EXCLUDE_PROPERTIES); + } + + /** + * 鍒ゆ柇鏄惁闇瑕佽繃婊ょ殑瀵硅薄銆 + * + * @param o 瀵硅薄淇℃伅銆 + * @return 濡傛灉鏄渶瑕佽繃婊ょ殑瀵硅薄锛屽垯杩斿洖true锛涘惁鍒欒繑鍥瀎alse銆 + */ + @SuppressWarnings("rawtypes") + public boolean isFilterObject(final Object o) { + Class clazz = o.getClass(); + if (clazz.isArray()) { + return clazz.getComponentType().isAssignableFrom(MultipartFile.class); + } else if (Collection.class.isAssignableFrom(clazz)) { + Collection collection = (Collection) o; + for (Object value : collection) { + return value instanceof MultipartFile; + } + } else if (Map.class.isAssignableFrom(clazz)) { + Map map = (Map) o; + for (Object value : map.entrySet()) { + Map.Entry entry = (Map.Entry) value; + return entry.getValue() instanceof MultipartFile; + } + } + return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse + || o instanceof BindingResult; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/RateLimiterAspect.java b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/RateLimiterAspect.java new file mode 100644 index 000000000..12cddc5cc --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/RateLimiterAspect.java @@ -0,0 +1,80 @@ +package com.jsowell.framework.aspectj; + +import com.jsowell.common.annotation.RateLimiter; +import com.jsowell.common.enums.LimitType; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.ServletUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.ip.IpUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.reflect.MethodSignature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.script.RedisScript; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.List; + +/** + * 闄愭祦澶勭悊 + * + * @author jsowell + */ +@Aspect +@Component +public class RateLimiterAspect { + private static final Logger log = LoggerFactory.getLogger(RateLimiterAspect.class); + + private RedisTemplate redisTemplate; + + private RedisScript limitScript; + + @Autowired + public void setRedisTemplate1(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + @Autowired + public void setLimitScript(RedisScript limitScript) { + this.limitScript = limitScript; + } + + @Before("@annotation(rateLimiter)") + public void doBefore(JoinPoint point, RateLimiter rateLimiter) throws Throwable { + String key = rateLimiter.key(); + int time = rateLimiter.time(); + int count = rateLimiter.count(); + + String combineKey = getCombineKey(rateLimiter, point); + List keys = Collections.singletonList(combineKey); + try { + Long number = redisTemplate.execute(limitScript, keys, count, time); + if (StringUtils.isNull(number) || number.intValue() > count) { + throw new ServiceException("璁块棶杩囦簬棰戠箒锛岃绋嶅欏啀璇"); + } + log.info("闄愬埗璇锋眰'{}',褰撳墠璇锋眰'{}',缂撳瓨key'{}'", count, number.intValue(), key); + } catch (ServiceException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException("鏈嶅姟鍣ㄩ檺娴佸紓甯革紝璇风◢鍊欏啀璇"); + } + } + + public String getCombineKey(RateLimiter rateLimiter, JoinPoint point) { + StringBuffer stringBuffer = new StringBuffer(rateLimiter.key()); + if (rateLimiter.limitType() == LimitType.IP) { + stringBuffer.append(IpUtils.getIpAddr(ServletUtils.getRequest())).append("-"); + } + MethodSignature signature = (MethodSignature) point.getSignature(); + Method method = signature.getMethod(); + Class targetClass = method.getDeclaringClass(); + stringBuffer.append(targetClass.getName()).append("-").append(method.getName()); + return stringBuffer.toString(); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/ApplicationConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/ApplicationConfig.java new file mode 100644 index 000000000..e9984beb9 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/ApplicationConfig.java @@ -0,0 +1,29 @@ +package com.jsowell.framework.config; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +import java.util.TimeZone; + +/** + * 绋嬪簭娉ㄨВ閰嶇疆 + * + * @author jsowell + */ +@Configuration +// 琛ㄧず閫氳繃aop妗嗘灦鏆撮湶璇ヤ唬鐞嗗璞,AopContext鑳藉璁块棶 +@EnableAspectJAutoProxy(exposeProxy = true) +// 鎸囧畾瑕佹壂鎻忕殑Mapper绫荤殑鍖呯殑璺緞 +@MapperScan("com.jsowell.**.mapper") +public class ApplicationConfig { + /** + * 鏃跺尯閰嶇疆 + */ + @Bean + public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() { + return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault()); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/CaptchaConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/CaptchaConfig.java new file mode 100644 index 000000000..fe52dce81 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/CaptchaConfig.java @@ -0,0 +1,84 @@ +package com.jsowell.framework.config; + +import com.google.code.kaptcha.impl.DefaultKaptcha; +import com.google.code.kaptcha.util.Config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Properties; + +import static com.google.code.kaptcha.Constants.*; + +/** + * 楠岃瘉鐮侀厤缃 + * + * @author jsowell + */ +@Configuration +public class CaptchaConfig { + @Bean(name = "captchaProducer") + public DefaultKaptcha getKaptchaBean() { + DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); + Properties properties = new Properties(); + // 鏄惁鏈夎竟妗 榛樿涓簍rue 鎴戜滑鍙互鑷繁璁剧疆yes锛宯o + properties.setProperty(KAPTCHA_BORDER, "yes"); + // 楠岃瘉鐮佹枃鏈瓧绗﹂鑹 榛樿涓篊olor.BLACK + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black"); + // 楠岃瘉鐮佸浘鐗囧搴 榛樿涓200 + properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); + // 楠岃瘉鐮佸浘鐗囬珮搴 榛樿涓50 + properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); + // 楠岃瘉鐮佹枃鏈瓧绗﹀ぇ灏 榛樿涓40 + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38"); + // KAPTCHA_SESSION_KEY + properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode"); + // 鏂囨湰闆嗗悎锛岄獙璇佺爜鍊间粠姝ら泦鍚堜腑鑾峰彇 + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_STRING, "012356789"); + // 楠岃瘉鐮佹枃鏈瓧绗﹂暱搴 榛樿涓5 + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); + // 楠岃瘉鐮佹枃鏈瓧浣撴牱寮 榛樿涓簄ew Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); + // 鍥剧墖鏍峰紡 姘寸汗com.google.code.kaptcha.impl.WaterRipple 楸肩溂com.google.code.kaptcha.impl.FishEyeGimpy 闃村奖com.google.code.kaptcha.impl.ShadowGimpy + properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); + Config config = new Config(properties); + defaultKaptcha.setConfig(config); + return defaultKaptcha; + } + + @Bean(name = "captchaProducerMath") + public DefaultKaptcha getKaptchaBeanMath() { + DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); + Properties properties = new Properties(); + // 鏄惁鏈夎竟妗 榛樿涓簍rue 鎴戜滑鍙互鑷繁璁剧疆yes锛宯o + properties.setProperty(KAPTCHA_BORDER, "yes"); + // 杈规棰滆壊 榛樿涓篊olor.BLACK + properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90"); + // 楠岃瘉鐮佹枃鏈瓧绗﹂鑹 榛樿涓篊olor.BLACK + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue"); + // 楠岃瘉鐮佸浘鐗囧搴 榛樿涓200 + properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); + // 楠岃瘉鐮佸浘鐗囬珮搴 榛樿涓50 + properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); + // 楠岃瘉鐮佹枃鏈瓧绗﹀ぇ灏 榛樿涓40 + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35"); + // KAPTCHA_SESSION_KEY + properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); + // 楠岃瘉鐮佹枃鏈敓鎴愬櫒 + properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.jsowell.framework.config.KaptchaTextCreator"); + // 楠岃瘉鐮佹枃鏈瓧绗﹂棿璺 榛樿涓2 + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); + // 楠岃瘉鐮佹枃鏈瓧绗﹂暱搴 榛樿涓5 + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6"); + // 楠岃瘉鐮佹枃鏈瓧浣撴牱寮 榛樿涓簄ew Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); + // 楠岃瘉鐮佸櫔鐐归鑹 榛樿涓篊olor.BLACK + properties.setProperty(KAPTCHA_NOISE_COLOR, "white"); + // 骞叉壈瀹炵幇绫 + properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); + // 鍥剧墖鏍峰紡 姘寸汗com.google.code.kaptcha.impl.WaterRipple 楸肩溂com.google.code.kaptcha.impl.FishEyeGimpy 闃村奖com.google.code.kaptcha.impl.ShadowGimpy + properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); + Config config = new Config(properties); + defaultKaptcha.setConfig(config); + return defaultKaptcha; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/DruidConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/DruidConfig.java new file mode 100644 index 000000000..95650c205 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/DruidConfig.java @@ -0,0 +1,112 @@ +package com.jsowell.framework.config; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; +import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; +import com.alibaba.druid.util.Utils; +import com.jsowell.common.enums.DataSourceType; +import com.jsowell.common.util.spring.SpringUtils; +import com.jsowell.framework.config.properties.DruidProperties; +import com.jsowell.framework.datasource.DynamicDataSource; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import javax.servlet.*; +import javax.sql.DataSource; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * druid 閰嶇疆澶氭暟鎹簮 + * + * @author jsowell + */ +@Configuration +public class DruidConfig { + @Bean + @ConfigurationProperties("spring.datasource.druid.master") + public DataSource masterDataSource(DruidProperties druidProperties) { + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); + return druidProperties.dataSource(dataSource); + } + + @Bean + @ConfigurationProperties("spring.datasource.druid.slave") + @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true") + public DataSource slaveDataSource(DruidProperties druidProperties) { + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); + return druidProperties.dataSource(dataSource); + } + + @Bean(name = "dynamicDataSource") + @Primary + public DynamicDataSource dataSource(DataSource masterDataSource) { + Map targetDataSources = new HashMap<>(); + targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); + setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource"); + return new DynamicDataSource(masterDataSource, targetDataSources); + } + + /** + * 璁剧疆鏁版嵁婧 + * + * @param targetDataSources 澶囬夋暟鎹簮闆嗗悎 + * @param sourceName 鏁版嵁婧愬悕绉 + * @param beanName bean鍚嶇О + */ + public void setDataSource(Map targetDataSources, String sourceName, String beanName) { + try { + DataSource dataSource = SpringUtils.getBean(beanName); + targetDataSources.put(sourceName, dataSource); + } catch (Exception e) { + } + } + + /** + * 鍘婚櫎鐩戞帶椤甸潰搴曢儴鐨勫箍鍛 + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + @Bean + @ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true") + public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) { + // 鑾峰彇web鐩戞帶椤甸潰鐨勫弬鏁 + DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); + // 鎻愬彇common.js鐨勯厤缃矾寰 + String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; + String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); + final String filePath = "support/http/resources/js/common.js"; + // 鍒涘缓filter杩涜杩囨护 + Filter filter = new Filter() { + @Override + public void init(javax.servlet.FilterConfig filterConfig) throws ServletException { + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + chain.doFilter(request, response); + // 閲嶇疆缂撳啿鍖猴紝鍝嶅簲澶翠笉浼氳閲嶇疆 + response.resetBuffer(); + // 鑾峰彇common.js + String text = Utils.readFromResource(filePath); + // 姝e垯鏇挎崲banner, 闄ゅ幓搴曢儴鐨勫箍鍛婁俊鎭 + text = text.replaceAll("
", ""); + text = text.replaceAll("powered.*?shrek.wang", ""); + response.getWriter().write(text); + } + + @Override + public void destroy() { + } + }; + FilterRegistrationBean registrationBean = new FilterRegistrationBean(); + registrationBean.setFilter(filter); + registrationBean.addUrlPatterns(commonJsPattern); + return registrationBean; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/FastJson2JsonRedisSerializer.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/FastJson2JsonRedisSerializer.java new file mode 100644 index 000000000..83425e3e9 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/FastJson2JsonRedisSerializer.java @@ -0,0 +1,43 @@ +package com.jsowell.framework.config; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONReader; +import com.alibaba.fastjson2.JSONWriter; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.SerializationException; + +import java.nio.charset.Charset; + +/** + * Redis浣跨敤FastJson搴忓垪鍖 + * + * @author jsowell + */ +public class FastJson2JsonRedisSerializer implements RedisSerializer { + public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); + + private Class clazz; + + public FastJson2JsonRedisSerializer(Class clazz) { + super(); + this.clazz = clazz; + } + + @Override + public byte[] serialize(T t) throws SerializationException { + if (t == null) { + return new byte[0]; + } + return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET); + } + + @Override + public T deserialize(byte[] bytes) throws SerializationException { + if (bytes == null || bytes.length <= 0) { + return null; + } + String str = new String(bytes, DEFAULT_CHARSET); + + return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/FilterConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/FilterConfig.java new file mode 100644 index 000000000..6be571a5e --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/FilterConfig.java @@ -0,0 +1,56 @@ +package com.jsowell.framework.config; + +import com.jsowell.common.filter.RepeatableFilter; +import com.jsowell.common.filter.XssFilter; +import com.jsowell.common.util.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.servlet.DispatcherType; +import java.util.HashMap; +import java.util.Map; + +/** + * Filter閰嶇疆 + * + * @author jsowell + */ +@Configuration +public class FilterConfig { + @Value("${xss.excludes}") + private String excludes; + + @Value("${xss.urlPatterns}") + private String urlPatterns; + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Bean + @ConditionalOnProperty(value = "xss.enabled", havingValue = "true") + public FilterRegistrationBean xssFilterRegistration() { + FilterRegistrationBean registration = new FilterRegistrationBean(); + registration.setDispatcherTypes(DispatcherType.REQUEST); + registration.setFilter(new XssFilter()); + registration.addUrlPatterns(StringUtils.split(urlPatterns, ",")); + registration.setName("xssFilter"); + registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); + Map initParameters = new HashMap(); + initParameters.put("excludes", excludes); + registration.setInitParameters(initParameters); + return registration; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Bean + public FilterRegistrationBean someFilterRegistration() { + FilterRegistrationBean registration = new FilterRegistrationBean(); + registration.setFilter(new RepeatableFilter()); + registration.addUrlPatterns("/*"); + registration.setName("repeatableFilter"); + registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE); + return registration; + } + +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/KaptchaTextCreator.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/KaptchaTextCreator.java new file mode 100644 index 000000000..fabe6024f --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/KaptchaTextCreator.java @@ -0,0 +1,56 @@ +package com.jsowell.framework.config; + +import com.google.code.kaptcha.text.impl.DefaultTextCreator; + +import java.util.Random; + +/** + * 楠岃瘉鐮佹枃鏈敓鎴愬櫒 + * + * @author jsowell + */ +public class KaptchaTextCreator extends DefaultTextCreator { + private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(","); + + @Override + public String getText() { + Integer result = 0; + Random random = new Random(); + int x = random.nextInt(10); + int y = random.nextInt(10); + StringBuilder suChinese = new StringBuilder(); + int randomoperands = random.nextInt(3); + if (randomoperands == 0) { + result = x * y; + suChinese.append(CNUMBERS[x]); + suChinese.append("*"); + suChinese.append(CNUMBERS[y]); + } else if (randomoperands == 1) { + if ((x != 0) && y % x == 0) { + result = y / x; + suChinese.append(CNUMBERS[y]); + suChinese.append("/"); + suChinese.append(CNUMBERS[x]); + } else { + result = x + y; + suChinese.append(CNUMBERS[x]); + suChinese.append("+"); + suChinese.append(CNUMBERS[y]); + } + } else { + if (x >= y) { + result = x - y; + suChinese.append(CNUMBERS[x]); + suChinese.append("-"); + suChinese.append(CNUMBERS[y]); + } else { + result = y - x; + suChinese.append(CNUMBERS[y]); + suChinese.append("-"); + suChinese.append(CNUMBERS[x]); + } + } + suChinese.append("=?@" + result); + return suChinese.toString(); + } +} \ No newline at end of file diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/MyBatisConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/MyBatisConfig.java new file mode 100644 index 000000000..d16425150 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/MyBatisConfig.java @@ -0,0 +1,110 @@ +package com.jsowell.framework.config; + +import com.jsowell.common.util.StringUtils; +import org.apache.ibatis.io.VFS; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.boot.autoconfigure.SpringBootVFS; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.core.type.classreading.CachingMetadataReaderFactory; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.util.ClassUtils; + +import javax.sql.DataSource; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; + +/** + * Mybatis鏀寔*鍖归厤鎵弿鍖 + * + * @author jsowell + */ +@Configuration +public class MyBatisConfig { + @Autowired + private Environment env; + + static final String DEFAULT_RESOURCE_PATTERN = "**/*.class"; + + public static String setTypeAliasesPackage(String typeAliasesPackage) { + ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver(); + MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver); + List allResult = new ArrayList(); + try { + for (String aliasesPackage : typeAliasesPackage.split(",")) { + List result = new ArrayList(); + aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN; + Resource[] resources = resolver.getResources(aliasesPackage); + if (resources != null && resources.length > 0) { + MetadataReader metadataReader = null; + for (Resource resource : resources) { + if (resource.isReadable()) { + metadataReader = metadataReaderFactory.getMetadataReader(resource); + try { + result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + } + } + if (result.size() > 0) { + HashSet hashResult = new HashSet(result); + allResult.addAll(hashResult); + } + } + if (allResult.size() > 0) { + typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0])); + } else { + throw new RuntimeException("mybatis typeAliasesPackage 璺緞鎵弿閿欒,鍙傛暟typeAliasesPackage:" + typeAliasesPackage + "鏈壘鍒颁换浣曞寘"); + } + } catch (IOException e) { + e.printStackTrace(); + } + return typeAliasesPackage; + } + + public Resource[] resolveMapperLocations(String[] mapperLocations) { + ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); + List resources = new ArrayList(); + if (mapperLocations != null) { + for (String mapperLocation : mapperLocations) { + try { + Resource[] mappers = resourceResolver.getResources(mapperLocation); + resources.addAll(Arrays.asList(mappers)); + } catch (IOException e) { + // ignore + } + } + } + return resources.toArray(new Resource[resources.size()]); + } + + @Bean + public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { + String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage"); + String mapperLocations = env.getProperty("mybatis.mapperLocations"); + String configLocation = env.getProperty("mybatis.configLocation"); + typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage); + VFS.addImplClass(SpringBootVFS.class); + + final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); + sessionFactory.setDataSource(dataSource); + sessionFactory.setTypeAliasesPackage(typeAliasesPackage); + sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ","))); + sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); + return sessionFactory.getObject(); + } +} \ No newline at end of file diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/RedisConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/RedisConfig.java new file mode 100644 index 000000000..b691c5b6b --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/RedisConfig.java @@ -0,0 +1,65 @@ +package com.jsowell.framework.config; + +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.script.DefaultRedisScript; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * redis閰嶇疆 + * + * @author jsowell + */ +@Configuration +@EnableCaching +public class RedisConfig extends CachingConfigurerSupport { + @Bean + @SuppressWarnings(value = {"unchecked", "rawtypes"}) + public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(connectionFactory); + + FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); + + // 浣跨敤StringRedisSerializer鏉ュ簭鍒楀寲鍜屽弽搴忓垪鍖杛edis鐨刱ey鍊 + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(serializer); + + // Hash鐨刱ey涔熼噰鐢⊿tringRedisSerializer鐨勫簭鍒楀寲鏂瑰紡 + template.setHashKeySerializer(new StringRedisSerializer()); + template.setHashValueSerializer(serializer); + + template.afterPropertiesSet(); + return template; + } + + @Bean + public DefaultRedisScript limitScript() { + DefaultRedisScript redisScript = new DefaultRedisScript<>(); + redisScript.setScriptText(limitScriptText()); + redisScript.setResultType(Long.class); + return redisScript; + } + + /** + * 闄愭祦鑴氭湰 + */ + private String limitScriptText() { + return "local key = KEYS[1]\n" + + "local count = tonumber(ARGV[1])\n" + + "local time = tonumber(ARGV[2])\n" + + "local current = redis.call('get', key);\n" + + "if current and tonumber(current) > count then\n" + + " return tonumber(current);\n" + + "end\n" + + "current = redis.call('incr', key)\n" + + "if tonumber(current) == 1 then\n" + + " redis.call('expire', key, time)\n" + + "end\n" + + "return tonumber(current);"; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/ResourcesConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/ResourcesConfig.java new file mode 100644 index 000000000..61a8d39bf --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/ResourcesConfig.java @@ -0,0 +1,66 @@ +package com.jsowell.framework.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import com.jsowell.common.config.JsowellConfig; +import com.jsowell.common.constant.Constants; +import com.jsowell.framework.interceptor.RepeatSubmitInterceptor; + +/** + * 閫氱敤閰嶇疆 + * + * @author jsowell + */ +@Configuration +public class ResourcesConfig implements WebMvcConfigurer { + @Autowired + private RepeatSubmitInterceptor repeatSubmitInterceptor; + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + /** 鏈湴鏂囦欢涓婁紶璺緞 */ + registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**") + .addResourceLocations("file:" + JsowellConfig.getProfile() + "/"); + + /** swagger閰嶇疆 */ + registry.addResourceHandler("/swagger-ui/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); + } + + /** + * 鑷畾涔夋嫤鎴鍒 + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**"); + } + + /** + * 璺ㄥ煙閰嶇疆 + */ + @Bean + public CorsFilter corsFilter() { + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + // 璁剧疆璁块棶婧愬湴鍧 + config.addAllowedOriginPattern("*"); + // 璁剧疆璁块棶婧愯姹傚ご + config.addAllowedHeader("*"); + // 璁剧疆璁块棶婧愯姹傛柟娉 + config.addAllowedMethod("*"); + // 鏈夋晥鏈 1800绉 + config.setMaxAge(1800L); + // 娣诲姞鏄犲皠璺緞锛屾嫤鎴竴鍒囪姹 + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", config); + // 杩斿洖鏂扮殑CorsFilter + return new CorsFilter(source); + } +} \ No newline at end of file diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/SecurityConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/SecurityConfig.java new file mode 100644 index 000000000..0f101dd1f --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/SecurityConfig.java @@ -0,0 +1,141 @@ +package com.jsowell.framework.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpMethod; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.authentication.logout.LogoutFilter; +import org.springframework.web.filter.CorsFilter; +import com.jsowell.framework.config.properties.PermitAllUrlProperties; +import com.jsowell.framework.security.filter.JwtAuthenticationTokenFilter; +import com.jsowell.framework.security.handle.AuthenticationEntryPointImpl; +import com.jsowell.framework.security.handle.LogoutSuccessHandlerImpl; + +/** + * spring security閰嶇疆 + * + * @author jsowell + */ +@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) +public class SecurityConfig extends WebSecurityConfigurerAdapter { + /** + * 鑷畾涔夌敤鎴疯璇侀昏緫 + */ + @Autowired + private UserDetailsService userDetailsService; + + /** + * 璁よ瘉澶辫触澶勭悊绫 + */ + @Autowired + private AuthenticationEntryPointImpl unauthorizedHandler; + + /** + * 閫鍑哄鐞嗙被 + */ + @Autowired + private LogoutSuccessHandlerImpl logoutSuccessHandler; + + /** + * token璁よ瘉杩囨护鍣 + */ + @Autowired + private JwtAuthenticationTokenFilter authenticationTokenFilter; + + /** + * 璺ㄥ煙杩囨护鍣 + */ + @Autowired + private CorsFilter corsFilter; + + /** + * 鍏佽鍖垮悕璁块棶鐨勫湴鍧 + */ + @Autowired + private PermitAllUrlProperties permitAllUrl; + + /** + * 瑙e喅 鏃犳硶鐩存帴娉ㄥ叆 AuthenticationManager + * + * @return + * @throws Exception + */ + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + /** + * anyRequest | 鍖归厤鎵鏈夎姹傝矾寰 + * access | SpringEl琛ㄨ揪寮忕粨鏋滀负true鏃跺彲浠ヨ闂 + * anonymous | 鍖垮悕鍙互璁块棶 + * denyAll | 鐢ㄦ埛涓嶈兘璁块棶 + * fullyAuthenticated | 鐢ㄦ埛瀹屽叏璁よ瘉鍙互璁块棶锛堥潪remember-me涓嬭嚜鍔ㄧ櫥褰曪級 + * hasAnyAuthority | 濡傛灉鏈夊弬鏁帮紝鍙傛暟琛ㄧず鏉冮檺锛屽垯鍏朵腑浠讳綍涓涓潈闄愬彲浠ヨ闂 + * hasAnyRole | 濡傛灉鏈夊弬鏁帮紝鍙傛暟琛ㄧず瑙掕壊锛屽垯鍏朵腑浠讳綍涓涓鑹插彲浠ヨ闂 + * hasAuthority | 濡傛灉鏈夊弬鏁帮紝鍙傛暟琛ㄧず鏉冮檺锛屽垯鍏舵潈闄愬彲浠ヨ闂 + * hasIpAddress | 濡傛灉鏈夊弬鏁帮紝鍙傛暟琛ㄧずIP鍦板潃锛屽鏋滅敤鎴稩P鍜屽弬鏁板尮閰嶏紝鍒欏彲浠ヨ闂 + * hasRole | 濡傛灉鏈夊弬鏁帮紝鍙傛暟琛ㄧず瑙掕壊锛屽垯鍏惰鑹插彲浠ヨ闂 + * permitAll | 鐢ㄦ埛鍙互浠绘剰璁块棶 + * rememberMe | 鍏佽閫氳繃remember-me鐧诲綍鐨勭敤鎴疯闂 + * authenticated | 鐢ㄦ埛鐧诲綍鍚庡彲璁块棶 + */ + @Override + protected void configure(HttpSecurity httpSecurity) throws Exception { + // 娉ㄨВ鏍囪鍏佽鍖垮悕璁块棶鐨剈rl + ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry = httpSecurity.authorizeRequests(); + permitAllUrl.getUrls().forEach(url -> registry.antMatchers(url).permitAll()); + + httpSecurity + // CSRF绂佺敤锛屽洜涓轰笉浣跨敤session + .csrf().disable() + // 璁よ瘉澶辫触澶勭悊绫 + .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() + // 鍩轰簬token锛屾墍浠ヤ笉闇瑕乻ession + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() + // 杩囨护璇锋眰 + .authorizeRequests() + // 瀵逛簬鐧诲綍login 娉ㄥ唽register 楠岃瘉鐮乧aptchaImage 鍏佽鍖垮悕璁块棶 + .antMatchers("/login", "/register", "/captchaImage").anonymous() + // 闈欐佽祫婧愶紝鍙尶鍚嶈闂 + .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() + .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() + // 闄や笂闈㈠鐨勬墍鏈夎姹傚叏閮ㄩ渶瑕侀壌鏉冭璇 + .anyRequest().authenticated() + .and() + .headers().frameOptions().disable(); + // 娣诲姞Logout filter + httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); + // 娣诲姞JWT filter + httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); + // 娣诲姞CORS filter + httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class); + httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class); + } + + /** + * 寮烘暎鍒楀搱甯屽姞瀵嗗疄鐜 + */ + @Bean + public BCryptPasswordEncoder bCryptPasswordEncoder() { + return new BCryptPasswordEncoder(); + } + + /** + * 韬唤璁よ瘉鎺ュ彛 + */ + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder()); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/ServerConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/ServerConfig.java new file mode 100644 index 000000000..3b68cc3dc --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/ServerConfig.java @@ -0,0 +1,30 @@ +package com.jsowell.framework.config; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.stereotype.Component; +import com.jsowell.common.util.ServletUtils; + +/** + * 鏈嶅姟鐩稿叧閰嶇疆 + * + * @author jsowell + */ +@Component +public class ServerConfig { + /** + * 鑾峰彇瀹屾暣鐨勮姹傝矾寰勶紝鍖呮嫭锛氬煙鍚嶏紝绔彛锛屼笂涓嬫枃璁块棶璺緞 + * + * @return 鏈嶅姟鍦板潃 + */ + public String getUrl() { + HttpServletRequest request = ServletUtils.getRequest(); + return getDomain(request); + } + + public static String getDomain(HttpServletRequest request) { + StringBuffer url = request.getRequestURL(); + String contextPath = request.getServletContext().getContextPath(); + return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString(); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/ThreadPoolConfig.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/ThreadPoolConfig.java new file mode 100644 index 000000000..628cd7bcf --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/ThreadPoolConfig.java @@ -0,0 +1,62 @@ +package com.jsowell.framework.config; + +import com.jsowell.common.util.Threads; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * 绾跨▼姹犻厤缃 + * + * @author jsowell + **/ +@Configuration +public class ThreadPoolConfig { + // 鏍稿績绾跨▼姹犲ぇ灏 + private final int corePoolSize = 50; + + // 鏈澶у彲鍒涘缓鐨勭嚎绋嬫暟 + private final int maxPoolSize = 200; + + // 闃熷垪鏈澶ч暱搴 + private final int queueCapacity = 1000; + + // 绾跨▼姹犵淮鎶ょ嚎绋嬫墍鍏佽鐨勭┖闂叉椂闂 + private final int keepAliveSeconds = 300; + + /** + * 绾跨▼姹 + */ + @Bean(name = "threadPoolTaskExecutor") + public ThreadPoolTaskExecutor threadPoolTaskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setMaxPoolSize(maxPoolSize); + executor.setCorePoolSize(corePoolSize); + executor.setQueueCapacity(queueCapacity); + executor.setKeepAliveSeconds(keepAliveSeconds); + // 绾跨▼姹犲鎷掔粷浠诲姟(鏃犵嚎绋嬪彲鐢)鐨勫鐞嗙瓥鐣 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; + } + + /** + * 鎵ц鍛ㄦ湡鎬ф垨瀹氭椂浠诲姟 + */ + @Bean(name = "scheduledExecutorService") + protected ScheduledExecutorService scheduledExecutorService() { + return new ScheduledThreadPoolExecutor(corePoolSize, + new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(), + new ThreadPoolExecutor.CallerRunsPolicy()) { + @Override + protected void afterExecute(Runnable r, Throwable t) { + super.afterExecute(r, t); + Threads.printException(r, t); + } + }; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/properties/DruidProperties.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/properties/DruidProperties.java new file mode 100644 index 000000000..3f433936d --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/properties/DruidProperties.java @@ -0,0 +1,75 @@ +package com.jsowell.framework.config.properties; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import com.alibaba.druid.pool.DruidDataSource; + +/** + * druid 閰嶇疆灞炴 + * + * @author jsowell + */ +@Configuration +public class DruidProperties { + @Value("${spring.datasource.druid.initialSize}") + private int initialSize; + + @Value("${spring.datasource.druid.minIdle}") + private int minIdle; + + @Value("${spring.datasource.druid.maxActive}") + private int maxActive; + + @Value("${spring.datasource.druid.maxWait}") + private int maxWait; + + @Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}") + private int timeBetweenEvictionRunsMillis; + + @Value("${spring.datasource.druid.minEvictableIdleTimeMillis}") + private int minEvictableIdleTimeMillis; + + @Value("${spring.datasource.druid.maxEvictableIdleTimeMillis}") + private int maxEvictableIdleTimeMillis; + + @Value("${spring.datasource.druid.validationQuery}") + private String validationQuery; + + @Value("${spring.datasource.druid.testWhileIdle}") + private boolean testWhileIdle; + + @Value("${spring.datasource.druid.testOnBorrow}") + private boolean testOnBorrow; + + @Value("${spring.datasource.druid.testOnReturn}") + private boolean testOnReturn; + + public DruidDataSource dataSource(DruidDataSource datasource) { + /** 閰嶇疆鍒濆鍖栧ぇ灏忋佹渶灏忋佹渶澶 */ + datasource.setInitialSize(initialSize); + datasource.setMaxActive(maxActive); + datasource.setMinIdle(minIdle); + + /** 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂 */ + datasource.setMaxWait(maxWait); + + /** 閰嶇疆闂撮殧澶氫箙鎵嶈繘琛屼竴娆℃娴嬶紝妫娴嬮渶瑕佸叧闂殑绌洪棽杩炴帴锛屽崟浣嶆槸姣 */ + datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); + + /** 閰嶇疆涓涓繛鎺ュ湪姹犱腑鏈灏忋佹渶澶х敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 */ + datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); + datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis); + + /** + * 鐢ㄦ潵妫娴嬭繛鎺ユ槸鍚︽湁鏁堢殑sql锛岃姹傛槸涓涓煡璇㈣鍙ワ紝甯哥敤select 'x'銆傚鏋渧alidationQuery涓簄ull锛宼estOnBorrow銆乼estOnReturn銆乼estWhileIdle閮戒笉浼氳捣浣滅敤銆 + */ + datasource.setValidationQuery(validationQuery); + /** 寤鸿閰嶇疆涓簍rue锛屼笉褰卞搷鎬ц兘锛屽苟涓斾繚璇佸畨鍏ㄦс傜敵璇疯繛鎺ョ殑鏃跺欐娴嬶紝濡傛灉绌洪棽鏃堕棿澶т簬timeBetweenEvictionRunsMillis锛屾墽琛寁alidationQuery妫娴嬭繛鎺ユ槸鍚︽湁鏁堛 */ + datasource.setTestWhileIdle(testWhileIdle); + /** 鐢宠杩炴帴鏃舵墽琛寁alidationQuery妫娴嬭繛鎺ユ槸鍚︽湁鏁堬紝鍋氫簡杩欎釜閰嶇疆浼氶檷浣庢ц兘銆 */ + datasource.setTestOnBorrow(testOnBorrow); + /** 褰掕繕杩炴帴鏃舵墽琛寁alidationQuery妫娴嬭繛鎺ユ槸鍚︽湁鏁堬紝鍋氫簡杩欎釜閰嶇疆浼氶檷浣庢ц兘銆 */ + datasource.setTestOnReturn(testOnReturn); + return datasource; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/config/properties/PermitAllUrlProperties.java b/jsowell-framework/src/main/java/com/jsowell/framework/config/properties/PermitAllUrlProperties.java new file mode 100644 index 000000000..8a5b680e6 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/config/properties/PermitAllUrlProperties.java @@ -0,0 +1,68 @@ +package com.jsowell.framework.config.properties; + +import com.jsowell.common.annotation.Anonymous; +import org.apache.commons.lang3.RegExUtils; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.mvc.method.RequestMappingInfo; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.regex.Pattern; + +/** + * 璁剧疆Anonymous娉ㄨВ鍏佽鍖垮悕璁块棶鐨剈rl + * + * @author jsowell + */ +@Configuration +public class PermitAllUrlProperties implements InitializingBean, ApplicationContextAware { + private static final Pattern PATTERN = Pattern.compile("\\{(.*?)\\}"); + + private ApplicationContext applicationContext; + + private List urls = new ArrayList<>(); + + public String ASTERISK = "*"; + + @Override + public void afterPropertiesSet() { + RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class); + Map map = mapping.getHandlerMethods(); + + map.keySet().forEach(info -> { + HandlerMethod handlerMethod = map.get(info); + + // 鑾峰彇鏂规硶涓婅竟鐨勬敞瑙 鏇夸唬path variable 涓 * + Anonymous method = AnnotationUtils.findAnnotation(handlerMethod.getMethod(), Anonymous.class); + Optional.ofNullable(method).ifPresent(anonymous -> info.getPatternsCondition().getPatterns() + .forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK)))); + + // 鑾峰彇绫讳笂杈圭殑娉ㄨВ, 鏇夸唬path variable 涓 * + Anonymous controller = AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), Anonymous.class); + Optional.ofNullable(controller).ifPresent(anonymous -> info.getPatternsCondition().getPatterns() + .forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK)))); + }); + } + + @Override + public void setApplicationContext(ApplicationContext context) throws BeansException { + this.applicationContext = context; + } + + public List getUrls() { + return urls; + } + + public void setUrls(List urls) { + this.urls = urls; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/datasource/DynamicDataSource.java b/jsowell-framework/src/main/java/com/jsowell/framework/datasource/DynamicDataSource.java new file mode 100644 index 000000000..a1ebaa7f7 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/datasource/DynamicDataSource.java @@ -0,0 +1,24 @@ +package com.jsowell.framework.datasource; + +import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; + +import javax.sql.DataSource; +import java.util.Map; + +/** + * 鍔ㄦ佹暟鎹簮 + * + * @author jsowell + */ +public class DynamicDataSource extends AbstractRoutingDataSource { + public DynamicDataSource(DataSource defaultTargetDataSource, Map targetDataSources) { + super.setDefaultTargetDataSource(defaultTargetDataSource); + super.setTargetDataSources(targetDataSources); + super.afterPropertiesSet(); + } + + @Override + protected Object determineCurrentLookupKey() { + return DynamicDataSourceContextHolder.getDataSourceType(); + } +} \ No newline at end of file diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/datasource/DynamicDataSourceContextHolder.java b/jsowell-framework/src/main/java/com/jsowell/framework/datasource/DynamicDataSourceContextHolder.java new file mode 100644 index 000000000..9f1c64c51 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/datasource/DynamicDataSourceContextHolder.java @@ -0,0 +1,41 @@ +package com.jsowell.framework.datasource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 鏁版嵁婧愬垏鎹㈠鐞 + * + * @author jsowell + */ +public class DynamicDataSourceContextHolder { + public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class); + + /** + * 浣跨敤ThreadLocal缁存姢鍙橀噺锛孴hreadLocal涓烘瘡涓娇鐢ㄨ鍙橀噺鐨勭嚎绋嬫彁渚涚嫭绔嬬殑鍙橀噺鍓湰锛 + * 鎵浠ユ瘡涓涓嚎绋嬮兘鍙互鐙珛鍦版敼鍙樿嚜宸辩殑鍓湰锛岃屼笉浼氬奖鍝嶅叾瀹冪嚎绋嬫墍瀵瑰簲鐨勫壇鏈 + */ + private static final ThreadLocal CONTEXT_HOLDER = new ThreadLocal<>(); + + /** + * 璁剧疆鏁版嵁婧愮殑鍙橀噺 + */ + public static void setDataSourceType(String dsType) { + log.info("鍒囨崲鍒皗}鏁版嵁婧", dsType); + CONTEXT_HOLDER.set(dsType); + } + + /** + * 鑾峰緱鏁版嵁婧愮殑鍙橀噺 + */ + public static String getDataSourceType() { + return CONTEXT_HOLDER.get(); + } + + /** + * 娓呯┖鏁版嵁婧愬彉閲 + */ + public static void clearDataSourceType() { + CONTEXT_HOLDER.remove(); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/interceptor/RepeatSubmitInterceptor.java b/jsowell-framework/src/main/java/com/jsowell/framework/interceptor/RepeatSubmitInterceptor.java new file mode 100644 index 000000000..1dcdc76ec --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/interceptor/RepeatSubmitInterceptor.java @@ -0,0 +1,49 @@ +package com.jsowell.framework.interceptor; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.annotation.RepeatSubmit; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.util.ServletUtils; +import org.springframework.stereotype.Component; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.lang.reflect.Method; + +/** + * 闃叉閲嶅鎻愪氦鎷︽埅鍣 + * + * @author jsowell + */ +@Component +public abstract class RepeatSubmitInterceptor implements HandlerInterceptor { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + if (handler instanceof HandlerMethod) { + HandlerMethod handlerMethod = (HandlerMethod) handler; + Method method = handlerMethod.getMethod(); + RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class); + if (annotation != null) { + if (this.isRepeatSubmit(request, annotation)) { + AjaxResult ajaxResult = AjaxResult.error(annotation.message()); + ServletUtils.renderString(response, JSON.toJSONString(ajaxResult)); + return false; + } + } + return true; + } else { + return true; + } + } + + /** + * 楠岃瘉鏄惁閲嶅鎻愪氦鐢卞瓙绫诲疄鐜板叿浣撶殑闃查噸澶嶆彁浜ょ殑瑙勫垯 + * + * @param request + * @return + * @throws Exception + */ + public abstract boolean isRepeatSubmit(HttpServletRequest request, RepeatSubmit annotation); +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/interceptor/impl/SameUrlDataInterceptor.java b/jsowell-framework/src/main/java/com/jsowell/framework/interceptor/impl/SameUrlDataInterceptor.java new file mode 100644 index 000000000..34f05fc56 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/interceptor/impl/SameUrlDataInterceptor.java @@ -0,0 +1,101 @@ +package com.jsowell.framework.interceptor.impl; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.annotation.RepeatSubmit; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.filter.RepeatedlyRequestWrapper; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.http.HttpHelper; +import com.jsowell.framework.interceptor.RepeatSubmitInterceptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * 鍒ゆ柇璇锋眰url鍜屾暟鎹槸鍚﹀拰涓婁竴娆$浉鍚岋紝 + * 濡傛灉鍜屼笂娆$浉鍚岋紝鍒欐槸閲嶅鎻愪氦琛ㄥ崟銆 鏈夋晥鏃堕棿涓10绉掑唴銆 + * + * @author jsowell + */ +@Component +public class SameUrlDataInterceptor extends RepeatSubmitInterceptor { + public final String REPEAT_PARAMS = "repeatParams"; + + public final String REPEAT_TIME = "repeatTime"; + + // 浠ょ墝鑷畾涔夋爣璇 + @Value("${token.header}") + private String header; + + @Autowired + private RedisCache redisCache; + + @SuppressWarnings("unchecked") + @Override + public boolean isRepeatSubmit(HttpServletRequest request, RepeatSubmit annotation) { + String nowParams = ""; + if (request instanceof RepeatedlyRequestWrapper) { + RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request; + nowParams = HttpHelper.getBodyString(repeatedlyRequest); + } + + // body鍙傛暟涓虹┖锛岃幏鍙朠arameter鐨勬暟鎹 + if (StringUtils.isEmpty(nowParams)) { + nowParams = JSON.toJSONString(request.getParameterMap()); + } + Map nowDataMap = new HashMap(); + nowDataMap.put(REPEAT_PARAMS, nowParams); + nowDataMap.put(REPEAT_TIME, System.currentTimeMillis()); + + // 璇锋眰鍦板潃锛堜綔涓哄瓨鏀綾ache鐨刱ey鍊硷級 + String url = request.getRequestURI(); + + // 鍞竴鍊硷紙娌℃湁娑堟伅澶村垯浣跨敤璇锋眰鍦板潃锛 + String submitKey = StringUtils.trimToEmpty(request.getHeader(header)); + + // 鍞竴鏍囪瘑锛堟寚瀹歬ey + url + 娑堟伅澶达級 + String cacheRepeatKey = CacheConstants.REPEAT_SUBMIT_KEY + url + submitKey; + + Object sessionObj = redisCache.getCacheObject(cacheRepeatKey); + if (sessionObj != null) { + Map sessionMap = (Map) sessionObj; + if (sessionMap.containsKey(url)) { + Map preDataMap = (Map) sessionMap.get(url); + if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap, annotation.interval())) { + return true; + } + } + } + Map cacheMap = new HashMap(); + cacheMap.put(url, nowDataMap); + redisCache.setCacheObject(cacheRepeatKey, cacheMap, annotation.interval(), TimeUnit.MILLISECONDS); + return false; + } + + /** + * 鍒ゆ柇鍙傛暟鏄惁鐩稿悓 + */ + private boolean compareParams(Map nowMap, Map preMap) { + String nowParams = (String) nowMap.get(REPEAT_PARAMS); + String preParams = (String) preMap.get(REPEAT_PARAMS); + return nowParams.equals(preParams); + } + + /** + * 鍒ゆ柇涓ゆ闂撮殧鏃堕棿 + */ + private boolean compareTime(Map nowMap, Map preMap, int interval) { + long time1 = (Long) nowMap.get(REPEAT_TIME); + long time2 = (Long) preMap.get(REPEAT_TIME); + if ((time1 - time2) < interval) { + return true; + } + return false; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/manager/AsyncManager.java b/jsowell-framework/src/main/java/com/jsowell/framework/manager/AsyncManager.java new file mode 100644 index 000000000..e41cbc459 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/manager/AsyncManager.java @@ -0,0 +1,53 @@ +package com.jsowell.framework.manager; + +import com.jsowell.common.util.Threads; +import com.jsowell.common.util.spring.SpringUtils; + +import java.util.TimerTask; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * 寮傛浠诲姟绠$悊鍣 + * + * @author jsowell + */ +public class AsyncManager { + /** + * 鎿嶄綔寤惰繜10姣 + */ + private final int OPERATE_DELAY_TIME = 10; + + /** + * 寮傛鎿嶄綔浠诲姟璋冨害绾跨▼姹 + */ + private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService"); + + /** + * 鍗曚緥妯″紡 + */ + private AsyncManager() { + } + + private static AsyncManager me = new AsyncManager(); + + public static AsyncManager me() { + return me; + } + + /** + * 鎵ц浠诲姟 + * + * @param task 浠诲姟 + */ + public void execute(TimerTask task) { + executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS); + } + + /** + * 鍋滄浠诲姟绾跨▼姹 + */ + public void shutdown() { + Threads.shutdownAndAwaitTermination(executor); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/manager/ShutdownManager.java b/jsowell-framework/src/main/java/com/jsowell/framework/manager/ShutdownManager.java new file mode 100644 index 000000000..d3ebb9294 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/manager/ShutdownManager.java @@ -0,0 +1,34 @@ +package com.jsowell.framework.manager; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.annotation.PreDestroy; + +/** + * 纭繚搴旂敤閫鍑烘椂鑳藉叧闂悗鍙扮嚎绋 + * + * @author jsowell + */ +@Component +public class ShutdownManager { + private static final Logger logger = LoggerFactory.getLogger("sys-user"); + + @PreDestroy + public void destroy() { + shutdownAsyncManager(); + } + + /** + * 鍋滄寮傛鎵ц浠诲姟 + */ + private void shutdownAsyncManager() { + try { + logger.info("====鍏抽棴鍚庡彴浠诲姟浠诲姟绾跨▼姹===="); + AsyncManager.me().shutdown(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/manager/factory/AsyncFactory.java b/jsowell-framework/src/main/java/com/jsowell/framework/manager/factory/AsyncFactory.java new file mode 100644 index 000000000..270106ced --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/manager/factory/AsyncFactory.java @@ -0,0 +1,93 @@ +package com.jsowell.framework.manager.factory; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.util.LogUtils; +import com.jsowell.common.util.ServletUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.ip.AddressUtils; +import com.jsowell.common.util.ip.IpUtils; +import com.jsowell.common.util.spring.SpringUtils; +import com.jsowell.system.domain.SysLogininfor; +import com.jsowell.system.domain.SysOperLog; +import com.jsowell.system.service.SysLogininforService; +import com.jsowell.system.service.SysOperLogService; +import eu.bitwalker.useragentutils.UserAgent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.TimerTask; + +/** + * 寮傛宸ュ巶锛堜骇鐢熶换鍔$敤锛 + * + * @author jsowell + */ +public class AsyncFactory { + private static final Logger sys_user_logger = LoggerFactory.getLogger("sys-user"); + + /** + * 璁板綍鐧诲綍淇℃伅 + * + * @param username 鐢ㄦ埛鍚 + * @param status 鐘舵 + * @param message 娑堟伅 + * @param args 鍒楄〃 + * @return 浠诲姟task + */ + public static TimerTask recordLogininfor(final String username, final String status, final String message, + final Object... args) { + final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); + final String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); + return new TimerTask() { + @Override + public void run() { + String address = AddressUtils.getRealAddressByIP(ip); + StringBuilder s = new StringBuilder(); + s.append(LogUtils.getBlock(ip)); + s.append(address); + s.append(LogUtils.getBlock(username)); + s.append(LogUtils.getBlock(status)); + s.append(LogUtils.getBlock(message)); + // 鎵撳嵃淇℃伅鍒版棩蹇 + sys_user_logger.info(s.toString(), args); + // 鑾峰彇瀹㈡埛绔搷浣滅郴缁 + String os = userAgent.getOperatingSystem().getName(); + // 鑾峰彇瀹㈡埛绔祻瑙堝櫒 + String browser = userAgent.getBrowser().getName(); + // 灏佽瀵硅薄 + SysLogininfor logininfor = new SysLogininfor(); + logininfor.setUserName(username); + logininfor.setIpaddr(ip); + logininfor.setLoginLocation(address); + logininfor.setBrowser(browser); + logininfor.setOs(os); + logininfor.setMsg(message); + // 鏃ュ織鐘舵 + if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER)) { + logininfor.setStatus(Constants.SUCCESS); + } else if (Constants.LOGIN_FAIL.equals(status)) { + logininfor.setStatus(Constants.FAIL); + } + // 鎻掑叆鏁版嵁 + SpringUtils.getBean(SysLogininforService.class).insertLogininfor(logininfor); + } + }; + } + + /** + * 鎿嶄綔鏃ュ織璁板綍 + * + * @param operLog 鎿嶄綔鏃ュ織淇℃伅 + * @return 浠诲姟task + */ + public static TimerTask recordOper(final SysOperLog operLog) { + return new TimerTask() { + @Override + public void run() { + // 杩滅▼鏌ヨ鎿嶄綔鍦扮偣 + operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp())); + SpringUtils.getBean(SysOperLogService.class).insertOperlog(operLog); + } + }; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/security/context/AuthenticationContextHolder.java b/jsowell-framework/src/main/java/com/jsowell/framework/security/context/AuthenticationContextHolder.java new file mode 100644 index 000000000..9a73b6e45 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/security/context/AuthenticationContextHolder.java @@ -0,0 +1,24 @@ +package com.jsowell.framework.security.context; + +import org.springframework.security.core.Authentication; + +/** + * 韬唤楠岃瘉淇℃伅 + * + * @author jsowell + */ +public class AuthenticationContextHolder { + private static final ThreadLocal contextHolder = new ThreadLocal<>(); + + public static Authentication getContext() { + return contextHolder.get(); + } + + public static void setContext(Authentication context) { + contextHolder.set(context); + } + + public static void clearContext() { + contextHolder.remove(); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/security/filter/JwtAuthenticationTokenFilter.java b/jsowell-framework/src/main/java/com/jsowell/framework/security/filter/JwtAuthenticationTokenFilter.java new file mode 100644 index 000000000..8fc2d948f --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/security/filter/JwtAuthenticationTokenFilter.java @@ -0,0 +1,42 @@ +package com.jsowell.framework.security.filter; + +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.framework.web.service.TokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * token杩囨护鍣 楠岃瘉token鏈夋晥鎬 + * + * @author jsowell + */ +@Component +public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { + @Autowired + private TokenService tokenService; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) + throws ServletException, IOException { + LoginUser loginUser = tokenService.getLoginUser(request); + if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) { + tokenService.verifyToken(loginUser); + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities()); + authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + } + chain.doFilter(request, response); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/security/handle/AuthenticationEntryPointImpl.java b/jsowell-framework/src/main/java/com/jsowell/framework/security/handle/AuthenticationEntryPointImpl.java new file mode 100644 index 000000000..b0e01e783 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/security/handle/AuthenticationEntryPointImpl.java @@ -0,0 +1,33 @@ +package com.jsowell.framework.security.handle; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.constant.HttpStatus; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.util.ServletUtils; +import com.jsowell.common.util.StringUtils; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.Serializable; + +/** + * 璁よ瘉澶辫触澶勭悊绫 杩斿洖鏈巿鏉 + * + * @author jsowell + */ +@Component +public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable { + private static final long serialVersionUID = -8970718410437077606L; + + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) + throws IOException { + int code = HttpStatus.UNAUTHORIZED; + String msg = StringUtils.format("璇锋眰璁块棶锛歿}锛岃璇佸け璐ワ紝鏃犳硶璁块棶绯荤粺璧勬簮", request.getRequestURI()); + ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg))); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/security/handle/LogoutSuccessHandlerImpl.java b/jsowell-framework/src/main/java/com/jsowell/framework/security/handle/LogoutSuccessHandlerImpl.java new file mode 100644 index 000000000..b3adc1e37 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/security/handle/LogoutSuccessHandlerImpl.java @@ -0,0 +1,51 @@ +package com.jsowell.framework.security.handle; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.constant.HttpStatus; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.util.ServletUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.framework.manager.AsyncManager; +import com.jsowell.framework.manager.factory.AsyncFactory; +import com.jsowell.framework.web.service.TokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.core.Authentication; +import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * 鑷畾涔夐鍑哄鐞嗙被 杩斿洖鎴愬姛 + * + * @author jsowell + */ +@Configuration +public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { + @Autowired + private TokenService tokenService; + + /** + * 閫鍑哄鐞 + * + * @return + */ + @Override + public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) + throws IOException, ServletException { + LoginUser loginUser = tokenService.getLoginUser(request); + if (StringUtils.isNotNull(loginUser)) { + String userName = loginUser.getUsername(); + // 鍒犻櫎鐢ㄦ埛缂撳瓨璁板綍 + tokenService.delLoginUser(loginUser.getToken()); + // 璁板綍鐢ㄦ埛閫鍑烘棩蹇 + AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "閫鍑烘垚鍔")); + } + ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.SUCCESS, "閫鍑烘垚鍔"))); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/Server.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/Server.java new file mode 100644 index 000000000..1d046e192 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/Server.java @@ -0,0 +1,215 @@ +package com.jsowell.framework.web.domain; + +import com.jsowell.common.util.Arith; +import com.jsowell.common.util.ip.IpUtils; +import com.jsowell.framework.web.domain.server.Cpu; +import com.jsowell.framework.web.domain.server.Jvm; +import com.jsowell.framework.web.domain.server.Mem; +import com.jsowell.framework.web.domain.server.Sys; +import com.jsowell.framework.web.domain.server.SysFile; +import oshi.SystemInfo; +import oshi.hardware.CentralProcessor; +import oshi.hardware.CentralProcessor.TickType; +import oshi.hardware.GlobalMemory; +import oshi.hardware.HardwareAbstractionLayer; +import oshi.software.os.FileSystem; +import oshi.software.os.OSFileStore; +import oshi.software.os.OperatingSystem; +import oshi.util.Util; + +import java.net.UnknownHostException; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +/** + * 鏈嶅姟鍣ㄧ浉鍏充俊鎭 + * + * @author jsowell + */ +public class Server { + private static final int OSHI_WAIT_SECOND = 1000; + + /** + * CPU鐩稿叧淇℃伅 + */ + private Cpu cpu = new Cpu(); + + /** + * 鍏у瓨鐩稿叧淇℃伅 + */ + private Mem mem = new Mem(); + + /** + * JVM鐩稿叧淇℃伅 + */ + private Jvm jvm = new Jvm(); + + /** + * 鏈嶅姟鍣ㄧ浉鍏充俊鎭 + */ + private Sys sys = new Sys(); + + /** + * 纾佺洏鐩稿叧淇℃伅 + */ + private List sysFiles = new LinkedList(); + + public Cpu getCpu() { + return cpu; + } + + public void setCpu(Cpu cpu) { + this.cpu = cpu; + } + + public Mem getMem() { + return mem; + } + + public void setMem(Mem mem) { + this.mem = mem; + } + + public Jvm getJvm() { + return jvm; + } + + public void setJvm(Jvm jvm) { + this.jvm = jvm; + } + + public Sys getSys() { + return sys; + } + + public void setSys(Sys sys) { + this.sys = sys; + } + + public List getSysFiles() { + return sysFiles; + } + + public void setSysFiles(List sysFiles) { + this.sysFiles = sysFiles; + } + + public void copyTo() throws Exception { + SystemInfo si = new SystemInfo(); + HardwareAbstractionLayer hal = si.getHardware(); + + setCpuInfo(hal.getProcessor()); + + setMemInfo(hal.getMemory()); + + setSysInfo(); + + setJvmInfo(); + + setSysFiles(si.getOperatingSystem()); + } + + /** + * 璁剧疆CPU淇℃伅 + */ + private void setCpuInfo(CentralProcessor processor) { + // CPU淇℃伅 + long[] prevTicks = processor.getSystemCpuLoadTicks(); + Util.sleep(OSHI_WAIT_SECOND); + long[] ticks = processor.getSystemCpuLoadTicks(); + long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()]; + long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()]; + long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()]; + long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()]; + long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()]; + long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()]; + long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()]; + long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()]; + long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal; + cpu.setCpuNum(processor.getLogicalProcessorCount()); + cpu.setTotal(totalCpu); + cpu.setSys(cSys); + cpu.setUsed(user); + cpu.setWait(iowait); + cpu.setFree(idle); + } + + /** + * 璁剧疆鍐呭瓨淇℃伅 + */ + private void setMemInfo(GlobalMemory memory) { + mem.setTotal(memory.getTotal()); + mem.setUsed(memory.getTotal() - memory.getAvailable()); + mem.setFree(memory.getAvailable()); + } + + /** + * 璁剧疆鏈嶅姟鍣ㄤ俊鎭 + */ + private void setSysInfo() { + Properties props = System.getProperties(); + sys.setComputerName(IpUtils.getHostName()); + sys.setComputerIp(IpUtils.getHostIp()); + sys.setOsName(props.getProperty("os.name")); + sys.setOsArch(props.getProperty("os.arch")); + sys.setUserDir(props.getProperty("user.dir")); + } + + /** + * 璁剧疆Java铏氭嫙鏈 + */ + private void setJvmInfo() throws UnknownHostException { + Properties props = System.getProperties(); + jvm.setTotal(Runtime.getRuntime().totalMemory()); + jvm.setMax(Runtime.getRuntime().maxMemory()); + jvm.setFree(Runtime.getRuntime().freeMemory()); + jvm.setVersion(props.getProperty("java.version")); + jvm.setHome(props.getProperty("java.home")); + } + + /** + * 璁剧疆纾佺洏淇℃伅 + */ + private void setSysFiles(OperatingSystem os) { + FileSystem fileSystem = os.getFileSystem(); + List fsArray = fileSystem.getFileStores(); + for (OSFileStore fs : fsArray) { + long free = fs.getUsableSpace(); + long total = fs.getTotalSpace(); + long used = total - free; + SysFile sysFile = new SysFile(); + sysFile.setDirName(fs.getMount()); + sysFile.setSysTypeName(fs.getType()); + sysFile.setTypeName(fs.getName()); + sysFile.setTotal(convertFileSize(total)); + sysFile.setFree(convertFileSize(free)); + sysFile.setUsed(convertFileSize(used)); + sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100)); + sysFiles.add(sysFile); + } + } + + /** + * 瀛楄妭杞崲 + * + * @param size 瀛楄妭澶у皬 + * @return 杞崲鍚庡 + */ + public String convertFileSize(long size) { + long kb = 1024; + long mb = kb * 1024; + long gb = mb * 1024; + if (size >= gb) { + return String.format("%.1f GB", (float) size / gb); + } else if (size >= mb) { + float f = (float) size / mb; + return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f); + } else if (size >= kb) { + float f = (float) size / kb; + return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f); + } else { + return String.format("%d B", size); + } + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Cpu.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Cpu.java new file mode 100644 index 000000000..692c14d77 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Cpu.java @@ -0,0 +1,88 @@ +package com.jsowell.framework.web.domain.server; + +import com.jsowell.common.util.Arith; + +/** + * CPU鐩稿叧淇℃伅 + * + * @author jsowell + */ +public class Cpu { + /** + * 鏍稿績鏁 + */ + private int cpuNum; + + /** + * CPU鎬荤殑浣跨敤鐜 + */ + private double total; + + /** + * CPU绯荤粺浣跨敤鐜 + */ + private double sys; + + /** + * CPU鐢ㄦ埛浣跨敤鐜 + */ + private double used; + + /** + * CPU褰撳墠绛夊緟鐜 + */ + private double wait; + + /** + * CPU褰撳墠绌洪棽鐜 + */ + private double free; + + public int getCpuNum() { + return cpuNum; + } + + public void setCpuNum(int cpuNum) { + this.cpuNum = cpuNum; + } + + public double getTotal() { + return Arith.round(Arith.mul(total, 100), 2); + } + + public void setTotal(double total) { + this.total = total; + } + + public double getSys() { + return Arith.round(Arith.mul(sys / total, 100), 2); + } + + public void setSys(double sys) { + this.sys = sys; + } + + public double getUsed() { + return Arith.round(Arith.mul(used / total, 100), 2); + } + + public void setUsed(double used) { + this.used = used; + } + + public double getWait() { + return Arith.round(Arith.mul(wait / total, 100), 2); + } + + public void setWait(double wait) { + this.wait = wait; + } + + public double getFree() { + return Arith.round(Arith.mul(free / total, 100), 2); + } + + public void setFree(double free) { + this.free = free; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Jvm.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Jvm.java new file mode 100644 index 000000000..c93b5b28d --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Jvm.java @@ -0,0 +1,114 @@ +package com.jsowell.framework.web.domain.server; + +import com.jsowell.common.util.Arith; +import com.jsowell.common.util.DateUtils; + +import java.lang.management.ManagementFactory; + +/** + * JVM鐩稿叧淇℃伅 + * + * @author jsowell + */ +public class Jvm { + /** + * 褰撳墠JVM鍗犵敤鐨勫唴瀛樻绘暟(M) + */ + private double total; + + /** + * JVM鏈澶у彲鐢ㄥ唴瀛樻绘暟(M) + */ + private double max; + + /** + * JVM绌洪棽鍐呭瓨(M) + */ + private double free; + + /** + * JDK鐗堟湰 + */ + private String version; + + /** + * JDK璺緞 + */ + private String home; + + public double getTotal() { + return Arith.div(total, (1024 * 1024), 2); + } + + public void setTotal(double total) { + this.total = total; + } + + public double getMax() { + return Arith.div(max, (1024 * 1024), 2); + } + + public void setMax(double max) { + this.max = max; + } + + public double getFree() { + return Arith.div(free, (1024 * 1024), 2); + } + + public void setFree(double free) { + this.free = free; + } + + public double getUsed() { + return Arith.div(total - free, (1024 * 1024), 2); + } + + public double getUsage() { + return Arith.mul(Arith.div(total - free, total, 4), 100); + } + + /** + * 鑾峰彇JDK鍚嶇О + */ + public String getName() { + return ManagementFactory.getRuntimeMXBean().getVmName(); + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getHome() { + return home; + } + + public void setHome(String home) { + this.home = home; + } + + /** + * JDK鍚姩鏃堕棿 + */ + public String getStartTime() { + return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate()); + } + + /** + * JDK杩愯鏃堕棿 + */ + public String getRunTime() { + return DateUtils.getDatePoor(DateUtils.getNowDate(), DateUtils.getServerStartDate()); + } + + /** + * 杩愯鍙傛暟 + */ + public String getInputArgs() { + return ManagementFactory.getRuntimeMXBean().getInputArguments().toString(); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Mem.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Mem.java new file mode 100644 index 000000000..871919457 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Mem.java @@ -0,0 +1,53 @@ +package com.jsowell.framework.web.domain.server; + +import com.jsowell.common.util.Arith; + +/** + * 鍏у瓨鐩稿叧淇℃伅 + * + * @author jsowell + */ +public class Mem { + /** + * 鍐呭瓨鎬婚噺 + */ + private double total; + + /** + * 宸茬敤鍐呭瓨 + */ + private double used; + + /** + * 鍓╀綑鍐呭瓨 + */ + private double free; + + public double getTotal() { + return Arith.div(total, (1024 * 1024 * 1024), 2); + } + + public void setTotal(long total) { + this.total = total; + } + + public double getUsed() { + return Arith.div(used, (1024 * 1024 * 1024), 2); + } + + public void setUsed(long used) { + this.used = used; + } + + public double getFree() { + return Arith.div(free, (1024 * 1024 * 1024), 2); + } + + public void setFree(long free) { + this.free = free; + } + + public double getUsage() { + return Arith.mul(Arith.div(used, total, 4), 100); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Sys.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Sys.java new file mode 100644 index 000000000..853586757 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/Sys.java @@ -0,0 +1,73 @@ +package com.jsowell.framework.web.domain.server; + +/** + * 绯荤粺鐩稿叧淇℃伅 + * + * @author jsowell + */ +public class Sys { + /** + * 鏈嶅姟鍣ㄥ悕绉 + */ + private String computerName; + + /** + * 鏈嶅姟鍣↖p + */ + private String computerIp; + + /** + * 椤圭洰璺緞 + */ + private String userDir; + + /** + * 鎿嶄綔绯荤粺 + */ + private String osName; + + /** + * 绯荤粺鏋舵瀯 + */ + private String osArch; + + public String getComputerName() { + return computerName; + } + + public void setComputerName(String computerName) { + this.computerName = computerName; + } + + public String getComputerIp() { + return computerIp; + } + + public void setComputerIp(String computerIp) { + this.computerIp = computerIp; + } + + public String getUserDir() { + return userDir; + } + + public void setUserDir(String userDir) { + this.userDir = userDir; + } + + public String getOsName() { + return osName; + } + + public void setOsName(String osName) { + this.osName = osName; + } + + public String getOsArch() { + return osArch; + } + + public void setOsArch(String osArch) { + this.osArch = osArch; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/SysFile.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/SysFile.java new file mode 100644 index 000000000..75b4df57a --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/domain/server/SysFile.java @@ -0,0 +1,99 @@ +package com.jsowell.framework.web.domain.server; + +/** + * 绯荤粺鏂囦欢鐩稿叧淇℃伅 + * + * @author jsowell + */ +public class SysFile { + /** + * 鐩樼璺緞 + */ + private String dirName; + + /** + * 鐩樼绫诲瀷 + */ + private String sysTypeName; + + /** + * 鏂囦欢绫诲瀷 + */ + private String typeName; + + /** + * 鎬诲ぇ灏 + */ + private String total; + + /** + * 鍓╀綑澶у皬 + */ + private String free; + + /** + * 宸茬粡浣跨敤閲 + */ + private String used; + + /** + * 璧勬簮鐨勪娇鐢ㄧ巼 + */ + private double usage; + + public String getDirName() { + return dirName; + } + + public void setDirName(String dirName) { + this.dirName = dirName; + } + + public String getSysTypeName() { + return sysTypeName; + } + + public void setSysTypeName(String sysTypeName) { + this.sysTypeName = sysTypeName; + } + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public String getTotal() { + return total; + } + + public void setTotal(String total) { + this.total = total; + } + + public String getFree() { + return free; + } + + public void setFree(String free) { + this.free = free; + } + + public String getUsed() { + return used; + } + + public void setUsed(String used) { + this.used = used; + } + + public double getUsage() { + return usage; + } + + public void setUsage(double usage) { + this.usage = usage; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/exception/GlobalExceptionHandler.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/exception/GlobalExceptionHandler.java new file mode 100644 index 000000000..17164ae33 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/exception/GlobalExceptionHandler.java @@ -0,0 +1,106 @@ +package com.jsowell.framework.web.exception; + +import com.jsowell.common.constant.HttpStatus; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.exception.DemoModeException; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.validation.BindException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import javax.servlet.http.HttpServletRequest; + +/** + * 鍏ㄥ眬寮傚父澶勭悊鍣 + * + * @author jsowell + */ +@RestControllerAdvice +public class GlobalExceptionHandler { + private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); + + /** + * 鏉冮檺鏍¢獙寮傚父 + */ + @ExceptionHandler(AccessDeniedException.class) + public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',鏉冮檺鏍¢獙澶辫触'{}'", requestURI, e.getMessage()); + return AjaxResult.error(HttpStatus.FORBIDDEN, "娌℃湁鏉冮檺锛岃鑱旂郴绠$悊鍛樻巿鏉"); + } + + /** + * 璇锋眰鏂瑰紡涓嶆敮鎸 + */ + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, + HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',涓嶆敮鎸'{}'璇锋眰", requestURI, e.getMethod()); + return AjaxResult.error(e.getMessage()); + } + + /** + * 涓氬姟寮傚父 + */ + @ExceptionHandler(ServiceException.class) + public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) { + log.error(e.getMessage(), e); + Integer code = e.getCode(); + return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage()); + } + + /** + * 鎷︽埅鏈煡鐨勮繍琛屾椂寮傚父 + */ + @ExceptionHandler(RuntimeException.class) + public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',鍙戠敓鏈煡寮傚父.", requestURI, e); + return AjaxResult.error(e.getMessage()); + } + + /** + * 绯荤粺寮傚父 + */ + @ExceptionHandler(Exception.class) + public AjaxResult handleException(Exception e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',鍙戠敓绯荤粺寮傚父.", requestURI, e); + return AjaxResult.error(e.getMessage()); + } + + /** + * 鑷畾涔夐獙璇佸紓甯 + */ + @ExceptionHandler(BindException.class) + public AjaxResult handleBindException(BindException e) { + log.error(e.getMessage(), e); + String message = e.getAllErrors().get(0).getDefaultMessage(); + return AjaxResult.error(message); + } + + /** + * 鑷畾涔夐獙璇佸紓甯 + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + log.error(e.getMessage(), e); + String message = e.getBindingResult().getFieldError().getDefaultMessage(); + return AjaxResult.error(message); + } + + /** + * 婕旂ず妯″紡寮傚父 + */ + @ExceptionHandler(DemoModeException.class) + public AjaxResult handleDemoModeException(DemoModeException e) { + return AjaxResult.error("婕旂ず妯″紡锛屼笉鍏佽鎿嶄綔"); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/service/PermissionService.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/PermissionService.java new file mode 100644 index 000000000..c510610d0 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/PermissionService.java @@ -0,0 +1,148 @@ +package com.jsowell.framework.web.service; + +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.Set; + +/** + * 鑷畾涔夋潈闄愬疄鐜帮紝ss鍙栬嚜SpringSecurity棣栧瓧姣 + * + * @author jsowell + */ +@Service("ss") +public class PermissionService { + /** + * 鎵鏈夋潈闄愭爣璇 + */ + private static final String ALL_PERMISSION = "*:*:*"; + + /** + * 绠$悊鍛樿鑹叉潈闄愭爣璇 + */ + private static final String SUPER_ADMIN = "admin"; + + private static final String ROLE_DELIMETER = ","; + + private static final String PERMISSION_DELIMETER = ","; + + /** + * 楠岃瘉鐢ㄦ埛鏄惁鍏峰鏌愭潈闄 + * + * @param permission 鏉冮檺瀛楃涓 + * @return 鐢ㄦ埛鏄惁鍏峰鏌愭潈闄 + */ + public boolean hasPermi(String permission) { + if (StringUtils.isEmpty(permission)) { + return false; + } + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) { + return false; + } + return hasPermissions(loginUser.getPermissions(), permission); + } + + /** + * 楠岃瘉鐢ㄦ埛鏄惁涓嶅叿澶囨煇鏉冮檺锛屼笌 hasPermi閫昏緫鐩稿弽 + * + * @param permission 鏉冮檺瀛楃涓 + * @return 鐢ㄦ埛鏄惁涓嶅叿澶囨煇鏉冮檺 + */ + public boolean lacksPermi(String permission) { + return hasPermi(permission) != true; + } + + /** + * 楠岃瘉鐢ㄦ埛鏄惁鍏锋湁浠ヤ笅浠绘剰涓涓潈闄 + * + * @param permissions 浠 PERMISSION_NAMES_DELIMETER 涓哄垎闅旂鐨勬潈闄愬垪琛 + * @return 鐢ㄦ埛鏄惁鍏锋湁浠ヤ笅浠绘剰涓涓潈闄 + */ + public boolean hasAnyPermi(String permissions) { + if (StringUtils.isEmpty(permissions)) { + return false; + } + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) { + return false; + } + Set authorities = loginUser.getPermissions(); + for (String permission : permissions.split(PERMISSION_DELIMETER)) { + if (permission != null && hasPermissions(authorities, permission)) { + return true; + } + } + return false; + } + + /** + * 鍒ゆ柇鐢ㄦ埛鏄惁鎷ユ湁鏌愪釜瑙掕壊 + * + * @param role 瑙掕壊瀛楃涓 + * @return 鐢ㄦ埛鏄惁鍏峰鏌愯鑹 + */ + public boolean hasRole(String role) { + if (StringUtils.isEmpty(role)) { + return false; + } + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) { + return false; + } + for (SysRole sysRole : loginUser.getUser().getRoles()) { + String roleKey = sysRole.getRoleKey(); + if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(StringUtils.trim(role))) { + return true; + } + } + return false; + } + + /** + * 楠岃瘉鐢ㄦ埛鏄惁涓嶅叿澶囨煇瑙掕壊锛屼笌 isRole閫昏緫鐩稿弽銆 + * + * @param role 瑙掕壊鍚嶇О + * @return 鐢ㄦ埛鏄惁涓嶅叿澶囨煇瑙掕壊 + */ + public boolean lacksRole(String role) { + return hasRole(role) != true; + } + + /** + * 楠岃瘉鐢ㄦ埛鏄惁鍏锋湁浠ヤ笅浠绘剰涓涓鑹 + * + * @param roles 浠 ROLE_NAMES_DELIMETER 涓哄垎闅旂鐨勮鑹插垪琛 + * @return 鐢ㄦ埛鏄惁鍏锋湁浠ヤ笅浠绘剰涓涓鑹 + */ + public boolean hasAnyRoles(String roles) { + if (StringUtils.isEmpty(roles)) { + return false; + } + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) { + return false; + } + for (String role : roles.split(ROLE_DELIMETER)) { + if (hasRole(role)) { + return true; + } + } + return false; + } + + /** + * 鍒ゆ柇鏄惁鍖呭惈鏉冮檺 + * + * @param permissions 鏉冮檺鍒楄〃 + * @param permission 鏉冮檺瀛楃涓 + * @return 鐢ㄦ埛鏄惁鍏峰鏌愭潈闄 + */ + private boolean hasPermissions(Set permissions, String permission) { + return permissions.contains(ALL_PERMISSION) || permissions.contains(StringUtils.trim(permission)); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysLoginService.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysLoginService.java new file mode 100644 index 000000000..1676786a7 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysLoginService.java @@ -0,0 +1,125 @@ +package com.jsowell.framework.web.service; + +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.exception.user.CaptchaException; +import com.jsowell.common.exception.user.CaptchaExpireException; +import com.jsowell.common.exception.user.UserPasswordNotMatchException; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.MessageUtils; +import com.jsowell.common.util.ServletUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.ip.IpUtils; +import com.jsowell.framework.manager.AsyncManager; +import com.jsowell.framework.manager.factory.AsyncFactory; +import com.jsowell.framework.security.context.AuthenticationContextHolder; +import com.jsowell.system.service.SysConfigService; +import com.jsowell.system.service.SysUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 鐧诲綍鏍¢獙鏂规硶 + * + * @author jsowell + */ +@Component +public class SysLoginService { + @Autowired + private TokenService tokenService; + + @Resource + private AuthenticationManager authenticationManager; + + @Autowired + private RedisCache redisCache; + + @Autowired + private SysUserService userService; + + @Autowired + private SysConfigService configService; + + /** + * 鐧诲綍楠岃瘉 + * + * @param username 鐢ㄦ埛鍚 + * @param password 瀵嗙爜 + * @param code 楠岃瘉鐮 + * @param uuid 鍞竴鏍囪瘑 + * @return 缁撴灉 + */ + public String login(String username, String password, String code, String uuid) { + boolean captchaEnabled = configService.selectCaptchaEnabled(); + // 楠岃瘉鐮佸紑鍏 + if (captchaEnabled) { + validateCaptcha(username, code, uuid); + } + // 鐢ㄦ埛楠岃瘉 + Authentication authentication = null; + try { + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); + AuthenticationContextHolder.setContext(authenticationToken); + // 璇ユ柟娉曚細鍘昏皟鐢║serDetailsServiceImpl.loadUserByUsername + authentication = authenticationManager.authenticate(authenticationToken); + } catch (Exception e) { + if (e instanceof BadCredentialsException) { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); + throw new UserPasswordNotMatchException(); + } else { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); + throw new ServiceException(e.getMessage()); + } + } + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + recordLoginInfo(loginUser.getUserId()); + // 鐢熸垚token + return tokenService.createToken(loginUser); + } + + /** + * 鏍¢獙楠岃瘉鐮 + * + * @param username 鐢ㄦ埛鍚 + * @param code 楠岃瘉鐮 + * @param uuid 鍞竴鏍囪瘑 + * @return 缁撴灉 + */ + public void validateCaptcha(String username, String code, String uuid) { + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); + String captcha = redisCache.getCacheObject(verifyKey); + redisCache.deleteObject(verifyKey); + if (captcha == null) { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); + throw new CaptchaExpireException(); + } + if (!code.equalsIgnoreCase(captcha)) { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); + throw new CaptchaException(); + } + } + + /** + * 璁板綍鐧诲綍淇℃伅 + * + * @param userId 鐢ㄦ埛ID + */ + public void recordLoginInfo(Long userId) { + SysUser sysUser = new SysUser(); + sysUser.setUserId(userId); + sysUser.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); + sysUser.setLoginDate(DateUtils.getNowDate()); + userService.updateUserProfile(sysUser); + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysPasswordService.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysPasswordService.java new file mode 100644 index 000000000..adbaa1a45 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysPasswordService.java @@ -0,0 +1,84 @@ +package com.jsowell.framework.web.service; + +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.exception.user.UserPasswordNotMatchException; +import com.jsowell.common.exception.user.UserPasswordRetryLimitExceedException; +import com.jsowell.common.util.MessageUtils; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.framework.manager.AsyncManager; +import com.jsowell.framework.manager.factory.AsyncFactory; +import com.jsowell.framework.security.context.AuthenticationContextHolder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +/** + * 鐧诲綍瀵嗙爜鏂规硶 + * + * @author jsowell + */ +@Component +public class SysPasswordService { + @Autowired + private RedisCache redisCache; + + @Value(value = "${user.password.maxRetryCount}") + private int maxRetryCount; + + @Value(value = "${user.password.lockTime}") + private int lockTime; + + /** + * 鐧诲綍璐︽埛瀵嗙爜閿欒娆℃暟缂撳瓨閿悕 + * + * @param username 鐢ㄦ埛鍚 + * @return 缂撳瓨閿甼ey + */ + private String getCacheKey(String username) { + return CacheConstants.PWD_ERR_CNT_KEY + username; + } + + public void validate(SysUser user) { + Authentication usernamePasswordAuthenticationToken = AuthenticationContextHolder.getContext(); + String username = usernamePasswordAuthenticationToken.getName(); + String password = usernamePasswordAuthenticationToken.getCredentials().toString(); + + Integer retryCount = redisCache.getCacheObject(getCacheKey(username)); + + if (retryCount == null) { + retryCount = 0; + } + + if (retryCount >= Integer.valueOf(maxRetryCount).intValue()) { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, + MessageUtils.message("user.password.retry.limit.exceed", maxRetryCount, lockTime))); + throw new UserPasswordRetryLimitExceedException(maxRetryCount, lockTime); + } + + if (!matches(user, password)) { + retryCount = retryCount + 1; + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, + MessageUtils.message("user.password.retry.limit.count", retryCount))); + redisCache.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); + throw new UserPasswordNotMatchException(); + } else { + clearLoginRecordCache(username); + } + } + + public boolean matches(SysUser user, String rawPassword) { + return SecurityUtils.matchesPassword(rawPassword, user.getPassword()); + } + + public void clearLoginRecordCache(String loginName) { + if (redisCache.hasKey(getCacheKey(loginName))) { + redisCache.deleteObject(getCacheKey(loginName)); + } + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysPermissionService.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysPermissionService.java new file mode 100644 index 000000000..78e971693 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysPermissionService.java @@ -0,0 +1,58 @@ +package com.jsowell.framework.web.service; + +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.system.service.SysMenuService; +import com.jsowell.system.service.SysRoleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.HashSet; +import java.util.Set; + +/** + * 鐢ㄦ埛鏉冮檺澶勭悊 + * + * @author jsowell + */ +@Component +public class SysPermissionService { + @Autowired + private SysRoleService roleService; + + @Autowired + private SysMenuService menuService; + + /** + * 鑾峰彇瑙掕壊鏁版嵁鏉冮檺 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 瑙掕壊鏉冮檺淇℃伅 + */ + public Set getRolePermission(SysUser user) { + Set roles = new HashSet(); + // 绠$悊鍛樻嫢鏈夋墍鏈夋潈闄 + if (user.isAdmin()) { + roles.add("admin"); + } else { + roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); + } + return roles; + } + + /** + * 鑾峰彇鑿滃崟鏁版嵁鏉冮檺 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鑿滃崟鏉冮檺淇℃伅 + */ + public Set getMenuPermission(SysUser user) { + Set perms = new HashSet(); + // 绠$悊鍛樻嫢鏈夋墍鏈夋潈闄 + if (user.isAdmin()) { + perms.add("*:*:*"); + } else { + perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); + } + return perms; + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysRegisterService.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysRegisterService.java new file mode 100644 index 000000000..2f7458c36 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/SysRegisterService.java @@ -0,0 +1,96 @@ +package com.jsowell.framework.web.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.domain.model.RegisterBody; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.exception.user.CaptchaException; +import com.jsowell.common.exception.user.CaptchaExpireException; +import com.jsowell.common.util.MessageUtils; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.framework.manager.AsyncManager; +import com.jsowell.framework.manager.factory.AsyncFactory; +import com.jsowell.system.service.SysConfigService; +import com.jsowell.system.service.SysUserService; + +/** + * 娉ㄥ唽鏍¢獙鏂规硶 + * + * @author jsowell + */ +@Component +public class SysRegisterService { + @Autowired + private SysUserService userService; + + @Autowired + private SysConfigService configService; + + @Autowired + private RedisCache redisCache; + + /** + * 娉ㄥ唽 + */ + public String register(RegisterBody registerBody) { + String msg = "", username = registerBody.getUsername(), password = registerBody.getPassword(); + + boolean captchaEnabled = configService.selectCaptchaEnabled(); + // 楠岃瘉鐮佸紑鍏 + if (captchaEnabled) { + validateCaptcha(username, registerBody.getCode(), registerBody.getUuid()); + } + + if (StringUtils.isEmpty(username)) { + msg = "鐢ㄦ埛鍚嶄笉鑳戒负绌"; + } else if (StringUtils.isEmpty(password)) { + msg = "鐢ㄦ埛瀵嗙爜涓嶈兘涓虹┖"; + } else if (username.length() < UserConstants.USERNAME_MIN_LENGTH + || username.length() > UserConstants.USERNAME_MAX_LENGTH) { + msg = "璐︽埛闀垮害蹇呴』鍦2鍒20涓瓧绗︿箣闂"; + } else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH + || password.length() > UserConstants.PASSWORD_MAX_LENGTH) { + msg = "瀵嗙爜闀垮害蹇呴』鍦5鍒20涓瓧绗︿箣闂"; + } else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) { + msg = "淇濆瓨鐢ㄦ埛'" + username + "'澶辫触锛屾敞鍐岃处鍙峰凡瀛樺湪"; + } else { + SysUser sysUser = new SysUser(); + sysUser.setUserName(username); + sysUser.setNickName(username); + sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword())); + boolean regFlag = userService.registerUser(sysUser); + if (!regFlag) { + msg = "娉ㄥ唽澶辫触,璇疯仈绯荤郴缁熺鐞嗕汉鍛"; + } else { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER, + MessageUtils.message("user.register.success"))); + } + } + return msg; + } + + /** + * 鏍¢獙楠岃瘉鐮 + * + * @param username 鐢ㄦ埛鍚 + * @param code 楠岃瘉鐮 + * @param uuid 鍞竴鏍囪瘑 + * @return 缁撴灉 + */ + public void validateCaptcha(String username, String code, String uuid) { + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); + String captcha = redisCache.getCacheObject(verifyKey); + redisCache.deleteObject(verifyKey); + if (captcha == null) { + throw new CaptchaExpireException(); + } + if (!code.equalsIgnoreCase(captcha)) { + throw new CaptchaException(); + } + } +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/service/TokenService.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/TokenService.java new file mode 100644 index 000000000..d7f6ba6cc --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/TokenService.java @@ -0,0 +1,211 @@ +package com.jsowell.framework.web.service; + +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.util.ServletUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.IdUtils; +import com.jsowell.common.util.ip.AddressUtils; +import com.jsowell.common.util.ip.IpUtils; +import eu.bitwalker.useragentutils.UserAgent; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * token楠岃瘉澶勭悊 + * + * @author jsowell + */ +@Component +public class TokenService { + // 浠ょ墝鑷畾涔夋爣璇 + @Value("${token.header}") + private String header; + + // 浠ょ墝绉橀挜 + @Value("${token.secret}") + private String secret; + + // 浠ょ墝鏈夋晥鏈燂紙榛樿30鍒嗛挓锛 + @Value("${token.expireTime}") + private int expireTime; + + // 鎺ュ彛鏈嶅姟 浠ょ墝鏈夋晥鏈 + @Value("${token.serviceExpireTime}") + private int serviceExpireTime; + + protected static final long MILLIS_SECOND = 1000; + + protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; + + private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L; + + @Autowired + private RedisCache redisCache; + + /** + * 鑾峰彇鐢ㄦ埛韬唤淇℃伅 + * + * @return 鐢ㄦ埛淇℃伅 + */ + public LoginUser getLoginUser(HttpServletRequest request) { + // 鑾峰彇璇锋眰鎼哄甫鐨勪护鐗 + String token = getToken(request); + if (StringUtils.isNotEmpty(token)) { + try { + Claims claims = parseToken(token); + // 瑙f瀽瀵瑰簲鐨勬潈闄愪互鍙婄敤鎴蜂俊鎭 + String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); + String userKey = getTokenKey(uuid); + LoginUser user = redisCache.getCacheObject(userKey); + return user; + } catch (Exception e) { + } + } + return null; + } + + /** + * 璁剧疆鐢ㄦ埛韬唤淇℃伅 + */ + public void setLoginUser(LoginUser loginUser) { + if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) { + refreshToken(loginUser); + } + } + + /** + * 鍒犻櫎鐢ㄦ埛韬唤淇℃伅 + */ + public void delLoginUser(String token) { + if (StringUtils.isNotEmpty(token)) { + String userKey = getTokenKey(token); + redisCache.deleteObject(userKey); + } + } + + /** + * 鍒涘缓浠ょ墝 + * + * @param loginUser 鐢ㄦ埛淇℃伅 + * @return 浠ょ墝 + */ + public String createToken(LoginUser loginUser) { + String token = IdUtils.fastUUID(); + loginUser.setToken(token); + setUserAgent(loginUser); + refreshToken(loginUser); + + Map claims = new HashMap<>(); + claims.put(Constants.LOGIN_USER_KEY, token); + return createToken(claims); + } + + /** + * 楠岃瘉浠ょ墝鏈夋晥鏈燂紝鐩稿樊涓嶈冻20鍒嗛挓锛岃嚜鍔ㄥ埛鏂扮紦瀛 + * + * @param loginUser + * @return 浠ょ墝 + */ + public void verifyToken(LoginUser loginUser) { + long expireTime = loginUser.getExpireTime(); + long currentTime = System.currentTimeMillis(); + if (expireTime - currentTime <= MILLIS_MINUTE_TEN) { + refreshToken(loginUser); + } + } + + /** + * 鍒锋柊浠ょ墝鏈夋晥鏈 + * + * @param loginUser 鐧诲綍淇℃伅 + */ + public void refreshToken(LoginUser loginUser) { + loginUser.setLoginTime(System.currentTimeMillis()); + loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); + // 鏍规嵁uuid灏唋oginUser缂撳瓨 + String userKey = getTokenKey(loginUser.getToken()); + redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); + } + + /** + * 璁剧疆鐢ㄦ埛浠g悊淇℃伅 + * + * @param loginUser 鐧诲綍淇℃伅 + */ + public void setUserAgent(LoginUser loginUser) { + UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); + String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); + loginUser.setIpaddr(ip); + loginUser.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); + loginUser.setBrowser(userAgent.getBrowser().getName()); + loginUser.setOs(userAgent.getOperatingSystem().getName()); + } + + /** + * 浠庢暟鎹0鏄庣敓鎴愪护鐗 + * + * @param claims 鏁版嵁澹版槑 + * @return 浠ょ墝 + */ + private String createToken(Map claims) { + String token = Jwts.builder() + .setClaims(claims) + .signWith(SignatureAlgorithm.HS512, secret).compact(); + return token; + } + + /** + * 浠庝护鐗屼腑鑾峰彇鏁版嵁澹版槑 + * + * @param token 浠ょ墝 + * @return 鏁版嵁澹版槑 + */ + private Claims parseToken(String token) { + return Jwts.parser() + .setSigningKey(secret) + .parseClaimsJws(token) + .getBody(); + } + + /** + * 浠庝护鐗屼腑鑾峰彇鐢ㄦ埛鍚 + * + * @param token 浠ょ墝 + * @return 鐢ㄦ埛鍚 + */ + public String getUsernameFromToken(String token) { + Claims claims = parseToken(token); + return claims.getSubject(); + } + + /** + * 鑾峰彇璇锋眰token + * + * @param request + * @return token + */ + private String getToken(HttpServletRequest request) { + String token = request.getHeader(header); + if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) { + token = token.replace(Constants.TOKEN_PREFIX, ""); + } + return token; + } + + private String getTokenKey(String uuid) { + return CacheConstants.LOGIN_TOKEN_KEY + uuid; + } + +} diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/web/service/UserDetailsServiceImpl.java b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/UserDetailsServiceImpl.java new file mode 100644 index 000000000..f0f9108f7 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/web/service/UserDetailsServiceImpl.java @@ -0,0 +1,57 @@ +package com.jsowell.framework.web.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.enums.UserStatus; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.service.SysUserService; + +/** + * 鐢ㄦ埛楠岃瘉澶勭悊 + * + * @author jsowell + */ +@Service +public class UserDetailsServiceImpl implements UserDetailsService { + private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class); + + @Autowired + private SysUserService userService; + + @Autowired + private SysPasswordService passwordService; + + @Autowired + private SysPermissionService permissionService; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + SysUser user = userService.selectUserByUserName(username); + if (StringUtils.isNull(user)) { + log.info("鐧诲綍鐢ㄦ埛锛歿} 涓嶅瓨鍦.", username); + throw new ServiceException("鐧诲綍鐢ㄦ埛锛" + username + " 涓嶅瓨鍦"); + } else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { + log.info("鐧诲綍鐢ㄦ埛锛歿} 宸茶鍒犻櫎.", username); + throw new ServiceException("瀵逛笉璧凤紝鎮ㄧ殑璐﹀彿锛" + username + " 宸茶鍒犻櫎"); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("鐧诲綍鐢ㄦ埛锛歿} 宸茶鍋滅敤.", username); + throw new ServiceException("瀵逛笉璧凤紝鎮ㄧ殑璐﹀彿锛" + username + " 宸插仠鐢"); + } + + passwordService.validate(user); + + return createLoginUser(user); + } + + public UserDetails createLoginUser(SysUser user) { + return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user)); + } +} diff --git a/jsowell-generator/pom.xml b/jsowell-generator/pom.xml new file mode 100644 index 000000000..9a7aa3fc1 --- /dev/null +++ b/jsowell-generator/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + com.jsowell + jsowell-charger-web + 1.0.0 + + + jsowell-generator + + + generator浠g爜鐢熸垚 + + + + + + + org.apache.velocity + velocity-engine-core + + + + + commons-collections + commons-collections + + + + + com.jsowell + jsowell-common + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + /src/test/** + + utf-8 + + + + + + \ No newline at end of file diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/config/GenConfig.java b/jsowell-generator/src/main/java/com/jsowell/generator/config/GenConfig.java new file mode 100644 index 000000000..16e3c2b97 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/config/GenConfig.java @@ -0,0 +1,72 @@ +package com.jsowell.generator.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; + +/** + * 璇诲彇浠g爜鐢熸垚鐩稿叧閰嶇疆 + * + * @author jsowell + */ +@Component +@ConfigurationProperties(prefix = "gen") +@PropertySource(value = {"classpath:generator.yml"}) +public class GenConfig { + /** + * 浣滆 + */ + public static String author; + + /** + * 鐢熸垚鍖呰矾寰 + */ + public static String packageName; + + /** + * 鑷姩鍘婚櫎琛ㄥ墠缂锛岄粯璁ゆ槸false + */ + public static boolean autoRemovePre; + + /** + * 琛ㄥ墠缂(绫诲悕涓嶄細鍖呭惈琛ㄥ墠缂) + */ + public static String tablePrefix; + + public static String getAuthor() { + return author; + } + + @Value("${author}") + public void setAuthor(String author) { + GenConfig.author = author; + } + + public static String getPackageName() { + return packageName; + } + + @Value("${packageName}") + public void setPackageName(String packageName) { + GenConfig.packageName = packageName; + } + + public static boolean getAutoRemovePre() { + return autoRemovePre; + } + + @Value("${autoRemovePre}") + public void setAutoRemovePre(boolean autoRemovePre) { + GenConfig.autoRemovePre = autoRemovePre; + } + + public static String getTablePrefix() { + return tablePrefix; + } + + @Value("${tablePrefix}") + public void setTablePrefix(String tablePrefix) { + GenConfig.tablePrefix = tablePrefix; + } +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/controller/GenController.java b/jsowell-generator/src/main/java/com/jsowell/generator/controller/GenController.java new file mode 100644 index 000000000..3283a6ad9 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/controller/GenController.java @@ -0,0 +1,194 @@ +package com.jsowell.generator.controller; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.core.text.Convert; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.generator.domain.GenTable; +import com.jsowell.generator.domain.GenTableColumn; +import com.jsowell.generator.service.IGenTableColumnService; +import com.jsowell.generator.service.IGenTableService; +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 浠g爜鐢熸垚 鎿嶄綔澶勭悊 + * + * @author jsowell + */ +@RestController +@RequestMapping("/tool/gen") +public class GenController extends BaseController { + @Autowired + private IGenTableService genTableService; + + @Autowired + private IGenTableColumnService genTableColumnService; + + /** + * 鏌ヨ浠g爜鐢熸垚鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:list')") + @GetMapping("/list") + public TableDataInfo genList(GenTable genTable) { + startPage(); + List list = genTableService.selectGenTableList(genTable); + return getDataTable(list); + } + + /** + * 淇敼浠g爜鐢熸垚涓氬姟 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:query')") + @GetMapping(value = "/{tableId}") + public AjaxResult getInfo(@PathVariable Long tableId) { + GenTable table = genTableService.selectGenTableById(tableId); + List tables = genTableService.selectGenTableAll(); + List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); + Map map = new HashMap(); + map.put("info", table); + map.put("rows", list); + map.put("tables", tables); + return AjaxResult.success(map); + } + + /** + * 鏌ヨ鏁版嵁搴撳垪琛 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:list')") + @GetMapping("/db/list") + public TableDataInfo dataList(GenTable genTable) { + startPage(); + List list = genTableService.selectDbTableList(genTable); + return getDataTable(list); + } + + /** + * 鏌ヨ鏁版嵁琛ㄥ瓧娈靛垪琛 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:list')") + @GetMapping(value = "/column/{tableId}") + public TableDataInfo columnList(Long tableId) { + TableDataInfo dataInfo = new TableDataInfo(); + List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); + dataInfo.setRows(list); + dataInfo.setTotal(list.size()); + return dataInfo; + } + + /** + * 瀵煎叆琛ㄧ粨鏋勶紙淇濆瓨锛 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:import')") + @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.IMPORT) + @PostMapping("/importTable") + public AjaxResult importTableSave(String tables) { + String[] tableNames = Convert.toStrArray(tables); + // 鏌ヨ琛ㄤ俊鎭 + List tableList = genTableService.selectDbTableListByNames(tableNames); + genTableService.importGenTable(tableList); + return AjaxResult.success(); + } + + /** + * 淇敼淇濆瓨浠g爜鐢熸垚涓氬姟 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:edit')") + @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult editSave(@Validated @RequestBody GenTable genTable) { + genTableService.validateEdit(genTable); + genTableService.updateGenTable(genTable); + return AjaxResult.success(); + } + + /** + * 鍒犻櫎浠g爜鐢熸垚 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:remove')") + @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.DELETE) + @DeleteMapping("/{tableIds}") + public AjaxResult remove(@PathVariable Long[] tableIds) { + genTableService.deleteGenTableByIds(tableIds); + return AjaxResult.success(); + } + + /** + * 棰勮浠g爜 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:preview')") + @GetMapping("/preview/{tableId}") + public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException { + Map dataMap = genTableService.previewCode(tableId); + return AjaxResult.success(dataMap); + } + + /** + * 鐢熸垚浠g爜锛堜笅杞芥柟寮忥級 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:code')") + @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.GENCODE) + @GetMapping("/download/{tableName}") + public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { + byte[] data = genTableService.downloadCode(tableName); + genCode(response, data); + } + + /** + * 鐢熸垚浠g爜锛堣嚜瀹氫箟璺緞锛 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:code')") + @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.GENCODE) + @GetMapping("/genCode/{tableName}") + public AjaxResult genCode(@PathVariable("tableName") String tableName) { + genTableService.generatorCode(tableName); + return AjaxResult.success(); + } + + /** + * 鍚屾鏁版嵁搴 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:edit')") + @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.UPDATE) + @GetMapping("/synchDb/{tableName}") + public AjaxResult synchDb(@PathVariable("tableName") String tableName) { + genTableService.synchDb(tableName); + return AjaxResult.success(); + } + + /** + * 鎵归噺鐢熸垚浠g爜 + */ + @PreAuthorize("@ss.hasPermi('tool:gen:code')") + @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.GENCODE) + @GetMapping("/batchGenCode") + public void batchGenCode(HttpServletResponse response, String tables) throws IOException { + String[] tableNames = Convert.toStrArray(tables); + byte[] data = genTableService.downloadCode(tableNames); + genCode(response, data); + } + + /** + * 鐢熸垚zip鏂囦欢 + */ + private void genCode(HttpServletResponse response, byte[] data) throws IOException { + response.reset(); + response.addHeader("Access-Control-Allow-Origin", "*"); + response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); + response.setHeader("Content-Disposition", "attachment; filename=\"jsowell.zip\""); + response.addHeader("Content-Length", "" + data.length); + response.setContentType("application/octet-stream; charset=UTF-8"); + IOUtils.write(data, response.getOutputStream()); + } +} \ No newline at end of file diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/domain/GenTable.java b/jsowell-generator/src/main/java/com/jsowell/generator/domain/GenTable.java new file mode 100644 index 000000000..641caefb9 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/domain/GenTable.java @@ -0,0 +1,363 @@ +package com.jsowell.generator.domain; + +import com.jsowell.common.constant.GenConstants; +import com.jsowell.common.core.domain.BaseEntity; +import com.jsowell.common.util.StringUtils; +import org.apache.commons.lang3.ArrayUtils; + +import javax.validation.Valid; +import javax.validation.constraints.NotBlank; +import java.util.List; + +/** + * 涓氬姟琛 gen_table + * + * @author jsowell + */ +public class GenTable extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 缂栧彿 + */ + private Long tableId; + + /** + * 琛ㄥ悕绉 + */ + @NotBlank(message = "琛ㄥ悕绉颁笉鑳戒负绌") + private String tableName; + + /** + * 琛ㄦ弿杩 + */ + @NotBlank(message = "琛ㄦ弿杩颁笉鑳戒负绌") + private String tableComment; + + /** + * 鍏宠仈鐖惰〃鐨勮〃鍚 + */ + private String subTableName; + + /** + * 鏈〃鍏宠仈鐖惰〃鐨勫閿悕 + */ + private String subTableFkName; + + /** + * 瀹炰綋绫诲悕绉(棣栧瓧姣嶅ぇ鍐) + */ + @NotBlank(message = "瀹炰綋绫诲悕绉颁笉鑳戒负绌") + private String className; + + /** + * 浣跨敤鐨勬ā鏉匡紙crud鍗曡〃鎿嶄綔 tree鏍戣〃鎿嶄綔 sub涓诲瓙琛ㄦ搷浣滐級 + */ + private String tplCategory; + + /** + * 鐢熸垚鍖呰矾寰 + */ + @NotBlank(message = "鐢熸垚鍖呰矾寰勪笉鑳戒负绌") + private String packageName; + + /** + * 鐢熸垚妯″潡鍚 + */ + @NotBlank(message = "鐢熸垚妯″潡鍚嶄笉鑳戒负绌") + private String moduleName; + + /** + * 鐢熸垚涓氬姟鍚 + */ + @NotBlank(message = "鐢熸垚涓氬姟鍚嶄笉鑳戒负绌") + private String businessName; + + /** + * 鐢熸垚鍔熻兘鍚 + */ + @NotBlank(message = "鐢熸垚鍔熻兘鍚嶄笉鑳戒负绌") + private String functionName; + + /** + * 鐢熸垚浣滆 + */ + @NotBlank(message = "浣滆呬笉鑳戒负绌") + private String functionAuthor; + + /** + * 鐢熸垚浠g爜鏂瑰紡锛0zip鍘嬬缉鍖 1鑷畾涔夎矾寰勶級 + */ + private String genType; + + /** + * 鐢熸垚璺緞锛堜笉濉粯璁ら」鐩矾寰勶級 + */ + private String genPath; + + /** + * 涓婚敭淇℃伅 + */ + private GenTableColumn pkColumn; + + /** + * 瀛愯〃淇℃伅 + */ + private GenTable subTable; + + /** + * 琛ㄥ垪淇℃伅 + */ + @Valid + private List columns; + + /** + * 鍏跺畠鐢熸垚閫夐」 + */ + private String options; + + /** + * 鏍戠紪鐮佸瓧娈 + */ + private String treeCode; + + /** + * 鏍戠埗缂栫爜瀛楁 + */ + private String treeParentCode; + + /** + * 鏍戝悕绉板瓧娈 + */ + private String treeName; + + /** + * 涓婄骇鑿滃崟ID瀛楁 + */ + private String parentMenuId; + + /** + * 涓婄骇鑿滃崟鍚嶇О瀛楁 + */ + private String parentMenuName; + + public Long getTableId() { + return tableId; + } + + public void setTableId(Long tableId) { + this.tableId = tableId; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public String getTableComment() { + return tableComment; + } + + public void setTableComment(String tableComment) { + this.tableComment = tableComment; + } + + public String getSubTableName() { + return subTableName; + } + + public void setSubTableName(String subTableName) { + this.subTableName = subTableName; + } + + public String getSubTableFkName() { + return subTableFkName; + } + + public void setSubTableFkName(String subTableFkName) { + this.subTableFkName = subTableFkName; + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getTplCategory() { + return tplCategory; + } + + public void setTplCategory(String tplCategory) { + this.tplCategory = tplCategory; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getModuleName() { + return moduleName; + } + + public void setModuleName(String moduleName) { + this.moduleName = moduleName; + } + + public String getBusinessName() { + return businessName; + } + + public void setBusinessName(String businessName) { + this.businessName = businessName; + } + + public String getFunctionName() { + return functionName; + } + + public void setFunctionName(String functionName) { + this.functionName = functionName; + } + + public String getFunctionAuthor() { + return functionAuthor; + } + + public void setFunctionAuthor(String functionAuthor) { + this.functionAuthor = functionAuthor; + } + + public String getGenType() { + return genType; + } + + public void setGenType(String genType) { + this.genType = genType; + } + + public String getGenPath() { + return genPath; + } + + public void setGenPath(String genPath) { + this.genPath = genPath; + } + + public GenTableColumn getPkColumn() { + return pkColumn; + } + + public void setPkColumn(GenTableColumn pkColumn) { + this.pkColumn = pkColumn; + } + + public GenTable getSubTable() { + return subTable; + } + + public void setSubTable(GenTable subTable) { + this.subTable = subTable; + } + + public List getColumns() { + return columns; + } + + public void setColumns(List columns) { + this.columns = columns; + } + + public String getOptions() { + return options; + } + + public void setOptions(String options) { + this.options = options; + } + + public String getTreeCode() { + return treeCode; + } + + public void setTreeCode(String treeCode) { + this.treeCode = treeCode; + } + + public String getTreeParentCode() { + return treeParentCode; + } + + public void setTreeParentCode(String treeParentCode) { + this.treeParentCode = treeParentCode; + } + + public String getTreeName() { + return treeName; + } + + public void setTreeName(String treeName) { + this.treeName = treeName; + } + + public String getParentMenuId() { + return parentMenuId; + } + + public void setParentMenuId(String parentMenuId) { + this.parentMenuId = parentMenuId; + } + + public String getParentMenuName() { + return parentMenuName; + } + + public void setParentMenuName(String parentMenuName) { + this.parentMenuName = parentMenuName; + } + + public boolean isSub() { + return isSub(this.tplCategory); + } + + public static boolean isSub(String tplCategory) { + return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory); + } + + public boolean isTree() { + return isTree(this.tplCategory); + } + + public static boolean isTree(String tplCategory) { + return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); + } + + public boolean isCrud() { + return isCrud(this.tplCategory); + } + + public static boolean isCrud(String tplCategory) { + return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); + } + + public boolean isSuperColumn(String javaField) { + return isSuperColumn(this.tplCategory, javaField); + } + + public static boolean isSuperColumn(String tplCategory, String javaField) { + if (isTree(tplCategory)) { + return StringUtils.equalsAnyIgnoreCase(javaField, + ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); + } + return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); + } +} \ No newline at end of file diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/domain/GenTableColumn.java b/jsowell-generator/src/main/java/com/jsowell/generator/domain/GenTableColumn.java new file mode 100644 index 000000000..0f50c274b --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/domain/GenTableColumn.java @@ -0,0 +1,348 @@ +package com.jsowell.generator.domain; + +import com.jsowell.common.core.domain.BaseEntity; +import com.jsowell.common.util.StringUtils; + +import javax.validation.constraints.NotBlank; + +/** + * 浠g爜鐢熸垚涓氬姟瀛楁琛 gen_table_column + * + * @author jsowell + */ +public class GenTableColumn extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 缂栧彿 + */ + private Long columnId; + + /** + * 褰掑睘琛ㄧ紪鍙 + */ + private Long tableId; + + /** + * 鍒楀悕绉 + */ + private String columnName; + + /** + * 鍒楁弿杩 + */ + private String columnComment; + + /** + * 鍒楃被鍨 + */ + private String columnType; + + /** + * JAVA绫诲瀷 + */ + private String javaType; + + /** + * JAVA瀛楁鍚 + */ + @NotBlank(message = "Java灞炴т笉鑳戒负绌") + private String javaField; + + /** + * 鏄惁涓婚敭锛1鏄級 + */ + private String isPk; + + /** + * 鏄惁鑷锛1鏄級 + */ + private String isIncrement; + + /** + * 鏄惁蹇呭~锛1鏄級 + */ + private String isRequired; + + /** + * 鏄惁涓烘彃鍏ュ瓧娈碉紙1鏄級 + */ + private String isInsert; + + /** + * 鏄惁缂栬緫瀛楁锛1鏄級 + */ + private String isEdit; + + /** + * 鏄惁鍒楄〃瀛楁锛1鏄級 + */ + private String isList; + + /** + * 鏄惁鏌ヨ瀛楁锛1鏄級 + */ + private String isQuery; + + /** + * 鏌ヨ鏂瑰紡锛圗Q绛変簬銆丯E涓嶇瓑浜庛丟T澶т簬銆丩T灏忎簬銆丩IKE妯$硦銆丅ETWEEN鑼冨洿锛 + */ + private String queryType; + + /** + * 鏄剧ず绫诲瀷锛坕nput鏂囨湰妗嗐乼extarea鏂囨湰鍩熴乻elect涓嬫媺妗嗐乧heckbox澶嶉夋銆乺adio鍗曢夋銆乨atetime鏃ユ湡鎺т欢銆乮mage鍥剧墖涓婁紶鎺т欢銆乽pload鏂囦欢涓婁紶鎺т欢銆乪ditor瀵屾枃鏈帶浠讹級 + */ + private String htmlType; + + /** + * 瀛楀吀绫诲瀷 + */ + private String dictType; + + /** + * 鎺掑簭 + */ + private Integer sort; + + public void setColumnId(Long columnId) { + this.columnId = columnId; + } + + public Long getColumnId() { + return columnId; + } + + public void setTableId(Long tableId) { + this.tableId = tableId; + } + + public Long getTableId() { + return tableId; + } + + public void setColumnName(String columnName) { + this.columnName = columnName; + } + + public String getColumnName() { + return columnName; + } + + public void setColumnComment(String columnComment) { + this.columnComment = columnComment; + } + + public String getColumnComment() { + return columnComment; + } + + public void setColumnType(String columnType) { + this.columnType = columnType; + } + + public String getColumnType() { + return columnType; + } + + public void setJavaType(String javaType) { + this.javaType = javaType; + } + + public String getJavaType() { + return javaType; + } + + public void setJavaField(String javaField) { + this.javaField = javaField; + } + + public String getJavaField() { + return javaField; + } + + public String getCapJavaField() { + return StringUtils.capitalize(javaField); + } + + public void setIsPk(String isPk) { + this.isPk = isPk; + } + + public String getIsPk() { + return isPk; + } + + public boolean isPk() { + return isPk(this.isPk); + } + + public boolean isPk(String isPk) { + return isPk != null && StringUtils.equals("1", isPk); + } + + public String getIsIncrement() { + return isIncrement; + } + + public void setIsIncrement(String isIncrement) { + this.isIncrement = isIncrement; + } + + public boolean isIncrement() { + return isIncrement(this.isIncrement); + } + + public boolean isIncrement(String isIncrement) { + return isIncrement != null && StringUtils.equals("1", isIncrement); + } + + public void setIsRequired(String isRequired) { + this.isRequired = isRequired; + } + + public String getIsRequired() { + return isRequired; + } + + public boolean isRequired() { + return isRequired(this.isRequired); + } + + public boolean isRequired(String isRequired) { + return isRequired != null && StringUtils.equals("1", isRequired); + } + + public void setIsInsert(String isInsert) { + this.isInsert = isInsert; + } + + public String getIsInsert() { + return isInsert; + } + + public boolean isInsert() { + return isInsert(this.isInsert); + } + + public boolean isInsert(String isInsert) { + return isInsert != null && StringUtils.equals("1", isInsert); + } + + public void setIsEdit(String isEdit) { + this.isEdit = isEdit; + } + + public String getIsEdit() { + return isEdit; + } + + public boolean isEdit() { + return isInsert(this.isEdit); + } + + public boolean isEdit(String isEdit) { + return isEdit != null && StringUtils.equals("1", isEdit); + } + + public void setIsList(String isList) { + this.isList = isList; + } + + public String getIsList() { + return isList; + } + + public boolean isList() { + return isList(this.isList); + } + + public boolean isList(String isList) { + return isList != null && StringUtils.equals("1", isList); + } + + public void setIsQuery(String isQuery) { + this.isQuery = isQuery; + } + + public String getIsQuery() { + return isQuery; + } + + public boolean isQuery() { + return isQuery(this.isQuery); + } + + public boolean isQuery(String isQuery) { + return isQuery != null && StringUtils.equals("1", isQuery); + } + + public void setQueryType(String queryType) { + this.queryType = queryType; + } + + public String getQueryType() { + return queryType; + } + + public String getHtmlType() { + return htmlType; + } + + public void setHtmlType(String htmlType) { + this.htmlType = htmlType; + } + + public void setDictType(String dictType) { + this.dictType = dictType; + } + + public String getDictType() { + return dictType; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + public Integer getSort() { + return sort; + } + + public boolean isSuperColumn() { + return isSuperColumn(this.javaField); + } + + public static boolean isSuperColumn(String javaField) { + return StringUtils.equalsAnyIgnoreCase(javaField, + // BaseEntity + "createBy", "createTime", "updateBy", "updateTime", "remark", + // TreeEntity + "parentName", "parentId", "orderNum", "ancestors"); + } + + public boolean isUsableColumn() { + return isUsableColumn(javaField); + } + + public static boolean isUsableColumn(String javaField) { + // isSuperColumn()涓殑鍚嶅崟鐢ㄤ簬閬垮厤鐢熸垚澶氫綑Domain灞炴э紝鑻ユ煇浜涘睘鎬у湪鐢熸垚椤甸潰鏃堕渶瑕佺敤鍒颁笉鑳藉拷鐣ワ紝鍒欐斁鍦ㄦ澶勭櫧鍚嶅崟 + return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); + } + + public String readConverterExp() { + String remarks = StringUtils.substringBetween(this.columnComment, "锛", "锛"); + StringBuffer sb = new StringBuffer(); + if (StringUtils.isNotEmpty(remarks)) { + for (String value : remarks.split(" ")) { + if (StringUtils.isNotEmpty(value)) { + Object startStr = value.subSequence(0, 1); + String endStr = value.substring(1); + sb.append("").append(startStr).append("=").append(endStr).append(","); + } + } + return sb.deleteCharAt(sb.length() - 1).toString(); + } else { + return this.columnComment; + } + } +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/mapper/GenTableColumnMapper.java b/jsowell-generator/src/main/java/com/jsowell/generator/mapper/GenTableColumnMapper.java new file mode 100644 index 000000000..120697836 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/mapper/GenTableColumnMapper.java @@ -0,0 +1,62 @@ +package com.jsowell.generator.mapper; + +import com.jsowell.generator.domain.GenTableColumn; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 涓氬姟瀛楁 鏁版嵁灞 + * + * @author jsowell + */ +@Repository +public interface GenTableColumnMapper { + /** + * 鏍规嵁琛ㄥ悕绉版煡璇㈠垪淇℃伅 + * + * @param tableName 琛ㄥ悕绉 + * @return 鍒椾俊鎭 + */ + public List selectDbTableColumnsByName(String tableName); + + /** + * 鏌ヨ涓氬姟瀛楁鍒楄〃 + * + * @param tableId 涓氬姟瀛楁缂栧彿 + * @return 涓氬姟瀛楁闆嗗悎 + */ + public List selectGenTableColumnListByTableId(Long tableId); + + /** + * 鏂板涓氬姟瀛楁 + * + * @param genTableColumn 涓氬姟瀛楁淇℃伅 + * @return 缁撴灉 + */ + public int insertGenTableColumn(GenTableColumn genTableColumn); + + /** + * 淇敼涓氬姟瀛楁 + * + * @param genTableColumn 涓氬姟瀛楁淇℃伅 + * @return 缁撴灉 + */ + public int updateGenTableColumn(GenTableColumn genTableColumn); + + /** + * 鍒犻櫎涓氬姟瀛楁 + * + * @param genTableColumns 鍒楁暟鎹 + * @return 缁撴灉 + */ + public int deleteGenTableColumns(List genTableColumns); + + /** + * 鎵归噺鍒犻櫎涓氬姟瀛楁 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteGenTableColumnByIds(Long[] ids); +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/mapper/GenTableMapper.java b/jsowell-generator/src/main/java/com/jsowell/generator/mapper/GenTableMapper.java new file mode 100644 index 000000000..049279544 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/mapper/GenTableMapper.java @@ -0,0 +1,85 @@ +package com.jsowell.generator.mapper; + +import com.jsowell.generator.domain.GenTable; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 涓氬姟 鏁版嵁灞 + * + * @author jsowell + */ +@Repository +public interface GenTableMapper { + /** + * 鏌ヨ涓氬姟鍒楄〃 + * + * @param genTable 涓氬姟淇℃伅 + * @return 涓氬姟闆嗗悎 + */ + public List selectGenTableList(GenTable genTable); + + /** + * 鏌ヨ鎹簱鍒楄〃 + * + * @param genTable 涓氬姟淇℃伅 + * @return 鏁版嵁搴撹〃闆嗗悎 + */ + public List selectDbTableList(GenTable genTable); + + /** + * 鏌ヨ鎹簱鍒楄〃 + * + * @param tableNames 琛ㄥ悕绉扮粍 + * @return 鏁版嵁搴撹〃闆嗗悎 + */ + public List selectDbTableListByNames(String[] tableNames); + + /** + * 鏌ヨ鎵鏈夎〃淇℃伅 + * + * @return 琛ㄤ俊鎭泦鍚 + */ + public List selectGenTableAll(); + + /** + * 鏌ヨ琛↖D涓氬姟淇℃伅 + * + * @param id 涓氬姟ID + * @return 涓氬姟淇℃伅 + */ + public GenTable selectGenTableById(Long id); + + /** + * 鏌ヨ琛ㄥ悕绉颁笟鍔′俊鎭 + * + * @param tableName 琛ㄥ悕绉 + * @return 涓氬姟淇℃伅 + */ + public GenTable selectGenTableByName(String tableName); + + /** + * 鏂板涓氬姟 + * + * @param genTable 涓氬姟淇℃伅 + * @return 缁撴灉 + */ + public int insertGenTable(GenTable genTable); + + /** + * 淇敼涓氬姟 + * + * @param genTable 涓氬姟淇℃伅 + * @return 缁撴灉 + */ + public int updateGenTable(GenTable genTable); + + /** + * 鎵归噺鍒犻櫎涓氬姟 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteGenTableByIds(Long[] ids); +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/service/IGenTableColumnService.java b/jsowell-generator/src/main/java/com/jsowell/generator/service/IGenTableColumnService.java new file mode 100644 index 000000000..1e1dc3553 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/service/IGenTableColumnService.java @@ -0,0 +1,44 @@ +package com.jsowell.generator.service; + +import com.jsowell.generator.domain.GenTableColumn; + +import java.util.List; + +/** + * 涓氬姟瀛楁 鏈嶅姟灞 + * + * @author jsowell + */ +public interface IGenTableColumnService { + /** + * 鏌ヨ涓氬姟瀛楁鍒楄〃 + * + * @param tableId 涓氬姟瀛楁缂栧彿 + * @return 涓氬姟瀛楁闆嗗悎 + */ + public List selectGenTableColumnListByTableId(Long tableId); + + /** + * 鏂板涓氬姟瀛楁 + * + * @param genTableColumn 涓氬姟瀛楁淇℃伅 + * @return 缁撴灉 + */ + public int insertGenTableColumn(GenTableColumn genTableColumn); + + /** + * 淇敼涓氬姟瀛楁 + * + * @param genTableColumn 涓氬姟瀛楁淇℃伅 + * @return 缁撴灉 + */ + public int updateGenTableColumn(GenTableColumn genTableColumn); + + /** + * 鍒犻櫎涓氬姟瀛楁淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteGenTableColumnByIds(String ids); +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/service/IGenTableService.java b/jsowell-generator/src/main/java/com/jsowell/generator/service/IGenTableService.java new file mode 100644 index 000000000..69ae9d57e --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/service/IGenTableService.java @@ -0,0 +1,121 @@ +package com.jsowell.generator.service; + +import com.jsowell.generator.domain.GenTable; + +import java.util.List; +import java.util.Map; + +/** + * 涓氬姟 鏈嶅姟灞 + * + * @author jsowell + */ +public interface IGenTableService { + /** + * 鏌ヨ涓氬姟鍒楄〃 + * + * @param genTable 涓氬姟淇℃伅 + * @return 涓氬姟闆嗗悎 + */ + public List selectGenTableList(GenTable genTable); + + /** + * 鏌ヨ鎹簱鍒楄〃 + * + * @param genTable 涓氬姟淇℃伅 + * @return 鏁版嵁搴撹〃闆嗗悎 + */ + public List selectDbTableList(GenTable genTable); + + /** + * 鏌ヨ鎹簱鍒楄〃 + * + * @param tableNames 琛ㄥ悕绉扮粍 + * @return 鏁版嵁搴撹〃闆嗗悎 + */ + public List selectDbTableListByNames(String[] tableNames); + + /** + * 鏌ヨ鎵鏈夎〃淇℃伅 + * + * @return 琛ㄤ俊鎭泦鍚 + */ + public List selectGenTableAll(); + + /** + * 鏌ヨ涓氬姟淇℃伅 + * + * @param id 涓氬姟ID + * @return 涓氬姟淇℃伅 + */ + public GenTable selectGenTableById(Long id); + + /** + * 淇敼涓氬姟 + * + * @param genTable 涓氬姟淇℃伅 + * @return 缁撴灉 + */ + public void updateGenTable(GenTable genTable); + + /** + * 鍒犻櫎涓氬姟淇℃伅 + * + * @param tableIds 闇瑕佸垹闄ょ殑琛ㄦ暟鎹甀D + * @return 缁撴灉 + */ + public void deleteGenTableByIds(Long[] tableIds); + + /** + * 瀵煎叆琛ㄧ粨鏋 + * + * @param tableList 瀵煎叆琛ㄥ垪琛 + */ + public void importGenTable(List tableList); + + /** + * 棰勮浠g爜 + * + * @param tableId 琛ㄧ紪鍙 + * @return 棰勮鏁版嵁鍒楄〃 + */ + public Map previewCode(Long tableId); + + /** + * 鐢熸垚浠g爜锛堜笅杞芥柟寮忥級 + * + * @param tableName 琛ㄥ悕绉 + * @return 鏁版嵁 + */ + public byte[] downloadCode(String tableName); + + /** + * 鐢熸垚浠g爜锛堣嚜瀹氫箟璺緞锛 + * + * @param tableName 琛ㄥ悕绉 + * @return 鏁版嵁 + */ + public void generatorCode(String tableName); + + /** + * 鍚屾鏁版嵁搴 + * + * @param tableName 琛ㄥ悕绉 + */ + public void synchDb(String tableName); + + /** + * 鎵归噺鐢熸垚浠g爜锛堜笅杞芥柟寮忥級 + * + * @param tableNames 琛ㄦ暟缁 + * @return 鏁版嵁 + */ + public byte[] downloadCode(String[] tableNames); + + /** + * 淇敼淇濆瓨鍙傛暟鏍¢獙 + * + * @param genTable 涓氬姟淇℃伅 + */ + public void validateEdit(GenTable genTable); +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/service/impl/GenTableColumnServiceImpl.java b/jsowell-generator/src/main/java/com/jsowell/generator/service/impl/GenTableColumnServiceImpl.java new file mode 100644 index 000000000..96e480362 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/service/impl/GenTableColumnServiceImpl.java @@ -0,0 +1,65 @@ +package com.jsowell.generator.service.impl; + +import com.jsowell.common.core.text.Convert; +import com.jsowell.generator.domain.GenTableColumn; +import com.jsowell.generator.mapper.GenTableColumnMapper; +import com.jsowell.generator.service.IGenTableColumnService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 涓氬姟瀛楁 鏈嶅姟灞傚疄鐜 + * + * @author jsowell + */ +@Service +public class GenTableColumnServiceImpl implements IGenTableColumnService { + @Autowired + private GenTableColumnMapper genTableColumnMapper; + + /** + * 鏌ヨ涓氬姟瀛楁鍒楄〃 + * + * @param tableId 涓氬姟瀛楁缂栧彿 + * @return 涓氬姟瀛楁闆嗗悎 + */ + @Override + public List selectGenTableColumnListByTableId(Long tableId) { + return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); + } + + /** + * 鏂板涓氬姟瀛楁 + * + * @param genTableColumn 涓氬姟瀛楁淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertGenTableColumn(GenTableColumn genTableColumn) { + return genTableColumnMapper.insertGenTableColumn(genTableColumn); + } + + /** + * 淇敼涓氬姟瀛楁 + * + * @param genTableColumn 涓氬姟瀛楁淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateGenTableColumn(GenTableColumn genTableColumn) { + return genTableColumnMapper.updateGenTableColumn(genTableColumn); + } + + /** + * 鍒犻櫎涓氬姟瀛楁瀵硅薄 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + @Override + public int deleteGenTableColumnByIds(String ids) { + return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); + } +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/service/impl/GenTableServiceImpl.java b/jsowell-generator/src/main/java/com/jsowell/generator/service/impl/GenTableServiceImpl.java new file mode 100644 index 000000000..fbb83851b --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/service/impl/GenTableServiceImpl.java @@ -0,0 +1,456 @@ +package com.jsowell.generator.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.constant.GenConstants; +import com.jsowell.common.core.text.CharsetKit; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.generator.domain.GenTable; +import com.jsowell.generator.domain.GenTableColumn; +import com.jsowell.generator.mapper.GenTableColumnMapper; +import com.jsowell.generator.mapper.GenTableMapper; +import com.jsowell.generator.service.IGenTableService; +import com.jsowell.generator.util.GenUtils; +import com.jsowell.generator.util.VelocityInitializer; +import com.jsowell.generator.util.VelocityUtils; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * 涓氬姟 鏈嶅姟灞傚疄鐜 + * + * @author jsowell + */ +@Service +public class GenTableServiceImpl implements IGenTableService { + private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); + + @Autowired + private GenTableMapper genTableMapper; + + @Autowired + private GenTableColumnMapper genTableColumnMapper; + + /** + * 鏌ヨ涓氬姟淇℃伅 + * + * @param id 涓氬姟ID + * @return 涓氬姟淇℃伅 + */ + @Override + public GenTable selectGenTableById(Long id) { + GenTable genTable = genTableMapper.selectGenTableById(id); + setTableFromOptions(genTable); + return genTable; + } + + /** + * 鏌ヨ涓氬姟鍒楄〃 + * + * @param genTable 涓氬姟淇℃伅 + * @return 涓氬姟闆嗗悎 + */ + @Override + public List selectGenTableList(GenTable genTable) { + return genTableMapper.selectGenTableList(genTable); + } + + /** + * 鏌ヨ鎹簱鍒楄〃 + * + * @param genTable 涓氬姟淇℃伅 + * @return 鏁版嵁搴撹〃闆嗗悎 + */ + @Override + public List selectDbTableList(GenTable genTable) { + return genTableMapper.selectDbTableList(genTable); + } + + /** + * 鏌ヨ鎹簱鍒楄〃 + * + * @param tableNames 琛ㄥ悕绉扮粍 + * @return 鏁版嵁搴撹〃闆嗗悎 + */ + @Override + public List selectDbTableListByNames(String[] tableNames) { + return genTableMapper.selectDbTableListByNames(tableNames); + } + + /** + * 鏌ヨ鎵鏈夎〃淇℃伅 + * + * @return 琛ㄤ俊鎭泦鍚 + */ + @Override + public List selectGenTableAll() { + return genTableMapper.selectGenTableAll(); + } + + /** + * 淇敼涓氬姟 + * + * @param genTable 涓氬姟淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public void updateGenTable(GenTable genTable) { + String options = JSON.toJSONString(genTable.getParams()); + genTable.setOptions(options); + int row = genTableMapper.updateGenTable(genTable); + if (row > 0) { + for (GenTableColumn cenTableColumn : genTable.getColumns()) { + genTableColumnMapper.updateGenTableColumn(cenTableColumn); + } + } + } + + /** + * 鍒犻櫎涓氬姟瀵硅薄 + * + * @param tableIds 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + @Override + @Transactional + public void deleteGenTableByIds(Long[] tableIds) { + genTableMapper.deleteGenTableByIds(tableIds); + genTableColumnMapper.deleteGenTableColumnByIds(tableIds); + } + + /** + * 瀵煎叆琛ㄧ粨鏋 + * + * @param tableList 瀵煎叆琛ㄥ垪琛 + */ + @Override + @Transactional + public void importGenTable(List tableList) { + String operName = SecurityUtils.getUsername(); + try { + for (GenTable table : tableList) { + String tableName = table.getTableName(); + GenUtils.initTable(table, operName); + int row = genTableMapper.insertGenTable(table); + if (row > 0) { + // 淇濆瓨鍒椾俊鎭 + List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); + for (GenTableColumn column : genTableColumns) { + GenUtils.initColumnField(column, table); + genTableColumnMapper.insertGenTableColumn(column); + } + } + } + } catch (Exception e) { + throw new ServiceException("瀵煎叆澶辫触锛" + e.getMessage()); + } + } + + /** + * 棰勮浠g爜 + * + * @param tableId 琛ㄧ紪鍙 + * @return 棰勮鏁版嵁鍒楄〃 + */ + @Override + public Map previewCode(Long tableId) { + Map dataMap = new LinkedHashMap<>(); + // 鏌ヨ琛ㄤ俊鎭 + GenTable table = genTableMapper.selectGenTableById(tableId); + // 璁剧疆涓诲瓙琛ㄤ俊鎭 + setSubTable(table); + // 璁剧疆涓婚敭鍒椾俊鎭 + setPkColumn(table); + VelocityInitializer.initVelocity(); + + VelocityContext context = VelocityUtils.prepareContext(table); + + // 鑾峰彇妯℃澘鍒楄〃 + List templates = VelocityUtils.getTemplateList(table.getTplCategory()); + for (String template : templates) { + // 娓叉煋妯℃澘 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, Constants.UTF8); + tpl.merge(context, sw); + dataMap.put(template, sw.toString()); + } + return dataMap; + } + + /** + * 鐢熸垚浠g爜锛堜笅杞芥柟寮忥級 + * + * @param tableName 琛ㄥ悕绉 + * @return 鏁版嵁 + */ + @Override + public byte[] downloadCode(String tableName) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(outputStream); + generatorCode(tableName, zip); + IOUtils.closeQuietly(zip); + return outputStream.toByteArray(); + } + + /** + * 鐢熸垚浠g爜锛堣嚜瀹氫箟璺緞锛 + * + * @param tableName 琛ㄥ悕绉 + */ + @Override + public void generatorCode(String tableName) { + // 鏌ヨ琛ㄤ俊鎭 + GenTable table = genTableMapper.selectGenTableByName(tableName); + // 璁剧疆涓诲瓙琛ㄤ俊鎭 + setSubTable(table); + // 璁剧疆涓婚敭鍒椾俊鎭 + setPkColumn(table); + + VelocityInitializer.initVelocity(); + + VelocityContext context = VelocityUtils.prepareContext(table); + + // 鑾峰彇妯℃澘鍒楄〃 + List templates = VelocityUtils.getTemplateList(table.getTplCategory()); + for (String template : templates) { + if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) { + // 娓叉煋妯℃澘 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, Constants.UTF8); + tpl.merge(context, sw); + try { + String path = getGenPath(table, template); + FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); + } catch (IOException e) { + throw new ServiceException("娓叉煋妯℃澘澶辫触锛岃〃鍚嶏細" + table.getTableName()); + } + } + } + } + + /** + * 鍚屾鏁版嵁搴 + * + * @param tableName 琛ㄥ悕绉 + */ + @Override + @Transactional + public void synchDb(String tableName) { + GenTable table = genTableMapper.selectGenTableByName(tableName); + List tableColumns = table.getColumns(); + Map tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity())); + + List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); + if (StringUtils.isEmpty(dbTableColumns)) { + throw new ServiceException("鍚屾鏁版嵁澶辫触锛屽師琛ㄧ粨鏋勪笉瀛樺湪"); + } + List dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); + + dbTableColumns.forEach(column -> { + GenUtils.initColumnField(column, table); + if (tableColumnMap.containsKey(column.getColumnName())) { + GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName()); + column.setColumnId(prevColumn.getColumnId()); + if (column.isList()) { + // 濡傛灉鏄垪琛紝缁х画淇濈暀鏌ヨ鏂瑰紡/瀛楀吀绫诲瀷閫夐」 + column.setDictType(prevColumn.getDictType()); + column.setQueryType(prevColumn.getQueryType()); + } + if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() + && (column.isInsert() || column.isEdit()) + && ((column.isUsableColumn()) || (!column.isSuperColumn()))) { + // 濡傛灉鏄(鏂板/淇敼&闈炰富閿/闈炲拷鐣ュ強鐖跺睘鎬)锛岀户缁繚鐣欏繀濉/鏄剧ず绫诲瀷閫夐」 + column.setIsRequired(prevColumn.getIsRequired()); + column.setHtmlType(prevColumn.getHtmlType()); + } + genTableColumnMapper.updateGenTableColumn(column); + } else { + genTableColumnMapper.insertGenTableColumn(column); + } + }); + + List delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); + if (StringUtils.isNotEmpty(delColumns)) { + genTableColumnMapper.deleteGenTableColumns(delColumns); + } + } + + /** + * 鎵归噺鐢熸垚浠g爜锛堜笅杞芥柟寮忥級 + * + * @param tableNames 琛ㄦ暟缁 + * @return 鏁版嵁 + */ + @Override + public byte[] downloadCode(String[] tableNames) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(outputStream); + for (String tableName : tableNames) { + generatorCode(tableName, zip); + } + IOUtils.closeQuietly(zip); + return outputStream.toByteArray(); + } + + /** + * 鏌ヨ琛ㄤ俊鎭苟鐢熸垚浠g爜 + */ + private void generatorCode(String tableName, ZipOutputStream zip) { + // 鏌ヨ琛ㄤ俊鎭 + GenTable table = genTableMapper.selectGenTableByName(tableName); + // 璁剧疆涓诲瓙琛ㄤ俊鎭 + setSubTable(table); + // 璁剧疆涓婚敭鍒椾俊鎭 + setPkColumn(table); + + VelocityInitializer.initVelocity(); + + VelocityContext context = VelocityUtils.prepareContext(table); + + // 鑾峰彇妯℃澘鍒楄〃 + List templates = VelocityUtils.getTemplateList(table.getTplCategory()); + for (String template : templates) { + // 娓叉煋妯℃澘 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, Constants.UTF8); + tpl.merge(context, sw); + try { + // 娣诲姞鍒皕ip + zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); + IOUtils.write(sw.toString(), zip, Constants.UTF8); + IOUtils.closeQuietly(sw); + zip.flush(); + zip.closeEntry(); + } catch (IOException e) { + log.error("娓叉煋妯℃澘澶辫触锛岃〃鍚嶏細" + table.getTableName(), e); + } + } + } + + /** + * 淇敼淇濆瓨鍙傛暟鏍¢獙 + * + * @param genTable 涓氬姟淇℃伅 + */ + @Override + public void validateEdit(GenTable genTable) { + if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { + String options = JSON.toJSONString(genTable.getParams()); + JSONObject paramsObj = JSON.parseObject(options); + if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { + throw new ServiceException("鏍戠紪鐮佸瓧娈典笉鑳戒负绌"); + } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { + throw new ServiceException("鏍戠埗缂栫爜瀛楁涓嶈兘涓虹┖"); + } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { + throw new ServiceException("鏍戝悕绉板瓧娈典笉鑳戒负绌"); + } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { + if (StringUtils.isEmpty(genTable.getSubTableName())) { + throw new ServiceException("鍏宠仈瀛愯〃鐨勮〃鍚嶄笉鑳戒负绌"); + } else if (StringUtils.isEmpty(genTable.getSubTableFkName())) { + throw new ServiceException("瀛愯〃鍏宠仈鐨勫閿悕涓嶈兘涓虹┖"); + } + } + } + } + + /** + * 璁剧疆涓婚敭鍒椾俊鎭 + * + * @param table 涓氬姟琛ㄤ俊鎭 + */ + public void setPkColumn(GenTable table) { + for (GenTableColumn column : table.getColumns()) { + if (column.isPk()) { + table.setPkColumn(column); + break; + } + } + if (StringUtils.isNull(table.getPkColumn())) { + table.setPkColumn(table.getColumns().get(0)); + } + if (GenConstants.TPL_SUB.equals(table.getTplCategory())) { + for (GenTableColumn column : table.getSubTable().getColumns()) { + if (column.isPk()) { + table.getSubTable().setPkColumn(column); + break; + } + } + if (StringUtils.isNull(table.getSubTable().getPkColumn())) { + table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); + } + } + } + + /** + * 璁剧疆涓诲瓙琛ㄤ俊鎭 + * + * @param table 涓氬姟琛ㄤ俊鎭 + */ + public void setSubTable(GenTable table) { + String subTableName = table.getSubTableName(); + if (StringUtils.isNotEmpty(subTableName)) { + table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); + } + } + + /** + * 璁剧疆浠g爜鐢熸垚鍏朵粬閫夐」鍊 + * + * @param genTable 璁剧疆鍚庣殑鐢熸垚瀵硅薄 + */ + public void setTableFromOptions(GenTable genTable) { + JSONObject paramsObj = JSON.parseObject(genTable.getOptions()); + if (StringUtils.isNotNull(paramsObj)) { + String treeCode = paramsObj.getString(GenConstants.TREE_CODE); + String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); + String treeName = paramsObj.getString(GenConstants.TREE_NAME); + String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); + String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); + + genTable.setTreeCode(treeCode); + genTable.setTreeParentCode(treeParentCode); + genTable.setTreeName(treeName); + genTable.setParentMenuId(parentMenuId); + genTable.setParentMenuName(parentMenuName); + } + } + + /** + * 鑾峰彇浠g爜鐢熸垚鍦板潃 + * + * @param table 涓氬姟琛ㄤ俊鎭 + * @param template 妯℃澘鏂囦欢璺緞 + * @return 鐢熸垚鍦板潃 + */ + public static String getGenPath(GenTable table, String template) { + String genPath = table.getGenPath(); + if (StringUtils.equals(genPath, "/")) { + return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); + } + return genPath + File.separator + VelocityUtils.getFileName(template, table); + } +} \ No newline at end of file diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/util/GenUtils.java b/jsowell-generator/src/main/java/com/jsowell/generator/util/GenUtils.java new file mode 100644 index 000000000..7ed1e8381 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/util/GenUtils.java @@ -0,0 +1,221 @@ +package com.jsowell.generator.util; + +import com.jsowell.common.constant.GenConstants; +import com.jsowell.common.util.StringUtils; +import com.jsowell.generator.config.GenConfig; +import com.jsowell.generator.domain.GenTable; +import com.jsowell.generator.domain.GenTableColumn; +import org.apache.commons.lang3.RegExUtils; + +import java.util.Arrays; + +/** + * 浠g爜鐢熸垚鍣 宸ュ叿绫 + * + * @author jsowell + */ +public class GenUtils { + /** + * 鍒濆鍖栬〃淇℃伅 + */ + public static void initTable(GenTable genTable, String operName) { + genTable.setClassName(convertClassName(genTable.getTableName())); + genTable.setPackageName(GenConfig.getPackageName()); + genTable.setModuleName(getModuleName(GenConfig.getPackageName())); + genTable.setBusinessName(getBusinessName(genTable.getTableName())); + genTable.setFunctionName(replaceText(genTable.getTableComment())); + genTable.setFunctionAuthor(GenConfig.getAuthor()); + genTable.setCreateBy(operName); + } + + /** + * 鍒濆鍖栧垪灞炴у瓧娈 + */ + public static void initColumnField(GenTableColumn column, GenTable table) { + String dataType = getDbType(column.getColumnType()); + String columnName = column.getColumnName(); + column.setTableId(table.getTableId()); + column.setCreateBy(table.getCreateBy()); + // 璁剧疆java瀛楁鍚 + column.setJavaField(StringUtils.toCamelCase(columnName)); + // 璁剧疆榛樿绫诲瀷 + column.setJavaType(GenConstants.TYPE_STRING); + column.setQueryType(GenConstants.QUERY_EQ); + + if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) { + // 瀛楃涓查暱搴﹁秴杩500璁剧疆涓烘枃鏈煙 + Integer columnLength = getColumnLength(column.getColumnType()); + String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; + column.setHtmlType(htmlType); + } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) { + column.setJavaType(GenConstants.TYPE_DATE); + column.setHtmlType(GenConstants.HTML_DATETIME); + } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) { + column.setHtmlType(GenConstants.HTML_INPUT); + + // 濡傛灉鏄诞鐐瑰瀷 缁熶竴鐢˙igDecimal + String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); + if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) { + column.setJavaType(GenConstants.TYPE_BIGDECIMAL); + } + // 濡傛灉鏄暣褰 + else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) { + column.setJavaType(GenConstants.TYPE_INTEGER); + } + // 闀挎暣褰 + else { + column.setJavaType(GenConstants.TYPE_LONG); + } + } + + // 鎻掑叆瀛楁锛堥粯璁ゆ墍鏈夊瓧娈甸兘闇瑕佹彃鍏ワ級 + column.setIsInsert(GenConstants.REQUIRE); + + // 缂栬緫瀛楁 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) { + column.setIsEdit(GenConstants.REQUIRE); + } + // 鍒楄〃瀛楁 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) { + column.setIsList(GenConstants.REQUIRE); + } + // 鏌ヨ瀛楁 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) { + column.setIsQuery(GenConstants.REQUIRE); + } + + // 鏌ヨ瀛楁绫诲瀷 + if (StringUtils.endsWithIgnoreCase(columnName, "name")) { + column.setQueryType(GenConstants.QUERY_LIKE); + } + // 鐘舵佸瓧娈佃缃崟閫夋 + if (StringUtils.endsWithIgnoreCase(columnName, "status")) { + column.setHtmlType(GenConstants.HTML_RADIO); + } + // 绫诲瀷&鎬у埆瀛楁璁剧疆涓嬫媺妗 + else if (StringUtils.endsWithIgnoreCase(columnName, "type") + || StringUtils.endsWithIgnoreCase(columnName, "sex")) { + column.setHtmlType(GenConstants.HTML_SELECT); + } + // 鍥剧墖瀛楁璁剧疆鍥剧墖涓婁紶鎺т欢 + else if (StringUtils.endsWithIgnoreCase(columnName, "image")) { + column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); + } + // 鏂囦欢瀛楁璁剧疆鏂囦欢涓婁紶鎺т欢 + else if (StringUtils.endsWithIgnoreCase(columnName, "file")) { + column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); + } + // 鍐呭瀛楁璁剧疆瀵屾枃鏈帶浠 + else if (StringUtils.endsWithIgnoreCase(columnName, "content")) { + column.setHtmlType(GenConstants.HTML_EDITOR); + } + } + + /** + * 鏍¢獙鏁扮粍鏄惁鍖呭惈鎸囧畾鍊 + * + * @param arr 鏁扮粍 + * @param targetValue 鍊 + * @return 鏄惁鍖呭惈 + */ + public static boolean arraysContains(String[] arr, String targetValue) { + return Arrays.asList(arr).contains(targetValue); + } + + /** + * 鑾峰彇妯″潡鍚 + * + * @param packageName 鍖呭悕 + * @return 妯″潡鍚 + */ + public static String getModuleName(String packageName) { + int lastIndex = packageName.lastIndexOf("."); + int nameLength = packageName.length(); + return StringUtils.substring(packageName, lastIndex + 1, nameLength); + } + + /** + * 鑾峰彇涓氬姟鍚 + * + * @param tableName 琛ㄥ悕 + * @return 涓氬姟鍚 + */ + public static String getBusinessName(String tableName) { + int lastIndex = tableName.lastIndexOf("_"); + int nameLength = tableName.length(); + return StringUtils.substring(tableName, lastIndex + 1, nameLength); + } + + /** + * 琛ㄥ悕杞崲鎴怞ava绫诲悕 + * + * @param tableName 琛ㄥ悕绉 + * @return 绫诲悕 + */ + public static String convertClassName(String tableName) { + boolean autoRemovePre = GenConfig.getAutoRemovePre(); + String tablePrefix = GenConfig.getTablePrefix(); + if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) { + String[] searchList = StringUtils.split(tablePrefix, ","); + tableName = replaceFirst(tableName, searchList); + } + return StringUtils.convertToCamelCase(tableName); + } + + /** + * 鎵归噺鏇挎崲鍓嶇紑 + * + * @param replacementm 鏇挎崲鍊 + * @param searchList 鏇挎崲鍒楄〃 + * @return + */ + public static String replaceFirst(String replacementm, String[] searchList) { + String text = replacementm; + for (String searchString : searchList) { + if (replacementm.startsWith(searchString)) { + text = replacementm.replaceFirst(searchString, ""); + break; + } + } + return text; + } + + /** + * 鍏抽敭瀛楁浛鎹 + * + * @param text 闇瑕佽鏇挎崲鐨勫悕瀛 + * @return 鏇挎崲鍚庣殑鍚嶅瓧 + */ + public static String replaceText(String text) { + return RegExUtils.replaceAll(text, "(?:琛▅鑻ヤ緷)", ""); + } + + /** + * 鑾峰彇鏁版嵁搴撶被鍨嬪瓧娈 + * + * @param columnType 鍒楃被鍨 + * @return 鎴彇鍚庣殑鍒楃被鍨 + */ + public static String getDbType(String columnType) { + if (StringUtils.indexOf(columnType, "(") > 0) { + return StringUtils.substringBefore(columnType, "("); + } else { + return columnType; + } + } + + /** + * 鑾峰彇瀛楁闀垮害 + * + * @param columnType 鍒楃被鍨 + * @return 鎴彇鍚庣殑鍒楃被鍨 + */ + public static Integer getColumnLength(String columnType) { + if (StringUtils.indexOf(columnType, "(") > 0) { + String length = StringUtils.substringBetween(columnType, "(", ")"); + return Integer.valueOf(length); + } else { + return 0; + } + } +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/util/VelocityInitializer.java b/jsowell-generator/src/main/java/com/jsowell/generator/util/VelocityInitializer.java new file mode 100644 index 000000000..51799a06b --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/util/VelocityInitializer.java @@ -0,0 +1,30 @@ +package com.jsowell.generator.util; + +import com.jsowell.common.constant.Constants; +import org.apache.velocity.app.Velocity; + +import java.util.Properties; + +/** + * VelocityEngine宸ュ巶 + * + * @author jsowell + */ +public class VelocityInitializer { + /** + * 鍒濆鍖杤m鏂规硶 + */ + public static void initVelocity() { + Properties p = new Properties(); + try { + // 鍔犺浇classpath鐩綍涓嬬殑vm鏂囦欢 + p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + // 瀹氫箟瀛楃闆 + p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8); + // 鍒濆鍖朧elocity寮曟搸锛屾寚瀹氶厤缃甈roperties + Velocity.init(p); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/jsowell-generator/src/main/java/com/jsowell/generator/util/VelocityUtils.java b/jsowell-generator/src/main/java/com/jsowell/generator/util/VelocityUtils.java new file mode 100644 index 000000000..5224128f0 --- /dev/null +++ b/jsowell-generator/src/main/java/com/jsowell/generator/util/VelocityUtils.java @@ -0,0 +1,348 @@ +package com.jsowell.generator.util; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.constant.GenConstants; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.generator.domain.GenTable; +import com.jsowell.generator.domain.GenTableColumn; +import org.apache.velocity.VelocityContext; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * 妯℃澘澶勭悊宸ュ叿绫 + * + * @author jsowell + */ +public class VelocityUtils { + /** + * 椤圭洰绌洪棿璺緞 + */ + private static final String PROJECT_PATH = "main/java"; + + /** + * mybatis绌洪棿璺緞 + */ + private static final String MYBATIS_PATH = "main/resources/mapper"; + + /** + * 榛樿涓婄骇鑿滃崟锛岀郴缁熷伐鍏 + */ + private static final String DEFAULT_PARENT_MENU_ID = "3"; + + /** + * 璁剧疆妯℃澘鍙橀噺淇℃伅 + * + * @return 妯℃澘鍒楄〃 + */ + public static VelocityContext prepareContext(GenTable genTable) { + String moduleName = genTable.getModuleName(); + String businessName = genTable.getBusinessName(); + String packageName = genTable.getPackageName(); + String tplCategory = genTable.getTplCategory(); + String functionName = genTable.getFunctionName(); + + VelocityContext velocityContext = new VelocityContext(); + velocityContext.put("tplCategory", genTable.getTplCategory()); + velocityContext.put("tableName", genTable.getTableName()); + velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "銆愯濉啓鍔熻兘鍚嶇О銆"); + velocityContext.put("ClassName", genTable.getClassName()); + velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); + velocityContext.put("moduleName", genTable.getModuleName()); + velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); + velocityContext.put("businessName", genTable.getBusinessName()); + velocityContext.put("basePackage", getPackagePrefix(packageName)); + velocityContext.put("packageName", packageName); + velocityContext.put("author", genTable.getFunctionAuthor()); + velocityContext.put("datetime", DateUtils.getDate()); + velocityContext.put("pkColumn", genTable.getPkColumn()); + velocityContext.put("importList", getImportList(genTable)); + velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); + velocityContext.put("columns", genTable.getColumns()); + velocityContext.put("table", genTable); + velocityContext.put("dicts", getDicts(genTable)); + setMenuVelocityContext(velocityContext, genTable); + if (GenConstants.TPL_TREE.equals(tplCategory)) { + setTreeVelocityContext(velocityContext, genTable); + } + if (GenConstants.TPL_SUB.equals(tplCategory)) { + setSubVelocityContext(velocityContext, genTable); + } + return velocityContext; + } + + public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { + String options = genTable.getOptions(); + JSONObject paramsObj = JSON.parseObject(options); + String parentMenuId = getParentMenuId(paramsObj); + context.put("parentMenuId", parentMenuId); + } + + public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { + String options = genTable.getOptions(); + JSONObject paramsObj = JSON.parseObject(options); + String treeCode = getTreecode(paramsObj); + String treeParentCode = getTreeParentCode(paramsObj); + String treeName = getTreeName(paramsObj); + + context.put("treeCode", treeCode); + context.put("treeParentCode", treeParentCode); + context.put("treeName", treeName); + context.put("expandColumn", getExpandColumn(genTable)); + if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { + context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); + } + if (paramsObj.containsKey(GenConstants.TREE_NAME)) { + context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); + } + } + + public static void setSubVelocityContext(VelocityContext context, GenTable genTable) { + GenTable subTable = genTable.getSubTable(); + String subTableName = genTable.getSubTableName(); + String subTableFkName = genTable.getSubTableFkName(); + String subClassName = genTable.getSubTable().getClassName(); + String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName); + + context.put("subTable", subTable); + context.put("subTableName", subTableName); + context.put("subTableFkName", subTableFkName); + context.put("subTableFkClassName", subTableFkClassName); + context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName)); + context.put("subClassName", subClassName); + context.put("subclassName", StringUtils.uncapitalize(subClassName)); + context.put("subImportList", getImportList(genTable.getSubTable())); + } + + /** + * 鑾峰彇妯℃澘淇℃伅 + * + * @return 妯℃澘鍒楄〃 + */ + public static List getTemplateList(String tplCategory) { + List templates = new ArrayList(); + templates.add("vm/java/domain.java.vm"); + templates.add("vm/java/mapper.java.vm"); + templates.add("vm/java/service.java.vm"); + templates.add("vm/java/serviceImpl.java.vm"); + templates.add("vm/java/controller.java.vm"); + templates.add("vm/xml/mapper.xml.vm"); + templates.add("vm/sql/sql.vm"); + templates.add("vm/js/api.js.vm"); + if (GenConstants.TPL_CRUD.equals(tplCategory)) { + templates.add("vm/vue/index.vue.vm"); + } else if (GenConstants.TPL_TREE.equals(tplCategory)) { + templates.add("vm/vue/index-tree.vue.vm"); + } else if (GenConstants.TPL_SUB.equals(tplCategory)) { + templates.add("vm/vue/index.vue.vm"); + templates.add("vm/java/sub-domain.java.vm"); + } + return templates; + } + + /** + * 鑾峰彇鏂囦欢鍚 + */ + public static String getFileName(String template, GenTable genTable) { + // 鏂囦欢鍚嶇О + String fileName = ""; + // 鍖呰矾寰 + String packageName = genTable.getPackageName(); + // 妯″潡鍚 + String moduleName = genTable.getModuleName(); + // 澶у啓绫诲悕 + String className = genTable.getClassName(); + // 涓氬姟鍚嶇О + String businessName = genTable.getBusinessName(); + + String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); + String mybatisPath = MYBATIS_PATH + "/" + moduleName; + String vuePath = "vue"; + + if (template.contains("domain.java.vm")) { + fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); + } + if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) { + fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); + } else if (template.contains("mapper.java.vm")) { + fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); + } else if (template.contains("service.java.vm")) { + fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); + } else if (template.contains("serviceImpl.java.vm")) { + fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); + } else if (template.contains("controller.java.vm")) { + fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); + } else if (template.contains("mapper.xml.vm")) { + fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); + } else if (template.contains("sql.vm")) { + fileName = businessName + "Menu.sql"; + } else if (template.contains("api.js.vm")) { + fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); + } else if (template.contains("index.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + } else if (template.contains("index-tree.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + } + return fileName; + } + + /** + * 鑾峰彇鍖呭墠缂 + * + * @param packageName 鍖呭悕绉 + * @return 鍖呭墠缂鍚嶇О + */ + public static String getPackagePrefix(String packageName) { + int lastIndex = packageName.lastIndexOf("."); + return StringUtils.substring(packageName, 0, lastIndex); + } + + /** + * 鏍规嵁鍒楃被鍨嬭幏鍙栧鍏ュ寘 + * + * @param genTable 涓氬姟琛ㄥ璞 + * @return 杩斿洖闇瑕佸鍏ョ殑鍖呭垪琛 + */ + public static HashSet getImportList(GenTable genTable) { + List columns = genTable.getColumns(); + GenTable subGenTable = genTable.getSubTable(); + HashSet importList = new HashSet(); + if (StringUtils.isNotNull(subGenTable)) { + importList.add("java.util.List"); + } + for (GenTableColumn column : columns) { + if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) { + importList.add("java.util.Date"); + importList.add("com.fasterxml.jackson.annotation.JsonFormat"); + } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) { + importList.add("java.math.BigDecimal"); + } + } + return importList; + } + + /** + * 鏍规嵁鍒楃被鍨嬭幏鍙栧瓧鍏哥粍 + * + * @param genTable 涓氬姟琛ㄥ璞 + * @return 杩斿洖瀛楀吀缁 + */ + public static String getDicts(GenTable genTable) { + List columns = genTable.getColumns(); + Set dicts = new HashSet(); + addDicts(dicts, columns); + if (StringUtils.isNotNull(genTable.getSubTable())) { + List subColumns = genTable.getSubTable().getColumns(); + addDicts(dicts, subColumns); + } + return StringUtils.join(dicts, ", "); + } + + /** + * 娣诲姞瀛楀吀鍒楄〃 + * + * @param dicts 瀛楀吀鍒楄〃 + * @param columns 鍒楅泦鍚 + */ + public static void addDicts(Set dicts, List columns) { + for (GenTableColumn column : columns) { + if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( + column.getHtmlType(), + new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) { + dicts.add("'" + column.getDictType() + "'"); + } + } + } + + /** + * 鑾峰彇鏉冮檺鍓嶇紑 + * + * @param moduleName 妯″潡鍚嶇О + * @param businessName 涓氬姟鍚嶇О + * @return 杩斿洖鏉冮檺鍓嶇紑 + */ + public static String getPermissionPrefix(String moduleName, String businessName) { + return StringUtils.format("{}:{}", moduleName, businessName); + } + + /** + * 鑾峰彇涓婄骇鑿滃崟ID瀛楁 + * + * @param paramsObj 鐢熸垚鍏朵粬閫夐」 + * @return 涓婄骇鑿滃崟ID瀛楁 + */ + public static String getParentMenuId(JSONObject paramsObj) { + if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) + && StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID))) { + return paramsObj.getString(GenConstants.PARENT_MENU_ID); + } + return DEFAULT_PARENT_MENU_ID; + } + + /** + * 鑾峰彇鏍戠紪鐮 + * + * @param paramsObj 鐢熸垚鍏朵粬閫夐」 + * @return 鏍戠紪鐮 + */ + public static String getTreecode(JSONObject paramsObj) { + if (paramsObj.containsKey(GenConstants.TREE_CODE)) { + return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); + } + return StringUtils.EMPTY; + } + + /** + * 鑾峰彇鏍戠埗缂栫爜 + * + * @param paramsObj 鐢熸垚鍏朵粬閫夐」 + * @return 鏍戠埗缂栫爜 + */ + public static String getTreeParentCode(JSONObject paramsObj) { + if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { + return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); + } + return StringUtils.EMPTY; + } + + /** + * 鑾峰彇鏍戝悕绉 + * + * @param paramsObj 鐢熸垚鍏朵粬閫夐」 + * @return 鏍戝悕绉 + */ + public static String getTreeName(JSONObject paramsObj) { + if (paramsObj.containsKey(GenConstants.TREE_NAME)) { + return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); + } + return StringUtils.EMPTY; + } + + /** + * 鑾峰彇闇瑕佸湪鍝竴鍒椾笂闈㈡樉绀哄睍寮鎸夐挳 + * + * @param genTable 涓氬姟琛ㄥ璞 + * @return 灞曞紑鎸夐挳鍒楀簭鍙 + */ + public static int getExpandColumn(GenTable genTable) { + String options = genTable.getOptions(); + JSONObject paramsObj = JSON.parseObject(options); + String treeName = paramsObj.getString(GenConstants.TREE_NAME); + int num = 0; + for (GenTableColumn column : genTable.getColumns()) { + if (column.isList()) { + num++; + String columnName = column.getColumnName(); + if (columnName.equals(treeName)) { + break; + } + } + } + return num; + } +} diff --git a/jsowell-generator/src/main/resources/generator.yml b/jsowell-generator/src/main/resources/generator.yml new file mode 100644 index 000000000..a2dfbb5c9 --- /dev/null +++ b/jsowell-generator/src/main/resources/generator.yml @@ -0,0 +1,10 @@ +# 浠g爜鐢熸垚 +gen: + # 浣滆 + author: jsowell + # 榛樿鐢熸垚鍖呰矾寰 system 闇鏀规垚鑷繁鐨勬ā鍧楀悕绉 濡 system monitor tool + packageName: com.jsowell.pile + # 鑷姩鍘婚櫎琛ㄥ墠缂锛岄粯璁ゆ槸false + autoRemovePre: false + # 琛ㄥ墠缂锛堢敓鎴愮被鍚嶄笉浼氬寘鍚〃鍓嶇紑锛屽涓敤閫楀彿鍒嗛殧锛 + tablePrefix: sys_ \ No newline at end of file diff --git a/jsowell-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/jsowell-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml new file mode 100644 index 000000000..13b9b2143 --- /dev/null +++ b/jsowell-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column + + + + + + + + insert into gen_table_column ( + table_id, + column_name, + column_comment, + column_type, + java_type, + java_field, + is_pk, + is_increment, + is_required, + is_insert, + is_edit, + is_list, + is_query, + query_type, + html_type, + dict_type, + sort, + create_by, + create_time + )values( + #{tableId}, + #{columnName}, + #{columnComment}, + #{columnType}, + #{javaType}, + #{javaField}, + #{isPk}, + #{isIncrement}, + #{isRequired}, + #{isInsert}, + #{isEdit}, + #{isList}, + #{isQuery}, + #{queryType}, + #{htmlType}, + #{dictType}, + #{sort}, + #{createBy}, + sysdate() + ) + + + + update gen_table_column + + column_comment = #{columnComment}, + java_type = #{javaType}, + java_field = #{javaField}, + is_insert = #{isInsert}, + is_edit = #{isEdit}, + is_list = #{isList}, + is_query = #{isQuery}, + is_required = #{isRequired}, + query_type = #{queryType}, + html_type = #{htmlType}, + dict_type = #{dictType}, + sort = #{sort}, + update_by = #{updateBy}, + update_time = sysdate() + + where column_id = #{columnId} + + + + delete from gen_table_column where table_id in + + #{tableId} + + + + + delete from gen_table_column where column_id in + + #{item.columnId} + + + + \ No newline at end of file diff --git a/jsowell-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/jsowell-generator/src/main/resources/mapper/generator/GenTableMapper.xml new file mode 100644 index 000000000..bc76c8140 --- /dev/null +++ b/jsowell-generator/src/main/resources/mapper/generator/GenTableMapper.xml @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select + table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, + package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, + create_by, create_time, update_by, update_time, remark + from gen_table + + + + + + + + + + + + + + + + + + insert into gen_table ( + table_name, + table_comment, + class_name, + tpl_category, + package_name, + module_name, + business_name, + function_name, + function_author, + gen_type, + gen_path, + remark, + create_by, + create_time + )values( + #{tableName}, + #{tableComment}, + #{className}, + #{tplCategory}, + #{packageName}, + #{moduleName}, + #{businessName}, + #{functionName}, + #{functionAuthor}, + #{genType}, + #{genPath}, + #{remark}, + #{createBy}, + sysdate() + ) + + + + update gen_table + + table_name = #{tableName}, + table_comment = #{tableComment}, + sub_table_name = #{subTableName}, + sub_table_fk_name = #{subTableFkName}, + class_name = #{className}, + function_author = #{functionAuthor}, + gen_type = #{genType}, + gen_path = #{genPath}, + tpl_category = #{tplCategory}, + package_name = #{packageName}, + module_name = #{moduleName}, + business_name = #{businessName}, + function_name = #{functionName}, + options = #{options}, + update_by = #{updateBy}, + remark = #{remark}, + update_time = sysdate() + + where table_id = #{tableId} + + + + delete from gen_table where table_id in + + #{tableId} + + + + \ No newline at end of file diff --git a/jsowell-generator/src/main/resources/vm/java/controller.java.vm b/jsowell-generator/src/main/resources/vm/java/controller.java.vm new file mode 100644 index 000000000..2f18870b3 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/java/controller.java.vm @@ -0,0 +1,115 @@ +package ${packageName}.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.enums.BusinessType; +import ${packageName}.domain.${ClassName}; +import ${packageName}.service.I${ClassName}Service; +import com.jsowell.common.util.poi.ExcelUtil; +#if($table.crud || $table.sub) +import com.jsowell.common.core.page.TableDataInfo; +#elseif($table.tree) +#end + +/** + * ${functionName}Controller + * + * @author ${author} + * @date ${datetime} + */ +@RestController +@RequestMapping("/${moduleName}/${businessName}") +public class ${ClassName}Controller extends BaseController +{ + @Autowired + private I${ClassName}Service ${className}Service; + + /** + * 鏌ヨ${functionName}鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')") + @GetMapping("/list") +#if($table.crud || $table.sub) + public TableDataInfo list(${ClassName} ${className}) + { + startPage(); + List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); + return getDataTable(list); + } +#elseif($table.tree) + public AjaxResult list(${ClassName} ${className}) + { + List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); + return AjaxResult.success(list); + } +#end + + /** + * 瀵煎嚭${functionName}鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')") + @Log(title = "${functionName}", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, ${ClassName} ${className}) + { + List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); + ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class); + util.exportExcel(response, list, "${functionName}鏁版嵁"); + } + + /** + * 鑾峰彇${functionName}璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')") + @GetMapping(value = "/{${pkColumn.javaField}}") + public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) + { + return AjaxResult.success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField})); + } + + /** + * 鏂板${functionName} + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')") + @Log(title = "${functionName}", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody ${ClassName} ${className}) + { + return toAjax(${className}Service.insert${ClassName}(${className})); + } + + /** + * 淇敼${functionName} + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')") + @Log(title = "${functionName}", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody ${ClassName} ${className}) + { + return toAjax(${className}Service.update${ClassName}(${className})); + } + + /** + * 鍒犻櫎${functionName} + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')") + @Log(title = "${functionName}", businessType = BusinessType.DELETE) + @DeleteMapping("/{${pkColumn.javaField}s}") + public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) + { + return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s)); + } +} diff --git a/jsowell-generator/src/main/resources/vm/java/domain.java.vm b/jsowell-generator/src/main/resources/vm/java/domain.java.vm new file mode 100644 index 000000000..e27acb01b --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/java/domain.java.vm @@ -0,0 +1,101 @@ +package ${packageName}.domain; + +#foreach ($import in $importList) +import ${import}; +#end +import com.jsowell.common.annotation.Excel; +#if($table.crud || $table.sub) +#elseif($table.tree) +#end + +/** + * ${functionName}瀵硅薄 ${tableName} + * + * @author ${author} + * @date ${datetime} + */ +#if($table.crud || $table.sub) +#set($Entity="BaseEntity") +#elseif($table.tree) +#set($Entity="TreeEntity") +#end +public class ${ClassName} extends ${Entity} +{ + private static final long serialVersionUID = 1L; + +#foreach ($column in $columns) +#if(!$table.isSuperColumn($column.javaField)) + /** $column.columnComment */ +#if($column.list) +#set($parentheseIndex=$column.columnComment.indexOf("锛")) +#if($parentheseIndex != -1) +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) +#else +#set($comment=$column.columnComment) +#end +#if($parentheseIndex != -1) + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") +#elseif($column.javaType == 'Date') + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") +#else + @Excel(name = "${comment}") +#end +#end + private $column.javaType $column.javaField; + +#end +#end +#if($table.sub) + /** $table.subTable.functionName淇℃伅 */ + private List<${subClassName}> ${subclassName}List; + +#end +#foreach ($column in $columns) +#if(!$table.isSuperColumn($column.javaField)) +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) +#set($AttrName=$column.javaField) +#else +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) +#end + public void set${AttrName}($column.javaType $column.javaField) + { + this.$column.javaField = $column.javaField; + } + + public $column.javaType get${AttrName}() + { + return $column.javaField; + } +#end +#end + +#if($table.sub) + public List<${subClassName}> get${subClassName}List() + { + return ${subclassName}List; + } + + public void set${subClassName}List(List<${subClassName}> ${subclassName}List) + { + this.${subclassName}List = ${subclassName}List; + } + +#end + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.JSON_STYLE) +#foreach ($column in $columns) +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) +#set($AttrName=$column.javaField) +#else +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) +#end + .append("${column.javaField}", get${AttrName}()) +#end +#if($table.sub) + .append("${subclassName}List", get${subClassName}List()) +#end + .toString(); + } +} diff --git a/jsowell-generator/src/main/resources/vm/java/mapper.java.vm b/jsowell-generator/src/main/resources/vm/java/mapper.java.vm new file mode 100644 index 000000000..7e7d7c26f --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/java/mapper.java.vm @@ -0,0 +1,91 @@ +package ${packageName}.mapper; + +import java.util.List; +import ${packageName}.domain.${ClassName}; +#if($table.sub) +import ${packageName}.domain.${subClassName}; +#end + +/** + * ${functionName}Mapper鎺ュ彛 + * + * @author ${author} + * @date ${datetime} + */ +public interface ${ClassName}Mapper +{ + /** + * 鏌ヨ${functionName} + * + * @param ${pkColumn.javaField} ${functionName}涓婚敭 + * @return ${functionName} + */ + public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); + + /** + * 鏌ヨ${functionName}鍒楄〃 + * + * @param ${className} ${functionName} + * @return ${functionName}闆嗗悎 + */ + public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); + + /** + * 鏂板${functionName} + * + * @param ${className} ${functionName} + * @return 缁撴灉 + */ + public int insert${ClassName}(${ClassName} ${className}); + + /** + * 淇敼${functionName} + * + * @param ${className} ${functionName} + * @return 缁撴灉 + */ + public int update${ClassName}(${ClassName} ${className}); + + /** + * 鍒犻櫎${functionName} + * + * @param ${pkColumn.javaField} ${functionName}涓婚敭 + * @return 缁撴灉 + */ + public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); + + /** + * 鎵归噺鍒犻櫎${functionName} + * + * @param ${pkColumn.javaField}s 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); +#if($table.sub) + + /** + * 鎵归噺鍒犻櫎${subTable.functionName} + * + * @param ${pkColumn.javaField}s 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); + + /** + * 鎵归噺鏂板${subTable.functionName} + * + * @param ${subclassName}List ${subTable.functionName}鍒楄〃 + * @return 缁撴灉 + */ + public int batch${subClassName}(List<${subClassName}> ${subclassName}List); + + + /** + * 閫氳繃${functionName}涓婚敭鍒犻櫎${subTable.functionName}淇℃伅 + * + * @param ${pkColumn.javaField} ${functionName}ID + * @return 缁撴灉 + */ + public int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField}); +#end +} diff --git a/jsowell-generator/src/main/resources/vm/java/service.java.vm b/jsowell-generator/src/main/resources/vm/java/service.java.vm new file mode 100644 index 000000000..264882b27 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/java/service.java.vm @@ -0,0 +1,61 @@ +package ${packageName}.service; + +import java.util.List; +import ${packageName}.domain.${ClassName}; + +/** + * ${functionName}Service鎺ュ彛 + * + * @author ${author} + * @date ${datetime} + */ +public interface I${ClassName}Service +{ + /** + * 鏌ヨ${functionName} + * + * @param ${pkColumn.javaField} ${functionName}涓婚敭 + * @return ${functionName} + */ + public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); + + /** + * 鏌ヨ${functionName}鍒楄〃 + * + * @param ${className} ${functionName} + * @return ${functionName}闆嗗悎 + */ + public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); + + /** + * 鏂板${functionName} + * + * @param ${className} ${functionName} + * @return 缁撴灉 + */ + public int insert${ClassName}(${ClassName} ${className}); + + /** + * 淇敼${functionName} + * + * @param ${className} ${functionName} + * @return 缁撴灉 + */ + public int update${ClassName}(${ClassName} ${className}); + + /** + * 鎵归噺鍒犻櫎${functionName} + * + * @param ${pkColumn.javaField}s 闇瑕佸垹闄ょ殑${functionName}涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); + + /** + * 鍒犻櫎${functionName}淇℃伅 + * + * @param ${pkColumn.javaField} ${functionName}涓婚敭 + * @return 缁撴灉 + */ + public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); +} diff --git a/jsowell-generator/src/main/resources/vm/java/serviceImpl.java.vm b/jsowell-generator/src/main/resources/vm/java/serviceImpl.java.vm new file mode 100644 index 000000000..6976ded59 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/java/serviceImpl.java.vm @@ -0,0 +1,169 @@ +package ${packageName}.service.impl; + +import java.util.List; +#foreach ($column in $columns) +#if($column.javaField == 'createTime' || $column.javaField == 'updateTime') +import com.jsowell.common.util.DateUtils; +#break +#end +#end +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +#if($table.sub) +import java.util.ArrayList; +import com.jsowell.common.util.StringUtils; +import org.springframework.transaction.annotation.Transactional; +import ${packageName}.domain.${subClassName}; +#end +import ${packageName}.mapper.${ClassName}Mapper; +import ${packageName}.domain.${ClassName}; +import ${packageName}.service.I${ClassName}Service; + +/** + * ${functionName}Service涓氬姟灞傚鐞 + * + * @author ${author} + * @date ${datetime} + */ +@Service +public class ${ClassName}ServiceImpl implements I${ClassName}Service +{ + @Autowired + private ${ClassName}Mapper ${className}Mapper; + + /** + * 鏌ヨ${functionName} + * + * @param ${pkColumn.javaField} ${functionName}涓婚敭 + * @return ${functionName} + */ + @Override + public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}) + { + return ${className}Mapper.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}); + } + + /** + * 鏌ヨ${functionName}鍒楄〃 + * + * @param ${className} ${functionName} + * @return ${functionName} + */ + @Override + public List<${ClassName}> select${ClassName}List(${ClassName} ${className}) + { + return ${className}Mapper.select${ClassName}List(${className}); + } + + /** + * 鏂板${functionName} + * + * @param ${className} ${functionName} + * @return 缁撴灉 + */ +#if($table.sub) + @Transactional +#end + @Override + public int insert${ClassName}(${ClassName} ${className}) + { +#foreach ($column in $columns) +#if($column.javaField == 'createTime') + ${className}.setCreateTime(DateUtils.getNowDate()); +#end +#end +#if($table.sub) + int rows = ${className}Mapper.insert${ClassName}(${className}); + insert${subClassName}(${className}); + return rows; +#else + return ${className}Mapper.insert${ClassName}(${className}); +#end + } + + /** + * 淇敼${functionName} + * + * @param ${className} ${functionName} + * @return 缁撴灉 + */ +#if($table.sub) + @Transactional +#end + @Override + public int update${ClassName}(${ClassName} ${className}) + { +#foreach ($column in $columns) +#if($column.javaField == 'updateTime') + ${className}.setUpdateTime(DateUtils.getNowDate()); +#end +#end +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}()); + insert${subClassName}(${className}); +#end + return ${className}Mapper.update${ClassName}(${className}); + } + + /** + * 鎵归噺鍒犻櫎${functionName} + * + * @param ${pkColumn.javaField}s 闇瑕佸垹闄ょ殑${functionName}涓婚敭 + * @return 缁撴灉 + */ +#if($table.sub) + @Transactional +#end + @Override + public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s) + { +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s); +#end + return ${className}Mapper.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s); + } + + /** + * 鍒犻櫎${functionName}淇℃伅 + * + * @param ${pkColumn.javaField} ${functionName}涓婚敭 + * @return 缁撴灉 + */ +#if($table.sub) + @Transactional +#end + @Override + public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}) + { +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField}); +#end + return ${className}Mapper.delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}); + } +#if($table.sub) + + /** + * 鏂板${subTable.functionName}淇℃伅 + * + * @param ${className} ${functionName}瀵硅薄 + */ + public void insert${subClassName}(${ClassName} ${className}) + { + List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List(); + ${pkColumn.javaType} ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}(); + if (StringUtils.isNotNull(${subclassName}List)) + { + List<${subClassName}> list = new ArrayList<${subClassName}>(); + for (${subClassName} ${subclassName} : ${subclassName}List) + { + ${subclassName}.set${subTableFkClassName}(${pkColumn.javaField}); + list.add(${subclassName}); + } + if (list.size() > 0) + { + ${className}Mapper.batch${subClassName}(list); + } + } + } +#end +} diff --git a/jsowell-generator/src/main/resources/vm/java/sub-domain.java.vm b/jsowell-generator/src/main/resources/vm/java/sub-domain.java.vm new file mode 100644 index 000000000..563124bdb --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/java/sub-domain.java.vm @@ -0,0 +1,73 @@ +package ${packageName}.domain; + +#foreach ($import in $subImportList) +import ${import}; +#end +import com.jsowell.common.annotation.Excel; + +/** + * ${subTable.functionName}瀵硅薄 ${subTableName} + * + * @author ${author} + * @date ${datetime} + */ +public class ${subClassName} extends BaseEntity +{ + private static final long serialVersionUID = 1L; + +#foreach ($column in $subTable.columns) +#if(!$table.isSuperColumn($column.javaField)) + /** $column.columnComment */ +#if($column.list) +#set($parentheseIndex=$column.columnComment.indexOf("锛")) +#if($parentheseIndex != -1) +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) +#else +#set($comment=$column.columnComment) +#end +#if($parentheseIndex != -1) + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") +#elseif($column.javaType == 'Date') + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") +#else + @Excel(name = "${comment}") +#end +#end + private $column.javaType $column.javaField; + +#end +#end +#foreach ($column in $subTable.columns) +#if(!$table.isSuperColumn($column.javaField)) +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) +#set($AttrName=$column.javaField) +#else +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) +#end + public void set${AttrName}($column.javaType $column.javaField) + { + this.$column.javaField = $column.javaField; + } + + public $column.javaType get${AttrName}() + { + return $column.javaField; + } +#end +#end + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.JSON_STYLE) +#foreach ($column in $subTable.columns) +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) +#set($AttrName=$column.javaField) +#else +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) +#end + .append("${column.javaField}", get${AttrName}()) +#end + .toString(); + } +} diff --git a/jsowell-generator/src/main/resources/vm/js/api.js.vm b/jsowell-generator/src/main/resources/vm/js/api.js.vm new file mode 100644 index 000000000..9295524a4 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/js/api.js.vm @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 鏌ヨ${functionName}鍒楄〃 +export function list${BusinessName}(query) { + return request({ + url: '/${moduleName}/${businessName}/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ${functionName}璇︾粏 +export function get${BusinessName}(${pkColumn.javaField}) { + return request({ + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, + method: 'get' + }) +} + +// 鏂板${functionName} +export function add${BusinessName}(data) { + return request({ + url: '/${moduleName}/${businessName}', + method: 'post', + data: data + }) +} + +// 淇敼${functionName} +export function update${BusinessName}(data) { + return request({ + url: '/${moduleName}/${businessName}', + method: 'put', + data: data + }) +} + +// 鍒犻櫎${functionName} +export function del${BusinessName}(${pkColumn.javaField}) { + return request({ + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, + method: 'delete' + }) +} diff --git a/jsowell-generator/src/main/resources/vm/sql/sql.vm b/jsowell-generator/src/main/resources/vm/sql/sql.vm new file mode 100644 index 000000000..0b54dcae6 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/sql/sql.vm @@ -0,0 +1,22 @@ +-- 鑿滃崟 SQL +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) +values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'thinkgem', sysdate(), '', null, '${functionName}鑿滃崟'); + +-- 鎸夐挳鐖惰彍鍗旾D +SELECT @parentId := LAST_INSERT_ID(); + +-- 鎸夐挳 SQL +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) +values('${functionName}鏌ヨ', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'thinkgem', sysdate(), '', null, ''); + +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) +values('${functionName}鏂板', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'thinkgem', sysdate(), '', null, ''); + +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) +values('${functionName}淇敼', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'thinkgem', sysdate(), '', null, ''); + +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) +values('${functionName}鍒犻櫎', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'thinkgem', sysdate(), '', null, ''); + +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) +values('${functionName}瀵煎嚭', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'thinkgem', sysdate(), '', null, ''); \ No newline at end of file diff --git a/jsowell-generator/src/main/resources/vm/vue/index-tree.vue.vm b/jsowell-generator/src/main/resources/vm/vue/index-tree.vue.vm new file mode 100644 index 000000000..3def70454 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/vue/index-tree.vue.vm @@ -0,0 +1,502 @@ + + + diff --git a/jsowell-generator/src/main/resources/vm/vue/index.vue.vm b/jsowell-generator/src/main/resources/vm/vue/index.vue.vm new file mode 100644 index 000000000..e9a1fae13 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/vue/index.vue.vm @@ -0,0 +1,598 @@ + + + diff --git a/jsowell-generator/src/main/resources/vm/vue/v3/index-tree.vue.vm b/jsowell-generator/src/main/resources/vm/vue/v3/index-tree.vue.vm new file mode 100644 index 000000000..862297c79 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/vue/v3/index-tree.vue.vm @@ -0,0 +1,486 @@ + + + diff --git a/jsowell-generator/src/main/resources/vm/vue/v3/index.vue.vm b/jsowell-generator/src/main/resources/vm/vue/v3/index.vue.vm new file mode 100644 index 000000000..f66cc3b89 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/vue/v3/index.vue.vm @@ -0,0 +1,596 @@ + + + diff --git a/jsowell-generator/src/main/resources/vm/xml/mapper.xml.vm b/jsowell-generator/src/main/resources/vm/xml/mapper.xml.vm new file mode 100644 index 000000000..0ceb3d859 --- /dev/null +++ b/jsowell-generator/src/main/resources/vm/xml/mapper.xml.vm @@ -0,0 +1,135 @@ + + + + + +#foreach ($column in $columns) + +#end + +#if($table.sub) + + + + + + +#foreach ($column in $subTable.columns) + +#end + +#end + + + select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName} + + + + + + + + insert into ${tableName} + +#foreach($column in $columns) +#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) + $column.columnName, +#end +#end + + +#foreach($column in $columns) +#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) + #{$column.javaField}, +#end +#end + + + + + update ${tableName} + +#foreach($column in $columns) +#if($column.columnName != $pkColumn.columnName) + $column.columnName = #{$column.javaField}, +#end +#end + + where ${pkColumn.columnName} = #{${pkColumn.javaField}} + + + + delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}} + + + + delete from ${tableName} where ${pkColumn.columnName} in + + #{${pkColumn.javaField}} + + +#if($table.sub) + + + delete from ${subTableName} where ${subTableFkName} in + + #{${subTableFkclassName}} + + + + + delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}} + + + + insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($foreach.count != $subTable.columns.size()),#end#end) values + + (#foreach($column in $subTable.columns) #{item.$column.javaField}#if($foreach.count != $subTable.columns.size()),#end#end) + + +#end + \ No newline at end of file diff --git a/jsowell-netty/pom.xml b/jsowell-netty/pom.xml new file mode 100644 index 000000000..b174b8f71 --- /dev/null +++ b/jsowell-netty/pom.xml @@ -0,0 +1,46 @@ + + + + jsowell-charger-web + com.jsowell + 1.0.0 + + 4.0.0 + + jsowell-netty + + + + org.projectlombok + lombok + + + com.jsowell + jsowell-pile + 1.0.0 + + + + + 8 + 8 + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + false + ${project.artifactId} + + + + + + + \ No newline at end of file diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClient.java b/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClient.java new file mode 100644 index 000000000..6f2b4b593 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClient.java @@ -0,0 +1,109 @@ +package com.jsowell.netty.client; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.util.DateUtils; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelOption; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Data +public class NettyClient implements Runnable { + + static final String HOST = System.getProperty("host", Constants.SOCKET_IP); + static final int PORT = Integer.parseInt(System.getProperty("port", "9011")); + static final int SIZE = Integer.parseInt(System.getProperty("size", "256")); + + private String content; + + public NettyClient(String content) { + this.content = content; + } + + @Override + public void run() { + // Configure the client. + EventLoopGroup group = new NioEventLoopGroup(); + try { + int num = 0; + boolean boo = true; + Bootstrap b = new Bootstrap(); + b.group(group) + .channel(NioSocketChannel.class) + .option(ChannelOption.TCP_NODELAY, true) + .handler(new NettyClientChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline p = ch.pipeline(); + p.addLast("decoder", new StringDecoder()); + p.addLast("encoder", new StringEncoder()); + p.addLast(new NettyClientHandler()); + } + }); + ChannelFuture future = b.connect(HOST, PORT).sync(); + while (boo) { + num++; + future.channel().writeAndFlush("鍙戦佹暟鎹=======" + content + "--" + DateUtils.getTime()); + try { //浼戠湢涓娈垫椂闂 + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + //姣忎竴鏉$嚎绋嬪悜鏈嶅姟绔彂閫佺殑娆℃暟 + if (num == 5) { + boo = false; + } + } + log.info(content + "-----------------------------" + num); + //future.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + group.shutdownGracefully(); + } + } + + /** + * 涓嬮潰鏄笉鍔犵嚎绋嬬殑 + */ + /*public static void main(String[] args) throws Exception { + + sendMessage("hhh浣犲ソ锛"); + } + + public static void sendMessage(String content) throws InterruptedException { + // Configure the client. + EventLoopGroup group = new NioEventLoopGroup(); + try { + Bootstrap b = new Bootstrap(); + b.group(group) + .channel(NioSocketChannel.class) + .option(ChannelOption.TCP_NODELAY, true) + .handler(new NettyClientChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline p = ch.pipeline(); + p.addLast("decoder", new StringDecoder()); + p.addLast("encoder", new StringEncoder()); + p.addLast(new NettyClientHandler()); + } + }); + + ChannelFuture future = b.connect(HOST, PORT).sync(); + future.channel().writeAndFlush(content); + future.channel().closeFuture().sync(); + } finally { + group.shutdownGracefully(); + } + }*/ + +} \ No newline at end of file diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClientChannelInitializer.java b/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClientChannelInitializer.java new file mode 100644 index 000000000..d5b61527d --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClientChannelInitializer.java @@ -0,0 +1,23 @@ +package com.jsowell.netty.client; + +import com.jsowell.netty.server.yunkuaichong.NettyServerHandler; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; +import io.netty.util.CharsetUtil; + +/** + * 瀹㈡埛绔垵濮嬪寲锛屽鎴风涓庢湇鍔″櫒绔繛鎺ヤ竴鏃﹀垱寤猴紝杩欎釜绫讳腑鏂规硶灏变細琚洖璋冿紝璁剧疆鍑虹珯缂栫爜鍣ㄥ拰鍏ョ珯瑙g爜鍣紝瀹㈡埛绔湇鍔$缂栬В鐮佽涓鑷 + */ +public class NettyClientChannelInitializer extends ChannelInitializer { + + @Override + protected void initChannel(SocketChannel channel) throws Exception { + + channel.pipeline().addLast("decoder",new StringDecoder(CharsetUtil.UTF_8)); + channel.pipeline().addLast("encoder",new StringEncoder(CharsetUtil.UTF_8)); + + channel.pipeline().addLast(new NettyServerHandler()); + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClientHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClientHandler.java new file mode 100644 index 000000000..41c1f896f --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClientHandler.java @@ -0,0 +1,71 @@ +package com.jsowell.netty.client; + +import com.jsowell.common.util.DateUtils; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelId; +import io.netty.channel.ChannelInboundHandlerAdapter; +import lombok.extern.slf4j.Slf4j; + +import java.util.concurrent.ConcurrentHashMap; + +/** + * 瀹㈡埛绔鐞嗙被 + */ +@Slf4j +public class NettyClientHandler extends ChannelInboundHandlerAdapter { + + /** + * 璁$畻鏈夊灏戝鎴风鎺ュ叆锛岀涓涓猻tring涓哄鎴风ip + */ + private static final ConcurrentHashMap CLIENT_MAP = new ConcurrentHashMap<>(); + + @Override + public void channelActive(ChannelHandlerContext ctx) { + CLIENT_MAP.put(ctx.channel().id(), ctx); + log.info("ClientHandler Active"); + } + + /** + * @param ctx + * @author xiongchuan on 2019/4/28 16:10 + * @DESCRIPTION: 鏈夋湇鍔$绔粓姝㈣繛鎺ユ湇鍔″櫒浼氳Е鍙戞鍑芥暟 + * @return: void + */ + @Override + public void channelInactive(ChannelHandlerContext ctx) { + ctx.close(); + log.info("鏈嶅姟绔粓姝簡鏈嶅姟"); + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) { + log.info("鍥炲啓鏁版嵁:" + msg); + } + + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + //cause.printStackTrace(); + log.info("鏈嶅姟绔彂鐢熷紓甯搞" + cause.getMessage() + "銆"); + ctx.close(); + } + + /** + * @param msg 闇瑕佸彂閫佺殑娑堟伅鍐呭 + * @param channelId 杩炴帴閫氶亾鍞竴id + * @author xiongchuan on 2019/4/28 16:10 + * @DESCRIPTION: 瀹㈡埛绔粰鏈嶅姟绔彂閫佹秷鎭 + * @return: void + */ + public void channelWrite(ChannelId channelId, String msg) { + ChannelHandlerContext ctx = CLIENT_MAP.get(channelId); + if (ctx == null) { + log.info("閫氶亾銆" + channelId + "銆戜笉瀛樺湪"); + return; + } + //灏嗗鎴风鐨勪俊鎭洿鎺ヨ繑鍥炲啓鍏tx + ctx.write(msg + " 鏃堕棿锛" + DateUtils.getTime()); + //鍒锋柊缂撳瓨鍖 + ctx.flush(); + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/client/TestNettyClient.java b/jsowell-netty/src/main/java/com/jsowell/netty/client/TestNettyClient.java new file mode 100644 index 000000000..34d4d77c9 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/client/TestNettyClient.java @@ -0,0 +1,14 @@ +package com.jsowell.netty.client; + +/** + * 妯℃嫙澶氬鎴风鍙戦佹姤鏂 + */ +public class TestNettyClient { + + public static void main(String[] args) { + //寮鍚10鏉$嚎绋嬶紝姣忔潯绾跨▼灏辩浉褰撲簬涓涓鎴风 + for (int i = 1; i <= 300; i++) { + new Thread(new NettyClient("thread" + "--" + i)).start(); + } + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/GetRealTimeMonitorDataCommand.java b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/GetRealTimeMonitorDataCommand.java new file mode 100644 index 000000000..00e625aca --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/GetRealTimeMonitorDataCommand.java @@ -0,0 +1,18 @@ +package com.jsowell.netty.command.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 璇诲彇瀹炴椂鐩戞祴鏁版嵁鍛戒护 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GetRealTimeMonitorDataCommand { + private String pileSn; + private String connectorCode; +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/IssueQRCodeCommand.java b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/IssueQRCodeCommand.java new file mode 100644 index 000000000..757195056 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/IssueQRCodeCommand.java @@ -0,0 +1,14 @@ +package com.jsowell.netty.command.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class IssueQRCodeCommand { + String pileSn; +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/ProofreadTimeCommand.java b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/ProofreadTimeCommand.java new file mode 100644 index 000000000..95508b6df --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/ProofreadTimeCommand.java @@ -0,0 +1,17 @@ +package com.jsowell.netty.command.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 瀵规椂鍛戒护 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ProofreadTimeCommand { + private String pileSn; +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/PublishPileBillingTemplateCommand.java b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/PublishPileBillingTemplateCommand.java new file mode 100644 index 000000000..2f0c03861 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/PublishPileBillingTemplateCommand.java @@ -0,0 +1,17 @@ +package com.jsowell.netty.command.ykc; + +import com.jsowell.pile.vo.web.BillingTemplateVO; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PublishPileBillingTemplateCommand { + private String pileSn; + + private BillingTemplateVO billingTemplateVO; +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/RebootCommand.java b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/RebootCommand.java new file mode 100644 index 000000000..17b1daa07 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/RebootCommand.java @@ -0,0 +1,14 @@ +package com.jsowell.netty.command.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class RebootCommand { + private String pileSn; +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/StartChargingCommand.java b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/StartChargingCommand.java new file mode 100644 index 000000000..891ac7525 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/StartChargingCommand.java @@ -0,0 +1,48 @@ +package com.jsowell.netty.command.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 鍚姩鍏呯數鎸囦护 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class StartChargingCommand { + /** + * 浜ゆ槗娴佹按鍙 + */ + private String orderCode; + + /** + * 鍏呯數妗╃紪鍙 + */ + private String pileSn; + + /** + * 鏋彛鍙 + */ + private String connectorCode; + + /** + * 鍏呯數閲戦 + */ + private BigDecimal chargeAmount; + + /** + * 閫昏緫鍗″彿 娌℃湁灏变紶0 + */ + private String logicCardNum; + + /** + * 鐗╃悊鍗″彿 娌℃湁灏变紶0 + */ + private String physicsCardNum; + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/StopChargingCommand.java b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/StopChargingCommand.java new file mode 100644 index 000000000..65683aee1 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/StopChargingCommand.java @@ -0,0 +1,18 @@ +package com.jsowell.netty.command.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 鍋滄鍏呯數鎸囦护 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class StopChargingCommand { + private String pileSn; + private String connectorCode; +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/UpdateFileCommand.java b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/UpdateFileCommand.java new file mode 100644 index 000000000..9d1155ec9 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/command/ykc/UpdateFileCommand.java @@ -0,0 +1,16 @@ +package com.jsowell.netty.command.ykc; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UpdateFileCommand { + List pileSnList; +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/decoder/CustomDecoder.java b/jsowell-netty/src/main/java/com/jsowell/netty/decoder/CustomDecoder.java new file mode 100644 index 000000000..3ea0044c8 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/decoder/CustomDecoder.java @@ -0,0 +1,40 @@ +package com.jsowell.netty.decoder; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.handler.codec.CorruptedFrameException; + +import java.util.List; + +public class CustomDecoder extends ByteToMessageDecoder { + private static final byte START_FLAG = (byte) 0x68; + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { + // 妫鏌ュ彲璇绘暟鎹暱搴︽槸鍚﹀ぇ浜庣瓑浜庤捣濮嬫爣蹇楃鍜屾暟鎹暱搴﹀瓧娈电殑闀垮害 + if (in.readableBytes() >= 3) { + // 鏍囪褰撳墠璇诲彇浣嶇疆 + in.markReaderIndex(); + // 璇诲彇璧峰鏍囧織绗 + byte startFlag = in.readByte(); + // 妫鏌ヨ捣濮嬫爣蹇楃鏄惁姝g‘ + if (startFlag != START_FLAG) { + // 濡傛灉涓嶆纭紝閲嶇疆璇诲彇浣嶇疆锛屽苟鎶涘嚭寮傚父 + in.resetReaderIndex(); + throw new CorruptedFrameException("Invalid start flag: " + startFlag); + } + // 璇诲彇鏁版嵁闀垮害 + byte length = in.readByte(); + // 妫鏌ュ彲璇绘暟鎹暱搴︽槸鍚﹀ぇ浜庣瓑浜庢暟鎹暱搴﹀瓧娈电殑鍊 + if (in.readableBytes() >= length) { + // 璇诲彇瀹屾暣鏁版嵁鍖 + ByteBuf frame = in.readBytes(length + 2); // 鍖呮嫭鏍¢獙浣 + out.add(frame); + } else { + // 濡傛灉鍙鏁版嵁闀垮害涓嶅锛岄噸缃鍙栦綅缃紝骞剁瓑寰呬笅涓娆¤鍙 + in.resetReaderIndex(); + } + } + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/decoder/StartAndLengthFieldFrameDecoder.java b/jsowell-netty/src/main/java/com/jsowell/netty/decoder/StartAndLengthFieldFrameDecoder.java new file mode 100644 index 000000000..b38288860 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/decoder/StartAndLengthFieldFrameDecoder.java @@ -0,0 +1,85 @@ +package com.jsowell.netty.decoder; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + +@Slf4j +public class StartAndLengthFieldFrameDecoder extends ByteToMessageDecoder { + // 璧峰鏍囧織 + private int HEAD_DATA; + + public StartAndLengthFieldFrameDecoder(int HEAD_DATA) { + this.HEAD_DATA = HEAD_DATA; + } + + /** + *
+	 * 鍗忚寮濮嬬殑鏍囧噯head_data锛宨nt绫诲瀷锛屽崰鎹1涓瓧鑺.
+	 * 琛ㄧず鏁版嵁鐨勯暱搴ontentLength锛宨nt绫诲瀷锛屽崰鎹1涓瓧鑺.
+	 * 
+ */ + public final int BASE_LENGTH = 1 + 1; + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, + List out) throws Exception { + System.out.println(); + // log.info("鎵撳嵃ByteBuf:{}", buffer.toString()); + // 鍙闀垮害蹇呴』澶т簬鍩烘湰闀垮害 + if (buffer.readableBytes() <= BASE_LENGTH) { + log.warn("鍙瀛楄妭鏁:{}灏忎簬鍩虹闀垮害:{}", buffer.readableBytes(), BASE_LENGTH); + return; + } + + // 璁板綍鍖呭ご寮濮嬬殑index + int beginReader; + + while (true) { + // 鑾峰彇鍖呭ご寮濮嬬殑index + beginReader = buffer.readerIndex(); + // log.info("鍖呭ご寮濮嬬殑index:{}", beginReader); + // 鏍囪鍖呭ご寮濮嬬殑index + buffer.markReaderIndex(); + // 璇诲埌浜嗗崗璁殑寮濮嬫爣蹇楋紝缁撴潫while寰幆 + if (buffer.getUnsignedByte(beginReader) == HEAD_DATA) { + // log.info("璇诲埌浜嗗崗璁殑寮濮嬫爣蹇楋紝缁撴潫while寰幆 byte:{}, HEAD_DATA:{}", buffer.getUnsignedByte(beginReader), HEAD_DATA); + break; + } + + // 鏈鍒板寘澶达紝鐣ヨ繃涓涓瓧鑺 + // 姣忔鐣ヨ繃锛屼竴涓瓧鑺傦紝鍘昏鍙栵紝鍖呭ご淇℃伅鐨勫紑濮嬫爣璁 + buffer.resetReaderIndex(); + buffer.readByte(); + + // 褰撶暐杩囷紝涓涓瓧鑺備箣鍚庯紝 + // 鏁版嵁鍖呯殑闀垮害锛屽張鍙樺緱涓嶆弧瓒 + // 姝ゆ椂锛屽簲璇ョ粨鏉熴傜瓑寰呭悗闈㈢殑鏁版嵁鍒拌揪 + if (buffer.readableBytes() < BASE_LENGTH) { + log.info("鏁版嵁鍖呯殑闀垮害涓嶆弧瓒 readableBytes:{}, BASE_LENGTH:{}", buffer.readableBytes(), BASE_LENGTH); + return; + } + } + + // 娑堟伅鐨勯暱搴 + int length = buffer.getUnsignedByte(beginReader + 1); + // 鍒ゆ柇璇锋眰鏁版嵁鍖呮暟鎹槸鍚﹀埌榻 + if (buffer.readableBytes() < length + 4) { + // log.info("璇锋眰鏁版嵁鍖呮暟鎹病鏈夊埌榻,杩樺師璇绘寚閽 readableBytes:{}, 娑堟伅鐨勯暱搴:{}", buffer.readableBytes(), length); + // 杩樺師璇绘寚閽 + buffer.readerIndex(beginReader); + return; + } + + // 璇诲彇data鏁版嵁 + byte[] data = new byte[length + 4]; + buffer.readBytes(data); + ByteBuf frame = buffer.retainedSlice(beginReader, length + 4); + buffer.readerIndex(beginReader + length + 4); + out.add(frame); + } + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/factory/YKCOperateFactory.java b/jsowell-netty/src/main/java/com/jsowell/netty/factory/YKCOperateFactory.java new file mode 100644 index 000000000..a0edbfcdf --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/factory/YKCOperateFactory.java @@ -0,0 +1,38 @@ +package com.jsowell.netty.factory; + +import com.google.common.collect.Maps; +import com.jsowell.common.util.StringUtils; +import com.jsowell.netty.handler.AbstractHandler; + +import java.util.Map; +import java.util.Objects; + +/** + * 宸ュ巶璁捐妯″紡 + * 浜戝揩鍏呮搷浣 + */ +public class YKCOperateFactory { + + private static Map strategyMap = Maps.newHashMap(); + + /** + * 娉ㄥ唽 + * @param str + * @param handler + */ + public static void register(String str, AbstractHandler handler) { + if (StringUtils.isBlank(str) || Objects.isNull(handler)) { + return; + } + strategyMap.put(str, handler); + } + + /** + * 鑾峰彇 + * @param name + * @return + */ + public static AbstractHandler getInvokeStrategy(String name) { + return strategyMap.get(name); + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/AbstractHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/AbstractHandler.java new file mode 100644 index 000000000..c8aa229db --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/AbstractHandler.java @@ -0,0 +1,73 @@ +package com.jsowell.netty.handler; + +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.CRC16Util; +import com.jsowell.common.util.DateUtils; +import io.netty.channel.Channel; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * 妯℃澘鏂规硶妯″紡 + */ +public abstract class AbstractHandler implements InitializingBean { + + @Autowired + private RedisCache redisCache; + + /** + * 鎵ц閫昏緫 + * 鏈夊簲绛 + */ + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + throw new UnsupportedOperationException(); + } + + /** + * 鎵ц閫昏緫 + * 涓嶉渶瑕佸簲绛 + */ + // public void pushProcess() { + // throw new UnsupportedOperationException(); + // } + + /** + * 缁勮搴旂瓟鐨勭粨鏋 + * @param ykcDataProtocol 璇锋眰鏁版嵁 + * @param messageBody 娑堟伅浣 + * @return 搴旂瓟缁撴灉 + */ + protected byte[] getResult(YKCDataProtocol ykcDataProtocol, byte[] messageBody) { + // 璧峰鏍囧織 + byte[] head = ykcDataProtocol.getHead(); + // 搴忓垪鍙峰煙 + byte[] serialNumber = ykcDataProtocol.getSerialNumber(); + // 鍔犲瘑鏍囧織 + byte[] encryptFlag = ykcDataProtocol.getEncryptFlag(); + // 璇锋眰甯х被鍨 + byte[] requestFrameType = ykcDataProtocol.getFrameType(); + // 搴旂瓟甯х被鍨 + byte[] responseFrameType = YKCFrameTypeCode.ResponseRelation.getResponseFrameType(requestFrameType); + + // 鏁版嵁鍩 鍊间负鈥滃簭鍒楀彿鍩+鍔犲瘑鏍囧織+甯х被鍨嬫爣蹇+娑堟伅浣撯濆瓧鑺傛暟涔嬪拰 + byte[] dataFields = Bytes.concat(serialNumber, encryptFlag, responseFrameType, messageBody); + // 璁$畻crc锛 浠庡簭鍒楀彿鍩熷埌鏁版嵁鍩熺殑 CRC 鏍¢獙 + int crc16 = CRC16Util.calcCrc16(dataFields); + return Bytes.concat(head, BytesUtil.intToBytes(dataFields.length, 1), dataFields, BytesUtil.intToBytes(crc16)); + } + + /** + * 淇濆瓨妗╂渶鍚庨摼鎺ュ埌骞冲彴鐨勬椂闂 + * @param pileSn 妗╃紪鍙 + */ + protected void saveLastTime(String pileSn) { + String redisKey = CacheConstants.PILE_LAST_CONNECTION + pileSn; + redisCache.setCacheObject(redisKey, DateUtils.getTime(), 60 * 60 * 24); + } + +} \ No newline at end of file diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSAbortDuringChargingPhaseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSAbortDuringChargingPhaseHandler.java new file mode 100644 index 000000000..71a2dfd8a --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSAbortDuringChargingPhaseHandler.java @@ -0,0 +1,96 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數闃舵 BMS 涓Handler + * + * GBT-27930 鍏呯數妗╀笌 BMS 鍏呯數闃舵 BMS 涓鎶ユ枃 + * @author JS-ZZA + * @date 2022/9/19 13:32 + */ +@Slf4j +@Component +public class BMSAbortDuringChargingPhaseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.BMS_ABORT_DURING_CHARGING_PHASE_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍏呯數闃舵 BMS 涓===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String orderCode = BytesUtil.bcd2Str(serialNumByteArr); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorCode = BytesUtil.bcd2Str(pileConnectorNumByteArr); + + /** + * BMS 涓鍏呯數鍘熷洜 + * 1-2 浣嶁斺旀墍闇姹傜殑 SOC 鐩爣鍊 + * 3-4 浣嶁斺旇揪鍒版荤數鍘嬬殑璁惧畾鍊 + * 5-6 浣嶁斺旇揪鍒板崟浣撶數鍘嬭瀹氬 + * 7-8 浣嶁斺斿厖鐢垫満涓诲姩涓 + */ + startIndex += length; + byte[] BMSStopReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + + /** + * BMS 涓鍏呯數鏁呴殰鍘熷洜 + * 1-2 浣嶁斺旂粷缂樻晠闅 + * 3-4 浣嶁斺旇緭鍑鸿繛鎺ュ櫒杩囨俯鏁呴殰 + * 5-6 浣嶁斺擝MS 鍏冧欢銆佽緭鍑鸿繛鎺 鍣ㄨ繃娓 + * 7-8 浣嶁斺斿厖鐢佃繛鎺ュ櫒鏁呴殰 + * 9-10 浣嶁斺旂數姹犵粍娓╁害杩囬珮鏁呴殰 + * 11-12 浣嶁斺旈珮鍘嬬户鐢靛櫒鏁呴殰 + * 13-14 浣嶁斺旀娴嬬偣 2 鐢靛帇妫娴嬫晠闅 + * 15-16 浣嶁斺斿叾浠栨晠闅 + */ + startIndex += length; + length = 2; + byte[] BMSStopFaultReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + /** + * BMS 涓鍏呯數閿欒鍘熷洜 + * 1-2 浣嶁斺旂數娴佽繃澶 + * 3-4 浣嶁斺旂數鍘嬪紓甯 + * 5-8 浣嶁斺旈鐣欎綅 + */ + startIndex += length; + byte[] BMSStopErrorReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSDemandAndChargerOutputHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSDemandAndChargerOutputHandler.java new file mode 100644 index 000000000..9ce2e1b3e --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSDemandAndChargerOutputHandler.java @@ -0,0 +1,108 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數杩囩▼ BMS 闇姹備笌鍏呯數鏈鸿緭鍑 0x23 + * + * GBT-27930 鍏呯數妗╀笌 BMS 鍏呯數杩囩▼ BMS 闇姹傘佸厖鐢垫満杈撳嚭 + * @author JS-ZZA + * @date 2022/9/19 13:51 + */ +@Slf4j +@Component +public class BMSDemandAndChargerOutputHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PROCESS_BMS_DEMAND_AND_CHARGER_OUTPUT_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍏呯數杩囩▼ BMS 闇姹備笌鍏呯數鏈鸿緭鍑===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢靛帇闇姹 0.1 V/浣嶏紝 0 V 鍋忕Щ閲 + startIndex += length; + length = 2; + byte[] bmsVoltageDemandByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫祦闇姹 0.1 A/浣嶏紝 -400 A 鍋忕Щ閲 + startIndex += length; + byte[] bmsCurrentDemandByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鍏呯數妯″紡 0x01锛氭亽鍘嬪厖鐢碉紱 0x02锛氭亽娴佸厖鐢 + startIndex += length; + length = 1; + byte[] bmsChargingModelByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鍏呯數鐢靛帇娴嬮噺鍊 0.1 V/浣嶏紝 0 V 鍋忕Щ閲 + startIndex += length; + length = 2; + byte[] bmsChargingVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鍏呯數鐢垫祦娴嬮噺鍊 0.1 A/浣嶏紝 -400 A 鍋忕Щ閲 + startIndex += length; + byte[] bmsChargingCurrentByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏈楂樺崟浣撳姩鍔涜搫鐢垫睜鐢靛帇鍙婄粍鍙 1-12 浣嶏細鏈楂樺崟浣撳姩鍔涜搫鐢垫睜鐢靛帇锛 鏁版嵁鍒嗚鲸鐜囷細 0.01 V/浣嶏紝 0 V 鍋忕Щ閲忥紱鏁版嵁鑼冨洿锛 0~24 V锛 13-16 浣嶏細 鏈楂樺崟浣撳姩鍔涜搫鐢垫睜鐢 鍘嬫墍鍦ㄧ粍鍙凤紝鏁版嵁鍒嗚鲸鐜囷細 1/浣嶏紝 0 鍋忕Щ閲忥紱鏁版嵁鑼冨洿锛 0~15 + startIndex += length; + byte[] bmsMaxVoltageAndGroupNum = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 褰撳墠鑽风數鐘舵 SOC锛 %锛 1%/浣嶏紝 0%鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 0~100% + startIndex += length; + length = 1; + byte[] socByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 浼扮畻鍓╀綑鍏呯數鏃堕棿 1 min/浣嶏紝 0 min 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 0~600 min + startIndex += length; + length = 2; + byte[] bmsTheRestChargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々鐢靛帇杈撳嚭鍊 0.1 V/浣嶏紝 0 V 鍋忕Щ閲 + startIndex += length; + byte[] pileVoltageOutputByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々鐢垫祦杈撳嚭鍊 0.1 A/浣嶏紝 -400 A 鍋忕Щ閲 + startIndex += length; + byte[] pileCurrentOutputByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 绱鍏呯數鏃堕棿 1 min/浣嶏紝 0 min 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 0~600 min + startIndex += length; + byte[] chargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSInformationHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSInformationHandler.java new file mode 100644 index 000000000..6182d838f --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BMSInformationHandler.java @@ -0,0 +1,99 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數杩囩▼ BMS 淇℃伅 0x25 + * + * GBT-27930 鍏呯數妗╀笌 BMS 鍏呯數杩囩▼ BMS 淇℃伅 + * @author JS-ZZA + * @date 2022/9/19 13:53 + */ +@Slf4j +@Component +public class BMSInformationHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PROCESS_BMS_INFORMATION_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍏呯數杩囩▼ BMS 淇℃伅===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏈楂樺崟浣撳姩鍔涜搫鐢垫睜鐢靛帇鎵鍦ㄧ紪鍙 1/浣嶏紝 1 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 1~256 + startIndex += length; + byte[] BMSMaxVoltageNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏈楂樺姩鍔涜搫鐢垫睜娓╁害 1潞C/浣嶏紝 -50 潞C 鍋忕Щ閲忥紱鏁版嵁鑼 鍥达細 -50 潞C ~+200 潞C + startIndex += length; + byte[] BMSMaxBatteryTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鏈楂樻俯搴︽娴嬬偣缂栧彿 1/浣嶏紝 1 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 1~128 + startIndex += length; + byte[] maxTemperatureDetectionNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鏈浣庡姩鍔涜搫鐢垫睜娓╁害 1潞C/浣嶏紝 -50 潞C 鍋忕Щ閲忥紱鏁版嵁鑼 鍥达細 -50 潞C ~+200 潞C + startIndex += length; + byte[] minBatteryTemperature = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鏈浣庡姩鍔涜搫鐢垫睜娓╁害妫娴嬬偣缂栧彿 1/浣嶏紝 1 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 1~128 + startIndex += length; + byte[] minTemperatureDetectionNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + /** + * 9-12 + * 9: BMS 鍗曚綋鍔ㄥ姏钃勭數姹犵數鍘嬭繃楂 /杩囦綆 (<00> 锛=姝e父 ; <01> 锛=杩囬珮 ; <10>锛 =杩囦綆) + * 10: BMS 鏁磋溅鍔ㄥ姏钃勭數姹犺嵎鐢电姸鎬 SOC 杩囬珮/杩囦綆 (<00> 锛=姝e父 ; <01> 锛=杩囬珮 ; <10>锛 =杩囦綆) + * 11: BMS 鍔ㄥ姏钃勭數姹犲厖鐢佃繃鐢垫祦 (<00> 锛=姝e父 ; <01> 锛=杩囨祦 ; <10>锛 =涓嶅彲淇$姸鎬) + * 12: BMS 鍔ㄥ姏钃勭數姹犳俯搴﹁繃楂 (<00> 锛=姝e父 ; <01> 锛=杩囨祦 ; <10>锛 =涓嶅彲淇$姸鎬) + */ + startIndex += length; + byte[] numNineToTwelve = BytesUtil.copyBytes(msgBody, startIndex, length); + + /** + * 13-16 + * 13: BMS 鍔ㄥ姏钃勭數姹犵粷缂樼姸鎬 (<00> 锛=姝e父 ; <01> 锛=杩囨祦 ; <10>锛 =涓嶅彲淇$姸鎬) + * 14: BMS 鍔ㄥ姏钃勭數姹犵粍杈撳嚭杩炴帴鍣ㄨ繛鎺ョ姸鎬 (<00> 锛=姝e父 ; <01> 锛=杩囨祦 ; <10>锛 =涓嶅彲淇$姸鎬) + * 15: 鍏呯數绂佹 (<00>锛 =绂佹; <01>锛 =鍏佽) + * 16: 棰勭暀浣 00 + */ + startIndex += length; + byte[] numThirteenToSixteen = BytesUtil.copyBytes(msgBody, startIndex, length); + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateRequestHandler.java new file mode 100644 index 000000000..13b87e24e --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateRequestHandler.java @@ -0,0 +1,78 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.command.ykc.IssueQRCodeCommand; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; +import com.jsowell.pile.service.IPileBillingTemplateService; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 璁¤垂妯℃澘璇锋眰 Handler + * + * @author JS-ZZA + * @date 2022/9/17 15:59 + */ +@Slf4j +@Component +public class BillingTemplateRequestHandler extends AbstractHandler{ + + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.BILLING_TEMPLATE_CODE.getBytes()); + + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鎵ц璁¤垂妯℃澘璇锋眰閫昏緫===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣擄紙姝よ姹傛秷鎭綋鍙湁妗╃紪鐮侊級 + byte[] pileSnByte = ykcDataProtocol.getMsgBody(); + String pileSn = BytesUtil.binary(pileSnByte, 16); + // log.info("妗╁彿锛歿}", pileSn); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏍规嵁妗╁彿鏌ヨ璁¤垂妯℃澘 + BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn); + if (billingTemplateVO == null) { + log.warn("鏍规嵁妗╁彿锛歿}锛屾煡璇㈣璐规ā鏉夸负null", pileSn); + return null; + } + + // log.info("涓嬮潰杩涜涓嬪彂浜岀淮鐮 pileSn:{}, thread:{}", pileSn, Thread.currentThread().getName()); + // CompletableFuture.runAsync(() -> { + // try { + // Thread.sleep(200); + // } catch (InterruptedException e) { + // e.printStackTrace(); + // } + // // 涓嬪彂浜岀淮鐮 + // IssueQRCodeCommand issueQRCodeCommand = IssueQRCodeCommand.builder().pileSn(pileSn).build(); + // ykcPushCommandService.pushIssueQRCodeCommand(issueQRCodeCommand); + // }); + + byte[] messageBody = pileBillingTemplateService.generateBillingTemplateMsgBody(pileSn, billingTemplateVO); + + return getResult(ykcDataProtocol, messageBody); + } + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateResponseHandler.java new file mode 100644 index 000000000..ab3094c70 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateResponseHandler.java @@ -0,0 +1,48 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 璁¤垂妯″瀷璁剧疆搴旂瓟 + * + * @author JS-ZZA + * @date 2022/9/27 11:31 + */ +@Slf4j +@Component +public class BillingTemplateResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.BILLING_TEMPLATE_SETTING_ANSWER_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鎵ц璁¤垂妯″瀷璁剧疆搴旂瓟閫昏緫===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, 0, 7); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 璁剧疆缁撴灉 0x00 澶辫触 0x01 鎴愬姛 + byte[] settingResultByteArr = BytesUtil.copyBytes(msgBody, 7, 1); + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateSettingHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateSettingHandler.java new file mode 100644 index 000000000..b83c0d9a5 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateSettingHandler.java @@ -0,0 +1,61 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 璁¤垂妯″瀷璁剧疆 + * + * 鐢ㄦ埛鍏呯數璐圭敤璁$畻锛屾瘡鍗婂皬鏃朵负涓涓垂鐜囨锛屽叡 48 娈碉紝姣忔瀵瑰簲灏栧嘲骞宠胺鍏朵腑涓涓垂鐜 鍏呯數鏃舵々灞忓箷鎸夋璐圭巼鍒嗗埆鏄剧ず宸插厖鐢佃垂鍜屾湇鍔¤垂 + * + * @author JS-ZZA + * @date 2022/9/19 15:17 + */ +@Slf4j +@Component +public class BillingTemplateSettingHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.BILLING_TEMPLATE_SETTING_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鎵ц璁¤垂妯″瀷璁剧疆閫昏緫===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鍙 + + // 璁¤垂妯″瀷缂栫爜 + + // 灏栫數璐硅垂鐜 绮剧‘鍒颁簲浣嶅皬鏁 + + // 灏栨湇鍔¤垂璐圭巼 + + // 宄扮數璐硅垂鐜 + + // 宄版湇鍔¤垂璐圭巼 + + // 骞崇數璐硅垂鐜 + + // 骞虫湇鍔¤垂璐圭巼 + + // 璋风數璐硅垂鐜 + + // 璋锋湇鍔¤垂璐圭巼 + + // 璁℃崯姣斾緥 + + // 48涓椂娈佃垂鐜囧彿 0锛氬皷璐圭巼 1锛氬嘲璐圭巼 2锛氬钩璐圭巼 3锛氳胺璐圭巼 + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateValidateRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateValidateRequestHandler.java new file mode 100644 index 000000000..d00bef543 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/BillingTemplateValidateRequestHandler.java @@ -0,0 +1,89 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; +import com.jsowell.pile.service.IPileBillingTemplateService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 璁¤垂妯℃澘楠岃瘉璇锋眰Handler + * + * @author JS-ZZA + * @date 2022/9/17 14:10 + */ +@Slf4j +@Component +public class BillingTemplateValidateRequestHandler extends AbstractHandler{ + + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.BILLING_TEMPLATE_VALIDATE_CODE.getBytes()); + + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + + log.info("[===鎵ц璁¤垂妯℃澘楠岃瘉璇锋眰閫昏緫===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╁彿 + byte[] pileSnByte = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.binary(pileSnByte, 16); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 璁¤垂妯″瀷缂栫爜 + startIndex += length; + length = 2; + byte[] billingTemplateCodeByte = BytesUtil.copyBytes(msgBody, startIndex, length); + String billingTemplateCode = BytesUtil.binary(billingTemplateCodeByte, 16); + + // 鏍规嵁妗╁彿鏌ヨ璁¤垂妯℃澘 + // BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn); + // String templateCode = null; + // if (billingTemplateVO != null) { + // templateCode = billingTemplateVO.getTemplateCode(); + // } + + + // log.info("妗╀紶鐨勮璐规ā鍨嬬紪鐮侊細{}, 鏍规嵁妗╁彿:{} 鏌ヨ鍒扮殑璁¤垂妯″瀷缂栫爜锛歿}", billingTemplateCode, pileSn, templateCode); + // log.info("妗╀紶鐨勮璐规ā鍨嬬紪鐮侊細{}", billingTemplateCode); + + /** + * 搴旂瓟 0x00 妗╄璐规ā鍨嬩笌骞冲彴涓鑷 0x01 妗╄璐规ā鍨嬩笌骞冲彴涓嶄竴鑷 + */ + // byte[] flag; + // if (StringUtils.equals(billingTemplateCode, "100")){ + // flag = Constants.zeroByteArray; + // }else { + // } + byte[] flag = Constants.oneByteArray; + // 娑堟伅浣 + byte[] messageBody = Bytes.concat(pileSnByte, billingTemplateCodeByte, flag); + return getResult(ykcDataProtocol, messageBody); + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargeEndHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargeEndHandler.java new file mode 100644 index 000000000..778528ef6 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargeEndHandler.java @@ -0,0 +1,121 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.service.IOrderBasicInfoService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.Objects; + +/** + * 鍏呯數缁撴潫Handler + * + * GBT-27930 鍏呯數妗╀笌 BMS 鍏呯數缁撴潫闃舵鎶ユ枃 + * @author JS-ZZA + * @date 2022/9/19 13:27 + */ +@Slf4j +@Component +public class ChargeEndHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGE_END_CODE.getBytes()); + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鎵ц鍏呯數缁撴潫閫昏緫===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String orderCode = BytesUtil.bcd2Str(serialNumByteArr); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr); + + // BMS涓鑽风數鐘舵 SOC 1%/浣嶏紝 0%鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 0~100% + startIndex += length; + byte[] BMSStopChargingSOC = BytesUtil.copyBytes(msgBody, startIndex, length); + String stopSoc = BytesUtil.binary(BMSStopChargingSOC, 10); + + // BMS 鍔ㄥ姏钃勭數姹犲崟浣撴渶浣庣數鍘 0.01 V/浣嶏紝 0 V 鍋忕Щ閲忥紱鏁版嵁鑼冨洿锛 0 ~24 V + startIndex += length; + length = 2; + byte[] BMSBatteryMinVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鍔ㄥ姏钃勭數姹犲崟浣撴渶楂樼數鍘 0.01 V/浣嶏紝 0 V 鍋忕Щ閲忥紱鏁版嵁鑼冨洿锛 0 ~24 V + startIndex += length; + byte[] BMSBatteryMaxVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鍔ㄥ姏钃勭數姹犳渶浣庢俯搴 1潞C/浣嶏紝 -50 潞C 鍋忕Щ閲忥紱鏁版嵁鑼冨洿锛 -50 潞C ~+200 潞C + startIndex += length; + length = 1; + byte[] BMSBatteryMinTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鍔ㄥ姏钃勭數姹犳渶楂樻俯搴 1潞C/浣嶏紝 -50 潞C 鍋忕Щ閲忥紱鏁版嵁鑼冨洿锛 -50 潞C ~+200 潞C + startIndex += length; + byte[] BMSBatteryMaxTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々绱鍏呯數鏃堕棿 1 min/浣嶏紝 0 min 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 0~600 min + startIndex += length; + length = 2; + byte[] pileSumChargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々杈撳嚭鑳介噺 0.1 kWh/浣嶏紝 0 kWh 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 0~1000 kWh + startIndex += length; + byte[] pileOutputEnergyByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々鍏呯數鏈虹紪鍙 鍏呯數鏈虹紪鍙凤紝 1/浣嶏紝 1鍋忕Щ閲 锛屾暟鎹寖鍥 锛 0 锝 0xFFFFFFFF + startIndex += length; + length = 4; + byte[] pileChargedCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鏌ヨ璁㈠崟锛屾敼涓哄緟缁撶畻 灏嗙粨鏉焥oc浼犲叆 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (Objects.nonNull(orderInfo)) { + if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) { + orderInfo.setOrderStatus(OrderStatusEnum.STAY_SETTLEMENT.getValue()); + } + orderInfo.setEndSOC(stopSoc); + if (orderInfo.getChargeEndTime() == null) { + orderInfo.setChargeEndTime(new Date()); // 缁撴潫鍏呯數鏃堕棿 + } + orderBasicInfoService.updateOrderBasicInfo(orderInfo); + } + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargerAbortedDuringChargingPhaseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargerAbortedDuringChargingPhaseHandler.java new file mode 100644 index 000000000..4e8218ed4 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargerAbortedDuringChargingPhaseHandler.java @@ -0,0 +1,93 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數闃舵鍏呯數鏈轰腑姝andler 0x21 + * + * GBT-27930 鍏呯數妗╀笌 BMS 鍏呯數闃舵鍏呯數鏈轰腑姝㈡姤鏂 + * @author JS-ZZA + * @date 2022/9/19 13:35 + */ +@Slf4j +@Component +public class ChargerAbortedDuringChargingPhaseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.THE_CHARGER_IS_ABORTED_DURING_THE_CHARGING_PHASE_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍏呯數闃舵鍏呯數鏈轰腑姝===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + /** + * BMS 涓鍏呯數鍘熷洜 + * 1-2 浣嶁斺旇揪鍒板厖鐢垫満璁惧畾 鐨勬潯浠朵腑姝 + * 3-4 浣嶁斺斾汉宸ヤ腑姝 + * 5-6 浣嶁斺斿紓甯镐腑姝 + * 7-8 浣嶁斺擝MS 涓诲姩涓 + */ + startIndex += length; + byte[] BMSStopChargingReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + /** + * BMS 涓鍏呯數鏁呴殰鍘熷洜 + * 1-2 浣嶁斺斿厖鐢垫満杩囨俯鏁呴殰 + * 3-4 浣嶁斺斿厖鐢佃繛鎺ュ櫒鏁呴殰 + * 5-6 浣嶁斺斿厖鐢垫満鍐呴儴杩囨俯鏁呴殰 + * 7-8 浣嶁斺旀墍闇鐢甸噺涓 鑳戒紶閫 + * 9-10 浣嶁斺斿厖鐢垫満鎬ュ仠鏁呴殰 + * 11-12 浣嶁斺斿叾浠栨晠闅 + * 13-16 浣嶁斺旈鐣欎綅 + */ + startIndex += length; + length = 2; + byte[] BMSStopChargingFaultReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + /** + * BMS 涓鍏呯數閿欒鍘熷洜 + * 1-2 浣嶁斺旂數娴佷笉鍖归厤 + * 3-4 浣嶁斺旂數鍘嬪紓甯 + * 5-8 浣嶁斺旈鐣欎綅 + */ + startIndex += length; + length = 1; + byte[] BMSStopChargingErrorReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargingHandshakeHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargingHandshakeHandler.java new file mode 100644 index 000000000..f989baa33 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ChargingHandshakeHandler.java @@ -0,0 +1,125 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數鎻℃墜 + * + * GBT-27930 鍏呯數妗╀笌 BMS 鍏呯數鎻℃墜闃舵鎶ユ枃 + * @author JS-ZZA + * @date 2022/9/19 13:20 + */ +@Slf4j +@Component +public class ChargingHandshakeHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_HANDSHAKE_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鎵ц鍏呯數鎻℃墜閫昏緫===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 閫氫俊鍗忚鐗堟湰鍙 褰撳墠鐗堟湰涓 V1.1锛 琛ㄧず涓猴細 byte3锛 byte2鈥0001H锛沚yte1鈥01H + startIndex += length; + length = 3; + byte[] BMSCommunicationProtocolVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫睜绫诲瀷 01H:閾呴吀鐢垫睜;02H:姘 鐢垫睜;03H:纾烽吀閾侀攤鐢垫睜;04H:閿 閰搁攤鐢垫睜;05H:閽撮吀閿傜數姹 ;06H: 涓夊厓鏉愭枡鐢垫睜;07H:鑱氬悎鐗╅攤绂诲瓙 鐢垫睜;08H:閽涢吀閿傜數姹;FFH:鍏朵粬 + startIndex += length; + length = 1; + byte[] BMSBatteryTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏁磋溅鍔ㄥ姏钃勭數姹犵郴缁熼瀹氬閲 0.1 Ah /浣嶏紝 0 Ah 鍋忕Щ閲 + startIndex += length; + length = 2; + byte[] BMSBatteryCapacityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏁磋溅鍔ㄥ姏钃勭數姹犵郴缁熼瀹氭荤數鍘 0.1V/浣嶏紝 0V 鍋忕Щ閲 + startIndex += length; + byte[] BMSBatteryVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫睜鐢熶骇鍘傚晢鍚嶇О + startIndex += length; + length = 4; + byte[] BMSBatteryFactoryByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫睜缁勫簭鍙 + startIndex += length; + byte[] BMSBatteryNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫睜缁勭敓浜ф棩鏈熷勾 1985 骞村亸绉婚噺锛 鏁版嵁鑼冨洿锛 1985锝 2235 骞 + startIndex += length; + length = 1; + byte[] BMSProductionDateYearByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫睜缁勭敓浜ф棩鏈熸湀 0 鏈堝亸绉婚噺锛 鏁版嵁鑼冨洿锛 1锝12 鏈 + startIndex += length; + byte[] BMSProductionDateMonthByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫睜缁勭敓浜ф棩鏈熸棩 0 鏃ュ亸绉婚噺锛 鏁版嵁鑼冨洿锛 1锝31 鏃 + startIndex += length; + byte[] BMSProductionDateDayByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫睜缁勫厖鐢垫鏁 1 娆/浣嶏紝 0 娆″亸绉婚噺锛 浠 BMS 缁 璁′负鍑 + startIndex += length; + length = 3; + byte[] BMSChargingTimesByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鐢垫睜缁勪骇鏉冩爣璇 锛<0>锛 =绉熻祦锛 <1>锛 =杞﹁嚜鏈夛級 + startIndex += length; + length = 1; + byte[] BMSPropertyIdentificationByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 棰勭暀浣 + startIndex += length; + byte[] BMSReservePosition = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 杞﹁締璇嗗埆鐮 + startIndex += length; + length = 17; + byte[] BMSCarIdentifyCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 杞欢鐗堟湰鍙 + startIndex += length; + length = 8; + byte[] BMSSoftwareVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/ConfirmStartChargingRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ConfirmStartChargingRequestHandler.java new file mode 100644 index 000000000..bc33fe23e --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ConfirmStartChargingRequestHandler.java @@ -0,0 +1,135 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.common.util.id.IdUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.service.impl.MemberBasicInfoServiceImpl; +import com.jsowell.pile.vo.uniapp.MemberVO; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; + +/** + * 鍏呯數妗╀富鍔ㄧ敵璇峰惎鍔ㄥ厖鐢 0x31 + * + * 鍚姩鍏呯數閴存潈缁撴灉 + * @author JS-ZZA + * @date 2022/9/19 14:29 + */ +@Slf4j +@Component +public class ConfirmStartChargingRequestHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REQUEST_START_CHARGING_CODE.getBytes()); + + @Autowired + private MemberBasicInfoServiceImpl memberBasicInfoService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍏呯數妗╀富鍔ㄧ敵璇峰惎鍔ㄥ厖鐢===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorCode = BytesUtil.bcd2Str(pileConnectorNumByteArr); + + // 鍚姩鏂瑰紡 + // 0x01 琛ㄧず閫氳繃鍒峰崱鍚姩鍏呯數 + // 0x02 琛ㄦ眰閫氳繃甯愬彿鍚姩鍏呯數 锛堟殏涓嶆敮鎸侊級 + // 0x03 琛ㄧずvin鐮佸惎鍔ㄥ厖鐢 + startIndex += length; + length = 1; + byte[] startModeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鏄惁闇瑕佸瘑鐮 0x00 涓嶉渶瑕 0x01 闇瑕 + startIndex += length; + byte[] needPasswordFlagByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐗╃悊鍗″彿 涓嶈冻 8 浣嶈ˉ 0 + startIndex += length; + length = 8; + byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String physicsCardNum = BytesUtil.bcd2Str(cardNumByteArr); + + // 杈撳叆瀵嗙爜 瀵圭敤鎴疯緭鍏ョ殑瀵嗙爜杩涜16 浣峂D5 鍔犲瘑锛岄噰鐢ㄥ皬鍐欎笂浼 + startIndex += length; + length = 16; + byte[] inputPasswordByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // VIN鐮 + startIndex += length; + length = 17; + byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + + // 搴旂瓟 + // 浜ゆ槗娴佹按鍙 + String serialNum = IdUtils.generateOrderCode(pileSn, connectorCode); + byte[] serialNumByteArr = BytesUtil.str2Bcd(serialNum); + + // 閫昏緫鍗″彿 + String logicCardNum = "00000000"; + byte[] logicCardNumByteArr = BytesUtil.str2Bcd(logicCardNum); // [0, 0, 0, 0] + + // 璐︽埛浣欓 淇濈暀涓や綅灏忔暟 + MemberVO memberVO = memberBasicInfoService.selectInfoByPhysicsCard(physicsCardNum); + BigDecimal principalBalance = memberVO.getPrincipalBalance(); // 鏈噾閲戦 + double accountBalance = principalBalance.add(memberVO.getGiftBalance()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + byte[] accountBalanceByteArr = BytesUtil.str2Bcd(String.valueOf(accountBalance)); + + // 閴存潈鎴愬姛鏍囪瘑 0x00 澶辫触 0x01 鎴愬姛 + byte[] authenticationFlagByteArr= Constants.oneByteArray; + + /** + * 澶辫触鍘熷洜 + * 0x01 璐︽埛涓嶅瓨鍦 + * 0x02 璐︽埛鍐荤粨 + * 0x03 璐︽埛浣欓涓嶈冻 + * 0x04 璇ュ崱瀛樺湪鏈粨璐﹁褰 + * 0x05 妗╁仠鐢 + * 0x06 璇ヨ处鎴蜂笉鑳藉湪姝ゆ々涓婂厖鐢 + * 0x07 瀵嗙爜閿欒 + * 0x08 鐢电珯鐢靛涓嶈冻 + * 0x09 绯荤粺涓璿in 鐮佷笉瀛樺湪 + * 0x0A 璇ユ々瀛樺湪鏈粨璐﹁褰 + * 0x0B 璇ユ々涓嶆敮鎸佸埛鍗 + */ + byte[] defeatReasonByteArr = Constants.zeroByteArray; + + // 鎷艰娑堟伅浣 + byte[] msgBodyByteArr = Bytes.concat(serialNumByteArr, logicCardNumByteArr, accountBalanceByteArr, + authenticationFlagByteArr, defeatReasonByteArr); + + return getResult(ykcDataProtocol, msgBodyByteArr); + + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/ErrorMessageHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ErrorMessageHandler.java new file mode 100644 index 000000000..97e038d20 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ErrorMessageHandler.java @@ -0,0 +1,93 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 閿欒鎶ユ枃Handler + * + * GBT-27930 鍏呯數妗╀笌 BMS 鍏呯數閿欒鎶ユ枃 + * @author JS-ZZA + * @date 2022/9/19 13:29 + */ +@Slf4j +@Component +public class ErrorMessageHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.ERROR_MESSAGE_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===閿欒鎶ユ枃===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + + byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴忓彿4-6 <00>锛 =姝e父锛 <01>锛 =瓒呮椂锛 <10>锛 =涓嶅彲淇$姸鎬 + startIndex += length; + byte[] NumFourToSix = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴忓彿7-9 + startIndex += length; + byte[] NumSevenToNine = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴忓彿10-12 + startIndex += length; + byte[] NumTenToTwelve = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴忓彿13-14 + startIndex += length; + byte[] NumThirteenToFourteen = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴忓彿15-16 + startIndex += length; + byte[] NumFifteenToSixteen = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴忓彿17-19 + startIndex += length; + byte[] NumSeventeenToNineteen = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴忓彿20-23 + startIndex += length; + byte[] NumTwentyToTwentyThree = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴忓彿24-25 + startIndex += length; + byte[] NumTwentyFourToTwentyFive = BytesUtil.copyBytes(msgBody, startIndex, length); + + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/GroundLockDataUploadHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/GroundLockDataUploadHandler.java new file mode 100644 index 000000000..adff001ab --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/GroundLockDataUploadHandler.java @@ -0,0 +1,58 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍦伴攣鏁版嵁涓婇 + * + * 鍦伴攣鐘舵/鎶ヨ淇℃伅鍙樺寲鏃讹紝妗╃珛鍒讳笂閫佸彉浣/鎶ヨ淇℃伅锛涘湴閿佺姸鎬佷笉鍙樺寲鏃讹紝姣忛殧 5 鍒嗛挓鍛ㄦ湡 鎬т笂閫佸湴閿佺姸鎬併傝嫢鏃犳姤璀︿俊鎭紝涓嶄笂閫併 + * + * @author JS-ZZA + * @date 2022/9/19 15:21 + */ +@Slf4j +@Component +public class GroundLockDataUploadHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.GROUND_LOCK_DATA_UPLOAD_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍦伴攣鏁版嵁涓婇===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + // 妗╃紪鐮 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, 0, 7); + // 鏋彿 + byte[] connectorByteArr = BytesUtil.copyBytes(msgBody, 7, 1); + /** + * 杞︿綅閿佺姸鎬 + * 0x00锛氭湭鍒颁綅鐘舵 + * 0x55锛氬崌閿佸埌浣嶇姸鎬 + * 0xFF锛氶檷閿佸埌浣嶇姸鎬 + */ + byte[] parkingLockStatusByteArr = BytesUtil.copyBytes(msgBody, 8, 1); + // 杞︿綅鐘舵 0x00锛氭棤杞﹁締 0xFF锛氬仠鏀捐溅杈 + byte[] parkingStatusByteArr = BytesUtil.copyBytes(msgBody, 9, 1); + // 鍦伴攣鐢甸噺鐘舵 鐧惧垎姣斿0~100 + byte[] groundLockElectricByteArr = BytesUtil.copyBytes(msgBody, 10, 1); + // 鎶ヨ鐘舵 0x00锛氭甯告棤鎶ヨ 0xFF锛氬緟鏈虹姸鎬佹憞鑷傜牬鍧 0x55锛氭憞鑷傚崌闄嶅紓甯(鏈埌浣) + byte[] alarmStatusByteArr = BytesUtil.copyBytes(msgBody, 11, 1); + // 棰勭暀浣 鍏ㄩ儴缃0 + byte[] waitingUseByteArr = BytesUtil.copyBytes(msgBody, 12, 4); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/HeartbeatRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/HeartbeatRequestHandler.java new file mode 100644 index 000000000..ba6ebae9f --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/HeartbeatRequestHandler.java @@ -0,0 +1,83 @@ +package com.jsowell.netty.handler; + +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileConnectorInfoService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數妗╁績璺冲寘 + */ +@Slf4j +@Component +public class HeartbeatRequestHandler extends AbstractHandler { + + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.HEART_BEAT_CODE.getBytes()); + + @Autowired + private RedisCache redisCache; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + // log.info("[===鍏呯數妗╁績璺冲寘===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╁彿 + byte[] pileSnByte = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.binary(pileSnByte, 16); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByte = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileConnectorNum = String.format("%02d", Integer.parseInt(BytesUtil.binary(pileConnectorNumByte, 16))); + + //鏋姸鎬侊紙涓嶅洖澶嶏級 + startIndex += length; + length = 1; + byte[] connectorStatusByte = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorStatus = BytesUtil.binary(connectorStatusByte, 16); + // log.info("妗╁彿锛歿}, 鏋彿锛歿}, 鏋姸鎬侊細{}", pileSn, pileConnectorNum, connectorStatus); + + // updateStatus(pileSn, pileConnectorNum, connectorStatus); + + // 鍏叡鏂规硶淇敼鐘舵 + pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, pileConnectorNum, connectorStatus, null); + + // 蹇冭烦搴旂瓟锛堢疆0锛 + byte[] flag = Constants.zeroByteArray; + + // 娑堟伅浣 + byte[] messageBody = Bytes.concat(pileSnByte, pileConnectorNumByte, flag); + return getResult(ykcDataProtocol, messageBody); + } + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/LoginRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/LoginRequestHandler.java new file mode 100644 index 000000000..33817202b --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/LoginRequestHandler.java @@ -0,0 +1,189 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.Lists; +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.LoginRequestData; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.ykc.PileChannelEntity; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.command.ykc.IssueQRCodeCommand; +import com.jsowell.netty.command.ykc.ProofreadTimeCommand; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileMsgRecordService; +import com.jsowell.pile.vo.base.PileInfoVO; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@Slf4j +@Component +public class LoginRequestHandler extends AbstractHandler{ + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Autowired + private IPileMsgRecordService pileMsgRecordService; + + @Autowired + private RedisCache redisCache; + + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.LOGIN_CODE.getBytes()); + + private List newProgramVersionList = Lists.newArrayList("c6-30"); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鎵ц鐧诲綍閫昏緫===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鐮 + byte[] pileSnByte = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.binary(pileSnByte, 16); + // log.info("妗╁彿锛歿}", pileSn); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 妗╃被鍨 0 琛ㄧず鐩存祦妗╋紝 1 琛ㄧず浜ゆ祦妗 + startIndex += length; + length = 1; + byte[] pileTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileType = BytesUtil.bcd2Str(pileTypeByteArr); + + // 鍏呯數鏋暟閲 + startIndex += length; + byte[] connectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorNum = BytesUtil.bcd2Str(connectorNumByteArr); + + // 閫氫俊鍗忚鐗堟湰 鐗堟湰鍙蜂箻 10锛寁1.0 琛ㄧず 0x0A + startIndex += length; + byte[] communicationVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + // int i = Integer.parseInt(BytesUtil.bcd2Str(communicationVersionByteArr)); // 0F --> 15 + BigDecimal bigDecimal = new BigDecimal(BytesUtil.bcd2Str(communicationVersionByteArr)); + BigDecimal communicationVersionTemp = bigDecimal.divide(new BigDecimal(10)); + String communicationVersion = "v" + communicationVersionTemp; + + // 绋嬪簭鐗堟湰 + startIndex += length; + length = 8; + byte[] programVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String programVersion = BytesUtil.ascii2Str(programVersionByteArr); + // log.info("绋嬪簭鐗堟湰:{} length:{}", programVersion, programVersion.length()); + + // 缃戠粶杩炴帴绫诲瀷 0x00 SIM 鍗 0x01 LAN 0x02 WAN 0x03 鍏朵粬 + startIndex += length; + length = 1; + byte[] internetConnectionTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String internetConnection = BytesUtil.bcd2Str(internetConnectionTypeByteArr); + + // sim鍗 + startIndex += length; + length = 10; + byte[] simCardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String iccid = BytesUtil.bin2HexStr(simCardNumByteArr); + + // 杩愯惀鍟 0x00 绉诲姩 0x02 鐢典俊 0x03 鑱旈 0x04 鍏朵粬 + startIndex += length; + length = 1; + byte[] businessTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String business = BytesUtil.bcd2Str(businessTypeByteArr); + + LoginRequestData loginRequestData = LoginRequestData.builder() + .pileSn(pileSn) + .pileType(pileType) + .connectorNum(connectorNum) + .communicationVersion(communicationVersion) + .programVersion(programVersion) + .internetConnection(internetConnection) + .iccid(iccid) + .business(business) + .build(); + + // 缁撴灉锛堥粯璁 0x01:鐧诲綍澶辫触锛 + byte[] flag = Constants.oneByteArray; + + // 閫氳繃妗╃紪鐮丼N鏌ヨ鏁版嵁搴擄紝濡傛灉鏈夋暟鎹紝鍒欑櫥褰曟垚鍔燂紝鍚﹀垯鐧诲綍澶辫触 + PileInfoVO pileInfoVO = null; + try { + pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn); + } catch (Exception e) { + log.error("selectPileInfoBySn鍙戠敓寮傚父", e); + } + + if (pileInfoVO != null) { + flag = Constants.zeroByteArray; + + // 鐧诲綍鎴愬姛锛屼繚瀛樻々鍙峰拰channel鐨勫叧绯 + PileChannelEntity.put(pileSn, channel); + + // 鏇存敼妗╁拰璇ユ々涓嬬殑鏋彛鐘舵佸垎鍒负 鍦ㄧ嚎銆佺┖闂 鍏叡鏂规硶淇敼鐘舵 + pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, null, null, null); + } + + // 鍏呯數妗╀娇鐢ㄧ殑sim鍗★紝鎶婁俊鎭瓨搴 + if (StringUtils.equals("00", internetConnection)) { + try { + pileBasicInfoService.updatePileSimInfo(pileSn, iccid); + } catch (Exception e) { + log.error("鏇存柊鍏呯數妗﹕im鍗′俊鎭け璐", e); + } + } + + // 淇濆瓨鎶ユ枃 + String jsonMsg = JSONObject.toJSONString(loginRequestData); + pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ykcDataProtocol.getHEXString()); + + CompletableFuture.runAsync(() -> { + try { + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + // 瀵规椂 + ProofreadTimeCommand command = ProofreadTimeCommand.builder().pileSn(pileSn).build(); + ykcPushCommandService.pushProofreadTimeCommand(command); + }); + + // log.info("涓嬮潰杩涜涓嬪彂浜岀淮鐮 pileSn:{}, thread:{}", pileSn, Thread.currentThread().getName()); + CompletableFuture.runAsync(() -> { + try { + Thread.sleep(600); + } catch (InterruptedException e) { + e.printStackTrace(); + } + // 涓嬪彂浜岀淮鐮 + IssueQRCodeCommand issueQRCodeCommand = IssueQRCodeCommand.builder().pileSn(pileSn).build(); + ykcPushCommandService.pushIssueQRCodeCommand(issueQRCodeCommand); + }); + + // 娑堟伅浣 + byte[] messageBody = Bytes.concat(pileSnByte, flag); + return getResult(ykcDataProtocol, messageBody); + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataCleaningHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataCleaningHandler.java new file mode 100644 index 000000000..7e27da875 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataCleaningHandler.java @@ -0,0 +1,45 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 绂荤嚎鍗℃暟鎹竻闄 + * + * 绂荤嚎鍗℃竻闄ゆ槸骞冲彴涓诲姩涓嬪彂鐨勬搷浣滐紝骞冲彴鍦ㄥ厖鐢垫々鍦ㄧ嚎鏃朵細涓嬪彂姝ゆ暟鎹抚鍒板厖鐢垫々锛屽厖鐢垫々鎺ユ敹鍒扮绾垮崱鏁版嵁娓呴櫎鎶ユ枃鍚庢竻闄ゅ埌妗╂湰鍦板搴旂殑绂荤嚎鍗℃暟鎹 + * + * @author JS-ZZA + * @date 2022/9/19 14:54 + */ +@Slf4j +@Component +public class OfflineCardDataCleaningHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.OFFLINE_CARD_DATA_CLEANING_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===绂荤嚎鍗℃暟鎹竻闄===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鍙 + + // 娓呴櫎绂荤嚎鍗$殑涓暟 + + // 绗 1 涓崱鐗╃悊鍗″彿 + + // 绗 N 涓崱鐗╃悊鍗″彿 + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataCleaningResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataCleaningResponseHandler.java new file mode 100644 index 000000000..597e31ba6 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataCleaningResponseHandler.java @@ -0,0 +1,69 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 绂荤嚎鍗℃暟鎹竻闄ゅ簲绛 + * + * @author JS-ZZA + * @date 2022/9/27 9:59 + */ +@Slf4j +@Component +public class OfflineCardDataCleaningResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.OFFLINE_CARD_DATA_CLEANING_ANSWER_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===绂荤嚎鍗℃暟鎹竻闄ゅ簲绛===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鐮 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 绗 1 涓崱鐗╃悊鍗″彿 + startIndex += length; + length = 8; + byte[] firstCardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 娓呴櫎鏍囪 0x00 娓呴櫎澶辫触 0x01 娓呴櫎鎴愬姛 + startIndex += length; + length = 1; + byte[] cleanFlagByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 澶辫触鍘熷洜 0x01 鍗″彿鏍煎紡閿欒 0x02 娓呴櫎鎴愬姛 + startIndex += length; + byte[] failedReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 绗琋涓墿鐞嗗崱鍙 + + // 娓呴櫎鏍囪 + + // 澶辫触鍘熷洜 + + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataQueryHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataQueryHandler.java new file mode 100644 index 000000000..0b8a1bc56 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataQueryHandler.java @@ -0,0 +1,46 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 绂荤嚎鍗℃暟鎹煡璇 + * + * 绂荤嚎鍗℃暟鎹煡璇㈢敱骞冲彴涓诲姩鍚戞々鍙戣捣鐨勬煡璇㈣姹傦紝 骞冲彴鍦ㄥ厖鐢垫々鍦ㄧ嚎鏃朵細鎸夐渶涓嬪彂姝ゆ暟鎹抚鍒板厖鐢垫々锛 + * 妗╂帴鏀跺埌璇ユ姤鏂囧悗杩涜鏌ヨ妗╂湰鍦版槸鍚﹀瓨鍦ㄥ搴旂殑绂荤嚎鍗 + * + * @author JS-ZZA + * @date 2022/9/27 10:18 + */ +@Slf4j +@Component +public class OfflineCardDataQueryHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.OFFLINE_CARD_DATA_QUERY_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===绂荤嚎鍗℃暟鎹煡璇===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鐮 + + // 鏌ヨ鐨勭绾垮崱涓暟 + + // 绗竴涓墿鐞嗗崱鍙 + + // 绗琋涓墿鐞嗗崱鍙 + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataQueryResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataQueryResponseHandler.java new file mode 100644 index 000000000..81d7d1972 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataQueryResponseHandler.java @@ -0,0 +1,60 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 绂荤嚎鍗℃暟鎹煡璇㈠簲绛 + * + * @author JS-ZZA + * @date 2022/9/27 10:20 + */ +@Slf4j +@Component +public class OfflineCardDataQueryResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.OFFLINE_CARD_DATA_QUERY_ANSWER_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===绂荤嚎鍗℃暟鎹煡璇㈠簲绛===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 绗1涓崱鐗╃悊鍗″彿 + startIndex += length; + length = 8; + byte[] firstCardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鏌ヨ缁撴灉 + startIndex += length; + length = 1; + byte[] firstCardResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 绗琋+1涓崱鐗╃悊鍗″彿 + // 鏌ヨ缁撴灉 + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataSynchronizationHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataSynchronizationHandler.java new file mode 100644 index 000000000..6acb5846b --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataSynchronizationHandler.java @@ -0,0 +1,46 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 绂荤嚎鍗℃暟鎹悓姝 + * + * 绂荤嚎鍗¢傜敤浜庢々绂荤嚎鍏呯數妯″紡锛 骞冲彴鍦ㄥ厖鐢垫々鍦ㄧ嚎鏃朵細涓嬪彂姝ゆ暟鎹抚鍒板厖鐢垫々锛 鍏呯數妗╂帴鏀跺埌鍚庡偍瀛樼绾垮崱淇℃伅鍒版々鏈湴 + * 锛堝鏋滃凡瀛樺湪绂荤嚎鍗″垯鐢ㄦ渶鏂扮殑鏁版嵁瑕嗙洊鏈湴鏁版嵁锛 涓嶅瓨鍦ㄥ垯鎻掑叆锛夛紝 鑻ョ敤鎴峰埛鍗″厖鐢垫椂妗╁鐞嗙绾挎ā寮忥紝鍒欏埛閴存潈璧版々鏈湴杩涜鍒ゆ柇 + * + * @author JS-ZZA + * @date 2022/9/19 14:51 + */ +@Slf4j +@Component +public class OfflineCardDataSynchronizationHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.OFFLINE_CARD_DATA_SYNCHRONIZATION_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===绂荤嚎鍗℃暟鎹悓姝===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鍙 + + // 涓嬪彂鍗′釜鏁 + + // 绗竴涓崱閫昏緫鍗″彿 + + // 绗琋涓崱鐗╃悊鍗″彿 + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataSynchronizationResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataSynchronizationResponseHandler.java new file mode 100644 index 000000000..1e7384c08 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/OfflineCardDataSynchronizationResponseHandler.java @@ -0,0 +1,57 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 绂荤嚎鍗℃暟鎹悓姝ュ簲绛 + * + * @author JS-ZZA + * @date 2022/9/27 9:31 + */ +@Slf4j +@Component +public class OfflineCardDataSynchronizationResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.OFFLINE_CARD_DATA_SYNCHRONIZATION_ANSWER_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===绂荤嚎鍗℃暟鎹悓姝ュ簲绛===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + //娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鐮 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 淇濆瓨缁撴灉 0x00 澶辫触 0x01 鎴愬姛 + startIndex += length; + length = 1; + byte[] resultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 澶辫触鍘熷洜 0x01 鍗″彿鏍煎紡閿欒 0x02 鍌ㄥ瓨绌洪棿涓嶈冻 + startIndex += length; + byte[] failedReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/ParameterConfigurationHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ParameterConfigurationHandler.java new file mode 100644 index 000000000..e7677499f --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ParameterConfigurationHandler.java @@ -0,0 +1,129 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.service.IOrderBasicInfoService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +/** + * 鍙傛暟閰嶇疆 Handler + * + * GBT-27930 鍏呯數妗╀笌 BMS 鍙傛暟閰嶇疆闃舵鎶ユ枃 + * @author JS-ZZA + * @date 2022/9/19 13:24 + */ +@Slf4j +@Component +public class ParameterConfigurationHandler extends AbstractHandler{ + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.PARAMETER_CONFIGURATION_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍙傛暟閰嶇疆===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String orderCode = BytesUtil.bcd2Str(serialNumByteArr); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鍗曚綋鍔ㄥ姏钃勭數姹犳渶楂樺厑璁稿厖鐢电數鍘 0.01 V/浣嶏紝 0 V 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 0~24 V + startIndex += length; + length = 2; + byte[] BMSMaxVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏈楂樺厑璁稿厖鐢电數娴 0.1 A/浣嶏紝 -400A 鍋忕Щ閲 + startIndex += length; + byte[] BMSMaxCurrentByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鍔ㄥ姏钃勭數姹犳爣绉版昏兘閲 0.1 kWh/浣嶏紝 0 kWh 鍋忕Щ閲忥紱 鏁版嵁鑼冨洿锛 0~1000 kWh + startIndex += length; + byte[] BMSSumEnergyByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏈楂樺厑璁稿厖鐢垫荤數鍘 0.1 V/浣嶏紝 0 V 鍋忕Щ閲 + startIndex += length; + byte[] BMSMaxChargingVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏈楂樺厑璁告俯搴 1潞C/浣嶏紝 -50 潞C 鍋忕Щ閲忥紱鏁版嵁鑼 鍥达細 -50 潞C ~+200 潞C + startIndex += length; + length = 1; + byte[] BMSMaxTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // BMS 鏁磋溅鍔ㄥ姏 钃勭數姹犺嵎鐢电姸鎬(soc) 0.1%/浣嶏紝 0%鍋忕Щ閲忥紱鏁版嵁鑼冨洿锛 0~100% + startIndex += length; + length = 2; + byte[] BMSSocByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String soc = YKCUtils.convertVoltageCurrent(BMSSocByteArr); + + + // BMS 鏁磋溅鍔ㄥ姏钃勭數姹犲綋鍓嶇數姹犵數鍘 鏁磋溅鍔ㄥ姏钃勭數姹犳荤數鍘 + startIndex += length; + byte[] BMSRealTimeVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々鏈楂樿緭鍑虹數鍘 0.1 V /浣嶏紝 0 V 鍋忕Щ閲 + startIndex += length; + byte[] pileMaxOutputVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々鏈浣庤緭鍑虹數鍘 0.1 V /浣嶏紝 0 V 鍋忕Щ閲 + startIndex += length; + byte[] pileMinOutputVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々鏈澶ц緭鍑虹數娴 0.1 A/浣嶏紝 -400 A 鍋忕Щ閲 + startIndex += length; + byte[] pileMaxOutputCurrentByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐢垫々鏈灏忚緭鍑虹數娴 0.1 A/浣嶏紝 -400 A 鍋忕Щ閲 + startIndex += length; + byte[] pileMinOutputCurrentByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + log.info("鍙傛暟閰嶇疆, 璧峰SOC:{}", soc); + + // 鏌ヨ璇ヨ鍗曚笅淇℃伅锛屽皢璧峰soc浼犲叆 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (Objects.nonNull(orderInfo)) { + OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder() + .id(orderInfo.getId()) + .startSOC(soc) + .build(); + + orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo); + } + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/PileWorkingParameterSettingHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/PileWorkingParameterSettingHandler.java new file mode 100644 index 000000000..ca4cb328e --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/PileWorkingParameterSettingHandler.java @@ -0,0 +1,45 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數妗╁伐浣滃弬鏁拌缃. + * + * 杩滅▼璁剧疆鍏呯數妗╂槸鍚﹀仠鐢紱璁剧疆鍏呯數妗╁厑璁歌緭鍑哄姛鐜囷紝浠ュ疄鐜扮數缃戝姛鐜囩殑璋冭妭 + * + * @author JS-ZZA + * @date 2022/9/19 15:06 + */ +@Slf4j +@Component +public class PileWorkingParameterSettingHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PILE_WORKING_PARAMETER_SETTING_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍏呯數妗╁伐浣滃弬鏁拌缃===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鍙 + + // 鏄惁鍏佽宸ヤ綔 + + // 鍏呯數妗╂渶澶у厑璁歌緭鍑哄姛鐜 + + + // return super.supplyProcess(ykcDataTemplate, channel); + return null; + } + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/PileWorkingParameterSettingResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/PileWorkingParameterSettingResponseHandler.java new file mode 100644 index 000000000..f063fe40b --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/PileWorkingParameterSettingResponseHandler.java @@ -0,0 +1,52 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數妗╁伐浣滃弬鏁拌缃簲绛 + * + * @author JS-ZZA + * @date 2022/9/27 10:40 + */ +@Slf4j +@Component +public class PileWorkingParameterSettingResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PILE_WORKING_PARAMETER_SETTING_ANSWER_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍏呯數妗╁伐浣滃弬鏁拌缃簲绛===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 璁剧疆缁撴灉 + startIndex += length; + length = 1; + byte[] settingResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/ReadRealTimeMonitorDataHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ReadRealTimeMonitorDataHandler.java new file mode 100644 index 000000000..d89324807 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/ReadRealTimeMonitorDataHandler.java @@ -0,0 +1,57 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.netty.service.yunkuaichong.impl.YKCPushCommandServiceImpl; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 璇诲彇瀹炴椂鐩戞祴鏁版嵁锛堟湇鍔″櫒绔悜妗╁彂閫佹秷鎭 0x12锛 + * + * @deprecated 妗╀笉浼氬彂閫佽繖涓寚浠わ紝鐢卞钩鍙颁富鍔ㄥ彂閫 + * @author JS-ZZA + * @date 2022/9/19 8:43 + */ +@Slf4j +@Component +public class ReadRealTimeMonitorDataHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.READ_REAL_TIME_MONITOR_DATA_CODE.getBytes()); + + @Autowired + private YKCPushCommandServiceImpl ykcPushBusinessServiceImpl; + + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===璇诲彇瀹炴椂鐩戞祴鏁版嵁===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鍙 + byte[] pileSnByteArr = new byte[]{}; + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + // 鏋彿 + byte[] pileConnectorByteArr = Constants.oneByteArray; + + // 鎷兼帴娑堟伅浣 + byte[] msg = Bytes.concat(pileSnByteArr, pileConnectorByteArr); + // push娑堟伅 + // boolean result = ykcPushBusinessServiceImpl.push(msg, pileSn, YKCFrameTypeCode.READ_REAL_TIME_MONITOR_DATA_CODE); + + // log.info(String.valueOf(result)); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteAccountBalanceUpdateRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteAccountBalanceUpdateRequestHandler.java new file mode 100644 index 000000000..d2b129295 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteAccountBalanceUpdateRequestHandler.java @@ -0,0 +1,74 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 浣欓鏇存柊搴旂瓟 + * + * @author JS-ZZA + * @date 2022/9/19 14:47 + */ +@Slf4j +@Component +public class RemoteAccountBalanceUpdateRequestHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_ACCOUNT_BALANCE_UPDATE_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===浣欓鏇存柊搴旂瓟===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鐮 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鐗╃悊鍗″彿 涓嶈冻 8 浣嶈ˉ闆 + //濡傛灉涓嶄负闆讹紝 闇瑕佹牎楠屾湰娆″厖鐢垫槸 鍚︿负姝ゅ崱鍏呯數 + //濡傛灉涓洪浂锛 鍒欎笉鏍¢獙锛 鐩存帴鏇存柊妗 褰撳墠鍏呯數鐢ㄦ埛浣欓 + startIndex += length; + length = 8; + byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 淇敼鍚庤处鎴烽噾棰 淇濈暀涓や綅灏忔暟 + startIndex += length; + length = 4; + byte[] accountBalance = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 搴旂瓟 + // 甯х被鍨 + byte[] remoteAccountBalanceUpdateAnswerCodeBytes = YKCFrameTypeCode.REMOTE_ACCOUNT_BALANCE_UPDATE_ANSWER_CODE.getBytes(); + + // 淇敼缁撴灉 0x00-淇敼鎴愬姛 + //0x01-璁惧缂栧彿閿欒 + //0x02-鍗″彿閿欒 + + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteControlGroundLockHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteControlGroundLockHandler.java new file mode 100644 index 000000000..0a08e7076 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteControlGroundLockHandler.java @@ -0,0 +1,45 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 閬ユ帶鍦伴攣鍗囬攣涓庨檷閿佸懡浠 + * + * 鏈嶅姟鍣ㄤ笅鍙戝懡浠ょ粰鍦伴攣锛屽湴閿佹墽琛屽姩浣 + * + * @author JS-ZZA + * @date 2022/9/19 15:41 + */ +@Slf4j +@Component +public class RemoteControlGroundLockHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_CONTROL_GROUND_LOCK_LIFTING_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===閬ユ帶鍦伴攣鍗囬攣涓庨檷閿佸懡浠===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鐮 + + // 鏋彿 + + // 鍗/闄嶅湴閿 + + // 棰勭暀浣 + + // return super.supplyProcess(ykcDataTemplate, channel); + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteControlGroundLockResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteControlGroundLockResponseHandler.java new file mode 100644 index 000000000..93ad4518e --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteControlGroundLockResponseHandler.java @@ -0,0 +1,57 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 鍏呯數妗╄繑鍥為仴鎺у湴閿佸崌閿佷笌闄嶉攣鏁版嵁锛堜笂琛岋級 + * + * @author JS-ZZA + * @date 2022/9/27 13:21 + */ +@Slf4j +@Component +public class RemoteControlGroundLockResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PILE_RESPOND_GROUND_LOCK_LIFTING_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍏呯數妗╄繑鍥為仴鎺у湴閿佸崌閿佷笌闄嶉攣鏁版嵁锛堜笂琛岋級===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 鍦伴攣鎺у埗杩斿洖鏍囧織 甯冨皵鍨嬶紙 1锛 閴存潈鎴愬姛锛 0锛 閴存潈澶辫触锛 + startIndex += length; + byte[] controlResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + // 棰勭暀浣 + startIndex += length; + length = 4; + byte[] waitingUseByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteIssuedQrCodeHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteIssuedQrCodeHandler.java new file mode 100644 index 000000000..36a4e0a6b --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteIssuedQrCodeHandler.java @@ -0,0 +1,75 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.netty.service.yunkuaichong.impl.YKCPushCommandServiceImpl; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 鍚庡彴杩滅▼涓嬪彂浜岀淮鐮佸墠缂鎸囦护 + * + * 浜岀淮鐮佷笅鍙戞椂锛屽彧闇涓嬪彂鍓嶇紑锛屽悓鏃堕夋嫨鏄 0 绉嶆牸寮忥紝杩樻槸绗 1 绉嶆牸寮忓嵆鍙紝濡傛灉浜岀淮鐮佹牸寮忎负 0 绉嶏紝妗╄嚜鍔ㄨˉ鍏呮々缂栧彿銆 + * 濡傛灉浜岀淮鐮佹牸寮忎负 1 绉嶏紝妗╄嚜鍔ㄨˉ鍏呮々缂栧彿+2浣嶆灙缂栧彿銆 + * 娉ㄥ唽閫氳繃鍚庯紝鍚庡彴鍗冲彲绔嬪嵆涓嬪彂浜岀淮鐮併傛帹鑽愭瘡娆℃敞鍐岄氳繃鍚庯紝鍧囦笅鍙戜竴娆′簩缁寸爜銆傛瘡涓々涓嬪彂涓娆″墠缂鍗冲彲銆傛棤椤绘寜鐓ф灙涓暟涓嬪彂銆 + * + * @deprecated 妗╀笉浼氬彂閫佽繖涓寚浠わ紝鐢卞钩鍙颁富鍔ㄥ彂閫 + * @author JS-ZZA + * @date 2022/9/29 14:05 + */ +@Slf4j +@Component +public class RemoteIssuedQrCodeHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_ISSUE_QRCODE_CODE.getBytes()); + + @Autowired + private YKCPushCommandServiceImpl ykcPushBusinessService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鍚庡彴杩滅▼涓嬪彂浜岀淮鐮佸墠缂鎸囦护===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鐮 + String pileSn = "88000000000001"; + byte[] a = new byte[]{88}; + byte[] b = Constants.zeroByteArray; + byte[] c = Constants.zeroByteArray; + byte[] d = Constants.zeroByteArray; + byte[] e = Constants.zeroByteArray; + byte[] f = Constants.zeroByteArray; + byte[] g = new byte[]{0x02}; + byte[] pileSnByteArr = Bytes.concat(a, b, c, d, e, f, g); + + // 浜岀淮鐮佹牸寮 0x00锛氱涓绉 鍓嶇紑+妗╃紪鍙 0x01锛氱浜岀 鍓嶇紑+妗╃紪鍙+鏋紪鍙 + byte[] qrCodeTypeByteArr = Constants.zeroByteArray; + // 浜岀淮鐮佸墠缂 濡傦細鈥渨ww.baidu.com锛烴o=鈥 + String qrCodePrefix = "https://wx.charging.shbochong.cn/prepare_charge?code="; + byte[] qrCodePrefixByteArr = BytesUtil.str2Asc(qrCodePrefix); + // 浜岀淮鐮佸墠缂闀垮害 浜岀淮鐮佸墠缂闀垮害闀垮害鏈澶т笉瓒呰繃200 瀛楄妭 + int length = qrCodePrefix.length(); + byte[] qrCodePrefixLengthByteArr = BytesUtil.intToBytes(length); + + // 鎷兼帴娑堟伅浣 + byte[] msg = Bytes.concat(pileSnByteArr, qrCodeTypeByteArr, qrCodePrefixLengthByteArr, qrCodePrefixByteArr); + + // push娑堟伅 + // boolean result = ykcPushBusinessService.push(msg, pileSn, YKCFrameTypeCode.REMOTE_ISSUE_QRCODE_CODE); + + // log.info(String.valueOf(result)); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteIssuedQrCodeResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteIssuedQrCodeResponseHandler.java new file mode 100644 index 000000000..efffd4b54 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteIssuedQrCodeResponseHandler.java @@ -0,0 +1,52 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 妗╁簲绛旇繙绋嬩笅鍙戜簩缁寸爜鍓嶇紑鎸囦护 + * + * @author JS-ZZA + * @date 2022/9/29 14:10 + */ +@Slf4j +@Component +public class RemoteIssuedQrCodeResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_ISSUE_QRCODE_ANSWER_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===妗╁簲绛旇繙绋嬩笅鍙戜簩缁寸爜鍓嶇紑鎸囦护===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鐮 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 涓嬪彂缁撴灉 0x00锛氭垚鍔 0x01锛氬け璐 + startIndex += length; + length = 1; + byte[] issuedResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteRestartHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteRestartHandler.java new file mode 100644 index 000000000..33f952924 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteRestartHandler.java @@ -0,0 +1,41 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 杩滅▼閲嶅惎 + * + * 閲嶅惎鍏呯數妗╋紝搴斿閮ㄥ垎闂锛屽鍗℃ + * 杩欎釜灞炰簬骞冲彴涓诲姩涓嬪彂鐨勬寚浠 + * @author JS-ZZA + * @date 2022/9/19 15:49 + */ +@Slf4j +@Component +@Deprecated +public class RemoteRestartHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_RESTART_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===杩滅▼閲嶅惎===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鍙 + + // 鎵ц鎺у埗 0x01锛氱珛鍗虫墽琛 0x02锛氱┖闂叉墽琛 + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteRestartResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteRestartResponseHandler.java new file mode 100644 index 000000000..8d24061b1 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteRestartResponseHandler.java @@ -0,0 +1,61 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.service.IPileMsgRecordService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 杩滅▼閲嶅惎搴旂瓟 + * + * @author JS-ZZA + * @date 2022/9/27 13:27 + */ +@Slf4j +@Component +public class RemoteRestartResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_RESTART_ANSWER_CODE.getBytes()); + + @Autowired + private IPileMsgRecordService pileMsgRecordService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===杩滅▼閲嶅惎搴旂瓟===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 淇濆瓨鎶ユ枃 + String jsonMsg = JSONObject.toJSONString(ykcDataProtocol); + pileMsgRecordService.save(pileSn, null, type, jsonMsg, ykcDataProtocol.getHEXString()); + + // 璁剧疆缁撴灉 + startIndex += length; + length = 1; + byte[] settingResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteStartChargingRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteStartChargingRequestHandler.java new file mode 100644 index 000000000..681c5b0e1 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteStartChargingRequestHandler.java @@ -0,0 +1,98 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.enums.ykc.ChargingFailedReasonEnum; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.service.IOrderBasicInfoService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 杩滅▼鍚姩鍏呯數鍛戒护鍥炲 0x33, 0x34 + * + * @author JS-ZZA + * @date 2022/9/19 14:35 + */ +@Slf4j +@Component +public class RemoteStartChargingRequestHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_START_CHARGING_ANSWER_CODE.getBytes()); + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===杩滅▼鍚姩鍏呯數鍛戒护鍥炲===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String orderCode = BytesUtil.bcd2Str(orderCodeByteArr); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr); + + // 鍚姩缁撴灉 0x00澶辫触 0x01鎴愬姛 + startIndex += length; + byte[] startResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String startResult = BytesUtil.bcd2Str(startResultByteArr); + + /** + * 澶辫触鍘熷洜 + * + * 妗╁湪鏀跺埌鍚厖鍛戒护鍚,妫娴嬪埌鏈彃鏋垯鍙戦 0x33 鎶ユ枃鍥炲鍏呯數澶辫触銆 + * 鑻ュ湪 60 绉掞紙浠ユ敹鍒 0x34 鏃堕棿寮濮嬭绠楋級鍐呮娴嬪埌鏋噸鏂拌繛鎺ワ紝鍒欒ˉ閫 0x33 鎴愬姛鎶ユ枃;瓒呮椂鎴栬呯绾跨瓑鍏朵粬寮傚父锛屾々涓嶅惎鍏呫佷笉琛ュ彂 0x33 鎶ユ枃 + * 0x00 鏃 + * 0x01 璁惧缂栧彿涓嶅尮閰 + * 0x02 鏋凡鍦ㄥ厖鐢 + * 0x03 璁惧鏁呴殰 + * 0x04 璁惧绂荤嚎 + * 0x05 鏈彃鏋 + */ + startIndex += length; + byte[] failedReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String failedReason = BytesUtil.bin2HexStr(failedReasonByteArr); + String failedReasonMsg = ChargingFailedReasonEnum.getMsgByCode(Integer.parseInt(failedReason, 16)); + + if (StringUtils.equals(startResult, Constants.DOUBLE_ZERO)) { + // 鍚姩澶辫触 + orderBasicInfoService.chargingPileFailedToStart(orderCode, failedReasonMsg); + } else { + // 鍚姩鎴愬姛 + orderBasicInfoService.chargingPileStartedSuccessfully(orderCode); + } + // orderBasicInfoService.updateOrderBasicInfo(orderInfo); + log.info("浜ゆ槗娴佹按鍙:{}, 妗╃紪鐮:{}, 鏋彿:{}, 鍚姩缁撴灉:{}, 澶辫触鍘熷洜:{}", orderCode, pileSn, connectorCode, startResult, failedReasonMsg); + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteStopChargingRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteStopChargingRequestHandler.java new file mode 100644 index 000000000..b389437f8 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteStopChargingRequestHandler.java @@ -0,0 +1,99 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.enums.ykc.StopChargingFailedReasonEnum; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.service.IOrderBasicInfoService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; + +/** + * 杩滅▼鍋滄満鍛戒护鍥炲 + * + * @author JS-ZZA + * @date 2022/9/19 14:37 + */ +@Slf4j +@Component +public class RemoteStopChargingRequestHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_STOP_CHARGING_ANSWER_CODE.getBytes()); + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===杩滅▼鍋滄満鍛戒护鍥炲===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr); + + // 鍋滄缁撴灉 0x00澶辫触 0x01鎴愬姛 + startIndex += length; + byte[] stopResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String stopResult = BytesUtil.bcd2Str(stopResultByteArr); + + /** + * 澶辫触鍘熷洜 + * 0x00 鏃 + * 0x01 璁惧缂栧彿涓嶅尮閰 + * 0x02 鏋湭澶勪簬鍏呯數鐘舵 + * 0x03 鍏朵粬 + */ + startIndex += length; + byte[] reasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String reasonCode = BytesUtil.bcd2Str(reasonByteArr); + String reason = StopChargingFailedReasonEnum.getMsgByCode(reasonCode); + + // 閫氳繃妗╃紪鍙+鏋彛鍙 鏌ュ嚭璁㈠崟 + OrderBasicInfo order = orderBasicInfoService.queryChargingByPileSnAndConnectorCode(pileSn, connectorCode); + if (order != null) { + // 鏀跺埌鍋滄満鍥炲鍚庯紝淇敼璁㈠崟鐘舵 + if (StringUtils.equals(stopResult, "01")) { + // 鍋滄満鎴愬姛锛屼慨鏀硅鍗曠姸鎬佷负 寰呯粨绠 + order.setOrderStatus(OrderStatusEnum.STAY_SETTLEMENT.getValue()); + if (order.getChargeEndTime() == null) { + order.setChargeEndTime(new Date()); // 缁撴潫鍏呯數鏃堕棿 + } + } else { + // 鍋滄満澶辫触锛屼慨鏀硅鍗曠姸鎬佷负 寮傚父 + order.setOrderStatus(OrderStatusEnum.ABNORMAL.getValue()); + order.setReason(reason); + } + orderBasicInfoService.updateOrderBasicInfo(order); + } + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteUpdateHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteUpdateHandler.java new file mode 100644 index 000000000..04c797261 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteUpdateHandler.java @@ -0,0 +1,58 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 杩滅▼鏇存柊 + * + * 瀵规々杩涜杞欢鍗囩骇锛屽钩鍙板崌绾фā寮忎负 ftp 鏂囦欢鍗囩骇锛岀敱妗╀紒鎻愪緵鍗囩骇闇瑕佺殑鏇存柊鏂囦欢锛堢壒瀹氭枃浠跺悕锛 鐢辨々浼佸畾涔夛級 锛 + * 骞冲彴鍦ㄦ暟鎹抚涓彁渚涜闂洿鏂版枃浠剁浉鍏虫湇鍔″櫒鍦板潃鍙婁笅杞借矾寰勪俊鎭紝 妗╀笅杞藉畬鏇存柊绋嬪簭鍚庡鏂囦欢杩涜杈冮獙锛屽苟瀵规々杩涜鍗囩骇 + * + * @author JS-ZZA + * @date 2022/9/19 15:56 + */ +@Slf4j +@Component +public class RemoteUpdateHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_UPDATE_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===杩滅▼鏇存柊===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鍙 + + // 妗╁瀷鍙 0x01锛氱洿娴 0x02锛氫氦娴 + + // 妗╁姛鐜 涓嶈冻 2 浣嶈ˉ闆 + + // 鍗囩骇鏈嶅姟鍣ㄥ湴鍧 涓嶈冻 16 浣嶈ˉ闆 + + // 鍗囩骇鏈嶅姟鍣ㄧ鍙 涓嶈冻 2 浣嶈ˉ闆 + + // 鐢ㄦ埛鍚 涓嶈冻 16 浣嶈ˉ闆 + + // 瀵嗙爜 涓嶈冻 16 浣嶈ˉ闆 + + // 鏂囦欢璺緞 涓嶈冻 32 浣嶈ˉ闆讹紝鏂囦欢璺緞鍚嶇敱骞 鍙板畾涔 + + // 鎵ц鎺у埗 0x01锛氱珛鍗虫墽琛 0x02锛氱┖闂叉墽琛 + + // 涓嬭浇瓒呮椂鏃堕棿 鍗曚綅锛 min + + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteUpdateResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteUpdateResponseHandler.java new file mode 100644 index 000000000..2291d071f --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/RemoteUpdateResponseHandler.java @@ -0,0 +1,52 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 杩滅▼鏇存柊搴旂瓟 + * + * @author JS-ZZA + * @date 2022/9/27 13:32 + */ +@Slf4j +@Component +public class RemoteUpdateResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_UPDATE_ANSWER_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[====杩滅▼鏇存柊搴旂瓟====] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, 0, 7); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鍗囩骇鐘舵 0x00-鎴愬姛 0x01-缂栧彿閿欒 0x02-绋嬪簭涓庢々鍨嬪彿涓嶇 0x03-涓嬭浇鏇存柊鏂囦欢瓒呮椂 + startIndex += length; + length = 1; + byte[] updateStatusByteArr = BytesUtil.copyBytes(msgBody, 7, 1); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/TimeCheckSettingHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/TimeCheckSettingHandler.java new file mode 100644 index 000000000..803b44b72 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/TimeCheckSettingHandler.java @@ -0,0 +1,41 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 瀵规椂璁剧疆 + * + * 杩愯惀骞冲彴鍚屾鍏呯數妗╂椂閽燂紝浠ヤ繚璇佸厖鐢垫々涓庤繍钀ュ钩鍙扮殑鏃堕挓涓鑷 + * + * @author JS-ZZA + * @date 2022/9/19 15:11 + */ +@Slf4j +@Component +public class TimeCheckSettingHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.TIME_CHECK_SETTING_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===瀵规椂璁剧疆===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 涓嬪彂 + // 妗╃紪鍙 + + // 褰撳墠鏃堕棿 CP56Time2a 鏍煎紡 + + // return super.supplyProcess(ykcDataTemplate, channel); + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/TimeCheckSettingResponseHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/TimeCheckSettingResponseHandler.java new file mode 100644 index 000000000..75e5c53af --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/TimeCheckSettingResponseHandler.java @@ -0,0 +1,52 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 瀵规椂璁剧疆搴旂瓟 + * + * @author JS-ZZA + * @date 2022/9/27 11:09 + */ +@Slf4j +@Component +public class TimeCheckSettingResponseHandler extends AbstractHandler{ + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.TIME_CHECK_SETTING_ANSWER_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + } + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===瀵规椂璁剧疆搴旂瓟===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 7; + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 褰撳墠鏃堕棿 + startIndex += length; + length = 7; + byte[] currentTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + + return null; + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/TransactionRecordsRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/TransactionRecordsRequestHandler.java new file mode 100644 index 000000000..9a20c33f0 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/TransactionRecordsRequestHandler.java @@ -0,0 +1,559 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.TransactionRecordsData; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.enums.ykc.YKCChargingStopReasonEnum; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.Cp56Time2a.Cp56Time2aUtil; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.common.util.id.IdUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.service.IPileMsgRecordService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.Objects; + +/** + * 浜ゆ槗璁板綍纭 + * 杩欎竴甯т粎鏄姤鏂囦氦浜掍娇鐢紝 鎰忔寚骞冲彴鎴愬姛鎺ユ敹鍒颁氦鏄撹褰曟姤鏂囷紝骞朵笉浠h〃浜ゆ槗璁㈠崟鎴愬姛缁撶畻 + * 杩愯惀骞冲彴鎺ユ敹鍒扮粨绠楄处鍗曚笂浼犲悗锛岄兘闇鍥炲姝ょ‘璁や俊鎭傝嫢妗╂湭鏀跺埌鍥炲甯э紝鍒 5 鍒嗛挓鍚庣户缁 涓婇佷竴娆′氦鏄撹褰曪紝 + * 姝ゆ儏鍐典笅鏃犺骞冲彴鏄惁鎴愬姛鍥炲閮藉仠姝笂閫併 + * + * @author JS-ZZA + * @date 2022/9/19 14:40 + */ +@Slf4j +@Component +public class TransactionRecordsRequestHandler extends AbstractHandler { + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.TRANSACTION_RECORDS_CODE.getBytes()); + private final String oldVersionType = YKCUtils.frameType2Str(YKCFrameTypeCode.TRANSACTION_RECORDS_OLD_VERSION_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + YKCOperateFactory.register(oldVersionType, this); + } + + @Autowired + private RedisCache redisCache; + + @Autowired + private IPileMsgRecordService pileMsgRecordService; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + /*public static void main(String[] args) { + String msgBodyStr = "880000000000040122121516483531998800000000000401000030100f0c16a8003b011a0368100f0400000000000000000000000000c891050000000000000000000000000080140700a406000000000000d01e000090170d0000000000000000000000000010b0390b0078f2390b00a406000000000000781e0000ffffffffffffffffffffffffffffffffff01a8003b011a0368830000000000000000" ; + byte[] msgBody = BytesUtil.str2Bcd(msgBodyStr); + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String orderCode = BytesUtil.bcd2Str(orderCodeByteArr); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr); + // 鏍规嵁涓嶅悓绋嬪簭鐗堟湰鑾峰彇宸ュ叿绫 + String programVersion = redisCache.getCacheMapValue(CacheConstants.PILE_PROGRAM_VERSION, pileSn); + AbsCp56Time2aUtil cp56Time2aUtil = Cp56Time2aFactory.getInvokeStrategy(programVersion); + // 寮濮嬫椂闂 CP56Time2a 鏍煎紡 + startIndex += length; + length = 7; + byte[] startTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String startTime = cp56Time2aUtil.toDateString(startTimeByteArr); + + // 缁撴潫鏃堕棿 CP56Time2a 鏍煎紡 + startIndex += length; + byte[] endTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String endTime = cp56Time2aUtil.toDateString(endTimeByteArr); + + // 灏栧崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙灏栫數璐+灏栨湇鍔¤垂锛岃璐圭巼甯э級 + startIndex += length; + length = 4; + byte[] sharpPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String sharpPrice = YKCUtils.convertDecimalPoint(sharpPriceByteArr, 5); + + // 灏栫數閲 绮剧‘鍒板皬鏁扮偣鍚庡洓浣 + startIndex += length; + length = 4; + byte[] sharpUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String sharpUsedElectricity = YKCUtils.convertDecimalPoint(sharpUsedElectricityByteArr, 4); + + // 璁℃崯灏栫數閲 + startIndex += length; + byte[] sharpPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String sharpPlanLossElectric = YKCUtils.convertDecimalPoint(sharpPlanLossElectricityByteArr, 4); + + // 灏栭噾棰 + startIndex += length; + byte[] sharpAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String sharpAmount = YKCUtils.convertDecimalPoint(sharpAmountByteArr, 4); + + // 宄板崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙宄扮數璐+宄版湇鍔¤垂锛 + startIndex += length; + byte[] peakPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String peakPrice = YKCUtils.convertDecimalPoint(peakPriceByteArr, 5); + + // 宄扮數閲 + startIndex += length; + byte[] peakUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String peakUsedElectricity = YKCUtils.convertDecimalPoint(peakUsedElectricityByteArr, 4); + + // 璁℃崯宄扮數閲 + startIndex += length; + byte[] peakPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String peakPlanLossElectricity = YKCUtils.convertDecimalPoint(peakPlanLossElectricityByteArr, 4); + + // 宄伴噾棰 + startIndex += length; + byte[] peakAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String peakAmount = YKCUtils.convertDecimalPoint(peakAmountByteArr, 4); + + // 骞冲崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙骞崇數璐+骞虫湇鍔¤垂锛 + startIndex += length; + byte[] flatPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String flatPrice = YKCUtils.convertDecimalPoint(flatPriceByteArr, 5); + + // 骞崇數閲 + startIndex += length; + byte[] flatUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String flatUsedElectricity = YKCUtils.convertDecimalPoint(flatUsedElectricityByteArr, 4); + + // 璁℃崯骞崇數閲 + startIndex += length; + byte[] flatPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String flatPlanLossElectricity = YKCUtils.convertDecimalPoint(flatPlanLossElectricityByteArr, 4); + + // 骞抽噾棰 + startIndex += length; + byte[] flatAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String flatAmount = YKCUtils.convertDecimalPoint(flatAmountByteArr, 4); + + // 璋峰崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙璋风數璐+璋 鏈嶅姟璐癸級 + startIndex += length; + byte[] valleyPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String valleyPrice = YKCUtils.convertDecimalPoint(valleyPriceByteArr, 5); + + // 璋风數閲 + startIndex += length; + byte[] valleyUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String valleyUsedElectricity = YKCUtils.convertDecimalPoint(valleyUsedElectricityByteArr, 4); + + // 璁℃崯璋风數閲 + startIndex += length; + byte[] valleyPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String valleyPlanLossElectricity = YKCUtils.convertDecimalPoint(valleyPlanLossElectricityByteArr, 4); + + // 璋烽噾棰 + startIndex += length; + byte[] valleyAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String valleyAmount = YKCUtils.convertDecimalPoint(valleyAmountByteArr, 4); + + // 鐢佃〃鎬昏捣鍊 + startIndex += length; + length = 5; + byte[] ammeterTotalStartByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String ammeterTotalStart = YKCUtils.convertDecimalPoint(ammeterTotalStartByteArr, 4); + + // 鐢佃〃鎬绘鍊 + startIndex += length; + byte[] ammeterTotalEndByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String ammeterTotalEnd = YKCUtils.convertDecimalPoint(ammeterTotalEndByteArr, 4); + + // 鎬荤數閲 + startIndex += length; + length = 4; + byte[] totalElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String totalElectricity = YKCUtils.convertDecimalPoint(totalElectricityByteArr, 4); + + // 璁℃崯鎬荤數閲 + startIndex += length; + byte[] planLossTotalElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String planLossTotalElectricity = YKCUtils.convertDecimalPoint(planLossTotalElectricityByteArr, 4); + + // 娑堣垂閲戦 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紝鍖呭惈鐢佃垂銆 鏈嶅姟璐 + startIndex += length; + byte[] consumptionAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String consumptionAmount = YKCUtils.convertDecimalPoint(consumptionAmountByteArr, 4); + + // VIN 鐮 VIN 鐮侊紝姝ゅ VIN 鐮佸拰鍏呯數鏃 VIN 鐮佷笉鍚岋紝 姝e簭鐩存帴涓婁紶锛 鏃犻渶琛 0 鍜屽弽搴 + startIndex += length; + length = 17; + byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String vinCode = BytesUtil.ascii2Str(vinCodeByteArr); + + *//** + * 浜ゆ槗鏍囪瘑 + * 0x01锛 app 鍚姩 + * 0x02锛氬崱鍚姩 + * 0x04锛氱绾垮崱鍚姩 + * 0x05: vin 鐮佸惎鍔ㄥ厖鐢 + *//* + startIndex += length; + length = 1; + byte[] transactionIdentifierByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String transactionIdentifier = BytesUtil.bcd2Str(transactionIdentifierByteArr); + + // 浜ゆ槗鏃堕棿 CP56Time2a 鏍煎紡 + startIndex += length; + length = 7; + byte[] transactionTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String transactionTime = cp56Time2aUtil.toDateString(transactionTimeByteArr); + + // 鍋滄鍘熷洜 + startIndex += length; + length = 1; + byte[] stopReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String stopReason = BytesUtil.bin2HexStr(stopReasonByteArr); + String stopReasonMsg = YKCChargingStopReasonEnum.getMsgByCode(Integer.parseInt(stopReason, 16)); + + // 鐗╃悊鍗″彿 涓嶈冻 8 浣嶈ˉ 0 + startIndex += length; + length = 8; + byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + byte[] logicCardNum = BytesUtil.checkLengthAndBehindAppendZero(cardNumByteArr, 16); + String logicCard = BytesUtil.binary(logicCardNum, 10); + + log.info("浜ゆ槗娴佹按鍙:{}, 妗╃紪鍙:{}, 鏋彿:{}, 寮濮嬫椂闂:{}, 缁撴潫鏃堕棿:{}, 灏栧崟浠:{}, 灏栫數閲:{}, 璁℃崯灏栫數閲:{}, 灏栭噾棰:{}, " + + "宄板崟浠:{}, 宄扮數閲:{}, 璁℃崯宄扮數閲:{}, 宄伴噾棰:{}, 骞冲崟浠:{}, 骞崇數閲:{}, 璁℃崯骞崇數閲:{}, 骞抽噾棰:{}, " + + "璋峰崟浠:{}, 璋风數閲:{}, 璁℃崯璋风數閲:{}, 璋烽噾棰:{}, 鐢佃〃鎬昏捣鍊:{}, 鐢佃〃鎬绘鍊:{}, 鎬荤數閲:{}, 璁℃崯鎬荤數閲:{}, 娑堣垂閲戦:{}, " + + "鐢靛姩姹借溅鍞竴鏍囪瘑:{}, 浜ゆ槗鏍囪瘑:{}, 浜ゆ槗鏃堕棿:{}, 鍋滄鍘熷洜鐮:{}, 鍋滄鍘熷洜鎻忚堪:{}, 鐗╃悊鍗″彿:{}", + orderCode, pileSn, connectorCode, startTime, endTime, sharpPrice, sharpUsedElectricity, sharpPlanLossElectric, sharpAmount, + peakPrice, peakUsedElectricity, peakPlanLossElectricity, peakAmount, flatPrice, flatUsedElectricity, flatPlanLossElectricity, flatAmount, + valleyPrice, valleyUsedElectricity, valleyPlanLossElectricity, valleyAmount, ammeterTotalStart, ammeterTotalEnd, totalElectricity, planLossTotalElectricity, + consumptionAmount, vinCode, transactionIdentifier, transactionTime, stopReason, stopReasonMsg, logicCard); + }*/ + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + // log.info("[===浜ゆ槗璁板綍===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String orderCode = BytesUtil.bcd2Str(orderCodeByteArr); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr); + + + // 寮濮嬫椂闂 CP56Time2a 鏍煎紡 + startIndex += length; + length = 7; + byte[] startTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + // String binary = BytesUtil.binary(startTimeByteArr, 16); + Date startDate = Cp56Time2aUtil.byte2Hdate(startTimeByteArr); + String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate); + + + // 缁撴潫鏃堕棿 CP56Time2a 鏍煎紡 + startIndex += length; + byte[] endTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + Date endDate = Cp56Time2aUtil.byte2Hdate(endTimeByteArr); + String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endDate); + + // 灏栧崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙灏栫數璐+灏栨湇鍔¤垂锛岃璐圭巼甯э級 + startIndex += length; + length = 4; + byte[] sharpPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String sharpPrice = YKCUtils.convertDecimalPoint(sharpPriceByteArr, 5); + + // 灏栫數閲 绮剧‘鍒板皬鏁扮偣鍚庡洓浣 + startIndex += length; + length = 4; + byte[] sharpUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String sharpUsedElectricity = YKCUtils.convertDecimalPoint(sharpUsedElectricityByteArr, 4); + + // 璁℃崯灏栫數閲 + startIndex += length; + byte[] sharpPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String sharpPlanLossElectricity = YKCUtils.convertDecimalPoint(sharpPlanLossElectricityByteArr, 4); + + // 灏栭噾棰 + startIndex += length; + byte[] sharpAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String sharpAmount = YKCUtils.convertDecimalPoint(sharpAmountByteArr, 4); + + // 宄板崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙宄扮數璐+宄版湇鍔¤垂锛 + startIndex += length; + byte[] peakPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String peakPrice = YKCUtils.convertDecimalPoint(peakPriceByteArr, 5); + + // 宄扮數閲 + startIndex += length; + byte[] peakUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String peakUsedElectricity = YKCUtils.convertDecimalPoint(peakUsedElectricityByteArr, 4); + + // 璁℃崯宄扮數閲 + startIndex += length; + byte[] peakPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String peakPlanLossElectricity = YKCUtils.convertDecimalPoint(peakPlanLossElectricityByteArr, 4); + + // 宄伴噾棰 + startIndex += length; + byte[] peakAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String peakAmount = YKCUtils.convertDecimalPoint(peakAmountByteArr, 4); + + // 骞冲崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙骞崇數璐+骞虫湇鍔¤垂锛 + startIndex += length; + byte[] flatPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String flatPrice = YKCUtils.convertDecimalPoint(flatPriceByteArr, 5); + + // 骞崇數閲 + startIndex += length; + byte[] flatUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String flatUsedElectricity = YKCUtils.convertDecimalPoint(flatUsedElectricityByteArr, 4); + + // 璁℃崯骞崇數閲 + startIndex += length; + byte[] flatPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String flatPlanLossElectricity = YKCUtils.convertDecimalPoint(flatPlanLossElectricityByteArr, 4); + + // 骞抽噾棰 + startIndex += length; + byte[] flatAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String flatAmount = YKCUtils.convertDecimalPoint(flatAmountByteArr, 4); + + // 璋峰崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙璋风數璐+璋 鏈嶅姟璐癸級 + startIndex += length; + byte[] valleyPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String valleyPrice = YKCUtils.convertDecimalPoint(valleyPriceByteArr, 5); + + // 璋风數閲 + startIndex += length; + byte[] valleyUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String valleyUsedElectricity = YKCUtils.convertDecimalPoint(valleyUsedElectricityByteArr, 4); + + // 璁℃崯璋风數閲 + startIndex += length; + byte[] valleyPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String valleyPlanLossElectricity = YKCUtils.convertDecimalPoint(valleyPlanLossElectricityByteArr, 4); + + // 璋烽噾棰 + startIndex += length; + byte[] valleyAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String valleyAmount = YKCUtils.convertDecimalPoint(valleyAmountByteArr, 4); + + // 鐢佃〃鎬昏捣鍊 + startIndex += length; + length = 5; + byte[] ammeterTotalStartByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String ammeterTotalStart = YKCUtils.convertDecimalPoint(ammeterTotalStartByteArr, 4); + + // 鐢佃〃鎬绘鍊 + startIndex += length; + byte[] ammeterTotalEndByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String ammeterTotalEnd = YKCUtils.convertDecimalPoint(ammeterTotalEndByteArr, 4); + + // 鎬荤數閲 + startIndex += length; + length = 4; + byte[] totalElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String totalElectricity = YKCUtils.convertDecimalPoint(totalElectricityByteArr, 4); + + // 璁℃崯鎬荤數閲 + startIndex += length; + byte[] planLossTotalElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String planLossTotalElectricity = YKCUtils.convertDecimalPoint(planLossTotalElectricityByteArr, 4); + + // 娑堣垂閲戦 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紝鍖呭惈鐢佃垂銆 鏈嶅姟璐 + startIndex += length; + byte[] consumptionAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String consumptionAmount = YKCUtils.convertDecimalPoint(consumptionAmountByteArr, 4); + + // VIN 鐮 VIN 鐮侊紝姝ゅ VIN 鐮佸拰鍏呯數鏃 VIN 鐮佷笉鍚岋紝 姝e簭鐩存帴涓婁紶锛 鏃犻渶琛 0 鍜屽弽搴 + startIndex += length; + length = 17; + byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String vinCode = BytesUtil.ascii2Str(vinCodeByteArr); + + /** + * 浜ゆ槗鏍囪瘑 + * 0x01锛 app 鍚姩 + * 0x02锛氬崱鍚姩 + * 0x04锛氱绾垮崱鍚姩 + * 0x05: vin 鐮佸惎鍔ㄥ厖鐢 + */ + startIndex += length; + length = 1; + byte[] transactionIdentifierByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String transactionIdentifier = BytesUtil.bcd2Str(transactionIdentifierByteArr); + + // 浜ゆ槗鏃堕棿 CP56Time2a 鏍煎紡 + startIndex += length; + length = 7; + byte[] transactionTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + Date transactionDate = Cp56Time2aUtil.byte2Hdate(transactionTimeByteArr); + String transactionTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, transactionDate); + + // 鍋滄鍘熷洜 + startIndex += length; + length = 1; + byte[] stopReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String stopReason = BytesUtil.bin2HexStr(stopReasonByteArr); + String stopReasonMsg = YKCChargingStopReasonEnum.getMsgByCode(Integer.parseInt(stopReason, 16)); + + // 鐗╃悊鍗″彿 涓嶈冻 8 浣嶈ˉ 0 + startIndex += length; + length = 8; + byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + byte[] logicCardNum = BytesUtil.checkLengthAndBehindAppendZero(cardNumByteArr, 16); + String logicCard = BytesUtil.binary(logicCardNum, 10); + + log.info("[===浜ゆ槗璁板綍===]浜ゆ槗娴佹按鍙:{}, 妗╃紪鍙:{}, 鏋彿:{}, 寮濮嬫椂闂:{}, 缁撴潫鏃堕棿:{}, 灏栧崟浠:{}, 灏栫數閲:{}, 璁℃崯灏栫數閲:{}, 灏栭噾棰:{}, " + + "宄板崟浠:{}, 宄扮數閲:{}, 璁℃崯宄扮數閲:{}, 宄伴噾棰:{}, 骞冲崟浠:{}, 骞崇數閲:{}, 璁℃崯骞崇數閲:{}, 骞抽噾棰:{}, " + + "璋峰崟浠:{}, 璋风數閲:{}, 璁℃崯璋风數閲:{}, 璋烽噾棰:{}, 鐢佃〃鎬昏捣鍊:{}, 鐢佃〃鎬绘鍊:{}, 鎬荤數閲:{}, 璁℃崯鎬荤數閲:{}, 娑堣垂閲戦:{}, " + + "鐢靛姩姹借溅鍞竴鏍囪瘑:{}, 浜ゆ槗鏍囪瘑:{}, 浜ゆ槗鏃ユ湡銆佹椂闂:{}, 鍋滄鍘熷洜鐮:{}, 鍋滄鍘熷洜鎻忚堪:{}, 鐗╃悊鍗″彿:{}", + orderCode, pileSn, connectorCode, startTime, endTime, sharpPrice, sharpUsedElectricity, sharpPlanLossElectricity, sharpAmount, + peakPrice, peakUsedElectricity, peakPlanLossElectricity, peakAmount, flatPrice, flatUsedElectricity, flatPlanLossElectricity, flatAmount, + valleyPrice, valleyUsedElectricity, valleyPlanLossElectricity, valleyAmount, ammeterTotalStart, ammeterTotalEnd, totalElectricity, planLossTotalElectricity, + consumptionAmount, vinCode, transactionIdentifier, transactionTime, stopReason, stopReasonMsg, logicCard); + + // 浜ゆ槗璁板綍灏佽鍒板璞¢噷 + TransactionRecordsData data = TransactionRecordsData.builder() + .orderCode(orderCode) + .pileSn(pileSn) + .connectorCode(connectorCode) + .startTime(startTime) + .endTime(endTime) + .sharpPrice(sharpPrice) + .sharpUsedElectricity(sharpUsedElectricity) + .sharpPlanLossElectricity(sharpPlanLossElectricity) + .sharpAmount(sharpAmount) + .peakPrice(peakPrice) + .peakUsedElectricity(peakUsedElectricity) + .peakPlanLossElectricity(peakPlanLossElectricity) + .peakAmount(peakAmount) + .flatPrice(flatPrice) + .flatUsedElectricity(flatUsedElectricity) + .flatPlanLossElectricity(flatPlanLossElectricity) + .flatAmount(flatAmount) + .valleyPrice(valleyPrice) + .valleyUsedElectricity(valleyUsedElectricity) + .valleyPlanLossElectricity(valleyPlanLossElectricity) + .valleyAmount(valleyAmount) + .ammeterTotalStart(ammeterTotalStart) + .ammeterTotalEnd(ammeterTotalEnd) + .totalElectricity(totalElectricity) + .planLossTotalElectricity(planLossTotalElectricity) + .consumptionAmount(consumptionAmount) + .vinCode(vinCode) + .transactionIdentifier(transactionIdentifier) + .transactionTime(transactionTime) + .stopReasonMsg(stopReasonMsg) + .logicCard(logicCard) + .build(); + + // 淇濆瓨鎶ユ枃 + String jsonMsg = JSONObject.toJSONString(data); + pileMsgRecordService.save(pileSn, pileSn + connectorCode, type, jsonMsg, ykcDataProtocol.getHEXString()); + + // 澶勭悊璁㈠崟鍔犻攣 + String lockKey = "settle_order_" + orderCode; + String uuid = IdUtils.fastUUID(); + try { + // redis閿 + Boolean isLock = redisCache.lock(lockKey, uuid, 1500); + if (isLock) { + processOrder(data); + } + } catch (Exception e) { + log.error("澶勭悊璁㈠崟鍙戠敓寮傚父", e); + } finally { + if (uuid.equals(redisCache.getCacheObject(lockKey).toString())) { + redisCache.unLock(lockKey); + } + } + + // TODO 灏嗗紑濮嬫椂闂村拰缁撴潫鏃堕棿瀛樺叆璁㈠崟琛ㄤ腑 + // OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder() + // .orderCode(orderCode) + // .chargeStartTime() + // .chargeEndTime() + // .build() + + + /* + 搴旂瓟 + 纭缁撴灉 0x00 涓婁紶鎴愬姛 0x01 闈炴硶璐﹀崟 + 2022骞12鏈15鏃11鐐28鍒嗗彂鐜拌繑鍥 01闈炴硶璐﹀崟锛屽厖鐢垫々浼氭寔缁笂浼犱氦鏄撹褰曪紝鍚庨潰浜х敓鐨勪氦鏄撹褰曡闃诲 + */ + byte[] confirmResultBytes = Constants.zeroByteArray; + byte[] concatMsgBody = Bytes.concat(orderCodeByteArr, confirmResultBytes); + + return getResult(ykcDataProtocol, concatMsgBody); + } + + private void processOrder(TransactionRecordsData data) { + String orderCode = data.getOrderCode(); + // 鏍规嵁璁㈠崟鍙锋煡璇㈣鍗曚俊鎭 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderBasicInfo != null) { + // 骞冲彴瀛樺湪璁㈠崟 + orderBasicInfo.setReason(data.getStopReasonMsg()); + // 濡傛灉璁㈠崟鐘舵佷负 寮傚父锛屽垯鏀逛负 寰呯粨绠 + if (StringUtils.equals(OrderStatusEnum.ABNORMAL.getValue(), orderBasicInfo.getOrderStatus())) { + orderBasicInfo.setOrderStatus(OrderStatusEnum.STAY_SETTLEMENT.getValue()); + } + + // 鏍¢獙涓涓嬪紑濮嬫椂闂村拰缁撴潫鏃堕棿锛岄槻姝㈠厖鐢典腑妗╃绾匡紝鏃堕棿涓嶅噯纭 + if (Objects.isNull(orderBasicInfo.getChargeStartTime())) { // 寮濮嬫椂闂 + orderBasicInfo.setChargeStartTime(DateUtils.parseDate(data.getStartTime())); + } + if (Objects.isNull(orderBasicInfo.getChargeEndTime())) { // 缁撴潫鏃堕棿 + orderBasicInfo.setChargeEndTime(DateUtils.parseDate(data.getEndTime())); + } + + orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo); + + // 缁撶畻璁㈠崟鎿嶄綔 + try { + orderBasicInfoService.settleOrder(data, orderBasicInfo); + } catch (Exception e) { + log.error("缁撶畻璁㈠崟鍙戠敓寮傚父", e); + } + } else { + // 骞冲彴娌℃湁鏌ュ埌璁㈠崟 + orderBasicInfoService.saveAbnormalOrder(data); + log.warn("鍏呯數妗╀紶鏉ョ殑浜ゆ槗璁板綍锛屾牴鎹鍗曞彿:{}鏌ヨ涓嶅埌璁㈠崟锛屽垽瀹氫负闈炴硶璐﹀崟", orderCode); + } + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/UploadRealTimeMonitorHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/UploadRealTimeMonitorHandler.java new file mode 100644 index 000000000..5e7cc98a3 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/UploadRealTimeMonitorHandler.java @@ -0,0 +1,267 @@ +package com.jsowell.netty.handler; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.enums.ykc.YKCPileFaultReasonEnum; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.service.IPileBasicInfoService; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.Objects; + +/** + * 鑾峰彇妗╀笂浼犵殑瀹炴椂鐩戞祴鏁版嵁 + * + * @author JS-ZZA + * @date 2022/9/19 9:08 + */ +@Slf4j +@Component +public class UploadRealTimeMonitorHandler extends AbstractHandler { + private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.UPLOAD_REAL_TIME_MONITOR_DATA_CODE.getBytes()); + private final String oldVersionType = YKCUtils.frameType2Str(YKCFrameTypeCode.UPLOAD_REAL_TIME_MONITOR_DATA_OLD_VERSION_CODE.getBytes()); + + @Override + public void afterPropertiesSet() throws Exception { + YKCOperateFactory.register(type, this); + YKCOperateFactory.register(oldVersionType, this); + } + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Override + public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { + log.info("[===鑾峰彇妗╀笂浼犵殑瀹炴椂鐩戞祴鏁版嵁===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); + RealTimeMonitorData realTimeMonitorData = new RealTimeMonitorData(); + + // 鑾峰彇娑堟伅浣 + byte[] msgBody = ykcDataProtocol.getMsgBody(); + // log.info("涓婁紶瀹炴椂鏁版嵁msgBody:{}", BytesUtil.bcd2Str(msgBody)); + int startIndex = 0; + int length = 16; + + // 浜ゆ槗娴佹按鍙 + byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String orderCode = BytesUtil.bcd2Str(orderCodeByteArr); + realTimeMonitorData.setOrderCode(orderCode); + + // 妗╃紪鐮 + startIndex += length; + length = 7; + byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String pileSn = BytesUtil.bcd2Str(pileSnByteArr); + realTimeMonitorData.setPileSn(pileSn); + + // 淇濆瓨鏃堕棿 + saveLastTime(pileSn); + + // 鏋彿 + startIndex += length; + length = 1; + byte[] pileConnectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorCode = BytesUtil.bcd2Str(pileConnectorCodeByteArr); + realTimeMonitorData.setConnectorCode(connectorCode); + + // 鏋彛鐘舵 0x00:绂荤嚎 0x01:鏁呴殰 0x02:绌洪棽 0x03:鍏呯數 + startIndex += length; + length = 1; + byte[] connectorStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String connectorStatus = BytesUtil.bcd2Str(connectorStatusByteArr); + realTimeMonitorData.setConnectorStatus(connectorStatus); + + // 鏄惁褰掍綅 0x00:鍚 0x01:鏄 0x02:鏈煡锛堟棤娉曟娴嬪埌鏋槸鍚︽彃鍥炴灙搴у嵆 鏈煡锛 + startIndex += length; + length = 1; + byte[] homingFlagByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String homingFlag = BytesUtil.bcd2Str(homingFlagByteArr); + realTimeMonitorData.setHomingFlag(homingFlag); + + // 鏄惁鎻掓灙 0x00:鍚 0x01:鏄 + startIndex += length; + length = 1; + byte[] putGunTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String putGunType = BytesUtil.bcd2Str(putGunTypeByteArr); + realTimeMonitorData.setPutGunType(putGunType); + + // 杈撳嚭鐢靛帇 绮剧‘鍒板皬鏁扮偣鍚庝竴浣嶏紱寰呮満缃浂 + startIndex += length; + length = 2; + byte[] outputVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String outputVoltage = YKCUtils.convertVoltageCurrent(outputVoltageByteArr); + realTimeMonitorData.setOutputVoltage(outputVoltage); + + // 杈撳嚭鐢垫祦 绮剧‘鍒板皬鏁扮偣鍚庝竴浣嶏紱寰呮満缃浂 + startIndex += length; + length = 2; + byte[] outputCurrentByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String outputCurrent = YKCUtils.convertVoltageCurrent(outputCurrentByteArr); + realTimeMonitorData.setOutputCurrent(outputCurrent); + + // 鏋嚎娓╁害 鏁村舰, 鍋忕Щ閲-50锛涘緟鏈虹疆闆 + startIndex += length; + length = 1; + byte[] gunLineTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String gunLineTemperature = String.valueOf(gunLineTemperatureByteArr[0]); + realTimeMonitorData.setGunLineTemperature(gunLineTemperature); + + // 鏋嚎缂栫爜 娌℃湁缃浂 + startIndex += length; + length = 8; + byte[] gunLineCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String gunLineCode = BytesUtil.bcd2Str(gunLineCodeByteArr); + realTimeMonitorData.setGunLineCode(gunLineCode); + + // SOC 寰呮満缃浂锛涗氦娴佹々缃浂 + startIndex += length; + length = 1; + byte[] SOCByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String SOC = String.valueOf(SOCByteArr[0]); + realTimeMonitorData.setSOC(SOC); + + // 鐢垫睜缁勬渶楂樻俯搴 鏁村舰, 鍋忕Щ閲-50 潞C锛涘緟鏈虹疆闆讹紱 浜ゆ祦妗╃疆闆 + startIndex += length; + length = 1; + byte[] batteryMaxTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String batteryMaxTemperature = String.valueOf(batteryMaxTemperatureByteArr[0]); + realTimeMonitorData.setBatteryMaxTemperature(batteryMaxTemperature); + + // 绱鍏呯數鏃堕棿 鍗曚綅: min锛涘緟鏈虹疆闆 + startIndex += length; + length = 2; + byte[] sumChargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + int sumChargingTime = BytesUtil.bytesToIntLittle(sumChargingTimeByteArr); + realTimeMonitorData.setSumChargingTime(String.valueOf(sumChargingTime)); + + // 鍓╀綑鏃堕棿 鍗曚綅: min锛涘緟鏈虹疆闆躲佷氦娴佹々缃浂 + startIndex += length; + length = 2; + byte[] timeRemainingByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + int timeRemaining = BytesUtil.bytesToIntLittle(timeRemainingByteArr); + realTimeMonitorData.setTimeRemaining(String.valueOf(timeRemaining)); + + // 鍏呯數搴︽暟 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紱寰呮満缃浂 + startIndex += length; + length = 4; + byte[] chargingDegreeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String chargingDegree = YKCUtils.convertDecimalPoint(chargingDegreeByteArr, 4); + realTimeMonitorData.setChargingDegree(chargingDegree); + + // 璁℃崯鍏呯數搴︽暟 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紱寰呮満缃浂 鏈缃鎹熸瘮渚嬫椂绛変簬鍏呯數搴︽暟 + startIndex += length; + length = 4; + byte[] lossDegreeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String lossDegree = YKCUtils.convertDecimalPoint(lossDegreeByteArr, 4); + realTimeMonitorData.setLossDegree(lossDegree); + + // 宸插厖閲戦 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紱寰呮満缃浂 锛堢數璐+鏈嶅姟璐癸級 *璁℃崯鍏呯數搴︽暟 + startIndex += length; + length = 4; + byte[] chargingAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String chargingAmount = YKCUtils.convertDecimalPoint(chargingAmountByteArr, 4); + realTimeMonitorData.setChargingAmount(chargingAmount); + + /** + * 纭欢鏁呴殰 + * + * Bit 浣嶈〃绀猴紙0 鍚 1 鏄級, 浣庝綅鍒伴珮浣嶉『搴 + * Bit1:鎬ュ仠鎸夐挳鍔ㄤ綔鏁呴殰锛 + * Bit2:鏃犲彲鐢ㄦ暣娴佹ā鍧楋紱 + * Bit3:鍑洪鍙f俯搴﹁繃楂橈紱 + * Bit4:浜ゆ祦闃查浄鏁呴殰锛 + * Bit5:浜ょ洿娴佹ā鍧 DC20 閫氫俊涓柇锛 + * Bit6:缁濈紭妫娴嬫ā鍧 FC08 閫氫俊涓柇锛 + * Bit7:鐢靛害琛ㄩ氫俊涓柇锛 + * Bit8:璇诲崱鍣ㄩ氫俊涓柇锛 + * Bit9: RC10 閫氫俊涓柇锛 + * Bit10:椋庢墖璋冮熸澘鏁呴殰锛 + * Bit11:鐩存祦鐔旀柇鍣ㄦ晠闅滐紱 + * Bit12:楂樺帇鎺ヨЕ鍣ㄦ晠闅滐紱 + * Bit13:闂ㄦ墦寮锛 + */ + startIndex += length; + length = 2; + byte[] hardwareFaultTempByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String hardwareFaultTemp = BytesUtil.bcd2Str(hardwareFaultTempByteArr); + String faultReason = "鏃"; + + if (!StringUtils.equals(hardwareFaultTemp, "0000")) { + // 涓嶇瓑浜0000璇存槑鏈夋晠闅 + StringBuffer sb = new StringBuffer(hardwareFaultTemp); + String lowOrder = sb.substring(0, 2); + String highOrder = sb.substring(2, 4); + + // String hardwareFault = highOrder + lowOrder; + byte[] hardwareFaultByteArr = BytesUtil.str2Bcd(highOrder + lowOrder); + String binStr = BytesUtil.bytes2BinStr(hardwareFaultByteArr); + // log.info("binStr:{}", binStr); // 0000 0000 0000 0001 + int faultCode = 0; + for (int i = 0; i < binStr.length(); i++) { + if (binStr.charAt(i) == '1') { + faultCode = 15 - i; + break; + } + } + faultReason = YKCPileFaultReasonEnum.getValueByCode(faultCode); + // log.info("鏁呴殰鐮:{}, 鏁呴殰鍘熷洜:{}", faultCode, faultReason); + } + realTimeMonitorData.setHardwareFault(hardwareFaultTemp); + + if (!StringUtils.equals(connectorStatus, "02")) { + log.info("0x13涓婁紶瀹炴椂鐩戞祴鏁版嵁==浜ゆ槗娴佹按鍙:{}, 妗╃紪鍙:{}, 鏋彿:{}, 鐘舵:{}, 鏋槸鍚﹀綊浣:{}, 鏄惁鎻掓灙:{}, 杈撳嚭鐢靛帇:{}, 杈撳嚭鐢垫祦:{}, 鏋嚎娓╁害:{}, " + + "鏋嚎缂栫爜:{}, SOC:{}, 鐢垫睜缁勬渶楂樻俯搴:{}, 绱鍏呯數鏃堕棿:{}, 鍓╀綑鏃堕棿:{}, 鍏呯數搴︽暟:{}, 璁版崯鍏呯數搴︽暟:{}, 宸插厖閲戦:{}, " + + "纭欢鏁呴殰:{}, 鏁呴殰鐮佽浆鎹㈢粨鏋:{}", orderCode, pileSn, connectorCode, connectorStatus, homingFlag, putGunType, outputVoltage, + outputCurrent, gunLineTemperature, gunLineCode, SOC, batteryMaxTemperature, sumChargingTime, timeRemaining, + chargingDegree, lossDegree, chargingAmount, hardwareFaultTemp, faultReason + ); + } + + // 鍏叡鏂规硶淇敼鐘舵 + pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, connectorCode, connectorStatus, putGunType); + + // 03琛ㄧず鍏呯數涓 + if (StringUtils.equals(connectorStatus, "03")) { + // 鍏呯數鏃朵繚瀛樺疄鏃舵暟鎹埌redis + pileBasicInfoService.saveRealTimeMonitorData2Redis(realTimeMonitorData); + + // 鏌ヨ鏁版嵁搴撲腑璇ヨ鍗曞綋鍓嶄俊鎭 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (Objects.nonNull(orderInfo)) { + boolean updateFlag = false; + if (StringUtils.equals(orderInfo.getOrderStatus(), OrderStatusEnum.NOT_START.getValue()) + || StringUtils.equals(orderInfo.getOrderStatus(), OrderStatusEnum.ABNORMAL.getValue())) { + updateFlag = true; + // 濡傛灉鏄湭鍚姩鐘舵佹垨鑰呭紓甯哥姸鎬, 淇敼杩欎釜璁㈠崟鐘舵佷负鍏呯數涓 + orderInfo.setOrderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue()); + } + + // 濡傛灉鍘熸潵娌℃湁寮濮嬪厖鐢垫椂闂村氨淇濆瓨褰撳墠鏃堕棿涓哄紑濮嬪厖鐢垫椂闂 + if (orderInfo.getChargeStartTime() == null) { + updateFlag = true; + orderInfo.setChargeStartTime(new Date()); + } + + if (updateFlag) { + orderBasicInfoService.updateOrderBasicInfo(orderInfo); + } + } + } + return null; + } + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServer.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServer.java new file mode 100644 index 000000000..15305e30b --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServer.java @@ -0,0 +1,77 @@ +package com.jsowell.netty.server.yunkuaichong; + +import com.jsowell.common.constant.Constants; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.logging.LogLevel; +import io.netty.handler.logging.LoggingHandler; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.CommandLineRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.net.InetSocketAddress; + +@Slf4j +@Component +public class NettyServer implements CommandLineRunner { + @Resource + private NettyServerChannelInitializer nettyServerChannelInitializer; + + @Order(value = 1) + @Override + public void run(String... args) throws Exception { + InetSocketAddress address = new InetSocketAddress(Constants.SOCKET_IP, Constants.SOCKET_PORT); + this.start(address); + } + + public void start(InetSocketAddress address) { + // log.info("========NettyServer.start order 1"); + //閰嶇疆鏈嶅姟绔殑NIO绾跨▼缁 + EventLoopGroup bossGroup = new NioEventLoopGroup(1); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + + try { + ServerBootstrap bootstrap = new ServerBootstrap() // //鍚姩NIO鏈嶅姟鐨勮緟鍔╁惎鍔ㄧ被 + .group(bossGroup, workerGroup) // 缁戝畾绾跨▼姹 + .channel(NioServerSocketChannel.class) // 鍚姩鏈嶅姟鏃, 閫氳繃鍙嶅皠鍒涘缓涓涓狽ioServerSocketChannel瀵硅薄 + + /* + ===> 鏈嶅姟鍣ㄥ垵濮嬪寲鏃舵墽琛, 灞炰簬AbstracBootstrap鐨勬柟娉 + */ + .handler(new LoggingHandler(LogLevel.DEBUG)) // handler鍦ㄥ垵濮嬪寲鏃跺氨浼氭墽琛岋紝鍙互璁剧疆鎵撳嵃鏃ュ織绾у埆 + // 璁剧疆tcp缂撳啿鍖, 鍙繛鎺ラ槦鍒楀ぇ灏 + .option(ChannelOption.SO_BACKLOG, 128) //鏈嶅姟绔帴鍙楄繛鎺ョ殑闃熷垪闀垮害锛屽鏋滈槦鍒楀凡婊★紝瀹㈡埛绔繛鎺ュ皢琚嫆缁 + .option(ChannelOption.SO_REUSEADDR, true) //鍏佽閲嶅浣跨敤鏈湴鍦板潃鍜岀鍙 + + /* + ===> 瀹㈡埛绔繛鎺ユ垚鍔熶箣鍚庢墽琛, 灞炰簬ServerBootstrap鐨勬柟娉,缁ф壙鑷狝bstractBootstrap + */ + .childOption(ChannelOption.SO_KEEPALIVE, true) //涓ゅ皬鏃舵病鏈夋暟鎹氫俊鏃, 鍚敤蹇冭烦淇濇椿鏈哄埗鎺㈡祴瀹㈡埛绔槸鍚﹁繛鎺ユ湁鏁 + .childOption(ChannelOption.SO_REUSEADDR, true) + .childHandler(nettyServerChannelInitializer)//缂栫爜瑙g爜 + + // 鍦板潃 + .localAddress(address); + + // 缁戝畾绔彛锛屽紑濮嬫帴鏀惰繘鏉ョ殑杩炴帴 + ChannelFuture future = bootstrap.bind(address.getPort()).sync(); + if (future.isSuccess()) { + log.info("NettyServer鍚姩鎴愬姛, 寮濮嬬洃鍚鍙:{}", address.getPort()); + } else { + log.error("NettyServer鍚姩澶辫触", future.cause()); + } + //鍏抽棴channel鍜屽潡锛岀洿鍒板畠琚叧闂 + future.channel().closeFuture().sync(); + } catch (Exception e) { + log.error("NettyServer.start error", e); + bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(); + } + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java new file mode 100644 index 000000000..ad6efd175 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java @@ -0,0 +1,32 @@ +package com.jsowell.netty.server.yunkuaichong; + +import com.jsowell.netty.decoder.StartAndLengthFieldFrameDecoder; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.bytes.ByteArrayDecoder; +import io.netty.handler.timeout.IdleStateHandler; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.concurrent.TimeUnit; + +@Component +public class NettyServerChannelInitializer extends ChannelInitializer { + + @Resource + NettyServerHandler nettyServerHandler; + + @Override + protected void initChannel(SocketChannel channel) throws Exception { + ChannelPipeline pipeline = channel.pipeline(); + // pipeline.addLast("decoder",new CustomDecoder()); + pipeline.addLast("frameDecoder", new StartAndLengthFieldFrameDecoder(0x68)); + pipeline.addLast("decoder", new ByteArrayDecoder()); + pipeline.addLast("encoder", new ByteArrayDecoder()); + //璇昏秴鏃舵椂闂磋缃负10s锛0琛ㄧず涓嶇洃鎺 + pipeline.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS)); + pipeline.addLast("handler", nettyServerHandler); + } + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java new file mode 100644 index 000000000..c02e23769 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java @@ -0,0 +1,203 @@ +package com.jsowell.netty.server.yunkuaichong; + +import com.google.common.collect.Lists; +import com.jsowell.common.enums.ykc.PileChannelEntity; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.service.yunkuaichong.YKCBusinessService; +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelId; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.handler.timeout.IdleState; +import io.netty.handler.timeout.IdleStateEvent; +import io.netty.handler.timeout.ReadTimeoutException; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.xml.bind.DatatypeConverter; +import java.net.InetSocketAddress; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + +/** + * netty鏈嶅姟绔鐞嗙被 + */ +@ChannelHandler.Sharable +@Slf4j +@Component +public class NettyServerHandler extends ChannelInboundHandlerAdapter { + + @Autowired + private YKCBusinessService ykcService; + + /** + * 绠$悊涓涓叏灞map锛屼繚瀛樿繛鎺ヨ繘鏈嶅姟绔殑閫氶亾鏁伴噺 + */ + private static final ConcurrentHashMap CHANNEL_MAP = new ConcurrentHashMap<>(); + + private final List notPrintFrameTypeList = Lists.newArrayList("0x03"); + + /** + * 鏈夊鎴风杩炴帴鏈嶅姟鍣ㄤ細瑙﹀彂姝ゅ嚱鏁 + * 杩炴帴琚缓绔嬪苟涓斿噯澶囪繘琛岄氫俊鏃惰璋冪敤 + */ + @Override + public void channelActive(ChannelHandlerContext ctx) { + InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress(); + String clientIp = insocket.getAddress().getHostAddress(); + int clientPort = insocket.getPort(); + //鑾峰彇杩炴帴閫氶亾鍞竴鏍囪瘑 + ChannelId channelId = ctx.channel().id(); + //濡傛灉map涓笉鍖呭惈姝よ繛鎺ワ紝灏变繚瀛樿繛鎺 + if (CHANNEL_MAP.containsKey(channelId)) { + log.info("瀹㈡埛绔恵}銆戞槸杩炴帴鐘舵侊紝杩炴帴閫氶亾鏁伴噺: {}", channelId, CHANNEL_MAP.size()); + } else { + //淇濆瓨杩炴帴 + CHANNEL_MAP.put(channelId, ctx); + log.info("瀹㈡埛绔恵}銆, 杩炴帴netty鏈嶅姟鍣╗IP:{}--->PORT:{}], 杩炴帴閫氶亾鏁伴噺: {}", channelId, clientIp, clientPort, CHANNEL_MAP.size()); + } + } + + /** + * 鏈夊鎴风鍙戞秷鎭細瑙﹀彂姝ゅ嚱鏁 + */ + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + // log.info("鍔犺浇瀹㈡埛绔姤鏂=== channelId:" + ctx.channel().id() + ", msg:" + msg); + // 涓嬮潰鍙互瑙f瀽鏁版嵁锛屼繚瀛樻暟鎹紝鐢熸垚杩斿洖鎶ユ枃锛屽皢闇瑕佽繑鍥炴姤鏂囧啓鍏rite鍑芥暟 + byte[] arr = (byte[]) msg; + // 鑾峰彇甯х被鍨 + String frameType = YKCUtils.frameType2Str(BytesUtil.copyBytes(arr, 5, 1)); + // 鑾峰彇搴忓垪鍙峰煙 + int serialNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(arr, 2, 2)); + + // new + String hexString = DatatypeConverter.printHexBinary(arr); + + // 蹇冭烦鍖0x03鏃ュ織澶锛岄犳垚鏃ュ織鏂囦欢杩囧ぇ锛屾敼涓轰笉鎵撳嵃 + if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) { + log.info("銆<<<<<骞冲彴鏀跺埌娑堟伅<<<<<銆慶hannel:{}, 甯х被鍨:{}, 搴忓垪鍙峰煙:{}, 鎶ユ枃:{}, new鎶ユ枃:{}, msg:{}", + ctx.channel().id(), frameType, serialNumber, BytesUtil.binary(arr, 16), hexString, Arrays.toString(arr)); + } + + // 澶勭悊鏁版嵁 + byte[] result = ykcService.process(arr, ctx.channel()); + if (Objects.nonNull(result)) { + // 鍝嶅簲瀹㈡埛绔 + ByteBuf buffer = ctx.alloc().buffer().writeBytes(result); + this.channelWrite(ctx.channel().id(), buffer); + if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) { + log.info("銆>>>>>骞冲彴鍝嶅簲娑堟伅>>>>>銆:{}", BytesUtil.binary(result, 16)); + } + } + } + + /** + * 鏈夊鎴风缁堟杩炴帴鏈嶅姟鍣ㄤ細瑙﹀彂姝ゅ嚱鏁 + */ + @Override + public void channelInactive(ChannelHandlerContext ctx) { + InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress(); + String clientIp = insocket.getAddress().getHostAddress(); + ChannelId channelId = ctx.channel().id(); + //鍖呭惈姝ゅ鎴风鎵嶅幓鍒犻櫎 + if (CHANNEL_MAP.containsKey(channelId)) { + ykcService.exit(channelId); + //鍒犻櫎杩炴帴 + CHANNEL_MAP.remove(channelId); + log.info("瀹㈡埛绔恵}銆, 閫鍑簄etty鏈嶅姟鍣╗IP:{}--->PORT:{}], 杩炴帴閫氶亾鏁伴噺: {}", channelId, clientIp, insocket.getPort(), CHANNEL_MAP.size()); + } + } + + @Override + public void handlerAdded(ChannelHandlerContext ctx) throws Exception { // (2) + // Channel incoming = ctx.channel(); + // log.info("handlerAdded: handler琚坊鍔犲埌channel鐨刾ipeline connect:" + incoming.remoteAddress()); + } + + @Override + public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { // (3) + // Channel incoming = ctx.channel(); + // log.info("handlerRemoved: handler浠巆hannel鐨刾ipeline涓Щ闄 connect:" + incoming.remoteAddress()); + // ChannelMapByEntity.removeChannel(incoming); + // ChannelMap.removeChannel(incoming); + } + + @Override + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { + Channel channel = ctx.channel(); + // log.info("channel:銆恵}銆戣鏁版嵁瀹屾垚", channel.id()); + super.channelReadComplete(ctx); + } + + /** + * 鏈嶅姟绔粰瀹㈡埛绔彂閫佹秷鎭 + * + * @param channelId 杩炴帴閫氶亾鍞竴id + * @param msg 闇瑕佸彂閫佺殑娑堟伅鍐呭 + */ + public void channelWrite(ChannelId channelId, Object msg) throws Exception { + ChannelHandlerContext ctx = CHANNEL_MAP.get(channelId); + if (ctx == null) { + log.info("閫氶亾銆恵}銆戜笉瀛樺湪", channelId); + return; + } + if (msg == null || msg == "") { + log.info("鏈嶅姟绔搷搴旂┖鐨勬秷鎭"); + return; + } + //灏嗗鎴风鐨勪俊鎭洿鎺ヨ繑鍥炲啓鍏tx + ctx.write(msg); + //鍒锋柊缂撳瓨鍖 + ctx.flush(); + } + + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + String socketString = ctx.channel().remoteAddress().toString(); + ChannelId channelId = ctx.channel().id(); + String pileSn = PileChannelEntity.getPileSnByChannelId(channelId.asLongText()); + if (evt instanceof IdleStateEvent) { // 瓒呮椂浜嬩欢 + IdleStateEvent event = (IdleStateEvent) evt; + boolean flag = false; + if (event.state() == IdleState.READER_IDLE) { // 璇 + flag = true; + log.info("Client-IP:銆恵}銆, channelId:銆恵}銆, pileSn:銆恵}銆, READER_IDLE 璇昏秴鏃", socketString, channelId, pileSn); + } else if (event.state() == IdleState.WRITER_IDLE) { // 鍐 + flag = true; + log.info("Client-IP:銆恵}銆, channelId:銆恵}銆, pileSn:銆恵}銆, WRITER_IDLE 鍐欒秴鏃", socketString, channelId, pileSn); + } else if (event.state() == IdleState.ALL_IDLE) { // 鍏ㄩ儴 + flag = true; + log.info("Client-IP:銆恵}銆, channelId:銆恵}銆, pileSn:銆恵}銆, ALL_IDLE 鎬昏秴鏃", socketString, channelId, pileSn); + } + // if (flag) { + // ctx.channel().close(); + // } + } + } + + /** + * 鍙戠敓寮傚父浼氳Е鍙戞鍑芥暟 + */ + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + ChannelId channelId = ctx.channel().id(); + log.error("鍙戠敓寮傚父 channelId:{}", channelId.asShortText(), cause); + cause.printStackTrace(); + // 濡傛灉妗╄繛鍒板钩鍙帮紝鍦1鍒嗛挓鍐呮病鏈夊彂閫佹暟鎹繃鏉ワ紝浼氭姤ReadTimeoutException寮傚父 + if (cause instanceof ReadTimeoutException) { + if (log.isTraceEnabled()) { + log.trace("Connection timeout 銆恵}銆", ctx.channel().remoteAddress()); + } + log.info("銆恵}銆戝彂鐢熶簡閿欒, 姝よ繛鎺ヨ鍏抽棴, 姝ゆ椂杩為氭暟閲: {}", channelId, CHANNEL_MAP.size()); + ctx.channel().close(); + } + } +} \ No newline at end of file diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/YKCBusinessService.java b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/YKCBusinessService.java new file mode 100644 index 000000000..f3d8102dd --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/YKCBusinessService.java @@ -0,0 +1,25 @@ +package com.jsowell.netty.service.yunkuaichong; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelId; + +/** + * 浜戝揩鍏呭鐞唖ervice + */ + +public interface YKCBusinessService { + /** + * 澶勭悊妗╁彂鏉ョ殑璇锋眰 + * 涓嶉渶瑕佸簲绛旂殑杩斿洖null + * @param msg 璇锋眰鎶ユ枃 + * @param channel 閫氶亾淇℃伅 + * @return 缁撴灉 + */ + byte[] process(byte[] msg, Channel channel); + + /** + * 妗╅鍑 + * @param channelId channelId + */ + void exit(ChannelId channelId); +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/YKCPushCommandService.java b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/YKCPushCommandService.java new file mode 100644 index 000000000..6d59df3c2 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/YKCPushCommandService.java @@ -0,0 +1,64 @@ +package com.jsowell.netty.service.yunkuaichong; + +import com.jsowell.netty.command.ykc.GetRealTimeMonitorDataCommand; +import com.jsowell.netty.command.ykc.IssueQRCodeCommand; +import com.jsowell.netty.command.ykc.ProofreadTimeCommand; +import com.jsowell.netty.command.ykc.PublishPileBillingTemplateCommand; +import com.jsowell.netty.command.ykc.RebootCommand; +import com.jsowell.netty.command.ykc.StartChargingCommand; +import com.jsowell.netty.command.ykc.StopChargingCommand; +import com.jsowell.netty.command.ykc.UpdateFileCommand; + +/** + * 浜戝揩鍏呭崗璁紝鍚戝厖鐢垫々鍙戦佸懡浠ervice + */ +public interface YKCPushCommandService { + + /** + * 鍙戦佸惎鍔ㄥ厖鐢垫寚浠 + * @param startChargingCommand + */ + void pushStartChargingCommand(StartChargingCommand startChargingCommand); + + /** + * 鍙戦佸仠姝㈠厖鐢垫寚浠 + * @param stopChargingCommand + */ + void pushStopChargingCommand(StopChargingCommand stopChargingCommand); + + /** + * 璇诲彇瀹炴椂鐩戞祴鏁版嵁鍛戒护 + * @param command + */ + void pushGetRealTimeMonitorDataCommand(GetRealTimeMonitorDataCommand command); + + /** + * 鍙戦侀噸鍚寚浠 + * @param command + */ + void pushRebootCommand(RebootCommand command); + + /** + * 鍙戦佷笅鍙戜簩缁寸爜鍛戒护 + * @param command + */ + void pushIssueQRCodeCommand(IssueQRCodeCommand command); + + /** + * 鍙戦佸鏃跺懡浠 + * @param command + */ + void pushProofreadTimeCommand(ProofreadTimeCommand command); + + /** + * 涓嬪彂璁¤垂妯℃澘鍛戒护 + * @param command + */ + void pushPublishPileBillingTemplate(PublishPileBillingTemplateCommand command); + + /** + * 鍙戦佽繙绋嬫洿鏂板懡浠 + * @param command + */ + void pushUpdateFileCommand(UpdateFileCommand command); +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCBusinessServiceImpl.java b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCBusinessServiceImpl.java new file mode 100644 index 000000000..26e41e063 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCBusinessServiceImpl.java @@ -0,0 +1,100 @@ +package com.jsowell.netty.service.yunkuaichong.impl; + +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.enums.ykc.PileChannelEntity; +import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.netty.handler.AbstractHandler; +import com.jsowell.netty.service.yunkuaichong.YKCBusinessService; +import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.service.IPileMsgRecordService; +import com.jsowell.pile.vo.web.OrderListVO; +import io.netty.channel.Channel; +import io.netty.channel.ChannelId; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Slf4j +@Service +public class YKCBusinessServiceImpl implements YKCBusinessService { + + @Autowired + private IPileMsgRecordService pileMsgRecordService; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Override + public byte[] process(byte[] msg, Channel channel) { + if (!YKCUtils.checkMsg(msg)) { + // 鏍¢獙涓嶉氳繃锛屼涪寮冩秷鎭 + return null; + } + YKCDataProtocol ykcDataProtocol = new YKCDataProtocol(msg); + // 鑾峰彇甯х被鍨 + String frameType = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType()); + // 鑾峰彇涓氬姟澶勭悊handler + AbstractHandler invokeStrategy = YKCOperateFactory.getInvokeStrategy(frameType); + return invokeStrategy.supplyProcess(ykcDataProtocol, channel); + } + + @Override + public void exit(ChannelId channelId) { + // 鑾峰彇妗╃紪鍙 + String pileSn = PileChannelEntity.getPileSnByChannelId(channelId.asLongText()); + if (StringUtils.isBlank(pileSn)) { + return; + } + log.info("鍏呯數妗╅鍑:{}, channelId:{}", pileSn, PileChannelEntity.getChannelByPileSn(pileSn).id()); + + // 鍏呯數妗╂柇寮杩炴帴锛屾墍鏈夋灙鍙i兘璁剧疆涓恒愮绾裤 + pileConnectorInfoService.updateConnectorStatusByPileSn(pileSn, PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue()); + + // 灏嗘妗╂鍦ㄨ繘琛屽厖鐢电殑璁㈠崟鐘舵佹敼涓 寮傚父 + List orderListVOS = orderBasicInfoService.selectChargingOrder(pileSn); + if (CollectionUtils.isNotEmpty(orderListVOS)) { + for (OrderListVO orderListVO : orderListVOS) { + if (StringUtils.equals(orderListVO.getOrderStatus(), OrderStatusEnum.IN_THE_CHARGING.getValue())) { + // 淇敼鏁版嵁搴撹鍗曠姸鎬 + OrderBasicInfo info = OrderBasicInfo.builder() + .id(Long.parseLong(orderListVO.getId())) + .orderStatus(OrderStatusEnum.ABNORMAL.getValue()) + .build(); + orderBasicInfoService.updateOrderBasicInfo(info); + log.info("鍏呯數妗:{}閫鍑, 淇敼鍏呯數妗╂鍦ㄥ厖鐢电殑璁㈠崟鐘舵佷负寮傚父, orderCode: {}", pileSn, orderListVO.getOrderCode()); + } + } + } + + // 璁板綍鍏呯數妗╅鍑簃sg + // 淇濆瓨鎶ユ枃 + String type = YKCFrameTypeCode.PILE_LOG_OUT.getCode() + ""; + String jsonMsg = YKCFrameTypeCode.PILE_LOG_OUT.getValue(); + pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ""); + + // 鑷姩閲嶅惎 鍙戦侀噸鍚寚浠 + // RebootCommand command = RebootCommand.builder().pileSn(pileSn).build(); + // ykcPushCommandService.pushRebootCommand(command); + + // 鍒犻櫎妗╃紪鍙峰拰channel鐨勫叧绯 + PileChannelEntity.removeByPileSn(pileSn); + } + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCPushCommandServiceImpl.java b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCPushCommandServiceImpl.java new file mode 100644 index 000000000..8de5bf249 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCPushCommandServiceImpl.java @@ -0,0 +1,341 @@ +package com.jsowell.netty.service.yunkuaichong.impl; + +import com.google.common.collect.Lists; +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.ykc.PileChannelEntity; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.CRC16Util; +import com.jsowell.common.util.Cp56Time2a.Cp56Time2aUtil; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.command.ykc.GetRealTimeMonitorDataCommand; +import com.jsowell.netty.command.ykc.IssueQRCodeCommand; +import com.jsowell.netty.command.ykc.ProofreadTimeCommand; +import com.jsowell.netty.command.ykc.PublishPileBillingTemplateCommand; +import com.jsowell.netty.command.ykc.RebootCommand; +import com.jsowell.netty.command.ykc.StartChargingCommand; +import com.jsowell.netty.command.ykc.StopChargingCommand; +import com.jsowell.netty.command.ykc.UpdateFileCommand; +import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileBillingTemplateService; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.service.IPileModelInfoService; +import com.jsowell.pile.service.IPileMsgRecordService; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import com.jsowell.pile.vo.web.PileModelInfoVO; +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +@Slf4j +@Service +public class YKCPushCommandServiceImpl implements YKCPushCommandService { + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private IPileModelInfoService pileModelInfoService; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private RedisCache redisCache; + + @Autowired + private IPileMsgRecordService pileMsgRecordService; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + // 闇瑕佽褰曟姤鏂囩殑鏁版嵁甯х被鍨 + private final List frameTypeList = Lists.newArrayList( + YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_RESTART_CODE.getBytes()), + YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_CONTROL_START_CODE.getBytes()), + YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_STOP_CHARGING_CODE.getBytes()) + ); + + public boolean push(byte[] msg, String pileSn, Enum frameTypeCode) { + // 閫氳繃妗╃紪鍙疯幏鍙朿hannel + Channel channel = PileChannelEntity.getChannelByPileSn(pileSn); + if (Objects.isNull(channel)) { + log.error("push鍛戒护澶辫触, 妗╁彿:{}鏃犳硶鑾峰彇鍒伴暱杩炴帴, 璇锋鏌ュ厖鐢垫々杩炴帴鐘舵!", pileSn); + return false; + } + /** + * 鎷兼帴鎶ユ枃 + */ + // 璧峰鏍囧織 + byte[] head = new byte[]{0x68}; + + // 搴忓垪鍙峰煙 + byte[] serialNumber = new byte[]{0x00, 0x00}; + + // 鍔犲瘑鏍囧織 + byte[] encryptFlag = new byte[]{0x00}; + + // 甯х被鍨嬫爣蹇 + byte[] frameType = new byte[]{(byte) ((YKCFrameTypeCode) frameTypeCode).getCode()}; + + // 搴忓垪鍙峰煙+鍔犲瘑鏍囧織+甯х被鍨嬫爣蹇+娑堟伅浣 + byte[] temp = Bytes.concat(serialNumber, encryptFlag, frameType, msg); + + // 鏁版嵁闀垮害 + byte[] length = BytesUtil.intToBytes(temp.length, 1); + + // 甯ф牎楠屽煙 + byte[] crc = BytesUtil.intToBytes(CRC16Util.calcCrc16(temp)); + // 杩斿洖鎶ユ枃 + byte[] writeMsg = Bytes.concat(head, length, temp, crc); + // 杩斿洖瀹屾暣鐨勬姤鏂 string绫诲瀷 + String wholeMsg= BytesUtil.binary(writeMsg, 16); + log.info("[" + channel.remoteAddress() + "] 涓诲姩鍙戦乸ush璇锋眰淇℃伅:{}", wholeMsg); + ByteBuf byteBuf = channel.alloc().buffer().writeBytes(writeMsg); + ChannelFuture channelFuture = channel.writeAndFlush(byteBuf); + channelFuture.addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture channelFuture) throws Exception { + // 妫鏌ユ搷浣滅殑鐘舵 + if (channelFuture.isSuccess()) { + log.info("push缁撴灉銆愭垚鍔熴, remoteAddress:{}, channelId:{}, 鎶ユ枃:{}, ", channel.remoteAddress(), channel.id(), wholeMsg); + } else { + // 濡傛灉鍙戠敓閿欒锛屽垯璁块棶鎻忚堪鍘熷洜鐨凾hrowable + Throwable cause = channelFuture.cause(); + cause.printStackTrace(); + log.info("push缁撴灉銆愬け璐ャ, remoteAddress:{}, channelId:{}, 鎶ユ枃:{}", channel.remoteAddress(), channel.id(), wholeMsg); + log.error("push鍙戦佸懡浠ゅけ璐", cause); + } + } + }); + + // 淇濆瓨鎶ユ枃 + String frameTypeStr = YKCUtils.frameType2Str(((YKCFrameTypeCode) frameTypeCode).getBytes()); + if (frameTypeList.contains(frameTypeStr)) { + pileMsgRecordService.save(pileSn, null, frameTypeStr, null, wholeMsg); + } + return true; + } + + /** + * 鍙戦佸惎鍔ㄥ厖鐢垫寚浠 + */ + @Override + public void pushStartChargingCommand(StartChargingCommand command) { + String pileSn = command.getPileSn(); + String connectorCode = command.getConnectorCode(); + String orderCode = command.getOrderCode(); + if (StringUtils.isEmpty(pileSn) || StringUtils.isEmpty(connectorCode) ) { + log.warn("杩滅▼鍚姩鍏呯數, 鍏呯數妗╃紪鍙峰拰鏋彛鍙蜂笉鑳戒负绌"); + return; + } + if (StringUtils.isEmpty(orderCode)) { + log.warn("杩滅▼鍚姩鍏呯數, 浜ゆ槗娴佹按鍙蜂笉鑳戒负绌"); + return; + } + if (command.getChargeAmount() == null || BigDecimal.ZERO.equals(command.getChargeAmount())) { + log.warn("杩滅▼鍚姩鍏呯數, 鍏呯數閲戦涓嶈兘涓0"); + return; + } + + // 鏋彛鍙 + byte[] connectorCodeByteArr = BytesUtil.str2Bcd(connectorCode); + + // 浜ゆ槗娴佹按鍙 + byte[] orderIdByteArr = BytesUtil.str2Bcd(orderCode); + + // 妗╃紪鍙 + byte[] pileSnByteArr = BytesUtil.str2Bcd(pileSn); + + // 閫昏緫鍗″彿 + String logicCardNum = StringUtils.isBlank(command.getLogicCardNum()) + ? Constants.ZERO + : command.getLogicCardNum(); + byte[] logicCardNumByteArr = BytesUtil.checkLengthAndFrontAppendZero(BytesUtil.str2Bcd(logicCardNum), 16); + + // 鐗╃悊鍗″彿 + String physicsCardNum = StringUtils.isBlank(command.getPhysicsCardNum()) + ? Constants.ZERO + : command.getPhysicsCardNum(); + byte[] physicsCardNumByteArr = BytesUtil.checkLengthAndFrontAppendZero(BytesUtil.str2Bcd(physicsCardNum), 16); + + // 璐︽埛浣欓 + BigDecimal chargeAmount = command.getChargeAmount(); + byte[] accountBalanceByteArr = YKCUtils.getPriceByte(chargeAmount.toString(), 2); + + byte[] msgBody = Bytes.concat(orderIdByteArr, pileSnByteArr, connectorCodeByteArr, logicCardNumByteArr, physicsCardNumByteArr, accountBalanceByteArr); + this.push(msgBody, pileSn, YKCFrameTypeCode.REMOTE_CONTROL_START_CODE); + log.info("銆=====骞冲彴涓嬪彂鍏呯數鎸囦护=====銆:璁㈠崟id:{}, 妗╁彿:{}, 鏋彛鍙:{}, 閫昏緫鍗″彿:{}, 鐗╃悊鍗″彿:{}, 璐︽埛浣欓:{}", + orderCode, pileSn, BytesUtil.bcd2Str(connectorCodeByteArr), logicCardNum, physicsCardNum, chargeAmount); + } + + @Override + public void pushStopChargingCommand(StopChargingCommand command) { + String pileSn = command.getPileSn(); + String connectorCode = command.getConnectorCode(); + // 杩滅▼鍋滄満 + byte[] msgBody = Bytes.concat(BytesUtil.str2Bcd(pileSn), BytesUtil.str2Bcd(connectorCode)); + this.push(msgBody, pileSn, YKCFrameTypeCode.REMOTE_STOP_CHARGING_CODE); + log.info("銆=====骞冲彴涓嬪彂鎸囦护=====銆:杩滅▼鍋滄鍏呯數,妗╁彿锛歿},鏋彛鍙凤細{}", pileSn, connectorCode); + } + + @Override + public void pushGetRealTimeMonitorDataCommand(GetRealTimeMonitorDataCommand command) { + String pileSn = command.getPileSn(); + String connectorCode = command.getConnectorCode(); + byte[] msg = BytesUtil.str2Bcd(pileSn + connectorCode); + this.push(msg, pileSn, YKCFrameTypeCode.READ_REAL_TIME_MONITOR_DATA_CODE); + log.info("銆=====骞冲彴涓嬪彂鎸囦护=====銆:鑾峰彇鍏呯數妗╋細{} 鐨 {} 鏋彛瀹炴椂鏁版嵁淇℃伅", pileSn, connectorCode); + } + + @Override + public void pushRebootCommand(RebootCommand command) { + String pileSn = command.getPileSn(); + byte[] msg = BytesUtil.str2Bcd(pileSn + Constants.ZERO_ONE); + log.info("銆=====骞冲彴涓嬪彂鎸囦护=====銆:閲嶅惎鍏呯數妗:,{}", pileSn); + this.push(msg, pileSn, YKCFrameTypeCode.REMOTE_RESTART_CODE); + + } + + // 涓嬪彂浜岀淮鐮 + @Override + public void pushIssueQRCodeCommand(IssueQRCodeCommand command) { + log.info("寮傛涓嬪彂浜岀淮鐮 thread:{}", Thread.currentThread().getName()); + String pileSn = command.getPileSn(); + // 妗╃紪鐮 + byte[] pileSnByteArr = BytesUtil.str2Bcd(pileSn); + + // 浜岀淮鐮佹牸寮 0x00锛氱涓绉 鍓嶇紑+妗╃紪鍙 0x01锛氱浜岀 鍓嶇紑+妗╃紪鍙+鏋紪鍙 + byte[] qrCodeTypeByteArr = Constants.oneByteArray; + + // 浜岀淮鐮佸墠缂 濡傦細鈥渨ww.baidu.com锛烴o=鈥 + // String qrCodePrefix = "https://wx.charging.shbochong.cn/prepare_charge?code="; + // String qrCodePrefix = pileBasicInfoService.getPileQrCodeUrl(null); + String qrCodePrefix = pileConnectorInfoService.getPileConnectorQrCodeUrl(null); + byte[] qrCodePrefixByteArr = BytesUtil.str2Asc(qrCodePrefix); + + // 浜岀淮鐮佸墠缂闀垮害 浜岀淮鐮佸墠缂闀垮害闀垮害鏈澶т笉瓒呰繃200 瀛楄妭 + int length = qrCodePrefix.length(); + byte[] qrCodePrefixLengthByteArr = BytesUtil.intToBytes(length, 1); + + // 鎷兼帴娑堟伅浣 + byte[] msg = Bytes.concat(pileSnByteArr, qrCodeTypeByteArr, qrCodePrefixLengthByteArr, qrCodePrefixByteArr); + + // push娑堟伅 + boolean result = this.push(msg, pileSn, YKCFrameTypeCode.REMOTE_ISSUE_QRCODE_CODE); + log.info("=====骞冲彴涓嬪彂鎸囦护===== :涓嬪彂浜岀淮鐮,鍦板潃涓猴細{}", qrCodePrefix); + } + + /** + * 0x56 瀵规椂璁剧疆 + * @param command + */ + @Override + public void pushProofreadTimeCommand(ProofreadTimeCommand command) { + log.info("鍏呯數妗╁鏃讹紝thread:{}", Thread.currentThread().getName()); + String pileSn = command.getPileSn(); + // Date date = new Date(); + // Date parseDate = DateUtils.parseDate("2023-02-28 16:45:20"); + Date date = DateUtils.parseDate(DateUtils.getTime()); + // 鏍规嵁涓嶅悓绋嬪簭鐗堟湰鑾峰彇宸ュ叿绫 + // String programVersion = redisCache.getCacheMapValue(CacheConstants.PILE_PROGRAM_VERSION, pileSn); + // AbsCp56Time2aUtil cp56Time2aUtil = Cp56Time2aFactory.getInvokeStrategy(programVersion); + // String encodeCP56Time2a = cp56Time2aUtil.date2HexStr(date); + byte[] bytes = Cp56Time2aUtil.date2Hbyte(date); + byte[] pileSnByteArr = BytesUtil.str2Bcd(pileSn); + byte[] msg = Bytes.concat(pileSnByteArr, bytes); + + this.push(msg, pileSn, YKCFrameTypeCode.TIME_CHECK_SETTING_CODE); + log.info("[鍏呯數妗:{}瀵规椂, 鏃堕棿:{}, CP56Time2a:{}]", pileSn, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date), BytesUtil.binary(bytes, 16)); + } + + @Override + public void pushPublishPileBillingTemplate(PublishPileBillingTemplateCommand command) { + BillingTemplateVO billingTemplateVO = command.getBillingTemplateVO(); + String pileSn = command.getPileSn(); + // 杞崲 + byte[] messageBody = pileBillingTemplateService.generateBillingTemplateMsgBody(pileSn, billingTemplateVO); + // 鍙戦 + if (messageBody != null) { + this.push(messageBody, pileSn, YKCFrameTypeCode.BILLING_TEMPLATE_SETTING_CODE); + } + } + + @Override + public void pushUpdateFileCommand(UpdateFileCommand command) { + List pileSns = command.getPileSnList(); + if (CollectionUtils.isEmpty(pileSns)) { + return; + } + + List list = pileModelInfoService.getPileModelInfoByPileSnList(pileSns); + if (CollectionUtils.isEmpty(list)) { + return; + } + // 鑾峰彇妗╁瀷鍙 01锛氱洿娴 02锛氫氦娴 + byte[] pileModelType; + for (PileModelInfoVO pileModelInfoVO : list) { + byte[] pileSnByteArr = BytesUtil.str2Bcd(pileModelInfoVO.getPileSn()); + + // 鏁版嵁搴 1- 蹇厖锛堢洿娴侊級 2-鎱㈠厖锛堜氦娴侊級 + /*if (StringUtils.equals(pileModelInfoVO.getSpeedType(), Constants.ONE)) { + pileModelType = Constants.oneByteArray; + } else { + pileModelType = Constants.twoByteArray; + }*/ + pileModelType = Constants.zeroByteArray; + + // 棰濆畾鍔熺巼 + String ratedPower = pileModelInfoVO.getRatedPower(); + int i = Integer.parseInt(ratedPower); + + // byte[] ratedPowerByteArr = Base64.getDecoder().decode(ratedPower); + byte[] ratedPowerByteArr = BytesUtil.checkLengthAndBehindAppendZero(Constants.zeroByteArray, 4); + + // 鍗囩骇鏈嶅姟鍣ㄥ湴鍧 + byte[] updateServerAddressByteArr = BytesUtil.checkLengthAndBehindAppendZero(BytesUtil.str2Asc(Constants.updateServerIP), 32); + + // 鍗囩骇鏈嶅姟鍣ㄧ鍙 + byte[] updateServerPortByteArr = BytesUtil.checkLengthAndBehindAppendZero(Constants.updateServerPort, 4); + // byte[] updateServerPortByteArr = BytesUtil.checkLengthAndBehindAppendZero(BytesUtil.str2Bcd("15"), 4); + + // 鐢ㄦ埛鍚 + byte[] userNameByteArr = BytesUtil.checkLengthAndBehindAppendZero(BytesUtil.str2Asc(Constants.updateServerUserName), 32); + + // 瀵嗙爜 + byte[] passwordByteArr = BytesUtil.checkLengthAndBehindAppendZero(BytesUtil.str2Asc(Constants.updateServerPassword), 32); + + // 鏂囦欢璺緞 + byte[] filePathByteArr = BytesUtil.checkLengthAndBehindAppendZero(BytesUtil.str2Asc(Constants.filePath), 64); + + // 鎵ц鎺у埗 01锛氱珛鍗虫墽琛 02锛氱┖闂叉墽琛 + byte[] performTypeByteArr = Constants.oneByteArray; + + // 涓嬭浇瓒呮椂鏃堕棿 鍗曚綅锛歮in + byte[] overTimeByteArr = new byte[]{0x05}; + + byte[] msgBody = Bytes.concat(pileSnByteArr, pileModelType, ratedPowerByteArr, updateServerAddressByteArr, + updateServerPortByteArr, userNameByteArr, passwordByteArr, filePathByteArr, performTypeByteArr, overTimeByteArr); + + this.push(msgBody, pileModelInfoVO.getPileSn(), YKCFrameTypeCode.REMOTE_UPDATE_CODE); + log.info("銆=====骞冲彴涓嬪彂鎸囦护=====銆:杩滅▼鏇存柊, 妗╁彿锛歿}, 绫诲瀷锛歿}, 棰濆畾鍔熺巼锛歿}, 鏈嶅姟鍣ㄥ湴鍧锛歿}, 绔彛鍙凤細{}, 鐢ㄦ埛鍚嶏細{}, 瀵嗙爜锛歿}, 鏂囦欢璺緞锛歿}", + pileModelInfoVO.getPileSn(), pileModelType, BytesUtil.bcd2Str(ratedPowerByteArr), BytesUtil.binary(updateServerAddressByteArr, 16), + BytesUtil.binary(updateServerPortByteArr, 16), BytesUtil.binary(userNameByteArr, 16), BytesUtil.binary(passwordByteArr, 16), + BytesUtil.binary(filePathByteArr, 16)); + } + } +} diff --git a/jsowell-pile/pom.xml b/jsowell-pile/pom.xml new file mode 100644 index 000000000..161983f02 --- /dev/null +++ b/jsowell-pile/pom.xml @@ -0,0 +1,106 @@ + + + + jsowell-charger-web + com.jsowell + 1.0.0 + + 4.0.0 + + jsowell-pile + + + + + + + + + com.jsowell + jsowell-framework + + + + org.projectlombok + lombok + + + junit + junit + + + org.springframework + spring-test + + + io.swagger + swagger-annotations + 1.6.2 + compile + + + + + org.apache.commons + commons-collections4 + 4.4 + + + + com.github.wxpay + wxpay-sdk + + + + org.jdom + jdom + + + + com.google.zxing + core + + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.0 + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-avro + + + + + 8 + 8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + /src/test/** + + utf-8 + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberBasicInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberBasicInfo.java new file mode 100644 index 000000000..e1a597936 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberBasicInfo.java @@ -0,0 +1,107 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +/** + * 浼氬憳鍩虹淇℃伅瀵硅薄 member_basic_info + * + * @author jsowell + * @date 2022-10-12 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class MemberBasicInfo extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭id + */ + private Integer id; + + /** + * 浼氬憳id + */ + @Excel(name = "浼氬憳id") + private String memberId; + + /** + * 寰俊鐢ㄦ埛韬唤鐮乷penid + */ + private String openId; + + /** + * 鏄电О + */ + @Excel(name = "鏄电О") + private String nickName; + + /** + * 閫昏緫鍗″彿 + */ + @Excel(name = "閫昏緫鍗″彿") + private String logicCard; + + /** + * 鐗╃悊鍗″彿 + */ + @Excel(name = "鐗╃悊鍗″彿") + private String physicsCard; + + /** + * 鐘舵 + */ + @Excel(name = "鐘舵") + private String status; + + /** + * 澶村儚url + */ + @Excel(name = "澶村儚url") + private String avatarUrl; + + /** + * 鎵嬫満鍙 + */ + @Excel(name = "鎵嬫満鍙") + private String mobileNumber; + + /** + * 鎵灞炶繍钀ュ晢 + */ + @Excel(name = "鎵灞炶繍钀ュ晢") + private Long merchantId; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", id) + .append("memberId", memberId) + .append("nickName", nickName) + .append("logicCard", logicCard) + .append("physicsCard", physicsCard) + .append("status", status) + .append("avatarUrl", avatarUrl) + .append("mobileNumber", mobileNumber) + .append("merchantId", merchantId) + .append("delFlag", delFlag) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberTransactionRecord.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberTransactionRecord.java new file mode 100644 index 000000000..460e74047 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberTransactionRecord.java @@ -0,0 +1,78 @@ +package com.jsowell.pile.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 浼氬憳浜ゆ槗璁板綍琛 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MemberTransactionRecord { + /** + * 涓婚敭 + */ + private Integer id; + + /** + * 鍏呯數璁㈠崟鍙 + */ + private String orderCode; + + /** + * 鍦烘櫙绫诲瀷锛坥rder, balance锛 + */ + private String scenarioType; + + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 鎿嶄綔绫诲瀷锛坒orward-姝e悜, reverse-閫嗗悜锛 + */ + private String actionType; + + /** + * 鏀粯绫诲瀷(wx, balance) + */ + private String payMode; + + /** + * 閲戦 + */ + private BigDecimal amount; + + /** + * 澶栭儴鍟嗘埛璁㈠崟鍙 + */ + private String outTradeNo; + + /** + * 澶栭儴鏀粯璁㈠崟鍙 + */ + private String transactionId; + + /** + * 澶栭儴閫娆惧崟鍙 + */ + private String outRefundNo; + + /** + * 澶栭儴鏀粯閫娆惧崟鍙 + */ + private String refundId; + + /** + * 鍒涘缓鏃堕棿 + */ + private LocalDateTime createTime; +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberWalletInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberWalletInfo.java new file mode 100644 index 000000000..1441ec242 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberWalletInfo.java @@ -0,0 +1,56 @@ +package com.jsowell.pile.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 浼氬憳閽卞寘淇℃伅琛 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MemberWalletInfo { + /** + * 涓婚敭 + */ + private Integer id; + + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 鏈噾浣欓 + */ + private BigDecimal principalBalance; + + /** + * 璧犻佷綑棰 + */ + private BigDecimal giftBalance; + + /** + * 鐗堟湰鍙 + */ + private Integer version; + + private String createBy; + + private LocalDateTime createTime; + + private String updateBy; + + private LocalDateTime updateTime; + + /** + * 鍒犻櫎鏍囪瘑(0-姝e父;1-鍒犻櫎) + */ + private String delFlag; +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberWalletLog.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberWalletLog.java new file mode 100644 index 000000000..a0487e88e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/MemberWalletLog.java @@ -0,0 +1,63 @@ +package com.jsowell.pile.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 浼氬憳閽卞寘娴佹按琛 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MemberWalletLog { + /** + * 涓婚敭 + */ + private Integer id; + + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 绫诲瀷锛1-杩涜处锛2-鍑鸿处锛 + */ + private String type; + + /** + * 瀛愮被鍨嬶紙10-鍏呭, 11-璧犻, 12-璁㈠崟缁撶畻閫娆撅紝20-鍚庣鎵f, 21-璁㈠崟浠樻, 22-鐢ㄦ埛閫娆撅級 + */ + private String subType; + + /** + * 閲戦 + */ + private BigDecimal amount; + + /** + * 浣欓绫诲瀷锛1-鏈噾锛2-璧犻侊級 + */ + private String category; + + /** + * 鍏宠仈璁㈠崟缂栧彿 + */ + private String relatedOrderCode; + + /** + * 鍒涘缓浜 + */ + private String createBy; + + /** + * 鍒涘缓鏃堕棿 + */ + private LocalDateTime createTime; +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderAbnormalRecord.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderAbnormalRecord.java new file mode 100644 index 000000000..2eda57291 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderAbnormalRecord.java @@ -0,0 +1,502 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 璁㈠崟寮傚父璁板綍瀵硅薄 order_abnormal_record + * + * @author jsowell + * @date 2023-02-13 + */ +public class OrderAbnormalRecord extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + private Integer id; + + /** + * 璁㈠崟缂栧彿/浜ゆ槗娴佹按鍙 + */ + @Excel(name = "璁㈠崟缂栧彿") + private String orderCode; + + /** + * 妗╃紪鐮 + */ + @Excel(name = "妗╃紪鐮") + private String pileSn; + + /** + * 鏋彿 + */ + @Excel(name = "鏋彿") + private String connectorCode; + + /** + * 寮濮嬫椂闂 + */ + @Excel(name = "寮濮嬫椂闂") + private String startTime; + + /** + * 缁撴潫鏃堕棿 + */ + @Excel(name = "缁撴潫鏃堕棿") + private String endTime; + + /** + * 灏栧崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙灏栫數璐+灏栨湇鍔¤垂锛岃璐圭巼甯э級 + */ + @Excel(name = "灏栧崟浠", readConverterExp = "灏=鐢佃垂+灏栨湇鍔¤垂锛岃璐圭巼甯") + private String sharpPrice; + + /** + * 灏栫數閲 绮剧‘鍒板皬鏁扮偣鍚庡洓浣 + */ + @Excel(name = "灏栫數閲") + private String sharpUsedElectricity; + + /** + * 璁℃崯灏栫數閲 + */ + @Excel(name = "璁℃崯灏栫數閲") + private String sharpPlanLossElectricity; + + /** + * 灏栭噾棰 + */ + @Excel(name = "灏栭噾棰") + private String sharpAmount; + + /** + * 宄板崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙宄扮數璐+宄版湇鍔¤垂锛 + */ + @Excel(name = "宄板崟浠", readConverterExp = "宄=鐢佃垂+宄版湇鍔¤垂") + private String peakPrice; + + /** + * 宄扮數閲 + */ + @Excel(name = "宄扮數閲") + private String peakUsedElectricity; + + /** + * 璁℃崯宄扮數閲 + */ + @Excel(name = "璁℃崯宄扮數閲") + private String peakPlanLossElectricity; + + /** + * 宄伴噾棰 + */ + @Excel(name = "宄伴噾棰") + private String peakAmount; + + /** + * 骞冲崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙骞崇數璐+骞虫湇鍔¤垂锛 + */ + @Excel(name = "骞冲崟浠", readConverterExp = "骞=鐢佃垂+骞虫湇鍔¤垂") + private String flatPrice; + + /** + * 骞崇數閲 + */ + @Excel(name = "骞崇數閲") + private String flatUsedElectricity; + + /** + * 璁℃崯骞崇數閲 + */ + @Excel(name = "璁℃崯骞崇數閲") + private String flatPlanLossElectricity; + + /** + * 骞抽噾棰 + */ + @Excel(name = "骞抽噾棰") + private String flatAmount; + + /** + * 璋峰崟浠 绮剧‘鍒板皬鏁扮偣鍚庝簲浣嶏紙璋风數璐+璋 鏈嶅姟璐癸級 + */ + @Excel(name = "璋峰崟浠", readConverterExp = "璋=鐢佃垂+璋,鏈=鍔¤垂") + private String valleyPrice; + + /** + * 璋风數閲 + */ + @Excel(name = "璋风數閲") + private String valleyUsedElectricity; + + /** + * 璁℃崯璋风數閲 + */ + @Excel(name = "璁℃崯璋风數閲") + private String valleyPlanLossElectricity; + + /** + * 璋烽噾棰 + */ + @Excel(name = "璋烽噾棰") + private String valleyAmount; + + /** + * 鐢佃〃鎬昏捣鍊 + */ + @Excel(name = "鐢佃〃鎬昏捣鍊") + private String ammeterTotalStart; + + /** + * 鐢佃〃鎬绘鍊 + */ + @Excel(name = "鐢佃〃鎬绘鍊") + private String ammeterTotalEnd; + + /** + * 鎬荤數閲 + */ + @Excel(name = "鎬荤數閲") + private String totalElectricity; + + /** + * 璁℃崯鎬荤數閲 + */ + @Excel(name = "璁℃崯鎬荤數閲") + private String planLossTotalElectricity; + + /** + * 娑堣垂閲戦 绮剧‘鍒板皬鏁扮偣鍚庡洓浣嶏紝鍖呭惈鐢佃垂銆 鏈嶅姟璐 + */ + @Excel(name = "娑堣垂閲戦") + private String consumptionAmount; + + /** + * VIN 鐮 VIN 鐮侊紝姝ゅ VIN 鐮佸拰鍏呯數鏃 VIN 鐮佷笉鍚岋紝 姝e簭鐩存帴涓婁紶锛 鏃犻渶琛 0 鍜屽弽搴 + */ + @Excel(name = "VIN鐮") + private String vinCode; + + /** + * 浜ゆ槗鏍囪瘑(0x01app鍚姩; 0x02鍗″惎鍔; 0x04绂荤嚎鍗″惎鍔; 0x05vin鐮佸惎鍔ㄥ厖鐢) + */ + @Excel(name = "浜ゆ槗鏍囪瘑(0x01app鍚姩; 0x02鍗″惎鍔; 0x04绂荤嚎鍗″惎鍔; 0x05vin鐮佸惎鍔ㄥ厖鐢)") + private String transactionIdentifier; + + /** + * 浜ゆ槗鏃堕棿 CP56Time2a 鏍煎紡 + */ + @Excel(name = "浜ゆ槗鏃堕棿") + private String transactionTime; + + /** + * 鍋滄鍘熷洜 + */ + @Excel(name = "鍋滄鍘熷洜") + private String stopReasonMsg; + + /** + * 鐗╃悊鍗″彿 涓嶈冻 8 浣嶈ˉ 0 + */ + @Excel(name = "鐗╃悊鍗″彿") + private String logicCard; + + public void setId(Integer id) { + this.id = id; + } + + public Integer getId() { + return id; + } + + public void setOrderCode(String orderCode) { + this.orderCode = orderCode; + } + + public String getOrderCode() { + return orderCode; + } + + public void setPileSn(String pileSn) { + this.pileSn = pileSn; + } + + public String getPileSn() { + return pileSn; + } + + public void setConnectorCode(String connectorCode) { + this.connectorCode = connectorCode; + } + + public String getConnectorCode() { + return connectorCode; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getStartTime() { + return startTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public String getEndTime() { + return endTime; + } + + public void setSharpPrice(String sharpPrice) { + this.sharpPrice = sharpPrice; + } + + public String getSharpPrice() { + return sharpPrice; + } + + public void setSharpUsedElectricity(String sharpUsedElectricity) { + this.sharpUsedElectricity = sharpUsedElectricity; + } + + public String getSharpUsedElectricity() { + return sharpUsedElectricity; + } + + public void setSharpPlanLossElectricity(String sharpPlanLossElectricity) { + this.sharpPlanLossElectricity = sharpPlanLossElectricity; + } + + public String getSharpPlanLossElectricity() { + return sharpPlanLossElectricity; + } + + public void setSharpAmount(String sharpAmount) { + this.sharpAmount = sharpAmount; + } + + public String getSharpAmount() { + return sharpAmount; + } + + public void setPeakPrice(String peakPrice) { + this.peakPrice = peakPrice; + } + + public String getPeakPrice() { + return peakPrice; + } + + public void setPeakUsedElectricity(String peakUsedElectricity) { + this.peakUsedElectricity = peakUsedElectricity; + } + + public String getPeakUsedElectricity() { + return peakUsedElectricity; + } + + public void setPeakPlanLossElectricity(String peakPlanLossElectricity) { + this.peakPlanLossElectricity = peakPlanLossElectricity; + } + + public String getPeakPlanLossElectricity() { + return peakPlanLossElectricity; + } + + public void setPeakAmount(String peakAmount) { + this.peakAmount = peakAmount; + } + + public String getPeakAmount() { + return peakAmount; + } + + public void setFlatPrice(String flatPrice) { + this.flatPrice = flatPrice; + } + + public String getFlatPrice() { + return flatPrice; + } + + public void setFlatUsedElectricity(String flatUsedElectricity) { + this.flatUsedElectricity = flatUsedElectricity; + } + + public String getFlatUsedElectricity() { + return flatUsedElectricity; + } + + public void setFlatPlanLossElectricity(String flatPlanLossElectricity) { + this.flatPlanLossElectricity = flatPlanLossElectricity; + } + + public String getFlatPlanLossElectricity() { + return flatPlanLossElectricity; + } + + public void setFlatAmount(String flatAmount) { + this.flatAmount = flatAmount; + } + + public String getFlatAmount() { + return flatAmount; + } + + public void setValleyPrice(String valleyPrice) { + this.valleyPrice = valleyPrice; + } + + public String getValleyPrice() { + return valleyPrice; + } + + public void setValleyUsedElectricity(String valleyUsedElectricity) { + this.valleyUsedElectricity = valleyUsedElectricity; + } + + public String getValleyUsedElectricity() { + return valleyUsedElectricity; + } + + public void setValleyPlanLossElectricity(String valleyPlanLossElectricity) { + this.valleyPlanLossElectricity = valleyPlanLossElectricity; + } + + public String getValleyPlanLossElectricity() { + return valleyPlanLossElectricity; + } + + public void setValleyAmount(String valleyAmount) { + this.valleyAmount = valleyAmount; + } + + public String getValleyAmount() { + return valleyAmount; + } + + public void setAmmeterTotalStart(String ammeterTotalStart) { + this.ammeterTotalStart = ammeterTotalStart; + } + + public String getAmmeterTotalStart() { + return ammeterTotalStart; + } + + public void setAmmeterTotalEnd(String ammeterTotalEnd) { + this.ammeterTotalEnd = ammeterTotalEnd; + } + + public String getAmmeterTotalEnd() { + return ammeterTotalEnd; + } + + public void setTotalElectricity(String totalElectricity) { + this.totalElectricity = totalElectricity; + } + + public String getTotalElectricity() { + return totalElectricity; + } + + public void setPlanLossTotalElectricity(String planLossTotalElectricity) { + this.planLossTotalElectricity = planLossTotalElectricity; + } + + public String getPlanLossTotalElectricity() { + return planLossTotalElectricity; + } + + public void setConsumptionAmount(String consumptionAmount) { + this.consumptionAmount = consumptionAmount; + } + + public String getConsumptionAmount() { + return consumptionAmount; + } + + public void setVinCode(String vinCode) { + this.vinCode = vinCode; + } + + public String getVinCode() { + return vinCode; + } + + public void setTransactionIdentifier(String transactionIdentifier) { + this.transactionIdentifier = transactionIdentifier; + } + + public String getTransactionIdentifier() { + return transactionIdentifier; + } + + public void setTransactionTime(String transactionTime) { + this.transactionTime = transactionTime; + } + + public String getTransactionTime() { + return transactionTime; + } + + public void setStopReasonMsg(String stopReasonMsg) { + this.stopReasonMsg = stopReasonMsg; + } + + public String getStopReasonMsg() { + return stopReasonMsg; + } + + public void setLogicCard(String logicCard) { + this.logicCard = logicCard; + } + + public String getLogicCard() { + return logicCard; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("orderCode", getOrderCode()) + .append("pileSn", getPileSn()) + .append("connectorCode", getConnectorCode()) + .append("startTime", getStartTime()) + .append("endTime", getEndTime()) + .append("sharpPrice", getSharpPrice()) + .append("sharpUsedElectricity", getSharpUsedElectricity()) + .append("sharpPlanLossElectricity", getSharpPlanLossElectricity()) + .append("sharpAmount", getSharpAmount()) + .append("peakPrice", getPeakPrice()) + .append("peakUsedElectricity", getPeakUsedElectricity()) + .append("peakPlanLossElectricity", getPeakPlanLossElectricity()) + .append("peakAmount", getPeakAmount()) + .append("flatPrice", getFlatPrice()) + .append("flatUsedElectricity", getFlatUsedElectricity()) + .append("flatPlanLossElectricity", getFlatPlanLossElectricity()) + .append("flatAmount", getFlatAmount()) + .append("valleyPrice", getValleyPrice()) + .append("valleyUsedElectricity", getValleyUsedElectricity()) + .append("valleyPlanLossElectricity", getValleyPlanLossElectricity()) + .append("valleyAmount", getValleyAmount()) + .append("ammeterTotalStart", getAmmeterTotalStart()) + .append("ammeterTotalEnd", getAmmeterTotalEnd()) + .append("totalElectricity", getTotalElectricity()) + .append("planLossTotalElectricity", getPlanLossTotalElectricity()) + .append("consumptionAmount", getConsumptionAmount()) + .append("vinCode", getVinCode()) + .append("transactionIdentifier", getTransactionIdentifier()) + .append("transactionTime", getTransactionTime()) + .append("stopReasonMsg", getStopReasonMsg()) + .append("logicCard", getLogicCard()) + .append("createTime", getCreateTime()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderBasicInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderBasicInfo.java new file mode 100644 index 000000000..01121bfe0 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderBasicInfo.java @@ -0,0 +1,185 @@ +package com.jsowell.pile.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * 璁㈠崟瀵硅薄 order_basic_info + * + * @author jsowell + * @date 2022-09-30 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class OrderBasicInfo extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + private Long id; + + /** + * 璁㈠崟缂栧彿 + */ + @Excel(name = "璁㈠崟缂栧彿") + private String orderCode; + + /** + * 璁㈠崟鐘舵(0-寰呮敮浠橈紱1-鍏呯數涓紱2-寰呯粨绠楋紱3-寰呰ˉ缂达紱4-寮傚父锛5-鍙枒锛6-璁㈠崟瀹屾垚) + */ + @Excel(name = "璁㈠崟鐘舵") + private String orderStatus; + + /** + * 浼氬憳id + */ + @Excel(name = "浼氬憳id") + private String memberId; + + /** + * 绔欑偣id + */ + @Excel(name = "绔欑偣id") + private String stationId; + + /** + * 鍏呯數妗﹕n鍙 + */ + @Excel(name = "鍏呯數妗﹕n鍙") + private String pileSn; + + /** + * 鍏呯數妗╂灙鍙e彿 + */ + @Excel(name = "鍏呯數妗╂灙鍙e彿") + private String connectorCode; + + /** + * 鍏呯數妗╂灙鍙g紪鍙 + */ + @Excel(name = "鍏呯數妗╂灙鍙g紪鍙") + private String pileConnectorCode; + + /** + * 鍚姩鏂瑰紡 + * 0-鍚庣鍚姩锛1-鐢ㄦ埛app鍚姩 + */ + @Excel(name = "鍚姩鏂瑰紡") + private String startMode; + + /** + * 鏀粯鏂瑰紡 + * 1-浣欓鏀粯锛3-鐧藉悕鍗曟敮浠; 4-寰俊鏀粯锛5-鏀粯瀹濇敮浠橈紱 + */ + @Excel(name = "鏀粯鏂瑰紡") + private String payMode; + + /** + * 鏀粯鐘舵 + * 0-寰呮敮浠橈紱1-鏀粯瀹屾垚 + */ + @Excel(name = "鏀粯鐘舵") + private String payStatus; + + /** + * 鏀粯閲戦 + * 鎸囩敤鎴锋湰娆¢渶瑕佸厖鐢电殑閲戦 + */ + @Excel(name = "鏀粯閲戦") + private BigDecimal payAmount; + + /** + * 鏀粯鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "鏀粯鏃堕棿", width = 30, dateFormat = "yyyy-MM-dd") + private Date payTime; + + /** + * 璁㈠崟鎬婚噾棰 = 鐢佃垂鎬婚噾棰 + 鏈嶅姟璐规婚噾棰 + */ + @Excel(name = "璁㈠崟鎬婚噾棰 = 鐢佃垂鎬婚噾棰 + 鏈嶅姟璐规婚噾棰") + private BigDecimal orderAmount; + + /** + * 鍏呯數寮濮嬫椂闂 + */ + private Date chargeStartTime; + + /** + * 鍏呯數缁撴潫鏃堕棿 + */ + private Date chargeEndTime; + + /** + * 寮濮婼OC + */ + private String startSOC; + + /** + * 缁撴潫SOC + */ + private String endSOC; + + /** + * 寮傚父鍘熷洜 + */ + private String reason; + + /** + * 缁撶畻鏃堕棿 + */ + private Date settlementTime; + + /** + * 閫娆鹃噾棰 + */ + private BigDecimal refundAmount; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + private List orderDetailList; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", id) + .append("orderCode", orderCode) + .append("orderStatus", orderStatus) + .append("memberId", memberId) + .append("stationId", stationId) + .append("pileSn", pileSn) + .append("connectorCode", connectorCode) + .append("startMode", startMode) + .append("payMode", payMode) + .append("payStatus", payStatus) + .append("payAmount", payAmount) + .append("payTime", payTime) + .append("orderAmount", orderAmount) + .append("chargeStartTime", chargeStartTime) + .append("chargeEndTime", chargeEndTime) + .append("startSOC", startSOC) + .append("endSOC", endSOC) + .append("reason", reason) + .append("delFlag", delFlag) + .append("orderDetailList", orderDetailList) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderDetail.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderDetail.java new file mode 100644 index 000000000..dfa20a9b8 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderDetail.java @@ -0,0 +1,319 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +/** + * 璁㈠崟璇︽儏瀵硅薄 order_detail + * + * @author jsowell + * @date 2022-09-30 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class OrderDetail extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + private Integer id; + + /** + * 璁㈠崟缂栧彿 + */ + @Excel(name = "璁㈠崟缂栧彿") + private String orderCode; + + /** + * 鎬荤敤鐢甸噺 + */ + @Excel(name = "鎬荤敤鐢甸噺") + private BigDecimal totalUsedElectricity; + + /** + * 璁㈠崟鎬婚噾棰濓紙鐢佃垂鎬婚+鏈嶅姟璐规婚锛 + */ + @Excel(name = "璁㈠崟鎬婚噾棰", readConverterExp = "鐢=璐规婚+鏈嶅姟璐规婚") + private BigDecimal totalOrderAmount; + + /** + * 鐢佃垂鎬婚噾棰濓紙鍚勬椂娈垫秷鑰楃數璐规婚噾棰濓級 + */ + @Excel(name = "鐢佃垂鎬婚噾棰", readConverterExp = "鍚=鏃舵娑堣楃數璐规婚噾棰") + private BigDecimal totalElectricityAmount; + + /** + * 鏈嶅姟璐规婚噾棰濓紙鍚勬椂娈垫湇鍔¤垂鎬婚噾棰濓級 + */ + @Excel(name = "鏈嶅姟璐规婚噾棰", readConverterExp = "鍚=鏃舵鏈嶅姟璐规婚噾棰") + private BigDecimal totalServiceAmount; + + /** + * 灏栨椂娈电敤鐢甸噺 + */ + @Excel(name = "灏栨椂娈电敤鐢甸噺") + private BigDecimal sharpUsedElectricity; + + /** + * 灏栨椂娈电數璐瑰崟浠 + */ + @Excel(name = "灏栨椂娈电數璐瑰崟浠") + private BigDecimal sharpElectricityPrice; + + /** + * 灏栨椂娈垫湇鍔¤垂鍗曚环 + */ + @Excel(name = "灏栨椂娈垫湇鍔¤垂鍗曚环") + private BigDecimal sharpServicePrice; + + /** + * 宄版椂娈电敤鐢甸噺 + */ + @Excel(name = "宄版椂娈电敤鐢甸噺") + private BigDecimal peakUsedElectricity; + + /** + * 宄版椂娈电數璐瑰崟浠 + */ + @Excel(name = "宄版椂娈电數璐瑰崟浠") + private BigDecimal peakElectricityPrice; + + /** + * 宄版椂娈垫湇鍔¤垂鍗曚环 + */ + @Excel(name = "宄版椂娈垫湇鍔¤垂鍗曚环") + private BigDecimal peakServicePrice; + + /** + * 骞虫椂娈电敤鐢甸噺 + */ + @Excel(name = "骞虫椂娈电敤鐢甸噺") + private BigDecimal flatUsedElectricity; + + /** + * 骞虫椂娈电數璐瑰崟浠 + */ + @Excel(name = "骞虫椂娈电數璐瑰崟浠") + private BigDecimal flatElectricityPrice; + + /** + * 骞虫椂娈垫湇鍔¤垂鍗曚环 + */ + @Excel(name = "骞虫椂娈垫湇鍔¤垂鍗曚环") + private BigDecimal flatServicePrice; + + /** + * 璋锋椂娈电敤鐢甸噺 + */ + @Excel(name = "璋锋椂娈电敤鐢甸噺") + private BigDecimal valleyUsedElectricity; + + /** + * 璋锋椂娈电數璐瑰崟浠 + */ + @Excel(name = "璋锋椂娈电數璐瑰崟浠") + private BigDecimal valleyElectricityPrice; + + /** + * 璋锋椂娈垫湇鍔¤垂鍗曚环 + */ + @Excel(name = "璋锋椂娈垫湇鍔¤垂鍗曚环") + private BigDecimal valleyServicePrice; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + public void setId(Integer id) { + this.id = id; + } + + public Integer getId() { + return id; + } + + public void setOrderCode(String orderCode) { + this.orderCode = orderCode; + } + + public String getOrderCode() { + return orderCode; + } + + public void setTotalUsedElectricity(BigDecimal totalUsedElectricity) { + this.totalUsedElectricity = totalUsedElectricity; + } + + public BigDecimal getTotalUsedElectricity() { + return totalUsedElectricity; + } + + public void setTotalOrderAmount(BigDecimal totalOrderAmount) { + this.totalOrderAmount = totalOrderAmount; + } + + public BigDecimal getTotalOrderAmount() { + return totalOrderAmount; + } + + public void setTotalElectricityAmount(BigDecimal totalElectricityAmount) { + this.totalElectricityAmount = totalElectricityAmount; + } + + public BigDecimal getTotalElectricityAmount() { + return totalElectricityAmount; + } + + public void setTotalServiceAmount(BigDecimal totalServiceAmount) { + this.totalServiceAmount = totalServiceAmount; + } + + public BigDecimal getTotalServiceAnount() { + return totalServiceAmount; + } + + public void setSharpUsedElectricity(BigDecimal sharpUsedElectricity) { + this.sharpUsedElectricity = sharpUsedElectricity; + } + + public BigDecimal getSharpUsedElectricity() { + return sharpUsedElectricity; + } + + public void setSharpElectricityPrice(BigDecimal sharpElectricityPrice) { + this.sharpElectricityPrice = sharpElectricityPrice; + } + + public BigDecimal getSharpElectricityPrice() { + return sharpElectricityPrice; + } + + public void setSharpServicePrice(BigDecimal sharpServicePrice) { + this.sharpServicePrice = sharpServicePrice; + } + + public BigDecimal getSharpServicePrice() { + return sharpServicePrice; + } + + public void setPeakUsedElectricity(BigDecimal peakUsedElectricity) { + this.peakUsedElectricity = peakUsedElectricity; + } + + public BigDecimal getPeakUsedElectricity() { + return peakUsedElectricity; + } + + public void setPeakElectricityPrice(BigDecimal peakElectricityPrice) { + this.peakElectricityPrice = peakElectricityPrice; + } + + public BigDecimal getPeakElectricityPrice() { + return peakElectricityPrice; + } + + public void setPeakServicePrice(BigDecimal peakServicePrice) { + this.peakServicePrice = peakServicePrice; + } + + public BigDecimal getPeakServicePrice() { + return peakServicePrice; + } + + public void setFlatUsedElectricity(BigDecimal flatUsedElectricity) { + this.flatUsedElectricity = flatUsedElectricity; + } + + public BigDecimal getFlatUsedElectricity() { + return flatUsedElectricity; + } + + public void setFlatElectricityPrice(BigDecimal flatElectricityPrice) { + this.flatElectricityPrice = flatElectricityPrice; + } + + public BigDecimal getFlatElectricityPrice() { + return flatElectricityPrice; + } + + public void setFlatServicePrice(BigDecimal flatServicePrice) { + this.flatServicePrice = flatServicePrice; + } + + public BigDecimal getFlatServicePrice() { + return flatServicePrice; + } + + public void setValleyUsedElectricity(BigDecimal valleyUsedElectricity) { + this.valleyUsedElectricity = valleyUsedElectricity; + } + + public BigDecimal getValleyUsedElectricity() { + return valleyUsedElectricity; + } + + public void setValleyElectricityPrice(BigDecimal valleyElectricityPrice) { + this.valleyElectricityPrice = valleyElectricityPrice; + } + + public BigDecimal getValleyElectricityPrice() { + return valleyElectricityPrice; + } + + public void setValleyServicePrice(BigDecimal valleyServicePrice) { + this.valleyServicePrice = valleyServicePrice; + } + + public BigDecimal getValleyServicePrice() { + return valleyServicePrice; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public String getDelFlag() { + return delFlag; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("orderCode", getOrderCode()) + .append("totalUsedElectricity", getTotalUsedElectricity()) + .append("totalOrderAmount", getTotalOrderAmount()) + .append("totalElectricityAmount", getTotalElectricityAmount()) + .append("totalServiceAnount", getTotalServiceAnount()) + .append("sharpUsedElectricity", getSharpUsedElectricity()) + .append("sharpElectricityPrice", getSharpElectricityPrice()) + .append("sharpServicePrice", getSharpServicePrice()) + .append("peakUsedElectricity", getPeakUsedElectricity()) + .append("peakElectricityPrice", getPeakElectricityPrice()) + .append("peakServicePrice", getPeakServicePrice()) + .append("flatUsedElectricity", getFlatUsedElectricity()) + .append("flatElectricityPrice", getFlatElectricityPrice()) + .append("flatServicePrice", getFlatServicePrice()) + .append("valleyUsedElectricity", getValleyUsedElectricity()) + .append("valleyElectricityPrice", getValleyElectricityPrice()) + .append("valleyServicePrice", getValleyServicePrice()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderPayRecord.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderPayRecord.java new file mode 100644 index 000000000..8b1b8aeee --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/OrderPayRecord.java @@ -0,0 +1,70 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.enums.ykc.OrderPayRecordEnum; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 璁㈠崟鏀粯璁板綍 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class OrderPayRecord { + /** + * 涓婚敭 + */ + private Integer id; + + /** + * 璁㈠崟鍙 + */ + private String orderCode; + + /** + * 鏀粯鏂瑰紡锛1-鏈噾浣欓鏀粯; 2-璧犻佷綑棰濇敮浠; 3-鐧藉悕鍗曟敮浠; 4-寰俊鏀粯; 5-鏀粯瀹濇敮浠橈級 + * @see OrderPayRecordEnum + */ + private String payMode; + + /** + * 鏀粯閲戦 + */ + private BigDecimal payAmount; + + /** + * 閫娆鹃噾棰 + */ + private BigDecimal refundAmount; + + /** + * 鍒涘缓浜 + */ + private String createBy; + + /** + * 鍒涘缓鏃堕棿 + */ + private LocalDateTime createTime; + + /** + * 鏇存柊浜 + */ + private String updateBy; + + /** + * 鏇存柊鏃堕棿 + */ + private LocalDateTime updateTime; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBasicInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBasicInfo.java new file mode 100644 index 000000000..b5d954a4a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBasicInfo.java @@ -0,0 +1,215 @@ +package com.jsowell.pile.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; + +/** + * 璁惧绠$悊瀵硅薄 pile_basic_info + * + * @author jsowell + * @date 2022-08-26 + */ +public class PileBasicInfo extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + private Long id; + + /** + * 妗╁彿 + */ + @Excel(name = "妗╁彿") + private String sn; + + /** + * 鐘舵侊紙0-鏈煡锛1-鍦ㄧ嚎锛2-绂荤嚎锛3-鏁呴殰锛 + */ + // @Excel(name = "鐘舵", readConverterExp = "0-鏈煡锛1-鍦ㄧ嚎锛2-绂荤嚎锛3-鏁呴殰") + // private String status; + + /** + * 缁忚惀绫诲瀷锛1-杩愯惀妗╋紱2-涓汉妗╋級 + */ + @Excel(name = "缁忚惀绫诲瀷", readConverterExp = "1=-杩愯惀妗╋紱2-涓汉妗") + private String businessType; + + /** + * 杞欢鍗忚锛1-浜戝揩鍏咃紱2-姘歌仈锛 + */ + @Excel(name = "杞欢鍗忚", readConverterExp = "1=-浜戝揩鍏咃紱2-姘歌仈") + private String softwareProtocol; + + /** + * 鐢熶骇鏃ユ湡 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "鐢熶骇鏃ユ湡", width = 30, dateFormat = "yyyy-MM-dd") + private Date productionDate; + + /** + * 璇佷功缂栧彿 + */ + @Excel(name = "璇佷功缂栧彿") + private Long licenceId; + + /** + * 鍏呯數妗╁瀷鍙 + */ + @Excel(name = "鍏呯數妗╁瀷鍙") + private Long modelId; + + /** + * sim鍗d + */ + @Excel(name = "sim鍗d") + private Long simId; + + /** + * 杩愯惀鍟唅d + */ + @Excel(name = "杩愯惀鍟唅d") + private Long merchantId; + + /** + * 鍏呯數绔檌d + */ + @Excel(name = "鍏呯數绔檌d") + private Long stationId; + + /** + * 鏁呴殰鍘熷洜 + */ + @Excel(name = "鏁呴殰鍘熷洜") + private String faultReason; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setSn(String sn) { + this.sn = sn; + } + + public String getSn() { + return sn; + } + + public void setBusinessType(String businessType) { + this.businessType = businessType; + } + + public String getBusinessType() { + return businessType; + } + + public void setSoftwareProtocol(String softwareProtocol) { + this.softwareProtocol = softwareProtocol; + } + + public String getSoftwareProtocol() { + return softwareProtocol; + } + + public void setProductionDate(Date productionDate) { + this.productionDate = productionDate; + } + + public Date getProductionDate() { + return productionDate; + } + + public void setLicenceId(Long licenceId) { + this.licenceId = licenceId; + } + + public Long getLicenceId() { + return licenceId; + } + + public void setModelId(Long modelId) { + this.modelId = modelId; + } + + public Long getModelId() { + return modelId; + } + + public void setSimId(Long simId) { + this.simId = simId; + } + + public Long getSimId() { + return simId; + } + + public void setMerchantId(Long merchantId) { + this.merchantId = merchantId; + } + + public Long getMerchantId() { + return merchantId; + } + + public void setStationId(Long stationId) { + this.stationId = stationId; + } + + public Long getStationId() { + return stationId; + } + + public void setFaultReason(String faultReason) { + this.faultReason = faultReason; + } + + public String getFaultReason() { + return faultReason; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public String getDelFlag() { + return delFlag; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("sn", getSn()) + .append("businessType", getBusinessType()) + .append("softwareProtocol", getSoftwareProtocol()) + .append("productionDate", getProductionDate()) + .append("licenceId", getLicenceId()) + .append("modelId", getModelId()) + .append("simId", getSimId()) + .append("merchantId", getMerchantId()) + .append("stationId", getStationId()) + .append("faultReason", getFaultReason()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingDetail.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingDetail.java new file mode 100644 index 000000000..4571e5b80 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingDetail.java @@ -0,0 +1,131 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +/** + * 璁¤垂妯℃澘璇︽儏瀵硅薄 pile_billing_detail + * + * @author jsowell + * @date 2022-09-20 + */ +public class PileBillingDetail extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + private Long id; + + /** + * 璁¤垂妯℃澘缂栧彿 + */ + @Excel(name = "璁¤垂妯℃澘缂栧彿") + private String templateCode; + + /** + * 鏃舵绫诲瀷锛1-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂锛 + */ + @Excel(name = "鏃舵绫诲瀷", readConverterExp = "1=-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂") + private String timeType; + + /** + * 鐢佃垂 + */ + @Excel(name = "鐢佃垂") + private BigDecimal electricityPrice; + + /** + * 鏈嶅姟璐 + */ + @Excel(name = "鏈嶅姟璐") + private BigDecimal servicePrice; + + /** + * 閫傜敤鏃堕棿娈 + */ + @Excel(name = "閫傜敤鏃堕棿娈") + private String applyTime; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setTemplateCode(String templateCode) { + this.templateCode = templateCode; + } + + public String getTemplateCode() { + return templateCode; + } + + public void setTimeType(String timeType) { + this.timeType = timeType; + } + + public String getTimeType() { + return timeType; + } + + public void setElectricityPrice(BigDecimal electricityPrice) { + this.electricityPrice = electricityPrice; + } + + public BigDecimal getElectricityPrice() { + return electricityPrice; + } + + public void setServicePrice(BigDecimal servicePrice) { + this.servicePrice = servicePrice; + } + + public BigDecimal getServicePrice() { + return servicePrice; + } + + public void setApplyTime(String applyTime) { + this.applyTime = applyTime; + } + + public String getApplyTime() { + return applyTime; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public String getDelFlag() { + return delFlag; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("templateCode", getTemplateCode()) + .append("timeType", getTimeType()) + .append("electricityPrice", getElectricityPrice()) + .append("servicePrice", getServicePrice()) + .append("applyTime", getApplyTime()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingRelation.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingRelation.java new file mode 100644 index 000000000..b4094d128 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingRelation.java @@ -0,0 +1,35 @@ +package com.jsowell.pile.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 鍏呯數妗╁拰璁¤垂妯℃澘鍏崇郴 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileBillingRelation { + /** + * 涓婚敭 + */ + private Long id; + + /** + * 妗╃紪鍙 + */ + private String pileSn; + + /** + * 璁¤垂妯℃澘缂栧彿 + */ + private String billingTemplateCode; + + /** + * 绔欑偣id + */ + private String stationId; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingTemplate.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingTemplate.java new file mode 100644 index 000000000..38ea662b2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBillingTemplate.java @@ -0,0 +1,154 @@ +package com.jsowell.pile.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; +import java.util.List; + +/** + * 璁¤垂妯℃澘瀵硅薄 pile_billing_template + * + * @author jsowell + * @date 2022-09-20 + */ +@Data +public class PileBillingTemplate extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + private Long id; + + /** + * 璁¤垂妯℃澘缂栧彿 + */ + private String templateCode; + + /** + * 妯℃澘鍚嶇О + */ + @Excel(name = "妯℃澘鍚嶇О") + private String name; + + /** + * 杞﹁締绫诲瀷锛1-鐢靛姩姹借溅锛2-鐢靛姩鑷杞︼級 + */ + @Excel(name = "杞﹁締绫诲瀷", readConverterExp = "1=-鐢靛姩姹借溅锛2-鐢靛姩鑷杞") + private String type; + + /** + * 鍏呯數绔檌d + */ + @Excel(name = "鍏呯數绔檌d") + private Long stationId; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + /** + * 璁¤垂妯℃澘璇︽儏淇℃伅 + */ + private List pileBillingDetailList; + + /** + * 鍏叡妯℃澘鏍囪瘑锛0-绉佹湁锛1-鍏叡锛 + */ + private String publicFlag; + + /** + * 鍙戝竷鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date publishTime; + + public String getPublicFlag() { + return publicFlag; + } + + public void setPublicFlag(String publicFlag) { + this.publicFlag = publicFlag; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setTemplateCode(String templateCode) { + this.templateCode = templateCode; + } + + public String getTemplateCode() { + return templateCode; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setStationId(Long stationId) { + this.stationId = stationId; + } + + public Long getStationId() { + return stationId; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public String getDelFlag() { + return delFlag; + } + + public List getPileBillingDetailList() { + return pileBillingDetailList; + } + + public void setPileBillingDetailList(List pileBillingDetailList) { + this.pileBillingDetailList = pileBillingDetailList; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("templateCode", getTemplateCode()) + .append("name", getName()) + .append("remark", getRemark()) + .append("type", getType()) + .append("stationId", getStationId()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .append("pileBillingDetailList", getPileBillingDetailList()) + .append("publicFlag", getPublicFlag()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileConnectorInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileConnectorInfo.java new file mode 100644 index 000000000..33bcf4ec3 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileConnectorInfo.java @@ -0,0 +1,121 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 鍏呯數妗╂灙鍙d俊鎭璞 pile_connector_info + * + * @author jsowell + * @date 2022-08-31 + */ +public class PileConnectorInfo extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + private Integer id; + + /** + * 鍚嶇О + */ + @Excel(name = "鍚嶇О") + private String name; + + /** + * 鍏呯數鏋紪鍙凤紝鐢卞厖鐢垫々SN+01鐢熸垚 + */ + @Excel(name = "鍏呯數鏋紪鍙凤紝鐢卞厖鐢垫々SN+01鐢熸垚") + private String pileConnectorCode; + + /** + * 鐘舵 + * 0锛氱缃 + * 1锛氱┖闂 + * 2锛氬崰鐢紙鏈厖鐢碉級 + * 3锛氬崰鐢紙鍏呯數涓級 + * 4锛氬崰鐢紙棰勭害閿佸畾锛 + * 255锛氭晠闅 + */ + @Excel(name = "鐘舵") + private String status; + + /** + * 鎵灞炲厖鐢垫々id + */ + @Excel(name = "鎵灞炲厖鐢垫々id") + private String pileSn; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + public void setId(Integer id) { + this.id = id; + } + + public Integer getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String getPileConnectorCode() { + return pileConnectorCode; + } + + public void setPileConnectorCode(String pileConnectorCode) { + this.pileConnectorCode = pileConnectorCode; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setPileSn(String pileSn) { + this.pileSn = pileSn; + } + + public String getPileSn() { + return pileSn; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public String getDelFlag() { + return delFlag; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("name", getName()) + .append("pileConnectorCode", getPileConnectorCode()) + .append("status", getStatus()) + .append("pileId", getPileSn()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .toString(); + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileLicenceInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileLicenceInfo.java new file mode 100644 index 000000000..be341692f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileLicenceInfo.java @@ -0,0 +1,114 @@ +package com.jsowell.pile.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; + +/** + * 鍏呯數妗╄瘉涔︿俊鎭璞 pile_licence_info + * + * @author jsowell + * @date 2022-08-27 + */ +public class PileLicenceInfo extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 涓婚敭 */ + private Long id; + + /** 璇佷功鍚嶇О */ + @Excel(name = "璇佷功鍚嶇О") + private String licenceName; + + /** 杩愯惀鍟唅d */ + @Excel(name = "杩愯惀鍟唅d") + private Long merchantId; + + /** 鐘舵侊紙0-寰呮縺娲伙紱1-姝e父锛2-杩囨湡锛 */ + @Excel(name = "鐘舵", readConverterExp = "0=-寰呮縺娲伙紱1-姝e父锛2-杩囨湡") + private String status; + + /** 杩囨湡鏃堕棿 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "杩囨湡鏃堕棿", width = 30, dateFormat = "yyyy-MM-dd") + private Date expireTime; + + /** 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 */ + private String delFlag; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setLicenceName(String licenceName) + { + this.licenceName = licenceName; + } + + public String getLicenceName() + { + return licenceName; + } + public void setMerchantId(Long merchantId) + { + this.merchantId = merchantId; + } + + public Long getMerchantId() + { + return merchantId; + } + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + public void setExpireTime(Date expireTime) + { + this.expireTime = expireTime; + } + + public Date getExpireTime() + { + return expireTime; + } + public void setDelFlag(String delFlag) + { + this.delFlag = delFlag; + } + + public String getDelFlag() + { + return delFlag; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("licenceName", getLicenceName()) + .append("merchantId", getMerchantId()) + .append("status", getStatus()) + .append("expireTime", getExpireTime()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMemberRelation.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMemberRelation.java new file mode 100644 index 000000000..2bdad4d86 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMemberRelation.java @@ -0,0 +1,56 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴瀵硅薄 pile_member_relation + * + * @author jsowell + * @date 2023-02-21 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PileMemberRelation extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Integer id; + + /** 妗╃紪鐮 */ + @Excel(name = "妗╃紪鐮") + private String pileSn; + + /** 浼氬憳id */ + @Excel(name = "浼氬憳id") + private String memberId; + + /** 韬唤绫诲瀷锛1-绠$悊鍛橈紝2-鐢ㄦ埛锛 */ + @Excel(name = "韬唤绫诲瀷", readConverterExp = "1=-绠$悊鍛橈紝2-鐢ㄦ埛") + private String type; + + public void setId(Integer id) + { + this.id = id; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("pileSn", getPileSn()) + .append("memberId", getMemberId()) + .append("type", getType()) + .append("createTime", getCreateTime()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMerchantInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMerchantInfo.java new file mode 100644 index 000000000..4695a8d06 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMerchantInfo.java @@ -0,0 +1,107 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 鍏呯數妗╄繍钀ュ晢淇℃伅瀵硅薄 pile_merchant_info + * + * @author jsowell + * @date 2022-08-27 + */ +@Data +public class PileMerchantInfo extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * + */ + private Long id; + + /** + * 杩愯惀鍟嗗悕绉 + */ + @Excel(name = "杩愯惀鍟嗗悕绉") + private String merchantName; + + /** + * 鍦板潃 + */ + @Excel(name = "鍦板潃") + private String address; + + /** + * 鐘舵 + * 0-澶辨晥锛1-鐢熸晥 + */ + @Excel(name = "鐘舵") + private String status; + + /** + * 缁勭粐鏈烘瀯浠g爜 + */ + @Excel(name = "缁勭粐鏈烘瀯浠g爜") + private String organizationCode; + + /** + * 璐熻矗浜哄鍚 + */ + @Excel(name = "璐熻矗浜哄鍚") + private String managerName; + + /** + * 璐熻矗浜虹數璇濆彿鐮 + */ + @Excel(name = "璐熻矗浜虹數璇濆彿鐮") + private String managerPhone; + + /** + * 瀹㈡湇鐢佃瘽鍙风爜 + */ + @Excel(name = "瀹㈡湇鐢佃瘽鍙风爜") + private String servicePhone; + + /** + * logo + */ + @Excel(name = "logo") + private String logoUrl; + + /** + * 杩愯惀鍟嗙殑灏忕▼搴廰ppId + */ + private String appId; + + /** + * 閮ㄩ棬id + */ + private String deptId; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("merchantName", getMerchantName()) + .append("address", getAddress()) + .append("status", getStatus()) + .append("organizationCode", getOrganizationCode()) + .append("managerName", getManagerName()) + .append("managerPhone", getManagerPhone()) + .append("servicePhone", getServicePhone()) + .append("logoUrl", getLogoUrl()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileModelInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileModelInfo.java new file mode 100644 index 000000000..2b3dad2e1 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileModelInfo.java @@ -0,0 +1,102 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 鍏呯數妗╁瀷鍙蜂俊鎭璞 pile_model_info + * + * @author jsowell + * @date 2022-09-07 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PileModelInfo extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * + */ + private Long id; + + /** + * 鍨嬪彿鍚嶇О + */ + @Excel(name = "鍨嬪彿鍚嶇О") + private String modelName; + + /** + * 棰濆畾鍔熺巼锛屽崟浣峎 + */ + @Excel(name = "棰濆畾鍔熺巼锛屽崟浣峩W") + private String ratedPower; + + /** + * 棰濆畾鐢垫祦锛屽崟浣岮 + */ + @Excel(name = "棰濆畾鐢垫祦锛屽崟浣岮") + private String ratedCurrent; + + /** + * 棰濆畾鐢靛帇锛屽崟浣峍 + */ + @Excel(name = "棰濆畾鐢靛帇锛屽崟浣峍") + private String ratedVoltage; + + /** + * 鍏呯數绫诲瀷锛1-蹇厖锛2-鎱㈠厖锛 + */ + @Excel(name = "鍏呯數绫诲瀷", readConverterExp = "1=-蹇厖锛2-鎱㈠厖") + private String speedType; + + /** + * 鍏呯數妗╃被鍨嬶紙1-姹借溅妗╋紝2-鐢靛崟杞︼級 + */ + @Excel(name = "鍏呯數妗╃被鍨", readConverterExp = "1=-姹借溅妗╋紝2-鐢靛崟杞") + private String chargerPileType; + + /** + * 鍏呯數鏋暟閲 + */ + @Excel(name = "鍏呯數鏋暟閲") + private Long connectorNum; + + /** + * 鍏呯數鎺ュ彛鏍囧噯 + */ + @Excel(name = "鍏呯數鎺ュ彛鏍囧噯") + private String interfaceStandard; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", getId()) + .append("modelName", getModelName()) + .append("ratedPower", getRatedPower()) + .append("ratedCurrent", getRatedCurrent()) + .append("ratedVoltage", getRatedVoltage()) + .append("speedType", getSpeedType()) + .append("chargerPileType", getChargerPileType()) + .append("connectorNum", getConnectorNum()) + .append("interfaceStandard", getInterfaceStandard()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMsgRecord.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMsgRecord.java new file mode 100644 index 000000000..5f10f71db --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileMsgRecord.java @@ -0,0 +1,53 @@ +package com.jsowell.pile.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileMsgRecord { + /** + * 涓婚敭 + */ + private Long id; + + /** + * 妗╃紪鍙 + */ + private String pileSn; + + /** + * 甯х被鍨 + */ + private String frameType; + + /** + * 鏋彛鍙 + */ + private String connectorCode; + + /** + * 鏋彛缂栧彿 + */ + private String pileConnectorCode; + + /** + * 鍘熷鎶ユ枃 + */ + private String originalMsg; + + /** + * json鏍煎紡鎶ユ枃 + */ + private String jsonMsg; + + /** + * 鍒涘缓鏃堕棿 + */ + private String createTime; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileSimInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileSimInfo.java new file mode 100644 index 000000000..5ca1b7b69 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileSimInfo.java @@ -0,0 +1,66 @@ +package com.jsowell.pile.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.*; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; + +/** + * 鍏呯數妗㏒IM鍗′俊鎭璞 pile_sim_info + * + * @author jsowell + * @date 2022-08-26 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileSimInfo extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 涓婚敭 */ + private Long id; + + /** 濂楅鍚嶇О */ + @Excel(name = "濂楅鍚嶇О") + private String name; + + /** ICCID */ + @Excel(name = "ICCID") + private String iccid; + + /** 鐘舵侊紙0-姝e父,1-寮哄埗鏂綉,2-瀹㈡埛鏂綉,3-瓒呭鍋,4-鏈嶅姟缁撴潫,5-鎻愯閿鍗,6-閿鍗★級 */ + @Excel(name = "鐘舵", readConverterExp = "0=-姝e父,1-寮哄埗鏂綉,2-瀹㈡埛鏂綉,3-瓒呭鍋,4-鏈嶅姟缁撴潫,5-鎻愯閿鍗,6-閿鍗") + private String status; + + /** sim鍗′緵搴斿晢 */ + @Excel(name = "sim鍗′緵搴斿晢") + private String simSupplier; + + /** 濂楅鎬绘祦閲 */ + @Excel(name = "濂楅鎬绘祦閲") + private String totalData; + + /** 鍓╀綑娴侀噺 */ + @Excel(name = "鍓╀綑娴侀噺") + private String surplusData; + + /** 鍒版湡鏃堕棿 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "鍒版湡鏃堕棿", width = 30, dateFormat = "yyyy-MM-dd") + private Date expireTime; + + /** SIM鍗¤繍钀ュ晢(china_telecom - 涓浗鐢典俊锛 china_mobile - 涓浗绉诲姩锛 china_unicom - 涓浗鑱旈) */ + @Excel(name = "SIM鍗¤繍钀ュ晢(china_telecom - 涓浗鐢典俊锛 china_mobile - 涓浗绉诲姩锛 china_unicom - 涓浗鑱旈)") + private String operator; + + /** 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 */ + private String delFlag; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileStationInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileStationInfo.java new file mode 100644 index 000000000..eeeca7a6f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileStationInfo.java @@ -0,0 +1,355 @@ +package com.jsowell.pile.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +/** + * 鍏呯數绔欎俊鎭璞 pile_station_info + * + * @author jsowell + * @date 2022-08-30 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class PileStationInfo extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 绔欑偣id + */ + private Long id; + + /** + * 杩愯惀鍟唅d + */ + private Long merchantId; + + /** + * 绔欑偣鍚嶇О + */ + @Excel(name = "绔欑偣鍚嶇О") + private String stationName; + + private String deptId; + + /** + * 鏄惁鐙珛鎶ユ々锛0-鍚︼紱1-鏄級 + */ + @Excel(name = "鏄惁鐙珛鎶ユ々", readConverterExp = "0=-鍚︼紱1-鏄") + private String aloneApply; + + /** + * 鍥界綉鐢佃垂璐﹀崟鎴峰彿 + */ + @Excel(name = "鍥界綉鐢佃垂璐﹀崟鎴峰彿") + private String accountNumber; + + /** + * 瀹归噺锛岀嫭绔嬬數琛ㄧ敵璇风殑鍔熺巼淇濈暀灏忔暟鐐瑰悗4浣 + */ + @Excel(name = "瀹归噺") + private BigDecimal capacity; + + /** + * 鍏叡鍋滆溅鍦哄簱(0-鍚︼紱1-鏄) + */ + @Excel(name = "鍏叡鍋滆溅鍦哄簱(0-鍚︼紱1-鏄)") + private String publicParking; + + /** + * 鍋滆溅鍦哄簱缂栧彿 + */ + @Excel(name = "鍋滆溅鍦哄簱缂栧彿") + private String parkingNumber; + + /** + * 鍏呯數绔欏浗瀹朵唬鐮 + */ + @Excel(name = "鍏呯數绔欏浗瀹朵唬鐮") + private String countryCode; + + /** + * 鍏呯數绔欑渷甯傝緰鍖虹紪鐮 + */ + @Excel(name = "鍏呯數绔欑渷甯傝緰鍖虹紪鐮") + private String areaCode; + + /** + * 绔欑偣鍦板潃 + */ + @Excel(name = "绔欑偣鍦板潃") + private String address; + + /** + * 绔欑偣鐢佃瘽 + */ + @Excel(name = "绔欑偣鐢佃瘽") + private String stationTel; + + /** + * 鏈嶅姟鐢佃瘽,渚嬪400鐢佃瘽 + */ + @Excel(name = "鏈嶅姟鐢佃瘽,渚嬪400鐢佃瘽") + private String serviceTel; + + /** + * 绔欑偣鐘舵併1锛氬叕鍏 + * 50锛氫釜浜 + * 100锛氬叕浜わ紙涓撶敤锛 + * 101锛氱幆鍗紙涓撶敤锛 + * 102锛氱墿娴侊紙涓撶敤锛 + * 103锛氬嚭绉熻溅锛堜笓鐢級 + * 104锛氬垎鏃剁璧侊紙涓撶敤锛 + * 105锛氬皬鍖哄叡浜紙涓撶敤锛 + * 106锛氬崟浣嶏紙涓撶敤锛 + * 255锛氬叾浠 + * 銆 + */ + @Excel(name = "绔欑偣鐘舵", readConverterExp = "涓=鐢") + private String stationType; + + /** + * 绔欑偣鐘舵併0锛氭湭鐭 + * 1锛氬缓璁句腑 + * 5锛氬叧闂笅绾 + * 6锛氱淮鎶や腑 + * 50锛氭甯镐娇鐢 + * 銆 + */ + @Excel(name = "绔欑偣鐘舵") + private String stationStatus; + + /** + * 绔欑偣绠$悊鍛樺悕绉 + */ + @Excel(name = "绔欑偣绠$悊鍛樺悕绉") + private String stationAdminName; + + /** + * 杞︿綅鏁伴噺(榛樿锛0 鏈煡) + */ + @Excel(name = "杞︿綅鏁伴噺(榛樿锛0 鏈煡)") + private String parkNums; + + /** + * 缁忓害GCJ-02鍧愭爣绯讳繚鐣欏皬鏁扮偣鍚6浣 + */ + @Excel(name = "缁忓害GCJ-02鍧愭爣绯讳繚鐣欏皬鏁扮偣鍚6浣") + private String stationLng; + + /** + * 绾害GCJ-02鍧愭爣绯讳繚鐣欏皬鏁扮偣鍚6浣 + */ + @Excel(name = "绾害GCJ-02鍧愭爣绯讳繚鐣欏皬鏁扮偣鍚6浣") + private String stationLat; + + /** + * 绔欑偣寮曞,鐢ㄤ簬寮曞杞︿富鎵惧埌鍏呯數杞︿綅 + */ + @Excel(name = "绔欑偣寮曞,鐢ㄤ簬寮曞杞︿富鎵惧埌鍏呯數杞︿綅") + private String siteGuide; + + /** + * 寤鸿鍦烘墍(1锛氬眳姘戝尯 + * 2锛氬叕鍏辨満鏋 + * 3锛氫紒浜嬩笟鍗曚綅 + * 4锛氬啓瀛楁ゼ + * 5锛氬伐涓氬洯鍖 + * 6锛氫氦閫氭灑绾 + * 7锛氬ぇ鍨嬫枃浣撹鏂 + * 8锛氬煄甯傜豢鍦 + * 9锛氬ぇ鍨嬪缓绛戦厤寤哄仠杞﹀満 + * 10锛氳矾杈瑰仠杞︿綅 + * 11锛氬煄闄呴珮閫熸湇鍔″尯 + * 12锛氶鏅尯 + * 13锛氬叕浜ゅ満绔 + * 14锛氬姞娌瑰姞姘旂珯 + * 15锛氬嚭绉熻溅 + * 255锛氬叾浠 + * ) + */ + @Excel(name = "寤鸿鍦烘墍") + private String construction; + + /** + * 绔欑偣鐓х墖 + */ + @Excel(name = "绔欑偣鐓х墖") + private String pictures; + + /** + * 浣跨敤杞﹀瀷鎻忚堪(鎻忚堪璇ョ珯鐐规帴鍙楃殑杞﹀ぇ灏忎互鍙婄被鍨嬶紝濡傚ぇ宸淬佺墿娴佽溅銆佺瀹朵箻鐢ㄨ溅銆佸嚭绉熻溅绛 ) + */ + @Excel(name = "浣跨敤杞﹀瀷鎻忚堪(鎻忚堪璇ョ珯鐐规帴鍙楃殑杞﹀ぇ灏忎互鍙婄被鍨嬶紝濡傚ぇ宸淬佺墿娴佽溅銆佺瀹朵箻鐢ㄨ溅銆佸嚭绉熻溅绛 )") + private String matchCars; + + /** + * 杞︿綅妤煎眰鍙婃暟閲忔弿杩 + */ + @Excel(name = "杞︿綅妤煎眰鍙婃暟閲忔弿杩") + private String parkInfo; + + /** + * 鍋滆溅鍦轰骇鏉冩柟 + */ + @Excel(name = "鍋滆溅鍦轰骇鏉冩柟") + private String parkOwner; + + /** + * 鍋滆溅鍦虹鐞嗕汉锛堝锛歑X 鐗╀笟锛 + */ + @Excel(name = "鍋滆溅鍦虹鐞嗕汉", readConverterExp = "濡=锛歑X,鐗=涓") + private String parkManager; + + /** + * 鏄惁鍏ㄥぉ寮鏀 + * 0锛氬惁 + * 1锛氭槸 + */ + @Excel(name = "鏄惁鍏ㄥぉ寮鏀") + private String openAllDay; + + /** + * 钀ヤ笟鏃堕棿鎻忚堪 + */ + @Excel(name = "钀ヤ笟鏃堕棿鎻忚堪") + private String businessHours; + + /** + * 鏄惁鍋滆溅鍏嶈垂 + * 0锛氬惁 + * 1锛氭槸 + */ + @Excel(name = "鏄惁鍋滆溅鍏嶈垂") + private String parkFree; + + /** + * 鏀粯鏂瑰紡:0-鍒峰崱銆1-绾夸笂銆2-鐜伴噾 + * 鍏朵腑鐢靛瓙閽卞寘绫诲崱涓哄埛鍗★紝韬唤閴存潈鍗°佸井淇/ 鏀粯瀹濄丄PP涓虹嚎涓 + */ + @Excel(name = "鏀粯鏂瑰紡") + private String payment; + + /** + * 鏄惁鏀寔棰勭害 (0涓轰笉鏀寔棰勭害銆1涓烘敮鎸侀绾︺備笉濉粯璁や负0) + */ + @Excel(name = "鏄惁鏀寔棰勭害 (0涓轰笉鏀寔棰勭害銆1涓烘敮鎸侀绾︺備笉濉粯璁や负0)") + private String supportOrder; + + /** + * 鏄惁瀵瑰寮鏀 锛0-鍚︼紱1-鏄級 + */ + private String publicFlag; + + /** + * 鏄惁钀ヤ笟涓紙0-鍚︼紱1-鏄級 + */ + private String openFlag; + + /** + * 鏄惁闈犺繎鍗敓闂 (0-鏃狅紱1-鏈) + */ + @Excel(name = "鏄惁闈犺繎鍗敓闂 (0-鏃狅紱1-鏈)") + private String toiletFlag; + + /** + * 鏄惁闈犺繎渚垮埄搴(0-鏃狅紱1-鏈) + */ + @Excel(name = "鏄惁闈犺繎渚垮埄搴(0-鏃狅紱1-鏈)") + private String storeFlag; + + /** + * 鏄惁闈犺繎椁愬巺(0-鏃狅紱1-鏈) + */ + @Excel(name = "鏄惁闈犺繎椁愬巺(0-鏃狅紱1-鏈)") + private String restaurantFlag; + + /** + * 鏄惁闈犺繎浼戞伅瀹(0-鏃狅紱1-鏈) + */ + @Excel(name = "鏄惁闈犺繎浼戞伅瀹(0-鏃狅紱1-鏈)") + private String loungeFlag; + + /** + * 鏄惁鏈夐洦妫(0-鏃狅紱1-鏈) + */ + @Excel(name = "鏄惁鏈夐洦妫(0-鏃狅紱1-鏈)") + private String canopyFlag; + + /** + * 鏄惁鏈夊皬绁ㄦ満 (0-鏃狅紱1-鏈) + */ + @Excel(name = "鏄惁鏈夊皬绁ㄦ満 (0-鏃狅紱1-鏈)") + private String printerFlag; + + /** + * 鏄惁鏈夐亾闂(0-鏃狅紱1-鏈) + */ + @Excel(name = "鏄惁鏈夐亾闂(0-鏃狅紱1-鏈)") + private String barrierFlag; + + /** + * 鏄惁鏈夊湴閿(0-鏃狅紱1-鏈) + */ + @Excel(name = "鏄惁鏈夊湴閿(0-鏃狅紱1-鏈)") + private String parkingLockFlag; + + /** + * 鍒犻櫎鏍囪瘑锛0-姝e父锛1-鍒犻櫎锛 + */ + private String delFlag; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("id", id) + .append("merchantId", merchantId) + .append("stationName", stationName) + .append("aloneApply", aloneApply) + .append("accountNumber", accountNumber) + .append("capacity", capacity) + .append("publicParking", publicParking) + .append("parkingNumber", parkingNumber) + .append("countryCode", countryCode) + .append("areaCode", areaCode) + .append("address", address) + .append("stationTel", stationTel) + .append("serviceTel", serviceTel) + .append("stationType", stationType) + .append("stationStatus", stationStatus) + .append("stationAdminName", stationAdminName) + .append("parkNums", parkNums) + .append("stationLng", stationLng) + .append("stationLat", stationLat) + .append("siteGuide", siteGuide) + .append("construction", construction) + .append("pictures", pictures) + .append("matchCars", matchCars) + .append("parkInfo", parkInfo) + .append("parkOwner", parkOwner) + .append("parkManager", parkManager) + .append("openAllDay", openAllDay) + .append("businessHours", businessHours) + .append("parkFree", parkFree) + .append("payment", payment) + .append("supportOrder", supportOrder) + .append("publicFlag", publicFlag) + .append("openFlag", openFlag) + .append("toiletFlag", toiletFlag) + .append("storeFlag", storeFlag) + .append("restaurantFlag", restaurantFlag) + .append("loungeFlag", loungeFlag) + .append("canopyFlag", canopyFlag) + .append("printerFlag", printerFlag) + .append("barrierFlag", barrierFlag) + .append("parkingLockFlag", parkingLockFlag) + .append("delFlag", delFlag) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/TransactionRecords.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/TransactionRecords.java new file mode 100644 index 000000000..a8f5bf92a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/TransactionRecords.java @@ -0,0 +1,178 @@ +package com.jsowell.pile.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 浜ゆ槗娴佹按璁板綍 0x3B + * + * @author JS-ZZA + * @date 2022/11/5 10:15 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TransactionRecords { + /** + * 浜ゆ槗娴佹按鍙 + */ + private String orderCode; + + /** + * 妗╃紪鐮 + */ + private String pileSn; + + /** + * 鏋彿 + */ + private String connectorCode; + + /** + * 寮濮嬫椂闂 + */ + private String startTime; + + /** + * 缁撴潫鏃堕棿 + */ + private String endTime; + + /** + * 灏栧崟浠 + */ + private String sharpPrice; + + /** + * 灏栫數閲 + */ + private String sharpUsedElectricity; + + /** + * 璁℃崯灏栫數閲 + */ + private String sharpPlanLossElectric; + + /** + * 灏栭噾棰 + */ + private String sharpAmount; + + /** + * 宄板崟浠 + */ + private String peakPrice; + + /** + * 宄扮數閲 + */ + private String peakUsedElectricity; + + /** + * 璁℃崯宄扮數閲 + */ + private String peakPlanLossElectricity; + + /** + * 宄伴噾棰 + */ + private String peakAmount; + + /** + * 骞冲崟浠 + */ + private String flatPrice; + + /** + * 骞崇數閲 + */ + private String flatUsedElectricity; + + /** + * 璁℃崯骞崇數閲 + */ + private String flatPlanLossElectricity; + + /** + * 骞抽噾棰 + */ + private String flatAmount; + + /** + * 璋峰崟浠 + */ + private String valleyPrice; + + /** + * 璋风數閲 + */ + private String valleyUsedElectricity; + + /** + * 璁℃崯璋风數閲 + */ + private String valleyPlanLossElectricity; + + /** + * 璋烽噾棰 + */ + private String valleyAmount; + + /** + * 鐢佃〃鎬昏捣鍊 + */ + private String ammeterTotalStart; + + /** + * 鐢佃〃鎬绘鍊 + */ + private String ammeterTotalEnd; + + /** + * 鎬荤數閲 + */ + private String totalElectricity; + + /** + * 璁℃崯鎬荤數閲 + */ + private String planLossTotalElectricity; + + /** + * 娑堣垂閲戦 + */ + private String consumptionAmount; + + /** + * VIN 鐮 + */ + private String vinCode; + + /** + * 浜ゆ槗鏍囪瘑 + * 0x01锛 app 鍚姩 + * 0x02锛氬崱鍚姩 + * 0x04锛氱绾垮崱鍚姩 + * 0x05: vin 鐮佸惎鍔ㄥ厖鐢 + */ + private String transactionIdentifier; + + /** + * 浜ゆ槗鏃堕棿 + */ + private String transactionTime; + + /** + * 鍋滄鍘熷洜 + */ + private String stopReason; + + /** + * 鐗╃悊鍗″彿 + */ + private String logicCardNum; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/WxpayCallbackRecord.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/WxpayCallbackRecord.java new file mode 100644 index 000000000..3c0630f9f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/WxpayCallbackRecord.java @@ -0,0 +1,102 @@ +package com.jsowell.pile.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +/** + * 寰俊鏀粯鍥炶皟璁板綍琛 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class WxpayCallbackRecord { + /** + * 涓婚敭id + */ + private Integer id; + + /** + * 鏀粯绫诲瀷锛1-鏀粯璁㈠崟锛2-鍏呭间綑棰濓級 + */ + private String payScenario; + + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 鍏呯數璁㈠崟鍙 + */ + private String orderCode; + + /** + * 寰俊鍟嗘埛璁㈠崟鍙 + */ + private String outTradeNo; + + /** + * 寰俊鏀粯璁㈠崟鍙 + */ + private String transactionId; + + /** + * 鍟嗘埛鍙 + */ + private String mchId; + + /** + * 搴旂敤ID + */ + private String appId; + + /** + * 浜ゆ槗绫诲瀷 + */ + private String tradeType; + + /** + * 浜ゆ槗鐘舵 + */ + private String tradeState; + + /** + * 浜ゆ槗鐘舵佹弿杩 + */ + private String tradeStateDesc; + + /** + * 閾惰绫诲瀷 + */ + private String bankType; + + /** + * 闄勫姞鏁版嵁 + */ + private String attach; + + /** + * 鏀粯瀹屾垚鏃堕棿 + */ + private LocalDateTime successTime; + + /** + * 鏀粯鑰呬俊鎭痮penId + */ + private String payerOpenId; + + /** + * 鐢ㄦ埛鏀粯閲戦锛堝崟浣嶅垎锛 + */ + private String payerTotal; + + /** + * 鍒涘缓鏃堕棿 + */ + private LocalDateTime createTime; +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/WxpayRefundCallback.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/WxpayRefundCallback.java new file mode 100644 index 000000000..0eec11456 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/WxpayRefundCallback.java @@ -0,0 +1,94 @@ +package com.jsowell.pile.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class WxpayRefundCallback { + /** + * 涓婚敭 + */ + private Integer id; + + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 璁㈠崟缂栧彿 + */ + private String orderCode; + + /** + * 寰俊鍟嗘埛璁㈠崟鍙 + */ + private String outTradeNo; + + /** + * 寰俊鍟嗘埛閫娆惧崟鍙 + */ + private String outRefundNo; + + /** + * 寰俊鏀粯璁㈠崟鍙 + */ + private String transactionId; + + /** + * 寰俊鍟嗘埛鍙 + */ + private String mchId; + + /** + * 寰俊鏀粯閫娆惧崟鍙 + */ + private String refundId; + + /** + * 閫娆剧姸鎬(SUCCESS锛氶娆炬垚鍔;CLOSED锛氶娆惧叧闂; ABNORMAL锛氶娆惧紓甯) + */ + private String refundStatus; + + /** + * 閫娆炬垚鍔熸椂闂 + */ + private String successTime; + + /** + * 閫娆惧叆璐﹁处鎴 + */ + private String userReceivedAccount; + + /** + * 鐢ㄦ埛鏀粯閲戦 + */ + private String payerTotal; + + /** + * 鐢ㄦ埛閫娆鹃噾棰 + */ + private String payerRefund; + + /** + * 璁㈠崟閲戦 + */ + private String amountTotal; + + /** + * 閫娆鹃噾棰 + */ + private String amountRefund; + + /** + * 鍒涘缓鏃堕棿 + */ + private LocalDateTime createTime; +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/BaseMemberDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/BaseMemberDTO.java new file mode 100644 index 000000000..23e6a7d96 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/BaseMemberDTO.java @@ -0,0 +1,32 @@ +package com.jsowell.pile.dto; + +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * uniapp鏌ヨ鐢ㄦ埛淇℃伅DTO + * + * @author JS-ZZA + * @date 2022/11/19 14:53 + */ +@Data +public class BaseMemberDTO { + /** + * 鐢ㄦ埛浠ょ墝 + */ + private String memberToken; + + /** + * 浼氬憳Id + */ + private String memberId; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("memberToken", memberToken) + .append("memberId", memberId) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/BasicPileDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/BasicPileDTO.java new file mode 100644 index 000000000..57cf3472d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/BasicPileDTO.java @@ -0,0 +1,42 @@ +package com.jsowell.pile.dto; + +import com.jsowell.common.core.domain.BaseEntity; +import lombok.Data; + +/** + * 鍏呯數妗╁熀纭DTO + */ +@Data +public class BasicPileDTO extends BaseEntity { + /** + * 绔欑偣id + */ + private String stationId; + + /** + * 鍏呯數妗﹊d + */ + private String pileId; + + /** + * 璁惧sn + */ + private String pileSn; + + /** + * 鏋彛鍙 + */ + private String connectorCode; + + /** + * 鏋彛缂栧彿 + * 妗╃紪鐮+鏋彛鍙 + */ + private String pileConnectorCode; + + /** + * 鍏呯數妗╃姸鎬 + * 1-鍦ㄧ嚎锛2-绂荤嚎锛3-鏁呴殰 + */ + private String status; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/BatchCreatePileDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/BatchCreatePileDTO.java new file mode 100644 index 000000000..627ecd2d6 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/BatchCreatePileDTO.java @@ -0,0 +1,54 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BatchCreatePileDTO { + /** + * 杩愯惀鍟唅d + */ + private String merchantId; + + /** + * 鍏呯數绔檌d + */ + private String stationId; + + /** + * 鍨嬪彿id + */ + private String modelId; + + /** + * 杞欢鍗忚锛1-浜戝揩鍏咃紱2-姘歌仈锛 + */ + private String softwareProtocol; + + /** + * 鐢熸垚鏃ユ湡 + */ + private Date productionDate; + + /** + * 鎺ュ彛鏁伴噺 + */ + private int connectorNum; + + /** + * 鐢熸垚鍙版暟 + */ + private int num; + + /** + * 澶囨敞 + */ + private String remark; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/BillingTimeDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/BillingTimeDTO.java new file mode 100644 index 000000000..461fd825e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/BillingTimeDTO.java @@ -0,0 +1,31 @@ +package com.jsowell.pile.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@ApiModel("璁¤垂妯℃澘鏃舵璇︽儏") +@Data +public class BillingTimeDTO { + /** + * 鏃舵绫诲瀷锛1-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂锛 + */ + @ApiModelProperty("鏃舵绫诲瀷锛1-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂锛") + private String type; + + /** + * 寮濮嬫椂闂 + */ + private String startTime; + + /** + * 缁撴潫鏃堕棿 + */ + private String endTime; + + /** + * 鏃舵 渚嬪锛00锛00-05锛00 + */ + @ApiModelProperty("鏃舵 渚嬪锛00锛00-05锛00") + private String timeDesc; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/CreateOrUpdateBillingTemplateDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/CreateOrUpdateBillingTemplateDTO.java new file mode 100644 index 000000000..bf96723bc --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/CreateOrUpdateBillingTemplateDTO.java @@ -0,0 +1,91 @@ +package com.jsowell.pile.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +// @ApiModel(value = "UserEntity" , description = "鐢ㄦ埛瀹炰綋") +@Data +public class CreateOrUpdateBillingTemplateDTO { + /** + * 璁¤垂妯℃澘id锛屼慨鏀规椂蹇呬紶 + */ + private String billingTemplateId; + + private String stationId; + + /** + * 妯℃澘鍚嶇О + */ + @ApiModelProperty("妯℃澘鍚嶇О") + private String name; + + /** + * 鏃舵绫诲瀷锛1-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂锛 + */ + @ApiModelProperty("鏃舵绫诲瀷") + private String type; + + /** + * 灏栨椂娈电數璐 + */ + @ApiModelProperty("灏栨椂娈电數璐") + private BigDecimal electricityPriceA; + + /** + * 灏栨椂娈垫湇鍔¤垂 + */ + @ApiModelProperty("灏栨椂娈垫湇鍔¤垂") + private BigDecimal servicePriceA; + + /** + * 宄版椂娈电數璐 + */ + @ApiModelProperty("宄版椂娈电數璐") + private BigDecimal electricityPriceB; + + /** + * 宄版椂娈垫湇鍔¤垂 + */ + @ApiModelProperty("宄版椂娈垫湇鍔¤垂") + private BigDecimal servicePriceB; + + /** + * 骞虫椂娈电數璐 + */ + @ApiModelProperty("骞虫椂娈电數璐") + private BigDecimal electricityPriceC; + + /** + * 骞虫椂娈垫湇鍔¤垂 + */ + @ApiModelProperty("骞虫椂娈垫湇鍔¤垂") + private BigDecimal servicePriceC; + + /** + * 璋锋椂娈电數璐 + */ + @ApiModelProperty("璋锋椂娈电數璐") + private BigDecimal electricityPriceD; + + /** + * 璋锋椂娈垫湇鍔¤垂 + */ + @ApiModelProperty("璋锋椂娈垫湇鍔¤垂") + private BigDecimal servicePriceD; + + /** + * 澶囨敞 + */ + @ApiModelProperty("澶囨敞") + private String remark; + + /** + * 鏃舵娓呭崟 + */ + @ApiModelProperty("鏃舵娓呭崟") + private List timeArray; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/FastCreateStationDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/FastCreateStationDTO.java new file mode 100644 index 000000000..6960c9ccd --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/FastCreateStationDTO.java @@ -0,0 +1,40 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 蹇熷缓绔橠TO + */ +@Data +public class FastCreateStationDTO { + /** + * 鎵灞炶繍钀ュ晢id + */ + private String merchantId; + + /** + * 鍚嶇О + */ + private String stationName; + + /** + * 鍦板潃 + */ + private String address; + + /** + * 鍖哄煙 + */ + private String areaCode; + + /** + * 绔欑偣鐢佃瘽 + */ + private String stationTel; + + /** + * 绠$悊鍛 + */ + private String stationAdminName; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/GenerateOrderDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/GenerateOrderDTO.java new file mode 100644 index 000000000..c654da65f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/GenerateOrderDTO.java @@ -0,0 +1,51 @@ +package com.jsowell.pile.dto; + +import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; + +/** + * 鐢熸垚璁㈠崟dto + * start_pile_charge + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class GenerateOrderDTO extends BasicPileDTO{ + /** + * 浼氬憳id + */ + private String memberId; + + /** + * token + */ + private String memberToken; + + /** + * 鍚姩鏂瑰紡锛0-鍚庣鍚姩锛1-鐢ㄦ埛app鍚姩锛 + */ + private String startMode; + + /** + * 鏀粯鏂瑰紡 1-浣欓鏀粯锛3-鐧藉悕鍗曟敮浠橈紱4-寰俊鏀粯锛5-鏀粯瀹濇敮浠 + */ + private String payMode; + + /** + * 鍏呯數閲戦 + */ + private BigDecimal chargeAmount; + + /** + * 鍏呯數妗╂灙鍙d俊鎭 + */ + private PileConnectorDetailVO pileConnector; + + /** + * 璁¤垂妯℃澘鐩稿叧淇℃伅 + */ + private BillingTemplateVO billingTemplate; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/ImportBillingTemplateDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/ImportBillingTemplateDTO.java new file mode 100644 index 000000000..c4cd45ee8 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/ImportBillingTemplateDTO.java @@ -0,0 +1,15 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 绔欑偣瀵煎叆璁¤垂妯℃澘dto + */ +@Data +public class ImportBillingTemplateDTO { + // 绔欑偣id + private String stationId; + + // 璁¤垂妯℃澘id + private String billingTemplateId; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/IndexQueryDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/IndexQueryDTO.java new file mode 100644 index 000000000..6f647e812 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/IndexQueryDTO.java @@ -0,0 +1,17 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 棣栭〉鏁版嵁灞曠ずDTO + * + * @author JS-ZZA + * @date 2023/2/3 16:11 + */ +@Data +public class IndexQueryDTO { + /** + * 绔欑偣id + */ + private String stationId; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/MemberRegisterAndLoginDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/MemberRegisterAndLoginDTO.java new file mode 100644 index 000000000..4d3753d57 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/MemberRegisterAndLoginDTO.java @@ -0,0 +1,37 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class MemberRegisterAndLoginDTO { + /** + * 鎵嬫満鍙 + */ + private String mobileNumber; + + /** + * 楠岃瘉鐮 + */ + private String verificationCode; + + /** + * 灏忕▼搴廰ppId + */ + private String appId; + + /** + * 杩愯惀鍟唅d + */ + private String merchantId; + + /** + * 寰俊鐢ㄦ埛openId + */ + private String openId; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/MemberRegisterDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/MemberRegisterDTO.java new file mode 100644 index 000000000..53ba073ae --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/MemberRegisterDTO.java @@ -0,0 +1,38 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 鐢ㄦ埛娉ㄥ唽鍓嶅彴鍙傛暟 + * + * @author JS-ZZA + * @date 2022/10/27 14:55 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class MemberRegisterDTO { + /** + * 鏄电О + */ + private String nickName; + + /** + * 鐘舵 + */ + private String status; + + /** + * 澶村儚url + */ + private String avatarUrl; + + /** + * 鎵嬫満鍙风爜 + */ + private String mobileNumber; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/PayOrderDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PayOrderDTO.java new file mode 100644 index 000000000..83f301573 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PayOrderDTO.java @@ -0,0 +1,55 @@ +package com.jsowell.pile.dto; + +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +/** + * 鏀粯璁㈠崟DTO + */ +@Data +public class PayOrderDTO { + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 璁㈠崟缂栧彿 + */ + private String orderCode; + + /** + * 鏀粯鏂瑰紡 + * @see com.jsowell.common.enums.ykc.OrderPayModeEnum + */ + private String payMode; + + /** + * 鏀粯閲戦 + */ + private BigDecimal payAmount; + + /** + * 寰俊鏀粯闇瑕佺敤鐨刢ode + */ + private String code; + + /** + * redis閿佺殑鍊 + */ + private String lockValue; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("memberId", memberId) + .append("orderCode", orderCode) + .append("payMode", payMode) + .append("payAmount", payAmount) + .append("code", code) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/PayOrderSuccessCallbackDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PayOrderSuccessCallbackDTO.java new file mode 100644 index 000000000..8f6c2167d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PayOrderSuccessCallbackDTO.java @@ -0,0 +1,32 @@ +package com.jsowell.pile.dto; + +import com.jsowell.common.enums.ykc.OrderPayModeEnum; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PayOrderSuccessCallbackDTO { + /** + * 璁㈠崟缂栧彿 + */ + private String orderCode; + + /** + * 鏀粯閲戦 鍗曚綅: 鍏 + */ + private BigDecimal payAmount; + + /** + * 鏀粯鏂瑰紡 + * 1-浣欓鏀粯锛2-寰俊鏀粯锛3-鏀粯瀹濇敮浠 + * @see OrderPayModeEnum + */ + private String payMode; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/PaymentScenarioDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PaymentScenarioDTO.java new file mode 100644 index 000000000..c4ad3f4da --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PaymentScenarioDTO.java @@ -0,0 +1,29 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PaymentScenarioDTO { + /** + * 鏀粯鍦烘櫙绫诲瀷 1-璁㈠崟鏀粯锛2-鍏呭间綑棰 + */ + private String type; + + /** + * 璁㈠崟缂栧彿 + * 褰搕ype==1鏃讹紝orderCode涓嶈兘涓虹┖ + */ + private String orderCode; + + /** + * 浼氬憳id + * 褰搕ype==2鏃讹紝memberId涓嶈兘涓虹┖ + */ + private String memberId; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/PileMemberBindingDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PileMemberBindingDTO.java new file mode 100644 index 000000000..6b498570a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PileMemberBindingDTO.java @@ -0,0 +1,32 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 涓汉妗╃粦瀹欴TO + * + * @author JS-ZZA + * @date 2023/2/20 16:46 + */ +@Data +public class PileMemberBindingDTO { + /** + * 妗╃紪鐮 + */ + private String pileSn; + + /** + * 鎵嬫満鍙 + */ + private String phoneNumber; + + /** + * 楠岃瘉鐮 + */ + private String verificationCode; + + /** + * 鐢ㄦ埛memberId + */ + private String memberId; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/PublishBillingTemplateDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PublishBillingTemplateDTO.java new file mode 100644 index 000000000..9bd42c679 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PublishBillingTemplateDTO.java @@ -0,0 +1,22 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PublishBillingTemplateDTO { + /** + * 绔欑偣id + */ + private String stationId; + + /** + * 璁¤垂妯℃澘id + */ + private String templateId; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryConnectorDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryConnectorDTO.java new file mode 100644 index 000000000..1e0322bc3 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryConnectorDTO.java @@ -0,0 +1,32 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 鏌ヨ鍏呯數鏋帴鏀跺墠鍙板弬鏁 + * + * @author JS-ZZA + * @date 2022/8/31 16:41 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class QueryConnectorDTO { + /** + * 鍏呯數鏋紪鍙 + */ + private String connectorCode; + + /** + * 绔欑偣id + */ + private Long stationId; + + private int pageNum; + + private int pageSize; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryConnectorListDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryConnectorListDTO.java new file mode 100644 index 000000000..5db718411 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryConnectorListDTO.java @@ -0,0 +1,50 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class QueryConnectorListDTO { + + /** + * 椤电爜 + */ + private int pageNum; + + /** + * 姣忛〉鏁伴噺 + */ + private int pageSize; + + /** + * 杩愯惀鍟唅d + */ + private String merchantId; + + /** + * 绔欑偣 + */ + private List stationIdList; + + /** + * 鍏呯數妗﹊d鍒楄〃 + */ + private List pileIds; + + /** + * 鎺ュ彛id + */ + private List connectorIdList; + + /** + * 鎺ュ彛缂栧彿 + */ + private List connectorCodeList; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryOrderDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryOrderDTO.java new file mode 100644 index 000000000..7d915ef33 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryOrderDTO.java @@ -0,0 +1,58 @@ +package com.jsowell.pile.dto; + +import com.jsowell.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class QueryOrderDTO extends BaseEntity { + /** + * 鍏呯數妗╃紪鍙 + */ + private String pileSn; + + /** + * 鏋彛鍙 + */ + private String connectorCode; + + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 璁㈠崟鐘舵 + */ + private String orderStatus; + + /** + * 璁㈠崟缂栧彿 + */ + private String orderCode; + + /** + * 鎵嬫満鍙 + */ + private String mobileNumber; + + /** + * 绔欑偣Id + */ + private String stationId; + + /** + * 寮濮嬫椂闂 + */ + private String startTime; + + /** + * 缁撴潫鏃堕棿 + */ + private String endTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryPersonPileDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryPersonPileDTO.java new file mode 100644 index 000000000..fb067cbda --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryPersonPileDTO.java @@ -0,0 +1,37 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 鏌ヨ涓汉妗╃浉鍏充俊鎭疍TO + * + * @author JS-ZZA + * @date 2023/2/23 15:27 + */ +@Data +public class QueryPersonPileDTO { + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 妗╂灙鍙e彿 + */ + private String pileConnectorCode; + + /** + * 寮濮嬫椂闂 + */ + private String startTime; + + /** + * 缁撴潫鏃堕棿 + */ + private String endTime; + + private int pageSize; + + private int pageNum; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryPileDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryPileDTO.java new file mode 100644 index 000000000..66a8a45bd --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryPileDTO.java @@ -0,0 +1,37 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 鎺ユ敹鍓嶇鍙傛暟 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class QueryPileDTO extends BasicPileDTO{ + + private int pageNum; + + private int pageSize; + + /** + * 璁㈠崟鍙 + */ + private String orderCode; + + /** + * 妗╃紪鐮+鏋彛鍙 + */ + private String pileConnectorCode; + + /** + * 妗╃紪鐮丩ist + */ + private List pileSns; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QuerySimInfoDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QuerySimInfoDTO.java new file mode 100644 index 000000000..dd86fd349 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QuerySimInfoDTO.java @@ -0,0 +1,32 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 鍚庣鏌ヨsim鍗′俊鎭疍TO + * + * @author JS-ZZA + * @date 2023/2/17 11:24 + */ +@Data +public class QuerySimInfoDTO { + /** + * 妗╃紪鐮 + */ + private String pileSn; + + /** + * iccId + */ + private String iccId; + + /** + * 鍒版湡鏃堕棿 + */ + private String expiredTime; + + /** + * sim鍗″晢 + */ + private String simSupplier; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStationDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStationDTO.java new file mode 100644 index 000000000..b648682f2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStationDTO.java @@ -0,0 +1,59 @@ +package com.jsowell.pile.dto; + +import com.jsowell.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 绔欑偣绠$悊鍓嶅彴鍙傛暟 + * + * @author JS-ZZA + * @date 2022/9/1 13:25 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class QueryStationDTO extends BaseEntity { + /** + * 绔欑偣鍚嶇О + */ + private String stationName; + + /** + * 杩愯惀鍟嗗悕绉 + */ + private String merchantName; + + /** + * 杩愯惀鍟唅d + */ + private String merchantId; + + /** + * 绔欑偣缁忓害 + */ + private String stationLng; + + /** + * 绔欑偣绾害 + */ + private String stationLat; + + /** + * 姣忛〉鏁伴噺 + */ + private int pageSize; + + /** + * 椤电爜 + */ + private int pageNum; + + /** + * 鏄惁瀵瑰寮鏀撅紙0-鍚︼紱1-鏄級 + */ + private String publicFlag; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/RemoteUpdatePileFileDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/RemoteUpdatePileFileDTO.java new file mode 100644 index 000000000..878b9e7b7 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/RemoteUpdatePileFileDTO.java @@ -0,0 +1,26 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 杩滅▼鏇存柊妗 + * + * @author JS-ZZA + * @date 2022/10/21 11:45 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class RemoteUpdatePileFileDTO { + + /** + * 妗╃紪鍙烽泦鍚 + */ + private List pileSnList; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/ReplaceMerchantStationDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/ReplaceMerchantStationDTO.java new file mode 100644 index 000000000..743ab30a7 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/ReplaceMerchantStationDTO.java @@ -0,0 +1,42 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import java.util.Date; +import java.util.List; + +@Data +public class ReplaceMerchantStationDTO { + /** + * 杩愯惀鍟唅d + */ + private String merchantId; + + /** + * 绔欑偣id + */ + @NotBlank(message = "绔欑偣涓嶈兘涓虹┖") + private String stationId; + + /** + * 鍏呯數妗﹊dList + */ + @NotEmpty(message = "鍏呯數妗╀笉鑳戒负绌") + private List pileIdList; + + /** + * 鍏呯數妗╃紪鍙穕ist + */ + private List pileSnList; + + // 鍨嬪彿id + private String modelId; + + // 鏋彛鏁伴噺 + private Integer connectorNum; + + private String updateBy; + private Date updateTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/SettleOrderDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/SettleOrderDTO.java new file mode 100644 index 000000000..4840edf98 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/SettleOrderDTO.java @@ -0,0 +1,27 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * 缁撶畻璁㈠崟DTO + * + * @author JS-ZZA + * @date 2022/11/15 9:23 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class SettleOrderDTO extends BasicPileDTO{ + + /** + * 璁㈠崟鍙 + */ + private String orderCode; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/SimRenewDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/SimRenewDTO.java new file mode 100644 index 000000000..b2771295c --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/SimRenewDTO.java @@ -0,0 +1,24 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +import java.util.List; + +/** + * sim鍗$画璐笵TO + * + * @author JS-ZZA + * @date 2022/12/19 10:36 + */ +@Data +public class SimRenewDTO { + /** + * 鍗″彿闆嗗悎 + */ + private List iccIds; + + /** + * 缁垂鍛ㄦ湡 + */ + private int cycleNumber; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/StartChargingDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/StartChargingDTO.java new file mode 100644 index 000000000..197d044ac --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/StartChargingDTO.java @@ -0,0 +1,29 @@ +package com.jsowell.pile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 鍚姩鍏呯數DTO + */ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class StartChargingDTO extends BasicPileDTO{ + /** + * 浼氬憳token + */ + private String memberToken; + + /** + * 鍏呯數閲戦 + */ + private BigDecimal chargeAmount; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/StopChargingDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/StopChargingDTO.java new file mode 100644 index 000000000..2ad98f661 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/StopChargingDTO.java @@ -0,0 +1,26 @@ +package com.jsowell.pile.dto; + +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +@Data +public class StopChargingDTO { + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 璁㈠崟缂栧彿 + */ + private String orderCode; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("memberId", memberId) + .append("orderCode", orderCode) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/UniAppQueryMemberBalanceDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/UniAppQueryMemberBalanceDTO.java new file mode 100644 index 000000000..c58b0a66a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/UniAppQueryMemberBalanceDTO.java @@ -0,0 +1,33 @@ +package com.jsowell.pile.dto; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 灏忕▼搴忔煡璇㈢敤鎴疯处鎴蜂綑棰濆彉鍔ㄤ俊鎭 + * + * @author JS-ZZA + * @date 2022/11/26 9:41 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class UniAppQueryMemberBalanceDTO extends BaseMemberDTO{ + private int pageSize; + private int pageNum; + + /** + * 鍙樺姩绫诲瀷 1-杩涜处锛2-鍑鸿处 + */ + private String type; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("pageSize", pageSize) + .append("pageNum", pageNum) + .append("type", type) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/UniAppQueryOrderDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/UniAppQueryOrderDTO.java new file mode 100644 index 000000000..37932ab24 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/UniAppQueryOrderDTO.java @@ -0,0 +1,24 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 灏忕▼搴忔煡璇㈣鍗曞垪琛―TO + * + * @author JS-ZZA + * @date 2022/11/25 15:16 + */ +@Data +public class UniAppQueryOrderDTO { + private int pageSize; + private int pageNum; + /** + * 璁㈠崟鐘舵 1-鍏ㄩ儴 2-鏈畬鎴 3-宸插畬鎴 + */ + private String orderStatus; + + /** + * 璁㈠崟缂栧彿 + */ + private String orderCode; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/WechatLoginDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/WechatLoginDTO.java new file mode 100644 index 000000000..7c3481e4c --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/WechatLoginDTO.java @@ -0,0 +1,18 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 寰俊鐧诲綍娉ㄥ唽dto + */ +@Data +public class WechatLoginDTO { + private String code; + + private String appId; + + /** + * 鐢ㄦ潵鑾峰彇openId鐨凜ode + */ + private String openIdCode; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/WeixinPayDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/WeixinPayDTO.java new file mode 100644 index 000000000..cd3e177b4 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/WeixinPayDTO.java @@ -0,0 +1,32 @@ +package com.jsowell.pile.dto; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +@EqualsAndHashCode(callSuper = true) +@Data +public class WeixinPayDTO extends BaseMemberDTO{ + private String openId; + + private String code; + + private String amount; + + private String description; // 寰俊鍟嗗搧璇︽儏 + + /** + * 闄勫姞鍙傛暟 + * json鏍煎紡锛屾敮浠樺洖璋冨彇鍑烘潵浣跨敤 + */ + private String attach; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("openId", openId) + .append("code", code) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberBasicInfoMapper.java new file mode 100644 index 000000000..632eac41e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberBasicInfoMapper.java @@ -0,0 +1,110 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.MemberBasicInfo; +import com.jsowell.pile.vo.uniapp.MemberVO; +import com.jsowell.pile.vo.uniapp.MemberWalletLogVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 浼氬憳鍩虹淇℃伅Mapper鎺ュ彛 + * + * @author jsowell + * @date 2022-10-12 + */ +@Repository +public interface MemberBasicInfoMapper { + /** + * 鏌ヨ浼氬憳鍩虹淇℃伅 + * + * @param id 浼氬憳鍩虹淇℃伅涓婚敭 + * @return 浼氬憳鍩虹淇℃伅 + */ + public MemberBasicInfo selectMemberBasicInfoById(Integer id); + + /** + * 鏌ヨ浼氬憳鍩虹淇℃伅鍒楄〃 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 浼氬憳鍩虹淇℃伅闆嗗悎 + */ + public List selectMemberBasicInfoList(MemberBasicInfo memberBasicInfo); + + /** + * 鏂板浼氬憳鍩虹淇℃伅 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 缁撴灉 + */ + public int insertMemberBasicInfo(MemberBasicInfo memberBasicInfo); + + /** + * 淇敼浼氬憳鍩虹淇℃伅 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 缁撴灉 + */ + public int updateMemberBasicInfo(MemberBasicInfo memberBasicInfo); + + /** + * 鎵归噺鍒犻櫎浼氬憳鍩虹淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deleteMemberBasicInfoByIds(List ids); + + /** + * 閫氳繃鐗╃悊鍗″彿鏌ヨ鍩烘湰淇℃伅 + * + * @param physicsCard 鐗╃悊鍗″彿 + * @return 浼氬憳鍩虹淇℃伅 + */ + MemberVO selectInfoByPhysicsCard(@Param("physicsCard") String physicsCard); + + /** + * 閫氳繃鎵嬫満鍙峰拰鍟嗘埛id鏌ヨ浼氬憳淇℃伅 + * 涓嶅悓鎵嬫満鍙峰彲浠ュ湪澶氫釜杩愯惀鍟嗕笅娉ㄥ唽璐﹀彿 + * + * @param mobileNumber 鎵嬫満鍙 + * @param merchantId 杩愯惀鍟唅d + * @return 浼氬憳淇℃伅 + */ + MemberBasicInfo selectInfoByMobileNumberAndMerchantId(@Param("mobileNumber") String mobileNumber, @Param("merchantId") String merchantId); + + /** + * 閫氳繃鎵嬫満鍙风爜鏌ヨ浼氬憳淇℃伅 + * + * @param mobileNumber 鐢佃瘽鍙风爜 + * @return 浼氬憳淇℃伅 + */ + // MemberBasicInfo selectInfoByMobileNumber(@Param("mobileNumber") String mobileNumber); + + /** + * 閫氳繃浼氬憳id鏌ヨ浼氬憳璇︽儏 + * @param memberId + * @return + */ + MemberBasicInfo selectInfoByMemberId(String memberId); + + /** + * 鏇存柊浼氬憳浣欓 + * @param memberId 浼氬憳id + * @param newPrincipalBalance new鏈噾浣欓 + * @param newGiftBalance new璧犻佷綑棰 + * @param version 涓婃鏌ヨ鐨勭増鏈彿 + * @return 鏇存柊琛屾暟 0-鏇存柊澶辫触锛1-鏇存柊鎴愬姛 + */ + int updateMemberBalance(@Param("memberId") String memberId, @Param("newPrincipalBalance") BigDecimal newPrincipalBalance, + @Param("newGiftBalance") BigDecimal newGiftBalance, @Param("version") Integer version); + + MemberVO queryMemberInfoByMemberId(String memberId); + + + List selectMemberList(@Param("mobileNumber") String mobileNumber, @Param("nickName") String nickName); + + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberTransactionRecordMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberTransactionRecordMapper.java new file mode 100644 index 000000000..13e7328fa --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberTransactionRecordMapper.java @@ -0,0 +1,13 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.MemberTransactionRecord; + +import java.util.List; + +public interface MemberTransactionRecordMapper { + + int insertSelective(MemberTransactionRecord record); + + List selectByMemberId(String memberId); + +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberWalletInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberWalletInfoMapper.java new file mode 100644 index 000000000..9c714b016 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberWalletInfoMapper.java @@ -0,0 +1,21 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.MemberWalletInfo; +import org.springframework.stereotype.Repository; + +@Repository +public interface MemberWalletInfoMapper { + int deleteByPrimaryKey(Integer id); + + int insert(MemberWalletInfo record); + + int insertSelective(MemberWalletInfo record); + + MemberWalletInfo selectByPrimaryKey(Integer id); + + MemberWalletInfo selectByMemberId(String memberId); + + int updateByPrimaryKeySelective(MemberWalletInfo record); + + int updateByPrimaryKey(MemberWalletInfo record); +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberWalletLogMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberWalletLogMapper.java new file mode 100644 index 000000000..c085f190d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberWalletLogMapper.java @@ -0,0 +1,33 @@ +package com.jsowell.pile.mapper; + + +import com.jsowell.pile.domain.MemberWalletLog; +import com.jsowell.pile.vo.uniapp.MemberWalletLogVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface MemberWalletLogMapper { + // int deleteByPrimaryKey(Integer id); + + // int insert(MemberWalletLog record); + + // int insertSelective(MemberWalletLog record); + + // MemberWalletLog selectByPrimaryKey(Integer id); + + // int updateByPrimaryKeySelective(MemberWalletLog record); + + // int updateByPrimaryKey(MemberWalletLog record); + + void batchInsert(@Param("list") List logList); + + /** + * 鏌ヨ鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 + * @param memberId 浼氬憳id + * @param type 1-杩涜处锛2-鍑鸿处 涓嶄紶鏌ュ叏閮 + */ + List getMemberBalanceChanges(@Param("memberId") String memberId, @Param("type") String type); +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderAbnormalRecordMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderAbnormalRecordMapper.java new file mode 100644 index 000000000..bec9190e0 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderAbnormalRecordMapper.java @@ -0,0 +1,56 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.OrderAbnormalRecord; + +import java.util.List; + +public interface OrderAbnormalRecordMapper { + + /** + * 鏌ヨ璁㈠崟寮傚父璁板綍 + * + * @param id 璁㈠崟寮傚父璁板綍涓婚敭 + * @return 璁㈠崟寮傚父璁板綍 + */ + public OrderAbnormalRecord selectOrderAbnormalRecordById(Integer id); + + /** + * 鏌ヨ璁㈠崟寮傚父璁板綍鍒楄〃 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 璁㈠崟寮傚父璁板綍闆嗗悎 + */ + public List selectOrderAbnormalRecordList(OrderAbnormalRecord orderAbnormalRecord); + + /** + * 鏂板璁㈠崟寮傚父璁板綍 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 缁撴灉 + */ + public int insertOrderAbnormalRecord(OrderAbnormalRecord orderAbnormalRecord); + + /** + * 淇敼璁㈠崟寮傚父璁板綍 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 缁撴灉 + */ + public int updateOrderAbnormalRecord(OrderAbnormalRecord orderAbnormalRecord); + + /** + * 鍒犻櫎璁㈠崟寮傚父璁板綍 + * + * @param id 璁㈠崟寮傚父璁板綍涓婚敭 + * @return 缁撴灉 + */ + public int deleteOrderAbnormalRecordById(Integer id); + + /** + * 鎵归噺鍒犻櫎璁㈠崟寮傚父璁板綍 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deleteOrderAbnormalRecordByIds(Integer[] ids); +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java new file mode 100644 index 000000000..4c8008bd6 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java @@ -0,0 +1,185 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.domain.OrderDetail; +import com.jsowell.pile.dto.IndexQueryDTO; +import com.jsowell.pile.dto.QueryOrderDTO; +import com.jsowell.pile.dto.QueryPersonPileDTO; +import com.jsowell.pile.vo.uniapp.OrderVO; +import com.jsowell.pile.vo.uniapp.PersonPileConnectorSumInfoVO; +import com.jsowell.pile.vo.uniapp.SendMessageVO; +import com.jsowell.pile.vo.web.IndexOrderInfoVO; +import com.jsowell.pile.vo.web.OrderListVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 璁㈠崟Mapper鎺ュ彛 + * + * @author jsowell + * @date 2022-09-30 + */ +@Repository +public interface OrderBasicInfoMapper { + /** + * 鏌ヨ璁㈠崟 + * + * @param id 璁㈠崟涓婚敭 + * @return 璁㈠崟 + */ + public OrderBasicInfo selectOrderBasicInfoById(Long id); + + /** + * 鏉′欢鏌ヨ璁㈠崟鍩虹淇℃伅 + * @param info + * @return + */ + OrderBasicInfo getOrderBasicInfo(OrderBasicInfo info); + + /** + * 鏌ヨ璁㈠崟鍒楄〃 + * + * @param orderBasicInfo 璁㈠崟 + * @return 璁㈠崟闆嗗悎 + */ + public List selectOrderBasicInfoList(QueryOrderDTO orderBasicInfo); + + /** + * 鏂板璁㈠崟 + * + * @param orderBasicInfo 璁㈠崟 + * @return 缁撴灉 + */ + public int insertOrderBasicInfo(OrderBasicInfo orderBasicInfo); + + /** + * 淇敼璁㈠崟 + * + * @param orderBasicInfo 璁㈠崟 + * @return 缁撴灉 + */ + public int updateOrderBasicInfo(OrderBasicInfo orderBasicInfo); + + /** + * 鎵归噺鍒犻櫎璁㈠崟 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deleteOrderBasicInfoByIds(Long[] ids); + + /** + * 鎵归噺鍒犻櫎璁㈠崟璇︽儏 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deleteOrderDetailByOrderCodes(Long[] ids); + + /** + * 鎵归噺鏂板璁㈠崟璇︽儏 + * + * @param orderDetailList 璁㈠崟璇︽儏鍒楄〃 + * @return 缁撴灉 + */ + public int batchOrderDetail(List orderDetailList); + + + /** + * 閫氳繃璁㈠崟涓婚敭鍒犻櫎璁㈠崟璇︽儏淇℃伅 + * + * @param id 璁㈠崟ID + * @return 缁撴灉 + */ + public int deleteOrderDetailByOrderCode(Long id); + + /** + * 淇敼璁㈠崟璇︽儏 + * @param orderDetail 璁㈠崟璇︽儏 + */ + void updateOrderDetail(OrderDetail orderDetail); + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曞熀鏈俊鎭 + * + * @param orderCode 璁㈠崟鍙 + * @return + */ + OrderBasicInfo getOrderInfoByOrderCode(String orderCode); + + /** + * 鏍规嵁妗╃紪鍙峰拰鏋彛鍙锋煡璇㈡煇鐘舵佽鍗 + * + * @param pileSn 妗╃紪鍙 + * @param connectorCode 鏋彛鍙 + * @param orderStatus 璁㈠崟鐘舵 + * @return 璁㈠崟 + */ + OrderBasicInfo queryOrderBasicInfo(@Param("pileSn") String pileSn, @Param("connectorCode") String connectorCode, @Param("orderStatus") String orderStatus); + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曡鎯 + * + * @param orderCode 璁㈠崟鍙 + * @return 璁㈠崟璇︽儏 + */ + OrderDetail getOrderDetailByOrderCode(@Param("orderCode") String orderCode); + + /** + * 閫氳繃浼氬憳Id鍜岃鍗曠姸鎬佹煡璇㈣鍗曚俊鎭 + * + * @param memberId 浼氬憳id + * @param orderStatusList 璁㈠崟鐘舵侀泦鍚 + * @return + */ + List getListByMemberIdAndOrderStatus(@Param("memberId") String memberId, @Param("orderStatusList") List orderStatusList); + + /** + * 灏嗘煇璁㈠崟淇敼涓烘煇鐘舵 + * @param orderCode 璁㈠崟鍙 + * @param orderStatus 淇敼涓烘煇鐘舵 + */ + void updateOrderStatusByOrderCode(@Param("orderCode") String orderCode, @Param("orderStatus") String orderStatus); + + + /** + * 棣栭〉璁㈠崟鏁版嵁灞曠ず + * @param dto 棣栭〉淇℃伅鏌ヨdto + * @return + */ + List getIndexOrderInfo(@Param("dto") IndexQueryDTO dto); + + /** + * 鑾峰彇瓒呰繃15鍒嗛挓鐨勫緟鏀粯鐘舵佽鍗 + * @return + */ + List getUnpaidOrderListOver15Min(@Param("createTime") String createTime); + + /** + * 鏍规嵁orderId鎵归噺淇敼璁㈠崟鐘舵 + * @param orderIds + * @param orderStatus + */ + void updateOrderStatusById(@Param("orderIds") List orderIds, @Param("orderStatus") String orderStatus); + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曚俊鎭紙灏忕▼搴忓彂閫佹秷鎭敤锛 + * @param orderCode + * @return + */ + SendMessageVO selectOrderInfoByOrderCode(@Param("orderCode") String orderCode); + + List selectOrderListByTimeRangeAndStatus(@Param("startTime") String startTime, + @Param("endTime") String endTime, + @Param("orderStatus") String orderStatus, + @Param("payStatus") String payStatus); + + /** + * 涓汉妗╂煡璇㈠厖鐢垫暟鎹 + * @param dto + * @return + */ + List getAccumulativeInfo(QueryPersonPileDTO dto); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderPayRecordMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderPayRecordMapper.java new file mode 100644 index 000000000..d64c0e2a5 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderPayRecordMapper.java @@ -0,0 +1,24 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.OrderPayRecord; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface OrderPayRecordMapper { + int deleteByPrimaryKey(Integer id); + + // int insert(OrderPayRecord record); + + // int insertSelective(OrderPayRecord record); + + OrderPayRecord selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(OrderPayRecord record); + + int updateByPrimaryKey(OrderPayRecord record); + + int batchInsert(@Param("payRecordList") List payRecordList); + + List getOrderPayRecordList(@Param("orderCode") String orderCode); +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java new file mode 100644 index 000000000..0e032eb99 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java @@ -0,0 +1,146 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileBasicInfo; +import com.jsowell.pile.dto.IndexQueryDTO; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import com.jsowell.pile.vo.web.IndexGeneralSituationVO; +import com.jsowell.pile.dto.QueryPileDTO; +import com.jsowell.pile.dto.ReplaceMerchantStationDTO; +import com.jsowell.pile.vo.web.PileDetailVO; +import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 璁惧绠$悊Mapper鎺ュ彛 + * + * @author jsowell + * @date 2022-08-26 + */ +@Repository +public interface PileBasicInfoMapper { + /** + * 鏌ヨ璁惧绠$悊 + * + * @param id 璁惧绠$悊涓婚敭 + * @return 璁惧绠$悊 + */ + PileBasicInfo selectPileBasicInfoById(Long id); + + PileBasicInfo selectPileBasicInfoBySn(String pileSn); + + /** + * 鏌ヨ璁惧绠$悊鍒楄〃 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 璁惧绠$悊闆嗗悎 + */ + List selectPileBasicInfoList(PileBasicInfo pileBasicInfo); + + /** + * 鏂板璁惧绠$悊 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 缁撴灉 + */ + int insertPileBasicInfo(PileBasicInfo pileBasicInfo); + + /** + * 鎵归噺淇濆瓨 + * + * @param pileBasicInfoList + * @return + */ + int batchInsertPileBasicInfo(@Param("infoList") List pileBasicInfoList); + + /** + * 淇敼璁惧绠$悊 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 缁撴灉 + */ + int updatePileBasicInfo(PileBasicInfo pileBasicInfo); + + /** + * 鍒犻櫎璁惧绠$悊 + * + * @param id 璁惧绠$悊涓婚敭 + * @return 缁撴灉 + */ + int deletePileBasicInfoById(Long id); + + /** + * 鎵归噺鍒犻櫎璁惧绠$悊 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + int deletePileBasicInfoByIds(Long[] ids); + + /** + * 鏌ヨ璁惧淇℃伅 + * + * @param dto 鏌ヨ鏉′欢瀹炰綋绫 + * @return 璁惧淇℃伅瀵硅薄闆嗗悎 + */ + List queryPileInfos(@Param("dto") QueryPileDTO dto); + + /** + * 閫氳繃绔欑偣ids鏌ヨ妗╀俊鎭 + * + * @param stationIds 绔欑偣id + * @return 妗╁璞¢泦鍚 + */ + List selectPileListByStationIds(@Param("stationIds") List stationIds); + + /** + * 閫氳繃pileId鏇存崲绔欑偣銆佽繍钀ュ晢淇℃伅 + * + * @param dto + * @return + */ + int replaceMerchantStationByPileIds(ReplaceMerchantStationDTO dto); + + /** + * 閫氳繃妗﹊d鏌ヨbasic淇℃伅 + * + * @param id 妗﹊d + * @return PileBasic瀵硅薄闆嗗悎 + */ + PileDetailVO selectBasicInfoById(Long id); + + /** + * 閫氳繃idList鎵归噺鏌ヨ + * + * @param pileIdList + * @return + */ + List selectByIdList(@Param("pileIdList") List pileIdList); + + /** + * 鏌ヨ鍏呯數妗╀俊鎭 + * + * @param pileConnectorCode 鍏呯數鏋紪鍙 + * @return + */ + PileConnectorDetailVO queryPileConnectorDetail(@Param("pileConnectorCode") String pileConnectorCode); + + + /** + * 鍚庣棣栭〉鍩烘湰淇℃伅鏌ヨ + * + * @param dto 绔欑偣Id + * @return 棣栭〉鍩烘湰淇℃伅 + */ + public IndexGeneralSituationVO getGeneralSituation(@Param("IndexQueryDTO")IndexQueryDTO dto); + + + /** + * 閫氳繃浼氬憳id鏌ヨ涓汉妗╁垪琛 + * @param memberId + * @return + */ + public List getPileInfoByMemberId(String memberId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBillingTemplateMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBillingTemplateMapper.java new file mode 100644 index 000000000..3622aacc5 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBillingTemplateMapper.java @@ -0,0 +1,144 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileBillingDetail; +import com.jsowell.pile.domain.PileBillingRelation; +import com.jsowell.pile.domain.PileBillingTemplate; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 璁¤垂妯℃澘Mapper鎺ュ彛 + * + * @author jsowell + * @date 2022-09-20 + */ +@Repository +public interface PileBillingTemplateMapper { + /** + * 鏌ヨ璁¤垂妯℃澘 + * + * @param id 璁¤垂妯℃澘涓婚敭 + * @return 璁¤垂妯℃澘 + */ + public PileBillingTemplate selectPileBillingTemplateById(Long id); + + /** + * 鏌ヨ璁¤垂妯℃澘鍒楄〃 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 璁¤垂妯℃澘闆嗗悎 + */ + public List selectPileBillingTemplateList(PileBillingTemplate pileBillingTemplate); + + /** + * 鏂板璁¤垂妯℃澘 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 缁撴灉 + */ + public int insertPileBillingTemplate(PileBillingTemplate pileBillingTemplate); + + /** + * 淇敼璁¤垂妯℃澘 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 缁撴灉 + */ + public int updatePileBillingTemplate(PileBillingTemplate pileBillingTemplate); + + /** + * 鍒犻櫎璁¤垂妯℃澘 + * + * @param id 璁¤垂妯℃澘涓婚敭 + * @return 缁撴灉 + */ + public int deletePileBillingTemplateById(Long id); + + /** + * 鎵归噺鍒犻櫎璁¤垂妯℃澘 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileBillingTemplateByIds(Long[] ids); + + /** + * 鎵归噺鍒犻櫎璁¤垂妯℃澘璇︽儏 + * + * @param templateCodes 闇瑕佸垹闄ょ殑templateCode闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileBillingDetailByTemplateCodes(@Param("templateCodes") List templateCodes); + + /** + * 鎵归噺鏂板璁¤垂妯℃澘璇︽儏 + * + * @param pileBillingDetailList 璁¤垂妯℃澘璇︽儏鍒楄〃 + * @return 缁撴灉 + */ + public int batchPileBillingDetail(List pileBillingDetailList); + + + /** + * 閫氳繃璁¤垂妯℃澘涓婚敭鍒犻櫎璁¤垂妯℃澘璇︽儏淇℃伅 + * + * @param templateCode 璁¤垂妯℃澘code + * @return 缁撴灉 + */ + public int deletePileBillingDetailByTemplateCode(String templateCode); + + /** + * 鏌ヨ鍏叡璁¤垂妯℃澘鍒楄〃 + * @return + */ + List queryPublicBillingTemplateList(); + + /** + * 鏍规嵁绔欑偣id鏌ヨ绔欑偣璁¤垂妯℃澘鍒楄〃 + * 鏍规嵁鍙戝竷鏃堕棿鍊掑簭锛屾渶鏂颁竴鏉″氨鏄洰鍓嶆鍦ㄤ娇鐢ㄧ殑璁¤垂妯℃澘 + * @param stationId 绔欑偣id + * @return + */ + List queryStationBillingTemplateList(String stationId); + + /** + * 閫氳繃妗﹕n鍙锋煡璇㈣璐规ā鏉 + * + * @param pileSn 妗﹕n + * @return 璁¤垂妯℃澘缂栧彿 + */ + BillingTemplateVO selectBillingTemplateByPileSn(@Param("pileSn") String pileSn); + + /** + * 閫氳繃璁¤垂妯℃澘id鏌ヨ + * @param templateId 璁¤垂妯℃澘id + * @return + */ + BillingTemplateVO selectBillingTemplateByTemplateId(@Param("templateId") String templateId); + + /** + * 鏌ヨ绔欑偣鏈鏂板彂甯冪殑璁¤垂妯℃澘 + * @param stationId + * @return + */ + BillingTemplateVO selectBillingTemplateByStationId(@Param("stationId") String stationId); + + /** + * 閫氳繃妯℃澘id鏌ヨ璁¤垂妯℃澘璇︽儏鍒楄〃 + */ + List queryBillingDetailByTemplateIds(@Param("templateIds") Long[] templateIds); + + /** + * 鎻掑叆鍏呯數妗╁拰璁¤垂妯℃澘鍏崇郴 + */ + void insertPileBillingRelation(List relationList); + + /** + * 鏍规嵁妗╁彿鍒犻櫎璁¤垂妯℃澘鍏崇郴 + * @param pileSnList + */ + void deleteRelationByPileSn(@Param("pileSnList") List pileSnList); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileConnectorInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileConnectorInfoMapper.java new file mode 100644 index 000000000..5f461ab98 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileConnectorInfoMapper.java @@ -0,0 +1,141 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileConnectorInfo; +import com.jsowell.pile.dto.QueryConnectorDTO; +import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 鍏呯數妗╂灙鍙d俊鎭疢apper鎺ュ彛 + * + * @author jsowell + * @date 2022-08-31 + */ +@Repository +public interface PileConnectorInfoMapper { + /** + * 鏌ヨ鍏呯數妗╂灙鍙d俊鎭 + * + * @param id 鍏呯數妗╂灙鍙d俊鎭富閿 + * @return 鍏呯數妗╂灙鍙d俊鎭 + */ + public PileConnectorInfo selectPileConnectorInfoById(Integer id); + + /** + * 鏌ヨ鍏呯數妗╂灙鍙d俊鎭垪琛 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 鍏呯數妗╂灙鍙d俊鎭泦鍚 + */ + public List selectPileConnectorInfoList(PileConnectorInfo pileConnectorInfo); + + /** + * 鏂板鍏呯數妗╂灙鍙d俊鎭 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 缁撴灉 + */ + // public int insertPileConnectorInfo(PileConnectorInfo pileConnectorInfo); + + /** + * 鎵归噺鏂板鍏呯數妗╂灙鍙d俊鎭 + * + * @param pileConnectorInfoList 鍏呯數妗╂灙鍙i泦鍚 + * @return 缁撴灉 + */ + public int batchInsertConnectorInfo(@Param("connectorList") List pileConnectorInfoList); + + /** + * 淇敼鍏呯數妗╂灙鍙d俊鎭 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 缁撴灉 + */ + public int updatePileConnectorInfo(PileConnectorInfo pileConnectorInfo); + + /** + * 鍒犻櫎鍏呯數妗╂灙鍙d俊鎭 + * + * @param id 鍏呯數妗╂灙鍙d俊鎭富閿 + * @return 缁撴灉 + */ + // public int deletePileConnectorInfoById(Integer id); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╂灙鍙d俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + // public int deletePileConnectorInfoByIds(Integer[] ids); + + /** + * 鏍规嵁鍏呯數妗╃紪鍙峰垹闄ゅ厖鐢垫々鏋彛淇℃伅 + * @param pileSnList + * @return + */ + int deletePileConnectorInfoByPileSnList(List pileSnList); + + /** + * 鑾峰彇鍏呯數鎺ュ彛淇℃伅鍒楄〃 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 鍏呯數鎺ュ彛瀵硅薄闆嗗悎 + */ + List getConnectorInfoList(@Param("connectorDTO") QueryConnectorDTO dto); + + /** + * 閫氳繃绔欑偣id鏌ヨ鍏呯數鏋俊鎭 + * + * @param stationId 绔欑偣id + * @return 鍏呯數鏋澶囬泦鍚 + */ + List selectConnectorListByStationId(@Param("stationId") Long stationId); + + /** + * 閫氳繃鍏呯數妗﹕n鎴朿onnectorId 鏌ヨ鍏呯數妗╂帴鍙e垪琛 + * + * @param pileSns 妗╃紪鍙峰垪琛 + * @param connectorIds 鏋彛鍙峰垪琛 + * @return 鍏呯數妗╂帴鍙e垪琛 + */ + List getPileConnectorInfoList(@Param("pileSns") List pileSns, @Param("connectorIds") List connectorIds, @Param("connectorCodes") List connectorCodeList); + + /** + * 鏍规嵁鏋彛鍙 淇敼鏋彛鐘舵 + * + * @param connectorCode 鏋彛鍙 + * @param connectorStatus 鐘舵 + */ + int updateConnectorStatus(@Param("connectorCode") String connectorCode, @Param("connectorStatus") String connectorStatus); + + /** + * 鏍规嵁妗╃紪鍙蜂慨鏀规灙鍙g姸鎬 + * + * @param pileSn 妗╃紪鍙 + * @param connectorStatus 鐘舵 + * @return 淇敼鏁伴噺 + */ + int updateConnectorStatusByPileSn(@Param("pileSn") String pileSn, @Param("connectorStatus") String connectorStatus); + + /** + * 鏌ヨ鏋彛淇℃伅 + * @param pileConnectorCode 鏋彛鍙 + * @return 鏋彛淇℃伅 + */ + PileConnectorInfoVO getPileConnectorInfoByConnectorCode(@Param("pileConnectorCode") String pileConnectorCode); + + + /** + * uniApp閫氳繃绔欑偣id鏌ヨ鏋彛鍒楄〃淇℃伅 + * + * @param stationId 绔欑偣id + * @return + */ + List getUniAppConnectorList(@Param("stationId") Long stationId); + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileLicenceInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileLicenceInfoMapper.java new file mode 100644 index 000000000..58d689512 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileLicenceInfoMapper.java @@ -0,0 +1,61 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileLicenceInfo; + +import java.util.List; + +/** + * 鍏呯數妗╄瘉涔︿俊鎭疢apper鎺ュ彛 + * + * @author jsowell + * @date 2022-08-27 + */ +public interface PileLicenceInfoMapper { + /** + * 鏌ヨ鍏呯數妗╄瘉涔︿俊鎭 + * + * @param id 鍏呯數妗╄瘉涔︿俊鎭富閿 + * @return 鍏呯數妗╄瘉涔︿俊鎭 + */ + public PileLicenceInfo selectPileLicenceInfoById(Long id); + + /** + * 鏌ヨ鍏呯數妗╄瘉涔︿俊鎭垪琛 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 鍏呯數妗╄瘉涔︿俊鎭泦鍚 + */ + public List selectPileLicenceInfoList(PileLicenceInfo pileLicenceInfo); + + /** + * 鏂板鍏呯數妗╄瘉涔︿俊鎭 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 缁撴灉 + */ + public int insertPileLicenceInfo(PileLicenceInfo pileLicenceInfo); + + /** + * 淇敼鍏呯數妗╄瘉涔︿俊鎭 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 缁撴灉 + */ + public int updatePileLicenceInfo(PileLicenceInfo pileLicenceInfo); + + /** + * 鍒犻櫎鍏呯數妗╄瘉涔︿俊鎭 + * + * @param id 鍏呯數妗╄瘉涔︿俊鎭富閿 + * @return 缁撴灉 + */ + public int deletePileLicenceInfoById(Long id); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╄瘉涔︿俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileLicenceInfoByIds(Long[] ids); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMemberRelationMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMemberRelationMapper.java new file mode 100644 index 000000000..672042776 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMemberRelationMapper.java @@ -0,0 +1,74 @@ +package com.jsowell.pile.mapper; + +import java.util.List; +import com.jsowell.pile.domain.PileMemberRelation; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import org.springframework.stereotype.Repository; + +/** + * 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴Mapper鎺ュ彛 + * + * @author jsowell + * @date 2023-02-21 + */ +@Repository +public interface PileMemberRelationMapper +{ + /** + * 鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param id 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴涓婚敭 + * @return 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + */ + public PileMemberRelation selectPileMemberRelationById(Integer id); + + /** + * 鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴鍒楄〃 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴闆嗗悎 + */ + public List selectPileMemberRelationList(PileMemberRelation pileMemberRelation); + + /** + * 鏉′欢鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation + * @return + */ + PileMemberRelation selectPileMemberRelation(PileMemberRelation pileMemberRelation); + + /** + * 鏂板妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 缁撴灉 + */ + public int insertPileMemberRelation(PileMemberRelation pileMemberRelation); + + /** + * 淇敼妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 缁撴灉 + */ + public int updatePileMemberRelation(PileMemberRelation pileMemberRelation); + + /** + * 鍒犻櫎妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param id 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴涓婚敭 + * @return 缁撴灉 + */ + public int deletePileMemberRelationById(Integer id); + + /** + * 鎵归噺鍒犻櫎妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileMemberRelationByIds(Integer[] ids); + + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMerchantInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMerchantInfoMapper.java new file mode 100644 index 000000000..1363b5b4a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMerchantInfoMapper.java @@ -0,0 +1,70 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileMerchantInfo; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 鍏呯數妗╄繍钀ュ晢淇℃伅Mapper鎺ュ彛 + * + * @author jsowell + * @date 2022-08-27 + */ +@Repository +public interface PileMerchantInfoMapper { + /** + * 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param id 鍏呯數妗╄繍钀ュ晢淇℃伅涓婚敭 + * @return 鍏呯數妗╄繍钀ュ晢淇℃伅 + */ + public PileMerchantInfo selectPileMerchantInfoById(Long id); + + /** + * 閫氳繃appid鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅 + * @param appId + * @return + */ + PileMerchantInfo selectPileMerchantInfoByAppId(String appId); + + /** + * 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅鍒楄〃 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 鍏呯數妗╄繍钀ュ晢淇℃伅闆嗗悎 + */ + public List selectPileMerchantInfoList(PileMerchantInfo pileMerchantInfo); + + /** + * 鏂板鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 缁撴灉 + */ + public int insertPileMerchantInfo(PileMerchantInfo pileMerchantInfo); + + /** + * 淇敼鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 缁撴灉 + */ + public int updatePileMerchantInfo(PileMerchantInfo pileMerchantInfo); + + /** + * 鍒犻櫎鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param id 鍏呯數妗╄繍钀ュ晢淇℃伅涓婚敭 + * @return 缁撴灉 + */ + public int deletePileMerchantInfoById(Long id); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileMerchantInfoByIds(Long[] ids); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileModelInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileModelInfoMapper.java new file mode 100644 index 000000000..1b9d4944d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileModelInfoMapper.java @@ -0,0 +1,73 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileModelInfo; +import com.jsowell.pile.vo.web.PileModelInfoVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 鍏呯數妗╁瀷鍙蜂俊鎭疢apper鎺ュ彛 + * + * @author jsowell + * @date 2022-08-26 + */ +@Repository +public interface PileModelInfoMapper { + /** + * 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param id 鍏呯數妗╁瀷鍙蜂俊鎭富閿 + * @return 鍏呯數妗╁瀷鍙蜂俊鎭 + */ + public PileModelInfo selectPileModelInfoById(Long id); + + /** + * 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭垪琛 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 鍏呯數妗╁瀷鍙蜂俊鎭泦鍚 + */ + public List selectPileModelInfoList(PileModelInfo pileModelInfo); + + /** + * 鏂板鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 缁撴灉 + */ + public int insertPileModelInfo(PileModelInfo pileModelInfo); + + /** + * 淇敼鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 缁撴灉 + */ + public int updatePileModelInfo(PileModelInfo pileModelInfo); + + /** + * 鍒犻櫎鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param id 鍏呯數妗╁瀷鍙蜂俊鎭富閿 + * @return 缁撴灉 + */ + public int deletePileModelInfoById(Long id); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileModelInfoByIds(Long[] ids); + + /** + * 閫氳繃妗╃紪鍙烽泦鍚堣幏鍙栧瀷鍙疯〃涓暟鎹 + * + * @param pileSns 妗╃紪鍙烽泦鍚 + * @return PileModelInfo瀵硅薄 + */ + List getPileModelInfoByPileSnList(@Param("pileSnList") List pileSns); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMsgRecordMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMsgRecordMapper.java new file mode 100644 index 000000000..4c81951e1 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileMsgRecordMapper.java @@ -0,0 +1,32 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileMsgRecord; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface PileMsgRecordMapper { + int insertSelective(PileMsgRecord record); + + // PileMsgRecord selectByPrimaryKey(Integer id); + + // PileMsgRecord getByPileSn(String pileSn); + + // PileMsgRecord getByConnectorCode(String connectorCode); + + /** + * 鏍规嵁鏋彛鍙锋煡璇㈡灙鍙f棩蹇 + * @param connectorCodeList + * @return + */ + // List getByConnectorCodeList(@Param("connectorCodeList") List connectorCodeList); + + /** + * 鏌ヨ鍏呯數妗╅氫俊鏃ュ織 + * @param pileSn 妗╁彿 + * @return + */ + List getPileFeedList(@Param("pileSn") String pileSn); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileSimInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileSimInfoMapper.java new file mode 100644 index 000000000..3a2d38e75 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileSimInfoMapper.java @@ -0,0 +1,96 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileSimInfo; +import com.jsowell.pile.dto.QuerySimInfoDTO; +import com.jsowell.pile.vo.web.SimCardInfoVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 鍏呯數妗㏒IM鍗′俊鎭疢apper鎺ュ彛 + * + * @author jsowell + * @date 2022-08-26 + */ +@Component +public interface PileSimInfoMapper { + /** + * 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭 + * + * @param id 鍏呯數妗㏒IM鍗′俊鎭富閿 + * @return 鍏呯數妗㏒IM鍗′俊鎭 + */ + public PileSimInfo selectPileSimInfoById(Long id); + + /** + * 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭垪琛 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 鍏呯數妗㏒IM鍗′俊鎭泦鍚 + */ + public List selectPileSimInfoList(PileSimInfo pileSimInfo); + + /** + * 鍚庣鏌ヨsim鍗′俊鎭垪琛 + * @return + */ + List getSimInfoList(@Param("dto") QuerySimInfoDTO dto); + + /** + * 鏂板鍏呯數妗㏒IM鍗′俊鎭 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 缁撴灉 + */ + public int insertPileSimInfo(PileSimInfo pileSimInfo); + + /** + * 淇敼鍏呯數妗㏒IM鍗′俊鎭 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 缁撴灉 + */ + public int updatePileSimInfo(PileSimInfo pileSimInfo); + + /** + * 鍒犻櫎鍏呯數妗㏒IM鍗′俊鎭 + * + * @param id 鍏呯數妗㏒IM鍗′俊鎭富閿 + * @return 缁撴灉 + */ + public int deletePileSimInfoById(Long id); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗㏒IM鍗′俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileSimInfoByIds(Long[] ids); + + + /** + * 閫氳繃妗╃紪鐮佹煡璇im鍗′俊鎭 + * @param pileSn 妗╃紪鐮 + * @return + */ + SimCardInfoVO querySimCardInfoByPileSn(String pileSn); + + /** + * 閫氳繃鍗″彿鎵归噺鏌ヨsim鍗′俊鎭 + * @param iccIds 鍗″彿闆嗗悎 + * @return + */ + List selectSimInfoByIccIds(@Param("iccIds") List iccIds); + + /** + * 閫氳繃鍗″彿鏌ヨsim鍗′俊鎭 + * @param iccId 鍗″彿 + * @return + */ + PileSimInfo getBasicInfoByIccId(@Param("iccId") String iccId); + + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileStationInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileStationInfoMapper.java new file mode 100644 index 000000000..294303459 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileStationInfoMapper.java @@ -0,0 +1,74 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.PileStationInfo; +import com.jsowell.pile.dto.QueryStationDTO; +import com.jsowell.pile.vo.web.PileStationVO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 鍏呯數绔欎俊鎭疢apper鎺ュ彛 + * + * @author jsowell + * @date 2022-08-30 + */ +@Repository +public interface PileStationInfoMapper { + /** + * 鏌ヨ鍏呯數绔欎俊鎭 + * + * @param id 鍏呯數绔欎俊鎭富閿 + * @return 鍏呯數绔欎俊鎭 + */ + public PileStationInfo selectPileStationInfoById(Long id); + + /** + * 鏌ヨ鍏呯數绔欎俊鎭垪琛 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 鍏呯數绔欎俊鎭泦鍚 + */ + public List selectPileStationInfoList(PileStationInfo pileStationInfo); + + /** + * 閫氳繃杩愯惀鍟唅d鏌ヨ绔欑偣淇℃伅 + * + * @param merchantId 杩愯惀鍟唅d + * @return 绔欑偣淇℃伅鍒楄〃 + */ + public List selectStationListByMerchantId(Long merchantId); + + /** + * 鏂板鍏呯數绔欎俊鎭 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 缁撴灉 + */ + public int insertPileStationInfo(PileStationInfo pileStationInfo); + + /** + * 淇敼鍏呯數绔欎俊鎭 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 缁撴灉 + */ + public int updatePileStationInfo(PileStationInfo pileStationInfo); + + /** + * 鎵归噺鍒犻櫎鍏呯數绔欎俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileStationInfoByIds(Long[] ids); + + /** + * 鏌ヨ鍏呯數绔欎俊鎭 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 鍏呯數绔欏璞¢泦鍚 + */ + List queryStationInfos(@Param("stationDTO") QueryStationDTO dto); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/WxpayCallbackRecordMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/WxpayCallbackRecordMapper.java new file mode 100644 index 000000000..a907ed2e6 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/WxpayCallbackRecordMapper.java @@ -0,0 +1,39 @@ +package com.jsowell.pile.mapper; + + +import com.jsowell.pile.domain.WxpayCallbackRecord; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; +import java.util.List; + +public interface WxpayCallbackRecordMapper { + int deleteByPrimaryKey(Integer id); + + int insert(WxpayCallbackRecord record); + + int insertSelective(WxpayCallbackRecord record); + + WxpayCallbackRecord selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(WxpayCallbackRecord record); + + int updateByPrimaryKey(WxpayCallbackRecord record); + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈡敮浠樿褰 + * @param orderCode + * @return + */ + WxpayCallbackRecord selectByOrderCode(String orderCode); + + /** + * 鏍规嵁浼氬憳id鍜屾椂闂存煡璇㈡敮浠樿褰 + * @param memberId 浼氬憳id + * @param date 鏃ユ湡锛屾煡璇㈣鏃ユ湡涔嬪悗鐨勮褰 + * @return + */ + List selectBalanceRechargeRecord(@Param("memberId") String memberId, @Param("date") LocalDateTime date); + + WxpayCallbackRecord selectByOutTradeNo(@Param("outTradeNo") String outTradeNo); +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/WxpayRefundCallbackMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/WxpayRefundCallbackMapper.java new file mode 100644 index 000000000..29dbd86e0 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/WxpayRefundCallbackMapper.java @@ -0,0 +1,17 @@ +package com.jsowell.pile.mapper; + +import com.jsowell.pile.domain.WxpayRefundCallback; + +public interface WxpayRefundCallbackMapper { + int deleteByPrimaryKey(Integer id); + + int insert(WxpayRefundCallback record); + + int insertSelective(WxpayRefundCallback record); + + WxpayRefundCallback selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(WxpayRefundCallback record); + + int updateByPrimaryKey(WxpayRefundCallback record); +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberBasicInfoService.java new file mode 100644 index 000000000..8ffd77fcf --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberBasicInfoService.java @@ -0,0 +1,118 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.MemberBasicInfo; +import com.jsowell.pile.vo.uniapp.MemberVO; +import com.jsowell.pile.vo.uniapp.MemberWalletLogVO; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; + +import java.util.List; + +/** + * 浼氬憳鍩虹淇℃伅Service鎺ュ彛 + * + * @author jsowell + * @date 2022-10-12 + */ +public interface IMemberBasicInfoService { + /** + * 鏌ヨ浼氬憳鍩虹淇℃伅 + * + * @param id 浼氬憳鍩虹淇℃伅涓婚敭 + * @return 浼氬憳鍩虹淇℃伅 + */ + public MemberBasicInfo selectMemberBasicInfoById(Integer id); + + /** + * 鏌ヨ浼氬憳鍩虹淇℃伅鍒楄〃 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 浼氬憳鍩虹淇℃伅闆嗗悎 + */ + // public List selectMemberBasicInfoList(MemberBasicInfo memberBasicInfo); + + /** + * 鏂板浼氬憳鍩虹淇℃伅 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 缁撴灉 + */ + public int insertMemberBasicInfo(MemberBasicInfo memberBasicInfo); + + /** + * 淇敼浼氬憳鍩虹淇℃伅 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 缁撴灉 + */ + public int updateMemberBasicInfo(MemberBasicInfo memberBasicInfo); + + /** + * 鎵归噺鍒犻櫎浼氬憳鍩虹淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑浼氬憳鍩虹淇℃伅涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deleteMemberBasicInfoByIds(List ids); + + + /** + * 閫氳繃鐗╃悊鍗″彿鏌ヨ鍩烘湰淇℃伅 + * + * @param physicsCard 鐗╃悊鍗″彿 + * @return 浼氬憳鍩虹淇℃伅 + */ + MemberVO selectInfoByPhysicsCard(String physicsCard); + + /** + * 鏍规嵁鎵嬫満鍙峰拰杩愯惀鍟唅d鏌ヨ浼氬憳淇℃伅 + * @param phone 鎵嬫満鍙 mobile number + * @param merchantId 杩愯惀鍟唅d + * @return 浼氬憳淇℃伅 + */ + MemberBasicInfo selectInfoByMobileNumberAndMerchantId(String phone, String merchantId); + + /** + * 鏍规嵁鎵嬫満鍙锋煡璇細鍛樹俊鎭 + * @param mobileNumber 鎵嬫満鍙 + * @return + */ + MemberBasicInfo selectInfoByMobileNumber(String mobileNumber); + + /** + * 鏍规嵁浼氬憳id鏌ヨ浼氬憳淇℃伅 + * @param memberId 浼氬憳id + * @return + */ + MemberBasicInfo selectInfoByMemberId(String memberId); + + /** + * 鏇存柊浼氬憳浣欓 + * @param dto + * @return + */ + int updateMemberBalance(UpdateMemberBalanceDTO dto); + + /** + * + * @param memberId + * @return + */ + MemberVO queryMemberInfoByMemberId(String memberId); + + List selectMemberList(String mobileNumber, String nickName); + + /** + * 鏌ヨ鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 + * @param memberId 浼氬憳id + * @param type 1-杩涜处锛2-鍑鸿处 涓嶄紶鏌ュ叏閮 + */ + List getMemberBalanceChanges(String memberId, String type); + + /** + * 閫氳繃memberId鏌ヨ浼氬憳鐨勪釜浜烘々淇℃伅 + * @param memberId + * @return + */ + List getMemberPersonPileInfo(String memberId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberTransactionRecordService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberTransactionRecordService.java new file mode 100644 index 000000000..79d5ad8e3 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberTransactionRecordService.java @@ -0,0 +1,18 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.MemberTransactionRecord; +import com.jsowell.pile.vo.web.MemberTransactionVO; + +import java.util.List; + +public interface IMemberTransactionRecordService { + + /** + * 淇濆瓨浜ゆ槗璁板綍 + * @param record + * @return + */ + int insertSelective(MemberTransactionRecord record); + + List selectMemberTransactionRecordList(String memberId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberWalletInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberWalletInfoService.java new file mode 100644 index 000000000..ba81057b4 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberWalletInfoService.java @@ -0,0 +1,17 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.MemberWalletInfo; + +public interface IMemberWalletInfoService { + int deleteByPrimaryKey(Integer id); + + int insert(MemberWalletInfo record); + + int insertSelective(MemberWalletInfo record); + + MemberWalletInfo selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(MemberWalletInfo record); + + int updateByPrimaryKey(MemberWalletInfo record); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberWalletLogService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberWalletLogService.java new file mode 100644 index 000000000..bfb159cf2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IMemberWalletLogService.java @@ -0,0 +1,16 @@ +package com.jsowell.pile.service; + +public interface IMemberWalletLogService { + // int deleteByPrimaryKey(Integer id); + // + // int insert(MemberWalletLog record); + // + // int insertSelective(MemberWalletLog record); + // + // MemberWalletLog selectByPrimaryKey(Integer id); + // + // int updateByPrimaryKeySelective(MemberWalletLog record); + // + // int updateByPrimaryKey(MemberWalletLog record); + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderAbnormalRecordService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderAbnormalRecordService.java new file mode 100644 index 000000000..923a689dc --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderAbnormalRecordService.java @@ -0,0 +1,61 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.OrderAbnormalRecord; + +import java.util.List; + +/** + * 璁㈠崟寮傚父璁板綍Service鎺ュ彛 + * + * @author jsowell + * @date 2023-02-13 + */ +public interface IOrderAbnormalRecordService { + /** + * 鏌ヨ璁㈠崟寮傚父璁板綍 + * + * @param id 璁㈠崟寮傚父璁板綍涓婚敭 + * @return 璁㈠崟寮傚父璁板綍 + */ + public OrderAbnormalRecord selectOrderAbnormalRecordById(Integer id); + + /** + * 鏌ヨ璁㈠崟寮傚父璁板綍鍒楄〃 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 璁㈠崟寮傚父璁板綍闆嗗悎 + */ + public List selectOrderAbnormalRecordList(OrderAbnormalRecord orderAbnormalRecord); + + /** + * 鏂板璁㈠崟寮傚父璁板綍 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 缁撴灉 + */ + public int insertOrderAbnormalRecord(OrderAbnormalRecord orderAbnormalRecord); + + /** + * 淇敼璁㈠崟寮傚父璁板綍 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 缁撴灉 + */ + public int updateOrderAbnormalRecord(OrderAbnormalRecord orderAbnormalRecord); + + /** + * 鎵归噺鍒犻櫎璁㈠崟寮傚父璁板綍 + * + * @param ids 闇瑕佸垹闄ょ殑璁㈠崟寮傚父璁板綍涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deleteOrderAbnormalRecordByIds(Integer[] ids); + + /** + * 鍒犻櫎璁㈠崟寮傚父璁板綍淇℃伅 + * + * @param id 璁㈠崟寮傚父璁板綍涓婚敭 + * @return 缁撴灉 + */ + public int deleteOrderAbnormalRecordById(Integer id); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderBasicInfoService.java new file mode 100644 index 000000000..2dcb9f955 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderBasicInfoService.java @@ -0,0 +1,194 @@ +package com.jsowell.pile.service; + +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.core.domain.ykc.TransactionRecordsData; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.domain.OrderDetail; +import com.jsowell.pile.dto.IndexQueryDTO; +import com.jsowell.pile.dto.QueryOrderDTO; +import com.jsowell.pile.dto.QueryPersonPileDTO; +import com.jsowell.pile.vo.uniapp.OrderVO; +import com.jsowell.pile.vo.uniapp.PersonPileConnectorSumInfoVO; +import com.jsowell.pile.vo.uniapp.SendMessageVO; +import com.jsowell.pile.vo.web.IndexOrderInfoVO; +import com.jsowell.pile.vo.web.OrderListVO; +import com.jsowell.pile.vo.web.OrderTotalDataVO; +import com.jsowell.wxpay.dto.WeChatRefundDTO; + +import java.util.List; + +/** + * 璁㈠崟Service鎺ュ彛 + * + * @author jsowell + * @date 2022-09-30 + */ +public interface IOrderBasicInfoService { + /** + * 鏌ヨ璁㈠崟 + * + * @param id 璁㈠崟涓婚敭 + * @return 璁㈠崟 + */ + OrderBasicInfo selectOrderBasicInfoById(Long id); + + /** + * 鏉′欢鏌ヨ璁㈠崟鍩虹淇℃伅 + * @param info + * @return + */ + OrderBasicInfo getOrderBasicInfo(OrderBasicInfo info); + + /** + * 鏌ヨ璁㈠崟鍒楄〃 + * + * @param dto 璁㈠崟 + * @return 璁㈠崟闆嗗悎 + */ + List selectOrderBasicInfoList(QueryOrderDTO dto); + + /** + * 鏌ヨ鍏呯數涓殑璁㈠崟锛屾病鏈夋暟鎹潈闄愭牎楠岋紝鍚庣涓嶈鐢 + * @param pileSn + * @return + */ + List selectChargingOrder(String pileSn); + + /** + * 淇敼璁㈠崟 + * + * @param orderBasicInfo 璁㈠崟 + * @return 缁撴灉 + */ + int updateOrderBasicInfo(OrderBasicInfo orderBasicInfo); + + /** + * 鎵归噺鍒犻櫎璁㈠崟 + * + * @param ids 闇瑕佸垹闄ょ殑璁㈠崟涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + int deleteOrderBasicInfoByIds(Long[] ids); + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曚俊鎭 + * + * @param orderCode 璁㈠崟鍙 + * @return + */ + OrderBasicInfo getOrderInfoByOrderCode(String orderCode); + + /** + * 閫氳繃妗╁彿鍜屾灙鍙e彿鏌ヨ鍏呯數涓殑鐘舵 + * @param pileSn 妗╃紪鍙 + * @param connectorCode 鏋彛鍙 + * @return + */ + OrderBasicInfo queryChargingByPileSnAndConnectorCode(String pileSn, String connectorCode); + + OrderBasicInfo queryChargingByPileConnectorCode(String pileConnectorCode); + + /** + * 鏍规嵁浜ゆ槗璁板綍缁撶畻璁㈠崟 + * @param data 浜ゆ槗璁板綍鏁版嵁 + * @param orderBasicInfo + */ + void settleOrder(TransactionRecordsData data, OrderBasicInfo orderBasicInfo); + + /** + * 鍏抽棴15鍒嗛挓鏈敮浠樿鍗 + * @return + */ + int close15MinutesOfUnpaidOrders(); + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曡鎯 + * + * @param orderCode 璁㈠崟鍙 + * @return 璁㈠崟璇︽儏 + */ + OrderDetail getOrderDetailByOrderCode(String orderCode); + + /** + * 閫氳繃浼氬憳Id鍜岃鍗曠姸鎬佹煡璇㈣鍗曚俊鎭 + * + * @param memberId 浼氬憳id + * @param orderStatusList 璁㈠崟鐘舵侀泦鍚 + * @return + */ + List getListByMemberIdAndOrderStatus(String memberId, List orderStatusList); + + /** + * 缁撶畻璁㈠崟閫娆惧拰鐢ㄦ埛浣欓閫娆捐皟杩欎釜鏂规硶 + */ + void weChatRefund(WeChatRefundDTO dto); + + /** + * 淇濆瓨闈炴硶璁㈠崟璁板綍 + */ + void saveAbnormalOrder(TransactionRecordsData data); + + /** + * 鑾峰彇鍏呯數瀹炴椂鏁版嵁 + * @param orderCode 璁㈠崟缂栧彿 + * @return + */ + List getChargingRealTimeData(String orderCode); + + /** + * 棣栭〉璁㈠崟鏁版嵁灞曠ず + * @param dto 棣栭〉淇℃伅鏌ヨdto + * @return + */ + List getIndexOrderInfo(IndexQueryDTO dto); + + /** + * 鑾峰彇瓒呰繃15鍒嗛挓鐨勫緟鏀粯鐘舵佽鍗 + * @return + */ + List getUnpaidOrderListOver15Min(); + + /** + * 鏍规嵁orderId鎵归噺淇敼璁㈠崟鐘舵 + * @param orderIds + * @param orderStatus + */ + void updateOrderStatusById(List orderIds, String orderStatus); + + /** + * 鏌ヨ鏃堕棿娈靛唴璁㈠崟鎬婚噾棰濆拰鎬荤敤鐢甸噺 + */ + OrderTotalDataVO getOrderTotalData(QueryOrderDTO orderBasicInfo); + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曚俊鎭紙灏忕▼搴忓彂閫佹秷鎭敤锛 + * @param orderCode + * @return + */ + SendMessageVO selectOrderInfoByOrderCode(String orderCode); + + /** + * 鍏呯數妗╁惎鍔ㄥけ璐 + * @param orderCode + * @param failedReasonMsg + */ + void chargingPileFailedToStart(String orderCode, String failedReasonMsg); + + /** + * 鍏呯數妗╁惎鍔ㄦ垚鍔 + * @param orderCode + */ + void chargingPileStartedSuccessfully(String orderCode); + + /** + * 鍏抽棴鍚姩澶辫触鐨勮鍗 + */ + void closeStartFailedOrder(String startTime, String endTime); + + /** + * 涓汉妗╂煡璇㈠厖鐢垫暟鎹 + * @param dto + * @return + */ + List getAccumulativeInfo(QueryPersonPileDTO dto); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderPayRecordService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderPayRecordService.java new file mode 100644 index 000000000..5adad0548 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderPayRecordService.java @@ -0,0 +1,29 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.OrderPayRecord; + +import java.util.List; + +public interface IOrderPayRecordService { + + // int deleteByPrimaryKey(Integer id); + + // int insert(OrderPayRecord record); + + // int insertSelective(OrderPayRecord record); + + // OrderPayRecord selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(OrderPayRecord record); + + // int updateByPrimaryKey(OrderPayRecord record); + + /** + * 鎵归噺淇濆瓨璁㈠崟鏀粯璁板綍 + * @param payRecordList + * @return + */ + int batchInsert(List payRecordList); + + List getOrderPayRecordList(String orderCode); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBasicInfoService.java new file mode 100644 index 000000000..2d5d46967 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBasicInfoService.java @@ -0,0 +1,158 @@ +package com.jsowell.pile.service; + +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.pile.domain.PileBasicInfo; +import com.jsowell.pile.dto.IndexQueryDTO; +import com.jsowell.pile.dto.QueryPileDTO; +import com.jsowell.pile.dto.ReplaceMerchantStationDTO; +import com.jsowell.pile.vo.base.PileInfoVO; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO; +import com.jsowell.pile.vo.web.IndexGeneralSituationVO; +import com.jsowell.pile.vo.web.PileDetailVO; + +import java.util.List; + +/** + * 璁惧绠$悊Service鎺ュ彛 + * + * @author jsowell + * @date 2022-08-26 + */ +public interface IPileBasicInfoService { + /** + * 鏌ヨ璁惧绠$悊 + * + * @param id 璁惧绠$悊涓婚敭 + * @return 璁惧绠$悊 + */ + PileBasicInfo selectPileBasicInfoById(Long id); + + PileBasicInfo selectPileBasicInfoBySN(String pileSn); + + /** + * 鏌ヨ璁惧绠$悊鍒楄〃 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 璁惧绠$悊闆嗗悎 + */ + List selectPileBasicInfoList(PileBasicInfo pileBasicInfo); + + /** + * 鏂板璁惧绠$悊 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 缁撴灉 + */ + int insertPileBasicInfo(PileBasicInfo pileBasicInfo); + + /** + * 淇敼璁惧绠$悊 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 缁撴灉 + */ + int updatePileBasicInfo(PileBasicInfo pileBasicInfo); + + /** + * 鎵归噺鍒犻櫎璁惧绠$悊 + * + * @param ids 闇瑕佸垹闄ょ殑璁惧绠$悊涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + int deletePileBasicInfoByIds(Long[] ids); + + /** + * 鍒犻櫎璁惧绠$悊淇℃伅 + * + * @param id 璁惧绠$悊涓婚敭 + * @return 缁撴灉 + */ + int deletePileBasicInfoById(Long id); + + /** + * 鏌ヨ鍒楄〃 + */ + List queryPileInfos(QueryPileDTO dto); + + List queryPileInfoList(QueryPileDTO queryPileDTO); + + /** + * 閫氳繃pileId鏇存敼杩愯惀鍟嗐佺珯鐐逛俊鎭 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 缁撴灉 + */ + int replaceMerchantStationByPileIds(ReplaceMerchantStationDTO dto); + + /** + * 閫氳繃妗﹊d鏌ヨbasic淇℃伅 + * + * @param id 妗﹊d + * @return 缁撴灉闆嗗悎 + */ + PileDetailVO selectBasicInfoById(Long id); + + PileInfoVO selectPileInfoBySn(String pileSn); + + /** + * 閫氳繃绔欑偣id鏌ヨ妗╅泦鍚 + * + * @param stationIdList 绔欑偣id + * @return 妗╅泦鍚 + */ + List selectPileListByStationIds(List stationIdList); + + /** + * 閫氳繃妗╃紪鍙锋煡璇㈢珯鐐筰d + * @param sn 妗╃紪鍙 + * @return 绔欑偣id + */ + // String selectStationIdBySn(String sn); + + /** + * uniApp閫氳繃妗╁彿鏌ヨ妗╄鎯 + * @param pileSn 妗╁彿 + * @return + */ + // PileDetailVO uniAppGetPileDetailByPileSn(String pileSn); + + /** + * 淇敼鐘舵 + * @param frameType + * @param pileSn + * @param connectorCode + * @param status + * @param putGunType + */ + void updateStatus(String frameType, String pileSn, String connectorCode, String status, String putGunType); + + /** + * 鍏呯數鏃朵繚瀛樺疄鏃舵暟鎹埌redis + * @param realTimeMonitorData 瀹炴椂鏁版嵁 + */ + void saveRealTimeMonitorData2Redis(RealTimeMonitorData realTimeMonitorData); + + PileConnectorDetailVO queryPileConnectorDetail(String pileConnectorCode); + + String getPileQrCodeUrl(String pileSn); + + // 鏇存柊鍏呯數妗╃殑sim鍗′俊鎭 + void updatePileSimInfo(String pileSn, String iccid); + + + /** + * 鍚庣棣栭〉鍩烘湰淇℃伅鏌ヨ + * + * @param dto 绔欑偣Id + * @return 棣栭〉鍩烘湰淇℃伅 + */ + public IndexGeneralSituationVO getGeneralSituation(IndexQueryDTO dto); + + /** + * 閫氳繃浼氬憳id鏌ヨ涓汉妗╁垪琛 + * @param memberId + * @return + */ + List getPileInfoByMemberId(String memberId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBillingTemplateService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBillingTemplateService.java new file mode 100644 index 000000000..380072c96 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBillingTemplateService.java @@ -0,0 +1,152 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.PileBillingRelation; +import com.jsowell.pile.domain.PileBillingTemplate; +import com.jsowell.pile.dto.CreateOrUpdateBillingTemplateDTO; +import com.jsowell.pile.dto.ImportBillingTemplateDTO; +import com.jsowell.pile.vo.uniapp.BillingPriceVO; +import com.jsowell.pile.vo.uniapp.CurrentTimePriceDetails; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import com.jsowell.pile.vo.web.EchoBillingTemplateVO; + +import java.util.List; + +/** + * 璁¤垂妯℃澘Service鎺ュ彛 + * + * @author jsowell + * @date 2022-09-20 + */ +public interface IPileBillingTemplateService { + /** + * 鏌ヨ璁¤垂妯℃澘 + * + * @param id 璁¤垂妯℃澘涓婚敭 + * @return 璁¤垂妯℃澘 + */ + public PileBillingTemplate selectPileBillingTemplateById(Long id); + + /** + * 鏌ヨ璁¤垂妯℃澘鍒楄〃 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 璁¤垂妯℃澘闆嗗悎 + */ + public List selectPileBillingTemplateList(PileBillingTemplate pileBillingTemplate); + + /** + * 鏂板璁¤垂妯℃澘 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 缁撴灉 + */ + public int insertPileBillingTemplate(PileBillingTemplate pileBillingTemplate); + + /** + * 淇敼璁¤垂妯℃澘 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 缁撴灉 + */ + public int updatePileBillingTemplate(PileBillingTemplate pileBillingTemplate); + + /** + * 鎵归噺鍒犻櫎璁¤垂妯℃澘 + * + * @param ids 闇瑕佸垹闄ょ殑璁¤垂妯℃澘涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileBillingTemplateByIds(Long[] ids); + + /** + * 鍒犻櫎璁¤垂妯℃澘淇℃伅 + * + * @param id 璁¤垂妯℃澘涓婚敭 + * @return 缁撴灉 + */ + public int deletePileBillingTemplateById(Long id); + + /** + * 鏂板璁¤垂妯℃澘 + * + * @param dto 鍙傛暟 + * @return 璁¤垂妯℃澘id + */ + void createBillingTemplate(CreateOrUpdateBillingTemplateDTO dto); + + /** + * 鏌ヨ鍏叡璁¤垂妯℃澘 + * + * @return + */ + List queryPublicBillingTemplateList(); + + /** + * 鏌ヨ绔欑偣璁¤垂妯℃澘 + * + * @param stationId 绔欑偣id + * @return + */ + List queryStationBillingTemplateList(String stationId); + + /** + * 鏌ヨ姝e湪浣跨敤涓殑璁¤垂妯℃澘 + * @param stationId 绔欑偣id + * @return + */ + BillingTemplateVO queryUsedBillingTemplate(String stationId); + + /** + * 鏌ヨ璁¤垂浠锋牸璇︽儏 + * @param stationId 绔欑偣id + * @return + */ + List queryBillingPrice(String stationId); + + /** + * 閫氳繃妗﹕n鍙锋煡璇㈣璐规ā鏉夸俊鎭 + * + * @param pileSn 妗﹕n + * @return 璁¤垂妯℃澘缂栧彿 + */ + BillingTemplateVO selectBillingTemplateDetailByPileSn(String pileSn); + + /** + * 绔欑偣瀵煎叆璁¤垂妯℃澘 + * + * @param dto + * @return + */ + boolean stationImportBillingTemplate(ImportBillingTemplateDTO dto); + + byte[] generateBillingTemplateMsgBody(String pileSn, BillingTemplateVO billingTemplateVO); + + /** + * 鏍规嵁璁¤垂妯℃澘id鏌ヨ璁¤垂妯℃澘淇℃伅 + * + * @param templateId 璁¤垂妯℃澘id + * @return 璁¤垂妯℃澘淇℃伅 + */ + BillingTemplateVO selectBillingTemplateByTemplateId(String templateId); + + /** + * 淇濆瓨璁¤垂妯℃澘鍜屾々鍏崇郴 + * + * @param relationList + */ + void insertPileBillingRelation(List relationList); + + /** + * 淇敼璁¤垂妯℃澘 + * + * @param dto + */ + void updateBillingTemplate(CreateOrUpdateBillingTemplateDTO dto); + + EchoBillingTemplateVO queryPileBillingTemplateById(Long id); + + /** + * 閫氳繃绔欑偣id鏌ヨ褰撳墠鏃堕棿鐨勬敹璐硅鎯 + */ + CurrentTimePriceDetails getCurrentTimePriceDetails(String stationId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileConnectorInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileConnectorInfoService.java new file mode 100644 index 000000000..20f1fe669 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileConnectorInfoService.java @@ -0,0 +1,133 @@ +package com.jsowell.pile.service; + +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.pile.domain.PileConnectorInfo; +import com.jsowell.pile.dto.QueryConnectorDTO; +import com.jsowell.pile.dto.QueryConnectorListDTO; +import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; + +import java.util.List; +import java.util.Map; + +/** + * 鍏呯數妗╂灙鍙d俊鎭疭ervice鎺ュ彛 + * + * @author jsowell + * @date 2022-08-31 + */ +public interface IPileConnectorInfoService { + /** + * 鏌ヨ鍏呯數妗╂灙鍙d俊鎭 + * + * @param id 鍏呯數妗╂灙鍙d俊鎭富閿 + * @return 鍏呯數妗╂灙鍙d俊鎭 + */ + PileConnectorInfo selectPileConnectorInfoById(Integer id); + + /** + * 鏌ヨ鍏呯數妗╂灙鍙d俊鎭垪琛 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 鍏呯數妗╂灙鍙d俊鎭泦鍚 + */ + List selectPileConnectorInfoList(PileConnectorInfo pileConnectorInfo); + + List selectPileConnectorInfoList(String pileSn); + + /** + * 鏂板鍏呯數妗╂灙鍙d俊鎭 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 缁撴灉 + */ + // int insertPileConnectorInfo(PileConnectorInfo pileConnectorInfo); + + /** + * 淇敼鍏呯數妗╂灙鍙d俊鎭 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 缁撴灉 + */ + // int updatePileConnectorInfo(PileConnectorInfo pileConnectorInfo); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╂灙鍙d俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗╂灙鍙d俊鎭富閿泦鍚 + * @return 缁撴灉 + */ + // int deletePileConnectorInfoByIds(Integer[] ids); + + int deletePileConnectorInfoByPileSnList(List pileSnList); + + int batchInsertConnectorInfo(List pileConnectorInfoList); + + /** + * 鍏呯數鎺ュ彛淇℃伅鍒楄〃 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 鍏呯數鎺ュ彛瀵硅薄闆嗗悎 + */ + List getConnectorInfoListByParams(QueryConnectorDTO dto); + + /** + * 閫氳繃鍏呯數绔檌d鏌ヨ鍏呯數鏋俊鎭 + * + * @param stationId 鍏呯數绔檌d + * @return 鍏呯數鏋俊鎭泦鍚 + */ + List selectConnectorListByStationId(Long stationId); + + /** + * 鏀寔澶氱鏌ヨ鍏呯數妗╂帴鍙e垪琛 + */ + List getConnectorInfoListByParams(QueryConnectorListDTO dto); + + /** + * 鏇存柊鍏呯數妗╂灙鍙g姸鎬 + * @param connectorCode 鏋彛鍙 + * @param status 鐘舵 0锛氱缃 (榛樿)锛1锛氱┖闂诧紱2锛氬崰鐢紙鏈厖鐢碉級锛3锛氬崰鐢紙鍏呯數涓級锛4锛氬崰鐢紙棰勭害閿佸畾锛 锛255锛氭晠闅 + */ + int updateConnectorStatus(String connectorCode, String status); + + /** + * 閫氳繃妗╃紪鍙蜂慨鏀规灙鍙g姸鎬 + * 浠呯敤浜庣櫥褰曢昏緫浣跨敤 + * @param pileSn 妗╃紪鍙 + * @param status 鐘舵 鐘舵 0锛氱缃 (榛樿)锛1锛氱┖闂诧紱2锛氬崰鐢紙鏈厖鐢碉級锛3锛氬崰鐢紙鍏呯數涓級锛4锛氬崰鐢紙棰勭害閿佸畾锛 锛255锛氭晠闅 + */ + int updateConnectorStatusByPileSn(String pileSn, String status); + + /** + * 鎵归噺鑾峰彇鍏呯數妗╃姸鎬 + * @param pileSnList 妗╃紪鍙穕ist + * @return key:妗╃紪鍙凤紱value:鐘舵佸 + */ + Map getPileStatus(List pileSnList); + + /** + * 閫氳繃鏋彛缂栫爜鏌ヨ鏋彛淇℃伅 + * + * @param connectorCode + * @return + */ + PileConnectorInfoVO getPileConnectorInfoByConnectorCode(String connectorCode); + + String getPileConnectorQrCodeUrl(String pileConnectorCode); + + /** + * 鏀寔澶氱鏌ヨ鍏呯數妗╂帴鍙e垪琛紙uniapp锛 + */ + PageResponse getUniAppConnectorInfoListByParams(QueryConnectorListDTO dto); + + /** + * uniApp閫氳繃绔欑偣id鏌ヨ鏋彛鍒楄〃淇℃伅 + * + * @param stationId 绔欑偣id + * @return + */ + List getUniAppConnectorList(Long stationId); + + List selectConnectorInfoList(String pileSn); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileLicenceInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileLicenceInfoService.java new file mode 100644 index 000000000..5e7eec071 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileLicenceInfoService.java @@ -0,0 +1,62 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.PileLicenceInfo; + +import java.util.List; + +/** + * 鍏呯數妗╄瘉涔︿俊鎭疭ervice鎺ュ彛 + * + * @author jsowell + * @date 2022-08-27 + */ +public interface IPileLicenceInfoService +{ + /** + * 鏌ヨ鍏呯數妗╄瘉涔︿俊鎭 + * + * @param id 鍏呯數妗╄瘉涔︿俊鎭富閿 + * @return 鍏呯數妗╄瘉涔︿俊鎭 + */ + public PileLicenceInfo selectPileLicenceInfoById(Long id); + + /** + * 鏌ヨ鍏呯數妗╄瘉涔︿俊鎭垪琛 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 鍏呯數妗╄瘉涔︿俊鎭泦鍚 + */ + public List selectPileLicenceInfoList(PileLicenceInfo pileLicenceInfo); + + /** + * 鏂板鍏呯數妗╄瘉涔︿俊鎭 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 缁撴灉 + */ + public int insertPileLicenceInfo(PileLicenceInfo pileLicenceInfo); + + /** + * 淇敼鍏呯數妗╄瘉涔︿俊鎭 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 缁撴灉 + */ + public int updatePileLicenceInfo(PileLicenceInfo pileLicenceInfo); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╄瘉涔︿俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗╄瘉涔︿俊鎭富閿泦鍚 + * @return 缁撴灉 + */ + public int deletePileLicenceInfoByIds(Long[] ids); + + /** + * 鍒犻櫎鍏呯數妗╄瘉涔︿俊鎭俊鎭 + * + * @param id 鍏呯數妗╄瘉涔︿俊鎭富閿 + * @return 缁撴灉 + */ + public int deletePileLicenceInfoById(Long id); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMemberRelationService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMemberRelationService.java new file mode 100644 index 000000000..53a653737 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMemberRelationService.java @@ -0,0 +1,79 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.PileMemberRelation; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; + +import java.util.List; + +/** + * 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴Service鎺ュ彛 + * + * @author jsowell + * @date 2023-02-21 + */ +public interface IPileMemberRelationService +{ + /** + * 鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param id 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴涓婚敭 + * @return 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + */ + public PileMemberRelation selectPileMemberRelationById(Integer id); + + /** + * 鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴鍒楄〃 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴闆嗗悎 + */ + public List selectPileMemberRelationList(PileMemberRelation pileMemberRelation); + + /** + * 鏉′欢鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴瀵硅薄 + */ + PileMemberRelation selectPileMemberRelation(PileMemberRelation pileMemberRelation); + + /** + * 鏂板妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 缁撴灉 + */ + public int insertPileMemberRelation(PileMemberRelation pileMemberRelation); + + /** + * 淇敼妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 缁撴灉 + */ + public int updatePileMemberRelation(PileMemberRelation pileMemberRelation); + + /** + * 鎵归噺鍒犻櫎妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param ids 闇瑕佸垹闄ょ殑妗╀笌鐢ㄦ埛缁戝畾鍏崇郴涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileMemberRelationByIds(Integer[] ids); + + /** + * 鍒犻櫎妗╀笌鐢ㄦ埛缁戝畾鍏崇郴淇℃伅 + * + * @param id 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴涓婚敭 + * @return 缁撴灉 + */ + public int deletePileMemberRelationById(Integer id); + + /** + * 閫氳繃妗╃紪鐮佹煡璇㈠叧绯讳俊鎭 + * @param pileSn + * @return + */ + List selectPileMemberRelationByPileSn(String pileSn); + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMerchantInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMerchantInfoService.java new file mode 100644 index 000000000..4a2279710 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMerchantInfoService.java @@ -0,0 +1,66 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.PileMerchantInfo; +import com.jsowell.pile.vo.base.MerchantInfoVO; + +import java.util.List; + +/** + * 鍏呯數妗╄繍钀ュ晢淇℃伅Service鎺ュ彛 + * + * @author jsowell + * @date 2022-08-27 + */ +public interface IPileMerchantInfoService { + /** + * 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param id 鍏呯數妗╄繍钀ュ晢淇℃伅涓婚敭 + * @return 鍏呯數妗╄繍钀ュ晢淇℃伅 + */ + public PileMerchantInfo selectPileMerchantInfoById(Long id); + + /** + * 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅鍒楄〃 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 鍏呯數妗╄繍钀ュ晢淇℃伅闆嗗悎 + */ + public List selectPileMerchantInfoList(PileMerchantInfo pileMerchantInfo); + + /** + * 鏂板鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 缁撴灉 + */ + public int insertPileMerchantInfo(PileMerchantInfo pileMerchantInfo); + + /** + * 淇敼鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 缁撴灉 + */ + public int updatePileMerchantInfo(PileMerchantInfo pileMerchantInfo); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗╄繍钀ュ晢淇℃伅涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deletePileMerchantInfoByIds(Long[] ids); + + /** + * 鍒犻櫎鍏呯數妗╄繍钀ュ晢淇℃伅淇℃伅 + * + * @param id 鍏呯數妗╄繍钀ュ晢淇℃伅涓婚敭 + * @return 缁撴灉 + */ + public int deletePileMerchantInfoById(Long id); + + String getMerchantIdByAppId(String appId); + + MerchantInfoVO getMerchantInfo(String merchantId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileModelInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileModelInfoService.java new file mode 100644 index 000000000..fbfc7c220 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileModelInfoService.java @@ -0,0 +1,72 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.PileModelInfo; +import com.jsowell.pile.vo.web.PileModelInfoVO; + +import java.util.List; + +/** + * 鍏呯數妗╁瀷鍙蜂俊鎭疭ervice鎺ュ彛 + * + * @author jsowell + * @date 2022-08-26 + */ +public interface IPileModelInfoService { + /** + * 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param id 鍏呯數妗╁瀷鍙蜂俊鎭富閿 + * @return 鍏呯數妗╁瀷鍙蜂俊鎭 + */ + public PileModelInfo selectPileModelInfoById(Long id); + + /** + * 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭垪琛 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 鍏呯數妗╁瀷鍙蜂俊鎭泦鍚 + */ + public List selectPileModelInfoList(PileModelInfo pileModelInfo); + + /** + * 鏂板鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 缁撴灉 + */ + public int insertPileModelInfo(PileModelInfo pileModelInfo); + + /** + * 淇敼鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 缁撴灉 + */ + public int updatePileModelInfo(PileModelInfo pileModelInfo); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗╁瀷鍙蜂俊鎭富閿泦鍚 + * @return 缁撴灉 + */ + public int deletePileModelInfoByIds(Long[] ids); + + /** + * 鍒犻櫎鍏呯數妗╁瀷鍙蜂俊鎭俊鎭 + * + * @param id 鍏呯數妗╁瀷鍙蜂俊鎭富閿 + * @return 缁撴灉 + */ + public int deletePileModelInfoById(Long id); + + /** + * 閫氳繃妗╃紪鍙烽泦鍚堣幏鍙栧瀷鍙疯〃涓暟鎹 + * + * @param pileSns 妗╃紪鍙烽泦鍚 + * @return PileModelInfo瀵硅薄 + */ + List getPileModelInfoByPileSnList(List pileSns); + + PileModelInfoVO getPileModelInfoByPileSn(String pileSn); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMsgRecordService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMsgRecordService.java new file mode 100644 index 000000000..31b43e810 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileMsgRecordService.java @@ -0,0 +1,24 @@ +package com.jsowell.pile.service; + +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.pile.dto.QueryPileDTO; + +public interface IPileMsgRecordService { + + /** + * 淇濆瓨鎶ユ枃 + * @param pileSn 妗╃紪鍙 + * @param connectorCode 鏋彿 + * @param frameType 甯х被鍨 + * @param jsonMsg msgBody鐨刯son瀛楃涓 + * @param originalMsg 鍘熷鎶ユ枃 + */ + void save(String pileSn, String connectorCode, String frameType, String jsonMsg, String originalMsg); + + // List getByConnectorCodeList(List connectorCodeList); + + /** + * 鏌ヨ鍏呯數妗╅氫俊鏃ュ織 鍒嗛〉 + */ + PageResponse getPileFeedList(QueryPileDTO dto); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileSimInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileSimInfoService.java new file mode 100644 index 000000000..ace0b4a0e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileSimInfoService.java @@ -0,0 +1,92 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.PileSimInfo; +import com.jsowell.pile.dto.QuerySimInfoDTO; +import com.jsowell.pile.vo.web.SimCardInfoVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 鍏呯數妗㏒IM鍗′俊鎭疭ervice鎺ュ彛 + * + * @author jsowell + * @date 2022-08-26 + */ +public interface IPileSimInfoService +{ + /** + * 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭 + * + * @param id 鍏呯數妗㏒IM鍗′俊鎭富閿 + * @return 鍏呯數妗㏒IM鍗′俊鎭 + */ + public PileSimInfo selectPileSimInfoById(Long id); + + /** + * 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭垪琛 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 鍏呯數妗㏒IM鍗′俊鎭泦鍚 + */ + public List selectPileSimInfoList(PileSimInfo pileSimInfo); + + /** + * 鍚庣鏌ヨsim鍗′俊鎭垪琛 + * @return + */ + List getSimInfoList(QuerySimInfoDTO dto); + + /** + * 鏂板鍏呯數妗㏒IM鍗′俊鎭 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 缁撴灉 + */ + public int insertPileSimInfo(PileSimInfo pileSimInfo); + + /** + * 淇敼鍏呯數妗㏒IM鍗′俊鎭 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 缁撴灉 + */ + public int updatePileSimInfo(PileSimInfo pileSimInfo); + + /** + * 鎵归噺鍒犻櫎鍏呯數妗㏒IM鍗′俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗㏒IM鍗′俊鎭富閿泦鍚 + * @return 缁撴灉 + */ + public int deletePileSimInfoByIds(Long[] ids); + + /** + * 鍒犻櫎鍏呯數妗㏒IM鍗′俊鎭俊鎭 + * + * @param id 鍏呯數妗㏒IM鍗′俊鎭富閿 + * @return 缁撴灉 + */ + public int deletePileSimInfoById(Long id); + + /** + * 閫氳繃妗╃紪鐮佹煡璇im鍗′俊鎭 + * @param pileSn 妗╃紪鐮 + * @return + */ + SimCardInfoVO querySimCardInfoByPileSn(String pileSn); + + /** + * 閫氳繃鍗″彿鎵归噺鏌ヨsim鍗′俊鎭 + * @param iccIds 鍗″彿 + * @return + */ + List selectSimInfoByIccIds(List iccIds); + + /** + * 閫氳繃鍗″彿鏌ヨsim鍗′俊鎭 + * @param iccId 鍗″彿 + * @return + */ + PileSimInfo getBasicInfoByIccId(String iccId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileStationInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileStationInfoService.java new file mode 100644 index 000000000..03541046a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileStationInfoService.java @@ -0,0 +1,91 @@ +package com.jsowell.pile.service; + +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.pile.domain.PileStationInfo; +import com.jsowell.pile.dto.FastCreateStationDTO; +import com.jsowell.pile.dto.QueryStationDTO; +import com.jsowell.pile.vo.web.PileStationVO; + +import java.util.List; + +/** + * 鍏呯數绔欎俊鎭疭ervice鎺ュ彛 + * + * @author jsowell + * @date 2022-08-30 + */ +public interface IPileStationInfoService { + /** + * 鏌ヨ鍏呯數绔欎俊鎭 + * + * @param id 鍏呯數绔欎俊鎭富閿 + * @return 鍏呯數绔欎俊鎭 + */ + public PileStationInfo selectPileStationInfoById(Long id); + + /** + * 鏌ヨ鍏呯數绔欎俊鎭垪琛 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 鍏呯數绔欎俊鎭泦鍚 + */ + public List selectPileStationInfoList(PileStationInfo pileStationInfo); + + /** + * 閫氳繃杩愯惀鍟唅d鏌ヨ绔欑偣淇℃伅 + * + * @param merchantId 杩愯惀鍟唅d + * @return 绔欑偣淇℃伅鍒楄〃 + */ + public List selectStationListByMerchantId(Long merchantId); + + /** + * 鏂板鍏呯數绔欎俊鎭 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 缁撴灉 + */ + public int insertPileStationInfo(PileStationInfo pileStationInfo); + + /** + * 蹇熷缓绔 + * + * @param dto + * @return + */ + public int fastCreateStation(FastCreateStationDTO dto); + + /** + * 淇敼鍏呯數绔欎俊鎭 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 缁撴灉 + */ + public int updatePileStationInfo(PileStationInfo pileStationInfo); + + /** + * 鎵归噺鍒犻櫎鍏呯數绔欎俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數绔欎俊鎭富閿泦鍚 + * @return 缁撴灉 + */ + public int deletePileStationInfoByIds(Long[] ids); + + /** + * 鏌ヨ鍏呯數绔欎俊鎭 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 鍏呯數绔欎俊鎭泦鍚 + */ + List queryStationInfos(QueryStationDTO dto); + + /** + * 鏌ヨ鍏呯數绔欎俊鎭苟閫氳繃缁忕含搴﹁窛绂绘帓搴 + * + * @param queryStationDTO 鍓嶅彴鍙傛暟 + * @return 鍏呯數绔欏璞¢泦鍚 + */ + PageResponse uniAppQueryStationInfoList(QueryStationDTO queryStationDTO); + + PileStationVO getStationInfo(String stationId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/SimCardService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/SimCardService.java new file mode 100644 index 000000000..1ae56dd9f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/SimCardService.java @@ -0,0 +1,468 @@ +package com.jsowell.pile.service; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.Lists; +import com.jsowell.common.enums.sim.SimCardStatusCorrespondEnum; +import com.jsowell.common.enums.sim.SimSupplierEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.RandomUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.http.HttpUtils; +import com.jsowell.common.util.id.IdUtils; +import com.jsowell.common.util.sim.SimCardUtils; +import com.jsowell.common.util.sim.XunZhongSimUtils; +import com.jsowell.pile.vo.web.*; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.stream.Collectors; + + +/** + * Sim鍗ervice + * + * @author JS-ZZA + * @date 2022/12/3 15:35 + */ +@Service +public class SimCardService { + + @Autowired + private IPileSimInfoService pileSimInfoService; + + protected final Logger logger = LoggerFactory.getLogger(SimCardService.class); + + @Value("${xunzhong.apiId}") + private String API_ID; + + @Value("${xunzhong.sim.getSimCardDetailURL}") + private String getSimCardDetailURL; + + @Value("${xunzhong.trafficPool.poolListURL}") + private String poolListURL; + + @Value("${xunzhong.sim.renewURL}") + private String renewURL; + + @Value("${wulian.appId}") + private String appId; + + @Value("${wulian.appSecret}") + private String appSecret; + + @Value("${wulian.getWay}") + private String wuLianGetWay; + + @Value("${wulian.name.getSimInfo}") + private String getSimInfoName; + + @Value("${wulian.name.WuLianSimRenew}") + private String WuLianSimRenew; + + /** + * 涓嶇煡閬搃ccid灞炰簬鍝渚涘簲鍟嗭紝灏辩敤杩欎釜鏂规硶鏌 + * @param iccid + * @return + */ + public SimCardVO searchByLoop(String iccid) { + SimCardVO vo = null; + // 鏌unZhong + List simCardVOS = XunZhongGetSimInfoByIccIds(Lists.newArrayList(iccid)); + if (CollectionUtils.isNotEmpty(simCardVOS)) { + vo = simCardVOS.get(0); + } + // 鏌uLian骞冲彴 + List wuLianSimData = WuLianGetSimInfoByIccIds(Lists.newArrayList(iccid)); + if (CollectionUtils.isNotEmpty(wuLianSimData)) { + vo = wuLianSimData.get(0); + } + // 绗笁涓緵搴斿晢 + + logger.info("鏌ヨiccid:{}, 璇︽儏淇℃伅:{}", iccid, JSON.toJSONString(vo)); + return vo; + } + + /** + * 鎵归噺缁垂锛堝悗绠¤皟鐢ㄦ鏂规硶锛 + * @param iccIds 鍗″彿 + * @param cycleNumber 缁垂鍛ㄦ湡 + */ + public List renewSimByLoop(List iccIds, int cycleNumber) { + if (CollectionUtils.isEmpty(iccIds)) { + return Lists.newArrayList(); + } + // 灏嗛泦鍚堜腑涓虹┖鍜0鐨勮繃婊 + iccIds = iccIds.stream() + .filter(StringUtils::isNotEmpty) + .filter(x -> !StringUtils.equals(x, "0")) + .collect(Collectors.toList()); + + ArrayList list = new ArrayList<>(); + for (String iccId : iccIds) { + // 鏌ュ嚭姝ゅ崱灞炰簬鍝鍏徃(鎷垮埌code) + SimCardVO simCardVO = searchByLoop(iccId); + String simSupplierCode = simCardVO.getSimCardFactory(); + + // 鏍规嵁涓嶅悓鐨勫叕鍙告墽琛屼笉鍚岀殑缁垂鏂规硶 + SimRenewResultVO simRenewResultVO = renewSimBySupplier(simSupplierCode, iccId, cycleNumber); + list.add(simRenewResultVO); + } + return list; + } + + + /** + * 鏍规嵁涓嶅悓鐨勫叕鍙告墽琛屼笉鍚岀殑缁垂鏂规硶 + * @param code SimSupplierEnum.getCode() + * @param iccId 鍗″彿 + * @param cycleNumber 缁垂鍛ㄦ湡 + */ + private SimRenewResultVO renewSimBySupplier(String code, String iccId, int cycleNumber) { + SimRenewResultVO vo = new SimRenewResultVO(); + vo.setIccId(iccId); + vo.setCycleNumber(cycleNumber); + + if (StringUtils.equals(code, SimSupplierEnum.XUN_ZHONG.getCode())) { + // 璁紬 + try { + vo.setSimSuppler(SimSupplierEnum.XUN_ZHONG.getName()); + XunZhongSimRenewal(Lists.newArrayList(iccId), cycleNumber); + vo.setResult(true); + }catch (BusinessException e) { + vo.setResult(false); + vo.setReason(e.getMessage()); + } + } + // 鐗╄仈骞冲彴 + if (StringUtils.equals(code, SimSupplierEnum.WU_LIAN_INTERNET.getCode())) { + try { + vo.setSimSuppler(SimSupplierEnum.WU_LIAN_INTERNET.getName()); + WuLianSimRenew(Lists.newArrayList(iccId), cycleNumber); + vo.setResult(true); + }catch (BusinessException e){ + vo.setResult(false); + vo.setReason(e.getMessage()); + } + } + return vo; + } + + + + /** + * 璁紬 鍐呴儴鎺ュ彛 + * 閫氳繃iccIds鏌ヨ璁紬Sim鍗′俊鎭 + * @param iccIds + */ + public List XunZhongGetSimInfoByIccIds(List iccIds) { + List resultList = new ArrayList<>(); + + List dataList = getSimCardDetail(iccIds); + SimCardVO simCard = null; + for (XunZhongSimData zhongSimData : dataList) { + // sim鍗″椁 + XunZhongSimData.Products products = null; + if (CollectionUtils.isNotEmpty(zhongSimData.getCurrent_products())) { + products = zhongSimData.getCurrent_products().get(0); + } else { + if (CollectionUtils.isNotEmpty(zhongSimData.getFuture_products())) { + products = zhongSimData.getFuture_products().get(0); + } + } + if (products == null) { + logger.info("iccid:{}, 娌℃湁濂楅", zhongSimData.getIccid()); + continue; + } + // set + simCard = new SimCardVO(); + simCard.setIccId(zhongSimData.getIccid()); // 鍗″彿 + simCard.setSimCardFactory(SimSupplierEnum.XUN_ZHONG.getCode()); // 1-璁紬鐗╄仈 + simCard.setSimCardOperator(zhongSimData.getCarrier_type()); // 杩愯惀鍟嗙被鍨 + simCard.setSimCardStatus(zhongSimData.getNet_status()); // 鑱旂綉鐘舵 + simCard.setName(products.getName()); // 濂楅鍚嶇О + simCard.setExpiredTime(products.getExpiration_time()); // 杩囨湡鏃堕棿 + + BigDecimal packageCapacity = products.getPackage_capacity(); // 濂楅鎬婚噺锛坢b锛 + simCard.setPackageCapacity(packageCapacity); + + if (products.getCurrent_cycle_usage() != null) { + BigDecimal current_cycle_usage = products.getCurrent_cycle_usage(); // 褰撳墠宸茬敤锛坘b锛 + String currentCycleUsage = SimCardUtils.kb2MbOrGb(current_cycle_usage.intValue()); + BigDecimal currentCycleUsageData = new BigDecimal(currentCycleUsage); + simCard.setUsedFlowRate(currentCycleUsageData); + BigDecimal residualData = packageCapacity.subtract(currentCycleUsageData); // 濂楅鍓╀綑 + simCard.setResidualFlowRate(residualData.setScale(2, BigDecimal.ROUND_HALF_UP)); + } + + resultList.add(simCard); + } + return resultList; + } + + public static void main(String[] args) { + // List iccIds = Lists.newArrayList(); + // iccIds.add("123"); + // iccIds.add(null); + // iccIds.add("0"); + // iccIds.add("asdf"); + // iccIds.add(null); + // iccIds.add("0"); + // iccIds.add(null); + // iccIds.add("0"); + // iccIds.add("9461351351"); + // iccIds = iccIds.stream() + // .filter(StringUtils::isNotEmpty) + // .filter(x -> !StringUtils.equals(x, "0")) + // .collect(Collectors.toList()); + // String iccId = StringUtils.join(iccIds, ","); + // System.out.println(iccId); + + + String packName = "绉诲姩 500M/鏈"; + System.out.println(StringUtils.contains(packName, "绉诲姩")); + // StringUtils.containsAny() + } + + + /** + * 璁紬瀹樻柟鎺ュ彛 + * 鑾峰彇sim鍗¤缁嗕俊鎭 + * @param iccIds Sim鍗¢泦鍚 + * @return + */ + public List getSimCardDetail(List iccIds) { + String iccId = list2Str(iccIds); + + String timestamp = String.valueOf(System.currentTimeMillis() / 1000); + + Hashtable params = new Hashtable<>(); + params.put("api_id", API_ID); + params.put("timestamp", timestamp); + params.put("iccids", iccId); + + String signStr = XunZhongSimUtils.getSignStr(params); + + params.put("sign", signStr); + + String postResult = XunZhongSimUtils.sendPost(getSimCardDetailURL, params); + logger.info("銆====璁紬鐗╄仈====銆戞煡璇im鍗′俊鎭, param:{}, result:{}", params, postResult); + JSONObject jsonObject = JSONObject.parseObject(postResult); + if (StringUtils.equals(jsonObject.getString("code"), "0")) { + String result = jsonObject.getString("result"); + return JSON.parseArray(result, XunZhongSimData.class); + } + return Lists.newArrayList(); + } + + /** + * 璁紬瀹樻柟鎺ュ彛 + * 鑾峰彇娴侀噺姹犱俊鎭 + * @return + */ + public String getTrafficPoolInfo() { + String timestamp = String.valueOf(System.currentTimeMillis() / 1000); + + Hashtable params = new Hashtable<>(); + params.put("api_id", API_ID); + params.put("timestamp", timestamp); + + String signStr = XunZhongSimUtils.getSignStr(params); + params.put("sign", signStr); + + String postResult = XunZhongSimUtils.sendPost(poolListURL, params); + logger.info("銆====璁紬鐗╄仈====銆戣幏鍙栨祦閲忔睜淇℃伅, result:{}", postResult); + return postResult; + } + + + /** + * 璁紬瀹樻柟鎺ュ彛 + * sim鍗$画鏈 + * @param iccIds 闇瑕佺画鏈熺殑sim鍗 + * @param cycleNumber 缁垂鍛ㄦ湡锛0-999锛夛紝0琛ㄧず鏃犻檺鍛ㄦ湡 + * @return + */ + public void XunZhongSimRenewal(List iccIds, int cycleNumber) { + if (CollectionUtils.isEmpty(iccIds)) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + String iccId = list2Str(iccIds); + + String timestamp = String.valueOf(System.currentTimeMillis() / 1000); + + Hashtable params = new Hashtable<>(); + params.put("api_id", API_ID); + params.put("timestamp", timestamp); + params.put("iccids", iccId); + params.put("cycle_number", cycleNumber); + + String signStr = XunZhongSimUtils.getSignStr(params); + + params.put("sign", signStr); + + String postResult = XunZhongSimUtils.sendPost(renewURL, params); + logger.info("銆====璁紬鐗╄仈====銆憇im鍗$画璐逛笟鍔, result:{}", postResult); + JSONObject jsonResult = JSONObject.parseObject(postResult); + String code = jsonResult.getString("code"); + if (!StringUtils.equals("0", code)) { + String message = jsonResult.getString("message"); + throw new BusinessException(code, message); + } + } + + + /** + * 鐗╄仈骞冲彴瀹樻柟鎺ュ彛 + * + * 鏌ヨ鍗′俊鎭 + * + * @param iccIds 鍗″彿闆嗗悎 + * @return 鍗′俊鎭泦鍚 + */ + public List WuLianGetSimInfo(List iccIds) { + ArrayList list = new ArrayList<>(); + + if (CollectionUtils.isEmpty(iccIds)) { + return list; + } + for (String iccId : iccIds) { + JSONObject param = new JSONObject(); + param.put("appid", appId); + param.put("appsecret", appSecret); + param.put("name", getSimInfoName); + param.put("iccid", iccId); + + String result = HttpUtils.sendPostContentType(wuLianGetWay, param.toJSONString(), "application/json"); + logger.info("銆====鐗╄仈缃戞櫤鑳戒簯骞冲彴====銆戞煡璇im鍗′俊鎭, result: {}", result); + + JSONObject jsonObject = JSONObject.parseObject(result); + JSONArray dataArray = (JSONArray) jsonObject.get("data"); + + if (CollectionUtils.isNotEmpty(dataArray)) { + JSONObject data = dataArray.getJSONObject(0); + WuLianSimData wuLianSimData = JSONObject.parseObject(data.toJSONString(), WuLianSimData.class); + + list.add(wuLianSimData); + } + } + return list; + } + + + /** + * 鐗╄仈骞冲彴 鍐呴儴鎺ュ彛 + * 閫氳繃iccIds鏌ヨ鐗╄仈骞冲彴Sim鍗′俊鎭 + * + * @param iccIds + * @return + */ + public List WuLianGetSimInfoByIccIds(List iccIds) { + List resultList = new ArrayList<>(); + + List list = WuLianGetSimInfo(iccIds); + SimCardVO vo = null; + + for (WuLianSimData wuLianSimData : list) { + String WuLianCardStatus = wuLianSimData.getCardStatus(); + + // 鍗$姸鎬佷笉涓鑷达紝闇鍋氬搴 + String dataBaseCardStatus = SimCardStatusCorrespondEnum.getDataBaseCardStatus(WuLianCardStatus); + + BigDecimal packageCanUsage = new BigDecimal(wuLianSimData.getPackageCanUsage()); // 鍙敤娴侀噺(MB) + BigDecimal packageHasUsage = new BigDecimal(wuLianSimData.getPackageHasUsage()); // 宸茬敤娴侀噺(MB) + BigDecimal residualFlowRate = packageCanUsage.subtract(packageHasUsage); // 鍓╀綑 + + // 杩愯惀鍟 + String packageName = wuLianSimData.getPackageName(); + String operator = ""; + if (StringUtils.contains(packageName, "绉诲姩")) { + operator = "china_mobile"; + }else if (StringUtils.contains(packageName, "鐢典俊")) { + operator = "china_telecom"; + } else if (StringUtils.contains(packageName, "鑱旈")) { + operator = "china_unicom"; + } + + //灏嗕俊鎭皝瑁呭埌SimCardVO + vo = new SimCardVO(); + vo.setIccId(wuLianSimData.getIccId()); + vo.setSimCardFactory(SimSupplierEnum.WU_LIAN_INTERNET.getCode()); // 2-鐗╄仈缃戞櫤鑳戒簯骞冲彴 + vo.setSimCardOperator(operator); // 杩愯惀鍟 + vo.setSimCardStatus(dataBaseCardStatus); // 鍗$姸鎬 + vo.setName(packageName); // 濂楅鍚嶇О + vo.setExpiredTime(wuLianSimData.getCardEndTime()); // 鍗″埌鏈熸椂闂 + vo.setPackageCapacity(packageCanUsage); // 濂楅瀹归噺 + vo.setUsedFlowRate(packageHasUsage); // 宸茬敤娴侀噺 + vo.setResidualFlowRate(residualFlowRate); // 鍓╀綑娴侀噺 + + + resultList.add(vo); + + } + return resultList; + + } + + + /** + * 鐗╄仈骞冲彴缁垂鎺ュ彛 + * + * @param iccIds + * @param cycleNumber + * @return + */ + public void WuLianSimRenew(List iccIds, int cycleNumber) { + List resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(iccIds)) { + return; + } + // 鍏堟煡鍑哄崱鐨勪俊鎭 + List wuLianSimData = WuLianGetSimInfo(iccIds); + for (WuLianSimData data : wuLianSimData) { + JSONObject param = new JSONObject(); + param.put("appid", appId); + param.put("appsecret", appSecret); + param.put("name", WuLianSimRenew); + param.put("msisdn", data.getMsisdn()); + param.put("packageId", data.getPackageId()); // 濂楅id + param.put("outOrderNo", IdUtils.generateOrderCode(data.getMsisdn())); // 澶栭儴涓氬姟璁㈠崟鍙 + param.put("period", cycleNumber); // 缁垂鍛ㄦ湡 + + String result = HttpUtils.sendPostContentType(wuLianGetWay, param.toJSONString(), "application/json"); + logger.info("銆====鐗╄仈缃戞櫤鑳戒簯骞冲彴====銆慡im鍗$画璐, result: {}", result); + JSONObject resultJson = JSONObject.parseObject(result); + String resultCode = resultJson.getString("code"); + WuLianSimRenewVO vo = null; + if (!StringUtils.equals("0", resultCode)) { + throw new BusinessException(resultCode, resultJson.getString("msg")); + } + } + } + + /** + * 灏唋ist鏁扮粍杞寲涓洪楀彿鍒嗛殧鐨勫瓧绗︿覆 + * + * @param iccIds + * @return + */ + private String list2Str(List iccIds) { + iccIds = iccIds.stream() + .filter(StringUtils::isNotEmpty) + .filter(x -> !StringUtils.equals(x, "0")) + .collect(Collectors.toList()); + // 鏁扮粍杞垚閫楀彿鍒嗗壊鐨勫瓧绗︿覆 + String iccId = StringUtils.join(iccIds, ","); + return iccId; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/WechatPayService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/WechatPayService.java new file mode 100644 index 000000000..2a0911a09 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/WechatPayService.java @@ -0,0 +1,43 @@ +package com.jsowell.pile.service; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.jsowell.pile.dto.WeixinPayDTO; +import com.jsowell.wxpay.response.WechatPayNotifyParameter; +import com.jsowell.wxpay.response.WechatPayRefundRequest; +import com.jsowell.wxpay.response.WechatPayRefundResponse; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +public interface WechatPayService { + /** + * 鑾峰彇寰俊鏀粯鍙傛暟 + * @param dto + * @return + * @throws Exception + */ + Map weixinPayV3(WeixinPayDTO dto) throws Exception; + + /** + * 鑾峰彇寰俊鏀粯鍥炶皟淇℃伅 + * @param request + * @param body + * @return + * @throws Exception + */ + Map wechatPayCallbackInfo(HttpServletRequest request, WechatPayNotifyParameter body) throws Exception; + + /** + * 寰俊閫娆炬帴鍙 + * ApplyForARefund + */ + WechatPayRefundResponse ApplyForWechatPayRefundV3(WechatPayRefundRequest request) throws JsonProcessingException; + + /** + * 鑾峰彇寰俊閫娆惧洖璋冧俊鎭 + * @param request + * @param body + * @return + */ + Map wechatPayRefundCallbackInfo(HttpServletRequest request, WechatPayNotifyParameter body) throws Exception; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/WxpayCallbackRecordService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/WxpayCallbackRecordService.java new file mode 100644 index 000000000..a296f0d40 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/WxpayCallbackRecordService.java @@ -0,0 +1,34 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.WxpayCallbackRecord; + +import java.util.List; + +public interface WxpayCallbackRecordService { + int deleteByPrimaryKey(Integer id); + + int insert(WxpayCallbackRecord record); + + int insertSelective(WxpayCallbackRecord record); + + WxpayCallbackRecord selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(WxpayCallbackRecord record); + + int updateByPrimaryKey(WxpayCallbackRecord record); + + WxpayCallbackRecord selectByOrderCode(String orderCode); + + /** + * 閫氳繃寰俊鍟嗘埛璁㈠崟鍙锋煡璇 + * @param outTradeNo + * @return + */ + WxpayCallbackRecord selectByOutTradeNo(String outTradeNo); + + /** + * 鏍规嵁memberId鏌ヨ鏈杩戜竴骞寸殑浣欓鍏呭艰褰 + * queryTheBalanceTopUpRecordOfTheLatestYear + */ + List queryBalanceRechargeRecordOfTheLatestYear(String memberId); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/WxpayRefundCallbackService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/WxpayRefundCallbackService.java new file mode 100644 index 000000000..9c4112164 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/WxpayRefundCallbackService.java @@ -0,0 +1,15 @@ +package com.jsowell.pile.service; + +import com.jsowell.pile.domain.WxpayRefundCallback; + +public interface WxpayRefundCallbackService { + int deleteByPrimaryKey(Integer id); + + int insertSelective(WxpayRefundCallback record); + + WxpayRefundCallback selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(WxpayRefundCallback record); + + int updateByPrimaryKey(WxpayRefundCallback record); +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberBasicInfoServiceImpl.java new file mode 100644 index 000000000..5cec801c2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberBasicInfoServiceImpl.java @@ -0,0 +1,264 @@ +package com.jsowell.pile.service.impl; + +import com.google.common.collect.Lists; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.MemberBasicInfo; +import com.jsowell.pile.domain.MemberWalletInfo; +import com.jsowell.pile.domain.MemberWalletLog; +import com.jsowell.pile.mapper.MemberBasicInfoMapper; +import com.jsowell.pile.mapper.MemberWalletInfoMapper; +import com.jsowell.pile.mapper.MemberWalletLogMapper; +import com.jsowell.pile.mapper.PileBasicInfoMapper; +import com.jsowell.pile.service.IMemberBasicInfoService; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.vo.uniapp.MemberVO; +import com.jsowell.pile.vo.uniapp.MemberWalletLogVO; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 浼氬憳鍩虹淇℃伅Service涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-10-12 + */ +@Slf4j +@Service +public class MemberBasicInfoServiceImpl implements IMemberBasicInfoService { + @Autowired + private MemberBasicInfoMapper memberBasicInfoMapper; + + @Autowired + private MemberWalletInfoMapper memberWalletInfoMapper; + + @Autowired + private MemberWalletLogMapper memberWalletLogMapper; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + /** + * 鏌ヨ浼氬憳鍩虹淇℃伅 + * + * @param id 浼氬憳鍩虹淇℃伅涓婚敭 + * @return 浼氬憳鍩虹淇℃伅 + */ + @Override + public MemberBasicInfo selectMemberBasicInfoById(Integer id) { + return memberBasicInfoMapper.selectMemberBasicInfoById(id); + } + + /** + * 鏌ヨ浼氬憳鍩虹淇℃伅鍒楄〃 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 浼氬憳鍩虹淇℃伅 + */ + /*@Override + public List selectMemberBasicInfoList(MemberBasicInfo memberBasicInfo) { + List voList = memberBasicInfoMapper.selectMemberList(memberBasicInfo.getMobileNumber(), memberBasicInfo.getNickName()); + for (MemberVO memberVO : voList) { + memberVO.setPrincipalBalance(memberVO.getPrincipalBalance() == null ? BigDecimal.ZERO : memberVO.getPrincipalBalance()); + memberVO.setGiftBalance(memberVO.getGiftBalance() == null ? BigDecimal.ZERO : memberVO.getGiftBalance()); + } + return voList; + }*/ + + /** + * 鏂板浼氬憳鍩虹淇℃伅 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertMemberBasicInfo(MemberBasicInfo memberBasicInfo) { + memberBasicInfo.setCreateTime(DateUtils.getNowDate()); + return memberBasicInfoMapper.insertMemberBasicInfo(memberBasicInfo); + } + + /** + * 淇敼浼氬憳鍩虹淇℃伅 + * + * @param memberBasicInfo 浼氬憳鍩虹淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateMemberBasicInfo(MemberBasicInfo memberBasicInfo) { + memberBasicInfo.setUpdateTime(DateUtils.getNowDate()); + return memberBasicInfoMapper.updateMemberBasicInfo(memberBasicInfo); + } + + /** + * 鎵归噺鍒犻櫎浼氬憳鍩虹淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑浼氬憳鍩虹淇℃伅涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deleteMemberBasicInfoByIds(List ids) { + return memberBasicInfoMapper.deleteMemberBasicInfoByIds(ids); + } + + /** + * 閫氳繃鐗╃悊鍗″彿鏌ヨ浼氬憳鍩烘湰淇℃伅 + * + * @param physicsCard 鐗╃悊鍗″彿 + * @return 浼氬憳鍩烘湰淇℃伅 + */ + @Override + public MemberVO selectInfoByPhysicsCard(String physicsCard) { + return memberBasicInfoMapper.selectInfoByPhysicsCard(physicsCard); + } + + /** + * 鏍规嵁鎵嬫満鍙峰拰杩愯惀鍟唅d鏌ヨ浼氬憳淇℃伅 + * @param mobileNumber 鎵嬫満鍙 + * @param merchantId 杩愯惀鍟唅d + * @return 浼氬憳淇℃伅 + */ + public MemberBasicInfo selectInfoByMobileNumberAndMerchantId(String mobileNumber, String merchantId) { + return memberBasicInfoMapper.selectInfoByMobileNumberAndMerchantId(mobileNumber, merchantId); + } + + @Override + public MemberBasicInfo selectInfoByMobileNumber(String mobileNumber) { + return selectInfoByMobileNumberAndMerchantId(mobileNumber, null); + } + + @Override + public MemberBasicInfo selectInfoByMemberId(String memberId) { + return memberBasicInfoMapper.selectInfoByMemberId(memberId); + } + + /** + * 淇敼鐢ㄦ埛浣欓 鍞竴鏂规硶 + * 鎺ユ敹鐨勯噾棰濋兘鏄鏁帮紝閫氳繃鎿嶄綔绫诲瀷鍒ゆ柇 鍏呭艰繕鏄墸鍑 + */ + @Override + public int updateMemberBalance(UpdateMemberBalanceDTO dto) { + String memberId = dto.getMemberId(); + BigDecimal updateGiftBalance = dto.getUpdateGiftBalance(); + BigDecimal updatePrincipalBalance = dto.getUpdatePrincipalBalance(); + log.info("淇敼鐢ㄦ埛浣欓 memberId:{}, updatePrincipalBalance:{}, updateGiftBalance:{}", memberId, updatePrincipalBalance, updateGiftBalance); + // 鏌ヨ鐢ㄦ埛浣欓 + MemberWalletInfo info = memberWalletInfoMapper.selectByMemberId(memberId); + if (info == null) { + log.warn("鏍规嵁浼氬憳id:{}, 鏌ヨ浼氬憳淇℃伅涓虹┖", memberId); + return 0; + } + + // 璁板綍娴佹按 + List logList = Lists.newArrayList(); + // 璁$畻鏂扮殑浣欓 + BigDecimal newPrincipalBalance = null; + BigDecimal newGiftBalance = null; + + // 鏇存柊鏈噾閲戦 + if (updatePrincipalBalance != null) { + if (StringUtils.equals(dto.getType(), "2")) { + // 鎵f 杞负璐熸暟 + updatePrincipalBalance = updatePrincipalBalance.negate(); + } + // 浼氬憳鑰佺殑浣欓 + BigDecimal oldPrincipalBalance = info.getPrincipalBalance() == null + ? BigDecimal.ZERO + : info.getPrincipalBalance(); + newPrincipalBalance = oldPrincipalBalance.add(updatePrincipalBalance); + if (newPrincipalBalance.compareTo(BigDecimal.ZERO) < 0) { + log.warn("鏂版湰閲戜綑棰濅笉鑳戒负璐熸暟"); + return 0; + } + // 璁版祦姘 + logList.add(MemberWalletLog.builder() + .memberId(dto.getMemberId()) + .type(dto.getType()) + .subType(dto.getSubType()) + .amount(updatePrincipalBalance) + .category("1") + .relatedOrderCode(dto.getRelatedOrderCode()) + .createBy(dto.getMemberId()) + .build()); + } + + // 鏇存柊璧犻侀噾棰 + if (updateGiftBalance != null) { + if (StringUtils.equals(dto.getType(), "2")) { + // 鎵f 杞负璐熸暟 + updateGiftBalance = updateGiftBalance.negate(); + } + BigDecimal oldGiftBalance = info.getGiftBalance() == null + ? BigDecimal.ZERO + : info.getGiftBalance(); + newGiftBalance = oldGiftBalance.add(updateGiftBalance); + // 浣欓涓嶈兘涓鸿礋鏁 + if (newGiftBalance.compareTo(BigDecimal.ZERO) < 0) { + log.warn("鏂拌禒閫佷綑棰濅笉鑳戒负璐熸暟"); + return 0; + } + // 璁版祦姘 + logList.add(MemberWalletLog.builder() + .memberId(dto.getMemberId()) + .type(dto.getType()) + .subType(dto.getSubType()) + .amount(updateGiftBalance) + .category("2") + .relatedOrderCode(dto.getRelatedOrderCode()) + .createBy(dto.getMemberId()) + .build()); + } + + // 淇敼鏁版嵁搴 + int i = 0; + if (newPrincipalBalance != null || newGiftBalance != null) { + i = memberBasicInfoMapper.updateMemberBalance(memberId, newPrincipalBalance, newGiftBalance, info.getVersion()); + if (i == 0) { + log.warn("淇敼浣欓澶辫触, memberId:{}", memberId); + } + } + // 鎻掑叆 member_wallet_log 琛 + if (CollectionUtils.isNotEmpty(logList)) { + memberWalletLogMapper.batchInsert(logList); + } + return i; + } + + @Override + public MemberVO queryMemberInfoByMemberId(String memberId) { + // 鍔犵紦瀛 + MemberVO vo = memberBasicInfoMapper.queryMemberInfoByMemberId(memberId); + return vo; + } + + @Override + public List selectMemberList(String mobileNumber, String nickName) { + return memberBasicInfoMapper.selectMemberList(mobileNumber, nickName); + } + + /** + * 鏌ヨ鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 + * @param memberId 浼氬憳id + * @param type 1-杩涜处锛2-鍑鸿处 涓嶄紶鏌ュ叏閮 + */ + @Override + public List getMemberBalanceChanges(String memberId, String type) { + return memberWalletLogMapper.getMemberBalanceChanges(memberId, type); + } + + /** + * 閫氳繃memberId鏌ヨ浼氬憳鐨勪釜浜烘々淇℃伅 + * @param memberId + * @return + */ + @Override + public List getMemberPersonPileInfo(String memberId) { + return pileBasicInfoService.getPileInfoByMemberId(memberId); + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberTransactionRecordServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberTransactionRecordServiceImpl.java new file mode 100644 index 000000000..6fac0fd17 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberTransactionRecordServiceImpl.java @@ -0,0 +1,41 @@ +package com.jsowell.pile.service.impl; + +import com.google.common.collect.Lists; +import com.jsowell.common.util.bean.BeanUtils; +import com.jsowell.pile.domain.MemberTransactionRecord; +import com.jsowell.pile.mapper.MemberTransactionRecordMapper; +import com.jsowell.pile.service.IMemberTransactionRecordService; +import com.jsowell.pile.vo.web.MemberTransactionVO; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class MemberTransactionRecordServiceImpl implements IMemberTransactionRecordService { + + @Resource + private MemberTransactionRecordMapper memberTransactionRecordMapper; + + @Override + public int insertSelective(MemberTransactionRecord record) { + return memberTransactionRecordMapper.insertSelective(record); + } + + @Override + public List selectMemberTransactionRecordList(String memberId) { + List list = memberTransactionRecordMapper.selectByMemberId(memberId); + if (CollectionUtils.isEmpty(list)) { + return Lists.newArrayList(); + } + List resultList = Lists.newArrayList(); + for (MemberTransactionRecord memberTransactionRecord : list) { + MemberTransactionVO vo = new MemberTransactionVO(); + BeanUtils.copyBeanProp(vo, memberTransactionRecord); + resultList.add(vo); + } + return resultList; + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberWalletInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberWalletInfoServiceImpl.java new file mode 100644 index 000000000..e41dbef02 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberWalletInfoServiceImpl.java @@ -0,0 +1,46 @@ +package com.jsowell.pile.service.impl; + +import com.jsowell.pile.domain.MemberWalletInfo; +import com.jsowell.pile.mapper.MemberWalletInfoMapper; +import com.jsowell.pile.service.IMemberWalletInfoService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +public class MemberWalletInfoServiceImpl implements IMemberWalletInfoService { + + @Resource + private MemberWalletInfoMapper memberWalletInfoMapper; + + @Override + public int deleteByPrimaryKey(Integer id) { + return memberWalletInfoMapper.deleteByPrimaryKey(id); + } + + @Override + public int insert(MemberWalletInfo record) { + return memberWalletInfoMapper.insert(record); + } + + @Override + public int insertSelective(MemberWalletInfo record) { + return memberWalletInfoMapper.insertSelective(record); + } + + @Override + public MemberWalletInfo selectByPrimaryKey(Integer id) { + return memberWalletInfoMapper.selectByPrimaryKey(id); + } + + @Override + public int updateByPrimaryKeySelective(MemberWalletInfo record) { + return memberWalletInfoMapper.updateByPrimaryKeySelective(record); + } + + @Override + public int updateByPrimaryKey(MemberWalletInfo record) { + return memberWalletInfoMapper.updateByPrimaryKey(record); + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberWalletLogServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberWalletLogServiceImpl.java new file mode 100644 index 000000000..c66e39eac --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberWalletLogServiceImpl.java @@ -0,0 +1,46 @@ +package com.jsowell.pile.service.impl; + +import com.jsowell.pile.domain.MemberWalletLog; +import com.jsowell.pile.mapper.MemberWalletLogMapper; +import com.jsowell.pile.service.IMemberWalletLogService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +public class MemberWalletLogServiceImpl implements IMemberWalletLogService { + + @Resource + private MemberWalletLogMapper memberWalletLogMapper; + + // @Override + // public int deleteByPrimaryKey(Integer id) { + // return memberWalletLogMapper.deleteByPrimaryKey(id); + // } + // + // @Override + // public int insert(MemberWalletLog record) { + // return memberWalletLogMapper.insert(record); + // } + // + // @Override + // public int insertSelective(MemberWalletLog record) { + // return memberWalletLogMapper.insertSelective(record); + // } + // + // @Override + // public MemberWalletLog selectByPrimaryKey(Integer id) { + // return memberWalletLogMapper.selectByPrimaryKey(id); + // } + // + // @Override + // public int updateByPrimaryKeySelective(MemberWalletLog record) { + // return memberWalletLogMapper.updateByPrimaryKeySelective(record); + // } + // + // @Override + // public int updateByPrimaryKey(MemberWalletLog record) { + // return memberWalletLogMapper.updateByPrimaryKey(record); + // } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderAbnormalRecordServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderAbnormalRecordServiceImpl.java new file mode 100644 index 000000000..c5d0f5de1 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderAbnormalRecordServiceImpl.java @@ -0,0 +1,88 @@ +package com.jsowell.pile.service.impl; + +import com.jsowell.pile.domain.OrderAbnormalRecord; +import com.jsowell.pile.mapper.OrderAbnormalRecordMapper; +import com.jsowell.pile.service.IOrderAbnormalRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 璁㈠崟寮傚父璁板綍Service涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2023-02-13 + */ +@Service +public class OrderAbnormalRecordServiceImpl implements IOrderAbnormalRecordService { + @Autowired + private OrderAbnormalRecordMapper orderAbnormalRecordMapper; + + /** + * 鏌ヨ璁㈠崟寮傚父璁板綍 + * + * @param id 璁㈠崟寮傚父璁板綍涓婚敭 + * @return 璁㈠崟寮傚父璁板綍 + */ + @Override + public OrderAbnormalRecord selectOrderAbnormalRecordById(Integer id) { + return orderAbnormalRecordMapper.selectOrderAbnormalRecordById(id); + } + + /** + * 鏌ヨ璁㈠崟寮傚父璁板綍鍒楄〃 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 璁㈠崟寮傚父璁板綍 + */ + @Override + public List selectOrderAbnormalRecordList(OrderAbnormalRecord orderAbnormalRecord) { + return orderAbnormalRecordMapper.selectOrderAbnormalRecordList(orderAbnormalRecord); + } + + /** + * 鏂板璁㈠崟寮傚父璁板綍 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 缁撴灉 + */ + @Override + public int insertOrderAbnormalRecord(OrderAbnormalRecord orderAbnormalRecord) { + // orderAbnormalRecord.setCreateTime(DateUtils.getNowDate()); + return orderAbnormalRecordMapper.insertOrderAbnormalRecord(orderAbnormalRecord); + } + + /** + * 淇敼璁㈠崟寮傚父璁板綍 + * + * @param orderAbnormalRecord 璁㈠崟寮傚父璁板綍 + * @return 缁撴灉 + */ + @Override + public int updateOrderAbnormalRecord(OrderAbnormalRecord orderAbnormalRecord) { + return orderAbnormalRecordMapper.updateOrderAbnormalRecord(orderAbnormalRecord); + } + + /** + * 鎵归噺鍒犻櫎璁㈠崟寮傚父璁板綍 + * + * @param ids 闇瑕佸垹闄ょ殑璁㈠崟寮傚父璁板綍涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deleteOrderAbnormalRecordByIds(Integer[] ids) { + return orderAbnormalRecordMapper.deleteOrderAbnormalRecordByIds(ids); + } + + /** + * 鍒犻櫎璁㈠崟寮傚父璁板綍淇℃伅 + * + * @param id 璁㈠崟寮傚父璁板綍涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deleteOrderAbnormalRecordById(Integer id) { + return orderAbnormalRecordMapper.deleteOrderAbnormalRecordById(id); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java new file mode 100644 index 000000000..7a0ce2ed2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java @@ -0,0 +1,852 @@ +package com.jsowell.pile.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.jsowell.common.annotation.DataScope; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.core.domain.ykc.TransactionRecordsData; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.MemberWalletEnum; +import com.jsowell.common.enums.ykc.OrderPayModeEnum; +import com.jsowell.common.enums.ykc.OrderPayStatusEnum; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.bean.BeanUtils; +import com.jsowell.common.util.id.SnowflakeIdWorker; +import com.jsowell.pile.domain.OrderAbnormalRecord; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.domain.OrderDetail; +import com.jsowell.pile.domain.OrderPayRecord; +import com.jsowell.pile.domain.WxpayCallbackRecord; +import com.jsowell.pile.dto.IndexQueryDTO; +import com.jsowell.pile.dto.QueryOrderDTO; +import com.jsowell.pile.dto.QueryPersonPileDTO; +import com.jsowell.pile.mapper.OrderBasicInfoMapper; +import com.jsowell.pile.service.IMemberBasicInfoService; +import com.jsowell.pile.service.IOrderAbnormalRecordService; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.service.IOrderPayRecordService; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.service.WechatPayService; +import com.jsowell.pile.service.WxpayCallbackRecordService; +import com.jsowell.pile.transaction.dto.OrderTransactionDTO; +import com.jsowell.pile.transaction.service.TransactionService; +import com.jsowell.pile.vo.uniapp.*; +import com.jsowell.pile.vo.web.IndexOrderInfoVO; +import com.jsowell.pile.vo.web.OrderListVO; +import com.jsowell.pile.vo.web.OrderTotalDataVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; +import com.jsowell.wxpay.common.WeChatPayParameter; +import com.jsowell.wxpay.dto.WeChatRefundDTO; +import com.jsowell.wxpay.dto.WechatSendMsgDTO; +import com.jsowell.wxpay.response.WechatPayRefundRequest; +import com.jsowell.wxpay.response.WechatPayRefundResponse; +import com.jsowell.wxpay.service.WxAppletRemoteService; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 璁㈠崟Service涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-09-30 + */ +@Service +public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService { + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private OrderBasicInfoMapper orderBasicInfoMapper; + + @Autowired + private TransactionService transactionService; + + @Autowired + private RedisCache redisCache; + + @Autowired + private IOrderPayRecordService orderPayRecordService; + + @Autowired + private IMemberBasicInfoService memberBasicInfoService; + + @Autowired + private WxpayCallbackRecordService wxpayCallbackRecordService; + + @Autowired + private WechatPayService wechatPayService; + + @Autowired + private IOrderAbnormalRecordService orderAbnormalRecordService; + + @Autowired + private WxAppletRemoteService wxAppletRemoteService; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + /** + * 鏌ヨ璁㈠崟 + * + * @param id 璁㈠崟涓婚敭 + * @return 璁㈠崟 + */ + @Override + public OrderBasicInfo selectOrderBasicInfoById(Long id) { + return orderBasicInfoMapper.selectOrderBasicInfoById(id); + } + + /** + * 鏉′欢鏌ヨ璁㈠崟鍩烘湰淇℃伅 + * @param info + * @return + */ + @Override + public OrderBasicInfo getOrderBasicInfo(OrderBasicInfo info) { + return orderBasicInfoMapper.getOrderBasicInfo(info); + } + + /** + * 鏌ヨ璁㈠崟鍒楄〃 + * + * @param dto 璁㈠崟 + * @return 璁㈠崟 + */ + @Override + @DataScope(deptAlias = "t3") + public List selectOrderBasicInfoList(QueryOrderDTO dto) { + List orderListVOS = orderBasicInfoMapper.selectOrderBasicInfoList(dto); + if (CollectionUtils.isNotEmpty(orderListVOS)) { + for (OrderListVO orderListVO : orderListVOS) { + // 濡傛灉鏄井淇℃敮浠橈紝閫氳繃璁㈠崟鍙锋煡璇㈠井淇℃敮浠樺崟鍙 + if (StringUtils.equals(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue(), orderListVO.getPayMode())) { + WxpayCallbackRecord wxpayCallbackRecord = wxpayCallbackRecordService.selectByOrderCode(orderListVO.getOrderCode()); + orderListVO.setOutTradeNo(wxpayCallbackRecord.getOutTradeNo()); + } + orderListVO.setPileConnectorCode(orderListVO.getPileSn() + orderListVO.getConnectorCode()); + + // 璁㈠崟鐘舵佹弿杩 + String orderStatus = orderListVO.getOrderStatus(); // 璁㈠崟鐘舵 + String payStatus = orderListVO.getPayStatus(); // 鏀粯鐘舵 + String orderStatusDescribe; + if (StringUtils.equals(orderStatus, OrderStatusEnum.NOT_START.getValue())) { + // 鏈惎鍔ㄨ繕鏈変袱绉嶆儏鍐 寰呮敮浠 / 鏀粯鎴愬姛 + if (StringUtils.equals(payStatus, OrderPayStatusEnum.paid.getValue())) { + // 鏀粯鎴愬姛锛屾湭鍚姩 + orderStatusDescribe = OrderPayStatusEnum.paid.getLabel() + ", " + OrderStatusEnum.getOrderStatus(orderStatus); + } else { + // 寰呮敮浠 + orderStatusDescribe = OrderPayStatusEnum.unpaid.getLabel(); + } + } else { + orderStatusDescribe = OrderStatusEnum.getOrderStatus(orderStatus); + } + orderListVO.setOrderStatusDescribe(orderStatusDescribe); + } + } + return orderListVOS; + } + + /** + * 鏌ヨ鏃堕棿娈靛唴璁㈠崟鎬婚噾棰濆拰鎬荤敤鐢甸噺 + * + * @param dto + * @return + */ + @Override + @DataScope(deptAlias = "t3") + public OrderTotalDataVO getOrderTotalData(QueryOrderDTO dto) { + OrderTotalDataVO vo = new OrderTotalDataVO(); + dto.setOrderStatus(OrderStatusEnum.ORDER_COMPLETE.getValue()); + List list = orderBasicInfoMapper.selectOrderBasicInfoList(dto); + BigDecimal sumOrderAmount = BigDecimal.ZERO; + BigDecimal sumUsedElectricity = BigDecimal.ZERO; + vo.setDateDescription(dto.getStartTime() + " - " + dto.getEndTime()); + if (CollectionUtils.isNotEmpty(list)) { + for (OrderListVO orderListVO : list) { + BigDecimal orderAmount = StringUtils.isBlank(orderListVO.getOrderAmount()) + ? BigDecimal.ZERO + : new BigDecimal(orderListVO.getOrderAmount()); + sumOrderAmount = sumOrderAmount.add(orderAmount); + + BigDecimal chargingDegree = StringUtils.isBlank(orderListVO.getChargingDegree()) + ? BigDecimal.ZERO + : new BigDecimal(orderListVO.getChargingDegree()); + sumUsedElectricity = sumUsedElectricity.add(chargingDegree); + } + } + vo.setSumOrderAmount(sumOrderAmount); + vo.setSumUsedElectricity(sumUsedElectricity); + return vo; + } + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曚俊鎭紙灏忕▼搴忓彂閫佹秷鎭敤锛 + * @param orderCode + * @return + */ + @Override + public SendMessageVO selectOrderInfoByOrderCode(String orderCode) { + return orderBasicInfoMapper.selectOrderInfoByOrderCode(orderCode); + } + + /** + * 鍏呯數妗╁惎鍔ㄥけ璐 + * @param orderCode + * @param failedReasonMsg + */ + @Override + public void chargingPileFailedToStart(String orderCode, String failedReasonMsg) { + OrderBasicInfo orderInfo = getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return; + } + // 鍚姩澶辫触鍘熷洜 + orderInfo.setReason(failedReasonMsg); + // 璁㈠崟閫娆(缁撶畻璁㈠崟) + TransactionRecordsData data = TransactionRecordsData.builder() + .orderCode(orderInfo.getOrderCode()) + .consumptionAmount(String.valueOf(orderInfo.getOrderAmount())) + .stopReasonMsg(failedReasonMsg) + .totalElectricity(Constants.ZERO) + .sharpUsedElectricity(Constants.ZERO) + .peakUsedElectricity(Constants.ZERO) + .flatUsedElectricity(Constants.ZERO) + .valleyUsedElectricity(Constants.ZERO) + .build(); + settleOrder(data, orderInfo); + } + + /** + * 鍏呯數妗╁惎鍔ㄦ垚鍔 + * @param orderCode + */ + @Override + public void chargingPileStartedSuccessfully(String orderCode) { + OrderBasicInfo orderInfo = getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return; + } + // 鍚姩鎴愬姛锛岃鍗曠姸鎬佹敼涓哄厖鐢典腑 + orderInfo.setOrderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue()); + if (orderInfo.getChargeStartTime() == null) { + orderInfo.setChargeStartTime(new Date()); + } + updateOrderBasicInfo(orderInfo); + } + + public static void main(String[] args) { + Date date = DateUtils.addMinute(new Date(), -10); + System.out.println(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date)); + long currentTimeMillis = System.currentTimeMillis(); + if (currentTimeMillis - date.getTime() > 1000 * 60 * 15) { + // 宸茬粡鏀粯瓒呰繃15鍒嗛挓 + System.out.println("宸茬粡鏀粯瓒呰繃15鍒嗛挓"); + } else { + System.out.println("宸茬粡鏀粯, 涓嶅埌15鍒嗛挓"); + } + } + + @Override + public void closeStartFailedOrder(String startTime, String endTime) { + List orderList = orderBasicInfoMapper.selectOrderListByTimeRangeAndStatus(startTime, endTime, OrderStatusEnum.NOT_START.getValue(), OrderPayStatusEnum.paid.getValue()); + List orderCodeList = orderList.stream().map(OrderBasicInfo::getOrderCode).collect(Collectors.toList()); + logger.info("{}-{}鏈熼棿锛屽叡{}鏉★紝鏀粯鎴愬姛鏈惎鍔ㄨ鍗曪紝璁㈠崟鍙:{}", startTime, endTime, orderList.size(), orderCodeList); + if (CollectionUtils.isEmpty(orderList)) { + return; + } + long currentTimeMillis = System.currentTimeMillis(); + // 鍒ゆ柇鏀粯鎴愬姛鏃堕棿璺濆綋鍓嶆椂闂存槸鍚﹀ぇ浜15鍒嗛挓 + for (OrderBasicInfo orderBasicInfo : orderList) { + String orderCode = orderBasicInfo.getOrderCode(); + Date payTime = orderBasicInfo.getPayTime(); + if (payTime == null) { + continue; + } + long time = payTime.getTime(); + if (currentTimeMillis - time < 1000 * 60 * 15) { + continue; + } + // 宸茬粡鏀粯瓒呰繃15鍒嗛挓 鍒ゆ柇鍏呯數妗╃殑鐘舵 + String pileConnectorCode = orderBasicInfo.getPileSn() + orderBasicInfo.getConnectorCode(); + PileConnectorInfoVO connector = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode); + // 鍏呯數妗╀笉鍦ㄧ嚎锛屽垯涓嶅仛澶勭悊銆傝鑱旂郴绠$悊鍛樻搷浣 + if (PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue().equals(String.valueOf(connector.getStatus()))) { + logger.info("璁㈠崟鍙:{}宸茬粡鏀粯瓒呰繃15鍒嗛挓锛屽厖鐢垫々:{}鏈惎鍔紝浣嗘槸璇ユ々涓虹绾跨姸鎬侊紝璇疯仈绯荤鐞嗗憳澶勭悊", orderCode, pileConnectorCode); + continue; + } + // 鑾峰彇璁㈠崟鐨勫疄鏃舵娴嬫暟鎹紝鏈夊疄鏃舵暟鎹鏄庡厖鐢典簡锛屾病鏈夊疄鏃舵暟鎹鏄庢々纭疄娌℃湁鍏呯數 + List chargingRealTimeData = getChargingRealTimeData(orderCode); + if (CollectionUtils.isEmpty(chargingRealTimeData)) { + // 鍏呯數妗╁湪绾匡紝骞朵笖娌℃湁0x13瀹炴椂鏁版嵁锛屽垯鎵ц缁撶畻閫娆炬搷浣 + chargingPileFailedToStart(orderCode, "鍏呯數妗╁惎鍔ㄥけ璐ワ紝鎵ц閫娆惧鐞"); + } + } + } + + /** + * 鏌ヨ鍏呯數涓殑璁㈠崟锛屾病鏈夋暟鎹潈闄愭牎楠岋紝鍚庣涓嶈鐢 + * + * @param pileSn + * @return + */ + @Override + public List selectChargingOrder(String pileSn) { + QueryOrderDTO dto = QueryOrderDTO.builder() + .pileSn(pileSn) + .orderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue()) + .build(); + return orderBasicInfoMapper.selectOrderBasicInfoList(dto); + } + + /** + * 淇敼璁㈠崟 + * + * @param orderBasicInfo 璁㈠崟 + * @return 缁撴灉 + */ + @Transactional + @Override + public int updateOrderBasicInfo(OrderBasicInfo orderBasicInfo) { + // 娓呯紦瀛 + String redisKey = CacheConstants.GET_ORDER_INFO_BY_ORDER_CODE + orderBasicInfo.getOrderCode(); + redisCache.deleteObject(redisKey); + return orderBasicInfoMapper.updateOrderBasicInfo(orderBasicInfo); + } + + /** + * 鎵归噺鍒犻櫎璁㈠崟 + * + * @param ids 闇瑕佸垹闄ょ殑璁㈠崟涓婚敭 + * @return 缁撴灉 + */ + @Transactional + @Override + public int deleteOrderBasicInfoByIds(Long[] ids) { + orderBasicInfoMapper.deleteOrderDetailByOrderCodes(ids); + return orderBasicInfoMapper.deleteOrderBasicInfoByIds(ids); + } + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曚俊鎭 + * + * @param orderCode 璁㈠崟鍙 + * @return + */ + @Override + public OrderBasicInfo getOrderInfoByOrderCode(String orderCode) { + String redisKey = CacheConstants.GET_ORDER_INFO_BY_ORDER_CODE + orderCode; + OrderBasicInfo orderBasicInfo = redisCache.getCacheObject(redisKey); + if (orderBasicInfo == null) { + // 鏌ユ暟鎹簱 + orderBasicInfo = orderBasicInfoMapper.getOrderInfoByOrderCode(orderCode); + // 鏀剧紦瀛 + if (orderBasicInfo != null) { + redisCache.setCacheObject(redisKey, orderBasicInfo, 5, TimeUnit.MINUTES); + } + } + logger.info("閫氳繃璁㈠崟鍙:{}, 鏌ヨ璁㈠崟淇℃伅:{}", orderCode, JSON.toJSONString(orderBasicInfo)); + return orderBasicInfo; + } + + /** + * 鏍规嵁鍏呯數妗╃紪鍙峰拰鏋彛鍙锋煡璇㈡鍦ㄥ厖鐢典腑鐨勮鍗 + * @param pileSn 妗╃紪鍙 + * @param connectorCode 鏋彛鍙 + * @return + */ + @Override + public OrderBasicInfo queryChargingByPileSnAndConnectorCode(String pileSn, String connectorCode) { + return orderBasicInfoMapper.queryOrderBasicInfo(pileSn, connectorCode, OrderStatusEnum.IN_THE_CHARGING.getValue()); + } + + /** + * 鏍规嵁鏋彛缂栧彿鏌ヨ姝e湪鍏呯數涓殑璁㈠崟 + * @param pileConnectorCode + * @return + */ + @Override + public OrderBasicInfo queryChargingByPileConnectorCode(String pileConnectorCode) { + if (StringUtils.isBlank(pileConnectorCode)) { + return null; + } + String pileSn = pileConnectorCode.substring(0, pileConnectorCode.length() - 2); + String connectorCode = pileConnectorCode.substring(pileConnectorCode.length() - 2); + return queryChargingByPileSnAndConnectorCode(pileSn, connectorCode); + } + + /** + * 缁撶畻璁㈠崟閫昏緫 + * + * @param data 浜ゆ槗璁板綍鏁版嵁 + * @param orderBasicInfo 璁㈠崟涓昏〃淇℃伅锛岀敱璋冪敤鏂逛紶杩囨潵 + */ + @Override + public void settleOrder(TransactionRecordsData data, OrderBasicInfo orderBasicInfo) { + logger.info("缁撶畻璁㈠崟start data:{}, orderBasicInfo:{}", data.toString(), orderBasicInfo.toString()); + String orderCode = data.getOrderCode(); + + // 鍒ゆ柇璁㈠崟鐘舵 + if (StringUtils.equals(orderBasicInfo.getOrderStatus(), OrderStatusEnum.ORDER_COMPLETE.getValue())) { + logger.info("缁撶畻璁㈠崟:{}, 鏄鍗曞畬鎴愮姸鎬", orderCode); + return; + } + // 娑堣垂閲戦灏辨槸璁㈠崟鎬婚噾棰 + BigDecimal orderAmount = new BigDecimal(data.getConsumptionAmount()); + + // 浠樻閲戦 - 瀹為檯娑堣垂閲戦锛屽鏋滄湁鍓╀綑锛岄渶瑕佽蛋閫娆炬搷浣 褰撲娇鐢ㄤ綑棰濇敮浠樻椂payAmount = principalPay + giftPay + BigDecimal payAmount = orderBasicInfo.getPayAmount(); + + // 鏈夋椂鍊欏厖鐢垫々鍒拌揪閲戦鍋滄鍏呯數浼氬鍑轰竴鐐归噾棰濓紝姣斿瀹為檯闇瑕佸厖50鍏冪殑鐢碉紝鍏呯數妗╀紶鏉ョ殑娑堣垂閲戦涓50.01鍏冿紝鍦ㄥ悗鍙拌褰曠殑鏃跺欓渶瑕佽垗鍘 + if (orderAmount.compareTo(payAmount) > 0) { + logger.info("缁撶畻璁㈠崟:銆恵}銆戝厖鐢垫々浼犳潵鐨勬秷璐归噾棰:銆恵}銆戝ぇ浜庝粯娆鹃噾棰:銆恵}銆, 娑堣垂閲戦璁剧疆涓轰粯娆鹃噾棰濈浉绛夋暟鎹", orderBasicInfo.getOrderCode(), orderAmount, payAmount); + orderAmount = payAmount; + } + + // 鍓╀綑闇瑕侀鍥炵殑閲戦 residue + BigDecimal residue = payAmount.subtract(orderAmount); + if (residue.compareTo(BigDecimal.ZERO) > 0) { + // 鏌ユ敮浠樿褰 + List payRecordList = orderPayRecordService.getOrderPayRecordList(orderBasicInfo.getOrderCode()); + // 鏇存柊璁㈠崟鏀粯璁板綍 + List updatePayRecordList = Lists.newArrayList(); + // 鏍规嵁鏀粯鏂瑰紡涓嶅悓锛岃蛋涓嶅悓娓犻亾閫娆 + String payMode = orderBasicInfo.getPayMode(); + if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) { // 浣欓鏀粯 + Map payRecordMap = payRecordList.stream() + .collect(Collectors.toMap(OrderPayRecord::getPayMode, Function.identity(), (k1, k2) -> k1)); + // 鍙栧嚭鏈噾鏀粯閲戦锛岃禒閫佹敮浠橀噾棰 + BigDecimal principalPay = null; + BigDecimal giftPay = null; + + OrderPayRecord principalPayRecord = payRecordMap.get("1"); + if (principalPayRecord != null) { + principalPay = principalPayRecord.getPayAmount(); + } + + OrderPayRecord giftPayRecord = payRecordMap.get("2"); + if (giftPayRecord != null) { + giftPay = giftPayRecord.getPayAmount(); + } + + Map returnAmountMap = calculateReturnAmount(principalPay, giftPay, orderAmount); + logger.info("缁撶畻璁㈠崟:{}, 鍓╀綑閲戦閫鍥炰綑棰, 璁㈠崟娑堣垂閲戦:{}, 鏈噾鏀粯閲戦:{}, 璧犻佹敮浠橀噾棰:{}, 閫鍥為噾棰漨ap:{}", + orderCode, orderAmount, principalPay, giftPay, JSONObject.toJSONString(returnAmountMap)); + // 鏇存柊浼氬憳閽卞寘 + BigDecimal returnPrincipal = returnAmountMap.get("returnPrincipal"); + if (returnPrincipal != null && principalPayRecord != null) { + principalPayRecord.setRefundAmount(returnPrincipal); + updatePayRecordList.add(principalPayRecord); + } + BigDecimal returnGift = returnAmountMap.get("returnGift"); + if (returnGift != null && giftPayRecord != null) { + giftPayRecord.setRefundAmount(returnGift); + updatePayRecordList.add(giftPayRecord); + } + UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder() + .memberId(orderBasicInfo.getMemberId()) + .type(MemberWalletEnum.TYPE_IN.getValue()) // 杩涜处 + .subType(MemberWalletEnum.SUBTYPE_ORDER_SETTLEMENT_REFUND.getValue()) // 璁㈠崟缁撶畻閫娆 + .updatePrincipalBalance(returnPrincipal) + .updateGiftBalance(returnGift) + .relatedOrderCode(orderCode) + .build(); + memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO); + } else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { // 寰俊鏀粯 + // 寰俊閫娆鹃昏緫 + WeChatRefundDTO weChatRefundDTO = new WeChatRefundDTO(); + weChatRefundDTO.setOrderCode(orderCode); + weChatRefundDTO.setRefundType("1"); + weChatRefundDTO.setRefundAmount(residue); + this.weChatRefund(weChatRefundDTO); + // 璁㈠崟鏀粯璁板綍 + OrderPayRecord orderPayRecord = payRecordList.get(0); + orderPayRecord.setRefundAmount(residue); + updatePayRecordList.add(orderPayRecord); + } else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 鏀粯瀹濇敮浠 + // 鏀粯瀹濋娆鹃昏緫 + } else { + // 鐧藉悕鍗曟敮浠 + logger.info("璁㈠崟锛歿}浣跨敤鐧藉悕鍗曟敮浠橈紝涓嶈繘琛岄娆惧鐞", orderBasicInfo.getOrderCode()); + } + + // 鏇存柊order_pay_record + if (CollectionUtils.isNotEmpty(updatePayRecordList)) { + for (OrderPayRecord orderPayRecord : updatePayRecordList) { + orderPayRecordService.updateByPrimaryKeySelective(orderPayRecord); + } + } + } + + // 淇敼璁㈠崟鏁版嵁 + // 鏌ヨ璁㈠崟璇︽儏 + OrderDetail orderDetail = getOrderDetailByOrderCode(orderCode); + + // 鎶婁氦鏄撹褰曚腑鐨勭敤鐢甸噺锛岄噾棰濈瓑淇℃伅 鏇存柊鍒皁rderBasicInfo鍜宱rderDetail + orderBasicInfo.setOrderAmount(orderAmount); // 璁㈠崟鎬婚噾棰 + orderBasicInfo.setOrderStatus(OrderStatusEnum.ORDER_COMPLETE.getValue()); + orderBasicInfo.setReason(data.getStopReasonMsg()); // 鍏呯數鍋滄鍘熷洜 + orderBasicInfo.setSettlementTime(DateUtils.getNowDate()); // 缁撶畻鏃堕棿 + orderBasicInfo.setRefundAmount(residue); // 缁撶畻閫娆鹃噾棰 + + orderDetail.setTotalUsedElectricity(new BigDecimal(data.getTotalElectricity())); // 鎬荤敤鐢甸噺 + orderDetail.setTotalOrderAmount(orderAmount); // 璁㈠崟鎬婚噾棰 + orderDetail.setSharpUsedElectricity(new BigDecimal(data.getSharpUsedElectricity())); // 灏栨椂娈电敤鐢甸噺 + orderDetail.setPeakUsedElectricity(new BigDecimal(data.getPeakUsedElectricity())); // 宄版椂娈电敤鐢甸噺 + orderDetail.setFlatUsedElectricity(new BigDecimal(data.getFlatUsedElectricity())); // 骞虫椂娈电敤鐢甸噺 + orderDetail.setValleyUsedElectricity(new BigDecimal(data.getValleyUsedElectricity())); // 璋锋椂娈电敤鐢甸噺 + OrderTransactionDTO dto = new OrderTransactionDTO(); + dto.setOrderBasicInfo(orderBasicInfo); + dto.setOrderDetail(orderDetail); + transactionService.doUpdateOrder(dto); + logger.info("缁撶畻璁㈠崟 end OrderTransactionDTO:{}", JSONObject.toJSONString(dto)); + + try { + // uniApp 鍙戦佸仠姝㈠厖鐢佃闃呮秷鎭 + WechatSendMsgDTO wechatSendMsgDTO = new WechatSendMsgDTO(); + wechatSendMsgDTO.setOrderCode(orderCode); + Map resultMap = wxAppletRemoteService.stopChargingSendMsg(wechatSendMsgDTO); + logger.info("灏忕▼搴忓彂閫佸厖鐢靛仠姝㈡帹閫佹秷鎭 result:{}", JSON.toJSONString(resultMap)); + }catch (Exception e) { + logger.error("灏忕▼搴忓彂閫佸厖鐢靛仠姝㈡帹閫佹秷鎭 error", e); + } + } + + /** + * 浣欓鏀粯 璁$畻闇瑕侀鍥炵殑閲戦 + * + * @param principalPay + * @param giftPay + * @param orderAmount + * @return + */ + private Map calculateReturnAmount(BigDecimal principalPay, BigDecimal giftPay, BigDecimal orderAmount) { + Map resultMap = Maps.newHashMap(); + + // 娑堣垂閲戦浼樺厛浣跨敤鏈噾 + BigDecimal returnPrincipal = null; // 閫鍥炴湰閲戦噾棰 + BigDecimal returnGift = null; // 閫鍥炶禒閫侀噾棰 + + // 浣欓鏀粯 鏈3绉嶆儏鍐 + if (principalPay != null && giftPay == null) { + // 鍙湁鏈噾鏀粯 + BigDecimal subtract = principalPay.subtract(orderAmount); + if (subtract.compareTo(BigDecimal.ZERO) > 0) { + returnPrincipal = subtract; + } + } + if (principalPay == null && giftPay != null) { + // 鍙湁璧犻侀噾棰濇敮浠 + BigDecimal subtract = giftPay.subtract(orderAmount); + if (subtract.compareTo(BigDecimal.ZERO) > 0) { + returnGift = subtract; + } + } + if (principalPay != null && giftPay != null) { + // 鏈噾+璧犻佹敮浠 + BigDecimal subtract = principalPay.subtract(orderAmount); + if (subtract.compareTo(BigDecimal.ZERO) > 0) { + // 鏈噾鍑忔帀璁㈠崟閲戦鍚庤繕鏈夊墿浣欙紝閭e氨鎶婂墿浣欑殑閫鍥烇紝璧犻佸師灏佷笉鍔ㄩ鍥 + returnPrincipal = subtract; + returnGift = giftPay; + } else if (subtract.compareTo(BigDecimal.ZERO) == 0) { + // 鏈噾鍒氬ソ澶燂紝閭h禒閫侀噾棰濇敮浠樼殑鍘熷皝涓嶅姩閫鍥 + returnGift = giftPay; + } else { + returnGift = giftPay.subtract(subtract.negate()); + } + } + + resultMap.put("returnPrincipal", returnPrincipal); + resultMap.put("returnGift", returnGift); + return resultMap; + } + + /** + * 缁撶畻璁㈠崟閫娆惧拰鐢ㄦ埛浣欓閫娆捐皟杩欎釜鏂规硶 + * + * @param dto + */ + @Override + public void weChatRefund(WeChatRefundDTO dto) { + // 閫娆炬湁涓ょ鎯呭喌 1-璁㈠崟缁撶畻閫娆 2-鐢ㄦ埛浣欓閫娆 + String refundType = dto.getRefundType(); + if (StringUtils.equals(refundType, "1")) { + WechatPayRefundResponse response = refundForOrder(dto); + logger.info("璁㈠崟缁撶畻閫娆 result:{}", JSONObject.toJSONString(response)); + } else if (StringUtils.equals(refundType, "2")) { + WechatPayRefundResponse response = refundForBalance(dto); + logger.info("鐢ㄦ埛浣欓閫娆 result:{}", JSONObject.toJSONString(response)); + } else { + logger.warn("娌℃湁鎵惧埌閫娆惧鐞嗛昏緫"); + } + } + + @Override + public void saveAbnormalOrder(TransactionRecordsData data) { + OrderAbnormalRecord record = new OrderAbnormalRecord(); + BeanUtils.copyBeanProp(record, data); + orderAbnormalRecordService.insertOrderAbnormalRecord(record); + } + + /** + * 鏍规嵁璁㈠崟缂栧彿鑾峰彇鍏呯數瀹炴椂鏁版嵁 鏃堕棿鍊掑簭 + * 璁㈠崟鍙湁鍦ㄥ厖鐢典腑锛屾墠浼氭妸瀹炴椂鏁版嵁淇濆瓨鍒皉edis + * @param orderCode 璁㈠崟缂栧彿 + * @return + */ + @Override + public List getChargingRealTimeData(String orderCode) { + List resultList = Lists.newArrayList(); + if (StringUtils.isBlank(orderCode)) { + return resultList; + } + String pileConnectorCode = orderCode.substring(0, 16); + String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + pileConnectorCode + "_" + orderCode; + // 鎷垮埌鎵鏈夋暟鎹 + Map map = redisCache.hmget(redisKey); + if (map != null && !map.isEmpty()) { + List keyList = map.keySet().stream() + .map(x -> (String) x) + .sorted(Comparator.reverseOrder()) // 瀵筴eyList鎺掑簭 鏃堕棿鍊掑簭 + .collect(Collectors.toList()); + for (String s : keyList) { + Object o = map.get(s); + RealTimeMonitorData data = JSONObject.parseObject((String) o, RealTimeMonitorData.class); + resultList.add(data); + } + } + return resultList; + } + + /** + * 棣栭〉璁㈠崟鏁版嵁灞曠ず + * + * @param dto 棣栭〉淇℃伅鏌ヨdto + * @return + */ + @Override + public List getIndexOrderInfo(IndexQueryDTO dto) { + return orderBasicInfoMapper.getIndexOrderInfo(dto); + } + + /** + * 鑾峰彇瓒呰繃15鍒嗛挓鐨勫緟鏀粯鐘舵佽鍗 + * + * @return + */ + @Override + public List getUnpaidOrderListOver15Min() { + Date now = DateUtils.addMinute(new Date(), -15); + String nowString = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now); + return orderBasicInfoMapper.getUnpaidOrderListOver15Min(nowString); + } + + /** + * 鏍规嵁orderId鎵归噺淇敼璁㈠崟鐘舵 + * + * @param orderIds + * @param orderStatus + */ + @Override + public void updateOrderStatusById(List orderIds, String orderStatus) { + orderBasicInfoMapper.updateOrderStatusById(orderIds, orderStatus); + } + + @Override + public int close15MinutesOfUnpaidOrders() { + List orderList = getUnpaidOrderListOver15Min(); + if (CollectionUtils.isNotEmpty(orderList)) { + List orderIdList = orderList.stream() + .map(x -> String.valueOf(x.getId())) + .collect(Collectors.toList()); + // 淇敼璁㈠崟鐘舵 + updateOrderStatusById(orderIdList, OrderStatusEnum.ORDER_CLOSE_TIMEOUT.getValue()); + } + return orderList.size(); + } + + /** + * 璁㈠崟閫娆惧鐞嗛昏緫 + */ + private WechatPayRefundResponse refundForOrder(WeChatRefundDTO dto) { + // 鏌ュ埌orderCode瀵瑰簲鐨勬敮浠樿鍗 + // OrderBasicInfo orderInfo = this.getOrderInfoByOrderCode(dto.getOrderCode()); + // // 鏍¢獙璁㈠崟 + // if (Objects.isNull(orderInfo)) { + // logger.warn("orderCode:{}, 璁㈠崟閫娆惧鐞嗛昏緫, 鏌ヨ璁㈠崟涓虹┖!", dto.getOrderCode()); + // throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR); + // } + // // 鍒ゆ柇閫娆鹃噾棰濓紝涓嶈兘澶т簬鏀粯閲戦 + // BigDecimal payAmount = orderInfo.getPayAmount(); + // // BigDecimal orderAmount = orderInfo.getOrderAmount(); + // // BigDecimal amountToBeRefunded = payAmount.subtract(orderAmount); // 鍙閲戦 + // BigDecimal amountToBeRefunded = dto.getRefundAmount(); // 鍙閲戦 + // logger.info("璁㈠崟:{}, 鏀粯閲戦:{}, 闇閫娆鹃噾棰:{}", dto.getOrderCode(), payAmount, amountToBeRefunded); + // if (dto.getRefundAmount().compareTo(amountToBeRefunded) > 0) { + // // 閫娆鹃噾棰濓紝澶т簬鍙閲戦 鎶涘嚭寮傚父 + // logger.warn("閫娆鹃噾棰:{}锛屽ぇ浜庡彲閫閲戦{}, 鎶涘嚭寮傚父", dto.getRefundAmount(), amountToBeRefunded); + // throw new BusinessException(ReturnCodeEnum.CODE_REFUND_ORDER_AMOUNT_ERROR); + // } + // 鏌ュ嚭鏉ュ師鏉ョ殑鏀粯淇℃伅 + WxpayCallbackRecord record = wxpayCallbackRecordService.selectByOrderCode(dto.getOrderCode()); + if (Objects.isNull(record)) { + logger.warn("orderCode:{}, 璁㈠崟閫娆惧鐞嗛昏緫, 鏌ヨ璁㈠崟寰俊鏀粯璁板綍涓虹┖!", dto.getOrderCode()); + throw new BusinessException(ReturnCodeEnum.CODE_REFUND_ORDER_CALLBACK_RECORD_ERROR); + } + + // 鍒ゆ柇鏀粯閲戦鍜岄娆鹃噾棰 + int refundAmountInt = dto.getRefundAmount().multiply(new BigDecimal("100")).intValue(); + int payerTotalInt = Integer.parseInt(record.getPayerTotal()); + if (refundAmountInt > payerTotalInt) { + logger.warn("璁㈠崟鍙:{}, 閫娆鹃噾棰:{}(鍒)锛屽ぇ浜庡彲閫閲戦{}(鍒), 鎶涘嚭寮傚父", dto.getOrderCode(), refundAmountInt, payerTotalInt); + throw new BusinessException(ReturnCodeEnum.CODE_REFUND_ORDER_AMOUNT_ERROR); + } + + // 璋冨井淇¢娆炬帴鍙 + WechatPayRefundRequest request = new WechatPayRefundRequest(); + request.setTransaction_id(record.getTransactionId()); // 寰俊鏀粯鍗曞彿 + request.setOut_trade_no(record.getOutTradeNo()); // 鍟嗘埛璁㈠崟鍙 + // 鐢熸垚閫娆惧崟鍙 + request.setOut_refund_no(SnowflakeIdWorker.getSnowflakeId()); // 鍟嗘埛閫娆惧崟鍙 + request.setNotify_url(WeChatPayParameter.refundNotifyUrl); // 鍥炶皟鎺ュ彛 + WechatPayRefundRequest.Amount amount = new WechatPayRefundRequest.Amount(); + amount.setRefund(refundAmountInt); // 閫娆鹃噾棰 + amount.setTotal(payerTotalInt); // 鍘熻鍗曢噾棰 + request.setAmount(amount); + request.setReason("璁㈠崟缁撶畻閫娆"); + request.setFunds_account("AVAILABLE"); + try { + return wechatPayService.ApplyForWechatPayRefundV3(request); + } catch (JsonProcessingException e) { + logger.error("璋冨井淇¢娆続PI鍙戠敓寮傚父", e); + } + return null; + } + + /** + * 浣欓閫娆惧鐞嗛昏緫 + * + * @param dto + */ + private WechatPayRefundResponse refundForBalance(WeChatRefundDTO dto) { + // 鏌ヤ細鍛樹綑棰 + MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId()); + if (memberVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_MEMBER_NULL_ERROR); + } + // 鏍¢獙閫娆鹃噾棰 + BigDecimal principalBalance = memberVO.getPrincipalBalance(); + BigDecimal refundAmount = dto.getRefundAmount(); + if (refundAmount.compareTo(principalBalance) > 0) { + throw new BusinessException(ReturnCodeEnum.CODE_REFUND_MEMBER_BALANCE_ERROR); + } + // 閫娆鹃噾棰 鍏冭浆鍒 123 + int totalCents = refundAmount.multiply(new BigDecimal(100)).intValue(); + // 鏌ヨ鏈杩戜竴骞翠綑棰濆厖鍊艰鍗 + List recordList = wxpayCallbackRecordService.queryBalanceRechargeRecordOfTheLatestYear(dto.getMemberId()); + // 涔熻闇瑕佸绗旀敮浠樿鍗曟墠澶熼娆 + List requestList = Lists.newArrayList(); + WechatPayRefundRequest request; + for (WxpayCallbackRecord record : recordList) { + int payerTotal = Integer.parseInt(record.getPayerTotal()); // 璇ョ瑪鏀粯璁㈠崟鐨勬敮浠橀噾棰濓紝鍗曚綅鍒 + totalCents = totalCents - payerTotal; // 123 - 100 + request = new WechatPayRefundRequest(); + request.setTransaction_id(record.getTransactionId()); // 寰俊鏀粯鍗曞彿 + request.setOut_trade_no(record.getOutTradeNo()); // 鍟嗘埛璁㈠崟鍙 + request.setOut_refund_no(SnowflakeIdWorker.getSnowflakeId()); // 鍟嗘埛閫娆惧崟鍙 + request.setNotify_url(WeChatPayParameter.refundNotifyUrl); // 鍥炶皟鎺ュ彛 + request.setReason("鐢ㄦ埛浣欓閫娆"); + request.setFunds_account("AVAILABLE"); + if (totalCents > 0) { + // 濡傛灉澶т簬0璇存槑锛岃繖绗斿崟閫瀹屼篃涓嶅 + WechatPayRefundRequest.Amount amount = new WechatPayRefundRequest.Amount(); + amount.setRefund(payerTotal); // 閫娆鹃噾棰 + amount.setTotal(payerTotal); // 鍘熻鍗曢噾棰 + request.setAmount(amount); + requestList.add(request); + } else { + // 濡傛灉灏忎簬0锛岃繖绗斿崟閫涓閮ㄥ垎 + // 鐢熸垚閫娆惧崟鍙 + WechatPayRefundRequest.Amount amount = new WechatPayRefundRequest.Amount(); + // 閮ㄥ垎閫 + int i = payerTotal + totalCents; + amount.setRefund(i); // 閫娆鹃噾棰 + amount.setTotal(payerTotal); // 鍘熻鍗曢噾棰 + request.setAmount(amount); + requestList.add(request); + break; + } + } + // 璋冨井淇¢娆綼pi + if (CollectionUtils.isNotEmpty(requestList)) { + for (WechatPayRefundRequest refundRequest : requestList) { + try { + return wechatPayService.ApplyForWechatPayRefundV3(refundRequest); + // logger.info("璋冨井淇¢娆続PI閫娆====={}", JSONObject.toJSONString(refundRequest)); + } catch (Exception e) { + logger.error("璋冨井淇¢娆続PI鍙戠敓寮傚父", e); + } + } + } + return null; + } + + /** + * 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曡鎯 + * + * @param orderCode 璁㈠崟鍙 + * @return 璁㈠崟璇︽儏 + */ + @Override + public OrderDetail getOrderDetailByOrderCode(String orderCode) { + return orderBasicInfoMapper.getOrderDetailByOrderCode(orderCode); + } + + /** + * 閫氳繃浼氬憳Id鍜岃鍗曠姸鎬佹煡璇㈣鍗曚俊鎭 + * + * @param memberId 浼氬憳id + * @param orderStatusList 璁㈠崟鐘舵侀泦鍚 + * @return + */ + @Override + public List getListByMemberIdAndOrderStatus(String memberId, List orderStatusList) { + return orderBasicInfoMapper.getListByMemberIdAndOrderStatus(memberId, orderStatusList); + } + + /** + * 涓汉妗╂煡璇㈠厖鐢垫暟鎹 + * @param dto + * @return + */ + @Override + public List getAccumulativeInfo(QueryPersonPileDTO dto) { + return orderBasicInfoMapper.getAccumulativeInfo(dto); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderPayRecordServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderPayRecordServiceImpl.java new file mode 100644 index 000000000..05bc9e0e7 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderPayRecordServiceImpl.java @@ -0,0 +1,58 @@ +package com.jsowell.pile.service.impl; + +import com.jsowell.pile.domain.OrderPayRecord; +import com.jsowell.pile.mapper.OrderPayRecordMapper; +import com.jsowell.pile.service.IOrderPayRecordService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class OrderPayRecordServiceImpl implements IOrderPayRecordService { + + @Resource + private OrderPayRecordMapper orderPayRecordMapper; + + + // @Override + // public int deleteByPrimaryKey(Integer id) { + // return orderPayRecordMapper.deleteByPrimaryKey(id); + // } + + // @Override + // public int insert(OrderPayRecord record) { + // return orderPayRecordMapper.insert(record); + // } + // + // @Override + // public int insertSelective(OrderPayRecord record) { + // return orderPayRecordMapper.insertSelective(record); + // } + + // @Override + // public OrderPayRecord selectByPrimaryKey(Integer id) { + // return orderPayRecordMapper.selectByPrimaryKey(id); + // } + + @Override + public int updateByPrimaryKeySelective(OrderPayRecord record) { + return orderPayRecordMapper.updateByPrimaryKeySelective(record); + } + + // @Override + // public int updateByPrimaryKey(OrderPayRecord record) { + // return orderPayRecordMapper.updateByPrimaryKey(record); + // } + + @Override + public int batchInsert(List payRecordList) { + return orderPayRecordMapper.batchInsert(payRecordList); + } + + @Override + public List getOrderPayRecordList(String orderCode) { + return orderPayRecordMapper.getOrderPayRecordList(orderCode); + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java new file mode 100644 index 000000000..4e09b5dc5 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java @@ -0,0 +1,566 @@ +package com.jsowell.pile.service.impl; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.Lists; +import com.jsowell.common.annotation.DataScope; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.enums.ykc.PileConnectorStatusEnum; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.PageUtils; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.PileBasicInfo; +import com.jsowell.pile.domain.PileConnectorInfo; +import com.jsowell.pile.domain.PileSimInfo; +import com.jsowell.pile.dto.IndexQueryDTO; +import com.jsowell.pile.dto.QueryPileDTO; +import com.jsowell.pile.dto.ReplaceMerchantStationDTO; +import com.jsowell.pile.mapper.PileBasicInfoMapper; +import com.jsowell.pile.mapper.PileMemberRelationMapper; +import com.jsowell.pile.service.*; +import com.jsowell.pile.vo.base.MerchantInfoVO; +import com.jsowell.pile.vo.base.PileInfoVO; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO; +import com.jsowell.pile.vo.web.IndexGeneralSituationVO; +import com.jsowell.pile.vo.web.PileDetailVO; +import com.jsowell.pile.vo.web.PileModelInfoVO; +import com.jsowell.pile.vo.web.SimCardVO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 璁惧绠$悊Service涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-08-26 + */ +@Slf4j +@Service +public class PileBasicInfoServiceImpl implements IPileBasicInfoService { + @Autowired + private PileBasicInfoMapper pileBasicInfoMapper; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + @Autowired + private IPileModelInfoService pileModelInfoService; + + @Autowired + private IPileMerchantInfoService pileMerchantInfoService; + + @Autowired + private IPileSimInfoService pileSimInfoService; + + @Autowired + private SimCardService simCardService; + + @Autowired + private RedisCache redisCache; + + @Value("${qrcodeurl.prefix}") + private String QRCODE_URL_PREFIX; + + /** + * 鏌ヨ璁惧绠$悊 + * + * @param id 璁惧绠$悊涓婚敭 + * @return 璁惧绠$悊 + */ + @Override + public PileBasicInfo selectPileBasicInfoById(Long id) { + return pileBasicInfoMapper.selectPileBasicInfoById(id); + } + + @Override + public PileBasicInfo selectPileBasicInfoBySN(String pileSn) { + return pileBasicInfoMapper.selectPileBasicInfoBySn(pileSn); + } + + /** + * 鏌ヨ璁惧绠$悊鍒楄〃 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 璁惧绠$悊 + */ + @Override + public List selectPileBasicInfoList(PileBasicInfo pileBasicInfo) { + return pileBasicInfoMapper.selectPileBasicInfoList(pileBasicInfo); + } + + /** + * 鏂板璁惧绠$悊 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 缁撴灉 + */ + @Override + public int insertPileBasicInfo(PileBasicInfo pileBasicInfo) { + pileBasicInfo.setCreateBy(SecurityUtils.getUsername()); + pileBasicInfo.setCreateTime(DateUtils.getNowDate()); + return pileBasicInfoMapper.insertPileBasicInfo(pileBasicInfo); + } + + /** + * 淇敼璁惧绠$悊 + * + * @param pileBasicInfo 璁惧绠$悊 + * @return 缁撴灉 + */ + @Override + public int updatePileBasicInfo(PileBasicInfo pileBasicInfo) { + // pileBasicInfo.setUpdateBy(SecurityUtils.getUsername()); + pileBasicInfo.setUpdateTime(DateUtils.getNowDate()); + return pileBasicInfoMapper.updatePileBasicInfo(pileBasicInfo); + } + + /** + * 鎵归噺鍒犻櫎璁惧绠$悊 + * + * @param ids 闇瑕佸垹闄ょ殑璁惧绠$悊涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deletePileBasicInfoByIds(Long[] ids) { + return pileBasicInfoMapper.deletePileBasicInfoByIds(ids); + } + + /** + * 鍒犻櫎璁惧绠$悊淇℃伅 + * + * @param id 璁惧绠$悊涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deletePileBasicInfoById(Long id) { + return pileBasicInfoMapper.deletePileBasicInfoById(id); + } + + /** + * 鏌ヨ鍏呯數妗╀俊鎭 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 鍏呯數妗╀俊鎭泦鍚 + */ + @Override + @DataScope(deptAlias = "t2") + public List queryPileInfos(QueryPileDTO dto) { + log.info("queryPileInfos dto:{}", JSONObject.toJSONString(dto)); + // 棣栧厛涓嶅垎椤垫煡璇㈡墍鏈夌鍚堟潯浠剁殑鍏呯數妗 + List pileInfoVOS = queryPileInfoList(dto); + // 鑾峰彇妗﹕n鍒楄〃 + List pileSnList = pileInfoVOS.stream().map(PileDetailVO::getPileSn).collect(Collectors.toList()); + // log.info("鑾峰彇妗﹕n鍒楄〃:{}", JSONObject.toJSONString(pileSnList)); + // 鎵归噺鑾峰彇妗╃姸鎬 key:妗╃紪鍙; value:鐘舵 + Map pileStatusMap = pileConnectorInfoService.getPileStatus(pileSnList); + // log.info("鎵归噺鑾峰彇妗╃姸鎬:{}", JSONObject.toJSONString(pileStatusMap)); + // 鏍规嵁鐘舵佽繃婊 + List snList = Lists.newArrayList(); + if (StringUtils.isNotBlank(dto.getStatus())) { + for (Map.Entry entry : pileStatusMap.entrySet()) { + String pileSn = entry.getKey(); + String pileStatus = entry.getValue(); + if (StringUtils.equals(dto.getStatus(), pileStatus)) { + snList.add(pileSn); + } + } + } else { + // 涓嶆牴鎹姸鎬佽繃婊わ紝snList灏辩瓑浜巔ileSnList + snList = pileSnList; + // 鏍规嵁鐘舵佹帓搴 + + } + + if (CollectionUtils.isEmpty(snList)) { + return Lists.newArrayList(); + } + // 浣跨敤snList鏌ヨ 鍒嗛〉 + if (dto.getPageNum() != 0) { + PageUtils.startPage(); + } + QueryPileDTO queryPileDTO = new QueryPileDTO(); + queryPileDTO.setPileSns(snList); + pileInfoVOS = queryPileInfoList(queryPileDTO); + + for (PileDetailVO pileInfoVO : pileInfoVOS) { + pileInfoVO.setStatus(pileStatusMap.get(pileInfoVO.getPileSn())); + } + return pileInfoVOS; + } + + @Override + // @DataScope(deptAlias = "t1") + public List queryPileInfoList(QueryPileDTO queryPileDTO) { + return pileBasicInfoMapper.queryPileInfos(queryPileDTO); + } + + /** + * 閫氳繃pileId鏇存敼杩愯惀鍟嗐佺珯鐐逛俊鎭 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 缁撴灉 + */ + @Override + public int replaceMerchantStationByPileIds(ReplaceMerchantStationDTO dto) { + dto.setUpdateBy(SecurityUtils.getUsername()); + dto.setUpdateTime(DateUtils.getNowDate()); + int num = pileBasicInfoMapper.replaceMerchantStationByPileIds(dto); + // 淇敼鏋彛淇℃伅 + if (dto.getConnectorNum() != null && dto.getConnectorNum() > 0) { + // 鍏堝垹鍚庢彃 + pileConnectorInfoService.deletePileConnectorInfoByPileSnList(dto.getPileSnList()); + List connectorInfoList = Lists.newArrayList(); + for (String pileSn : dto.getPileSnList()) { + for (int i = 1; i < dto.getConnectorNum() + 1; i++) { + // 缁勮pile_connector_info琛ㄦ暟鎹 + PileConnectorInfo connectorInfo = new PileConnectorInfo(); + connectorInfo.setPileSn(pileSn); // sn鍙 + String connectorCode = String.format("%1$02d", i); + connectorInfo.setPileConnectorCode(pileSn + connectorCode); // 鏋彛缂栧彿 + connectorInfo.setStatus(Constants.ZERO); //鐘舵侊紝榛樿 0-绂荤綉 + connectorInfo.setCreateBy(SecurityUtils.getUsername()); // 鍒涘缓浜 + connectorInfo.setDelFlag(Constants.DEL_FLAG_NORMAL); // 鍒犻櫎鏍囪瘑 + connectorInfoList.add(connectorInfo); + } + } + if (CollectionUtils.isNotEmpty(connectorInfoList)) { + pileConnectorInfoService.batchInsertConnectorInfo(connectorInfoList); + } + } + return num; + } + + /** + * 閫氳繃妗﹊d鏌ヨbasic淇℃伅 + * + * @param id 妗﹊d + * @return 缁撴灉闆嗗悎 + */ + @Override + public PileDetailVO selectBasicInfoById(Long id) { + PileDetailVO pileInfoVO = pileBasicInfoMapper.selectBasicInfoById(id); + if (pileInfoVO == null) { + return null; + } + // 鑾峰彇妗╃姸鎬 + Map pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileInfoVO.getPileSn())); + pileInfoVO.setStatus(pileStatusMap.get(pileInfoVO.getPileSn())); + // String url = "http://localhost:8080/uniapp/pile/pileDetail/"; + String pileQrCodeUrl = getPileQrCodeUrl(pileInfoVO.getPileSn()); + pileInfoVO.setQrCodeURL(pileQrCodeUrl); + // 棰濆畾鍔熺巼 鐡︽敼涓哄崈鐡(2023.2.8鍙戠幇鏁版嵁搴撲腑鍨嬪彿琛ㄥ凡缁忓瓨鐨勫崟浣嶆槸 kw锛屽洜姝ゆ敞閲婃帀) + // pileInfoVO.setRatedPower(pileInfoVO.getRatedPower() / 1000); + return pileInfoVO; + } + + @Override + public PileInfoVO selectPileInfoBySn(String pileSn) { + PileBasicInfo basicInfo = pileBasicInfoMapper.selectPileBasicInfoBySn(pileSn); + if (basicInfo == null) { + return null; + } + + PileInfoVO pileInfoVO = PileInfoVO.builder() + .pileId(String.valueOf(basicInfo.getId())) + .pileSn(basicInfo.getSn()) + .stationId(String.valueOf(basicInfo.getStationId())) + .merchantId(String.valueOf(basicInfo.getMerchantId())) + .build(); + // 鏌ョ珯鐐逛俊鎭 + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(basicInfo.getMerchantId())); + if (merchantInfo != null) { + pileInfoVO.setMerchantName(merchantInfo.getMerchantName()); + } + + // 鏌ヨ鍏呯數妗╅瀹氬姛鐜 + PileModelInfoVO pileModelInfoVO = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + if (pileModelInfoVO != null) { + pileInfoVO.setRatedPower(pileModelInfoVO.getRatedPower()); + pileInfoVO.setRatedCurrent(pileModelInfoVO.getRatedCurrent()); + pileInfoVO.setRatedVoltage(pileModelInfoVO.getRatedVoltage()); + } + return pileInfoVO; + } + + @Override + public List selectPileListByStationIds(List stationIdList) { + // 鍔犵紦瀛 + List pileInfoVOS = pileBasicInfoMapper.selectPileListByStationIds(stationIdList); + if (CollectionUtils.isEmpty(pileInfoVOS)) { + return Lists.newArrayList(); + } + List pileSnList = pileInfoVOS.stream().map(PileDetailVO::getPileSn).collect(Collectors.toList()); + Map pileStatusMap = pileConnectorInfoService.getPileStatus(pileSnList); + for (PileDetailVO pileInfoVO : pileInfoVOS) { + pileInfoVO.setStatus(pileStatusMap.get(pileInfoVO.getPileSn())); + } + return pileInfoVOS; + } + + /** + * 閫氳繃妗﹕n鍙锋煡璇㈢珯鐐筰d + * + * @param sn 妗﹕n鍙 + * @return 绔欑偣id + */ + // @Override + // public String selectStationIdBySn(String sn) { + // return pileBasicInfoMapper.selectStationIdBySn(sn); + // } + + /** + * uniApp閫氳繃妗╁彿鏌ヨ妗╄鎯 + * + * @param pileSn 妗╁彿 + * @return + */ + // @Override + // public PileDetailVO uniAppGetPileDetailByPileSn(String pileSn) { + // PileDetailVO pileDetailVO = pileBasicInfoMapper.uniAppGetPileDetailByPileSn(pileSn); + // // 鏌ヨ璁¤垂妯℃澘 + // BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn); + // if (Objects.nonNull(billingTemplateVO)) { + // pileDetailVO.setBillingTemplate(billingTemplateVO); + // + // } + // // 鏌ヨ鏋彛鐩稿叧淇℃伅 + // List connectorList = new ArrayList<>(); + // + // return pileDetailVO; + // } + + /** + * 淇敼鐘舵 + * 鐢ㄤ簬鐧婚檰鍗忚锛屽績璺冲寘鍗忚锛屼笂浼犲疄鏃舵暟鎹崗璁 鏇存柊鐘舵佺殑鏂规硶 + * 鏁版嵁搴撶姸鎬 + * 鍏呯數鏋細0-绂荤嚎锛1-绌洪棽锛2-鍗犵敤锛堟湭鍏呯數锛夛紱3-鍗犵敤锛堝厖鐢典腑锛夛紱4-鍗犵敤锛堥绾﹂攣瀹氾級锛255-鏁呴殰 + *

+ * 鍏呯數鏋彛鐘舵佸湪浠ヤ笅鎯呭喌浼氭敼鍙 + * 1.鐧婚檰鎴愬姛鍚庯紝璁剧疆涓恒1-绌洪棽銆 + * 2.蹇冭烦鍖呬紶0x01鏁呴殰锛岃缃负銆255-鏁呴殰銆 + * 3.涓婁紶瀹炴椂鏁版嵁锛屾灙鐘舵佷紶0x00绂荤嚎锛岃缃负銆0-绂荤嚎銆 + * 4.涓婁紶瀹炴椂鏁版嵁锛屾灙鐘舵佷紶0x01鏁呴殰锛岃缃负銆255-鏁呴殰銆 + * 5.涓婁紶瀹炴椂鏁版嵁锛屾灙鐘舵佷紶0x02绌洪棽锛屽苟涓斾负鎻掓灙鐘舵侊紝璁剧疆涓恒2-鍗犵敤锛堟湭鍏呯數锛夈 + * 6.涓婁紶瀹炴椂鏁版嵁锛屾灙鐘舵佷紶0x02绌洪棽锛屽苟涓斾负鏈彃鏋姸鎬侊紝璁剧疆涓恒1-绌洪棽銆 + * 7.涓婁紶瀹炴椂鏁版嵁锛屾灙鐘舵佷紶0x03鍏呯數锛岃缃负銆3-鍗犵敤锛堝厖鐢典腑锛夈 + */ + @Override + public void updateStatus(String frameType, String pileSn, String connectorCode, String status, String putGunType) { + // log.info("updateStatus浼犲弬锛氬抚绫诲瀷:{}, 妗╃紪鍙:{}, 鏋彛鍙:{}, 鐘舵:{}, 鎻掓嫈鏋:{}", "0x" + frameType, pileSn, connectorCode, status, putGunType); + /* + 0x01 鐧婚檰璁よ瘉 + 鐧婚檰鎴愬姛锛屾妸鍏呯數妗╁拰鏋彛鐨勭姸鎬侀兘鏇存柊涓恒愬湪绾裤 + */ + if (StringUtils.equals(frameType, String.valueOf(YKCFrameTypeCode.LOGIN_CODE.getCode()))) { + // 鏋彛鐘舵佽缃负銆愮┖闂层 + pileConnectorInfoService.updateConnectorStatusByPileSn(pileSn, PileConnectorDataBaseStatusEnum.FREE.getValue()); + } + + /* + 0x03 蹇冭烦鍖 鏋彛鐘舵 0-姝e父 1-鏁呴殰 + 蹇冭烦鍖呬細浼犺繃鏉ユ灙鍙g殑鐘舵侊紝鐢辨灙鍙g姸鎬佹帹瀵煎嚭鏉ュ厖鐢垫々鐨勭姸鎬併備换鎰忎竴涓灙鍙g姸鎬佷负鏁呴殰锛屽垯鍏呯數妗╃姸鎬佷篃鏄晠闅 + */ + if (StringUtils.equals(frameType, BytesUtil.bcd2Str(YKCFrameTypeCode.HEART_BEAT_CODE.getBytes()))) { + // log.info("蹇冭烦鍖呯殑淇敼鐘舵侀昏緫 妗╁彿:{}, 鏋彿:{}, 鏋姸鎬:{}", pileSn, connectorCode, status); + + /* + 鏇存柊鍏呯數妗╂帴鍙g殑鏁版嵁搴撶姸鎬 + 浼犲叆鐨勭姸鎬佷负銆1-鏁呴殰銆戯紝灏辨妸鏋彛鏁版嵁搴撴敼涓烘晠闅 + */ + if (StringUtils.equals(status, Constants.ONE)) { + // 鏁呴殰 + pileConnectorInfoService.updateConnectorStatus(pileSn + connectorCode, PileConnectorDataBaseStatusEnum.FAULT.getValue()); + } else { + // 姝e父 + // List connectorInfoList = pileConnectorInfoService.selectPileConnectorInfoList(pileSn); + // for (PileConnectorInfo connectorInfo : connectorInfoList) { + // // 鏀跺埌蹇冭烦鍖咃紝鍙湁鍦ㄧ绾挎垨鏁呴殰鏃讹紝淇敼涓虹┖闂茬姸鎬 + // if (StringUtils.equals(connectorInfo.getStatus(), PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue()) + // || StringUtils.equals(connectorInfo.getStatus(), PileConnectorDataBaseStatusEnum.FAULT.getValue())) { + // pileConnectorInfoService.updateConnectorStatus(pileSn + connectorCode, PileConnectorDataBaseStatusEnum.FREE.getValue()); + // } + // } + } + } + + /* + 0x13 涓婁紶瀹炴椂鏁版嵁 鏋彛鐘舵 0x00锛氱绾 0x01锛氭晠闅 0x02锛氱┖闂 0x03锛氬厖鐢 + 鏍规嵁浼犳潵鐨勬灙鐘舵佸拰鏄惁鎻掓灙锛屽垽鏂姸鎬 + */ + if (StringUtils.equals(frameType, BytesUtil.bcd2Str(YKCFrameTypeCode.UPLOAD_REAL_TIME_MONITOR_DATA_CODE.getBytes())) + || StringUtils.equals(frameType, BytesUtil.bcd2Str(YKCFrameTypeCode.UPLOAD_REAL_TIME_MONITOR_DATA_OLD_VERSION_CODE.getBytes()))) { + // log.info("涓婁紶瀹炴椂鏁版嵁涓殑淇敼鐘舵侀昏緫 妗╁彿:{}, 鏋彿:{}, 鏋姸鎬亄}, 鏄惁鎻掓灙锛歿}", pileSn, connectorCode, status, putGunType); + /** + * 鏇存柊鏋姸鎬 + * connectorStatus 妗╀紶杩囨潵鐨勬灙鍙g姸鎬侊細 0x00锛氱绾 0x01锛氭晠闅 0x02锛氱┖闂 0x03锛氬厖鐢 + * 鏁版嵁搴撶姸鎬侊細0锛氱缃 (榛樿)锛1锛氱┖闂诧紱2锛氬崰鐢紙鏈厖鐢碉級锛3锛氬崰鐢紙鍏呯數涓級锛4锛氬崰鐢紙棰勭害閿佸畾锛 锛255锛氭晠闅 + */ + String statusDataBase = ""; // 浼犵粰鏁版嵁搴撶殑鐘舵 + if (StringUtils.equals(status, PileConnectorStatusEnum.OFF_NETWORK.getValue())) { // 绂荤嚎 + statusDataBase = PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue(); + } else if (StringUtils.equals(status, PileConnectorStatusEnum.FAULT.getValue())) { // 鏁呴殰 + statusDataBase = PileConnectorDataBaseStatusEnum.FAULT.getValue(); + } else if (StringUtils.equals(status, PileConnectorStatusEnum.FREE.getValue())) { // 绌洪棽 + //鏄惁鎻掓灙 0x00锛氬惁 0x01锛氭槸 + if (StringUtils.equals(putGunType, Constants.ZERO_ONE)) { + // 绌洪棽骞舵彃鏋 璁剧疆涓恒愬崰鐢紙鏈厖鐢碉級銆 + statusDataBase = PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(); + } else { + // 绌洪棽娌℃彃鏋 璁剧疆涓恒愮┖闂层 + statusDataBase = PileConnectorDataBaseStatusEnum.FREE.getValue(); + } + } else if (StringUtils.equals(status, PileConnectorStatusEnum.OCCUPIED_CHARGING.getValue())) { // 鍏呯數 + // 璁剧疆涓恒愬崰鐢紙鍏呯數涓級銆 + statusDataBase = PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(); + } + pileConnectorInfoService.updateConnectorStatus(pileSn + connectorCode, statusDataBase); + } + } + + /** + * 鍏呯數妗╂鍦ㄥ厖鐢垫椂鐨勫疄鏃舵暟鎹瓨鍒皉edis + * @param realTimeMonitorData 瀹炴椂鏁版嵁 + */ + @Override + public void saveRealTimeMonitorData2Redis(RealTimeMonitorData realTimeMonitorData) { + // 淇濆瓨鍒皉edis + String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + realTimeMonitorData.getPileConnectorCode() + "_" + realTimeMonitorData.getOrderCode(); + + // 璁剧疆鎺ユ敹鍒板疄鏃舵暟鎹殑鏃堕棿 + Date now = new Date(); + realTimeMonitorData.setDateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now)); + // 璁$畻鍔熺巼锛屽悗闈㈡煡璇㈣鐢 + String power = new BigDecimal(realTimeMonitorData.getOutputVoltage()) + .multiply(new BigDecimal(realTimeMonitorData.getOutputCurrent())).setScale(2, BigDecimal.ROUND_HALF_UP).toString(); + realTimeMonitorData.setOutputPower(power); + // 淇濆瓨json瀛楃涓 + String jsonMsg = JSONObject.toJSONString(realTimeMonitorData); + // 涓婁紶瀹炴椂鏁版嵁姣10绉掑彂閫佷竴娆★紝1鍒嗛挓6娆★紝鍦ㄥ悓涓鍒嗛挓鍐咃紝鍙繚鐣欐渶鍚庝竴鏉″疄鏃舵暟鎹 + redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", now), jsonMsg); + } + + @Override + public PileConnectorDetailVO queryPileConnectorDetail(String pileConnectorCode) { + return pileBasicInfoMapper.queryPileConnectorDetail(pileConnectorCode); + } + + /** + * 杩斿洖鍏呯數妗╀簩缁寸爜 + * @param pileSn 濡傚厖鐢垫々缂栧彿涓虹┖锛屽垯杩斿洖鍓嶇紑 https://api.jsowellcloud.com/app-xcx-h5/pile/pileDetail/ + * @return + */ + @Override + public String getPileQrCodeUrl(String pileSn) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(QRCODE_URL_PREFIX); + stringBuilder.append("/app-xcx-h5/pile/pileDetail/"); + if (StringUtils.isNotEmpty(pileSn)) { + if (!stringBuilder.toString().endsWith("/")) { + stringBuilder.append("/"); + } + stringBuilder.append(pileSn); + } + return stringBuilder.toString(); + } + + @Override + public void updatePileSimInfo(String pileSn, String iccid) { + PileBasicInfo basicInfo = selectPileBasicInfoBySN(pileSn); + if (basicInfo == null) { + return; + } + // 閫氳繃iccid鏌ile_sim_info + PileSimInfo simInfo = pileSimInfoService.getBasicInfoByIccId(iccid); + if (simInfo == null) { + SimCardVO simCardVO = simCardService.searchByLoop(iccid); + // pile_sim_info 鏂板鏁版嵁 + if (simCardVO != null) { + simInfo = PileSimInfo.builder() + .iccid(iccid) + .name(simCardVO.getName()) + .simSupplier(simCardVO.getSimCardFactory()) + .expireTime(DateUtils.parseDate(simCardVO.getExpiredTime())) + .operator(simCardVO.getSimCardOperator()) + .status(simCardVO.getSimCardStatus()) + .surplusData(String.valueOf(simCardVO.getResidualFlowRate())) + .totalData(String.valueOf(simCardVO.getPackageCapacity())) + .build(); + }else { + // 鍗″晢鏈煡鍒颁俊鎭紝璁板綍涓烘柊鍗★紝鍙瓨鍗″彿 + simInfo = PileSimInfo.builder() + .iccid(iccid) + .build(); + } + pileSimInfoService.insertPileSimInfo(simInfo); + // 鎷垮埌id + Long simId = simInfo.getId(); + log.info("鏂颁繚瀛樼殑sim鍗d:{}", simId); + // sim_id 鏇存柊鍒皃ile_basic_info + basicInfo.setSimId(simId); + } else { + // sim淇℃伅宸茬粡瀛樺簱浜 鐒跺悗鏇存柊鍏呯數妗╃殑sim鍗 + basicInfo.setSimId(simInfo.getId()); + } + updatePileBasicInfo(basicInfo); + } + + /** + * 鍚庣棣栭〉鍩烘湰淇℃伅鏌ヨ + * + * @param dto 绔欑偣Id + * @return 棣栭〉鍩烘湰淇℃伅 + */ + @Override + public IndexGeneralSituationVO getGeneralSituation(IndexQueryDTO dto) { + // + return pileBasicInfoMapper.getGeneralSituation(dto); + } + + /** + * 閫氳繃浼氬憳id鏌ヨ涓汉妗╁垪琛 + * @param memberId + * @return + */ + @Override + public List getPileInfoByMemberId(String memberId) { + List list = pileBasicInfoMapper.getPileInfoByMemberId(memberId); + if(CollectionUtils.isEmpty(list)){ + return null; + } + + for (PersonalPileInfoVO personalPileInfoVO : list) { + String pileSn = personalPileInfoVO.getPileSn(); + + // 鑾峰彇妗╃姸鎬 + Map pileStatus = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn)); + personalPileInfoVO.setPileStatus(pileStatus.get(pileSn)); + if (StringUtils.equals("1", personalPileInfoVO.getType())) { + personalPileInfoVO.setType("绠$悊鍛樼敤鎴"); + }else { + personalPileInfoVO.setType("鏅氱敤鎴"); + } + if (StringUtils.equals("1", personalPileInfoVO.getSpeedType())) { + personalPileInfoVO.setSpeedType("蹇厖"); + }else { + personalPileInfoVO.setSpeedType("鎱㈠厖"); + } + } + return list; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBillingTemplateServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBillingTemplateServiceImpl.java new file mode 100644 index 000000000..f09382280 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBillingTemplateServiceImpl.java @@ -0,0 +1,619 @@ +package com.jsowell.pile.service.impl; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.primitives.Bytes; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.enums.DelFlagEnum; +import com.jsowell.common.enums.ykc.BillingTimeEnum; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.common.util.id.Seq; +import com.jsowell.pile.domain.PileBillingDetail; +import com.jsowell.pile.domain.PileBillingRelation; +import com.jsowell.pile.domain.PileBillingTemplate; +import com.jsowell.pile.dto.BillingTimeDTO; +import com.jsowell.pile.dto.CreateOrUpdateBillingTemplateDTO; +import com.jsowell.pile.dto.ImportBillingTemplateDTO; +import com.jsowell.pile.mapper.PileBillingTemplateMapper; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileBillingTemplateService; +import com.jsowell.pile.transaction.dto.BillingTemplateTransactionDTO; +import com.jsowell.pile.transaction.service.TransactionService; +import com.jsowell.pile.vo.uniapp.BillingPriceVO; +import com.jsowell.pile.vo.uniapp.CurrentTimePriceDetails; +import com.jsowell.pile.vo.web.BillingDetailVO; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import com.jsowell.pile.vo.web.EchoBillingTemplateVO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * 璁¤垂妯℃澘Service涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-09-20 + */ +@Slf4j +@Service +public class PileBillingTemplateServiceImpl implements IPileBillingTemplateService { + @Autowired + private PileBillingTemplateMapper pileBillingTemplateMapper; + + @Autowired + private TransactionService transactionService; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + /** + * 鏌ヨ璁¤垂妯℃澘 + * + * @param id 璁¤垂妯℃澘涓婚敭 + * @return 璁¤垂妯℃澘 + */ + @Override + public PileBillingTemplate selectPileBillingTemplateById(Long id) { + return pileBillingTemplateMapper.selectPileBillingTemplateById(id); + } + + /** + * 鏌ヨ璁¤垂妯℃澘鍒楄〃 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 璁¤垂妯℃澘 + */ + @Override + public List selectPileBillingTemplateList(PileBillingTemplate pileBillingTemplate) { + return pileBillingTemplateMapper.selectPileBillingTemplateList(pileBillingTemplate); + } + + /** + * 鏂板璁¤垂妯℃澘 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 缁撴灉 + */ + @Transactional + @Override + public int insertPileBillingTemplate(PileBillingTemplate pileBillingTemplate) { + pileBillingTemplate.setCreateTime(DateUtils.getNowDate()); + int rows = pileBillingTemplateMapper.insertPileBillingTemplate(pileBillingTemplate); + insertPileBillingDetail(pileBillingTemplate); + return rows; + } + + /** + * 淇敼璁¤垂妯℃澘 + * + * @param pileBillingTemplate 璁¤垂妯℃澘 + * @return 缁撴灉 + */ + @Transactional + @Override + public int updatePileBillingTemplate(PileBillingTemplate pileBillingTemplate) { + return pileBillingTemplateMapper.updatePileBillingTemplate(pileBillingTemplate); + } + + /** + * 鎵归噺鍒犻櫎璁¤垂妯℃澘 + * + * @param ids 闇瑕佸垹闄ょ殑璁¤垂妯℃澘涓婚敭 + * @return 缁撴灉 + */ + @Transactional + @Override + public int deletePileBillingTemplateByIds(Long[] ids) { + // 鏌ヨ璁¤垂妯℃澘璇︽儏鍒楄〃 + List pileBillingDetails = pileBillingTemplateMapper.queryBillingDetailByTemplateIds(ids); + if (CollectionUtils.isNotEmpty(pileBillingDetails)) { + List templateCodes = pileBillingDetails.stream().map(PileBillingDetail::getTemplateCode).collect(Collectors.toList()); + pileBillingTemplateMapper.deletePileBillingDetailByTemplateCodes(templateCodes); + } + return pileBillingTemplateMapper.deletePileBillingTemplateByIds(ids); + } + + /** + * 鍒犻櫎璁¤垂妯℃澘淇℃伅 + * + * @param id 璁¤垂妯℃澘涓婚敭 + * @return 缁撴灉 + */ + @Transactional + @Override + public int deletePileBillingTemplateById(Long id) { + // pileBillingTemplateMapper.deletePileBillingDetailByTemplateCode(id); + return pileBillingTemplateMapper.deletePileBillingTemplateById(id); + } + + @Override + public void createBillingTemplate(CreateOrUpdateBillingTemplateDTO dto) { + // 鐢熸垚璁¤垂妯℃澘缂栧彿 + String templateCode = Seq.getId(); + // 缁勮鍏ュ簱鍙傛暟 + PileBillingTemplate billingTemplate = new PileBillingTemplate(); + billingTemplate.setName(dto.getName()); + billingTemplate.setType(String.valueOf(dto.getType())); + billingTemplate.setRemark(dto.getRemark()); + billingTemplate.setTemplateCode(templateCode); + billingTemplate.setCreateBy(SecurityUtils.getUsername()); + billingTemplate.setDelFlag(DelFlagEnum.normal.getValue()); + if (StringUtils.isBlank(dto.getStationId())) { + // 鍏叡妯℃澘鏍囪瘑锛0-绉佹湁锛1-鍏叡锛 + billingTemplate.setPublicFlag(Constants.ONE); + } else { + billingTemplate.setPublicFlag(Constants.ZERO); + } + + // key涓烘椂闂寸被鍨嬶紝value涓烘椂闂存弿杩 + Map> map = dto.getTimeArray().stream() + .collect(Collectors.groupingBy(BillingTimeDTO::getType)); + + // 璁¤垂妯℃澘璇︽儏 + List detailList = Lists.newArrayList(); + PileBillingDetail detail = null; + for (BillingTimeEnum billingTimeEnum : BillingTimeEnum.values()) { + detail = new PileBillingDetail(); + detail.setTemplateCode(templateCode); + String type = billingTimeEnum.getValue(); // 鏃舵绫诲瀷 + detail.setTimeType(type); + Map priceMap = getPriceMap(dto, type); + detail.setElectricityPrice(priceMap.get("electricityPrice")); + detail.setServicePrice(priceMap.get("servicePrice")); + List entryValue = map.get(type); + String applyTime = ""; + if (CollectionUtils.isNotEmpty(entryValue)) { + applyTime = entryValue.stream() + .map(x -> x.getStartTime() + "-" + x.getEndTime()) + .collect(Collectors.joining(",")); + } + detail.setApplyTime(applyTime); + detail.setCreateBy(SecurityUtils.getUsername()); + detailList.add(detail); + } + + BillingTemplateTransactionDTO build = BillingTemplateTransactionDTO.builder() + .billingTemplate(billingTemplate) + .detailList(detailList) + .build(); + // 鍏ュ簱 + transactionService.doCreateBillingTemplate(build); + } + + @Override + public void updateBillingTemplate(CreateOrUpdateBillingTemplateDTO dto) { + PileBillingTemplate billingTemplate = selectPileBillingTemplateById(Long.valueOf(dto.getBillingTemplateId())); + if (billingTemplate == null) { + log.info("鏍规嵁璁¤垂妯℃澘id锛歿}锛屾煡璇负null銆傛棤娉曚慨鏀圭洿鎺ヨ繑鍥", dto.getBillingTemplateId()); + return; + } + billingTemplate.setName(dto.getName()); + billingTemplate.setType(String.valueOf(dto.getType())); + billingTemplate.setRemark(dto.getRemark()); + billingTemplate.setUpdateBy(SecurityUtils.getUsername()); + + // key涓烘椂闂寸被鍨嬶紝value涓烘椂闂存弿杩 + Map> map = dto.getTimeArray().stream() + .collect(Collectors.groupingBy(BillingTimeDTO::getType)); + + // 璁¤垂妯℃澘璇︽儏 + List detailList = Lists.newArrayList(); + PileBillingDetail detail = null; + for (BillingTimeEnum billingTimeEnum : BillingTimeEnum.values()) { + detail = new PileBillingDetail(); + detail.setTemplateCode(billingTemplate.getTemplateCode()); + String type = billingTimeEnum.getValue(); // 鏃舵绫诲瀷 + detail.setTimeType(type); + Map priceMap = getPriceMap(dto, type); + detail.setElectricityPrice(priceMap.get("electricityPrice")); + detail.setServicePrice(priceMap.get("servicePrice")); + List entryValue = map.get(type); + String applyTime = ""; + if (CollectionUtils.isNotEmpty(entryValue)) { + applyTime = entryValue.stream() + .map(x -> x.getStartTime() + "-" + x.getEndTime()) + .collect(Collectors.joining(",")); + } + detail.setApplyTime(applyTime); + detail.setCreateBy(SecurityUtils.getUsername()); + detailList.add(detail); + } + + BillingTemplateTransactionDTO build = BillingTemplateTransactionDTO.builder() + .billingTemplate(billingTemplate) + .detailList(detailList) + .build(); + // 鍏ュ簱 + transactionService.doUpdateBillingTemplate(build); + } + + @Override + public EchoBillingTemplateVO queryPileBillingTemplateById(Long id) { + PileBillingTemplate pileBillingTemplate = selectPileBillingTemplateById(id); + if (pileBillingTemplate == null) { + return null; + } + EchoBillingTemplateVO result = new EchoBillingTemplateVO(); + result.setBillingTemplateId(String.valueOf(id)); + result.setName(pileBillingTemplate.getName()); + result.setRemark(pileBillingTemplate.getRemark()); + result.setType(pileBillingTemplate.getType()); + + // 鏌ヨ璐规ā鏉胯鎯 + List detailList = pileBillingTemplateMapper.queryBillingDetailByTemplateIds(new Long[]{id}); + if (CollectionUtils.isNotEmpty(detailList)) { + List timeArray = Lists.newArrayList(); + // 鍙栧嚭4涓椂闂存绫诲瀷 + for (PileBillingDetail billingDetail : detailList) { + String type = billingDetail.getTimeType(); + BigDecimal electricityPrice = billingDetail.getElectricityPrice(); + BigDecimal servicePrice = billingDetail.getServicePrice(); + if (StringUtils.equals(type, BillingTimeEnum.SHARP.getValue())) { + result.setElectricityPriceA(electricityPrice); + result.setServicePriceA(servicePrice); + } else if (StringUtils.equals(type, BillingTimeEnum.PEAK.getValue())) { + result.setElectricityPriceB(electricityPrice); + result.setServicePriceB(servicePrice); + } else if (StringUtils.equals(type, BillingTimeEnum.FLAT.getValue())) { + result.setElectricityPriceC(electricityPrice); + result.setServicePriceC(servicePrice); + } else if (StringUtils.equals(type, BillingTimeEnum.VALLEY.getValue())) { + result.setElectricityPriceD(electricityPrice); + result.setServicePriceD(servicePrice); + } + // 閫楀彿鎷兼帴鐨勬椂闂存 00:00-01:30,01:30-04:00,23:30-24:00 + String applyTime = billingDetail.getApplyTime(); + if (StringUtils.isBlank(applyTime)) { + continue; + } + List list = Lists.newArrayList(applyTime.split(",")); + BillingTimeDTO timeDTO; + for (String s : list) { + String[] split = s.split("-"); + timeDTO = new BillingTimeDTO(); + timeDTO.setType(type); + timeDTO.setStartTime(split[0]); + timeDTO.setEndTime(split[1]); + timeArray.add(timeDTO); + } + } + // timeArray閲嶆柊鎺掑簭 + result.setTimeArray(timeArray.stream().sorted(Comparator.comparing(BillingTimeDTO::getStartTime)).collect(Collectors.toList())); + } + return result; + } + + /** + * 閫氳繃绔欑偣id鏌ヨ褰撳墠鏃堕棿鐨勬敹璐硅鎯 + * + * @param stationId 绔欑偣id + */ + @Override + public CurrentTimePriceDetails getCurrentTimePriceDetails(String stationId) { + CurrentTimePriceDetails result = null; + // 鏌ヨ褰撳墠鏃舵鐢佃垂 + LocalTime localTime = LocalTime.now(); + String now = LocalTime.of(localTime.getHour(), localTime.getMinute(), localTime.getSecond()).toString(); + // 閫氳繃绔欑偣id鏌ヨ璁¤垂妯℃澘 + BillingTemplateVO billingTemplateVO = pileBillingTemplateMapper.selectBillingTemplateByStationId(stationId); + if (Objects.nonNull(billingTemplateVO)) { + result = new CurrentTimePriceDetails(); + result.setTemplateCode(billingTemplateVO.getTemplateCode()); + result.setStationId(stationId); + result.setDateTime(localTime.toString()); + + List billingDetailList = billingTemplateVO.getBillingDetailList(); + for (BillingDetailVO detailVO : billingDetailList) { + List applyTimeList = detailVO.getApplyTime(); + for (String applyTime : applyTimeList) { + boolean b = DateUtils.checkTime(now + "-" + now, applyTime); + if (b) { + // 灏嗘々鐨勮垂鐜囧瓨鍏tationVO + BigDecimal electricityPrice = detailVO.getElectricityPrice(); + BigDecimal servicePrice = detailVO.getServicePrice(); + + result.setElectricityPrice(electricityPrice.toString()); + result.setServicePrice(servicePrice.toString()); + result.setTotalPrice(electricityPrice.add(servicePrice).toString()); + } + } + } + } + return result; + } + + @Override + public List queryPublicBillingTemplateList() { + return pileBillingTemplateMapper.queryPublicBillingTemplateList(); + } + + @Override + public List queryStationBillingTemplateList(String stationId) { + if (StringUtils.isBlank(stationId)) { + return Lists.newArrayList(); + } + return pileBillingTemplateMapper.queryStationBillingTemplateList(stationId); + } + + /** + * 鏌ヨ姝e湪浣跨敤涓殑璁¤垂妯℃澘 + * 1 鍙戝竷鏃堕棿涓嶄负null + * 2 鏈杩戝彂甯冪殑涓烘鍦ㄤ娇鐢ㄤ腑鐨 + * @param stationId 绔欑偣id + * @return + */ + @Override + public BillingTemplateVO queryUsedBillingTemplate(String stationId) { + List list = queryStationBillingTemplateList(stationId); + Optional max = list.stream() + .filter(x -> StringUtils.isNotBlank(x.getPublishTime())) + .max(Comparator.comparing(BillingTemplateVO::getPublishTime)); + return max.orElse(null); + } + + @Override + public List queryBillingPrice(String stationId) { + BillingTemplateVO billingTemplateVO = queryUsedBillingTemplate(stationId); + if (billingTemplateVO == null) { + return Lists.newArrayList(); + } + EchoBillingTemplateVO echoBillingTemplateVO = queryPileBillingTemplateById(Long.parseLong(billingTemplateVO.getTemplateId())); + List timeArray = echoBillingTemplateVO.getTimeArray(); + log.info("璁¤垂妯℃澘鏃舵:{}", JSONObject.toJSONString(timeArray)); + + List resultList = Lists.newArrayList(); + for (BillingTimeDTO billingTimeDTO : timeArray) { + BillingPriceVO vo = new BillingPriceVO(); + String type = billingTimeDTO.getType(); + if (StringUtils.equals(type, BillingTimeEnum.SHARP.getValue())) { + vo.setElectricityPrice(billingTemplateVO.getSharpElectricityPrice().toString()); + vo.setServicePrice(billingTemplateVO.getSharpServicePrice().toString()); + } else if (StringUtils.equals(type, BillingTimeEnum.PEAK.getValue())) { + vo.setElectricityPrice(billingTemplateVO.getPeakElectricityPrice().toString()); + vo.setServicePrice(billingTemplateVO.getPeakServicePrice().toString()); + } else if (StringUtils.equals(type, BillingTimeEnum.FLAT.getValue())) { + vo.setElectricityPrice(billingTemplateVO.getFlatElectricityPrice().toString()); + vo.setServicePrice(billingTemplateVO.getFlatServicePrice().toString()); + } else if (StringUtils.equals(type, BillingTimeEnum.VALLEY.getValue())) { + vo.setElectricityPrice(billingTemplateVO.getValleyElectricityPrice().toString()); + vo.setServicePrice(billingTemplateVO.getValleyServicePrice().toString()); + } + // 鎬昏垂鐢 + vo.setTotalPrice(new BigDecimal(vo.getElectricityPrice()).add(new BigDecimal(vo.getServicePrice())).toString()); + // 寮濮嬫椂闂 + vo.setStartTime(billingTimeDTO.getStartTime()); + // 缁撴潫鏃堕棿 + String endTime = StringUtils.equals("24:00", billingTimeDTO.getEndTime()) ? "23:59" : billingTimeDTO.getEndTime(); + vo.setEndTime(endTime); + // 鏃舵绫诲瀷 + vo.setTimeType(type); + // 鏄惁褰撳墠鏃堕棿 + boolean in = DateUtils.isIn(LocalTime.now(), LocalTime.parse(vo.getStartTime()), LocalTime.parse(vo.getEndTime())); + vo.setIsCurrentTime(in ? Constants.ONE : Constants.ZERO); + resultList.add(vo); + } + return resultList; + } + + public static void main(String[] args) { + // 21:30-23:00 + String startTime = "01:30"; + String endTime = "23:00"; + boolean in = DateUtils.isIn(LocalTime.now(), LocalTime.parse(startTime), LocalTime.parse(endTime)); + System.out.println(in); + + } + + /** + * 閫氳繃妗﹕n鍙锋煡璇㈣璐规ā鏉 + * + * @param pileSn 妗﹕n + * @return 璁¤垂妯℃澘缂栧彿 + */ + @Override + public BillingTemplateVO selectBillingTemplateDetailByPileSn(String pileSn) { + return pileBillingTemplateMapper.selectBillingTemplateByPileSn(pileSn); + } + + @Override + public boolean stationImportBillingTemplate(ImportBillingTemplateDTO dto) { + // 鏌ヨ鍏叡璁¤垂妯℃澘鏄惁瀛樺湪 + PileBillingTemplate pileBillingTemplate = pileBillingTemplateMapper.selectPileBillingTemplateById(Long.valueOf(dto.getBillingTemplateId())); + if (pileBillingTemplate == null) { + log.warn("鏍规嵁璁¤垂妯℃澘id锛歿}锛屾煡璇负绌", dto.getBillingTemplateId()); + return false; + } + List billingDetailList = pileBillingTemplate.getPileBillingDetailList(); + // 澶嶅埗璁¤垂妯℃澘 + PileBillingTemplate stationBillingTemplate = new PileBillingTemplate(); + + String templateCode = Seq.getId(); // 鐢熸垚璁¤垂妯℃澘缂栧彿 + BeanUtils.copyProperties(pileBillingTemplate, stationBillingTemplate, "id", "createBy", "createTime", "updateBy", "updateTime"); + stationBillingTemplate.setStationId(Long.valueOf(dto.getStationId())); // 绔欑偣id + stationBillingTemplate.setPublicFlag(Constants.ZERO); // 绔欑偣绉佹湁璁¤垂妯℃澘 + stationBillingTemplate.setTemplateCode(templateCode); + stationBillingTemplate.setCreateBy(SecurityUtils.getUsername()); + stationBillingTemplate.setDelFlag(DelFlagEnum.normal.getValue()); + // 澶嶅埗璁¤垂妯℃澘璇︽儏 + List stationBillingDetailList = Lists.newArrayList(); + PileBillingDetail pileBillingDetail; + for (PileBillingDetail detail : billingDetailList) { + pileBillingDetail = new PileBillingDetail(); + BeanUtils.copyProperties(detail, pileBillingDetail, "id", "templateCode", "createBy", "createTime", "updateBy", "updateTime"); + pileBillingDetail.setTemplateCode(templateCode); + pileBillingDetail.setCreateBy(SecurityUtils.getUsername()); + pileBillingDetail.setDelFlag(DelFlagEnum.normal.getValue()); + stationBillingDetailList.add(pileBillingDetail); + } + // 鍏ュ簱 + BillingTemplateTransactionDTO billingTemplateTransactionDTO = new BillingTemplateTransactionDTO(); + billingTemplateTransactionDTO.setBillingTemplate(stationBillingTemplate); + billingTemplateTransactionDTO.setDetailList(stationBillingDetailList); + transactionService.doCreateBillingTemplate(billingTemplateTransactionDTO); + return true; + } + + @Override + public byte[] generateBillingTemplateMsgBody(String pileSn, BillingTemplateVO billingTemplateVO) { + if (StringUtils.isBlank(pileSn) || billingTemplateVO == null) { + log.error("鐢熸垚鍙戠粰鍏呯數妗╃殑璁¤垂妯℃澘msgBody 鍙傛暟涓嶈兘涓虹┖"); + return null; + } + + // 妗╃紪鐮 + byte[] pileSnByte = BytesUtil.str2Bcd(pileSn); + + // 璁¤垂妯″瀷缂栧彿 鍥哄畾鍊硷細 01 00 + byte[] billingTemplateCode = new byte[]{0x01, 0x00}; + + // 灏栨椂娈电數璐 + byte[] sharpElectricityPrice = YKCUtils.getPriceByte(billingTemplateVO.getSharpElectricityPrice().toString(), 5); + // 灏栨椂娈垫湇鍔¤垂 + byte[] sharpServicePrice = YKCUtils.getPriceByte(billingTemplateVO.getSharpServicePrice().toString(), 5); + + // 宄版椂娈电數璐 + byte[] peakElectricityPrice = YKCUtils.getPriceByte(billingTemplateVO.getPeakElectricityPrice().toString(), 5); + // 宄版椂娈垫湇鍔¤垂 + byte[] peakServicePrice = YKCUtils.getPriceByte(billingTemplateVO.getPeakServicePrice().toString(), 5); + + // 骞虫椂娈电數璐 + byte[] flatElectricityPrice = YKCUtils.getPriceByte(billingTemplateVO.getFlatElectricityPrice().toString(), 5); + // 骞虫椂娈垫湇鍔¤垂 + byte[] flatServicePrice = YKCUtils.getPriceByte(billingTemplateVO.getFlatServicePrice().toString(), 5); + + // 璋锋椂娈电數璐 + byte[] valleyElectricityPrice = YKCUtils.getPriceByte(billingTemplateVO.getValleyElectricityPrice().toString(), 5); + // 璋锋椂娈垫湇鍔¤垂 + byte[] valleyServicePrice = YKCUtils.getPriceByte(billingTemplateVO.getValleyServicePrice().toString(), 5); + // 璁℃崯姣斾緥锛堢洰鍓嶇疆0锛 + byte[] PlanLossRatio = Constants.zeroByteArray; + + // 48涓椂娈佃垂鐜囷紙鍗婂皬鏃朵负涓涓椂娈碉級 + Map> timeMap = billingTemplateVO.getTimeMap(); + List periodOfTime = DateUtils.getPeriodOfTime(); + byte[] timeArray = new byte[periodOfTime.size()]; + for (int i = 0; i < periodOfTime.size(); i++) { + // 瀵规瘮鏃堕棿娈 + byte timeType = getTimeType(periodOfTime.get(i), timeMap); + // log.info("鏃堕棿娈:{}, 瀵瑰簲璐圭巼绫诲瀷:{}", periodOfTime.get(i), timeType); + timeArray[i] = timeType; + } + + // 娑堟伅浣 + byte[] msgBody = Bytes.concat(pileSnByte, billingTemplateCode, sharpElectricityPrice, sharpServicePrice, + peakElectricityPrice, peakServicePrice, flatElectricityPrice, flatServicePrice, valleyElectricityPrice, + valleyServicePrice, PlanLossRatio, timeArray); + log.warn("generateBillingTemplateMsgBody:{}", BytesUtil.binary(msgBody, 16)); + return msgBody; + } + + /** + * 鑾峰彇鏃舵璐圭巼鍙 + * + * @param timeRange 鏃堕棿娈 渚嬪锛07:30:00-10:30:00 + * @param timeMap 灏栧嘲骞宠胺4涓被鍨嬬殑鏃堕棿娈碉紝姣忎釜绫诲瀷閮藉寘鍚竴涓椂闂存闆嗗悎 + * @return + */ + private byte getTimeType(String timeRange, Map> timeMap) { + byte b = 5; + // 杩欓噷鐨則imeRange鏄00:00-00:30 杩欐牱鐨勬牸寮 + String[] split = timeRange.split("-"); + LocalTime startTime1 = DateUtils.getLocalTime(split[0]); + LocalTime endTime1 = DateUtils.getLocalTime(split[1]); + + for (Map.Entry> entry : timeMap.entrySet()) { + List value = entry.getValue().stream().filter(StringUtils::isNotBlank).collect(Collectors.toList()); // 姣忎釜绫诲瀷鏃堕棿娈甸泦鍚 + if (CollectionUtils.isEmpty(value)) { + continue; + } + for (String s : value) { + // 杩欓噷鐨剆鏄07:30-10:30 杩欐牱鐨勬牸寮 + List list = Lists.newArrayList(s.split("-")); + LocalTime startTime2 = DateUtils.getLocalTime(list.get(0)); + LocalTime endTime2 = DateUtils.getLocalTime(list.get(1)); + + boolean overlap = DateUtils.isOverlap(startTime1, endTime1, startTime2, endTime2, false); + if (overlap) { + return (byte) entry.getKey().intValue(); + } + } + } + return b; + } + + @Override + public BillingTemplateVO selectBillingTemplateByTemplateId(String templateId) { + return pileBillingTemplateMapper.selectBillingTemplateByTemplateId(templateId); + } + + @Override + public void insertPileBillingRelation(List relationList) { + if (CollectionUtils.isEmpty(relationList)) { + return; + } + // 鏍规嵁妗╁彿鍒犻櫎璁¤垂妯℃澘鍏崇郴 + List pileSnList = relationList.stream().map(PileBillingRelation::getPileSn).collect(Collectors.toList()); + pileBillingTemplateMapper.deleteRelationByPileSn(pileSnList); + pileBillingTemplateMapper.insertPileBillingRelation(relationList); + } + + private Map getPriceMap(CreateOrUpdateBillingTemplateDTO dto, String type) { + BigDecimal electricityPrice = null; + BigDecimal servicePrice = null; + if (StringUtils.equals(type, "1")) { + electricityPrice = dto.getElectricityPriceA(); + servicePrice = dto.getServicePriceA(); + } else if (StringUtils.equals(type, "2")) { + electricityPrice = dto.getElectricityPriceB(); + servicePrice = dto.getServicePriceB(); + } else if (StringUtils.equals(type, "3")) { + electricityPrice = dto.getElectricityPriceC(); + servicePrice = dto.getServicePriceC(); + } else if (StringUtils.equals(type, "4")) { + electricityPrice = dto.getElectricityPriceD(); + servicePrice = dto.getServicePriceD(); + } + Map resultMap = Maps.newHashMap(); + resultMap.put("electricityPrice", electricityPrice); + resultMap.put("servicePrice", servicePrice); + return resultMap; + } + + /** + * 鏂板璁¤垂妯℃澘璇︽儏淇℃伅 + * + * @param pileBillingTemplate 璁¤垂妯℃澘瀵硅薄 + */ + public void insertPileBillingDetail(PileBillingTemplate pileBillingTemplate) { + List pileBillingDetailList = pileBillingTemplate.getPileBillingDetailList(); + String templateCode = pileBillingTemplate.getTemplateCode(); + if (StringUtils.isNotNull(pileBillingDetailList)) { + List list = new ArrayList(); + for (PileBillingDetail pileBillingDetail : pileBillingDetailList) { + pileBillingDetail.setTemplateCode(templateCode); + list.add(pileBillingDetail); + } + if (list.size() > 0) { + pileBillingTemplateMapper.batchPileBillingDetail(list); + } + } + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java new file mode 100644 index 000000000..4e84292d7 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java @@ -0,0 +1,562 @@ +package com.jsowell.pile.service.impl; + +import com.alibaba.fastjson2.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.enums.ykc.PileStatusEnum; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.domain.PileBasicInfo; +import com.jsowell.pile.domain.PileConnectorInfo; +import com.jsowell.pile.dto.QueryConnectorDTO; +import com.jsowell.pile.dto.QueryConnectorListDTO; +import com.jsowell.pile.mapper.PileBasicInfoMapper; +import com.jsowell.pile.mapper.PileConnectorInfoMapper; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.service.IPileBasicInfoService; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.service.IPileModelInfoService; +import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +import com.jsowell.pile.vo.web.PileDetailVO; +import com.jsowell.pile.vo.web.PileModelInfoVO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 鍏呯數妗╂灙鍙d俊鎭疭ervice涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-08-31 + */ +@Slf4j +@Service +public class PileConnectorInfoServiceImpl implements IPileConnectorInfoService { + @Autowired + private PileConnectorInfoMapper pileConnectorInfoMapper; + + @Autowired + private PileBasicInfoMapper pileBasicInfoMapper; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private IPileModelInfoService pileModelInfoService; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Autowired + private RedisCache redisCache; + + private final String URL = "http://localhost/pileConnectorInfo&code="; + + @Value("${qrcodeurl.prefix}") + private String QRCODE_URL_PREFIX; + + /** + * 鏌ヨ鍏呯數妗╂灙鍙d俊鎭 + * + * @param id 鍏呯數妗╂灙鍙d俊鎭富閿 + * @return 鍏呯數妗╂灙鍙d俊鎭 + */ + @Override + public PileConnectorInfo selectPileConnectorInfoById(Integer id) { + return pileConnectorInfoMapper.selectPileConnectorInfoById(id); + } + + /** + * 鏌ヨ鍏呯數妗╂灙鍙d俊鎭垪琛 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 鍏呯數妗╂灙鍙d俊鎭 + */ + @Override + public List selectPileConnectorInfoList(PileConnectorInfo pileConnectorInfo) { + return pileConnectorInfoMapper.selectPileConnectorInfoList(pileConnectorInfo); + } + + /** + * 閫氳繃鍏呯數妗╁彿鏌ヨ鏋彛淇℃伅鍒楄〃 鍔犵紦瀛 + * + * @param pileSn 妗╃紪鍙 + * @return 鏋彛淇℃伅鍒楄〃 + */ + @Override + public List selectPileConnectorInfoList(String pileSn) { + // 鍙栫紦瀛 + String redisKey = CacheConstants.SELECT_PILE_CONNECTOR_INFO_LIST + pileSn; + List result = redisCache.getCacheObject(redisKey); + if (CollectionUtils.isEmpty(result)) { + // 缂撳瓨涓虹┖锛屾煡鏁版嵁搴 + PileConnectorInfo pileConnectorInfo = new PileConnectorInfo(); + pileConnectorInfo.setPileSn(pileSn); + result = selectPileConnectorInfoList(pileConnectorInfo); + if (CollectionUtils.isNotEmpty(result)) { + // 鏌ヨ鏁版嵁搴撲笉涓虹┖锛屽瓨redis 2鍒嗛挓 + redisCache.setCacheObject(redisKey, result, 2, TimeUnit.MINUTES); + } + } + return result; + } + + /** + * 鍏叡鏂规硶 鏍规嵁妗╃紪鍙峰垹闄edis缂撳瓨 + */ + private void deleteRedisByPileSn(String pileSn) { + List keys = Lists.newArrayList(); + // 鍒犻櫎鏋彛淇℃伅缂撳瓨 + keys.add(CacheConstants.SELECT_PILE_CONNECTOR_INFO_LIST + pileSn); + // 鍒犻櫎鍏呯數妗╄鎯呯紦瀛 + keys.add(CacheConstants.PILE_DETAIL_KEY + pileSn); + // 鍒犻櫎鍏呯數妗╂灙鍙g姸鎬佺紦瀛 + Set scan = redisCache.scan(CacheConstants.PILE_CONNECTOR_STATUS_KEY + pileSn + "*"); + if (CollectionUtils.isNotEmpty(scan)) { + keys.addAll(scan); + } + // 鎵归噺鍒犻櫎 + // log.debug("鎵归噺鍒犻櫎缂撳瓨 pileSn:{}, keys:{}", pileSn, keys); + redisCache.deleteObject(keys); + } + + /** + * 鏂板鍏呯數妗╂灙鍙d俊鎭 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 缁撴灉 + */ + // @Override + // public int insertPileConnectorInfo(PileConnectorInfo pileConnectorInfo) { + // pileConnectorInfo.setCreateTime(DateUtils.getNowDate()); + // return pileConnectorInfoMapper.insertPileConnectorInfo(pileConnectorInfo); + // } + + /** + * 淇敼鍏呯數妗╂灙鍙d俊鎭 + * + * @param pileConnectorInfo 鍏呯數妗╂灙鍙d俊鎭 + * @return 缁撴灉 + */ + // @Override + // public int updatePileConnectorInfo(PileConnectorInfo pileConnectorInfo) { + // pileConnectorInfo.setUpdateTime(DateUtils.getNowDate()); + // deleteRedisByPileSn(pileConnectorInfo.getPileSn()); + // return pileConnectorInfoMapper.updatePileConnectorInfo(pileConnectorInfo); + // } + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╂灙鍙d俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗╂灙鍙d俊鎭富閿 + * @return 缁撴灉 + */ + // @Override + // public int deletePileConnectorInfoByIds(Integer[] ids) { + // return pileConnectorInfoMapper.deletePileConnectorInfoByIds(ids); + // } + + @Override + public int deletePileConnectorInfoByPileSnList(List pileSnList) { + return pileConnectorInfoMapper.deletePileConnectorInfoByPileSnList(pileSnList); + } + + @Override + public int batchInsertConnectorInfo(List pileConnectorInfoList) { + return pileConnectorInfoMapper.batchInsertConnectorInfo(pileConnectorInfoList); + } + + /** + * 鍏呯數鎺ュ彛鐩稿叧淇℃伅 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 鍏呯數鎺ュ彛瀵硅薄缁撴灉闆 + */ + @Override + public List getConnectorInfoListByParams(QueryConnectorDTO dto) { + List list = pileConnectorInfoMapper.getConnectorInfoList(dto); + // 浜岀淮鐮併佺數閲忋佽澶囪鍗曞彿銆佸钩鍙拌鍗曟殏鏃舵湭浼 + if (Objects.nonNull(list)) { + for (PileConnectorInfoVO p : list) { + // p.setConnectorQrCodeUrl(URL + p.getPileConnectorCode()); + p.setConnectorQrCodeUrl(getPileConnectorQrCodeUrl(p.getPileConnectorCode())); + } + } + return list; + } + + /** + * 閫氳繃鍏呯數绔檌d鏌ヨ鍏呯數鏋俊鎭 + * + * @param stationId 鍏呯數绔檌d + * @return 鍏呯數鎺ュ彛淇℃伅闆嗗悎 + */ + @Override + public List selectConnectorListByStationId(Long stationId) { + return pileConnectorInfoMapper.selectConnectorListByStationId(stationId); + } + + /** + * 閫氳繃鍏ュ弬鏌ヨ鏋彛鏁版嵁 + * + * @param dto + * @return + */ + @Override + public List getConnectorInfoListByParams(QueryConnectorListDTO dto) { + int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum(); + int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize(); + List pileSns = Lists.newArrayList(); + List connectorIds = dto.getConnectorIdList(); + List stationIdList = dto.getStationIdList(); + List connectorCodeList = dto.getConnectorCodeList(); + + // 閫氳繃杩愯惀鍟嗘煡璇㈢珯鐐 + if (StringUtils.isNotBlank(dto.getMerchantId())) { + // 鏌ヨ绔欑偣idList + List queryStationIdList = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(queryStationIdList)) { + if (CollectionUtils.isEmpty(stationIdList)) { + stationIdList = Lists.newArrayList(); + } + stationIdList.addAll(queryStationIdList); + } + } + + // 绔欑偣涓嶄负绌猴紝鎷垮埌绔欑偣涓嬫墍鏈夌殑鍏呯數妗﹊d + if (CollectionUtils.isNotEmpty(stationIdList)) { + List pileInfoVOS = pileBasicInfoService.selectPileListByStationIds(stationIdList); + if (CollectionUtils.isNotEmpty(pileInfoVOS)) { + pileSns.addAll(pileInfoVOS.stream().map(PileDetailVO::getPileSn).collect(Collectors.toList())); + } + } + + // 閫氳繃鍏呯數妗﹊d鏌ヨ + if (CollectionUtils.isNotEmpty(dto.getPileIds())) { + // 鎵归噺鏌 + List pileList = pileBasicInfoMapper.selectByIdList(dto.getPileIds()); + if (CollectionUtils.isNotEmpty(pileList)) { + pileSns.addAll(pileList.stream().map(PileBasicInfo::getSn).collect(Collectors.toList())); + } + } + if (CollectionUtils.isEmpty(pileSns) && CollectionUtils.isEmpty(connectorIds) && CollectionUtils.isEmpty(connectorCodeList)) { + return Lists.newArrayList(); + } + PageHelper.startPage(pageNum, pageSize); + + List pileConnectorInfoList = pileConnectorInfoMapper.getPileConnectorInfoList(pileSns, connectorIds, connectorCodeList); + + // 鏌ヨ鏋彛褰撳墠璁㈠崟 + for (PileConnectorInfoVO pileConnectorInfoVO : pileConnectorInfoList) { + String pileConnectorCode = pileConnectorInfoVO.getPileConnectorCode(); + pileConnectorInfoVO.setConnectorQrCodeUrl(getPileConnectorQrCodeUrl(pileConnectorCode)); // 鏋彛鍙蜂簩缁寸爜 + OrderBasicInfo order = orderBasicInfoService.queryChargingByPileConnectorCode(pileConnectorCode); + if (order != null) { + pileConnectorInfoVO.setOrderCode(order.getOrderCode()); + } + } + + queryRealTimeData(pileConnectorInfoList); + return pileConnectorInfoList; + } + + /** + * 鍏呯數妗╂灙鍙g殑浜岀淮鐮 + * @param pileConnectorCode 鏋彛缂栧彿 濡傛灙鍙g紪鍙蜂负绌猴紝鍒欒繑鍥炲墠缂 https://api.jsowellcloud.com/app-xcx-h5/pile/connectorDetail/ + * @return + */ + @Override + public String getPileConnectorQrCodeUrl(String pileConnectorCode) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(QRCODE_URL_PREFIX); + stringBuilder.append("/app-xcx-h5/pile/connectorDetail/"); + if (StringUtils.isNotBlank(pileConnectorCode)) { + if (!stringBuilder.toString().endsWith("/")) { + stringBuilder.append("/"); + } + stringBuilder.append(pileConnectorCode); + } + return stringBuilder.toString(); + } + + /** + * uniapp閫氳繃鍏ュ弬鏌ヨ鏋彛鏁版嵁 + * + * @param dto + * @return + */ + @Override + public PageResponse getUniAppConnectorInfoListByParams(QueryConnectorListDTO dto) { + int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum(); + int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize(); + + List pileSns = Lists.newArrayList(); + List connectorIds = dto.getConnectorIdList(); + List stationIdList = dto.getStationIdList(); + List connectorCodeList = dto.getConnectorCodeList(); + + // 閫氳繃杩愯惀鍟嗘煡璇㈢珯鐐 + if (StringUtils.isNotBlank(dto.getMerchantId())) { + // 鏌ヨ绔欑偣idList + List queryStationIdList = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(queryStationIdList)) { + if (CollectionUtils.isEmpty(stationIdList)) { + stationIdList = Lists.newArrayList(); + } + stationIdList.addAll(queryStationIdList); + } + } + + // 绔欑偣涓嶄负绌猴紝鎷垮埌绔欑偣涓嬫墍鏈夌殑鍏呯數妗﹊d + if (CollectionUtils.isNotEmpty(stationIdList)) { + List pileInfoVOS = pileBasicInfoService.selectPileListByStationIds(stationIdList); + if (CollectionUtils.isNotEmpty(pileInfoVOS)) { + pileSns.addAll(pileInfoVOS.stream().map(PileDetailVO::getPileSn).collect(Collectors.toList())); + } + } + + // 閫氳繃鍏呯數妗﹊d鏌ヨ + if (CollectionUtils.isNotEmpty(dto.getPileIds())) { + // 鎵归噺鏌 + List pileList = pileBasicInfoMapper.selectByIdList(dto.getPileIds()); + if (CollectionUtils.isNotEmpty(pileList)) { + pileSns.addAll(pileList.stream().map(PileBasicInfo::getSn).collect(Collectors.toList())); + } + } + if (CollectionUtils.isEmpty(pileSns) && CollectionUtils.isEmpty(connectorIds) && CollectionUtils.isEmpty(connectorCodeList)) { + return new PageResponse(); + } + // 鍒嗛〉 + PageHelper.startPage(pageNum, pageSize); + + List pileConnectorInfoList = pileConnectorInfoMapper.getPileConnectorInfoList(pileSns, connectorIds, connectorCodeList); + + PageInfo pageInfo = new PageInfo<>(pileConnectorInfoList); + + queryRealTimeData(pageInfo.getList()); + + // 杩斿洖缁撴灉闆 + PageResponse pageResponse = PageResponse.builder() + .pageNum(pageNum) + .pageSize(pageSize) + .list(pageInfo.getList()) + .pages(pageInfo.getPages()) + .total(pageInfo.getTotal()) + .build(); + return pageResponse; + } + + /** + * uniApp閫氳繃绔欑偣id鏌ヨ鏋彛鍒楄〃淇℃伅 + * + * @param stationId 绔欑偣id + * @return + */ + @Override + public List getUniAppConnectorList(Long stationId) { + // TODO 鍔犵紦瀛 + return pileConnectorInfoMapper.getUniAppConnectorList(stationId); + } + + @Override + public List selectConnectorInfoList(String pileSn) { + // 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭 + PileModelInfoVO pileModelInfoVO = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + + List connectorList = selectPileConnectorInfoList(pileSn); + List connectorInfoList = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(connectorList)) { + for (PileConnectorInfo connectorInfo : connectorList) { + ConnectorInfoVO infoVO = ConnectorInfoVO.builder() + .connectorCode(StringUtils.replace(connectorInfo.getPileConnectorCode(), pileSn, "")) + .pileConnectorCode(connectorInfo.getPileConnectorCode()) + .connectorStatus(connectorInfo.getStatus()) + .build(); + if (pileModelInfoVO != null) { + infoVO.setChargingType(pileModelInfoVO.getSpeedType()); + infoVO.setRatedPower(pileModelInfoVO.getRatedPower()); + } + connectorInfoList.add(infoVO); + } + } + return connectorInfoList; + } + + /** + * 鏌ヨ鍏呯數鏋彛鐨勫疄鏃舵暟鎹 + */ + private void queryRealTimeData(List pileConnectorInfoList) { + if (CollectionUtils.isEmpty(pileConnectorInfoList)) { + return; + } + + // 鑾峰彇鏋彛鐨勬棩蹇楄褰 + for (PileConnectorInfoVO pileConnectorInfoVO : pileConnectorInfoList) { + // 浠巖edis涓幏鍙栧疄鏃舵暟鎹俊鎭 + if (StringUtils.isNotBlank(pileConnectorInfoVO.getOrderCode())) { + List chargingRealTimeDataList = orderBasicInfoService.getChargingRealTimeData(pileConnectorInfoVO.getOrderCode()); + RealTimeMonitorData realTimeMonitorData = chargingRealTimeDataList.get(0); + BigDecimal outputVoltage = new BigDecimal(realTimeMonitorData.getOutputVoltage()); + pileConnectorInfoVO.setVoltage(outputVoltage); + BigDecimal outputCurrent = new BigDecimal(realTimeMonitorData.getOutputCurrent()); + pileConnectorInfoVO.setCurrent(outputCurrent); + pileConnectorInfoVO.setSOC(realTimeMonitorData.getSOC()); // 鍏呯數鐧惧垎姣 + pileConnectorInfoVO.setChargingAmount(new BigDecimal(realTimeMonitorData.getChargingAmount())); + pileConnectorInfoVO.setChargingDegree(new BigDecimal(realTimeMonitorData.getChargingDegree())); + pileConnectorInfoVO.setGunLineTemperature(realTimeMonitorData.getGunLineTemperature()); // 鏋嚎娓╁害 + pileConnectorInfoVO.setTimeRemaining(realTimeMonitorData.getTimeRemaining()); + pileConnectorInfoVO.setChargingTime(realTimeMonitorData.getSumChargingTime()); + // 璁$畻瀹炴椂鍔熺巼锛堝崟浣嶏細kw锛 + BigDecimal instantPowerTemp = outputVoltage.multiply(outputCurrent); + BigDecimal instantPower = instantPowerTemp.divide(new BigDecimal(1000)); + pileConnectorInfoVO.setInstantPower(instantPower.setScale(2, BigDecimal.ROUND_HALF_UP)); + log.info("鏋彛瀹炴椂鏁版嵁锛歿}", JSONObject.toJSONString(pileConnectorInfoVO)); + } + + if (checkPileOffLine(pileConnectorInfoVO.getPileSn())) { + // 鏈鍚庢敹鍒版秷鎭殑鏃堕棿鍦1鍒嗛挓鍓嶏紝鍒欒繑鍥炵粰鍓嶇鏋彛绂荤嚎 + pileConnectorInfoVO.setStatus(Integer.valueOf(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue())); + // 骞朵慨鏀规暟鎹簱鐘舵佷负绂荤嚎 + updateConnectorStatusByPileSn(pileConnectorInfoVO.getPileSn(), PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue()); + } + } + } + + /** + * 閫氳繃妗╃紪鍙蜂慨鏀规灙鍙g姸鎬 + * 浠呯敤浜庣櫥褰曢昏緫浣跨敤 + * + * @param pileSn 鍏呯數妗╃紪鍙 + * @param status 鍏呯數妗╂灙鍙g姸鎬 + */ + public int updateConnectorStatusByPileSn(String pileSn, String status) { + if (StringUtils.isBlank(pileSn) || StringUtils.isBlank(status)) { + return 0; + } + // 閫氳繃pileSn鏌ヨ鏋彛鍒楄〃 + List connectorInfoList = selectPileConnectorInfoList(pileSn); + if (CollectionUtils.isEmpty(connectorInfoList)) { + return 0; + } + int i = 0; + for (PileConnectorInfo connectorInfo : connectorInfoList) { + i = i + updateConnectorStatus(connectorInfo.getPileConnectorCode(), status); + } + return i; + } + + /** + * 淇敼鏋彛鐘舵 + * 鎵鏈変慨鏀规灙鍙g姸鎬佺殑閮借浣跨敤杩欎釜鏂规硶锛屽拰鏁版嵁搴撲氦浜掑彧鏈夎繖涓涓彛瀛 + * + * @param connectorCode 鏋彛鍙 妗╃紪鍙+鏋彛鍙 + * @param status 鐘舵 0锛氱缃 (榛樿)锛1锛氱┖闂诧紱2锛氬崰鐢紙鏈厖鐢碉級锛3锛氬崰鐢紙鍏呯數涓級锛4锛氬崰鐢紙棰勭害閿佸畾锛 锛255锛氭晠闅 + */ + @Override + public int updateConnectorStatus(String connectorCode, String status) { + int num = 0; + if (StringUtils.isBlank(connectorCode) || StringUtils.isBlank(status)) { + return num; + } + String redisKey = CacheConstants.PILE_CONNECTOR_STATUS_KEY + connectorCode; + String redisStatus = redisCache.getCacheObject(redisKey); + // log.info("淇敼鍏呯數妗╂灙鍙g姸鎬 缂撳瓨鐘舵侊細{}, 浼犳潵鐨勭姸鎬侊細{}", redisStatus, status); + if (!StringUtils.equals(redisStatus, status)) { + log.info("鏇存柊鏋彛鐘舵 鏋彛鍙:{}, 缂撳瓨鐘舵侊細{}, 鐘舵佸:{}, 鐘舵:{}", connectorCode, redisStatus, status, PileConnectorDataBaseStatusEnum.getStatusDescription(status)); + String pileSn = connectorCode.substring(0, connectorCode.length() - 2); + // 鍙慨鏀逛竴涓灙鍙g殑鐘舵 + num = pileConnectorInfoMapper.updateConnectorStatus(connectorCode, status); + deleteRedisByPileSn(pileSn); + redisCache.setCacheObject(redisKey, status); + } + return num; + } + + /** + * 鎵归噺鑾峰彇妗╃姸鎬 + * 妗╃殑鐘舵佹湁 鍦ㄧ嚎 绂荤嚎 鏁呴殰 + * + * @param pileSnList 妗╃紪鍙峰垪琛 + * @return key:妗╃紪鍙; value:鐘舵 + */ + @Override + public Map getPileStatus(List pileSnList) { + Map resultMap = Maps.newHashMap(); + for (String pileSn : pileSnList) { + String pileStatus = ""; + + // 鏍囪瘑妗╂晠闅滄垨鑰呯绾 + boolean flag = false; + + // 鍒ゆ柇鏁呴殰鐘舵 + List connectorList = selectPileConnectorInfoList(pileSn); // 鑾峰彇鏋彛淇℃伅 + List connectorStatusList = connectorList.stream().map(PileConnectorInfo::getStatus).collect(Collectors.toList()); + // 妗╀笅闈㈢殑鏋彛锛屼换鎰忎竴涓晠闅滐紝妗╃殑鐘舵佸氨鏄晠闅 + if (connectorStatusList.contains(PileConnectorDataBaseStatusEnum.FAULT.getValue())) { + pileStatus = PileStatusEnum.FAULT.getValue(); + flag = true; + } + + // 鍒ゆ柇绂荤嚎鐘舵 鏄剧ず浼樺厛绾 绂荤嚎>鏁呴殰 + // if (checkPileOffLine(pileSn)) { + // pileStatus = PileStatusEnum.OFF_LINE.getValue(); + // flag = true; + // } + + // 2023骞1鏈10鏃11鐐32鍒 鏀规垚濡傛灉鏋彛绂荤嚎锛岄偅涔堝厖鐢垫々灏辨槸绂荤嚎 + if (connectorStatusList.contains(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue())) { + pileStatus = PileStatusEnum.OFF_LINE.getValue(); + flag = true; + } + + // 娌℃湁鏁呴殰鎴栬呯绾匡紝灏辨槸鍦ㄧ嚎鐘舵 + if (!flag) { + pileStatus = PileStatusEnum.ON_LINE.getValue(); + } + + resultMap.put(pileSn, pileStatus); + } + return resultMap; + } + + @Override + public PileConnectorInfoVO getPileConnectorInfoByConnectorCode(String pileConnectorCode) { + return pileConnectorInfoMapper.getPileConnectorInfoByConnectorCode(pileConnectorCode); + } + + /** + * 鍒ゆ柇鍏呯數妗╂槸鍚︾绾 + * + * @param pileSn 妗╃紪鍙 + * @return true绂荤嚎 + */ + private boolean checkPileOffLine(String pileSn) { + // 鑾峰彇妗╂渶鍚庤繛鎺ユ椂闂达紝鏈鍚庤繛鎺ュ埌骞冲彴鐨勬椂闂村湪1鍒嗛挓涔嬪墠锛屽垽瀹氫负绂荤嚎 + String lastConnectionTime = redisCache.getCacheObject(CacheConstants.PILE_LAST_CONNECTION + pileSn); + if (StringUtils.isBlank(lastConnectionTime)) { + // 娌℃湁鏈鍚庤繛鎺ユ椂闂达紝杩斿洖绂荤嚎 + return true; + } + long l = DateUtils.intervalTime(lastConnectionTime, DateUtils.getTime()); + return l >= 1L; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileLicenceInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileLicenceInfoServiceImpl.java new file mode 100644 index 000000000..2116b2a05 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileLicenceInfoServiceImpl.java @@ -0,0 +1,108 @@ +package com.jsowell.pile.service.impl; + +import com.google.common.collect.Lists; +import com.jsowell.common.util.DateUtils; +import com.jsowell.pile.domain.PileLicenceInfo; +import com.jsowell.pile.mapper.PileLicenceInfoMapper; +import com.jsowell.pile.service.IPileLicenceInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 鍏呯數妗╄瘉涔︿俊鎭疭ervice涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-08-27 + */ +@Service +public class PileLicenceInfoServiceImpl implements IPileLicenceInfoService +{ + @Autowired + private PileLicenceInfoMapper pileLicenceInfoMapper; + + /** + * 鏌ヨ鍏呯數妗╄瘉涔︿俊鎭 + * + * @param id 鍏呯數妗╄瘉涔︿俊鎭富閿 + * @return 鍏呯數妗╄瘉涔︿俊鎭 + */ + @Override + public PileLicenceInfo selectPileLicenceInfoById(Long id) + { + + return pileLicenceInfoMapper.selectPileLicenceInfoById(id); + } + + public static void main(String[] args) { + String applyTime = "00:00-05:00,10:00-13:00,10:00-13:00,10:00-13:00"; + List timeList = Lists.newArrayList(applyTime.split(",")); + System.out.println(timeList); + for (String s : timeList) { + System.out.println(s); + } + } + + /** + * 鏌ヨ鍏呯數妗╄瘉涔︿俊鎭垪琛 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 鍏呯數妗╄瘉涔︿俊鎭 + */ + @Override + public List selectPileLicenceInfoList(PileLicenceInfo pileLicenceInfo) + { + return pileLicenceInfoMapper.selectPileLicenceInfoList(pileLicenceInfo); + } + + /** + * 鏂板鍏呯數妗╄瘉涔︿俊鎭 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 缁撴灉 + */ + @Override + public int insertPileLicenceInfo(PileLicenceInfo pileLicenceInfo) + { + pileLicenceInfo.setCreateTime(DateUtils.getNowDate()); + return pileLicenceInfoMapper.insertPileLicenceInfo(pileLicenceInfo); + } + + /** + * 淇敼鍏呯數妗╄瘉涔︿俊鎭 + * + * @param pileLicenceInfo 鍏呯數妗╄瘉涔︿俊鎭 + * @return 缁撴灉 + */ + @Override + public int updatePileLicenceInfo(PileLicenceInfo pileLicenceInfo) + { + pileLicenceInfo.setUpdateTime(DateUtils.getNowDate()); + return pileLicenceInfoMapper.updatePileLicenceInfo(pileLicenceInfo); + } + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╄瘉涔︿俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗╄瘉涔︿俊鎭富閿 + * @return 缁撴灉 + */ + @Override + public int deletePileLicenceInfoByIds(Long[] ids) + { + return pileLicenceInfoMapper.deletePileLicenceInfoByIds(ids); + } + + /** + * 鍒犻櫎鍏呯數妗╄瘉涔︿俊鎭俊鎭 + * + * @param id 鍏呯數妗╄瘉涔︿俊鎭富閿 + * @return 缁撴灉 + */ + @Override + public int deletePileLicenceInfoById(Long id) + { + return pileLicenceInfoMapper.deletePileLicenceInfoById(id); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMemberRelationServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMemberRelationServiceImpl.java new file mode 100644 index 000000000..9f8ba88ee --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMemberRelationServiceImpl.java @@ -0,0 +1,118 @@ +package com.jsowell.pile.service.impl; + +import com.google.common.collect.Lists; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.PileMemberRelation; +import com.jsowell.pile.mapper.PileMemberRelationMapper; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.service.IPileMemberRelationService; +import com.jsowell.pile.vo.uniapp.PersonalPileInfoVO; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴Service涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2023-02-21 + */ +@Service +public class PileMemberRelationServiceImpl implements IPileMemberRelationService { + @Autowired + private PileMemberRelationMapper pileMemberRelationMapper; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + /** + * 鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param id 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴涓婚敭 + * @return 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + */ + @Override + public PileMemberRelation selectPileMemberRelationById(Integer id) { + return pileMemberRelationMapper.selectPileMemberRelationById(id); + } + + /** + * 鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴鍒楄〃 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + */ + @Override + public List selectPileMemberRelationList(PileMemberRelation pileMemberRelation) { + return pileMemberRelationMapper.selectPileMemberRelationList(pileMemberRelation); + } + + /** + * 鏉′欢鏌ヨ妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴瀵硅薄 + */ + @Override + public PileMemberRelation selectPileMemberRelation(PileMemberRelation pileMemberRelation) { + return pileMemberRelationMapper.selectPileMemberRelation(pileMemberRelation); + } + + /** + * 鏂板妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 缁撴灉 + */ + @Override + public int insertPileMemberRelation(PileMemberRelation pileMemberRelation) { + pileMemberRelation.setCreateTime(DateUtils.getNowDate()); + return pileMemberRelationMapper.insertPileMemberRelation(pileMemberRelation); + } + + /** + * 淇敼妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param pileMemberRelation 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * @return 缁撴灉 + */ + @Override + public int updatePileMemberRelation(PileMemberRelation pileMemberRelation) { + return pileMemberRelationMapper.updatePileMemberRelation(pileMemberRelation); + } + + /** + * 鎵归噺鍒犻櫎妗╀笌鐢ㄦ埛缁戝畾鍏崇郴 + * + * @param ids 闇瑕佸垹闄ょ殑妗╀笌鐢ㄦ埛缁戝畾鍏崇郴涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deletePileMemberRelationByIds(Integer[] ids) { + return pileMemberRelationMapper.deletePileMemberRelationByIds(ids); + } + + /** + * 鍒犻櫎妗╀笌鐢ㄦ埛缁戝畾鍏崇郴淇℃伅 + * + * @param id 妗╀笌鐢ㄦ埛缁戝畾鍏崇郴涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deletePileMemberRelationById(Integer id) { + return pileMemberRelationMapper.deletePileMemberRelationById(id); + } + + @Override + public List selectPileMemberRelationByPileSn(String pileSn) { + PileMemberRelation pileMemberRelation = new PileMemberRelation(); + pileMemberRelation.setPileSn(pileSn); + return selectPileMemberRelationList(pileMemberRelation); + } + + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMerchantInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMerchantInfoServiceImpl.java new file mode 100644 index 000000000..b30177e17 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMerchantInfoServiceImpl.java @@ -0,0 +1,167 @@ +package com.jsowell.pile.service.impl; + +import com.jsowell.common.annotation.DataScope; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.entity.SysDept; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.DictUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.PileMerchantInfo; +import com.jsowell.pile.mapper.PileMerchantInfoMapper; +import com.jsowell.pile.service.IPileMerchantInfoService; +import com.jsowell.pile.vo.base.MerchantInfoVO; +import com.jsowell.system.service.SysDeptService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Objects; + +/** + * 鍏呯數妗╄繍钀ュ晢淇℃伅Service涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-08-27 + */ +@Slf4j +@Service +public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService { + @Autowired + private PileMerchantInfoMapper pileMerchantInfoMapper; + + @Autowired + private SysDeptService sysDeptService; + + @Value("${weixin.login.appid}") + private String appid; + + /** + * 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param id 鍏呯數妗╄繍钀ュ晢淇℃伅涓婚敭 + * @return 鍏呯數妗╄繍钀ュ晢淇℃伅 + */ + @Override + public PileMerchantInfo selectPileMerchantInfoById(Long id) { + return pileMerchantInfoMapper.selectPileMerchantInfoById(id); + } + + /** + * 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅鍒楄〃 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 鍏呯數妗╄繍钀ュ晢淇℃伅 + */ + @Override + @DataScope(deptAlias = "t") + public List selectPileMerchantInfoList(PileMerchantInfo pileMerchantInfo) { + List list = pileMerchantInfoMapper.selectPileMerchantInfoList(pileMerchantInfo); + if (Objects.nonNull(list)) { + for (PileMerchantInfo p:list) { + String status = p.getStatus(); + String merchant_status = DictUtils.getDictLabel("merchant_status", status); + p.setStatus(merchant_status); + } + } + return list; + } + + /** + * 鏂板鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public int insertPileMerchantInfo(PileMerchantInfo pileMerchantInfo) { + // 1. 鏂板sys_dept + SysDept dept = new SysDept(); + dept.setParentId(100L); + dept.setOrderNum(0); + dept.setDeptName(pileMerchantInfo.getMerchantName()); + dept.setLeader(pileMerchantInfo.getManagerName()); + dept.setPhone(pileMerchantInfo.getManagerPhone()); + dept.setStatus("0"); + sysDeptService.insertDept(dept); + + // 2. 鏂板pile_merchant_info + Long deptId = dept.getDeptId(); + // pileMerchantInfo.setId(deptId); + pileMerchantInfo.setDeptId(String.valueOf(deptId)); + pileMerchantInfo.setStatus(Constants.ONE); + String appId = StringUtils.isBlank(pileMerchantInfo.getAppId()) + ? appid + : pileMerchantInfo.getAppId(); + pileMerchantInfo.setAppId(appId); + return pileMerchantInfoMapper.insertPileMerchantInfo(pileMerchantInfo); + } + + /** + * 淇敼鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param pileMerchantInfo 鍏呯數妗╄繍钀ュ晢淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updatePileMerchantInfo(PileMerchantInfo pileMerchantInfo) { + pileMerchantInfo.setUpdateTime(DateUtils.getNowDate()); + return pileMerchantInfoMapper.updatePileMerchantInfo(pileMerchantInfo); + } + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╄繍钀ュ晢淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗╄繍钀ュ晢淇℃伅涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deletePileMerchantInfoByIds(Long[] ids) { + return pileMerchantInfoMapper.deletePileMerchantInfoByIds(ids); + } + + /** + * 鍒犻櫎鍏呯數妗╄繍钀ュ晢淇℃伅淇℃伅 + * + * @param id 鍏呯數妗╄繍钀ュ晢淇℃伅涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deletePileMerchantInfoById(Long id) { + return pileMerchantInfoMapper.deletePileMerchantInfoById(id); + } + + @Override + public String getMerchantIdByAppId(String appId) { + if (StringUtils.isBlank(appId)) { + return null; + } + try { + PileMerchantInfo pileMerchantInfo = pileMerchantInfoMapper.selectPileMerchantInfoByAppId(appId); + if (pileMerchantInfo != null) { + return pileMerchantInfo.getId().toString(); + } + } catch (Exception e) { + log.error("閫氳繃appid鑾峰彇杩愯惀鍟唅d error", e); + } + return null; + } + + @Override + public MerchantInfoVO getMerchantInfo(String merchantId) { + PileMerchantInfo pileMerchantInfo = selectPileMerchantInfoById(Long.parseLong(merchantId)); + if (pileMerchantInfo == null) { + return null; + } + MerchantInfoVO vo = MerchantInfoVO.builder() + .merchantId(merchantId) + .merchantName(pileMerchantInfo.getMerchantName()) + .merchantTel(pileMerchantInfo.getServicePhone()) + .deptId(pileMerchantInfo.getDeptId()) + .build(); + return vo; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileModelInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileModelInfoServiceImpl.java new file mode 100644 index 000000000..51a4d4a1f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileModelInfoServiceImpl.java @@ -0,0 +1,113 @@ +package com.jsowell.pile.service.impl; + +import com.google.common.collect.Lists; +import com.jsowell.common.util.DateUtils; +import com.jsowell.pile.domain.PileModelInfo; +import com.jsowell.pile.mapper.PileModelInfoMapper; +import com.jsowell.pile.service.IPileModelInfoService; +import com.jsowell.pile.vo.web.PileModelInfoVO; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 鍏呯數妗╁瀷鍙蜂俊鎭疭ervice涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-08-26 + */ +@Service +public class PileModelInfoServiceImpl implements IPileModelInfoService { + @Autowired + private PileModelInfoMapper pileModelInfoMapper; + + /** + * 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param id 鍏呯數妗╁瀷鍙蜂俊鎭富閿 + * @return 鍏呯數妗╁瀷鍙蜂俊鎭 + */ + @Override + public PileModelInfo selectPileModelInfoById(Long id) { + return pileModelInfoMapper.selectPileModelInfoById(id); + } + + /** + * 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭垪琛 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 鍏呯數妗╁瀷鍙蜂俊鎭 + */ + @Override + public List selectPileModelInfoList(PileModelInfo pileModelInfo) { + return pileModelInfoMapper.selectPileModelInfoList(pileModelInfo); + } + + /** + * 鏂板鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 缁撴灉 + */ + @Override + public int insertPileModelInfo(PileModelInfo pileModelInfo) { + pileModelInfo.setCreateTime(DateUtils.getNowDate()); + return pileModelInfoMapper.insertPileModelInfo(pileModelInfo); + } + + /** + * 淇敼鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param pileModelInfo 鍏呯數妗╁瀷鍙蜂俊鎭 + * @return 缁撴灉 + */ + @Override + public int updatePileModelInfo(PileModelInfo pileModelInfo) { + pileModelInfo.setUpdateTime(DateUtils.getNowDate()); + return pileModelInfoMapper.updatePileModelInfo(pileModelInfo); + } + + /** + * 鎵归噺鍒犻櫎鍏呯數妗╁瀷鍙蜂俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗╁瀷鍙蜂俊鎭富閿 + * @return 缁撴灉 + */ + @Override + public int deletePileModelInfoByIds(Long[] ids) { + return pileModelInfoMapper.deletePileModelInfoByIds(ids); + } + + /** + * 鍒犻櫎鍏呯數妗╁瀷鍙蜂俊鎭俊鎭 + * + * @param id 鍏呯數妗╁瀷鍙蜂俊鎭富閿 + * @return 缁撴灉 + */ + @Override + public int deletePileModelInfoById(Long id) { + return pileModelInfoMapper.deletePileModelInfoById(id); + } + + /** + * 閫氳繃妗╃紪鍙烽泦鍚堣幏鍙栧瀷鍙疯〃涓暟鎹 + * + * @param pileSns 妗╃紪鍙烽泦鍚 + * @return PileModelInfo瀵硅薄 + */ + @Override + public List getPileModelInfoByPileSnList(List pileSns) { + return pileModelInfoMapper.getPileModelInfoByPileSnList(pileSns); + } + + @Override + public PileModelInfoVO getPileModelInfoByPileSn(String pileSn) { + List list = getPileModelInfoByPileSnList(Lists.newArrayList(pileSn)); + if (CollectionUtils.isNotEmpty(list)) { + return list.get(0); + } + return null; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMsgRecordServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMsgRecordServiceImpl.java new file mode 100644 index 000000000..e27b692e2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileMsgRecordServiceImpl.java @@ -0,0 +1,109 @@ +package com.jsowell.pile.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.pile.domain.PileMsgRecord; +import com.jsowell.pile.dto.QueryPileDTO; +import com.jsowell.pile.mapper.PileMsgRecordMapper; +import com.jsowell.pile.service.IPileMsgRecordService; +import com.jsowell.pile.vo.web.PileCommunicationLogVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class PileMsgRecordServiceImpl implements IPileMsgRecordService { + + @Autowired + private PileMsgRecordMapper pileMsgRecordMapper; + + @Override + public void save(String pileSn, String connectorCode, String frameType, String jsonMsg, String originalMsg) { + PileMsgRecord pileMsgRecord = PileMsgRecord.builder() + .pileSn(pileSn) + .connectorCode(connectorCode) + .jsonMsg(jsonMsg) + .frameType(frameType) + .originalMsg(originalMsg) + .build(); + pileMsgRecordMapper.insertSelective(pileMsgRecord); + } + + // @Override + // public List getByConnectorCodeList(List connectorCodeList) { + // if (CollectionUtils.isEmpty(connectorCodeList)) { + // return Lists.newArrayList(); + // } + // return pileMsgRecordMapper.getByConnectorCodeList(connectorCodeList); + // } + + public static void main(String[] args) { + String type = BytesUtil.bcd2Str(YKCFrameTypeCode.TRANSACTION_RECORDS_CODE.getBytes()); + System.out.println(type); + String binary = BytesUtil.binary(YKCFrameTypeCode.TRANSACTION_RECORDS_CODE.getBytes(), 16); + System.out.println(binary); + String s = YKCUtils.frameType2Str(YKCFrameTypeCode.TRANSACTION_RECORDS_CODE.getBytes()); + System.out.println(s); + + } + + @Override + public PageResponse getPileFeedList(QueryPileDTO dto) { + // 鍒嗛〉 + PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); + List pileFeedList = pileMsgRecordMapper.getPileFeedList(dto.getPileSn()); + PageInfo pageInfo = new PageInfo<>(pileFeedList); + + List list = new ArrayList<>(); + for (PileMsgRecord pileMsgRecord : pageInfo.getList()) { + PileCommunicationLogVO vo = new PileCommunicationLogVO(); + String frameType = pileMsgRecord.getFrameType(); + + String frameTypeStr = YKCFrameTypeCode.getFrameTypeStr(frameType); + if (StringUtils.isNotBlank(frameTypeStr)) { + vo.setDescription(frameTypeStr); + } else { + vo.setDescription(pileMsgRecord.getJsonMsg()); + } + // if (StringUtils.equals(YKCUtils.frameType2Str(YKCFrameTypeCode.LOGIN_CODE.getBytes()), frameType)) { + // // 鐧诲綍 + // vo.setDescription("鍏呯數妗╃櫥褰曡璇"); + // } else if (StringUtils.equals(YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_RESTART_CODE.getBytes()), frameType)) { + // // 杩滅▼閲嶅惎 + // vo.setDescription("杩滅▼閲嶅惎"); + // } else if (StringUtils.equals(YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_CONTROL_START_CODE.getBytes()), frameType)) { + // // 杩滅▼鍚姩鍏呯數 + // vo.setDescription("杩愯惀骞冲彴杩滅▼鎺у埗鍚満"); + // }else if (StringUtils.equals(YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_STOP_CHARGING_CODE.getBytes()), frameType)) { + // // 杩滅▼鍋滄満 + // vo.setDescription("杩愯惀骞冲彴杩滅▼鍋滄満"); + // }else if (StringUtils.equals(YKCUtils.frameType2Str(YKCFrameTypeCode.TRANSACTION_RECORDS_CODE.getBytes()), frameType)) { + // // 浜ゆ槗璁板綍 + // vo.setDescription("浜ゆ槗缁撶畻"); + // }else if (StringUtils.equals(YKCUtils.frameType2Str(YKCFrameTypeCode.PILE_LOG_OUT.getBytes()), frameType)) { + // // 閫鍑 + // vo.setDescription("鍏呯數妗╅鍑"); + // } + vo.setPileSn(pileMsgRecord.getPileSn()); + vo.setCreateTime(pileMsgRecord.getCreateTime()); + vo.setFrameType(frameType); + list.add(vo); + } + + PageResponse pageResponse = PageResponse.builder() + .pageNum(pageInfo.getPageNum()) + .pageSize(pageInfo.getPageSize()) + .list(list) + .total(pageInfo.getTotal()) + .pages(pageInfo.getPages()) + .build(); + return pageResponse; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileSimInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileSimInfoServiceImpl.java new file mode 100644 index 000000000..a45bd2b9f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileSimInfoServiceImpl.java @@ -0,0 +1,137 @@ +package com.jsowell.pile.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.util.DateUtils; +import com.jsowell.pile.domain.PileSimInfo; +import com.jsowell.pile.dto.QuerySimInfoDTO; +import com.jsowell.pile.mapper.PileSimInfoMapper; +import com.jsowell.pile.service.IPileSimInfoService; +import com.jsowell.pile.vo.web.SimCardInfoVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 鍏呯數妗㏒IM鍗′俊鎭疭ervice涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-08-26 + */ +@Slf4j +@Service +public class PileSimInfoServiceImpl implements IPileSimInfoService { + @Autowired + private PileSimInfoMapper pileSimInfoMapper; + + /** + * 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭 + * + * @param id 鍏呯數妗㏒IM鍗′俊鎭富閿 + * @return 鍏呯數妗㏒IM鍗′俊鎭 + */ + @Override + public PileSimInfo selectPileSimInfoById(Long id) { + return pileSimInfoMapper.selectPileSimInfoById(id); + } + + /** + * 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭垪琛 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 鍏呯數妗㏒IM鍗′俊鎭 + */ + @Override + public List selectPileSimInfoList(PileSimInfo pileSimInfo) { + return pileSimInfoMapper.selectPileSimInfoList(pileSimInfo); + } + + /** + * 鍚庣鏌ヨsim鍗′俊鎭垪琛 + * @return + */ + @Override + public List getSimInfoList(QuerySimInfoDTO dto) { + return pileSimInfoMapper.getSimInfoList(dto); + } + + /** + * 鏂板鍏呯數妗㏒IM鍗′俊鎭 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 缁撴灉 + */ + @Override + public int insertPileSimInfo(PileSimInfo pileSimInfo) { + pileSimInfo.setCreateTime(DateUtils.getNowDate()); + log.info("鏂板鍏呯數妗㏒IM鍗′俊鎭 PileSimInfo:{}", JSON.toJSONString(pileSimInfo)); + return pileSimInfoMapper.insertPileSimInfo(pileSimInfo); + } + + /** + * 淇敼鍏呯數妗㏒IM鍗′俊鎭 + * + * @param pileSimInfo 鍏呯數妗㏒IM鍗′俊鎭 + * @return 缁撴灉 + */ + @Override + public int updatePileSimInfo(PileSimInfo pileSimInfo) { + pileSimInfo.setUpdateTime(DateUtils.getNowDate()); + return pileSimInfoMapper.updatePileSimInfo(pileSimInfo); + } + + /** + * 鎵归噺鍒犻櫎鍏呯數妗㏒IM鍗′俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數妗㏒IM鍗′俊鎭富閿 + * @return 缁撴灉 + */ + @Override + public int deletePileSimInfoByIds(Long[] ids) { + return pileSimInfoMapper.deletePileSimInfoByIds(ids); + } + + /** + * 鍒犻櫎鍏呯數妗㏒IM鍗′俊鎭俊鎭 + * + * @param id 鍏呯數妗㏒IM鍗′俊鎭富閿 + * @return 缁撴灉 + */ + @Override + public int deletePileSimInfoById(Long id) { + return pileSimInfoMapper.deletePileSimInfoById(id); + } + + /** + * 閫氳繃妗╃紪鐮佹煡璇im鍗′俊鎭 + * + * @param pileSn 妗╃紪鐮 + * @return + */ + @Override + public SimCardInfoVO querySimCardInfoByPileSn(String pileSn) { + return pileSimInfoMapper.querySimCardInfoByPileSn(pileSn); + } + + /** + * 閫氳繃鍗″彿鎵归噺鏌ヨsim鍗′俊鎭 + * + * @param iccIds 鍗″彿 + * @return + */ + @Override + public List selectSimInfoByIccIds(List iccIds) { + return pileSimInfoMapper.selectSimInfoByIccIds(iccIds); + } + + /** + * 閫氳繃鍗″彿鏌ヨsim鍗′俊鎭 + * + * @param iccId 鍗″彿 + * @return + */ + public PileSimInfo getBasicInfoByIccId(String iccId) { + return pileSimInfoMapper.getBasicInfoByIccId(iccId); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java new file mode 100644 index 000000000..d3e4b51e0 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java @@ -0,0 +1,352 @@ +package com.jsowell.pile.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.google.common.collect.Lists; +import com.jsowell.common.annotation.DataScope; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.entity.SysDept; +import com.jsowell.common.core.page.PageResponse; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.DistanceUtils; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.ip.AddressUtils; +import com.jsowell.pile.domain.PileStationInfo; +import com.jsowell.pile.dto.FastCreateStationDTO; +import com.jsowell.pile.dto.QueryStationDTO; +import com.jsowell.pile.mapper.PileStationInfoMapper; +import com.jsowell.pile.service.IPileBillingTemplateService; +import com.jsowell.pile.service.IPileConnectorInfoService; +import com.jsowell.pile.service.IPileMerchantInfoService; +import com.jsowell.pile.service.IPileStationInfoService; +import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.base.MerchantInfoVO; +import com.jsowell.pile.vo.base.StationInfoVO; +import com.jsowell.pile.vo.uniapp.CurrentTimePriceDetails; +import com.jsowell.pile.vo.web.PileStationVO; +import com.jsowell.system.service.SysDeptService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * 鍏呯數绔欎俊鎭疭ervice涓氬姟灞傚鐞 + * + * @author jsowell + * @date 2022-08-30 + */ +@Service +public class PileStationInfoServiceImpl implements IPileStationInfoService { + @Autowired + private PileStationInfoMapper pileStationInfoMapper; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private IPileMerchantInfoService pileMerchantInfoService; + + @Autowired + private SysDeptService sysDeptService; + + /** + * 鏌ヨ鍏呯數绔欎俊鎭 + * + * @param id 鍏呯數绔欎俊鎭富閿 + * @return 鍏呯數绔欎俊鎭 + */ + @Override + public PileStationInfo selectPileStationInfoById(Long id) { + return pileStationInfoMapper.selectPileStationInfoById(id); + } + + /** + * 鏌ヨ绔欑偣鍩烘湰璧勬枡 + * @param stationId + * @return + */ + @Override + public PileStationVO getStationInfo(String stationId) { + PileStationVO vo = new PileStationVO(); + PileStationInfo pileStationInfo = selectPileStationInfoById(Long.parseLong(stationId)); + // 鏌ヨ璐规ā鏉 + CurrentTimePriceDetails currentTimePriceDetails = pileBillingTemplateService.getCurrentTimePriceDetails(stationId); + if (currentTimePriceDetails != null) { + vo.setElectricityPrice(new BigDecimal(currentTimePriceDetails.getElectricityPrice())); + vo.setServicePrice(new BigDecimal(currentTimePriceDetails.getServicePrice())); + } + + if (pileStationInfo != null) { + vo.setMerchantId(pileStationInfo.getMerchantId().toString()); + vo.setStationName(pileStationInfo.getStationName()); + vo.setId(pileStationInfo.getId().toString()); + vo.setAreaCode(pileStationInfo.getAreaCode()); + vo.setAddress(pileStationInfo.getAddress()); + vo.setMerchantId(pileStationInfo.getMerchantId().toString()); + // vo.setMerchantName(pileStationInfo.getmer()); + vo.setMerchantAdminName(pileStationInfo.getStationAdminName()); + vo.setStationStatus(Integer.parseInt(pileStationInfo.getStationStatus())); + vo.setStationType(pileStationInfo.getStationType()); + vo.setCreateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, pileStationInfo.getCreateTime())); + vo.setStationTel(pileStationInfo.getStationTel()); + vo.setMatchCars(pileStationInfo.getMatchCars()); + if (StringUtils.isNotBlank(pileStationInfo.getMatchCars())) { + vo.setSelectMatchCars(Lists.newArrayList(pileStationInfo.getMatchCars().split(","))); + } + vo.setStationLat(pileStationInfo.getStationLat()); + vo.setStationLng(pileStationInfo.getStationLng()); + vo.setConstruction(pileStationInfo.getConstruction()); + vo.setBusinessHours(pileStationInfo.getBusinessHours()); + // vo.setOrganizationCode(pileStationInfo.getor); + vo.setPublicFlag(pileStationInfo.getPublicFlag()); + vo.setOpenFlag(pileStationInfo.getOpenFlag()); + } + return vo; + } + + /** + * 鏌ヨ鍏呯數绔欎俊鎭垪琛 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 鍏呯數绔欎俊鎭 + */ + @Override + public List selectPileStationInfoList(PileStationInfo pileStationInfo) { + return pileStationInfoMapper.selectPileStationInfoList(pileStationInfo); + } + + /** + * 閫氳繃杩愯惀鍟唅d鏌ヨ绔欑偣淇℃伅 + * + * @param merchantId 杩愯惀鍟唅d + * @return 绔欑偣淇℃伅鍒楄〃 + */ + @Override + public List selectStationListByMerchantId(Long merchantId) { + return pileStationInfoMapper.selectStationListByMerchantId(merchantId); + } + + /** + * 鏂板鍏呯數绔欎俊鎭 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 缁撴灉 + */ + @Override + + public int insertPileStationInfo(PileStationInfo pileStationInfo) { + pileStationInfo.setCreateTime(DateUtils.getNowDate()); + pileStationInfo.setCreateBy(SecurityUtils.getUsername()); + return pileStationInfoMapper.insertPileStationInfo(pileStationInfo); + } + + /** + * 蹇熷缓绔 + * @param dto + * @return + */ + @Override + public int fastCreateStation(FastCreateStationDTO dto) { + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(dto.getMerchantId()); + if (merchantInfo == null) { + return 0; + } + + // 1. 鏂板sys_dept + SysDept dept = new SysDept(); + // 鏍规嵁杩愯惀鍟咺d鏌ヨ鍒板搴旂殑閮ㄩ棬id + dept.setParentId(Long.parseLong(merchantInfo.getDeptId())); + dept.setOrderNum(0); + dept.setDeptName(dto.getStationName()); + dept.setLeader(dto.getStationAdminName()); + dept.setPhone(dto.getStationTel()); + dept.setStatus("0"); + sysDeptService.insertDept(dept); + + PileStationInfo pileStationInfo = new PileStationInfo(); + // pileStationInfo.setId(dept.getDeptId()); + pileStationInfo.setDeptId(String.valueOf(dept.getDeptId())); + // 鍓嶇杈撳叆淇℃伅 + pileStationInfo.setMerchantId(Long.valueOf(dto.getMerchantId())); + pileStationInfo.setStationName(dto.getStationName()); + pileStationInfo.setAddress(dto.getAddress()); + pileStationInfo.setAreaCode(dto.getAreaCode()); + pileStationInfo.setCapacity(BigDecimal.ZERO); // 瀹归噺 + pileStationInfo.setStationTel(dto.getStationTel()); + pileStationInfo.setStationAdminName(dto.getStationAdminName()); + // 鑾峰彇缁忕含搴 + Map longitudeAndLatitude = AddressUtils.getLongitudeAndLatitude(dto.getAreaCode(), dto.getAddress()); + if (longitudeAndLatitude != null) { + pileStationInfo.setStationLng(longitudeAndLatitude.get("lng")); + pileStationInfo.setStationLat(longitudeAndLatitude.get("lat")); + } + pileStationInfo.setCreateBy(SecurityUtils.getUsername()); + int i = pileStationInfoMapper.insertPileStationInfo(pileStationInfo); + + + return i; + } + + /** + * 淇敼鍏呯數绔欎俊鎭 + * + * @param pileStationInfo 鍏呯數绔欎俊鎭 + * @return 缁撴灉 + */ + @Override + public int updatePileStationInfo(PileStationInfo pileStationInfo) { + pileStationInfo.setUpdateBy(SecurityUtils.getUsername()); + pileStationInfo.setUpdateTime(DateUtils.getNowDate()); + return pileStationInfoMapper.updatePileStationInfo(pileStationInfo); + } + + /** + * 鎵归噺鍒犻櫎鍏呯數绔欎俊鎭 + * + * @param ids 闇瑕佸垹闄ょ殑鍏呯數绔欎俊鎭富閿 + * @return 缁撴灉 + */ + @Override + public int deletePileStationInfoByIds(Long[] ids) { + return pileStationInfoMapper.deletePileStationInfoByIds(ids); + } + + /** + * 鍏呯數绔欏垪琛ㄤ俊鎭 + * @param dto 鍓嶅彴鍙傛暟 + * @return 鍏呯數绔欏璞¢泦鍚 + */ + @Override + @DataScope(deptAlias = "t3") + public List queryStationInfos(QueryStationDTO dto) { + List list = pileStationInfoMapper.queryStationInfos(dto); + // if (Objects.nonNull(list)){ + // for (PileStationVO p:list) { + // String station_type = p.getStationType(); + // p.setStationType(DictUtils.getDictLabel("station_type", station_type)); + // } + // } + return list; + } + + /** + * uniApp鏌ヨ鍏呯數绔欎俊鎭苟閫氳繃缁忕含搴︽帓搴 + * + * @param dto 鍓嶅彴鍙傛暟 + * @return 鍏呯數绔欏璞¢泦鍚 + */ + @Override + public PageResponse uniAppQueryStationInfoList(QueryStationDTO dto) { + int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum(); + int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize(); + + // 灏忕▼搴忕珯鐐瑰垪琛ㄩ〉鍙睍绀哄澶栧紑鏀剧殑绔欑偣 + dto.setPublicFlag(Constants.ONE); + // 鏍规嵁鍓嶅彴鍙傛暟鍒嗛〉 + PageHelper.startPage(pageNum, pageSize); + List list = pileStationInfoMapper.queryStationInfos(dto); + PageInfo pageInfo = new PageInfo<>(list); + if (CollectionUtils.isEmpty(pageInfo.getList())) { + return PageResponse.builder() + .pageNum(pageInfo.getPageNum()) + .pageSize(pageInfo.getPageSize()) + .list(Lists.newArrayList()) + .pages(pageInfo.getPages()) + .total(pageInfo.getTotal()) + .build(); + } + + List stationVOList = Lists.newArrayList(); + StationInfoVO stationVO = null; + String stationLng = dto.getStationLng(); + String stationLat = dto.getStationLat(); + double distance = 0d; + for (PileStationVO pileStationVO : pageInfo.getList()) { + stationVO = new StationInfoVO(); + if (StringUtils.isNotEmpty(stationLng) && StringUtils.isNotEmpty(stationLat)) { + try{ + // 璁$畻褰撳墠缁忕含搴﹀拰绔欑偣涔嬮棿鐨勮窛绂 + distance = DistanceUtils.getDistance(Double.parseDouble(stationLng), Double.parseDouble(stationLat), + Double.parseDouble(pileStationVO.getStationLng()), Double.parseDouble(pileStationVO.getStationLat())); + // 淇濈暀涓や綅灏忔暟 + stationVO.setDistance(String.format("%.2f", distance)); + }catch (Exception e){ + stationVO.setDistance("0.00"); + } + + } + stationVO.setStationId(pileStationVO.getId()); + stationVO.setStationName(pileStationVO.getStationName()); + stationVO.setStationAddress(pileStationVO.getAddress()); + stationVO.setStationLat(pileStationVO.getStationLat()); + stationVO.setStationLng(pileStationVO.getStationLng()); + + // 绔欑偣鍥剧墖 + if (StringUtils.isNotBlank(pileStationVO.getPictures())) { + stationVO.setStationImgList(Lists.newArrayList(pileStationVO.getPictures().split(","))); + } + // 鏋彛鏁伴噺 + int fastTotal = 0; + int fastFree = 0; + int slowTotal = 0; + int slowFree = 0; + List connectorList = pileConnectorInfoService.getUniAppConnectorList(Long.parseLong(pileStationVO.getId())); + for (ConnectorInfoVO connectorVO : connectorList) { + if (StringUtils.equals(connectorVO.getChargingType(), Constants.ONE)) { + // 蹇厖 + fastTotal += 1; + if (StringUtils.equals(connectorVO.getConnectorStatus(), Constants.ONE)) { + fastFree += 1; + } + } else { + // 鎱㈠厖 + slowTotal += 1; + if (StringUtils.equals(connectorVO.getConnectorStatus(), Constants.ONE)) { + slowFree += 1; + } + } + } + stationVO.setFastTotal(fastTotal); + stationVO.setFastFree(fastFree); + stationVO.setSlowTotal(slowTotal); + stationVO.setSlowFree(slowFree); + + // 鏌ヨ褰撳墠鏃舵鐢佃垂 + CurrentTimePriceDetails currentTimePriceDetails = pileBillingTemplateService.getCurrentTimePriceDetails(stationVO.getStationId()); + if (currentTimePriceDetails != null) { + stationVO.setElectricityPrice(currentTimePriceDetails.getElectricityPrice()); + stationVO.setServicePrice(currentTimePriceDetails.getServicePrice()); + stationVO.setTotalPrice(currentTimePriceDetails.getTotalPrice()); + } + stationVOList.add(stationVO); + } + + if (distance != 0.00) { + // 瀵归泦鍚堟寜鐓ц窛绂绘帓搴忥紝璺濈灏忕殑鍦ㄥ墠 + stationVOList.sort((o1, o2) -> { + Double a = Double.valueOf(o1.getDistance()); + Double b = Double.valueOf(o2.getDistance()); + return a.compareTo(b); + }); + } + + // 杩斿洖缁撴灉闆 + return PageResponse.builder() + .pageNum(pageInfo.getPageNum()) + .pageSize(pageInfo.getPageSize()) + .list(stationVOList) + .pages(pageInfo.getPages()) + .total(pageInfo.getTotal()) + .build(); + } + +} + diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WechatPayServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WechatPayServiceImpl.java new file mode 100644 index 000000000..90b8cccc6 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WechatPayServiceImpl.java @@ -0,0 +1,353 @@ +package com.jsowell.pile.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Maps; +import com.jsowell.common.enums.MemberWalletEnum; +import com.jsowell.common.enums.ykc.ActionTypeEnum; +import com.jsowell.common.enums.ykc.PayModeEnum; +import com.jsowell.common.enums.ykc.ScenarioEnum; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.SnowflakeIdWorker; +import com.jsowell.pile.domain.MemberTransactionRecord; +import com.jsowell.pile.domain.WxpayCallbackRecord; +import com.jsowell.pile.domain.WxpayRefundCallback; +import com.jsowell.pile.dto.PaymentScenarioDTO; +import com.jsowell.pile.dto.WeixinPayDTO; +import com.jsowell.pile.service.IMemberBasicInfoService; +import com.jsowell.pile.service.IMemberTransactionRecordService; +import com.jsowell.pile.service.WechatPayService; +import com.jsowell.pile.service.WxpayCallbackRecordService; +import com.jsowell.pile.service.WxpayRefundCallbackService; +import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; +import com.jsowell.wxpay.common.WeChatPayParameter; +import com.jsowell.wxpay.response.WechatPayNotifyParameter; +import com.jsowell.wxpay.response.WechatPayNotifyResource; +import com.jsowell.wxpay.response.WechatPayRefundNotifyResource; +import com.jsowell.wxpay.response.WechatPayRefundRequest; +import com.jsowell.wxpay.response.WechatPayRefundResponse; +import com.jsowell.wxpay.utils.AesUtil; +import com.jsowell.wxpay.utils.HttpUtils; +import com.jsowell.wxpay.utils.WechatPayUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.security.cert.X509Certificate; +import java.util.HashMap; +import java.util.Map; + +/** + * 寰俊鏀粯 + */ +@Slf4j +@Service +public class WechatPayServiceImpl implements WechatPayService { + + @Autowired + private WxpayCallbackRecordService wxpayCallbackRecordService; + + @Autowired + private WxpayRefundCallbackService wxpayRefundCallbackService; + + @Autowired + private IMemberBasicInfoService memberBasicInfoService; + + @Autowired + private IMemberTransactionRecordService memberTransactionRecordService; + + @Override + public Map weixinPayV3(WeixinPayDTO dto) throws Exception { + String openId = dto.getOpenId(); + //灏佽璇锋眰鍙傛暟 + Map paramMap = new HashMap<>(); + // 鏀粯鐨勪骇鍝侊紙灏忕▼搴忔垨鑰呭叕浼楀彿锛屼富瑕侀渶瑕佸拰寰俊鏀粯缁戝畾鍝︼級 + paramMap.put("appid", WeChatPayParameter.appId); + // 鏀粯鐨勫晢鎴峰彿 + paramMap.put("mchid", WeChatPayParameter.mchId); + // 鍟嗗搧鎻忚堪 + paramMap.put("description", dto.getDescription()); + // 鍟嗘埛璁㈠崟鍙 + paramMap.put("out_trade_no", SnowflakeIdWorker.getSnowflakeId()); + // 浜ゆ槗缁撴潫鏃堕棿 + paramMap.put("time_expire", getTimeExpire()); + // 闄勫姞鏁版嵁 + paramMap.put("attach", dto.getAttach()); + // 閫氱煡鍦板潃 + paramMap.put("notify_url", WeChatPayParameter.notifyUrl); + + Map amountMap = Maps.newHashMap(); + //璁㈠崟閲戦 鍗曚綅鍒 + amountMap.put("total", Integer.parseInt(getMoney(dto.getAmount()))); + amountMap.put("currency", "CNY"); + paramMap.put("amount", amountMap); + // 璁剧疆灏忕▼搴忔墍闇鐨刼penid + Map payerMap = Maps.newHashMap(); + payerMap.put("openid", openId); + paramMap.put("payer", payerMap); + + ObjectMapper objectMapper = new ObjectMapper(); + String body = objectMapper.writeValueAsString(paramMap); + log.info("鏀粯鐨勭浉鍏冲弬鏁版槸锛歿}", body); + + Map stringObjectMap = HttpUtils.doPostWexin(WeChatPayParameter.unifiedOrderUrlJS, body); + try { + return WechatPayUtils.getTokenWeixin(WeChatPayParameter.appId, String.valueOf(stringObjectMap.get("prepay_id"))); + } catch (Exception e) { + log.error("寰俊鏀粯v3 error", e); + } + return null; + } + + /** + * 鑾峰彇杩囨湡鏃堕棿 + * @return + */ + private String getTimeExpire() { + long currentTimeMillis = System.currentTimeMillis(); + currentTimeMillis = currentTimeMillis + (30 * 60 * 1000); + return DateUtils.timeStampToRfc3339(currentTimeMillis); + } + + /** + * 鍏冭浆鎹㈡垚鍒 + * + * @param amount + * @return + */ + public static String getMoney(String amount) { + if (amount == null) { + return ""; + } + // 閲戦杞寲涓哄垎涓哄崟浣 + // 澶勭悊鍖呭惈, 锟 鎴栬$鐨勯噾棰 + String currency = amount.replaceAll("\\$|\\锟\\,", ""); + int index = currency.indexOf("."); + int length = currency.length(); + Long amLong = 0L; + if (index == -1) { + amLong = Long.valueOf(currency + "00"); + } else if (length - index >= 3) { + amLong = Long.valueOf((currency.substring(0, index + 3)).replace(".", "")); + } else if (length - index == 2) { + amLong = Long.valueOf((currency.substring(0, index + 2)).replace(".", "") + 0); + } else { + amLong = Long.valueOf((currency.substring(0, index + 1)).replace(".", "") + "00"); + } + return amLong.toString(); + } + + /** + * 寰俊鏀粯鍥炶皟 + * @param request + * @param body + * @throws Exception + * @return + */ + @Override + public Map wechatPayCallbackInfo(HttpServletRequest request, WechatPayNotifyParameter body) throws Exception { + Map resultMap = Maps.newHashMap(); + //1锛氳幏鍙栧井淇℃敮浠樺洖璋冪殑鑾峰彇绛惧悕淇℃伅 + String timestamp = request.getHeader("Wechatpay-Timestamp"); + String nonce = request.getHeader("Wechatpay-Nonce"); + ObjectMapper objectMapper = new ObjectMapper(); + // 2: 寮濮嬭В鏋愭姤鏂囦綋 + String data = objectMapper.writeValueAsString(body); + String message = timestamp + "\n" + nonce + "\n" + data + "\n"; + //3锛氳幏鍙栧簲绛旂鍚 + String sign = request.getHeader("Wechatpay-Signature"); + //4锛氳幏鍙栧钩鍙板搴旂殑璇佷功 + String serialNo = request.getHeader("Wechatpay-Serial"); + if (!WeChatPayParameter.certificateMap.containsKey(serialNo)) { + WeChatPayParameter.certificateMap = WechatPayUtils.refreshCertificate(); + } + X509Certificate x509Certificate = WeChatPayParameter.certificateMap.get(serialNo); + if (!WechatPayUtils.verify(x509Certificate, message.getBytes(), sign)) { + throw new IllegalArgumentException("寰俊鏀粯绛惧悕楠岃瘉澶辫触:" + message); + } + // log.info("绛惧悕楠岃瘉鎴愬姛"); + WechatPayNotifyParameter.Resource resource = body.getResource(); + // 5锛氬洖璋冩姤鏂囪В瀵 + AesUtil aesUtil = new AesUtil(WeChatPayParameter.v3Key.getBytes()); + // 瑙e瘑鍚巎son瀛楃涓 + String decryptToString = aesUtil.decryptToString( + resource.getAssociated_data().getBytes(), + resource.getNonce().getBytes(), + resource.getCiphertext()); + log.info("2-->decryptToString====>{}", decryptToString); + + //6锛氳幏鍙栧井淇℃敮浠樿繑鍥炵殑淇℃伅 + WechatPayNotifyResource wechatPayNotifyResource = JSON.parseObject(decryptToString, WechatPayNotifyResource.class); + //7: 鏀粯鐘舵佺殑鍒ゆ柇 濡傛灉鏄痵uccess灏变唬琛ㄦ敮浠樻垚鍔 + if (StringUtils.equals(wechatPayNotifyResource.getTrade_state(), "SUCCESS")) { + // 8锛氳幏鍙栨敮浠樼殑浜ゆ槗鍗曞彿锛屾祦姘村彿锛屽拰闄勫睘鍙傛暟 + String out_trade_no = wechatPayNotifyResource.getOut_trade_no(); + // 寰俊鏀粯鍗曞彿 + String transaction_id = wechatPayNotifyResource.getTransaction_id(); + String attach = wechatPayNotifyResource.getAttach(); + log.info("3-->寰俊鏀粯鎴愬姛,鍟嗘埛璁㈠崟鍙锋槸:{}, 鏀粯璁㈠崟鍙:{}, 闄勫睘鍙傛暟鏄細{}", out_trade_no, transaction_id, attach); + // 杞崲闄勫睘鍙傛暟 + PaymentScenarioDTO paymentScenarioDTO = JSONObject.parseObject(attach, PaymentScenarioDTO.class); + String type = paymentScenarioDTO.getType(); + BigDecimal amount = new BigDecimal(wechatPayNotifyResource.getAmount().getTotal()); + if (StringUtils.equals(type, ScenarioEnum.ORDER.getValue())) { + // 1-璁㈠崟鏀粯 + resultMap.put("orderCode", paymentScenarioDTO.getOrderCode()); + resultMap.put("memberId", paymentScenarioDTO.getMemberId()); + resultMap.put("amount", amount); + resultMap.put("type", type); + } else if (StringUtils.equals(type, ScenarioEnum.BALANCE.getValue())) { + // 2-鍏呭间綑棰 + resultMap.put("memberId", paymentScenarioDTO.getMemberId()); + resultMap.put("amount", amount); + resultMap.put("type", type); + } + resultMap.put("out_trade_no", out_trade_no); + resultMap.put("transaction_id", transaction_id); + // 淇濆瓨寰俊鏀粯璁板綍 + WxpayCallbackRecord record = new WxpayCallbackRecord(); + record.setPayScenario(type); + record.setMemberId(paymentScenarioDTO.getMemberId()); + record.setOrderCode(paymentScenarioDTO.getOrderCode()); + record.setOutTradeNo(out_trade_no); + record.setTransactionId(transaction_id); + record.setMchId(wechatPayNotifyResource.getMchid()); + record.setAppId(wechatPayNotifyResource.getAppid()); + record.setTradeType(wechatPayNotifyResource.getTrade_type()); + record.setTradeState(wechatPayNotifyResource.getTrade_state()); + record.setTradeStateDesc(wechatPayNotifyResource.getTrade_state_desc()); + record.setBankType(wechatPayNotifyResource.getBank_type()); + record.setAttach(wechatPayNotifyResource.getAttach()); + record.setSuccessTime(DateUtils.toLocalDateTime(wechatPayNotifyResource.getSuccess_time(), DateUtils.RFC3339)); + record.setPayerOpenId(wechatPayNotifyResource.getPayer().getOpenid()); + record.setPayerTotal(wechatPayNotifyResource.getAmount().getPayer_total()); + wxpayCallbackRecordService.insertSelective(record); + } + return resultMap; + } + + /** + * 鑾峰彇寰俊閫娆惧洖璋冧俊鎭 + * + * @param request + * @param body + * @return + */ + @Override + public Map wechatPayRefundCallbackInfo(HttpServletRequest request, WechatPayNotifyParameter body) throws Exception { + //1锛氳幏鍙栧井淇℃敮浠樺洖璋冪殑鑾峰彇绛惧悕淇℃伅 + String timestamp = request.getHeader("Wechatpay-Timestamp"); + String nonce = request.getHeader("Wechatpay-Nonce"); + ObjectMapper objectMapper = new ObjectMapper(); + // 2: 寮濮嬭В鏋愭姤鏂囦綋 + String data = objectMapper.writeValueAsString(body); + String message = timestamp + "\n" + nonce + "\n" + data + "\n"; + //3锛氳幏鍙栧簲绛旂鍚 + String sign = request.getHeader("Wechatpay-Signature"); + //4锛氳幏鍙栧钩鍙板搴旂殑璇佷功 + String serialNo = request.getHeader("Wechatpay-Serial"); + if (!WeChatPayParameter.certificateMap.containsKey(serialNo)) { + WeChatPayParameter.certificateMap = WechatPayUtils.refreshCertificate(); + } + X509Certificate x509Certificate = WeChatPayParameter.certificateMap.get(serialNo); + if (!WechatPayUtils.verify(x509Certificate, message.getBytes(), sign)) { + throw new IllegalArgumentException("寰俊鏀粯绛惧悕楠岃瘉澶辫触:" + message); + } + // log.info("绛惧悕楠岃瘉鎴愬姛"); + WechatPayNotifyParameter.Resource resource = body.getResource(); + // 5锛氬洖璋冩姤鏂囪В瀵 + AesUtil aesUtil = new AesUtil(WeChatPayParameter.v3Key.getBytes()); + // 瑙e瘑鍚巎son瀛楃涓 + String decryptToString = aesUtil.decryptToString( + resource.getAssociated_data().getBytes(), + resource.getNonce().getBytes(), + resource.getCiphertext()); + log.info("寰俊閫娆惧洖璋冧俊鎭:{}", decryptToString); + + WechatPayRefundNotifyResource refundNotifyResource = JSONObject.parseObject(decryptToString, WechatPayRefundNotifyResource.class); + if (refundNotifyResource == null) { + return null; + } + // 鏌ヨ鍘熸敮浠樹俊鎭紝鑾峰彇鏄鍗曠粨绠楅娆捐繕鏄綑棰濋娆 + String out_trade_no = refundNotifyResource.getOut_trade_no(); + String out_refund_no = refundNotifyResource.getOut_refund_no(); + String transaction_id = refundNotifyResource.getTransaction_id(); + String refund_id = refundNotifyResource.getRefund_id(); + + WxpayCallbackRecord wxpayCallbackRecord = wxpayCallbackRecordService.selectByOutTradeNo(out_trade_no); + if (wxpayCallbackRecord == null) { + log.info("鏌ヨ鍘熸敮浠樹俊鎭负绌 OutTradeNo:{}", out_trade_no); + return null; + } + + String memberId = wxpayCallbackRecord.getMemberId(); + String orderCode = wxpayCallbackRecord.getOrderCode(); + // 閫娆鹃噾棰 鍗曚綅鍒 + int payer_refund = refundNotifyResource.getAmount().getPayer_refund(); + // 鍒嗚浆鎴愬厓 + BigDecimal refundAmount = new BigDecimal(payer_refund).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP); + if (StringUtils.equals(wxpayCallbackRecord.getPayScenario(), ScenarioEnum.BALANCE.getValue())) { + // 杩欑瑪鏀粯璁㈠崟鍘熸潵鏄厖鍊间綑棰濈殑锛岄娆炬垚鍔熶簡锛岄渶瑕佹墸鎺変細鍛樼殑鏈噾閲戦 + UpdateMemberBalanceDTO dto = new UpdateMemberBalanceDTO(); + dto.setMemberId(memberId); + dto.setUpdatePrincipalBalance(refundAmount); // 鏇存柊浼氬憳鏈噾閲戦锛屽崟浣嶅厓 + dto.setType(MemberWalletEnum.TYPE_OUT.getValue()); + dto.setSubType(MemberWalletEnum.SUBTYPE_USER_REFUND.getValue()); + memberBasicInfoService.updateMemberBalance(dto); + } + + // 淇濆瓨寰俊閫娆惧洖璋冧俊鎭 + WxpayRefundCallback record = WxpayRefundCallback.builder() + .memberId(memberId) + .orderCode(orderCode) + .outTradeNo(out_trade_no) + .outRefundNo(out_refund_no) + .transactionId(transaction_id) + .mchId(refundNotifyResource.getMchid()) + .refundId(refund_id) + .refundStatus(refundNotifyResource.getRefund_status()) + .successTime(refundNotifyResource.getSuccess_time()) + .userReceivedAccount(refundNotifyResource.getUser_received_account()) + .payerTotal(refundNotifyResource.getAmount().getPayer_total() + "") + .payerRefund(payer_refund + "") // 寰俊鏀粯鎺ユ敹鍗曚綅鍒 + .amountTotal(refundNotifyResource.getAmount().getTotal() + "") + .amountRefund(refundNotifyResource.getAmount().getRefund() + "") + .build(); + wxpayRefundCallbackService.insertSelective(record); + + // 浣欓鏀粯璁㈠崟 璁板綍浼氬憳浜ゆ槗娴佹按 + MemberTransactionRecord memberTransactionRecord = MemberTransactionRecord.builder() + .orderCode(orderCode) + .scenarioType(wxpayCallbackRecord.getPayScenario()) + .memberId(memberId) + .actionType(ActionTypeEnum.REVERSE.getValue()) + .payMode(PayModeEnum.PAYMENT_OF_WECHATPAY.getValue()) + .amount(refundAmount) // 璁板綍浼氬憳浜ゆ槗娴佹按锛屽崟浣嶅厓 + .outTradeNo(out_trade_no) + .transactionId(transaction_id) + .outRefundNo(out_refund_no) + .refundId(refund_id) + .build(); + memberTransactionRecordService.insertSelective(memberTransactionRecord); + return null; + } + + /** + * 寰俊鏀粯 鐢宠閫娆炬帴鍙 + */ + @Override + public WechatPayRefundResponse ApplyForWechatPayRefundV3(WechatPayRefundRequest request) throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + String body = objectMapper.writeValueAsString(request); + log.info("鐢宠閫娆剧殑鐩稿叧鍙傛暟鏄:{}", body); + Map stringObjectMap = HttpUtils.doPostWexin(WeChatPayParameter.refundJsUrl, body); + log.info("鐢宠閫娆剧殑杩斿洖鍙傛暟鏄:{}", stringObjectMap); + return JSON.parseObject(JSON.toJSONString(stringObjectMap), WechatPayRefundResponse.class); + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WxpayCallbackRecordServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WxpayCallbackRecordServiceImpl.java new file mode 100644 index 000000000..cb10f7639 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WxpayCallbackRecordServiceImpl.java @@ -0,0 +1,86 @@ +package com.jsowell.pile.service.impl; + +import com.jsowell.pile.domain.WxpayCallbackRecord; +import com.jsowell.pile.mapper.WxpayCallbackRecordMapper; +import com.jsowell.pile.service.WxpayCallbackRecordService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; + +@Slf4j +@Service +public class WxpayCallbackRecordServiceImpl implements WxpayCallbackRecordService { + + @Resource + private WxpayCallbackRecordMapper wxpayCallbackRecordMapper; + + @Override + public int deleteByPrimaryKey(Integer id) { + return wxpayCallbackRecordMapper.deleteByPrimaryKey(id); + } + + @Override + public int insert(WxpayCallbackRecord record) { + return wxpayCallbackRecordMapper.insert(record); + } + + @Override + public int insertSelective(WxpayCallbackRecord record) { + return wxpayCallbackRecordMapper.insertSelective(record); + } + + @Override + public WxpayCallbackRecord selectByPrimaryKey(Integer id) { + return wxpayCallbackRecordMapper.selectByPrimaryKey(id); + } + + @Override + public int updateByPrimaryKeySelective(WxpayCallbackRecord record) { + return wxpayCallbackRecordMapper.updateByPrimaryKeySelective(record); + } + + @Override + public int updateByPrimaryKey(WxpayCallbackRecord record) { + return wxpayCallbackRecordMapper.updateByPrimaryKey(record); + } + + @Override + public WxpayCallbackRecord selectByOrderCode(String orderCode) { + WxpayCallbackRecord wxpayCallbackRecord = null; + try { + wxpayCallbackRecord = wxpayCallbackRecordMapper.selectByOrderCode(orderCode); + } catch (Exception e) { + log.error("鏍规嵁璁㈠崟鍙锋煡璇㈠井淇℃敮浠樿褰:{}", orderCode, e); + } + return wxpayCallbackRecord; + } + + @Override + public WxpayCallbackRecord selectByOutTradeNo(String outTradeNo) { + return wxpayCallbackRecordMapper.selectByOutTradeNo(outTradeNo); + } + + @Override + public List queryBalanceRechargeRecordOfTheLatestYear(String memberId) { + LocalDateTime now = LocalDateTime.now(); + LocalDate localDate = now.minusYears(1).toLocalDate(); + LocalTime localTime = now.toLocalTime(); + LocalDateTime lastYear = LocalDateTime.of(localDate, localTime); + // 鏌ヨ鏈杩戜竴骞寸殑浣欓鍏呭艰褰 + return wxpayCallbackRecordMapper.selectBalanceRechargeRecord(memberId, lastYear); + } + + public static void main(String[] args) { + LocalDateTime now = LocalDateTime.now(); + LocalDate localDate = now.minusYears(1).toLocalDate(); + LocalTime localTime = now.toLocalTime(); + LocalDateTime of = LocalDateTime.of(localDate, localTime); + System.out.println(of); + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WxpayRefundCallbackServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WxpayRefundCallbackServiceImpl.java new file mode 100644 index 000000000..fa2eed663 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/WxpayRefundCallbackServiceImpl.java @@ -0,0 +1,41 @@ +package com.jsowell.pile.service.impl; + +import com.jsowell.pile.domain.WxpayRefundCallback; +import com.jsowell.pile.mapper.WxpayRefundCallbackMapper; +import com.jsowell.pile.service.WxpayRefundCallbackService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +public class WxpayRefundCallbackServiceImpl implements WxpayRefundCallbackService { + + @Resource + private WxpayRefundCallbackMapper wxpayRefundCallbackMapper; + + @Override + public int deleteByPrimaryKey(Integer id) { + return wxpayRefundCallbackMapper.deleteByPrimaryKey(id); + } + + @Override + public int insertSelective(WxpayRefundCallback record) { + return wxpayRefundCallbackMapper.insertSelective(record); + } + + @Override + public WxpayRefundCallback selectByPrimaryKey(Integer id) { + return wxpayRefundCallbackMapper.selectByPrimaryKey(id); + } + + @Override + public int updateByPrimaryKeySelective(WxpayRefundCallback record) { + return wxpayRefundCallbackMapper.updateByPrimaryKeySelective(record); + } + + @Override + public int updateByPrimaryKey(WxpayRefundCallback record) { + return wxpayRefundCallbackMapper.updateByPrimaryKey(record); + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/BillingTemplateTransactionDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/BillingTemplateTransactionDTO.java new file mode 100644 index 000000000..37ba17081 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/BillingTemplateTransactionDTO.java @@ -0,0 +1,32 @@ +package com.jsowell.pile.transaction.dto; + +import com.jsowell.pile.domain.PileBillingDetail; +import com.jsowell.pile.domain.PileBillingTemplate; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BillingTemplateTransactionDTO { + // 璁¤垂妯℃澘鍩烘湰淇℃伅 + private PileBillingTemplate billingTemplate; + + // 璁¤垂妯℃澘璇︽儏 + private List detailList; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("billingTemplate", billingTemplate) + .append("detailList", detailList) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/MemberTransactionDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/MemberTransactionDTO.java new file mode 100644 index 000000000..27eb03399 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/MemberTransactionDTO.java @@ -0,0 +1,18 @@ +package com.jsowell.pile.transaction.dto; + +import com.jsowell.pile.domain.MemberBasicInfo; +import com.jsowell.pile.domain.MemberWalletInfo; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MemberTransactionDTO { + private MemberBasicInfo memberBasicInfo; + + private MemberWalletInfo memberWalletInfo; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/OrderTransactionDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/OrderTransactionDTO.java new file mode 100644 index 000000000..87aa3c601 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/OrderTransactionDTO.java @@ -0,0 +1,24 @@ +package com.jsowell.pile.transaction.dto; + +import com.jsowell.pile.domain.OrderBasicInfo; +import com.jsowell.pile.domain.OrderDetail; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class OrderTransactionDTO { + /** + * 璁㈠崟鍩烘湰淇℃伅 + */ + private OrderBasicInfo orderBasicInfo; + + /** + * 璁㈠崟璇︽儏 + */ + private OrderDetail orderDetail; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/PileTransactionDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/PileTransactionDTO.java new file mode 100644 index 000000000..fa2bddf23 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/dto/PileTransactionDTO.java @@ -0,0 +1,20 @@ +package com.jsowell.pile.transaction.dto; + +import com.jsowell.pile.domain.PileBasicInfo; +import com.jsowell.pile.domain.PileConnectorInfo; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileTransactionDTO { + private List pileBasicInfoList; + + private List pileConnectorInfoList; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/transaction/service/TransactionService.java b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/service/TransactionService.java new file mode 100644 index 000000000..b617a8136 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/transaction/service/TransactionService.java @@ -0,0 +1,155 @@ +package com.jsowell.pile.transaction.service; + +import com.google.common.collect.Lists; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.mapper.MemberBasicInfoMapper; +import com.jsowell.pile.mapper.MemberWalletInfoMapper; +import com.jsowell.pile.mapper.OrderBasicInfoMapper; +import com.jsowell.pile.mapper.PileBasicInfoMapper; +import com.jsowell.pile.mapper.PileBillingTemplateMapper; +import com.jsowell.pile.mapper.PileConnectorInfoMapper; +import com.jsowell.pile.transaction.dto.BillingTemplateTransactionDTO; +import com.jsowell.pile.transaction.dto.MemberTransactionDTO; +import com.jsowell.pile.transaction.dto.OrderTransactionDTO; +import com.jsowell.pile.transaction.dto.PileTransactionDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Objects; + +/** + * 鐢ㄦ潵鍏ュ簱鐨剆ervice + */ +@Slf4j +@Service +public class TransactionService { + @Resource + private PileBasicInfoMapper pileBasicInfoMapper; + + @Resource + private PileConnectorInfoMapper pileConnectorInfoMapper; + + @Resource + private PileBillingTemplateMapper pileBillingTemplateMapper; + + @Autowired + private OrderBasicInfoMapper orderBasicInfoMapper; + + @Autowired + private MemberBasicInfoMapper memberBasicInfoMapper; + + @Autowired + private MemberWalletInfoMapper memberWalletInfoMapper; + + @Autowired + private RedisCache redisCache; + + /** + * 鎵归噺鏂板鍏呯數妗╁拰鍏呯數妗╂帴鍙 + * @param dto + * @return + */ + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public int doCreatePileTransaction(PileTransactionDTO dto) { + int result = 0; + if (CollectionUtils.isNotEmpty(dto.getPileBasicInfoList())) { + result = pileBasicInfoMapper.batchInsertPileBasicInfo(dto.getPileBasicInfoList()); + } + if (CollectionUtils.isNotEmpty(dto.getPileConnectorInfoList())) { + pileConnectorInfoMapper.batchInsertConnectorInfo(dto.getPileConnectorInfoList()); + } + return result; + } + + /** + * 鏂板璁¤垂妯℃澘鍜岃鎯 + */ + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public void doCreateBillingTemplate(BillingTemplateTransactionDTO dto) { + log.info("鏂板璁¤垂妯℃澘鍜岃鎯 param:{}", dto.toString()); + if (dto.getBillingTemplate() == null || CollectionUtils.isEmpty(dto.getDetailList())) { + return; + } + // 淇濆瓨璁¤垂妯℃澘鍩烘湰淇℃伅 + pileBillingTemplateMapper.insertPileBillingTemplate(dto.getBillingTemplate()); + // log.info("鑷id锛歿}", dto.getBillingTemplate().getId()); + // 淇濆瓨璁¤垂妯℃澘璇︽儏 + pileBillingTemplateMapper.batchPileBillingDetail(dto.getDetailList()); + } + + /** + * 鏇存柊璁¤垂妯℃澘 + * @param dto + */ + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public void doUpdateBillingTemplate(BillingTemplateTransactionDTO dto) { + if (dto.getBillingTemplate() == null || CollectionUtils.isEmpty(dto.getDetailList())) { + return; + } + // 淇濆瓨璁¤垂妯℃澘鍩烘湰淇℃伅 + pileBillingTemplateMapper.updatePileBillingTemplate(dto.getBillingTemplate()); + // 璁¤垂妯℃澘 鍏堝垹鍚庢彃 + pileBillingTemplateMapper.deletePileBillingDetailByTemplateCode(dto.getBillingTemplate().getTemplateCode()); + // 淇濆瓨璁¤垂妯℃澘璇︽儏 + pileBillingTemplateMapper.batchPileBillingDetail(dto.getDetailList()); + } + + /** + * 鎻掑叆璁㈠崟 + */ + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public void doCreateOrder(OrderTransactionDTO dto) { + if (Objects.nonNull(dto.getOrderBasicInfo())) { + orderBasicInfoMapper.insertOrderBasicInfo(dto.getOrderBasicInfo()); + } + + if (Objects.nonNull(dto.getOrderDetail())) { + orderBasicInfoMapper.batchOrderDetail(Lists.newArrayList(dto.getOrderDetail())); + } + } + + /** + * 鏇存柊璁㈠崟淇℃伅 + * @param dto + */ + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public void doUpdateOrder(OrderTransactionDTO dto) { + String orderCode = null; + if (Objects.nonNull(dto.getOrderBasicInfo())) { + orderCode = dto.getOrderBasicInfo().getOrderCode(); + orderBasicInfoMapper.updateOrderBasicInfo(dto.getOrderBasicInfo()); + } + + if (Objects.nonNull(dto.getOrderDetail())) { + orderCode = dto.getOrderDetail().getOrderCode(); + orderBasicInfoMapper.updateOrderDetail(dto.getOrderDetail()); + } + // 娓呯紦瀛 + if (StringUtils.isNotBlank(orderCode)) { + String redisKey = CacheConstants.GET_ORDER_INFO_BY_ORDER_CODE + orderCode; + redisCache.deleteObject(redisKey); + } + } + + /** + * 鏂板缓浼氬憳 + * @param dto + */ + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public void createMember(MemberTransactionDTO dto) { + if (Objects.nonNull(dto.getMemberBasicInfo())) { + memberBasicInfoMapper.insertMemberBasicInfo(dto.getMemberBasicInfo()); + } + if (Objects.nonNull(dto.getMemberWalletInfo())) { + memberWalletInfoMapper.insertSelective(dto.getMemberWalletInfo()); + } + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/ConnectorInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/ConnectorInfoVO.java new file mode 100644 index 000000000..52ddbdf8e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/ConnectorInfoVO.java @@ -0,0 +1,44 @@ +package com.jsowell.pile.vo.base; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 鏋彛淇℃伅璇︽儏 + * + * @author JS-ZZA + * @date 2022/11/2 16:18 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ConnectorInfoVO { + /** + * 鏋彛鍙 + */ + private String connectorCode; + + /** + * 鏋彛缂栧彿 + */ + private String pileConnectorCode; + + /** + * 鏋彛鐘舵 + */ + private String connectorStatus; + + /** + * 鍏呯數绫诲瀷锛1-蹇厖锛2-鎱㈠厖锛 + */ + private String chargingType; + + /** + * 棰濆畾鍔熺巼 + */ + private String ratedPower; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/MerchantInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/MerchantInfoVO.java new file mode 100644 index 000000000..a3498279d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/MerchantInfoVO.java @@ -0,0 +1,33 @@ +package com.jsowell.pile.vo.base; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MerchantInfoVO { + /** + * 鍟嗘埛id + */ + private String merchantId; + + /** + * 鍟嗘埛鍚嶇О + */ + private String merchantName; + + /** + * 鍟嗘埛鐢佃瘽 + */ + private String merchantTel; + + /** + * 閮ㄩ棬id + */ + private String deptId; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/PileInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/PileInfoVO.java new file mode 100644 index 000000000..d8cb381d8 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/PileInfoVO.java @@ -0,0 +1,52 @@ +package com.jsowell.pile.vo.base; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileInfoVO { + /** + * 鍏呯數妗﹊d + */ + private String pileId; + + /** + * 鍏呯數妗╃紪鍙 + */ + private String pileSn; + + /** + * 鎵灞炶繍钀ュ晢id + */ + private String merchantId; + + /** + * 鎵灞炶繍钀ュ晢鍚嶇О + */ + private String merchantName; + + /** + * 鎵灞炵珯鐐筰d + */ + private String stationId; + + /** + * 棰濆畾鐢靛帇 + */ + private String ratedVoltage; + + /** + * 棰濆畾鐢垫祦 + */ + private String ratedCurrent; + + /** + * 棰濆畾鍔熺巼 + */ + private String ratedPower; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/StationInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/StationInfoVO.java new file mode 100644 index 000000000..b229e0727 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/base/StationInfoVO.java @@ -0,0 +1,87 @@ +package com.jsowell.pile.vo.base; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 杩斿洖缁欏墠绔殑绔欑偣淇℃伅vo + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class StationInfoVO { + /** + * 绔欑偣id + */ + private String stationId; + + /** + * 绔欑偣鍚嶇О + */ + private String stationName; + + /** + * 绔欑偣鍦板潃 + */ + private String stationAddress; + + /** + * 绔欑偣鍥剧墖 + */ + private List stationImgList; + + /** + * 璺濈 鍗曚綅鍗冪背 + */ + private String distance; + + /** + * 鐢佃垂 姣忓害鍗曚环 + */ + private String electricityPrice; + + /** + * 鏈嶅姟璐 姣忓害鍗曚环 + */ + private String servicePrice; + + /** + * 鐢佃垂 + 鏈嶅姟璐 姣忓害鍗曚环 + */ + private String totalPrice; + + /** + * 蹇厖鏋彛鎬绘暟 + */ + private int fastTotal; + + /** + * 蹇厖鏋彛绌洪棽鏁 + */ + private int fastFree; + + /** + * 鎱㈠厖鏋彛鎬绘暟 + */ + private int slowTotal; + + /** + * 鎱㈠厖鏋彛绌洪棽鏁 + */ + private int slowFree; + + /** + * 缁忓害 + */ + private String stationLng; + + /** + * 绾害 + */ + private String stationLat; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/BillingPriceVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/BillingPriceVO.java new file mode 100644 index 000000000..bd1e818c2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/BillingPriceVO.java @@ -0,0 +1,50 @@ +package com.jsowell.pile.vo.uniapp; + +import com.jsowell.common.enums.ykc.BillingTimeEnum; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BillingPriceVO { + /** + * 鏄惁褰撳墠鏃堕棿 + * 1-鏄 0-鍚 + */ + private String isCurrentTime; + + /** + * 寮濮嬫椂闂 + */ + private String startTime; + + /** + * 缁撴潫鏃堕棿 + */ + private String endTime; + + /** + * 鐢佃垂 + */ + private String electricityPrice; + + /** + * 鏈嶅姟璐 + */ + private String servicePrice; + + /** + * 鎬昏垂鐢 + */ + private String totalPrice; + + /** + * 鏃舵绫诲瀷锛1-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂锛 + * @see BillingTimeEnum + */ + private String timeType; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/CurrentTimePriceDetails.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/CurrentTimePriceDetails.java new file mode 100644 index 000000000..c15c2ed96 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/CurrentTimePriceDetails.java @@ -0,0 +1,42 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CurrentTimePriceDetails { + /** + * 褰撳墠鏃堕棿 + */ + private String dateTime; + + /** + * 绔欑偣id + */ + private String stationId; + + /** + * 璁¤垂妯℃澘缂栧彿 + */ + private String templateCode; + + /** + * 鐢佃垂 姣忓害鍗曚环 + */ + private String electricityPrice; + + /** + * 鏈嶅姟璐 姣忓害鍗曚环 + */ + private String servicePrice; + + /** + * 鐢佃垂 + 鏈嶅姟璐 姣忓害鍗曚环 + */ + private String totalPrice; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/MemberVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/MemberVO.java new file mode 100644 index 000000000..3f447ced9 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/MemberVO.java @@ -0,0 +1,56 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 鐢ㄦ埛淇℃伅VO + * + * @author JS-ZZA + * @date 2022/11/19 13:31 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class MemberVO { + /** + * 浼氬憳Id + */ + private String memberId; + + /** + * 鐘舵 + */ + private String status; + + /** + * 鏄电О + */ + private String nickName; + + /** + * 鎵嬫満鍙风爜 + */ + private String mobileNumber; + + /** + * 鏈噾閲戦 + */ + private BigDecimal principalBalance; + + /** + * 璧犻侀噾棰 + */ + private BigDecimal giftBalance; + + /** + * 鎬昏处鎴蜂綑棰 + */ + private BigDecimal totalAccountAmount; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/MemberWalletLogVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/MemberWalletLogVO.java new file mode 100644 index 000000000..0c6c60709 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/MemberWalletLogVO.java @@ -0,0 +1,47 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 浼氬憳閽卞寘浣欓鏄庣粏鐩稿叧 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MemberWalletLogVO { + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 浜ゆ槗绫诲瀷 1-杩涜处锛2-鍑鸿处 + */ + private String type; + + /** + * 瀛愮被鍨 10-鍏呭, 11-璧犻, 12-璁㈠崟缁撶畻閫娆撅紝20-鍚庣鎵f, 21-璁㈠崟浠樻, 22-鐢ㄦ埛閫娆 + */ + private String subType; + + /** + * 鍑鸿处/鍏ヨ处閲戦 + */ + private BigDecimal amount; + + /** + * 浜ゆ槗鏃堕棿 + */ + private String transactionTime; + + /** + * 浣欓绫诲瀷锛1-鏈噾锛2-璧犻侊級 + */ + private String category; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/OrderVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/OrderVO.java new file mode 100644 index 000000000..b9fc40895 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/OrderVO.java @@ -0,0 +1,84 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 璁㈠崟淇℃伅VO + * + * @author JS-ZZA + * @date 2022/11/24 14:08 + */ +@Data +public class OrderVO { + /** + * 璁㈠崟鍙 + */ + private String orderCode; + + /** + * 妗╃紪鍙 + */ + private String pileSn; + + /** + * 鏋彛鍙 + */ + private String connectorCode; + + /** + * 鏋彛缂栫爜 + */ + private String pileConnectorCode; + + /** + * 绔欑偣鍚嶇О + */ + private String stationName; + + /** + * 鍏呯數搴︽暟 + */ + private String chargingDegree; + + /** + * 璁㈠崟閲戦 + */ + private BigDecimal orderAmount; + + /** + * 璁㈠崟鐘舵 + */ + private String orderStatus; + + /** + * 璁㈠崟寮傚父鍘熷洜 + */ + private String reason; + + /** + * 鏀粯鐘舵 + */ + private String payStatus; + + /** + * 鐢ㄦ埛鏀粯閲戦 + */ + private BigDecimal payAmount; + + /** + * 鍏呯數寮濮嬫椂闂 + */ + private String startTime; + + /** + * 鍏呯數缁撴潫鏃堕棿 + */ + private String endTime; + + /** + * 鍏呯數鏃堕暱 + */ + private String chargingTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonPileConnectorSumInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonPileConnectorSumInfoVO.java new file mode 100644 index 000000000..9d3883138 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonPileConnectorSumInfoVO.java @@ -0,0 +1,38 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.Data; + +/** + * 涓汉妗╂灙鍙g疮璁℃暟鎹 + * + * @author JS-ZZA + * @date 2023/2/25 8:42 + */ +@Data +public class PersonPileConnectorSumInfoVO { + private String memberId; + + private String startTime; + + private String endTime; + + /** + * 鍏呯數寮濮嬫椂闂 + */ + private String chargeStartTime; + + /** + * 鍏呯數缁撴潫鏃堕棿 + */ + private String chargeEndTime; + + /** + * 绱鍏呯數閲 + */ + private String sumChargingDegree; + + /** + * 绱鍏呯數鏃堕暱 + */ + private String sumChargingTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonPileRealTimeVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonPileRealTimeVO.java new file mode 100644 index 000000000..88c43f441 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonPileRealTimeVO.java @@ -0,0 +1,48 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 涓汉妗╂煡璇㈡灙鍙e疄鏃舵暟鎹 + * + * @author JS-ZZA + * @date 2023/2/23 16:21 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PersonPileRealTimeVO { + /** + * 鍚姩鏃堕棿 + */ + private String startTime; + + /** + * 宸插厖搴︽暟 + */ + private String chargingDegree; + + /** + * 鍏呯數鏃堕暱 + */ + private String chargingTime; + + /** + * 瀹炴椂鐢垫祦 + */ + private String instantCurrent; + + /** + * 瀹炴椂鐢靛帇 + */ + private String instantVoltage; + + /** + * 瀹炴椂鍔熺巼 + */ + private String instantPower; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonalPileInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonalPileInfoVO.java new file mode 100644 index 000000000..806ffd747 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PersonalPileInfoVO.java @@ -0,0 +1,62 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.Data; + +/** + * 涓汉妗╀俊鎭疺O + * + * @author JS-ZZA + * @date 2023/2/21 16:53 + */ +@Data +public class PersonalPileInfoVO { + /** + * 妗╃紪鐮 + */ + private String pileSn; + + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 韬唤绫诲瀷锛1-绠$悊鍛橈紱2-鏅氱敤鎴凤級 + */ + private String type; + + /** + * 妗╃姸鎬 + */ + private String pileStatus; + + /** + * 鍨嬪彿 + */ + private String modelName; + + /** + * 棰濆畾鍔熺巼 + */ + private String ratedPower; + + /** + * 棰濆畾鐢垫祦 + */ + private String ratedCurrent; + + /** + * 棰濆畾鐢靛帇 + */ + private String ratedVoltage; + + /** + * 鍏呯數绫诲瀷锛1-蹇厖锛2-鎱㈠厖锛 + */ + private String speedType; + + /** + * 鏋彛鏁伴噺 + */ + private String connectorNum; +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileConnectorDetailVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileConnectorDetailVO.java new file mode 100644 index 000000000..9511f68b1 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileConnectorDetailVO.java @@ -0,0 +1,54 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.Data; + +/** + * 鍏呯數鏋鎯匳O + * 鍖呭惈鍏呯數妗╁拰鏋彛鐨勪竴浜涗俊鎭 + * 鍙互浣滀负鍏叡瀵硅薄 + */ +@Data +public class PileConnectorDetailVO { + /** + * 鍏呯數妗﹊d + */ + private String pileId; + + /** + * 鍏呯數妗╃紪鍙 + */ + private String pileSn; + + /** + * 绔欑偣id + */ + private String stationId; + + /** + * 鏋彛id + */ + private String connectorId; + + /** + * 鍏呯數鏋紪鍙 + */ + private String pileConnectorCode; + + /** + * 鏋彛鐘舵 + * 鐘舵 0锛氱缃 (榛樿)锛1锛氱┖闂诧紱2锛氬崰鐢紙鏈厖鐢碉級锛3锛氬崰鐢紙鍏呯數涓級锛4锛氬崰鐢紙棰勭害閿佸畾锛 锛255锛氭晠闅 + */ + private String connectorStatus; + + /** + * 缁忚惀绫诲瀷锛1-杩愯惀妗╋紱2-涓汉妗╋級 + */ + private String businessType; + + /** + * 杞欢鍗忚锛1-浜戝揩鍏咃紱2-姘歌仈锛 + */ + private String softwareProtocol; + + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileConnectorVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileConnectorVO.java new file mode 100644 index 000000000..422fb151a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileConnectorVO.java @@ -0,0 +1,39 @@ +package com.jsowell.pile.vo.uniapp; + +import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.base.MerchantInfoVO; +import com.jsowell.pile.vo.base.PileInfoVO; +import com.jsowell.pile.vo.web.PileStationVO; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileConnectorVO { + + // 鍏呯數鏋俊鎭垪琛 + private List connectorInfoList; + + // 璁¤垂妯℃澘淇℃伅 + // private BillingTemplateVO billingTemplate; + + // 鍏呯數妗╀俊鎭 + private PileInfoVO pileInfo; + + // 杩愯惀鍟嗕俊鎭 + private MerchantInfoVO merchantInfo; + + // 绔欑偣淇℃伅 + private PileStationVO stationInfo; + + /** + * 浠锋牸鍒楄〃 + */ + private List billingPriceList; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileDetailVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileDetailVO.java new file mode 100644 index 000000000..438d010ff --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/PileDetailVO.java @@ -0,0 +1,41 @@ +package com.jsowell.pile.vo.uniapp; + +import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileDetailVO { + /** + * 绔欑偣id + */ + private String stationId; + + /** + * 绔欑偣鍚嶇О + */ + private String stationName; + + /** + * 绔欑偣鐢佃瘽 + */ + private String stationTel; + + /** + * 鏋彛鍒楄〃 + */ + private List connectorList; + + /** + * 璁¤垂妯℃澘淇℃伅 + */ + private BillingTemplateVO billingTemplate; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/SendMessageVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/SendMessageVO.java new file mode 100644 index 000000000..9a7a8a6a0 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/SendMessageVO.java @@ -0,0 +1,55 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * uniapp鍙戦佹秷鎭疺O + * + * @author JS-ZZA + * @date 2023/2/15 10:37 + */ +@Data +public class SendMessageVO { + /** + * 璁㈠崟鍙 + */ + public String orderCode; + + /** + * 绔欑偣鍚嶇О + */ + public String stationName; + + /** + * 鍏呯數寮濮嬫椂闂 + */ + public String chargeStartTime; + + /** + * 绔欑偣Id + */ + public String stationId; + + /** + * 璁㈠崟閲戦 + */ + public String orderAmount; + + /** + * 鐢ㄦ埛openId + */ + public String openId; + + /** + * 鍏呯數缁撴潫鏃堕棿 + */ + public String chargeStopTime; + + /** + * 鍏呯數鍋滄鍘熷洜 + */ + public String stopReason; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/UniAppOrderVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/UniAppOrderVO.java new file mode 100644 index 000000000..705683c85 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/uniapp/UniAppOrderVO.java @@ -0,0 +1,128 @@ +package com.jsowell.pile.vo.uniapp; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UniAppOrderVO { + /** + * 璁㈠崟缂栧彿 + */ + private String orderCode; + + /** + * 妗╃紪鍙 + */ + private String pileSn; + + /** + * 鏋彛鍙 + */ + private String connectorCode; + + /** + * 鏋彛缂栫爜 + */ + private String pileConnectorCode; + + /** + * 璁㈠崟鐘舵 + */ + private String orderStatus; + + /** + * 璁㈠崟鐘舵佹弿杩 + */ + private String orderStatusDescribe; + + /** + * 褰撳墠SOC + */ + private String SOC; + + /** + * 鏋彛鐘舵 + */ + private String pileConnectorStatus; + + /** + * 鍏呯數閲戦 + */ + private String chargingAmount; + + /** + * 鍏呯數鐢甸噺 + */ + private String chargingDegree; + + /** + * 鍏呯數鏃堕暱 + */ + private String sumChargingTime; + + /** + * 鍓╀綑鏃堕暱 + */ + private String timeRemaining; + + /** + * 瀹炴椂鐢垫祦 + */ + private String outputCurrent; + + /** + * 瀹炴椂鐢靛帇 + */ + private String outputVoltage; + + /** + * 瀹炴椂鍏呯數鍔熺巼 + */ + private String outputPower; + + /** + * 瀹炴椂娓╁害 + */ + private String batteryMaxTemperature; + + /** + * 鍏呯數瀹炴椂鏁版嵁鍒楄〃 + */ + private List chargingDataList; + + @Data + public static class ChargingData { + private String dateTime; + /** + * 杈撳嚭鐢靛帇 + */ + private String outputVoltage; + + /** + * 杈撳嚭鐢垫祦 + */ + private String outputCurrent; + + /** + * 鍔熺巼 + */ + private String power; + + /** + * SOC 寰呮満缃浂锛涗氦娴佹々缃浂 + */ + private String SOC; + + /** + * 鐢垫睜缁勬渶楂樻俯搴 + */ + private String batteryMaxTemperature; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/BillingDetailVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/BillingDetailVO.java new file mode 100644 index 000000000..bf8962b71 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/BillingDetailVO.java @@ -0,0 +1,27 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BillingDetailVO { + // 鏃舵绫诲瀷锛1-灏栨椂锛2-宄版椂锛3-骞虫椂锛4-璋锋椂锛 + private String timeType; + + // 鐢佃垂(姣忓害鍗曚环) + private BigDecimal electricityPrice; + + // 鏈嶅姟璐(姣忓害鍗曚环) + private BigDecimal servicePrice; + + // 閫傜敤鏃堕棿娈 + private List applyTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/BillingTemplateVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/BillingTemplateVO.java new file mode 100644 index 000000000..3d15d66ba --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/BillingTemplateVO.java @@ -0,0 +1,150 @@ +package com.jsowell.pile.vo.web; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.jsowell.common.util.StringUtils; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BillingTemplateVO { + // 璁¤垂妯℃澘id + private String templateId; + + // 璁¤垂妯℃澘缂栧彿 + private String templateCode; + + // 璁¤垂妯℃澘鍚嶇О + private String templateName; + + // 璁¤垂妯℃澘澶囨敞 + private String remark; + + // 鍙戝竷鏃堕棿 + private String publishTime; + + // 璁惧绫诲瀷 1-鐢靛姩姹借溅妗╋紱2-鐢靛姩鑷杞︽々 + private String deviceType; + + // 灏栨椂娈电數璐 + private BigDecimal sharpElectricityPrice; + // 灏栨椂娈垫湇鍔¤垂 + private BigDecimal sharpServicePrice; + // 灏栨椂娈垫椂闂 閫楀彿鍒嗗壊鐨勬椂娈垫 + private String sharpApplyDate; + + // 宄版椂娈电數璐 + private BigDecimal peakElectricityPrice; + // 宄版椂娈电數璐 + private BigDecimal peakServicePrice; + // 宄版椂娈垫椂闂 閫楀彿鍒嗗壊鐨勬椂娈垫 + private String peakApplyDate; + + // 骞虫椂娈电數璐 + private BigDecimal flatElectricityPrice; + // 骞虫椂娈垫湇鍔¤垂 + private BigDecimal flatServicePrice; + // 骞虫椂娈垫椂闂 閫楀彿鍒嗗壊鐨勬椂娈垫 + private String flatApplyDate; + + // 璋锋椂娈电數璐 + private BigDecimal valleyElectricityPrice; + // 璋锋椂娈垫湇鍔¤垂 + private BigDecimal valleyServicePrice; + // 骞虫椂娈垫椂闂 閫楀彿鍒嗗壊鐨勬椂娈垫 + private String valleyApplyDate; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("templateId", templateId) + .append("templateCode", templateCode) + .append("templateName", templateName) + .append("publishTime", publishTime) + .append("remark", remark) + .append("deviceType", deviceType) + .append("sharpElectricityPrice", sharpElectricityPrice) + .append("sharpServicePrice", sharpServicePrice) + .append("sharpApplyDate", sharpApplyDate) + .append("peakElectricityPrice", peakElectricityPrice) + .append("peakServicePrice", peakServicePrice) + .append("peakApplyDate", peakApplyDate) + .append("flatElectricityPrice", flatElectricityPrice) + .append("flatServicePrice", flatServicePrice) + .append("flatApplyDate", flatApplyDate) + .append("valleyElectricityPrice", valleyElectricityPrice) + .append("valleyServicePrice", valleyServicePrice) + .append("valleyApplyDate", valleyApplyDate) + .toString(); + } + + public Map> getTimeMap() { + Map> resultMap = Maps.newHashMap(); + if (StringUtils.isNotBlank(this.getSharpApplyDate())) { + resultMap.put(0x00, Lists.newArrayList(this.getSharpApplyDate().split(","))); + } + if (StringUtils.isNotBlank(this.getPeakApplyDate())) { + resultMap.put(0x01, Lists.newArrayList(this.getPeakApplyDate().split(","))); + } + if (StringUtils.isNotBlank(this.getFlatApplyDate())) { + resultMap.put(0x02, Lists.newArrayList(this.getFlatApplyDate().split(","))); + } + if (StringUtils.isNotBlank(this.getValleyApplyDate())) { + resultMap.put(0x03, Lists.newArrayList(this.getValleyApplyDate().split(","))); + } + return resultMap; + } + + public List getBillingDetailList() { + List resultList = Lists.newArrayList(); + if (StringUtils.isNotBlank(this.getSharpApplyDate())) { + List list = Lists.newArrayList(this.getSharpApplyDate().split(",")); + resultList.add(BillingDetailVO.builder() + .timeType("1") + .applyTime(list) + .electricityPrice(this.sharpElectricityPrice) + .servicePrice(this.sharpServicePrice) + .build()); + } + if (StringUtils.isNotBlank(this.getPeakApplyDate())) { + List list = Lists.newArrayList(this.getPeakApplyDate().split(",")); + resultList.add(BillingDetailVO.builder() + .timeType("2") + .applyTime(list) + .electricityPrice(this.peakElectricityPrice) + .servicePrice(this.peakServicePrice) + .build()); + } + if (StringUtils.isNotBlank(this.getFlatApplyDate())) { + List list = Lists.newArrayList(this.getFlatApplyDate().split(",")); + resultList.add(BillingDetailVO.builder() + .timeType("3") + .applyTime(list) + .electricityPrice(this.flatElectricityPrice) + .servicePrice(this.flatServicePrice) + .build()); + } + if (StringUtils.isNotBlank(this.getValleyApplyDate())) { + List list = Lists.newArrayList(this.getValleyApplyDate().split(",")); + resultList.add(BillingDetailVO.builder() + .timeType("4") + .applyTime(list) + .electricityPrice(this.valleyElectricityPrice) + .servicePrice(this.valleyServicePrice) + .build()); + } + return resultList; + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/EchoBillingTemplateVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/EchoBillingTemplateVO.java new file mode 100644 index 000000000..a28e8342e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/EchoBillingTemplateVO.java @@ -0,0 +1,10 @@ +package com.jsowell.pile.vo.web; + +import com.jsowell.pile.dto.CreateOrUpdateBillingTemplateDTO; + +/** + * 鐢ㄤ簬璁¤垂妯℃澘淇敼椤甸潰鍥炴樉鐨剉o + * 鍜屽垱寤鸿璐规ā鏉跨殑缁撴瀯涓鏍 + */ +public class EchoBillingTemplateVO extends CreateOrUpdateBillingTemplateDTO { +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/IndexGeneralSituationVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/IndexGeneralSituationVO.java new file mode 100644 index 000000000..0412a5b5e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/IndexGeneralSituationVO.java @@ -0,0 +1,37 @@ +package com.jsowell.pile.vo.web; + +import lombok.Data; + +/** + * 棣栭〉鍩虹淇℃伅鏁版嵁灞曠ずVO + * + * @author JS-ZZA + * @date 2023/2/3 10:36 + */ +@Data +public class IndexGeneralSituationVO { + /** + * 鎬诲厖鐢电數閲 + */ + private String totalChargingDegree; + + /** + * 鎬诲厖鐢佃垂鐢 + */ + private String totalChargingAmount; + + /** + * 鎬诲厖鐢电瑪鏁 + */ + private String totalChargingQuantity; + + /** + * 鎬昏澶囨暟閲 + */ + private String totalPileQuantity; + + /** + * 鎬诲鎴蜂綑棰 + */ + private String totalMemberAmount; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/IndexOrderInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/IndexOrderInfoVO.java new file mode 100644 index 000000000..3b211ab7a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/IndexOrderInfoVO.java @@ -0,0 +1,48 @@ +package com.jsowell.pile.vo.web; + +import lombok.Data; + +/** + * 鍚庣棣栭〉璁㈠崟淇℃伅VO + * + * @author JS-ZZA + * @date 2023/2/4 9:09 + */ +@Data +public class IndexOrderInfoVO { + /** + * 鏃ユ湡 + */ + private String date; + + /** + * 鎬荤敤鐢甸噺 + */ + private String totalElectricity; + + /** + * 鎬昏鍗曢噾棰 + */ + private String totalOrderAmount; + + /** + * 灏栨椂娈垫荤敤鐢甸噺 + */ + private String totalSharpUsedElectricity; + + /** + * 宄版椂娈垫荤敤鐢甸噺 + */ + private String totalPeakUsedElectricity; + + /** + * 骞虫椂娈垫荤敤鐢甸噺 + */ + private String totalFlatUsedElectricity; + + /** + * 璋锋椂娈垫荤敤鐢甸噺 + */ + private String totalValleyUsedElectricity; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/MemberTransactionVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/MemberTransactionVO.java new file mode 100644 index 000000000..da939fc67 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/MemberTransactionVO.java @@ -0,0 +1,70 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MemberTransactionVO { + /** + * 鍏呯數璁㈠崟鍙 + */ + private String orderCode; + + /** + * 鍦烘櫙绫诲瀷锛坥rder, balance锛 + */ + private String scenarioType; + + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 鎿嶄綔绫诲瀷锛坒orward-姝e悜, reverse-閫嗗悜锛 + */ + private String actionType; + + /** + * 鏀粯绫诲瀷(wx, balance) + */ + private String payMode; + + /** + * 閲戦 + */ + private BigDecimal amount; + + /** + * 澶栭儴鍟嗘埛璁㈠崟鍙 + */ + private String outTradeNo; + + /** + * 澶栭儴鏀粯璁㈠崟鍙 + */ + private String transactionId; + + /** + * 澶栭儴閫娆惧崟鍙 + */ + private String outRefundNo; + + /** + * 澶栭儴鏀粯閫娆惧崟鍙 + */ + private String refundId; + + /** + * 鍒涘缓鏃堕棿 + */ + private LocalDateTime createTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderDetailInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderDetailInfoVO.java new file mode 100644 index 000000000..ecb07ba9c --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderDetailInfoVO.java @@ -0,0 +1,73 @@ +package com.jsowell.pile.vo.web; + +import com.jsowell.pile.vo.base.PileInfoVO; +import com.jsowell.pile.vo.uniapp.MemberVO; +import lombok.Data; + +import java.util.List; + +/** + * 璁㈠崟璇︽儏淇℃伅VO + */ +@Data +public class OrderDetailInfoVO { + // 璁㈠崟淇℃伅 + private OrderInfo orderInfo; + + // 鐢ㄦ埛淇℃伅 + private MemberVO memberInfo; + + // 璁惧淇℃伅 + private PileInfoVO pileInfo; + + // 鏀粯淇℃伅 + private List payRecordList; + + // 鏋彛淇℃伅 + private List realTimeMonitorDataList; + + // 璁㈠崟鐩稿叧瀹炴椂鏁版嵁 + private OrderRealTimeInfo orderRealTimeInfo; + + @Data + public static class OrderInfo { + private String orderCode; // 璁㈠崟缂栧彿 + private String orderStatus; // 璁㈠崟鐘舵 + private String startTime; // 鍏呯數寮濮嬫椂闂 + private String endTime; // 鍏呯數缁撴潫鏃堕棿 + private String stopReasonMsg; // 鍋滄鍘熷洜 + private String createTime; // 璁㈠崟鍒涘缓鏃堕棿 + private String startSOC; // 寮濮婼OC + private String endSOC; // 缁撴潫SOC + } + + @Data + public static class PayRecord { + private String payAmount; // 鏀粯閲戦 + private String payStatus; // 鏀粯鐘舵 + private String payMode; // 鏀粯鏂瑰紡(1-浣欓鏀粯锛2-寰俊鏀粯锛3-鏀粯瀹濇敮浠) + private String payModeDesc; // 鏀粯鏂瑰紡鎻忚堪 + private String payTime; // 鏀粯鏃堕棿 + private String outTradeNo; // 寰俊鍟嗘埛璁㈠崟鍙 real_time_monitor_data + private String transactionId; // 寰俊鏀粯璁㈠崟鍙 + } + + @Data + public static class RealTimeMonitorData{ + private String instantCurrent; // 瀹炴椂鐢垫祦 + private String instantVoltage; // 瀹炴椂鐢靛帇 + private String instantPower; // 瀹炴椂鍔熺巼 + private String SOC; + private String time; + } + + @Data + public static class OrderRealTimeInfo{ + private String orderAmount; // 璁㈠崟閲戦 + private String totalElectricityAmount; // 鎬荤數璐 + private String totalServiceAmount; // 鎬绘湇鍔¤垂 + private String chargedDegree; // 宸插厖搴︽暟 + private String SOC; // soc + private String chargingTime; // 鍏呯數鏃堕暱锛堝垎閽燂級 + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderListVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderListVO.java new file mode 100644 index 000000000..d9789d013 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderListVO.java @@ -0,0 +1,159 @@ +package com.jsowell.pile.vo.web; + +import com.jsowell.common.annotation.Excel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 鍚庣璁㈠崟鍒楄〃椤甸潰 + * + * @author JS-ZZA + * @date 2022/12/1 9:59 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class OrderListVO { + private String id; + + /** + * 璁㈠崟鍙 + */ + @Excel(name = "璁㈠崟鍙") + private String orderCode; + + /** + * 璁㈠崟鐘舵 + */ + // @Excel(name = "璁㈠崟鐘舵") + private String orderStatus; + + /** + * 璁㈠崟鐘舵佹弿杩 + */ + @Excel(name = "璁㈠崟鐘舵佹弿杩") + private String orderStatusDescribe; + + /** + * 浼氬憳id + */ + @Excel(name = "浼氬憳id") + private String memberId; + + /** + * 鏄电О + */ + @Excel(name = "鏄电О") + private String nickName; + + /** + * 鎵嬫満鍙风爜 + */ + @Excel(name = "鎵嬫満鍙风爜") + private String mobileNumber; + + /** + * 绔欑偣id + */ + // @Excel(name = "绔欑偣id") + private String stationId; + + /** + * 绔欑偣鍚嶇О + */ + @Excel(name = "绔欑偣鍚嶇О") + private String stationName; + + /** + * 妗╃紪鐮 + */ + @Excel(name = "鍏呯數妗╂々缂栫爜") + private String pileSn; + + /** + * 鏋彛鍙 + */ + @Excel(name = "鏋彛鍙") + private String connectorCode; + + /** + * 妗╂灙鍙g紪鍙 + */ + @Excel(name = "鍏呯數妗╂灙鍙g紪鍙") + private String pileConnectorCode; + + /** + * 鍚姩鏂瑰紡锛0-鍚庣鍚姩锛1-鐢ㄦ埛app鍚姩锛 + */ + @Excel(name = "鍚姩鏂瑰紡", dictType = "start_mode") + private String startMode; + + /** + * 鏀粯鏂瑰紡(1-浣欓鏀粯锛3-鐧藉悕鍗曟敮浠橈紱4-寰俊鏀粯锛5-鏀粯瀹濇敮浠) + */ + @Excel(name = "鏀粯鏂瑰紡", dictType = "pay_mode") + private String payMode; + + /** + * 鏀粯鐘舵 + */ + @Excel(name = "鏀粯鐘舵", dictType = "pay_status") + private String payStatus; + + /** + * 璧峰soc + */ + @Excel(name = "璧峰soc", suffix = "%") + private String startSoc; + + /** + * 缁堟soc + */ + @Excel(name = "缁堟soc", suffix = "%") + private String endSoc; + + /** + * 寮濮嬪厖鐢垫椂闂 + */ + @Excel(name = "寮濮嬪厖鐢垫椂闂") + private String chargeStartTime; + + /** + * 缁撴潫鍏呯數鏃堕棿 + */ + @Excel(name = "缁撴潫鍏呯數鏃堕棿") + private String chargeEndTime; + + /** + * 鏀粯閲戦 + */ + @Excel(name = "鏀粯閲戦") + private String payAmount; + + /** + * 璁㈠崟閲戦 + */ + @Excel(name = "璁㈠崟閲戦") + private String orderAmount; + + /** + * 鍒涘缓鏃ユ湡 + */ + @Excel(name = "鍒涘缓鏃ユ湡") + private String createTime; + + /** + * 鍏呯數搴︽暟 + */ + @Excel(name = "鍏呯數搴︽暟") + private String chargingDegree; + + /** + * 寰俊鍟嗘埛鍗曞彿 + */ + @Excel(name = "寰俊鍟嗘埛鍗曞彿") + private String outTradeNo; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderRealTimeInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderRealTimeInfoVO.java new file mode 100644 index 000000000..4f9389575 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderRealTimeInfoVO.java @@ -0,0 +1,37 @@ +package com.jsowell.pile.vo.web; + +import lombok.Data; + +/** + * 璁㈠崟瀹炴椂鏁版嵁锛堝悗绠¤鍗曡鎯呴〉浣跨敤锛 + * + * @author JS-ZZA + * @date 2023/2/18 11:43 + */ +@Data +public class OrderRealTimeInfoVO { + /** + * 璁㈠崟閲戦 + */ + private String orderAmount; + + /** + * 鎬荤數璐 + */ + private String totalElectricityAmount; + + /** + * 鎬绘湇鍔¤垂 + */ + private String totalServiceAmount; + + /** + * 宸插厖搴︽暟 + */ + private String chargedDegree; + + /** + * soc + */ + private String SOC; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderTotalDataVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderTotalDataVO.java new file mode 100644 index 000000000..dbc38956c --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/OrderTotalDataVO.java @@ -0,0 +1,23 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class OrderTotalDataVO { + // 寮濮嬫椂闂 + private String dateDescription; + + // 鎬绘秷璐归噾棰 + private BigDecimal sumOrderAmount; + + // 鎬荤敤鐢甸噺 + private BigDecimal sumUsedElectricity; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileCommunicationLogVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileCommunicationLogVO.java new file mode 100644 index 000000000..86b54ef0d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileCommunicationLogVO.java @@ -0,0 +1,39 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 妗╅氳鏃ュ織 + * + * @author JS-ZZA + * @date 2023/1/12 14:57 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PileCommunicationLogVO { + /** + * 妗╁彿 + */ + private String pileSn; + + /** + * 鏃堕棿 + */ + private String createTime; + + /** + * 甯х被鍨 + */ + private String frameType; + + /** + * 鎻忚堪 + */ + private String description; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileConnectorInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileConnectorInfoVO.java new file mode 100644 index 000000000..3f5fa89cb --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileConnectorInfoVO.java @@ -0,0 +1,159 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 鏌ヨ鍏呯數鏋繑鍥炲墠鍙板弬鏁 + * + * @author JS-ZZA + * @date 2022/8/31 16:40 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileConnectorInfoVO { + /** + * 鍏呯數鏋彛id + */ + private String connectorId; + + /** + * 鏋彛缂栧彿锛岀敱鍏呯數妗㏒N+01鐢熸垚 + */ + private String pileConnectorCode; + + /** + * 缁忚惀绫诲瀷锛1-杩愯惀妗╋紱2-涓汉妗╋級 + */ + private String businessType; + + /** + * 鍏呯數浜岀淮鐮 + */ + private String connectorQrCodeUrl; + + /** + * 鐘舵 0锛氱缃 (榛樿)锛1锛氱┖闂诧紱2锛氬崰鐢紙鏈厖鐢碉級锛3锛氬崰鐢紙鍏呯數涓級锛4锛氬崰鐢紙棰勭害閿佸畾锛 锛255锛氭晠闅 + */ + private Integer status; + + /** + * 绔欑偣id + */ + private String stationId; + + /** + * 杩愯惀鍟唅d + */ + private String merchantId; + + /** + * 杩愯惀鍟嗗悕绉 + */ + private String merchantName; + + /** + * 鍏呯數妗╃紪鍙 + */ + private String pileSn; + + /** + * 绫诲瀷 + * 1-鐩存祦鎺ュ彛 姹借溅妗+蹇厖 + * 2-浜ゆ祦鎺ュ彛 姹借溅妗+鎱㈠厖 + * 3-鎻掑骇鎺ュ彛 鐢靛崟杞︽々 + */ + private String type; + + /** + * 鍗虫椂鍔熺巼 + */ + private BigDecimal instantPower; + + /** + * 鐢甸噺 + */ + private BigDecimal electricity; + + /** + * SOC + */ + private String SOC; + + /** + * 璁惧璁㈠崟鍙 + */ + private String equipmentOrderNum; + + /** + * 骞冲彴璁㈠崟 + */ + private String orderCode; + + /** + * --------------------------------- + * 鍏呯數鏃堕暱 + */ + private String chargingTime; + + /** + * 鐢靛帇 + */ + private BigDecimal voltage; + + /** + * 鐢垫祦 + */ + private BigDecimal current; + + /** + * 娓╁害 + */ + private String gunLineTemperature; + + /** + * 鐢ㄦ埛淇℃伅 + */ + private String userInfo; + + /** + * 璁㈠崟id + */ + private String orderId; + + /** + * 杞︾墝鍙 + */ + private String carNo; + + /** + * 绔欑偣鍚嶇О + */ + private String stationName; + + /** + * 宸插厖閲戦 + */ + private BigDecimal chargingAmount; + + /** + * 鍏呯數搴︽暟 + */ + private BigDecimal chargingDegree; + + /** + * 妗╅瀹氬姛鐜 + */ + private String ratedPower; + + /** + * 鍓╀綑鏃堕棿 + */ + private String timeRemaining; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileDetailVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileDetailVO.java new file mode 100644 index 000000000..efe48b351 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileDetailVO.java @@ -0,0 +1,111 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 杩斿洖鍓嶇鍙傛暟 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PileDetailVO { + /** + * 妗﹊d + */ + private String pileId; + + /** + * sn鍙 + */ + private String pileSn; + + /** + * 鐘舵 0-鏈煡锛1-鍦ㄧ嚎锛2-绂荤嚎锛3-鏁呴殰 + */ + private String status; + + /** + * 绔欑偣鍚嶇О + */ + private String stationName; + + /** + * 绔欑偣id + */ + private String stationId; + + /** + * 杩愯惀鍟嗗悕绉 + */ + private String merchantName; + + /** + * 杩愯惀鍟唅d + */ + private String merchantId; + + /** + * 璁惧绫诲瀷(1-蹇厖锛2-鎱㈠厖锛3-鐢靛崟杞) + */ + private String pileType; + + /** + * 鏋暟閲 + */ + private Integer gunNum; + + /** + * 鎺ュ彛鏍囧噯 + */ + private String interfaceStandard; + + /** + * 棰濆畾鍔熺巼 + */ + private Integer ratedPower; + + /** + * 棰濆畾鐢垫祦 + */ + private Integer ratedCurrent; + + /** + * sim鍗″彿 + */ + private String ICCID; + + /** + * sim鍗″晢 + */ + private String simSupplier; + + /** + * sim鍗¤繍钀ュ晢 + */ + private String operator; + + /** + * 娉ㄥ唽鏃堕棿 + */ + private String registrationTime; + + /** + * 鍒版湡鏃堕棿 + */ + private String expireTime; + + /** + * 浣跨敤杞﹁締鎻忚堪 + */ + private String matchCars; + + /** + * 浜岀淮鐮佸瓧绗︿覆 + */ + private String qrCodeURL; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileModelInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileModelInfoVO.java new file mode 100644 index 000000000..d2664d4ef --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileModelInfoVO.java @@ -0,0 +1,88 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * + * + * @author JS-ZZA + * @date 2022/10/21 14:29 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PileModelInfoVO { + /** + * 妗╃紪鍙 + */ + private String pileSn; + + /** + * 鍨嬪彿id + */ + private String modelId; + + /** + * 鍨嬪彿鍚嶇О + */ + private String modelName; + + /** + * 棰濆畾鍔熺巼 + */ + private String ratedPower; + + /** + * 棰濆畾鐢垫祦 + */ + private String ratedCurrent; + + /** + * 棰濆畾鐢靛帇 + */ + private String ratedVoltage; + + /** + * 鍏呯數绫诲瀷 + */ + private String speedType; + + /** + * 鍏呯數妗╃被鍨嬶紙1-姹借溅妗╋紝2-鐢靛崟杞︼級 + */ + private String chargerPileType; + + /** + * 鍏呯數鏋暟閲 + */ + private String connectorNum; + + /** + * 鍏呯數鎺ュ彛鏍囧噯 + */ + private String interfaceStandard; + + /** + * 鍒涘缓浜 + */ + private String createBy; + + /** + * 鍒涘缓鏃堕棿 + */ + private String createTime; + + /** + * 鏇存柊浜 + */ + private String updateBy; + + /** + * 鏇存柊鏃堕棿 + */ + private String updateTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileStationVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileStationVO.java new file mode 100644 index 000000000..4d256513d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/PileStationVO.java @@ -0,0 +1,150 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 绔欑偣绠$悊鍒楄〃鍙嶅弬 + * + * @author JS-ZZA + * @date 2022/9/1 13:28 + */ +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PileStationVO { + /** + * 绔欑偣id + */ + private String id; + + /** + * 绔欑偣鍚嶇О + */ + private String stationName; + + /** + * 鐪佸競杈栧尯缂栫爜 + */ + private String areaCode; + + /** + * 鍦板尯 + */ + private String area; + + /** + * 鍦板潃 + */ + private String address; + + /** + * 鍏呯數璁惧鏁伴噺 + */ + private Integer pileNum; + + /** + * 杩愯惀鍟咺D + */ + private String merchantId; + + /** + * 杩愯惀鍟嗗悕绉 + */ + private String merchantName; + + /** + * 杩愯惀鍟嗙鐞嗗憳 + */ + private String merchantAdminName; + + /** + * 绔欑偣鐘舵 + */ + private Integer stationStatus; + + /** + * 绔欑偣绫诲瀷 + */ + private String stationType; + + /** + * 鍒涘缓鏃堕棿 + */ + private String createTime; + + /** + * ---------------------------- + * 绔欑偣鐢佃瘽 + */ + private String stationTel; + + /** + * 閫傜敤杞﹀瀷鎻忚堪 + */ + private String matchCars; + + private List selectMatchCars; + + /** + * 缁忓害 + */ + private String stationLng; + + /** + * 绾害 + */ + private String stationLat; + + /** + * 寤鸿鍦烘墍 + */ + private String construction; + + /** + * 钀ヤ笟鏃堕棿鎻忚堪 + */ + private String businessHours; + + /** + * 缁勭粐缁撴瀯浠g爜 + */ + private String organizationCode; + + /** + * 鏄惁瀵瑰寮鏀 + */ + private String publicFlag; + + /** + * 鏄惁钀ヤ笟涓 + */ + private String openFlag; + + /** + * 褰撳墠缁忕含搴﹁窛绂 + */ + private String distance; + + /** + * 绔欑偣鐓х墖 浣跨敤鑻辨枃閫楀彿(,)鎷兼帴 + */ + private String pictures; + + /** + * 鐢佃垂 + */ + private BigDecimal electricityPrice; + + /** + * 鏈嶅姟璐 + */ + private BigDecimal servicePrice; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimCardInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimCardInfoVO.java new file mode 100644 index 000000000..8c05ca13d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimCardInfoVO.java @@ -0,0 +1,63 @@ +package com.jsowell.pile.vo.web; + +import lombok.Data; + +/** + * sim鍗′俊鎭疺O + * + * @author JS-ZZA + * @date 2022/12/3 10:31 + */ +@Data +public class SimCardInfoVO { + /** + * sim鍗d + */ + private String id; + + /** + * 濂楅鍚嶇О + */ + private String name; + + /** + * 妗╃紪鐮 + */ + private String pileSn; + + /** + * ICCID + */ + private String iccId; + + /** + * sim鍗$姸鎬 锛0-娌夐粯锛1-姝e湪浣跨敤锛2-姝e父浣跨敤锛 + */ + private String simCardStatus; + + /** + * 鎬昏娴侀噺 + */ + private String totalData; + + /** + * 鍓╀綑娴侀噺 + */ + private String surplusData; + + /** + * 鍒版湡鏃堕棿 + */ + private String expireTime; + + /** + * 杩愯惀鍟 + */ + private String operator; + + /** + * Sim鍗′緵搴斿晢 + */ + private String simSupplier; + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimCardVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimCardVO.java new file mode 100644 index 000000000..e6e725502 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimCardVO.java @@ -0,0 +1,84 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +/** + * Sim鍗$浉鍏充俊鎭疺O + * 1鍗$殑杩愯惀鍟 2杩愯惀鍟嗭紙绉诲姩銆佽仈閫氾級3鐘舵 4鍒版湡鏃ユ湡 5鏈堝厖閲/鍓╀綑娴侀噺 6缁垂 + * + * @author JS-ZZA + * @date 2022/12/7 11:00 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class SimCardVO { + /** + * 鍗″彿 + */ + private String iccId; + + /** + * 鍗″晢 + */ + private String simCardFactory; + + /** + * 杩愯惀鍟 绉诲姩/鐢典俊/鑱旈/鍏朵粬 + */ + private String simCardOperator; + + /** + * sim鍗$姸鎬 0-姝e父,1-寮哄埗鏂綉,2-瀹㈡埛鏂綉,3-瓒呭鍋,4-鏈嶅姟缁撴潫,5-鎻愯閿鍗,6-閿鍗, (XunZhong) + * 7-鏈紑鍗,8-娌夐粯鏈,9-宸插仠鏈,10-寰呮縺娲,11-宸插洖鏀,12-鏈煡锛圵uLian锛 + */ + private String simCardStatus; + + /** + * 濂楅鍚嶇О + */ + private String name; + + /** + * 杩囨湡鏃堕棿 + */ + private String expiredTime; + + /** + * 鏈堝厖閲 + */ + private BigDecimal packageCapacity; + + /** + * 宸茬敤娴侀噺 + */ + private BigDecimal usedFlowRate; + + /** + * 鍓╀綑娴侀噺 + */ + private BigDecimal residualFlowRate; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("iccId", iccId) + .append("simCardFactory", simCardFactory) + .append("simCardOperator", simCardOperator) + .append("simCardStatus", simCardStatus) + .append("name", name) + .append("expiredTime", expiredTime) + .append("packageCapacity", packageCapacity) + .append("usedFlowRate", usedFlowRate) + .append("residualFlowRate", residualFlowRate) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimRenewResultVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimRenewResultVO.java new file mode 100644 index 000000000..83477ba1f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/SimRenewResultVO.java @@ -0,0 +1,37 @@ +package com.jsowell.pile.vo.web; + +import lombok.Data; + +/** + * sim鍗$画璐筕O + * + * @author JS-ZZA + * @date 2022/12/21 11:12 + */ +@Data +public class SimRenewResultVO { + /** + * 鍗″彿 + */ + private String iccId; + + /** + * 鍗″晢 + */ + private String simSuppler; + + /** + * 缁垂鍛ㄦ湡 + */ + private int cycleNumber; + + /** + * 缁垂缁撴灉 + */ + private boolean result; + + /** + * 澶辫触鍘熷洜 + */ + private String reason; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/UpdateMemberBalanceDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/UpdateMemberBalanceDTO.java new file mode 100644 index 000000000..599b3136d --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/UpdateMemberBalanceDTO.java @@ -0,0 +1,61 @@ +package com.jsowell.pile.vo.web; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UpdateMemberBalanceDTO { + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 鏇存柊绫诲瀷 + * 1-杩涜处锛2-鍑鸿处 + */ + private String type; + + /** + * 瀛愮被鍨 + * 杩涜处锛10-鍏呭, 11-璧犻, 12-璁㈠崟缁撶畻閫娆 + * 鍑鸿处锛20-鍚庣鎵f, 21-璁㈠崟浠樻, 22-鐢ㄦ埛閫娆 + */ + private String subType; + + /** + * 鍏呭/鎵f 鏈噾閲戦 + */ + private BigDecimal updatePrincipalBalance; + + /** + * 鍏呭/鎵f 璧犻侀噾棰 + */ + private BigDecimal updateGiftBalance; + + /** + * 鍏宠仈璁㈠崟 + * 鍙湁鏀粯璁㈠崟鍜岃鍗曢娆炬椂鎵嶆湁鍊 + */ + private String relatedOrderCode; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("memberId", memberId) + .append("type", type) + .append("subType", subType) + .append("updatePrincipalBalance", updatePrincipalBalance) + .append("updateGiftBalance", updateGiftBalance) + .toString(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/WuLianSimData.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/WuLianSimData.java new file mode 100644 index 000000000..23b2d02c1 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/WuLianSimData.java @@ -0,0 +1,93 @@ +package com.jsowell.pile.vo.web; + +import lombok.Data; + +/** + * 鐗╄仈鏅鸿兘Sim鍗′俊鎭 + * + * @author JS-ZZA + * @date 2023/1/4 11:56 + */ +@Data +public class WuLianSimData { + /** + * 鍒版湡鏃堕棿 + */ + private String cardEndTime; + + /** + * 寮濮嬭璐规椂闂 + */ + private String cardFeeTime; + + /** + * 鍗$姸鎬 + * + * 0-鏈紑鍗 + * 2-娌夐粯鏈 + * 4-宸插仠鏈 + * 5-宸叉柇缃 + * 8-寰呮縺娲 + * 9-姝e父浣跨敤 + * 20-鏈熸弧,鍏冲仠 + * 21-宸插洖鏀剁姸鎬 + * 80-鏈煡 + * 99-宸插垹闄 + */ + private String cardStatus; + + /** + * 鍗″彿 + */ + private String iccId; + + /** + * IMSI鍙 + */ + private String imsi; + + /** + * 鍓╀綑鍛ㄦ湡 + */ + private String leftPeriod; + + /** + * 鍗 msisdn + */ + private String msisdn; + + /** + * 澶囨敞 + */ + private String note; + + /** + * 鍗″椁愬彲浣跨敤娴侀噺锛圡锛 + */ + private String packageCanUsage; + + /** + * 濂楅宸蹭娇鐢ㄦ祦閲(M) + */ + private String packageHasUsage; + + /** + * 濂楅 ID + */ + private String packageId; + + /** + * 濂楅鍚嶇О + */ + private String packageName; + + /** + * 鏈湡缁撴潫鏃堕棿 + */ + private String periodEndTime; + + /** + * 鏈湡寮濮嬫椂闂 + */ + private String periodStartTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/WuLianSimRenewVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/WuLianSimRenewVO.java new file mode 100644 index 000000000..7e6f06bc1 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/WuLianSimRenewVO.java @@ -0,0 +1,44 @@ +package com.jsowell.pile.vo.web; + +import lombok.Data; + +/** + * 鐗╄仈骞冲彴Sim鍗$画璐圭粨鏋 + * + * @author JS-ZZA + * @date 2023/2/18 9:31 + */ +@Data +public class WuLianSimRenewVO { + + /** + * 杩斿洖code + */ + private String code; + + /** + * 杩斿洖鐨刴sg + */ + private String msg; + + /** + * 涓嬪崟鎴愬姛涔嬪悗鐨勮鍗曞彿 + */ + private String orderNo; + + /** + * 璁㈠崟鐘舵 + * 0.寰呬粯娆 1.寰呭鏍 2.瀹℃牳閫氳繃 3.瀹℃牳涓嶉氳繃 + */ + private String orderStatus; + + /** + * 澶栭儴璁㈠崟鍙 + */ + private String outOrderNo; + + /** + * 鍒涘缓鏃堕棿 + */ + private String createTime; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/XunZhongSimData.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/XunZhongSimData.java new file mode 100644 index 000000000..e4406bbf7 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/web/XunZhongSimData.java @@ -0,0 +1,50 @@ +package com.jsowell.pile.vo.web; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +@Data +public class XunZhongSimData { + private String code; + private String message; + private String iccid; + private String carrier_type; + private String msisdn; + private String imsi; + private String activated_at; + private String life_cycle; + private String net_status; + private String bind_status; + private String power_status; + private String online_status; + private String is_need_verified; + private String authentication_status; + private String service_end_time; + private String agent_name; + private String agent_id; + private List current_products; + private List future_products; + + @Data + public static class Products { + private String user_business_type; + private String code; + private String name; + private String service_cycle; + private String service_cycle_unit; + private BigDecimal package_capacity; + private String capacity_unit; + private BigDecimal voice_capacity; + private String subscribed_at; + private String effective_time; + private String expiration_time; + private String cycles; + private String cycle_list; + private String current_cycle_begin_time; + private String current_cycle_end_time; + private BigDecimal current_cycle_usage; + private BigDecimal current_cycle_voice_usage; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/common/WeChatPayParameter.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/common/WeChatPayParameter.java new file mode 100644 index 000000000..3cb853b30 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/common/WeChatPayParameter.java @@ -0,0 +1,72 @@ +package com.jsowell.wxpay.common; + +import java.security.PrivateKey; +import java.security.cert.X509Certificate; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @Author 寰愭煰 + * @Description 瀹氫箟寰俊鏀粯鍙傛暟閰嶇疆绫 + * @Date 21:06 2021/5/10 + * @Param + * @return + **/ +public class WeChatPayParameter { + /** + * 寰俊鍟嗘埛鍙 + */ + public static String mchId; + + /** + * 鍟嗘埛鍦ㄥ井淇″叕浼楀钩鍙扮敵璇锋湇鍔″彿瀵瑰簲鐨凙PPID + */ + public static String appId; + + /** + * 鍥炶皟鎶ユ枃瑙e瘑V3瀵嗛挜key + */ + public static String v3Key; + + /** + * 寰俊鑾峰彇骞冲彴璇佷功鍒楄〃鍦板潃 + */ + public static String certificatesUrl; + + /** + * 寰俊APP涓嬪崟URL + */ + public static String unifiedOrderUrl; + /** + * 寰俊灏忕▼搴忕殑鍗昒RL + */ + public static String unifiedOrderUrlJS; + + /** + * 寮傛鎺ユ敹寰俊鏀粯缁撴灉閫氱煡鐨勫洖璋冨湴鍧 + */ + public static String notifyUrl; + + /** + * 寰俊璇佷功绉侀挜 + */ + public static PrivateKey privateKey; + + /** + * 寰俊鍟嗗api搴忓垪鍙 + */ + public static String mchSerialNo; + + // 瀹氫箟鍏ㄥ眬瀹瑰櫒 淇濆瓨寰俊骞冲彴璇佷功鍏挜 + public static Map certificateMap = new ConcurrentHashMap<>(); + + /** + * jsapi鏀粯 鐢宠閫娆綼pi + */ + public static String refundJsUrl; + + /** + * 寮傛鎺ユ敹寰俊閫娆剧粨鏋滈氱煡鐨勫洖璋冨湴鍧 + */ + public static String refundNotifyUrl; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/config/WechatPayConfig.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/config/WechatPayConfig.java new file mode 100644 index 000000000..511c166f2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/config/WechatPayConfig.java @@ -0,0 +1,98 @@ +package com.jsowell.wxpay.config; + + +import com.jsowell.wxpay.common.WeChatPayParameter; +import com.jsowell.wxpay.utils.WechatPayUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Order(value = 2) +@Component +public class WechatPayConfig implements CommandLineRunner { + /** + * 鍏紬鍙穉ppid + */ + @Value("${wechat.appId}") + private String wechatAppId; + + /** + * 鍟嗘埛鍙穒d + */ + @Value("${wechat.mchId}") + private String wechatMchId; + + /** + * 鍟嗘埛搴忓垪鍙 + */ + @Value("${wechat.mchSerialNo}") + private String mchSerialNo; + /** + * 鏀粯key + */ + @Value("${wechat.v3Key}") + private String wechatV3Key; + + /** + * 寰俊鏀粯鍥炶皟url + */ + @Value("${wechat.callback}") + private String payCallbackUrl; + + /** + * 寰俊閫娆惧洖璋僽rl + */ + @Value("${wechat.refundCallback}") + private String refundCallbackUrl; + + /** + * 缁熶竴涓嬪崟url + */ + @Value("${wechat.unifiedOrder.url}") + private String wechatUnifiedOrderUrl; + + /** + * 缁熶竴涓嬪崟url + */ + @Value("${wechat.unifiedOrder.jsurl}") + private String wechatUnifiedOrderUrlJS; + + /** + * jsapi鐢宠閫娆緐rl + */ + @Value("${wechat.refund.jsurl}") + private String wechatRefundJsUrl; + + /** + * 骞冲彴璇佷功鍒楄〃鍦板潃 + */ + @Value("${wechat.certificates.url}") + private String wechatCertificatesUrl; + + /** + * 鍟嗘埛绉侀挜璺緞 + */ + @Value("${wechat.key.path}") + private String wechatKeyPath; + + @Override + public void run(String... args) throws Exception { + // System.out.println(">>>>>>>>>>>>>>>鏈嶅姟鍚姩鎵ц锛屾墽琛屽姞杞芥暟鎹瓑鎿嶄綔 MyStartupRunner1 order 2 <<<<<<<<<<<<<"); + //寰俊鏀粯 + WeChatPayParameter.mchId = wechatMchId; + WeChatPayParameter.appId = wechatAppId; + WeChatPayParameter.v3Key = wechatV3Key; + WeChatPayParameter.certificatesUrl = wechatCertificatesUrl; + WeChatPayParameter.unifiedOrderUrl = wechatUnifiedOrderUrl; + WeChatPayParameter.unifiedOrderUrlJS = wechatUnifiedOrderUrlJS; + WeChatPayParameter.notifyUrl = payCallbackUrl; + WeChatPayParameter.refundJsUrl = wechatRefundJsUrl; + WeChatPayParameter.refundNotifyUrl = refundCallbackUrl; + //鍔犺浇鍟嗘埛绉侀挜 + WeChatPayParameter.privateKey = WechatPayUtils.getPrivateKey(wechatKeyPath); + WeChatPayParameter.mchSerialNo = mchSerialNo; + //鑾峰彇骞冲彴璇佷功 + WeChatPayParameter.certificateMap = WechatPayUtils.refreshCertificate(); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/config/WeixinLoginProperties.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/config/WeixinLoginProperties.java new file mode 100644 index 000000000..31a38be68 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/config/WeixinLoginProperties.java @@ -0,0 +1,34 @@ +package com.jsowell.wxpay.config; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class WeixinLoginProperties implements InitializingBean { + + @Value("${weixin.login.gateway}") + private String gateway; + + @Value("${weixin.login.appid}") + private String appid; + + @Value("${weixin.login.appsecret}") + private String appsecret; + + @Value("${weixin.login.redirectUrl}") + private String redirectUrl; + + public static String WX_OPEN_GATEWAY; + public static String WX_OPEN_APP_ID; + public static String WX_OPEN_APP_SECRET; + public static String WX_OPEN_REDIRECT_URL; + + @Override + public void afterPropertiesSet() throws Exception { + WX_OPEN_APP_ID = appid; + WX_OPEN_GATEWAY = gateway; + WX_OPEN_APP_SECRET = appsecret; + WX_OPEN_REDIRECT_URL = redirectUrl; + } +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/AppletTemplateMessageSendDTO.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/AppletTemplateMessageSendDTO.java new file mode 100644 index 000000000..570d2043f --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/AppletTemplateMessageSendDTO.java @@ -0,0 +1,70 @@ +package com.jsowell.wxpay.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 灏忕▼搴忔ā鏉挎秷鎭彂閫佹ā鏉 + */ +@Data +public class AppletTemplateMessageSendDTO implements Serializable { + private static final long serialVersionUID = 2234575457450378840L; + + // 鍦烘櫙绫诲瀷锛1-寮濮嬪厖鐢碉紱2-缁撴潫鍏呯數锛 + private String type; + + //鎺ユ敹鑰咃紙鐢ㄦ埛锛夌殑 openid + private String touser; + + //鎵闇涓嬪彂鐨勮闃呮ā鏉縤d + private String template_id; + + //鎵璺宠浆鐨勯〉闈 + private String page; + + //妯℃澘娑堟伅鍐呭 + private Object data; + + private StartChargingMessage startChargingMessage; + + private StopChargingMessage stopChargingMessage; + + @Data + public static class StartChargingMessage { + + /** + * 绔欑偣鍚嶇О + * thing5 + */ + private String stationName; + + /** + * 寮濮嬫椂闂 + * time2 + */ + private String startTime; + + } + + @Data + public static class StopChargingMessage { + /** + * 鍏呯數璐圭敤 + * amount17 + */ + private String chargingAmount; + + /** + * 缁撴潫鏃堕棿 + * time3 + */ + private String endTime; + + /** + * 缁撴潫鍘熷洜 + * thing7 + */ + private String endReason; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/WeChatRefundDTO.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/WeChatRefundDTO.java new file mode 100644 index 000000000..8a56f09cf --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/WeChatRefundDTO.java @@ -0,0 +1,35 @@ +package com.jsowell.wxpay.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class WeChatRefundDTO { + /** + * 浼氬憳id + */ + private String memberId; + + /** + * 璁㈠崟缂栧彿 + */ + private String orderCode; + + /** + * 閫娆剧被鍨 + * 1-璁㈠崟缁撶畻閫娆 2-鐢ㄦ埛浣欓閫娆 + */ + private String refundType; + + /** + * 閫娆鹃噾棰 + */ + private BigDecimal refundAmount; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/WechatSendMsgDTO.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/WechatSendMsgDTO.java new file mode 100644 index 000000000..ad346ffe6 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/dto/WechatSendMsgDTO.java @@ -0,0 +1,27 @@ +package com.jsowell.wxpay.dto; + +import lombok.Data; + +/** + * 灏忕▼搴忎笅鍙戞秷鎭疍TO + * + * @author JS-ZZA + * @date 2023/2/15 9:50 + */ +@Data +public class WechatSendMsgDTO { + /** + * 鐢ㄦ埛code + */ + private String code; + + /** + * 鐢ㄦ埛openid + */ + private String openId; + + /** + * 璁㈠崟鍙 + */ + private String orderCode; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayNotifyParameter.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayNotifyParameter.java new file mode 100644 index 000000000..658a0a3fe --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayNotifyParameter.java @@ -0,0 +1,67 @@ +package com.jsowell.wxpay.response; + +import lombok.Data; + +/** + * 寰俊鏀粯閫氱煡鍙傛暟 + */ +@Data +public class WechatPayNotifyParameter { + /** + * 閫氱煡ID 閫氱煡鐨勫敮涓ID + */ + private String id; + + /** + * 閫氱煡鍒涘缓鏃堕棿 鏍煎紡涓簓yyy-MM-DDTHH:mm:ss+TIMEZONE + */ + private String create_time; + + /** + * 閫氱煡鏁版嵁绫诲瀷 鏀粯鎴愬姛閫氱煡涓篹ncrypt-resource + */ + private String resource_type; + + /** + * 閫氱煡绫诲瀷 鏀粯鎴愬姛閫氱煡鐨勭被鍨嬩负TRANSACTION.SUCCESS + */ + private String event_type; + + /** + * 鍥炶皟鎽樿 鍥炶皟鎽樿 绀轰緥鍊硷細鏀粯鎴愬姛 + */ + private String summary; + + /** + * 閫氱煡鏁版嵁 閫氱煡璧勬簮鏁版嵁json鏍煎紡 + */ + private Resource resource; + + @Data + public static class Resource { + /** + * 鍘熷绫诲瀷 鍘熷鍥炶皟绫诲瀷锛屼负transaction + */ + private String original_type; + + /** + * 鍔犲瘑绠楁硶绫诲瀷 瀵瑰紑鍚粨鏋滄暟鎹繘琛屽姞瀵嗙殑鍔犲瘑绠楁硶锛岀洰鍓嶅彧鏀寔AEAD_AES_256_GCM + */ + private String algorithm; + + /** + * 鏁版嵁瀵嗘枃 Base64缂栫爜鍚庣殑寮鍚/鍋滅敤缁撴灉鏁版嵁瀵嗘枃 + */ + private String ciphertext; + + /** + * 闄勫姞鏁版嵁 + */ + private String associated_data; + + /** + * 闅忔満涓 鍔犲瘑浣跨敤鐨勯殢鏈轰覆 + */ + private String nonce; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayNotifyResource.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayNotifyResource.java new file mode 100644 index 000000000..0c197aeb4 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayNotifyResource.java @@ -0,0 +1,112 @@ +package com.jsowell.wxpay.response; + +import lombok.Data; + +@Data +public class WechatPayNotifyResource { + + /** + * 鍟嗘埛鍙 + */ + private String mchid; + + /** + * 搴旂敤ID + */ + private String appid; + + /** + * 鍟嗘埛璁㈠崟鍙 鍟嗘埛绯荤粺鍐呴儴璁㈠崟鍙凤紝鍙兘鏄暟瀛椼佸ぇ灏忓啓瀛楁瘝_-*涓斿湪鍚屼竴涓晢鎴峰彿涓嬪敮涓銆 + */ + private String out_trade_no; + + /** + * 寰俊鏀粯璁㈠崟鍙 寰俊鏀粯绯荤粺鐢熸垚鐨勮鍗曞彿銆 + */ + private String transaction_id; + + /** + * 浜ゆ槗绫诲瀷 + * JSAPI锛氬叕浼楀彿鏀粯 + * NATIVE锛氭壂鐮佹敮浠 + * APP锛欰PP鏀粯 + * MICROPAY锛氫粯娆剧爜鏀粯 + * MWEB锛欻5鏀粯 + * FACEPAY锛氬埛鑴告敮浠 + */ + private String trade_type; + + /** + * 浜ゆ槗鐘舵侊紝鏋氫妇鍊硷細 + * SUCCESS锛氭敮浠樻垚鍔 + * REFUND锛氳浆鍏ラ娆 + * NOTPAY锛氭湭鏀粯 + * CLOSED锛氬凡鍏抽棴 + * REVOKED锛氬凡鎾ら攢锛堜粯娆剧爜鏀粯锛 + * USERPAYING锛氱敤鎴锋敮浠樹腑锛堜粯娆剧爜鏀粯锛 + * PAYERROR锛氭敮浠樺け璐(鍏朵粬鍘熷洜锛屽閾惰杩斿洖澶辫触) + */ + private String trade_state; + + /** + * 浜ゆ槗鐘舵佹弿杩 + */ + private String trade_state_desc; + + /** + * 浠樻閾惰 閾惰绫诲瀷锛岄噰鐢ㄥ瓧绗︿覆绫诲瀷鐨勯摱琛屾爣璇嗐 + * https://pay.weixin.qq.com/wiki/doc/apiv3/terms_definition/chapter1_1_3.shtml#part-6 + */ + private String bank_type; + + /** + * 闄勫姞鏁版嵁 + */ + private String attach; + + /** + * 鏀粯瀹屾垚鏃堕棿 鏀粯瀹屾垚鏃堕棿锛岄伒寰猺fc3339鏍囧噯鏍煎紡锛屾牸寮忎负yyyy-MM-DDTHH:mm:ss+TIMEZONE + */ + private String success_time; + + /** + * 鏀粯鑰呬俊鎭 + */ + private Payer payer; + + /** + * 璁㈠崟閲戦 + */ + private Amount amount; + + @Data + public static class Payer { + /** + * 鐢ㄦ埛鏍囪瘑 鐢ㄦ埛鍦ㄧ洿杩炲晢鎴穉ppid涓嬬殑鍞竴鏍囪瘑銆 + */ + private String openid; + } + + @Data + public static class Amount { + /** + * 鎬婚噾棰 璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎銆 + */ + private String total; + + /** + * 鐢ㄦ埛鏀粯閲戦 鐢ㄦ埛鏀粯閲戦锛屽崟浣嶄负鍒嗐 + */ + private String payer_total; + + /** + * 璐у竵绫诲瀷 CNY锛氫汉姘戝竵锛屽鍐呭晢鎴峰彿浠呮敮鎸佷汉姘戝竵銆 + */ + private String currency; + + /** + * 鐢ㄦ埛鏀粯甯佺 + */ + private String payer_currency; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundNotifyResource.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundNotifyResource.java new file mode 100644 index 000000000..6bd6a3427 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundNotifyResource.java @@ -0,0 +1,83 @@ +package com.jsowell.wxpay.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 寰俊閫娆鹃氱煡鍙傛暟 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class WechatPayRefundNotifyResource { + /** + * 鐩磋繛鍟嗘埛鍙 + */ + private String mchid; + + /** + * 鍟嗘埛璁㈠崟鍙 + */ + private String out_trade_no; + + /** + * 寰俊鏀粯璁㈠崟鍙 + */ + private String transaction_id; + + /** + * 鍟嗘埛閫娆惧崟鍙 + */ + private String out_refund_no; + + /** + * 寰俊鏀粯閫娆惧崟鍙 + */ + private String refund_id; + + /** + * 閫娆剧姸鎬 + */ + private String refund_status; + + /** + * 閫娆炬垚鍔熸椂闂 + */ + private String success_time; + + /** + * 閫娆惧叆璐﹁处鎴 + */ + private String user_received_account; + + /** + * 閲戦淇℃伅 + */ + private Amount amount; + + @Data + public static class Amount { + /** + * 璁㈠崟閲戦 + */ + private int total; + + /** + * 閫娆鹃噾棰 + */ + private int refund; + + /** + * 鐢ㄦ埛鏀粯閲戦 + */ + private int payer_total; + + /** + * 鐢ㄦ埛閫娆鹃噾棰 + */ + private int payer_refund; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundRequest.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundRequest.java new file mode 100644 index 000000000..5f21a557e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundRequest.java @@ -0,0 +1,59 @@ +package com.jsowell.wxpay.response; + +import lombok.Data; + +@Data +public class WechatPayRefundRequest { + /** + * 寰俊鏀粯璁㈠崟鍙 + */ + private String transaction_id; + + /** + * 鍟嗘埛璁㈠崟鍙 + */ + private String out_trade_no; + + /** + * 鍟嗘埛閫娆惧崟鍙 + */ + private String out_refund_no; + + /** + * 閫娆惧師鍥 + */ + private String reason; + + /** + * 閫娆剧粨鏋滃洖璋僽rl + */ + private String notify_url; + + /** + * 閫娆捐祫閲戞潵婧 + */ + private String funds_account; + + /** + * 閲戦淇℃伅 + */ + private Amount amount; + + @Data + public static class Amount { + /** + * 閫娆鹃噾棰 + */ + private int refund; + + /** + * 鍘熻鍗曢噾棰 + */ + private int total; + + /** + * 閫娆惧竵绉 + */ + private String currency = "CNY"; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundResponse.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundResponse.java new file mode 100644 index 000000000..156ed5d40 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/response/WechatPayRefundResponse.java @@ -0,0 +1,161 @@ +package com.jsowell.wxpay.response; + +import lombok.Data; + +import java.util.List; + +@Data +public class WechatPayRefundResponse { + + /** + * 寰俊鏀粯閫娆惧崟鍙 + */ + private String refund_id; + + /** + * 鍟嗘埛閫娆惧崟鍙 + */ + private String out_refund_no; + + /** + * 寰俊鏀粯璁㈠崟鍙 + */ + private String transaction_id; + + /** + * 鍟嗘埛璁㈠崟鍙 + */ + private String out_trade_no; + + /** + * 閫娆炬笭閬 + * 鏋氫妇鍊硷細 + * ORIGINAL锛氬師璺娆 + * BALANCE锛氶鍥炲埌浣欓 + * OTHER_BALANCE锛氬師璐︽埛寮傚父閫鍒板叾浠栦綑棰濊处鎴 + * OTHER_BANKCARD锛氬師閾惰鍗″紓甯搁鍒板叾浠栭摱琛屽崱 + */ + private String channel; + + /** + * 閫娆惧叆璐﹁处鎴 + * 鍙栧綋鍓嶉娆惧崟鐨勯娆惧叆璐︽柟锛屾湁浠ヤ笅鍑犵鎯呭喌锛 + * 1锛夐鍥為摱琛屽崱锛歿閾惰鍚嶇О}{鍗$被鍨媫{鍗″熬鍙穧 + * 2锛夐鍥炴敮浠樼敤鎴烽浂閽:鏀粯鐢ㄦ埛闆堕挶 + * 3锛夐杩樺晢鎴:鍟嗘埛鍩烘湰璐︽埛鍟嗘埛缁撶畻閾惰璐︽埛 + * 4锛夐鍥炴敮浠樼敤鎴烽浂閽遍:鏀粯鐢ㄦ埛闆堕挶閫 + */ + private String user_received_account; + + /** + * 閫娆炬垚鍔熸椂闂 + */ + private String success_time; + + /** + * 閫娆惧垱寤烘椂闂 + */ + private String create_time; + + /** + * 閫娆剧姸鎬 + * 閫娆惧埌閾惰鍙戠幇鐢ㄦ埛鐨勫崱浣滃簾鎴栬呭喕缁撲簡锛屽鑷村師璺娆鹃摱琛屽崱澶辫触锛屽彲鍓嶅線鍟嗘埛骞冲彴-浜ゆ槗涓績锛屾墜鍔ㄥ鐞嗘绗旈娆俱 + * 鏋氫妇鍊硷細 + * SUCCESS锛氶娆炬垚鍔 + * CLOSED锛氶娆惧叧闂 + * PROCESSING锛氶娆惧鐞嗕腑 + * ABNORMAL锛氶娆惧紓甯 + */ + private String status; + + /** + * 璧勯噾璐︽埛 + * 閫娆炬墍浣跨敤璧勯噾瀵瑰簲鐨勮祫閲戣处鎴风被鍨 + * 鏋氫妇鍊硷細 + * UNSETTLED : 鏈粨绠楄祫閲 + * AVAILABLE : 鍙敤浣欓 + * UNAVAILABLE : 涓嶅彲鐢ㄤ綑棰 + * OPERATION : 杩愯惀鎴 + * BASIC : 鍩烘湰璐︽埛锛堝惈鍙敤浣欓鍜屼笉鍙敤浣欓锛 + */ + private String funds_account; + + /** + * 閲戦璇︾粏淇℃伅 + */ + private Amount amount; + + @Data + public static class Amount { + /** + * 璁㈠崟閲戦 + */ + private int total; + + /** + * 閫娆鹃噾棰 + */ + private int refund; + + /** + * 閫娆惧嚭璧勮处鎴峰強閲戦 + */ + private List from; + + /** + * 鐢ㄦ埛鏀粯閲戦 + */ + private int payer_total; + + /** + * 鐢ㄦ埛閫娆鹃噾棰 + */ + private int payer_refund; + + /** + * 搴旂粨閫娆鹃噾棰 + */ + private int settlement_refund; + + /** + * 搴旂粨璁㈠崟閲戦 + */ + private int settlement_total; + + /** + * 浼樻儬閫娆鹃噾棰 + */ + private int discount_refund; + + /** + * 閫娆惧竵绉 + */ + private String currency; + + /** + * 鎵嬬画璐归娆鹃噾棰 + */ + private int refund_fee; + } + + /** + * 閫娆惧嚭璧勭殑璐︽埛绫诲瀷鍙婇噾棰濅俊鎭 + */ + @Data + public static class From { + /** + * 鍑鸿祫璐︽埛绫诲瀷 + * 涓嬮潰鏋氫妇鍊煎閫変竴銆 + * 鏋氫妇鍊硷細 + * AVAILABLE : 鍙敤浣欓 + * UNAVAILABLE : 涓嶅彲鐢ㄤ綑棰 + */ + private String account; + + /** + * 鍑鸿祫閲戦 + */ + private int amount; + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/service/WxAppletRemoteService.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/service/WxAppletRemoteService.java new file mode 100644 index 000000000..f69aa56a2 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/service/WxAppletRemoteService.java @@ -0,0 +1,288 @@ +package com.jsowell.wxpay.service; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableMap; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.http.HttpUtils; +import com.jsowell.pile.service.IOrderBasicInfoService; +import com.jsowell.pile.vo.uniapp.SendMessageVO; +import com.jsowell.wxpay.config.WeixinLoginProperties; +import com.jsowell.wxpay.dto.AppletTemplateMessageSendDTO; +import com.jsowell.wxpay.dto.WechatSendMsgDTO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +@Service +public class WxAppletRemoteService { + + private Logger log = LoggerFactory.getLogger(WxAppletRemoteService.class); + + private static final String WX_APPLET_URl = "https://api.weixin.qq.com/cgi-bin"; + + private static final String GET_USER_PHONE_NUMBER_URL = "https://api.weixin.qq.com/wxa/business/getuserphonenumber"; + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private RedisCache redisCache; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Value("${weixin.login.appid}") + private String appid; + + @Value("${weixin.login.appsecret}") + private String secret; + + @Value("${weixin.sendMsg.startChargingTmpId}") + private String startChargingTmpId; + + @Value("${weixin.sendMsg.stopChargingTmpId}") + private String stopChargingTmpId; + + /** + * 鑾峰彇accessToken + * + * @return + */ + public String getAccessToken() { + // String appid = Constants.APP_ID; + // String secret = Constants.APP_SECRET; + + // 杩欓噷鎴戞槸浠庨厤缃枃浠朵腑鍙栧緱appid鍜宎ppsecret + // appid = properties.getAppId(); + // secret = properties.getAppSecret(); + + //鏌ヨtoken鏄惁瀛樺湪 + String redisKey = "AccessToken_" + appid; + // 浣跨敤缂撳瓨鍏堟煡璇ccessToken鏄惁瀛樺湪 + String accessToken = redisCache.getCacheObject(redisKey); + // 瀛樺湪鐩存帴杩斿洖锛屼笉瀛樺湪閲嶆柊鑾峰彇AccessToken + if (!Strings.isNullOrEmpty(accessToken)) { + return accessToken; + } + // 鑾峰彇AccessToken鐨剈rl + String grantType = "client_credential"; + // https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= + String url = WX_APPLET_URl + "/token?grant_type=" + grantType + "&appid=" + appid + "&secret=" + secret; + // 鑾峰彇鍒癆ccessToken + String token = HttpUtils.sendGet(url); + Map map = null; + try { + map = objectMapper.readValue(token, Map.class); + } catch (IOException e) { + log.error("灏忕▼搴忓紓甯搁氱煡-鑾峰彇AccessToken-杞寲寮傚父", e); + } + String access_token = String.valueOf(map.get("access_token")); + // 鎶夾ccessToken瀛樺叆缂撳瓨涓紝骞惰缃繃鏈熸椂闂达紝鍥犱负access_token鐨勮繃鏈熸椂闂存槸涓ゅ皬鏃讹紝鎴戜滑缂撳瓨鐨勬椂闂翠竴瀹氳灏忎簬涓ゅ皬鏃讹紝 + redisCache.setCacheObject(redisKey, access_token, 300); + if (map.get("errcode") != null || map.get("errmsg") != null) { + String errcode = String.valueOf(map.get("errcode")); + String errmsg = String.valueOf(map.get("errmsg")); + if (!errcode.equals("0")) { + log.error("鑾峰彇token澶辫触锛歝ode=" + errcode + "msg=" + errmsg); + return null; + } + } + return access_token; + } + + /** + * 鑾峰彇鎵嬫満鍙 + * + * @param code + * @return + */ + public String getMobileNumberByCode(String code) { + if (StringUtils.isBlank(code)) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + // 璇锋眰鑾峰彇浠ょ墝 + String access_token = getAccessToken(); + // 閫氳繃token锛宑ode锛堝墠绔痝etPhoneNum鎸夐挳杩斿洖鐨刢ode锛岃屼笉鏄櫥褰曠殑code锛夊彂閫乸ost璇锋眰鍒板畼鏂硅幏鍙栧埌鎵嬫満鍙风爜 + String postUrl = GET_USER_PHONE_NUMBER_URL + "?access_token=" + access_token; + JSONObject paramJson = new JSONObject(); + paramJson.put("code", code); + String postResult = HttpUtils.sendPost(postUrl, paramJson.toJSONString()); + JSONObject postResultJson = JSONObject.parseObject(postResult); + String errCode = postResultJson.getString("errcode"); + + if (!StringUtils.equals(errCode, Constants.ZERO)) { + // errCode涓嶄负0锛岃〃绀烘湁閿欒 + String errMsg = postResultJson.getString("errmsg"); + log.info("鍙戦丳ost璇锋眰澶辫触,閿欒娑堟伅锛歿}", errMsg); + throw new BusinessException(errCode, errMsg); + } + JSONObject phoneInfoJson = (JSONObject) postResultJson.get("phone_info"); + return phoneInfoJson.getString("phoneNumber"); + } + + /** + * 鑾峰彇openId + * + * @param code + * @return + */ + public String getOpenIdByCode(String code) { + String baseAccessTokenUrl = WeixinLoginProperties.WX_OPEN_GATEWAY + + "?appid=%s" + + "&secret=%s" + + "&js_code=%s" + + "&grant_type=authorization_code"; + + log.info("appid:{},appscrect:{}", WeixinLoginProperties.WX_OPEN_APP_ID, WeixinLoginProperties.WX_OPEN_APP_SECRET); + + String accessTokenUrl = String.format(baseAccessTokenUrl, WeixinLoginProperties.WX_OPEN_APP_ID, WeixinLoginProperties.WX_OPEN_APP_SECRET, code); + + //2锛氭墽琛岃姹傦紝鑾峰彇寰俊璇锋眰杩斿洖寰楁暟鎹 + String result = HttpUtils.sendGet(accessTokenUrl); + + // 3锛 瀵瑰井淇¤繑鍥炲緱鏁版嵁杩涜杞崲 + Map resultMap = JSONObject.parseObject(result, HashMap.class); + log.info("寰俊杩斿洖鐨勬棩蹇椾俊鎭槸锛歝ode:{}锛宺esultMap锛歿}", code, resultMap); + if (resultMap.get("errcode") != null) { + throw new BusinessException("22006", "寰俊鐧诲綍鍑洪敊!"); + } + + // 4: 瑙f瀽寰俊鐢ㄦ埛寰楀敮涓鍑瘉openid + String openid = (String) resultMap.get("openid"); + if (StringUtils.isBlank(openid)) { + throw new BusinessException("22009", "鐧诲綍澶辫触锛屽皾璇曞埛鏂伴噸鏂版壂鐮佺櫥褰!!!"); + } + + // 5锛氬皝瑁呰繑鍥 + return openid; + } + + /** + * 寮濮嬪厖鐢靛彂閫佹秷鎭 + * @param dto + * @return + */ + public Map startChargingSendMsg(WechatSendMsgDTO dto) { + // 閫氳繃code鏌ヨopenId骞秙et + String openId = getOpenIdByCode(dto.getCode()); + if (StringUtils.isBlank(openId)) { + return null; + } + AppletTemplateMessageSendDTO msgInfo = new AppletTemplateMessageSendDTO(); + msgInfo.setType("1"); // 1-寮濮嬪厖鐢垫帹閫佹秷鎭 + msgInfo.setTouser(openId); + // 閫氳繃orderCode鏌ヨ鍒板厖鐢电珯鐐瑰拰寮濮嬫椂闂村苟set + String orderCode = dto.getOrderCode(); + SendMessageVO sendMessageVO = orderBasicInfoService.selectOrderInfoByOrderCode(orderCode); + + AppletTemplateMessageSendDTO.StartChargingMessage startChargingMessage = new AppletTemplateMessageSendDTO.StartChargingMessage(); + msgInfo.setStartChargingMessage(startChargingMessage); + if (StringUtils.isBlank(sendMessageVO.getChargeStartTime())) { + startChargingMessage.setStartTime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm")); + }else { + startChargingMessage.setStartTime(sendMessageVO.getChargeStartTime()); // 寮濮嬫椂闂 + } + startChargingMessage.setStationName(sendMessageVO.getStationName()); // 绔欑偣鍚嶇О + return uniAppSendMsg(msgInfo); + } + + + /** + * 鍋滄鍏呯數鍙戦佹秷鎭 + * @param dto + * @return + */ + public Map stopChargingSendMsg(WechatSendMsgDTO dto) { + // 閫氳繃璁㈠崟鍙锋煡璇㈣鍗曢噾棰 + AppletTemplateMessageSendDTO msgInfo = new AppletTemplateMessageSendDTO(); + SendMessageVO sendMessageVO = orderBasicInfoService.selectOrderInfoByOrderCode(dto.getOrderCode()); + + msgInfo.setType("2"); // 2-缁撴潫鍏呯數鎺ㄩ佹秷鎭 + msgInfo.setTouser(sendMessageVO.getOpenId()); + // 灏佽瀵硅薄骞惰皟鐢ㄥ彂閫佹秷鎭殑鏂规硶 + AppletTemplateMessageSendDTO.StopChargingMessage stopChargingMessage = new AppletTemplateMessageSendDTO.StopChargingMessage(); + msgInfo.setStopChargingMessage(stopChargingMessage); + + stopChargingMessage.setChargingAmount(sendMessageVO.getOrderAmount()); + stopChargingMessage.setEndReason(sendMessageVO.getStopReason()); + if (StringUtils.isBlank(sendMessageVO.getChargeStopTime())) { + stopChargingMessage.setEndTime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm")); + }else { + stopChargingMessage.setEndTime(sendMessageVO.getChargeStopTime()); + } + return uniAppSendMsg(msgInfo); + } + + /** + * 灏忕▼搴忓彂閫佹秷鎭柟娉 + * @param dto + * @return + */ + private Map uniAppSendMsg(AppletTemplateMessageSendDTO dto) { + // 鍒ゆ柇鏄粈涔堝満鏅皟鐢ㄦ鏂规硶锛1-寮濮嬪厖鐢垫帹閫佹秷鎭紱2-鍏呯數缁撴潫鎺ㄩ佹秷鎭級 + String type = dto.getType(); + // 鏍规嵁涓嶅悓鐨勫満鏅痵et涓嶅悓鐨勫璞 + if (StringUtils.equals("1", type)) { + // 寮濮嬪厖鐢 + String templateId = startChargingTmpId; + dto.setTemplate_id(templateId); + // dto.setPage("璺宠浆鐨勯〉闈"); + Map map = new HashMap<>(); + map.put("thing5", ImmutableMap.of("value", dto.getStartChargingMessage().getStationName())); // 鍏呯數绔欏悕绉 + map.put("time2", ImmutableMap.of("value", dto.getStartChargingMessage().getStartTime())); // 寮濮嬫椂闂 + dto.setData(map); + } else if (StringUtils.equals("2", type)) { + // 缁撴潫鍏呯數 + String templateId = stopChargingTmpId; + dto.setTemplate_id(templateId); + // dto.setPage("璺宠浆鐨勯〉闈"); + Map map = new HashMap<>(); + map.put("amount17", ImmutableMap.of("value", dto.getStopChargingMessage().getChargingAmount())); // 鍏呯數閲戦 + map.put("time3", ImmutableMap.of("value", dto.getStopChargingMessage().getEndTime())); // 缁撴潫鏃堕棿 + map.put("thing7", ImmutableMap.of("value", dto.getStopChargingMessage().getEndReason())); // 缁撴潫鍘熷洜 + dto.setData(map); + } + // 璋冪敤涓嬮潰鐨勫彂閫佹秷鎭帴鍙 + return uniformMessageSend(dto); + } + + /** + * 鍚屼竴娑堟伅鍙戦佹帴鍙 + * AppletTemplateMessageSendDTO 鏄竴涓紶杈撶被 + */ + public Map uniformMessageSend(AppletTemplateMessageSendDTO data) { + String token = getAccessToken(); + // 璋冪敤鍙戝瀷鎺ュ彛 + String url = WX_APPLET_URl + "/message/subscribe/send?access_token=" + token; + String returnData = HttpUtils.sendPost(url, JSON.toJSONString(data)); + Map map = null; + try { + map = objectMapper.readValue(returnData, Map.class); + } catch (IOException e) { + log.error("灏忕▼搴忓紓甯搁氱煡-鍚屼竴娑堟伅鍙戦-杞寲寮傚父", e); + } + String errcode = String.valueOf(map.get("errcode")); + String errmsg = String.valueOf(map.get("errmsg")); + if (!errcode.equals(Constants.ZERO)) { + log.error("娑堟伅鍙戦佸け璐ワ細code=" + errcode + "msg=" + errmsg); + } + Map resultMap = new HashMap<>(); + resultMap.put("code", errcode); + resultMap.put("message", errmsg); + return resultMap; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/AesUtil.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/AesUtil.java new file mode 100644 index 000000000..b5f041f8b --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/AesUtil.java @@ -0,0 +1,45 @@ +package com.jsowell.wxpay.utils; + +import javax.crypto.Cipher; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.GCMParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + +public class AesUtil { + + static final int KEY_LENGTH_BYTE = 32; + static final int TAG_LENGTH_BIT = 128; + private final byte[] aesKey; + + public AesUtil(byte[] key) { + if (key.length != KEY_LENGTH_BYTE) { + throw new IllegalArgumentException("鏃犳晥鐨凙piV3Key锛岄暱搴﹀繀椤讳负32涓瓧鑺"); + } + this.aesKey = key; + } + + public String decryptToString(byte[] associatedData, byte[] nonce, String ciphertext) + throws GeneralSecurityException, IOException { + try { + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); + + SecretKeySpec key = new SecretKeySpec(aesKey, "AES"); + GCMParameterSpec spec = new GCMParameterSpec(TAG_LENGTH_BIT, nonce); + + cipher.init(Cipher.DECRYPT_MODE, key, spec); + cipher.updateAAD(associatedData); + + return new String(cipher.doFinal(Base64.getDecoder().decode(ciphertext)), "utf-8"); + } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { + throw new IllegalStateException(e); + } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { + throw new IllegalArgumentException(e); + } + } +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/BufferedImageLuminanceSource.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/BufferedImageLuminanceSource.java new file mode 100644 index 000000000..0864a0497 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/BufferedImageLuminanceSource.java @@ -0,0 +1,87 @@ +package com.jsowell.wxpay.utils; + +import com.google.zxing.LuminanceSource; + +import java.awt.*; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; + +public class BufferedImageLuminanceSource extends LuminanceSource { + + private final BufferedImage image; + private final int left; + private final int top; + + public BufferedImageLuminanceSource(BufferedImage image) { + this(image, 0, 0, image.getWidth(), image.getHeight()); + } + + public BufferedImageLuminanceSource(BufferedImage image, int left, int top, int width, int height) { + super(width, height); + + int sourceWidth = image.getWidth(); + int sourceHeight = image.getHeight(); + if (left + width > sourceWidth || top + height > sourceHeight) { + throw new IllegalArgumentException("Crop rectangle does not fit within image data."); + } + + for (int y = top; y < top + height; y++) { + for (int x = left; x < left + width; x++) { + if ((image.getRGB(x, y) & 0xFF000000) == 0) { + image.setRGB(x, y, 0xFFFFFFFF); // = white + } + } + } + + this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY); + this.image.getGraphics().drawImage(image, 0, 0, null); + this.left = left; + this.top = top; + } + + public byte[] getRow(int y, byte[] row) { + if (y < 0 || y >= getHeight()) { + throw new IllegalArgumentException("Requested row is outside the image: " + y); + } + int width = getWidth(); + if (row == null || row.length < width) { + row = new byte[width]; + } + image.getRaster().getDataElements(left, top + y, width, 1, row); + return row; + } + + public byte[] getMatrix() { + int width = getWidth(); + int height = getHeight(); + int area = width * height; + byte[] matrix = new byte[area]; + image.getRaster().getDataElements(left, top, width, height, matrix); + return matrix; + } + + public boolean isCropSupported() { + return true; + } + + public LuminanceSource crop(int left, int top, int width, int height) { + return new BufferedImageLuminanceSource(image, this.left + left, this.top + top, width, height); + } + + public boolean isRotateSupported() { + return true; + } + + public LuminanceSource rotateCounterClockwise() { + int sourceWidth = image.getWidth(); + int sourceHeight = image.getHeight(); + AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth); + BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY); + Graphics2D g = rotatedImage.createGraphics(); + g.drawImage(image, transform, null); + g.dispose(); + int width = getWidth(); + return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width); + } + +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/HttpUtils.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/HttpUtils.java new file mode 100644 index 000000000..d9c0535aa --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/HttpUtils.java @@ -0,0 +1,137 @@ +package com.jsowell.wxpay.utils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class HttpUtils { + + private static final Logger log = LoggerFactory.getLogger(HttpUtils.class); + + private static final ObjectMapper JSON = new ObjectMapper(); + + /** + * get鏂规硶 + * + * @param url + * @return + */ + public static JsonNode doGet(String url) { + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + HttpGet httpget = new HttpGet(url); + httpget.addHeader("Content-Type", "application/json;charset=UTF-8"); + httpget.addHeader("Accept", "application/json"); + try { + String token = WechatPayUtils.getToken("GET", new URL(url), ""); + httpget.addHeader("Authorization", token); + CloseableHttpResponse httpResponse = httpClient.execute(httpget); + if (httpResponse.getStatusLine().getStatusCode() == 200) { + String jsonResult = EntityUtils.toString(httpResponse.getEntity()); + return JSON.readTree(jsonResult); + } else { + log.warn(EntityUtils.toString(httpResponse.getEntity())); + } + } catch (Exception e) { + log.error("HttpUtils.doGet error", e); + } finally { + try { + httpClient.close(); + } catch (Exception e) { + log.error("httpClient.close() error", e); + } + } + return null; + } + + /** + * 灏佽post + * + * @return + */ + public static Map doPost(String url, String body) { + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + httpPost.addHeader("Content-Type", "application/json;chartset=utf-8"); + httpPost.addHeader("Accept", "application/json"); + try { + String token = WechatPayUtils.getToken("POST", new URL(url), body); + httpPost.addHeader("Authorization", token); + if (body == null) { + throw new IllegalArgumentException("data鍙傛暟涓嶈兘涓虹┖"); + } + StringEntity stringEntity = new StringEntity(body, "utf-8"); + httpPost.setEntity(stringEntity); + + CloseableHttpResponse httpResponse = httpClient.execute(httpPost); + HttpEntity httpEntity = httpResponse.getEntity(); + + if (httpResponse.getStatusLine().getStatusCode() == 200) { + String jsonResult = EntityUtils.toString(httpEntity); + return JSON.readValue(jsonResult, HashMap.class); + } else { + log.warn("寰俊鏀粯閿欒淇℃伅" + EntityUtils.toString(httpEntity)); + } + } catch (Exception e) { + log.error("HttpUtils.doPost error", e); + } finally { + try { + httpClient.close(); + } catch (Exception e) { + log.error("httpClient.close() error", e); + } + } + return null; + } + + /** + * 灏佽post + * + * @return + */ + public static Map doPostWexin(String url, String body) { + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + httpPost.addHeader("Content-Type", "application/json;chartset=utf-8"); + httpPost.addHeader("Accept", "application/json"); + try { + String token = WechatPayUtils.getToken("POST", new URL(url), body); + httpPost.addHeader("Authorization", token); + if (body == null) { + throw new IllegalArgumentException("data鍙傛暟涓嶈兘涓虹┖"); + } + StringEntity stringEntity = new StringEntity(body, "utf-8"); + httpPost.setEntity(stringEntity); + CloseableHttpResponse httpResponse = httpClient.execute(httpPost); + HttpEntity httpEntity = httpResponse.getEntity(); + if (httpResponse.getStatusLine().getStatusCode() == 200) { + String jsonResult = EntityUtils.toString(httpEntity); + return JSON.readValue(jsonResult, HashMap.class); + } else { + log.error("寰俊鏀粯閿欒淇℃伅:{}", EntityUtils.toString(httpEntity)); + } + } catch (Exception e) { + log.error("HttpUtils.doPostWexin error", e); + } finally { + try { + httpClient.close(); + } catch (Exception e) { + log.error("httpClient.close() error", e); + } + } + return null; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/QRCodeUtil.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/QRCodeUtil.java new file mode 100644 index 000000000..3a63095ab --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/QRCodeUtil.java @@ -0,0 +1,147 @@ +package com.jsowell.wxpay.utils; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.BinaryBitmap; +import com.google.zxing.DecodeHintType; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatReader; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.Result; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.common.HybridBinarizer; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.geom.RoundRectangle2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.OutputStream; +import java.util.Hashtable; + +public class QRCodeUtil { + private static final String CHARSET = "utf-8"; + private static final String FORMAT_NAME = "JPG"; + // 浜岀淮鐮佸昂瀵 + private static final int QRCODE_SIZE = 300; + // LOGO瀹藉害 + private static final int WIDTH = 90; + // LOGO楂樺害 + private static final int HEIGHT = 90; + + private static BufferedImage createImage(String content, String imgPath, boolean needCompress) throws Exception { + Hashtable hints = new Hashtable(); + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + hints.put(EncodeHintType.CHARACTER_SET, CHARSET); + hints.put(EncodeHintType.MARGIN, 1); + BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, + hints); + int width = bitMatrix.getWidth(); + int height = bitMatrix.getHeight(); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); + } + } + if (imgPath == null || "".equals(imgPath)) { + return image; + } + // 鎻掑叆鍥剧墖 + QRCodeUtil.insertImage(image, imgPath, needCompress); + return image; + } + + private static void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception { + File file = new File(imgPath); + if (!file.exists()) { + System.err.println("" + imgPath + " 璇ユ枃浠朵笉瀛樺湪锛"); + return; + } + Image src = ImageIO.read(new File(imgPath)); + int width = src.getWidth(null); + int height = src.getHeight(null); + if (needCompress) { // 鍘嬬缉LOGO + if (width > WIDTH) { + width = WIDTH; + } + if (height > HEIGHT) { + height = HEIGHT; + } + Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); + BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics g = tag.getGraphics(); + g.drawImage(image, 0, 0, null); // 缁樺埗缂╁皬鍚庣殑鍥 + g.dispose(); + src = image; + } + // 鎻掑叆LOGO + Graphics2D graph = source.createGraphics(); + int x = (QRCODE_SIZE - width) / 2; + int y = (QRCODE_SIZE - height) / 2; + graph.drawImage(src, x, y, width, height, null); + Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); + graph.setStroke(new BasicStroke(3f)); + graph.draw(shape); + graph.dispose(); + } + + public static void encode(String content, String imgPath, String destPath, boolean needCompress) throws Exception { + BufferedImage image = QRCodeUtil.createImage(content, imgPath, needCompress); + mkdirs(destPath); + ImageIO.write(image, FORMAT_NAME, new File(destPath)); + } + + public static BufferedImage encode(String content, String imgPath, boolean needCompress) throws Exception { + BufferedImage image = QRCodeUtil.createImage(content, imgPath, needCompress); + return image; + } + + public static void mkdirs(String destPath) { + File file = new File(destPath); + // 褰撴枃浠跺す涓嶅瓨鍦ㄦ椂锛宮kdirs浼氳嚜鍔ㄥ垱寤哄灞傜洰褰曪紝鍖哄埆浜巑kdir锛(mkdir濡傛灉鐖剁洰褰曚笉瀛樺湪鍒欎細鎶涘嚭寮傚父) + if (!file.exists() && !file.isDirectory()) { + file.mkdirs(); + } + } + + public static void encode(String content, String imgPath, String destPath) throws Exception { + QRCodeUtil.encode(content, imgPath, destPath, false); + } + + + public static void encode(String content, String destPath) throws Exception { + QRCodeUtil.encode(content, null, destPath, false); + } + + public static void encode(String content, String imgPath, OutputStream output, boolean needCompress) + throws Exception { + BufferedImage image = QRCodeUtil.createImage(content, imgPath, needCompress); + ImageIO.write(image, FORMAT_NAME, output); + } + + public static void encode(String content, OutputStream output) throws Exception { + QRCodeUtil.encode(content, null, output, false); + } + + public static String decode(File file) throws Exception { + BufferedImage image; + image = ImageIO.read(file); + if (image == null) { + return null; + } + BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image); + BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); + Result result; + Hashtable hints = new Hashtable(); + hints.put(DecodeHintType.CHARACTER_SET, CHARSET); + result = new MultiFormatReader().decode(bitmap, hints); + String resultStr = result.getText(); + return resultStr; + } + + public static String decode(String path) throws Exception { + return QRCodeUtil.decode(new File(path)); + } + +} \ No newline at end of file diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/WechatPayUtils.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/WechatPayUtils.java new file mode 100644 index 000000000..d6fb71c6e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/utils/WechatPayUtils.java @@ -0,0 +1,243 @@ +package com.jsowell.wxpay.utils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jsowell.wxpay.common.WeChatPayParameter; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.InvalidKeyException; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.Signature; +import java.security.SignatureException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + + +/** + * 鍙傝冨畼缃 https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_0.shtml + */ +public class WechatPayUtils { + /** + * 鑾峰彇绉侀挜銆 + * + * @param filename 绉侀挜鏂囦欢璺緞 (required) + * @return 绉侀挜瀵硅薄 + */ + public static PrivateKey getPrivateKey(String filename) throws IOException { + // System.out.println("filename:" + filename); + String content = new String(Files.readAllBytes(Paths.get(filename)), "utf-8"); + try { + String privateKey = content.replace("-----BEGIN PRIVATE KEY-----", "") + .replace("-----END PRIVATE KEY-----", "") + .replaceAll("\\s+", ""); + + KeyFactory kf = KeyFactory.getInstance("RSA"); + return kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey))); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("褰撳墠Java鐜涓嶆敮鎸丷SA", e); + } catch (InvalidKeySpecException e) { + throw new RuntimeException("鏃犳晥鐨勫瘑閽ユ牸寮"); + } + } + + /** + * 鐢熸垚token 涔熷氨鏄敓鎴愮鍚 + * + * @param method + * @param url + * @param body + * @return + * @throws Exception + */ + public static String getToken(String method, URL url, String body) throws Exception { + String nonceStr = getNonceStr(); + long timestamp = System.currentTimeMillis() / 1000; + String message = buildMessage(method, url, timestamp, nonceStr, body); + String signature = sign(message.getBytes("utf-8")); + + return "WECHATPAY2-SHA256-RSA2048 " + "mchid=\"" + WeChatPayParameter.mchId + "\"," + + "nonce_str=\"" + nonceStr + "\"," + + "timestamp=\"" + timestamp + "\"," + + "serial_no=\"" + WeChatPayParameter.mchSerialNo + "\"," + + "signature=\"" + signature + "\""; + } + + /** + * 鐢熸垚token + * + * @param method + * @param url + * @param body + * @return + * @throws Exception + */ + public static Map getTokenWeixin(String method, URL url, String body, String prepay_id) throws Exception { + String nonceStr = getNonceStr(); + long timestamp = System.currentTimeMillis() / 1000; + String message = buildMessage(method, url, timestamp, nonceStr, body); + String signature = sign(message.getBytes("utf-8")); + + Map map = new HashMap<>(); + map.put("timeStamp", String.valueOf(timestamp)); + map.put("nonceStr", nonceStr); + map.put("package", "prepay_id=" + prepay_id); + map.put("signType", "RSA"); + map.put("paySign", signature); + + return map; + } + + + /** + * 鐢熸垚绛惧悕 + * + * @param message + * @return + * @throws Exception + */ + public static String sign(byte[] message) throws Exception { + Signature sign = Signature.getInstance("SHA256withRSA"); + sign.initSign(WeChatPayParameter.privateKey); + sign.update(message); + return Base64.getEncoder().encodeToString(sign.sign()); + } + + /** + * 鐢熸垚绛惧悕涓 + * + * @param method + * @param url + * @param timestamp + * @param nonceStr + * @param body + * @return + */ + public static String buildMessage(String method, URL url, long timestamp, String nonceStr, String body) { + String canonicalUrl = url.getPath(); + if (url.getQuery() != null) { + canonicalUrl += "?" + url.getQuery(); + } + return method + "\n" + + canonicalUrl + "\n" + + timestamp + "\n" + + nonceStr + "\n" + + body + "\n"; + } + + /** + * 鐢熸垚闅忔満鏁 + * + * @return + */ + public static String getNonceStr() { + return UUID.randomUUID().toString() + .replaceAll("-", "") + .substring(0, 32); + } + + /** + * 鑾峰彇骞冲彴璇佷功 + * + * @return + */ + public static Map refreshCertificate() throws Exception { + Map certificateMap = new HashMap(); + // 1: 鎵цget璇锋眰 + JsonNode jsonNode = HttpUtils.doGet(WeChatPayParameter.certificatesUrl); + // 2: 鑾峰彇骞冲彴楠岃瘉鐨勭浉鍏冲弬鏁颁俊鎭 + JsonNode data = jsonNode.get("data"); + if (data != null) { + for (int i = 0; i < data.size(); i++) { + JsonNode encrypt_certificate = data.get(i).get("encrypt_certificate"); + //瀵瑰叧閿俊鎭繘琛岃В瀵 + AesUtil aesUtil = new AesUtil(WeChatPayParameter.v3Key.getBytes()); + String associated_data = encrypt_certificate.get("associated_data").toString().replaceAll("\"", ""); + String nonce = encrypt_certificate.get("nonce").toString().replaceAll("\"", ""); + String ciphertext = encrypt_certificate.get("ciphertext").toString().replaceAll("\"", ""); + //璇佷功鍐呭 + String certStr = aesUtil.decryptToString(associated_data.getBytes(), nonce.getBytes(), ciphertext); + //璇佷功鍐呭杞垚璇佷功瀵硅薄 + CertificateFactory cf = CertificateFactory.getInstance("X509"); + X509Certificate x509Cert = (X509Certificate) cf.generateCertificate( + new ByteArrayInputStream(certStr.getBytes("utf-8")) + ); + String serial_no = data.get(i).get("serial_no").toString().replaceAll("\"", ""); + certificateMap.put(serial_no, x509Cert); + } + } + return certificateMap; + } + + /** + * 楠岃瘉绛惧悕 + * + * @param certificate + * @param message + * @param signature + * @return + */ + public static boolean verify(X509Certificate certificate, byte[] message, String signature) { + try { + Signature sign = Signature.getInstance("SHA256withRSA"); + sign.initVerify(certificate); + sign.update(message); + return sign.verify(Base64.getDecoder().decode(signature)); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("褰撳墠Java鐜涓嶆敮鎸丼HA256withRSA", e); + } catch (SignatureException e) { + throw new RuntimeException("绛惧悕楠岃瘉杩囩▼鍙戠敓浜嗛敊璇", e); + } catch (InvalidKeyException e) { + throw new RuntimeException("鏃犳晥鐨勮瘉涔", e); + } + } + + /** + * 鍙傝冪綉绔 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_4.shtml + * + * @param appId + * @param prepay_id + * @return + * @throws IOException + * @throws SignatureException + * @throws NoSuchAlgorithmException + * @throws InvalidKeyException + */ + public static HashMap getTokenWeixin(String appId, String prepay_id) throws Exception { + // 鑾峰彇闅忔満瀛楃涓 + String nonceStr = getNonceStr(); + // 鑾峰彇寰俊灏忕▼搴忔敮浠榩ackage + String packagestr = "prepay_id=" + prepay_id; + long timestamp = System.currentTimeMillis() / 1000; + //绛惧悕锛屼娇鐢ㄥ瓧娈礱ppId銆乼imeStamp銆乶onceStr銆乸ackage璁$畻寰楀嚭鐨勭鍚嶅 + String message = buildMessageTwo(appId, timestamp, nonceStr, packagestr); + //鑾峰彇瀵瑰簲鐨勭鍚 + String signature = sign(message.getBytes("utf-8")); + // 缁勮杩斿洖 + HashMap map = new HashMap<>(); + map.put("timeStamp", String.valueOf(timestamp)); + map.put("nonceStr", nonceStr); + map.put("package", packagestr); + map.put("signType", "RSA"); + map.put("paySign", signature); + return map; + } + + private static String buildMessageTwo(String appId, long timestamp, String nonceStr, String packag) { + return appId + "\n" + + timestamp + "\n" + + nonceStr + "\n" + + packag + "\n"; + } + +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/vo/R.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/vo/R.java new file mode 100644 index 000000000..69dc0f45c --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/vo/R.java @@ -0,0 +1,85 @@ +package com.jsowell.wxpay.vo; + +import lombok.Data; +import lombok.ToString; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName BaseController + * @Author 锛歺uke + * @Date 锛2021/1/17 13:01 + * @Description锛氶氱敤鏁版嵁杩斿洖鏍煎紡 + * @Version: 1.0 + */ +@Data +@ToString +public class R implements Serializable { + + private Boolean success; + + private Integer code; + + private String message; + + private Map data = new HashMap(); + + + private R() { + } + + public static R ok() { + R r = new R(); + r.setSuccess(ResultCodeEnum.SUCCESS.getSuccess()); + r.setCode(ResultCodeEnum.SUCCESS.getCode()); + r.setMessage(ResultCodeEnum.SUCCESS.getMessage()); + return r; + } + + public static R error() { + R r = new R(); + r.setSuccess(ResultCodeEnum.UNKNOWN_REASON.getSuccess()); + r.setCode(ResultCodeEnum.UNKNOWN_REASON.getCode()); + r.setMessage(ResultCodeEnum.UNKNOWN_REASON.getMessage()); + return r; + } + + public static R setResult(ResultCodeEnum resultCodeEnum) { + R r = new R(); + r.setSuccess(resultCodeEnum.getSuccess()); + r.setCode(resultCodeEnum.getCode()); + r.setMessage(resultCodeEnum.getMessage()); + return r; + } + + public R success(Boolean success) { + this.setSuccess(success); + return this; + } + + public R message(String message) { + this.setMessage(message); + return this; + } + + public R code(Integer code) { + this.setCode(code); + return this; + } + + public R data(String key, Object value) { + this.data.put(key, value); + return this; + } + + public R data(Map map) { + this.setData(map); + return this; + } + + public Map toMap(){ + return this.data; + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/wxpay/vo/ResultCodeEnum.java b/jsowell-pile/src/main/java/com/jsowell/wxpay/vo/ResultCodeEnum.java new file mode 100644 index 000000000..e26cef670 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/wxpay/vo/ResultCodeEnum.java @@ -0,0 +1,42 @@ +package com.jsowell.wxpay.vo; + +import lombok.Getter; + +@Getter +public enum ResultCodeEnum { + + SUCCESS(true, 20000,"鎴愬姛"), + UNKNOWN_REASON(false, 20001, "鏈煡閿欒"), + + LOGIN_PHONE_ERRROR(false, 20002, "鎵嬫満鍙风爜涓嶈兘涓虹┖"), + ACCOUNT_PHONE_ERRROR(false, 20002, "璐﹀彿淇℃伅涓嶈兘涓虹┖"), + LOGIN_PHONE_PATTARN_ERRROR(false, 20003, "鎵嬫満鍙风爜鏍煎紡涓嶆纭"), + VALIDATION_CODE_ERROR(false, 20004, "楠岃瘉鐮佷笉姝g‘"), + LOGIN_CODE_ERROR(false, 20005, "鐭俊楠岃瘉鐮佷笉鑳戒负绌"), + LOGIN_CAPATA_ERROR(false, 20006, "鍥惧舰楠岃瘉鐮佷笉鑳戒负绌"), + LOGIN_CODE_FAIL_ERROR(false, 20007, "鐭俊楠岃瘉鐮佸け鏁堬紝璇烽噸鏂板彂閫"), + LOGIN_CODE_INPUT_ERROR(false, 20008, "杈撳叆鐨勭煭淇$爜鏈夎"), + PHONE_ERROR_MSG(false, 20009, "璇ユ墜鏈哄彿鏈粦瀹氳处鎴"), + USER_FORBIDDEN(false, 20010, "璇ョ敤鎴峰凡琚鐢紝璇疯仈绯诲钩鍙板鏈"), + LOGIN_PWD_ERROR(false, 200011, "瀵嗙爜涓嶅厑璁镐负绌"), + LOGIN_PWD_INPUT_ERROR(false, 200012, "瀵嗙爜杈撳叆鏈夎"), + LOGIN_PWD_ACCOUNT_INPUT_ERROR(false, 200012, "杈撳叆鐨勮处鍙锋垨鑰呭瘑鐮佹湁璇"), + LOGIN_PWD_NO_INPUT_ERROR(false, 200013, "妫娴嬪埌娌℃湁瀹屽杽瀵嗙爜淇℃伅"), + + + BAD_SQL_GRAMMAR(false, 21001, "sql璇硶閿欒"), + JSON_PARSE_ERROR(false, 21002, "json瑙f瀽寮傚父"), + PARAM_ERROR(false, 21003, "鍙傛暟涓嶆纭"), + USER_PWD_ERROR(false, 21003, "灏氭湭鎵惧埌瀵瑰簲鐨勭敤鎴蜂俊鎭"); + + + private Boolean success; + private Integer code; + private String message; + + private ResultCodeEnum(Boolean success, Integer code, String message) { + this.success = success; + this.code = code; + this.message = message; + } +} \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/mapper/pile/MemberTransactionRecordMapper.xml b/jsowell-pile/src/main/resources/mapper/mapper/pile/MemberTransactionRecordMapper.xml new file mode 100644 index 000000000..89fe4cf1d --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/mapper/pile/MemberTransactionRecordMapper.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + id, order_code, scenario_type, member_id, action_type, pay_mode, amount, out_trade_no, + transaction_id, out_refund_no, refund_id, create_time + + + + + insert into member_transaction_record + + + id, + + + order_code, + + + scenario_type, + + + member_id, + + + action_type, + + + pay_mode, + + + amount, + + + out_trade_no, + + + transaction_id, + + + out_refund_no, + + + refund_id, + + + create_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{orderCode,jdbcType=VARCHAR}, + + + #{scenarioType,jdbcType=VARCHAR}, + + + #{memberId,jdbcType=VARCHAR}, + + + #{actionType,jdbcType=VARCHAR}, + + + #{payMode,jdbcType=VARCHAR}, + + + #{amount,jdbcType=VARCHAR}, + + + #{outTradeNo,jdbcType=VARCHAR}, + + + #{transactionId,jdbcType=VARCHAR}, + + + #{outRefundNo,jdbcType=VARCHAR}, + + + #{refundId,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/MemberBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/MemberBasicInfoMapper.xml new file mode 100644 index 000000000..61bc083d6 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/MemberBasicInfoMapper.xml @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + + + + + + + select + + from member_basic_info + + + + + id, member_id, open_id, nick_name,logic_card, physics_card, status, avatar_url, mobile_number, merchant_id, remark, + create_time, create_by, update_time, update_by, del_flag + + + + + + + + insert into member_basic_info + + member_id, + open_id, + nick_name, + logic_card, + physics_card, + status, + avatar_url, + mobile_number, + merchant_id, + remark, + create_time, + create_by, + update_time, + update_by, + + + #{memberId}, + #{openId}, + #{nickName}, + #{logicCard}, + #{physicsCard}, + #{status}, + #{avatarUrl}, + #{mobileNumber}, + #{merchantId}, + #{remark}, + #{createTime}, + #{createBy}, + #{updateTime}, + #{updateBy}, + + + + + update member_basic_info + + member_id = #{memberId}, + open_id = #{openId}, + nick_name = #{nickName}, + logic_card = #{logicCard}, + physics_card = #{physicsCard}, + status = #{status}, + avatar_url = #{avatarUrl}, + mobile_number = #{mobileNumber}, + merchant_id = #{merchantId}, + remark = #{remark}, + create_time = #{createTime}, + create_by = #{createBy}, + update_time = #{updateTime}, + update_by = #{updateBy}, + del_flag = #{delFlag}, + + where id = #{id} + + + + delete from member_basic_info where id in + + #{id} + + + + + + + + + + + update member_wallet_info + + version = version + 1, + principal_balance = #{newPrincipalBalance}, + gift_balance = #{newGiftBalance}, + + where member_id = #{memberId,jdbcType=VARCHAR} + and version = #{version,jdbcType=INTEGER} + + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/MemberWalletInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/MemberWalletInfoMapper.xml new file mode 100644 index 000000000..3e2572c73 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/MemberWalletInfoMapper.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + id, member_id, principal_balance, gift_balance, version, create_by, create_time, + update_by, update_time, del_flag + + + + + delete from member_wallet_info + where id = #{id,jdbcType=INTEGER} + + + + insert into member_wallet_info (id, member_id, principal_balance, + gift_balance, version, create_by, + create_time, update_by, update_time, + del_flag) + values (#{id,jdbcType=INTEGER}, #{memberId,jdbcType=VARCHAR}, #{principalBalance,jdbcType=DECIMAL}, + #{giftBalance,jdbcType=DECIMAL}, #{version,jdbcType=INTEGER}, #{createBy,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, + #{delFlag,jdbcType=CHAR}) + + + + insert into member_wallet_info + + + id, + + + member_id, + + + principal_balance, + + + gift_balance, + + + version, + + + create_by, + + + create_time, + + + update_by, + + + update_time, + + + del_flag, + + + + + #{id,jdbcType=INTEGER}, + + + #{memberId,jdbcType=VARCHAR}, + + + #{principalBalance,jdbcType=DECIMAL}, + + + #{giftBalance,jdbcType=DECIMAL}, + + + #{version,jdbcType=INTEGER}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateBy,jdbcType=VARCHAR}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{delFlag,jdbcType=CHAR}, + + + + + + update member_wallet_info + + + member_id = #{memberId,jdbcType=VARCHAR}, + + + principal_balance = #{principalBalance,jdbcType=DECIMAL}, + + + gift_balance = #{giftBalance,jdbcType=DECIMAL}, + + + version = #{version,jdbcType=INTEGER}, + + + create_by = #{createBy,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + del_flag = #{delFlag,jdbcType=CHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + + update member_wallet_info + set member_id = #{memberId,jdbcType=VARCHAR}, + principal_balance = #{principalBalance,jdbcType=DECIMAL}, + gift_balance = #{giftBalance,jdbcType=DECIMAL}, + version = #{version,jdbcType=INTEGER}, + create_by = #{createBy,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_by = #{updateBy,jdbcType=VARCHAR}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + del_flag = #{delFlag,jdbcType=CHAR} + where id = #{id,jdbcType=INTEGER} + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/MemberWalletLogMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/MemberWalletLogMapper.xml new file mode 100644 index 000000000..598c3df0a --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/MemberWalletLogMapper.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + id, member_id, `type`, sub_type, amount, category, create_by, create_time + + + + insert into member_wallet_log (member_id, `type`, + sub_type, amount, category, related_order_code, create_by) + values + + ( + #{item.memberId,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR}, #{item.subType,jdbcType=VARCHAR}, + #{item.amount,jdbcType=DECIMAL}, #{item.category,jdbcType=CHAR}, #{item.relatedOrderCode,jdbcType=VARCHAR}, + #{item.createBy,jdbcType=VARCHAR} + ) + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/OrderAbnormalRecordMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/OrderAbnormalRecordMapper.xml new file mode 100644 index 000000000..0d1315f36 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/OrderAbnormalRecordMapper.xml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id, order_code, pile_sn, connector_code, start_time, end_time, sharp_price, sharp_used_electricity, sharp_plan_loss_electricity, sharp_amount, peak_price, peak_used_electricity, peak_plan_loss_electricity, peak_amount, flat_price, flat_used_electricity, flat_plan_loss_electricity, flat_amount, valley_price, valley_used_electricity, valley_plan_loss_electricity, valley_amount, ammeter_total_start, ammeter_total_end, total_electricity, plan_loss_total_electricity, consumption_amount, vin_code, transaction_identifier, transaction_time, stop_reason_msg, logic_card, create_time from order_abnormal_record + + + + + + + + insert into order_abnormal_record + + order_code, + pile_sn, + connector_code, + start_time, + end_time, + sharp_price, + sharp_used_electricity, + sharp_plan_loss_electricity, + sharp_amount, + peak_price, + peak_used_electricity, + peak_plan_loss_electricity, + peak_amount, + flat_price, + flat_used_electricity, + flat_plan_loss_electricity, + flat_amount, + valley_price, + valley_used_electricity, + valley_plan_loss_electricity, + valley_amount, + ammeter_total_start, + ammeter_total_end, + total_electricity, + plan_loss_total_electricity, + consumption_amount, + vin_code, + transaction_identifier, + transaction_time, + stop_reason_msg, + logic_card, + create_time, + + + #{orderCode}, + #{pileSn}, + #{connectorCode}, + #{startTime}, + #{endTime}, + #{sharpPrice}, + #{sharpUsedElectricity}, + #{sharpPlanLossElectricity}, + #{sharpAmount}, + #{peakPrice}, + #{peakUsedElectricity}, + #{peakPlanLossElectricity}, + #{peakAmount}, + #{flatPrice}, + #{flatUsedElectricity}, + #{flatPlanLossElectricity}, + #{flatAmount}, + #{valleyPrice}, + #{valleyUsedElectricity}, + #{valleyPlanLossElectricity}, + #{valleyAmount}, + #{ammeterTotalStart}, + #{ammeterTotalEnd}, + #{totalElectricity}, + #{planLossTotalElectricity}, + #{consumptionAmount}, + #{vinCode}, + #{transactionIdentifier}, + #{transactionTime}, + #{stopReasonMsg}, + #{logicCard}, + #{createTime}, + + + + + update order_abnormal_record + + order_code = #{orderCode}, + pile_sn = #{pileSn}, + connector_code = #{connectorCode}, + start_time = #{startTime}, + end_time = #{endTime}, + sharp_price = #{sharpPrice}, + sharp_used_electricity = #{sharpUsedElectricity}, + sharp_plan_loss_electricity = #{sharpPlanLossElectricity}, + sharp_amount = #{sharpAmount}, + peak_price = #{peakPrice}, + peak_used_electricity = #{peakUsedElectricity}, + peak_plan_loss_electricity = #{peakPlanLossElectricity}, + peak_amount = #{peakAmount}, + flat_price = #{flatPrice}, + flat_used_electricity = #{flatUsedElectricity}, + flat_plan_loss_electricity = #{flatPlanLossElectricity}, + flat_amount = #{flatAmount}, + valley_price = #{valleyPrice}, + valley_used_electricity = #{valleyUsedElectricity}, + valley_plan_loss_electricity = #{valleyPlanLossElectricity}, + valley_amount = #{valleyAmount}, + ammeter_total_start = #{ammeterTotalStart}, + ammeter_total_end = #{ammeterTotalEnd}, + total_electricity = #{totalElectricity}, + plan_loss_total_electricity = #{planLossTotalElectricity}, + consumption_amount = #{consumptionAmount}, + vin_code = #{vinCode}, + transaction_identifier = #{transactionIdentifier}, + transaction_time = #{transactionTime}, + stop_reason_msg = #{stopReasonMsg}, + logic_card = #{logicCard}, + create_time = #{createTime}, + + where id = #{id} + + + + delete from order_abnormal_record where id = #{id} + + + + delete from order_abnormal_record where id in + + #{id} + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml new file mode 100644 index 000000000..a080e84ab --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml @@ -0,0 +1,775 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select + + from order_basic_info + + + + id, + order_code, + order_status, + member_id, + station_id, + pile_sn, + connector_code, + pile_connector_code, + start_mode, + pay_mode, + pay_status, + pay_amount, + pay_time, + order_amount, + charge_start_time, + charge_end_time, + start_soc, + end_soc, + reason, + settlement_time, + refund_amount, + create_by, + create_time, + update_by, + update_time, + del_flag + + + + id, + order_code, + total_used_electricity, + total_order_amount, + total_electricity_amount, + total_service_amount, + sharp_used_electricity, + sharp_electricity_price, + sharp_service_price, + peak_used_electricity, + peak_electricity_price, + peak_service_price, + flat_used_electricity, + flat_electricity_price, + flat_service_price, + valley_used_electricity, + valley_electricity_price, + valley_service_price, + create_by, + create_time, + update_by, + update_time, + del_flag + + + + + + + + insert into order_basic_info + + + order_code, + + + order_status, + + + member_id, + + + station_id, + + + pile_sn, + + + connector_code, + + + pile_connector_code, + + + start_mode, + + + pay_mode, + + + pay_status, + + + pay_amount, + + + pay_time, + + + order_amount, + + + charge_start_time, + + + charge_end_time, + + + start_soc, + + + end_soc, + + + reason, + + + settlement_time, + + + refund_amount, + + + create_by, + + + create_time, + + + update_by, + + + update_time, + + + del_flag, + + + + + #{orderCode}, + + + #{orderStatus}, + + + #{memberId}, + + + #{stationId}, + + + #{pileSn,jdbcType=VARCHAR}, + + + #{connectorCode}, + + + #{pileConnectorCode}, + + + #{startMode}, + + + #{payMode}, + + + #{payStatus}, + + + #{payAmount}, + + + #{payTime}, + + + #{orderAmount}, + + + #{chargeStartTime}, + + + #{chargeEndTime}, + + + #{startSOC}, + + + #{endSOC}, + + + #{reason}, + + + #{settlementTime}, + + + #{refundAmount}, + + + #{createBy}, + + + #{createTime}, + + + #{updateBy}, + + + #{updateTime}, + + + #{delFlag}, + + + + + + update order_basic_info + + + order_code = #{orderCode}, + + + order_status = #{orderStatus}, + + + member_id = #{memberId}, + + + station_id = #{stationId}, + + + pile_sn = #{pileSn}, + + + connector_code = #{connectorCode}, + + + pile_connector_code = #{pileConnectorCode}, + + + start_mode = #{startMode}, + + + pay_mode = #{payMode}, + + + pay_status = #{payStatus}, + + + pay_amount = #{payAmount}, + + + pay_time = #{payTime}, + + + order_amount = #{orderAmount}, + + + charge_start_time = #{chargeStartTime}, + + + charge_end_time = #{chargeEndTime}, + + + start_soc = #{startSOC}, + + + end_soc = #{endSOC}, + + + reason = #{reason}, + + + settlement_time = #{settlementTime}, + + + refund_amount = #{refundAmount}, + + + create_by = #{createBy}, + + + create_time = #{createTime}, + + + update_by = #{updateBy}, + + + update_time = #{updateTime}, + + + del_flag = #{delFlag}, + + + where id = #{id} + + + + delete + from order_basic_info where id in + + #{id} + + + + + delete + from order_detail where order_code in + + #{orderCode} + + + + + delete + from order_detail + where order_code = #{orderCode} + + + + insert into order_detail(id, order_code, total_used_electricity, total_order_amount, total_electricity_amount, + total_service_amount, sharp_used_electricity, sharp_electricity_price, + sharp_service_price, + peak_used_electricity, peak_electricity_price, peak_service_price, + flat_used_electricity, flat_electricity_price, + flat_service_price, valley_used_electricity, valley_electricity_price, + valley_service_price, create_by, + update_by) values + + (#{item.id}, #{item.orderCode}, #{item.totalUsedElectricity}, #{item.totalOrderAmount}, + #{item.totalElectricityAmount}, #{item.totalServiceAmount}, #{item.sharpUsedElectricity}, + #{item.sharpElectricityPrice}, #{item.sharpServicePrice}, #{item.peakUsedElectricity}, + #{item.peakElectricityPrice}, #{item.peakServicePrice}, #{item.flatUsedElectricity}, + #{item.flatElectricityPrice}, #{item.flatServicePrice}, #{item.valleyUsedElectricity}, + #{item.valleyElectricityPrice}, #{item.valleyServicePrice}, #{item.createBy}, #{item.updateBy}) + + + + + update order_detail + + + order_code = #{orderCode}, + + + total_used_electricity = #{totalUsedElectricity}, + + + total_order_amount = #{totalOrderAmount}, + + + total_electricity_amount = #{totalElectricityAmount}, + + + total_service_amount = #{totalServiceAmount}, + + + sharp_used_electricity = #{sharpUsedElectricity}, + + + sharp_electricity_price = #{sharpElectricityPrice}, + + + sharp_service_price = #{sharpServicePrice}, + + + peak_used_electricity = #{peakUsedElectricity}, + + + peak_electricity_price = #{peakElectricityPrice}, + + + peak_service_price = #{peakServicePrice}, + + + flat_used_electricity = #{flatUsedElectricity}, + + + flat_electricity_price = #{flatElectricityPrice}, + + + flat_service_price = #{flatServicePrice}, + + + valley_used_electricity = #{valleyUsedElectricity}, + + + valley_electricity_price = #{valleyElectricityPrice}, + + + valley_service_price = #{valleyServicePrice}, + + + create_by = #{createBy}, + + + create_time = #{createTime}, + + + update_by = #{updateBy}, + + + update_time = #{updateTime}, + + + del_flag = #{delFlag}, + + + where id = #{id} + + + + + + + + + + + + + update order_basic_info set order_status = #{orderStatus,jdbcType=VARCHAR} + where del_flag = '0' + and order_code = #{orderCode,jdbcType=VARCHAR} + + + + + + + + + + update order_basic_info set order_status = #{orderStatus,jdbcType=VARCHAR} + where del_flag = '0' + and id in + + #{orderId,jdbcType=VARCHAR} + + + + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/OrderPayRecordMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/OrderPayRecordMapper.xml new file mode 100644 index 000000000..340961104 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/OrderPayRecordMapper.xml @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + id, order_code, pay_mode, pay_amount, refund_amount, create_by, create_time, update_by, update_time, + del_flag + + + + + delete from order_pay_record + where id = #{id,jdbcType=INTEGER} + + + + insert into order_pay_record (order_code, pay_mode, pay_amount, refund_amount, + create_by, create_time, update_by, + update_time, del_flag) + values (#{orderCode,jdbcType=VARCHAR}, #{payMode,jdbcType=VARCHAR}, #{payAmount,jdbcType=DECIMAL}, #{refundAmount,jdbcType=DECIMAL}, + #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, + #{updateTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=CHAR}) + + + + insert into order_pay_record + + + order_code, + + + pay_mode, + + + pay_amount, + + + refund_amount, + + + create_by, + + + create_time, + + + update_by, + + + update_time, + + + del_flag, + + + + + #{orderCode,jdbcType=VARCHAR}, + + + #{payMode,jdbcType=VARCHAR}, + + + #{payAmount,jdbcType=DECIMAL}, + + + #{refundAmount,jdbcType=DECIMAL}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateBy,jdbcType=VARCHAR}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{delFlag,jdbcType=CHAR}, + + + + + + update order_pay_record + + + order_code = #{orderCode,jdbcType=VARCHAR}, + + + pay_mode = #{payMode,jdbcType=VARCHAR}, + + + pay_amount = #{payAmount,jdbcType=DECIMAL}, + + + refund_amount = #{refundAmount,jdbcType=DECIMAL}, + + + create_by = #{createBy,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + del_flag = #{delFlag,jdbcType=CHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + + update order_pay_record + set order_code = #{orderCode,jdbcType=VARCHAR}, + pay_mode = #{payMode,jdbcType=VARCHAR}, + pay_amount = #{payAmount,jdbcType=DECIMAL}, + refund_amount = #{refundAmount,jdbcType=DECIMAL}, + create_by = #{createBy,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_by = #{updateBy,jdbcType=VARCHAR}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + del_flag = #{delFlag,jdbcType=CHAR} + where id = #{id,jdbcType=INTEGER} + + + + insert into order_pay_record + (order_code, pay_mode, pay_amount, create_by) + values + + ( + #{item.orderCode,jdbcType=VARCHAR}, #{item.payMode,jdbcType=VARCHAR}, #{item.payAmount,jdbcType=DECIMAL}, + #{item.createBy,jdbcType=VARCHAR} + ) + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml new file mode 100644 index 000000000..97dbaa675 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml @@ -0,0 +1,345 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + id, sn, business_type, software_protocol, production_date, licence_id, model_id, sim_id, + merchant_id, station_id, fault_reason, create_by, create_time, update_by, update_time, del_flag, remark + + + + select + from pile_basic_info + + + + + + + + + + insert into pile_basic_info + + sn, + business_type, + software_protocol, + production_date, + licence_id, + model_id, + sim_id, + merchant_id, + station_id, + fault_reason, + create_by, + create_time, + update_by, + update_time, + del_flag, + remark, + + + #{sn}, + #{businessType}, + #{softwareProtocol}, + #{productionDate}, + #{licenceId}, + #{modelId}, + #{simId}, + #{merchantId}, + #{stationId}, + #{faultReason}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{delFlag}, + #{remark}, + + + + + update pile_basic_info + + sn = #{sn}, + business_type = #{businessType}, + software_protocol = #{softwareProtocol}, + production_date = #{productionDate}, + licence_id = #{licenceId}, + model_id = #{modelId}, + sim_id = #{simId}, + merchant_id = #{merchantId}, + station_id = #{stationId}, + fault_reason = #{faultReason}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + remark = #{remark}, + + where id = #{id} + + + + delete from pile_basic_info where id = #{id} + + + + delete from pile_basic_info where id in + + #{id} + + + + + + + insert into pile_basic_info + (sn, business_type, software_protocol, production_date, licence_id, model_id, sim_id, + merchant_id, station_id, fault_reason, create_by, update_by, del_flag, remark) + values + + ( + #{item.sn,jdbcType=VARCHAR}, + #{item.businessType,jdbcType=VARCHAR}, + #{item.softwareProtocol,jdbcType=VARCHAR}, + #{item.productionDate,jdbcType=TIMESTAMP}, + #{item.licenceId,jdbcType=BIGINT}, + #{item.modelId,jdbcType=BIGINT}, + #{item.simId,jdbcType=BIGINT}, + #{item.merchantId,jdbcType=BIGINT}, + #{item.stationId,jdbcType=BIGINT}, + #{item.faultReason,jdbcType=VARCHAR}, + #{item.createBy,jdbcType=VARCHAR}, + #{item.updateBy,jdbcType=VARCHAR}, + #{item.delFlag,jdbcType=VARCHAR}, + #{item.remark,jdbcType=VARCHAR} + ) + + + + + update pile_basic_info + + merchant_id = #{merchantId}, + station_id = #{stationId}, + model_id = #{modelId}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where id in + + #{pileId,jdbcType=BIGINT} + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileBillingTemplateMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileBillingTemplateMapper.xml new file mode 100644 index 000000000..5efe1f55d --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileBillingTemplateMapper.xml @@ -0,0 +1,433 @@ + + + + + + + + + + + + + + + + + + + + + id, template_code, name, remark, type, station_id, public_flag, + create_time, update_by, update_time, del_flag + + + + + + + + + + + + + + + + + + + id, template_code, time_type, electricity_price, service_price, apply_time, create_by, + create_time, update_by, update_time, del_flag + + + + + + + + + + + + + + + + + + + + select + + from pile_billing_template + + + + + + + + insert into pile_billing_template + + + template_code, + + + public_flag, + + + name, + + + remark, + + + type, + + + station_id, + + + create_by, + + + create_time, + + + update_by, + + + update_time, + + + del_flag, + + + + + #{templateCode}, + + + #{publicFlag}, + + + #{name}, + + + #{remark}, + + + #{type}, + + + #{stationId}, + + + #{createBy}, + + + #{createTime}, + + + #{updateBy}, + + + #{updateTime}, + + + #{delFlag}, + + + + + + update pile_billing_template + + + template_code = #{templateCode}, + + + public_flag = #{publicFlag}, + + + name = #{name}, + + + remark = #{remark}, + + + type = #{type}, + + + station_id = #{stationId}, + + + publish_time = #{publishTime}, + + + create_by = #{createBy}, + + + create_time = #{createTime}, + + + update_by = #{updateBy}, + + + update_time = #{updateTime}, + + + del_flag = #{delFlag}, + + + where id = #{id} + + + + delete + from pile_billing_template + where id = #{id} + + + + delete + from pile_billing_template where id in + + #{id} + + + + + delete + from pile_billing_detail + where template_code in + + #{templateCode} + + + + + delete + from pile_billing_detail + where template_code = #{templateCode} + + + + insert into pile_billing_detail + (id, template_code, time_type, electricity_price, service_price, apply_time, + create_by, update_by) + values + + (#{item.id}, #{item.templateCode}, #{item.timeType}, #{item.electricityPrice}, #{item.servicePrice}, + #{item.applyTime}, #{item.createBy}, #{item.updateBy}) + + + + + + + + + + + + + + + insert into pile_billing_relation + (pile_sn, billing_template_code, station_id) + values + + (#{item.pileSn}, #{item.billingTemplateCode}, #{item.stationId}) + + + + + delete + from pile_billing_relation + where pile_sn in + + #{pileSn,jdbcType=VARCHAR} + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileConnectorInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileConnectorInfoMapper.xml new file mode 100644 index 000000000..8144bc722 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileConnectorInfoMapper.xml @@ -0,0 +1,239 @@ + + + + + + + + + + + + + + + + + + + select id, name, pile_connector_code, status, pile_sn, create_by, create_time, update_by, update_time, del_flag from pile_connector_info + + + + + + + + insert into pile_connector_info + + name, + pile_connector_code, + status, + pile_sn, + create_by, + create_time, + update_by, + update_time, + del_flag, + + + #{name}, + #{pileConnectorCode}, + #{status}, + #{pileSn}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{delFlag}, + + + + + update pile_connector_info + + name = #{name}, + pile_connector_code = #{pileConnectorCode}, + status = #{status}, + pile_sn = #{pileSn}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + + where id = #{id} + + + + delete from pile_connector_info where id = #{id} + + + + delete from pile_connector_info where id in + + #{id} + + + + + delete from pile_connector_info where pile_sn in + + #{pileSn,jdbcType=VARCHAR} + + + + + + + insert into pile_connector_info + (name,pile_connector_code,status,pile_sn,create_by,update_by,del_flag) + values + + ( + #{item.name,jdbcType=VARCHAR}, + #{item.pileConnectorCode,jdbcType=VARCHAR}, + #{item.status,jdbcType=VARCHAR}, + #{item.pileSn,jdbcType=VARCHAR}, + #{item.createBy,jdbcType=VARCHAR}, + #{item.updateBy,jdbcType=VARCHAR}, + #{item.delFlag,jdbcType=VARCHAR} + ) + + + + + + + + + + + update pile_connector_info + set status = #{connectorStatus,jdbcType=VARCHAR} + where pile_connector_code = #{connectorCode,jdbcType=VARCHAR} + + + + update pile_connector_info + set status = #{connectorStatus,jdbcType=VARCHAR} + where pile_sn = #{pileSn,jdbcType=VARCHAR} + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileLicenceInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileLicenceInfoMapper.xml new file mode 100644 index 000000000..1daaf7d57 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileLicenceInfoMapper.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + select id, licence_name, merchant_id, status, expire_time, create_by, create_time, update_by, update_time, del_flag from pile_licence_info + + + + + + + + insert into pile_licence_info + + id, + licence_name, + merchant_id, + status, + expire_time, + create_by, + create_time, + update_by, + update_time, + del_flag, + + + #{id}, + #{licenceName}, + #{merchantId}, + #{status}, + #{expireTime}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{delFlag}, + + + + + update pile_licence_info + + licence_name = #{licenceName}, + merchant_id = #{merchantId}, + status = #{status}, + expire_time = #{expireTime}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + + where id = #{id} + + + + delete from pile_licence_info where id = #{id} + + + + delete from pile_licence_info where id in + + #{id} + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileMemberRelationMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileMemberRelationMapper.xml new file mode 100644 index 000000000..2fcffd640 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileMemberRelationMapper.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + select id, pile_sn, member_id, type, create_time from pile_member_relation + + + + id, pile_sn, member_id, type, create_time + + + + + + + + insert into pile_member_relation + + pile_sn, + member_id, + type, + + + #{pileSn}, + #{memberId}, + #{type}, + + + + + update pile_member_relation + + pile_sn = #{pileSn}, + member_id = #{memberId}, + type = #{type}, + + where id = #{id} + + + + delete from pile_member_relation where id = #{id} + + + + delete from pile_member_relation where id in + + #{id} + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileMerchantInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileMerchantInfoMapper.xml new file mode 100644 index 000000000..0063370cf --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileMerchantInfoMapper.xml @@ -0,0 +1,262 @@ + + + + + + + + + + + + + + + + + + + + + + + + id, + merchant_name, + address, + status, + organization_code, + manager_name, + manager_phone, + service_phone, + logo_url, + app_id, + dept_id, + create_by, + create_time, + update_by, + update_time, + del_flag + + + + select + + from pile_merchant_info t + + + + + + + + insert into pile_merchant_info + + + id, + + + merchant_name, + + + address, + + + status, + + + organization_code, + + + manager_name, + + + manager_phone, + + + service_phone, + + + logo_url, + + + app_id, + + + dept_id, + + + create_by, + + + create_time, + + + update_by, + + + update_time, + + + del_flag, + + + + + #{id}, + + + #{merchantName}, + + + #{address}, + + + #{status}, + + + #{organizationCode}, + + + #{managerName}, + + + #{managerPhone}, + + + #{servicePhone}, + + + #{logoUrl}, + + + #{appId}, + + + #{deptId}, + + + #{createBy}, + + + #{createTime}, + + + #{updateBy}, + + + #{updateTime}, + + + #{delFlag}, + + + + + + update pile_merchant_info + + + merchant_name = #{merchantName}, + + + address = #{address}, + + + status = #{status}, + + + organization_code = #{organizationCode}, + + + manager_name = #{managerName}, + + + manager_phone = #{managerPhone}, + + + service_phone = #{servicePhone}, + + + logo_url = #{logoUrl}, + + + app_id = #{appId}, + + + create_by = #{createBy}, + + + create_time = #{createTime}, + + + update_by = #{updateBy}, + + + update_time = #{updateTime}, + + + del_flag = #{delFlag}, + + + where id = #{id} + + + + delete + from pile_merchant_info + where id = #{id} + + + + delete + from pile_merchant_info where id in + + #{id} + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileModelInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileModelInfoMapper.xml new file mode 100644 index 000000000..03084b571 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileModelInfoMapper.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + select + + from pile_model_info + + + + id, model_name,rated_power, rated_current, rated_voltage, speed_type, charger_pile_type, connector_num, interface_standard, create_by, + create_time, update_by, update_time, del_flag + + + + + + + + insert into pile_model_info + + model_name, + rated_power, + rated_current, + rated_voltage, + speed_type, + charger_pile_type, + connector_num, + interface_standard, + create_by, + create_time, + update_by, + update_time, + del_flag, + + + #{modelName}, + #{ratedPower}, + #{ratedCurrent}, + #{ratedVoltage}, + #{speedType}, + #{chargerPileType}, + #{connectorNum}, + #{interfaceStandard}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{delFlag}, + + + + + update pile_model_info + + model_name = #{modelName}, + rated_power = #{ratedPower}, + rated_current = #{ratedCurrent}, + rated_voltage = #{ratedVoltage}, + speed_type = #{speedType}, + charger_pile_type = #{chargerPileType}, + connector_num = #{connectorNum}, + interface_standard = #{interfaceStandard}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + + where id = #{id} + + + + delete from pile_model_info where id = #{id} + + + + delete from pile_model_info where id in + + #{id} + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileMsgRecordMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileMsgRecordMapper.xml new file mode 100644 index 000000000..bf174de4b --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileMsgRecordMapper.xml @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + id, pile_sn, frame_type, connector_code, pile_connector_code, original_msg, json_msg, create_time + + + + + + insert into pile_msg_record + + + id, + + + pile_sn, + + + frame_type, + + + connector_code, + + + pile_connector_code, + + + original_msg, + + + json_msg, + + + create_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{pileSn,jdbcType=VARCHAR}, + + + #{frameType,jdbcType=VARCHAR}, + + + #{connectorCode,jdbcType=VARCHAR}, + + + #{pileConnectorCode,jdbcType=VARCHAR}, + + + #{originalMsg,jdbcType=VARCHAR}, + + + #{jsonMsg,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileSimInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileSimInfoMapper.xml new file mode 100644 index 000000000..8eb36457f --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileSimInfoMapper.xml @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + select id, name, iccid, status, sim_supplier, total_data, surplus_data, expire_time, operator, create_by, create_time, update_by, update_time, del_flag from pile_sim_info + + + + + + + + insert into pile_sim_info + + id, + name, + iccid, + status, + sim_supplier, + total_data, + surplus_data, + expire_time, + operator, + create_by, + create_time, + update_by, + update_time, + del_flag, + + + #{id}, + #{name}, + #{iccid}, + #{status}, + #{simSupplier}, + #{totalData}, + #{surplusData}, + #{expireTime}, + #{operator}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{delFlag}, + + + + + update pile_sim_info + + name = #{name}, + iccid = #{iccid}, + status = #{status}, + sim_supplier = #{simSupplier}, + total_data = #{totalData}, + surplus_data = #{surplusData}, + expire_time = #{expireTime}, + operator = #{operator}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + + where id = #{id} + + + + delete from pile_sim_info where id = #{id} + + + + delete from pile_sim_info where id in + + #{id} + + + + + id, name, iccid, status, sim_supplier, total_data, surplus_data, expire_time, operator, create_by, create_time, + update_by, del_flag + + + + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileStationInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileStationInfoMapper.xml new file mode 100644 index 000000000..4114bf55c --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/PileStationInfoMapper.xml @@ -0,0 +1,352 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id,merchant_id, station_name, dept_id, alone_apply, account_number, capacity, public_parking, parking_number, + country_code, area_code, address, station_tel, service_tel, station_type, station_status, station_admin_name, park_nums, + station_lng, station_lat, site_guide, construction, pictures, match_cars, park_info, park_owner, + park_manager, open_all_day, business_hours, park_free, payment, support_order, remark, public_flag, + open_flag,toilet_flag, store_flag, restaurant_flag, lounge_flag, canopy_flag, printer_flag, barrier_flag, + parking_lock_flag, create_by, create_time, update_by, update_time, del_flag + from pile_station_info + + + + + + + + insert into pile_station_info + + id, + merchant_id, + station_name, + dept_id, + alone_apply, + account_number, + capacity, + public_parking, + parking_number, + country_code, + area_code, + address, + station_tel, + service_tel, + station_type, + station_status, + station_admin_name, + park_nums, + station_lng, + station_lat, + site_guide, + construction, + pictures, + match_cars, + park_info, + park_owner, + park_manager, + open_all_day, + business_hours, + park_free, + payment, + support_order, + remark, + publicFlag, + openFlag, + toilet_flag, + store_flag, + restaurant_flag, + lounge_flag, + canopy_flag, + printer_flag, + barrier_flag, + parking_lock_flag, + create_by, + create_time, + update_by, + update_time, + del_flag, + + + #{id}, + #{merchantId}, + #{stationName}, + #{deptId}, + #{aloneApply}, + #{accountNumber}, + #{capacity}, + #{publicParking}, + #{parkingNumber}, + #{countryCode}, + #{areaCode}, + #{address}, + #{stationTel}, + #{serviceTel}, + #{stationType}, + #{stationStatus}, + #{stationAdminName}, + #{parkNums}, + #{stationLng}, + #{stationLat}, + #{siteGuide}, + #{construction}, + #{pictures}, + #{matchCars}, + #{parkInfo}, + #{parkOwner}, + #{parkManager}, + #{openAllDay}, + #{businessHours}, + #{parkFree}, + #{payment}, + #{supportOrder}, + #{remark}, + #{publicFlag}, + #{openFlag}, + #{toiletFlag}, + #{storeFlag}, + #{restaurantFlag}, + #{loungeFlag}, + #{canopyFlag}, + #{printerFlag}, + #{barrierFlag}, + #{parkingLockFlag}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{delFlag}, + + + + + update pile_station_info + + merchant_id = #{merchantId}, + station_name = #{stationName}, + dept_id = #{deptId}, + alone_apply = #{aloneApply}, + account_number = #{accountNumber}, + capacity = #{capacity}, + public_parking = #{publicParking}, + parking_number = #{parkingNumber}, + country_code = #{countryCode}, + area_code = #{areaCode}, + address = #{address}, + station_tel = #{stationTel}, + service_tel = #{serviceTel}, + station_type = #{stationType}, + station_status = #{stationStatus}, + station_admin_name = #{stationAdminName}, + park_nums = #{parkNums}, + station_lng = #{stationLng}, + station_lat = #{stationLat}, + site_guide = #{siteGuide}, + construction = #{construction}, + pictures = #{pictures}, + match_cars = #{matchCars}, + park_info = #{parkInfo}, + park_owner = #{parkOwner}, + park_manager = #{parkManager}, + open_all_day = #{openAllDay}, + business_hours = #{businessHours}, + park_free = #{parkFree}, + payment = #{payment}, + support_order = #{supportOrder}, + remark = #{remark}, + public_flag = #{publicFlag}, + open_flag = #{openFlag}, + toilet_flag = #{toiletFlag}, + store_flag = #{storeFlag}, + restaurant_flag = #{restaurantFlag}, + lounge_flag = #{loungeFlag}, + canopy_flag = #{canopyFlag}, + printer_flag = #{printerFlag}, + barrier_flag = #{barrierFlag}, + parking_lock_flag = #{parkingLockFlag}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + + where id = #{id} + + + + delete from pile_station_info where id in + + #{id} + + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/WxpayCallbackRecordMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/WxpayCallbackRecordMapper.xml new file mode 100644 index 000000000..ef5209d85 --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/WxpayCallbackRecordMapper.xml @@ -0,0 +1,263 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + id, pay_scenario, member_id, order_code, out_trade_no, transaction_id, mch_id, app_id, trade_type, + trade_state, trade_state_desc, bank_type, attach, success_time, payer_open_id, payer_total, + create_time + + + + + delete from wxpay_callback_record + where id = #{id,jdbcType=INTEGER} + + + + insert into wxpay_callback_record (pay_scenario, member_id, order_code, out_trade_no, + transaction_id, mch_id, app_id, + trade_type, trade_state, trade_state_desc, + bank_type, attach, success_time, + payer_open_id, payer_total, create_time + ) + values (#{payScenario,jdbcType=VARCHAR}, #{memberId,jdbcType=VARCHAR}, #{orderCode,jdbcType=VARCHAR}, #{outTradeNo,jdbcType=VARCHAR}, + #{transactionId,jdbcType=VARCHAR}, #{mchId,jdbcType=VARCHAR}, #{appId,jdbcType=VARCHAR}, + #{tradeType,jdbcType=VARCHAR}, #{tradeState,jdbcType=VARCHAR}, #{tradeStateDesc,jdbcType=VARCHAR}, + #{bankType,jdbcType=VARCHAR}, #{attach,jdbcType=VARCHAR}, #{successTime,jdbcType=TIMESTAMP}, + #{payerOpenId,jdbcType=VARCHAR}, #{payerTotal,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP} + ) + + + + insert into wxpay_callback_record + + + pay_scenario, + + + member_id, + + + order_code, + + + out_trade_no, + + + transaction_id, + + + mch_id, + + + app_id, + + + trade_type, + + + trade_state, + + + trade_state_desc, + + + bank_type, + + + attach, + + + success_time, + + + payer_open_id, + + + payer_total, + + + create_time, + + + + + #{payScenario,jdbcType=VARCHAR}, + + + #{memberId,jdbcType=VARCHAR}, + + + #{orderCode,jdbcType=VARCHAR}, + + + #{outTradeNo,jdbcType=VARCHAR}, + + + #{transactionId,jdbcType=VARCHAR}, + + + #{mchId,jdbcType=VARCHAR}, + + + #{appId,jdbcType=VARCHAR}, + + + #{tradeType,jdbcType=VARCHAR}, + + + #{tradeState,jdbcType=VARCHAR}, + + + #{tradeStateDesc,jdbcType=VARCHAR}, + + + #{bankType,jdbcType=VARCHAR}, + + + #{attach,jdbcType=VARCHAR}, + + + #{successTime,jdbcType=TIMESTAMP}, + + + #{payerOpenId,jdbcType=VARCHAR}, + + + #{payerTotal,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + + update wxpay_callback_record + + + pay_scenario = #{payScenario,jdbcType=VARCHAR}, + + + member_id = #{memberId,jdbcType=VARCHAR}, + + + order_code = #{orderCode,jdbcType=VARCHAR}, + + + out_trade_no = #{outTradeNo,jdbcType=VARCHAR}, + + + transaction_id = #{transactionId,jdbcType=VARCHAR}, + + + mch_id = #{mchId,jdbcType=VARCHAR}, + + + app_id = #{appId,jdbcType=VARCHAR}, + + + trade_type = #{tradeType,jdbcType=VARCHAR}, + + + trade_state = #{tradeState,jdbcType=VARCHAR}, + + + trade_state_desc = #{tradeStateDesc,jdbcType=VARCHAR}, + + + bank_type = #{bankType,jdbcType=VARCHAR}, + + + attach = #{attach,jdbcType=VARCHAR}, + + + success_time = #{successTime,jdbcType=TIMESTAMP}, + + + payer_open_id = #{payerOpenId,jdbcType=VARCHAR}, + + + payer_total = #{payerTotal,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + + update wxpay_callback_record + set + pay_scenario = #{payScenario,jdbcType=VARCHAR}, + member_id = #{memberId,jdbcType=VARCHAR}, + order_code = #{orderCode,jdbcType=VARCHAR}, + out_trade_no = #{outTradeNo,jdbcType=VARCHAR}, + transaction_id = #{transactionId,jdbcType=VARCHAR}, + mch_id = #{mchId,jdbcType=VARCHAR}, + app_id = #{appId,jdbcType=VARCHAR}, + trade_type = #{tradeType,jdbcType=VARCHAR}, + trade_state = #{tradeState,jdbcType=VARCHAR}, + trade_state_desc = #{tradeStateDesc,jdbcType=VARCHAR}, + bank_type = #{bankType,jdbcType=VARCHAR}, + attach = #{attach,jdbcType=VARCHAR}, + success_time = #{successTime,jdbcType=TIMESTAMP}, + payer_open_id = #{payerOpenId,jdbcType=VARCHAR}, + payer_total = #{payerTotal,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + + + + + + + \ No newline at end of file diff --git a/jsowell-pile/src/main/resources/mapper/pile/WxpayRefundCallbackMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/WxpayRefundCallbackMapper.xml new file mode 100644 index 000000000..c732fbbff --- /dev/null +++ b/jsowell-pile/src/main/resources/mapper/pile/WxpayRefundCallbackMapper.xml @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + id, member_id, order_code, out_trade_no, out_refund_no, transaction_id, mch_id, refund_id, + refund_status, success_time, user_received_account, payer_total, payer_refund, amount_total, + amount_refund, create_time + + + + + delete from wxpay_refund_callback + where id = #{id,jdbcType=INTEGER} + + + + insert into wxpay_refund_callback (member_id, order_code, out_trade_no, + out_refund_no, transaction_id, mch_id, + refund_id, refund_status, success_time, + user_received_account, payer_total, payer_refund, + amount_total, amount_refund, create_time + ) + values (#{memberId,jdbcType=VARCHAR}, #{orderCode,jdbcType=VARCHAR}, #{outTradeNo,jdbcType=VARCHAR}, + #{outRefundNo,jdbcType=VARCHAR}, #{transactionId,jdbcType=VARCHAR}, #{mchId,jdbcType=VARCHAR}, + #{refundId,jdbcType=VARCHAR}, #{refundStatus,jdbcType=VARCHAR}, #{successTime,jdbcType=VARCHAR}, + #{userReceivedAccount,jdbcType=VARCHAR}, #{payerTotal,jdbcType=VARCHAR}, #{payerRefund,jdbcType=VARCHAR}, + #{amountTotal,jdbcType=VARCHAR}, #{amountRefund,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP} + ) + + + + insert into wxpay_refund_callback + + + member_id, + + + order_code, + + + out_trade_no, + + + out_refund_no, + + + transaction_id, + + + mch_id, + + + refund_id, + + + refund_status, + + + success_time, + + + user_received_account, + + + payer_total, + + + payer_refund, + + + amount_total, + + + amount_refund, + + + create_time, + + + + + #{memberId,jdbcType=VARCHAR}, + + + #{orderCode,jdbcType=VARCHAR}, + + + #{outTradeNo,jdbcType=VARCHAR}, + + + #{outRefundNo,jdbcType=VARCHAR}, + + + #{transactionId,jdbcType=VARCHAR}, + + + #{mchId,jdbcType=VARCHAR}, + + + #{refundId,jdbcType=VARCHAR}, + + + #{refundStatus,jdbcType=VARCHAR}, + + + #{successTime,jdbcType=VARCHAR}, + + + #{userReceivedAccount,jdbcType=VARCHAR}, + + + #{payerTotal,jdbcType=VARCHAR}, + + + #{payerRefund,jdbcType=VARCHAR}, + + + #{amountTotal,jdbcType=VARCHAR}, + + + #{amountRefund,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + + update wxpay_refund_callback + + + member_id = #{memberId,jdbcType=VARCHAR}, + + + order_code = #{orderCode,jdbcType=VARCHAR}, + + + out_trade_no = #{outTradeNo,jdbcType=VARCHAR}, + + + out_refund_no = #{outRefundNo,jdbcType=VARCHAR}, + + + transaction_id = #{transactionId,jdbcType=VARCHAR}, + + + mch_id = #{mchId,jdbcType=VARCHAR}, + + + refund_id = #{refundId,jdbcType=VARCHAR}, + + + refund_status = #{refundStatus,jdbcType=VARCHAR}, + + + success_time = #{successTime,jdbcType=VARCHAR}, + + + user_received_account = #{userReceivedAccount,jdbcType=VARCHAR}, + + + payer_total = #{payerTotal,jdbcType=VARCHAR}, + + + payer_refund = #{payerRefund,jdbcType=VARCHAR}, + + + amount_total = #{amountTotal,jdbcType=VARCHAR}, + + + amount_refund = #{amountRefund,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + + update wxpay_refund_callback + set member_id = #{memberId,jdbcType=VARCHAR}, + order_code = #{orderCode,jdbcType=VARCHAR}, + out_trade_no = #{outTradeNo,jdbcType=VARCHAR}, + out_refund_no = #{outRefundNo,jdbcType=VARCHAR}, + transaction_id = #{transactionId,jdbcType=VARCHAR}, + mch_id = #{mchId,jdbcType=VARCHAR}, + refund_id = #{refundId,jdbcType=VARCHAR}, + refund_status = #{refundStatus,jdbcType=VARCHAR}, + success_time = #{successTime,jdbcType=VARCHAR}, + user_received_account = #{userReceivedAccount,jdbcType=VARCHAR}, + payer_total = #{payerTotal,jdbcType=VARCHAR}, + payer_refund = #{payerRefund,jdbcType=VARCHAR}, + amount_total = #{amountTotal,jdbcType=VARCHAR}, + amount_refund = #{amountRefund,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/jsowell-quartz/pom.xml b/jsowell-quartz/pom.xml new file mode 100644 index 000000000..540ac9fcc --- /dev/null +++ b/jsowell-quartz/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + com.jsowell + jsowell-charger-web + 1.0.0 + + + jsowell-quartz + + + quartz瀹氭椂浠诲姟 + + + + + + + org.quartz-scheduler + quartz + + + com.mchange + c3p0 + + + + + + + com.jsowell + jsowell-common + + + + + com.jsowell + jsowell-pile + 1.0.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + /src/test/** + + utf-8 + + + + + + \ No newline at end of file diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/config/ScheduleConfig.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/config/ScheduleConfig.java new file mode 100644 index 000000000..70e7364d8 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/config/ScheduleConfig.java @@ -0,0 +1,57 @@ +//package com.jsowell.quartz.config; +// +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.scheduling.quartz.SchedulerFactoryBean; +//import javax.sql.DataSource; +//import java.util.Properties; +// +///** +// * 瀹氭椂浠诲姟閰嶇疆锛堝崟鏈洪儴缃插缓璁垹闄ゆ绫诲拰qrtz鏁版嵁搴撹〃锛岄粯璁よ蛋鍐呭瓨浼氭渶楂樻晥锛 +// * +// * @author jsowell +// */ +//@Configuration +//public class ScheduleConfig +//{ +// @Bean +// public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) +// { +// SchedulerFactoryBean factory = new SchedulerFactoryBean(); +// factory.setDataSource(dataSource); +// +// // quartz鍙傛暟 +// Properties prop = new Properties(); +// prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler"); +// prop.put("org.quartz.scheduler.instanceId", "AUTO"); +// // 绾跨▼姹犻厤缃 +// prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); +// prop.put("org.quartz.threadPool.threadCount", "20"); +// prop.put("org.quartz.threadPool.threadPriority", "5"); +// // JobStore閰嶇疆 +// prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore"); +// // 闆嗙兢閰嶇疆 +// prop.put("org.quartz.jobStore.isClustered", "true"); +// prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); +// prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); +// prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); +// +// // sqlserver 鍚敤 +// // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); +// prop.put("org.quartz.jobStore.misfireThreshold", "12000"); +// prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); +// factory.setQuartzProperties(prop); +// +// factory.setSchedulerName("RuoyiScheduler"); +// // 寤舵椂鍚姩 +// factory.setStartupDelay(1); +// factory.setApplicationContextSchedulerContextKey("applicationContextKey"); +// // 鍙夛紝QuartzScheduler +// // 鍚姩鏃舵洿鏂板繁瀛樺湪鐨凧ob锛岃繖鏍峰氨涓嶇敤姣忔淇敼targetObject鍚庡垹闄rtz_job_details琛ㄥ搴旇褰曚簡 +// factory.setOverwriteExistingJobs(true); +// // 璁剧疆鑷姩鍚姩锛岄粯璁や负true +// factory.setAutoStartup(true); +// +// return factory; +// } +//} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/controller/SysJobController.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/controller/SysJobController.java new file mode 100644 index 000000000..cee7267ed --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/controller/SysJobController.java @@ -0,0 +1,148 @@ +package com.jsowell.quartz.controller; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.exception.job.TaskException; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.quartz.domain.SysJob; +import com.jsowell.quartz.service.ISysJobService; +import com.jsowell.quartz.util.CronUtils; +import com.jsowell.quartz.util.ScheduleUtils; +import org.quartz.SchedulerException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 璋冨害浠诲姟淇℃伅鎿嶄綔澶勭悊 + * + * @author jsowell + */ +@RestController +@RequestMapping("/monitor/job") +public class SysJobController extends BaseController { + @Autowired + private ISysJobService jobService; + + /** + * 鏌ヨ瀹氭椂浠诲姟鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:list')") + @GetMapping("/list") + public TableDataInfo list(SysJob sysJob) { + startPage(); + List list = jobService.selectJobList(sysJob); + return getDataTable(list); + } + + /** + * 瀵煎嚭瀹氭椂浠诲姟鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:export')") + @Log(title = "瀹氭椂浠诲姟", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SysJob sysJob) { + List list = jobService.selectJobList(sysJob); + ExcelUtil util = new ExcelUtil(SysJob.class); + util.exportExcel(response, list, "瀹氭椂浠诲姟"); + } + + /** + * 鑾峰彇瀹氭椂浠诲姟璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:query')") + @GetMapping(value = "/{jobId}") + public AjaxResult getInfo(@PathVariable("jobId") Long jobId) { + return AjaxResult.success(jobService.selectJobById(jobId)); + } + + /** + * 鏂板瀹氭椂浠诲姟 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:add')") + @Log(title = "瀹氭椂浠诲姟", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException { + if (!CronUtils.isValid(job.getCronExpression())) { + return error("鏂板浠诲姟'" + job.getJobName() + "'澶辫触锛孋ron琛ㄨ揪寮忎笉姝g‘"); + } else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) { + return error("鏂板浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆涓嶅厑璁'rmi'璋冪敤"); + } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS})) { + return error("鏂板浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆涓嶅厑璁'ldap(s)'璋冪敤"); + } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{Constants.HTTP, Constants.HTTPS})) { + return error("鏂板浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆涓嶅厑璁'http(s)'璋冪敤"); + } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR)) { + return error("鏂板浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆瀛樺湪杩濊"); + } else if (!ScheduleUtils.whiteList(job.getInvokeTarget())) { + return error("鏂板浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆涓嶅湪鐧藉悕鍗曞唴"); + } + job.setCreateBy(getUsername()); + return toAjax(jobService.insertJob(job)); + } + + /** + * 淇敼瀹氭椂浠诲姟 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:edit')") + @Log(title = "瀹氭椂浠诲姟", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SysJob job) throws SchedulerException, TaskException { + if (!CronUtils.isValid(job.getCronExpression())) { + return error("淇敼浠诲姟'" + job.getJobName() + "'澶辫触锛孋ron琛ㄨ揪寮忎笉姝g‘"); + } else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) { + return error("淇敼浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆涓嶅厑璁'rmi'璋冪敤"); + } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS})) { + return error("淇敼浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆涓嶅厑璁'ldap(s)'璋冪敤"); + } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{Constants.HTTP, Constants.HTTPS})) { + return error("淇敼浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆涓嶅厑璁'http(s)'璋冪敤"); + } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR)) { + return error("淇敼浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆瀛樺湪杩濊"); + } else if (!ScheduleUtils.whiteList(job.getInvokeTarget())) { + return error("淇敼浠诲姟'" + job.getJobName() + "'澶辫触锛岀洰鏍囧瓧绗︿覆涓嶅湪鐧藉悕鍗曞唴"); + } + job.setUpdateBy(getUsername()); + return toAjax(jobService.updateJob(job)); + } + + /** + * 瀹氭椂浠诲姟鐘舵佷慨鏀 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") + @Log(title = "瀹氭椂浠诲姟", businessType = BusinessType.UPDATE) + @PutMapping("/changeStatus") + public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException { + SysJob newJob = jobService.selectJobById(job.getJobId()); + newJob.setStatus(job.getStatus()); + return toAjax(jobService.changeStatus(newJob)); + } + + /** + * 瀹氭椂浠诲姟绔嬪嵆鎵ц涓娆 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") + @Log(title = "瀹氭椂浠诲姟", businessType = BusinessType.UPDATE) + @PutMapping("/run") + public AjaxResult run(@RequestBody SysJob job) throws SchedulerException { + boolean result = jobService.run(job); + return result ? success() : error("浠诲姟涓嶅瓨鍦ㄦ垨宸茶繃鏈燂紒"); + } + + /** + * 鍒犻櫎瀹氭椂浠诲姟 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:remove')") + @Log(title = "瀹氭椂浠诲姟", businessType = BusinessType.DELETE) + @DeleteMapping("/{jobIds}") + public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException { + jobService.deleteJobByIds(jobIds); + return success(); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/controller/SysJobLogController.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/controller/SysJobLogController.java new file mode 100644 index 000000000..493d0a00c --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/controller/SysJobLogController.java @@ -0,0 +1,82 @@ +package com.jsowell.quartz.controller; + +import com.jsowell.common.annotation.Log; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.core.page.TableDataInfo; +import com.jsowell.common.enums.BusinessType; +import com.jsowell.common.util.poi.ExcelUtil; +import com.jsowell.quartz.domain.SysJobLog; +import com.jsowell.quartz.service.ISysJobLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 璋冨害鏃ュ織鎿嶄綔澶勭悊 + * + * @author jsowell + */ +@RestController +@RequestMapping("/monitor/jobLog") +public class SysJobLogController extends BaseController { + @Autowired + private ISysJobLogService jobLogService; + + /** + * 鏌ヨ瀹氭椂浠诲姟璋冨害鏃ュ織鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:list')") + @GetMapping("/list") + public TableDataInfo list(SysJobLog sysJobLog) { + startPage(); + List list = jobLogService.selectJobLogList(sysJobLog); + return getDataTable(list); + } + + /** + * 瀵煎嚭瀹氭椂浠诲姟璋冨害鏃ュ織鍒楄〃 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:export')") + @Log(title = "浠诲姟璋冨害鏃ュ織", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SysJobLog sysJobLog) { + List list = jobLogService.selectJobLogList(sysJobLog); + ExcelUtil util = new ExcelUtil(SysJobLog.class); + util.exportExcel(response, list, "璋冨害鏃ュ織"); + } + + /** + * 鏍规嵁璋冨害缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:query')") + @GetMapping(value = "/{configId}") + public AjaxResult getInfo(@PathVariable Long jobLogId) { + return AjaxResult.success(jobLogService.selectJobLogById(jobLogId)); + } + + + /** + * 鍒犻櫎瀹氭椂浠诲姟璋冨害鏃ュ織 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:remove')") + @Log(title = "瀹氭椂浠诲姟璋冨害鏃ュ織", businessType = BusinessType.DELETE) + @DeleteMapping("/{jobLogIds}") + public AjaxResult remove(@PathVariable Long[] jobLogIds) { + return toAjax(jobLogService.deleteJobLogByIds(jobLogIds)); + } + + /** + * 娓呯┖瀹氭椂浠诲姟璋冨害鏃ュ織 + */ + @PreAuthorize("@ss.hasPermi('monitor:job:remove')") + @Log(title = "璋冨害鏃ュ織", businessType = BusinessType.CLEAN) + @DeleteMapping("/clean") + public AjaxResult clean() { + jobLogService.cleanJobLog(); + return AjaxResult.success(); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/domain/SysJob.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/domain/SysJob.java new file mode 100644 index 000000000..18e8b6f14 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/domain/SysJob.java @@ -0,0 +1,169 @@ +package com.jsowell.quartz.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.constant.ScheduleConstants; +import com.jsowell.common.core.domain.BaseEntity; +import com.jsowell.common.util.StringUtils; +import com.jsowell.quartz.util.CronUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * 瀹氭椂浠诲姟璋冨害琛 sys_job + * + * @author jsowell + */ +public class SysJob extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 浠诲姟ID + */ + @Excel(name = "浠诲姟搴忓彿", cellType = ColumnType.NUMERIC) + private Long jobId; + + /** + * 浠诲姟鍚嶇О + */ + @Excel(name = "浠诲姟鍚嶇О") + private String jobName; + + /** + * 浠诲姟缁勫悕 + */ + @Excel(name = "浠诲姟缁勫悕") + private String jobGroup; + + /** + * 璋冪敤鐩爣瀛楃涓 + */ + @Excel(name = "璋冪敤鐩爣瀛楃涓") + private String invokeTarget; + + /** + * cron鎵ц琛ㄨ揪寮 + */ + @Excel(name = "鎵ц琛ㄨ揪寮 ") + private String cronExpression; + + /** + * cron璁″垝绛栫暐 + */ + @Excel(name = "璁″垝绛栫暐 ", readConverterExp = "0=榛樿,1=绔嬪嵆瑙﹀彂鎵ц,2=瑙﹀彂涓娆℃墽琛,3=涓嶈Е鍙戠珛鍗虫墽琛") + private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT; + + /** + * 鏄惁骞跺彂鎵ц锛0鍏佽 1绂佹锛 + */ + @Excel(name = "骞跺彂鎵ц", readConverterExp = "0=鍏佽,1=绂佹") + private String concurrent; + + /** + * 浠诲姟鐘舵侊紙0姝e父 1鏆傚仠锛 + */ + @Excel(name = "浠诲姟鐘舵", readConverterExp = "0=姝e父,1=鏆傚仠") + private String status; + + public Long getJobId() { + return jobId; + } + + public void setJobId(Long jobId) { + this.jobId = jobId; + } + + @NotBlank(message = "浠诲姟鍚嶇О涓嶈兘涓虹┖") + @Size(min = 0, max = 64, message = "浠诲姟鍚嶇О涓嶈兘瓒呰繃64涓瓧绗") + public String getJobName() { + return jobName; + } + + public void setJobName(String jobName) { + this.jobName = jobName; + } + + public String getJobGroup() { + return jobGroup; + } + + public void setJobGroup(String jobGroup) { + this.jobGroup = jobGroup; + } + + @NotBlank(message = "璋冪敤鐩爣瀛楃涓蹭笉鑳戒负绌") + @Size(min = 0, max = 500, message = "璋冪敤鐩爣瀛楃涓查暱搴︿笉鑳借秴杩500涓瓧绗") + public String getInvokeTarget() { + return invokeTarget; + } + + public void setInvokeTarget(String invokeTarget) { + this.invokeTarget = invokeTarget; + } + + @NotBlank(message = "Cron鎵ц琛ㄨ揪寮忎笉鑳戒负绌") + @Size(min = 0, max = 255, message = "Cron鎵ц琛ㄨ揪寮忎笉鑳借秴杩255涓瓧绗") + public String getCronExpression() { + return cronExpression; + } + + public void setCronExpression(String cronExpression) { + this.cronExpression = cronExpression; + } + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + public Date getNextValidTime() { + if (StringUtils.isNotEmpty(cronExpression)) { + return CronUtils.getNextExecution(cronExpression); + } + return null; + } + + public String getMisfirePolicy() { + return misfirePolicy; + } + + public void setMisfirePolicy(String misfirePolicy) { + this.misfirePolicy = misfirePolicy; + } + + public String getConcurrent() { + return concurrent; + } + + public void setConcurrent(String concurrent) { + this.concurrent = concurrent; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("jobId", getJobId()) + .append("jobName", getJobName()) + .append("jobGroup", getJobGroup()) + .append("cronExpression", getCronExpression()) + .append("nextValidTime", getNextValidTime()) + .append("misfirePolicy", getMisfirePolicy()) + .append("concurrent", getConcurrent()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/domain/SysJobLog.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/domain/SysJobLog.java new file mode 100644 index 000000000..824bac9f9 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/domain/SysJobLog.java @@ -0,0 +1,155 @@ +package com.jsowell.quartz.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; + +/** + * 瀹氭椂浠诲姟璋冨害鏃ュ織琛 sys_job_log + * + * @author jsowell + */ +public class SysJobLog extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @Excel(name = "鏃ュ織搴忓彿") + private Long jobLogId; + + /** + * 浠诲姟鍚嶇О + */ + @Excel(name = "浠诲姟鍚嶇О") + private String jobName; + + /** + * 浠诲姟缁勫悕 + */ + @Excel(name = "浠诲姟缁勫悕") + private String jobGroup; + + /** + * 璋冪敤鐩爣瀛楃涓 + */ + @Excel(name = "璋冪敤鐩爣瀛楃涓") + private String invokeTarget; + + /** + * 鏃ュ織淇℃伅 + */ + @Excel(name = "鏃ュ織淇℃伅") + private String jobMessage; + + /** + * 鎵ц鐘舵侊紙0姝e父 1澶辫触锛 + */ + @Excel(name = "鎵ц鐘舵", readConverterExp = "0=姝e父,1=澶辫触") + private String status; + + /** + * 寮傚父淇℃伅 + */ + @Excel(name = "寮傚父淇℃伅") + private String exceptionInfo; + + /** + * 寮濮嬫椂闂 + */ + private Date startTime; + + /** + * 鍋滄鏃堕棿 + */ + private Date stopTime; + + public Long getJobLogId() { + return jobLogId; + } + + public void setJobLogId(Long jobLogId) { + this.jobLogId = jobLogId; + } + + public String getJobName() { + return jobName; + } + + public void setJobName(String jobName) { + this.jobName = jobName; + } + + public String getJobGroup() { + return jobGroup; + } + + public void setJobGroup(String jobGroup) { + this.jobGroup = jobGroup; + } + + public String getInvokeTarget() { + return invokeTarget; + } + + public void setInvokeTarget(String invokeTarget) { + this.invokeTarget = invokeTarget; + } + + public String getJobMessage() { + return jobMessage; + } + + public void setJobMessage(String jobMessage) { + this.jobMessage = jobMessage; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getExceptionInfo() { + return exceptionInfo; + } + + public void setExceptionInfo(String exceptionInfo) { + this.exceptionInfo = exceptionInfo; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getStopTime() { + return stopTime; + } + + public void setStopTime(Date stopTime) { + this.stopTime = stopTime; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("jobLogId", getJobLogId()) + .append("jobName", getJobName()) + .append("jobGroup", getJobGroup()) + .append("jobMessage", getJobMessage()) + .append("status", getStatus()) + .append("exceptionInfo", getExceptionInfo()) + .append("startTime", getStartTime()) + .append("stopTime", getStopTime()) + .toString(); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/mapper/SysJobLogMapper.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/mapper/SysJobLogMapper.java new file mode 100644 index 000000000..98899d58d --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/mapper/SysJobLogMapper.java @@ -0,0 +1,66 @@ +package com.jsowell.quartz.mapper; + +import com.jsowell.quartz.domain.SysJobLog; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 璋冨害浠诲姟鏃ュ織淇℃伅 鏁版嵁灞 + * + * @author jsowell + */ +@Repository +public interface SysJobLogMapper { + /** + * 鑾峰彇quartz璋冨害鍣ㄦ棩蹇楃殑璁″垝浠诲姟 + * + * @param jobLog 璋冨害鏃ュ織淇℃伅 + * @return 璋冨害浠诲姟鏃ュ織闆嗗悎 + */ + public List selectJobLogList(SysJobLog jobLog); + + /** + * 鏌ヨ鎵鏈夎皟搴︿换鍔℃棩蹇 + * + * @return 璋冨害浠诲姟鏃ュ織鍒楄〃 + */ + public List selectJobLogAll(); + + /** + * 閫氳繃璋冨害浠诲姟鏃ュ織ID鏌ヨ璋冨害淇℃伅 + * + * @param jobLogId 璋冨害浠诲姟鏃ュ織ID + * @return 璋冨害浠诲姟鏃ュ織瀵硅薄淇℃伅 + */ + public SysJobLog selectJobLogById(Long jobLogId); + + /** + * 鏂板浠诲姟鏃ュ織 + * + * @param jobLog 璋冨害鏃ュ織淇℃伅 + * @return 缁撴灉 + */ + public int insertJobLog(SysJobLog jobLog); + + /** + * 鎵归噺鍒犻櫎璋冨害鏃ュ織淇℃伅 + * + * @param logIds 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteJobLogByIds(Long[] logIds); + + /** + * 鍒犻櫎浠诲姟鏃ュ織 + * + * @param jobId 璋冨害鏃ュ織ID + * @return 缁撴灉 + */ + public int deleteJobLogById(Long jobId); + + /** + * 娓呯┖浠诲姟鏃ュ織 + */ + public void cleanJobLog(); +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/mapper/SysJobMapper.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/mapper/SysJobMapper.java new file mode 100644 index 000000000..c726a3618 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/mapper/SysJobMapper.java @@ -0,0 +1,69 @@ +package com.jsowell.quartz.mapper; + +import com.jsowell.quartz.domain.SysJob; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 璋冨害浠诲姟淇℃伅 鏁版嵁灞 + * + * @author jsowell + */ +@Repository +public interface SysJobMapper { + /** + * 鏌ヨ璋冨害浠诲姟鏃ュ織闆嗗悎 + * + * @param job 璋冨害淇℃伅 + * @return 鎿嶄綔鏃ュ織闆嗗悎 + */ + public List selectJobList(SysJob job); + + /** + * 鏌ヨ鎵鏈夎皟搴︿换鍔 + * + * @return 璋冨害浠诲姟鍒楄〃 + */ + public List selectJobAll(); + + /** + * 閫氳繃璋冨害ID鏌ヨ璋冨害浠诲姟淇℃伅 + * + * @param jobId 璋冨害ID + * @return 瑙掕壊瀵硅薄淇℃伅 + */ + public SysJob selectJobById(Long jobId); + + /** + * 閫氳繃璋冨害ID鍒犻櫎璋冨害浠诲姟淇℃伅 + * + * @param jobId 璋冨害ID + * @return 缁撴灉 + */ + public int deleteJobById(Long jobId); + + /** + * 鎵归噺鍒犻櫎璋冨害浠诲姟淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteJobByIds(Long[] ids); + + /** + * 淇敼璋冨害浠诲姟淇℃伅 + * + * @param job 璋冨害浠诲姟淇℃伅 + * @return 缁撴灉 + */ + public int updateJob(SysJob job); + + /** + * 鏂板璋冨害浠诲姟淇℃伅 + * + * @param job 璋冨害浠诲姟淇℃伅 + * @return 缁撴灉 + */ + public int insertJob(SysJob job); +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/service/ISysJobLogService.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/service/ISysJobLogService.java new file mode 100644 index 000000000..e720277cd --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/service/ISysJobLogService.java @@ -0,0 +1,56 @@ +package com.jsowell.quartz.service; + +import com.jsowell.quartz.domain.SysJobLog; + +import java.util.List; + +/** + * 瀹氭椂浠诲姟璋冨害鏃ュ織淇℃伅淇℃伅 鏈嶅姟灞 + * + * @author jsowell + */ +public interface ISysJobLogService { + /** + * 鑾峰彇quartz璋冨害鍣ㄦ棩蹇楃殑璁″垝浠诲姟 + * + * @param jobLog 璋冨害鏃ュ織淇℃伅 + * @return 璋冨害浠诲姟鏃ュ織闆嗗悎 + */ + public List selectJobLogList(SysJobLog jobLog); + + /** + * 閫氳繃璋冨害浠诲姟鏃ュ織ID鏌ヨ璋冨害淇℃伅 + * + * @param jobLogId 璋冨害浠诲姟鏃ュ織ID + * @return 璋冨害浠诲姟鏃ュ織瀵硅薄淇℃伅 + */ + public SysJobLog selectJobLogById(Long jobLogId); + + /** + * 鏂板浠诲姟鏃ュ織 + * + * @param jobLog 璋冨害鏃ュ織淇℃伅 + */ + public void addJobLog(SysJobLog jobLog); + + /** + * 鎵归噺鍒犻櫎璋冨害鏃ュ織淇℃伅 + * + * @param logIds 闇瑕佸垹闄ょ殑鏃ュ織ID + * @return 缁撴灉 + */ + public int deleteJobLogByIds(Long[] logIds); + + /** + * 鍒犻櫎浠诲姟鏃ュ織 + * + * @param jobId 璋冨害鏃ュ織ID + * @return 缁撴灉 + */ + public int deleteJobLogById(Long jobId); + + /** + * 娓呯┖浠诲姟鏃ュ織 + */ + public void cleanJobLog(); +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/service/ISysJobService.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/service/ISysJobService.java new file mode 100644 index 000000000..04df9b3e4 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/service/ISysJobService.java @@ -0,0 +1,102 @@ +package com.jsowell.quartz.service; + +import com.jsowell.common.exception.job.TaskException; +import com.jsowell.quartz.domain.SysJob; +import org.quartz.SchedulerException; + +import java.util.List; + +/** + * 瀹氭椂浠诲姟璋冨害淇℃伅淇℃伅 鏈嶅姟灞 + * + * @author jsowell + */ +public interface ISysJobService { + /** + * 鑾峰彇quartz璋冨害鍣ㄧ殑璁″垝浠诲姟 + * + * @param job 璋冨害淇℃伅 + * @return 璋冨害浠诲姟闆嗗悎 + */ + public List selectJobList(SysJob job); + + /** + * 閫氳繃璋冨害浠诲姟ID鏌ヨ璋冨害淇℃伅 + * + * @param jobId 璋冨害浠诲姟ID + * @return 璋冨害浠诲姟瀵硅薄淇℃伅 + */ + public SysJob selectJobById(Long jobId); + + /** + * 鏆傚仠浠诲姟 + * + * @param job 璋冨害淇℃伅 + * @return 缁撴灉 + */ + public int pauseJob(SysJob job) throws SchedulerException; + + /** + * 鎭㈠浠诲姟 + * + * @param job 璋冨害淇℃伅 + * @return 缁撴灉 + */ + public int resumeJob(SysJob job) throws SchedulerException; + + /** + * 鍒犻櫎浠诲姟鍚庯紝鎵瀵瑰簲鐨則rigger涔熷皢琚垹闄 + * + * @param job 璋冨害淇℃伅 + * @return 缁撴灉 + */ + public int deleteJob(SysJob job) throws SchedulerException; + + /** + * 鎵归噺鍒犻櫎璋冨害淇℃伅 + * + * @param jobIds 闇瑕佸垹闄ょ殑浠诲姟ID + * @return 缁撴灉 + */ + public void deleteJobByIds(Long[] jobIds) throws SchedulerException; + + /** + * 浠诲姟璋冨害鐘舵佷慨鏀 + * + * @param job 璋冨害淇℃伅 + * @return 缁撴灉 + */ + public int changeStatus(SysJob job) throws SchedulerException; + + /** + * 绔嬪嵆杩愯浠诲姟 + * + * @param job 璋冨害淇℃伅 + * @return 缁撴灉 + */ + public boolean run(SysJob job) throws SchedulerException; + + /** + * 鏂板浠诲姟 + * + * @param job 璋冨害淇℃伅 + * @return 缁撴灉 + */ + public int insertJob(SysJob job) throws SchedulerException, TaskException; + + /** + * 鏇存柊浠诲姟 + * + * @param job 璋冨害淇℃伅 + * @return 缁撴灉 + */ + public int updateJob(SysJob job) throws SchedulerException, TaskException; + + /** + * 鏍¢獙cron琛ㄨ揪寮忔槸鍚︽湁鏁 + * + * @param cronExpression 琛ㄨ揪寮 + * @return 缁撴灉 + */ + public boolean checkCronExpressionIsValid(String cronExpression); +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/service/impl/SysJobLogServiceImpl.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/service/impl/SysJobLogServiceImpl.java new file mode 100644 index 000000000..56b1a1bd7 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/service/impl/SysJobLogServiceImpl.java @@ -0,0 +1,81 @@ +package com.jsowell.quartz.service.impl; + +import com.jsowell.quartz.domain.SysJobLog; +import com.jsowell.quartz.mapper.SysJobLogMapper; +import com.jsowell.quartz.service.ISysJobLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 瀹氭椂浠诲姟璋冨害鏃ュ織淇℃伅 鏈嶅姟灞 + * + * @author jsowell + */ +@Service +public class SysJobLogServiceImpl implements ISysJobLogService { + @Autowired + private SysJobLogMapper jobLogMapper; + + /** + * 鑾峰彇quartz璋冨害鍣ㄦ棩蹇楃殑璁″垝浠诲姟 + * + * @param jobLog 璋冨害鏃ュ織淇℃伅 + * @return 璋冨害浠诲姟鏃ュ織闆嗗悎 + */ + @Override + public List selectJobLogList(SysJobLog jobLog) { + return jobLogMapper.selectJobLogList(jobLog); + } + + /** + * 閫氳繃璋冨害浠诲姟鏃ュ織ID鏌ヨ璋冨害淇℃伅 + * + * @param jobLogId 璋冨害浠诲姟鏃ュ織ID + * @return 璋冨害浠诲姟鏃ュ織瀵硅薄淇℃伅 + */ + @Override + public SysJobLog selectJobLogById(Long jobLogId) { + return jobLogMapper.selectJobLogById(jobLogId); + } + + /** + * 鏂板浠诲姟鏃ュ織 + * + * @param jobLog 璋冨害鏃ュ織淇℃伅 + */ + @Override + public void addJobLog(SysJobLog jobLog) { + jobLogMapper.insertJobLog(jobLog); + } + + /** + * 鎵归噺鍒犻櫎璋冨害鏃ュ織淇℃伅 + * + * @param logIds 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + @Override + public int deleteJobLogByIds(Long[] logIds) { + return jobLogMapper.deleteJobLogByIds(logIds); + } + + /** + * 鍒犻櫎浠诲姟鏃ュ織 + * + * @param jobId 璋冨害鏃ュ織ID + */ + @Override + public int deleteJobLogById(Long jobId) { + return jobLogMapper.deleteJobLogById(jobId); + } + + /** + * 娓呯┖浠诲姟鏃ュ織 + */ + @Override + public void cleanJobLog() { + jobLogMapper.cleanJobLog(); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/service/impl/SysJobServiceImpl.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/service/impl/SysJobServiceImpl.java new file mode 100644 index 000000000..c4eadaf6b --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/service/impl/SysJobServiceImpl.java @@ -0,0 +1,236 @@ +package com.jsowell.quartz.service.impl; + +import com.jsowell.common.constant.ScheduleConstants; +import com.jsowell.common.exception.job.TaskException; +import com.jsowell.quartz.domain.SysJob; +import com.jsowell.quartz.mapper.SysJobMapper; +import com.jsowell.quartz.service.ISysJobService; +import com.jsowell.quartz.util.CronUtils; +import com.jsowell.quartz.util.ScheduleUtils; +import org.quartz.JobDataMap; +import org.quartz.JobKey; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.PostConstruct; +import java.util.List; + +/** + * 瀹氭椂浠诲姟璋冨害淇℃伅 鏈嶅姟灞 + * + * @author jsowell + */ +@Service +public class SysJobServiceImpl implements ISysJobService { + @Autowired + private Scheduler scheduler; + + @Autowired + private SysJobMapper jobMapper; + + /** + * 椤圭洰鍚姩鏃讹紝鍒濆鍖栧畾鏃跺櫒 涓昏鏄槻姝㈡墜鍔ㄤ慨鏀规暟鎹簱瀵艰嚧鏈悓姝ュ埌瀹氭椂浠诲姟澶勭悊锛堟敞锛氫笉鑳芥墜鍔ㄤ慨鏀规暟鎹簱ID鍜屼换鍔$粍鍚嶏紝鍚﹀垯浼氬鑷磋剰鏁版嵁锛 + */ + @PostConstruct + public void init() throws SchedulerException, TaskException { + scheduler.clear(); + List jobList = jobMapper.selectJobAll(); + for (SysJob job : jobList) { + ScheduleUtils.createScheduleJob(scheduler, job); + } + } + + /** + * 鑾峰彇quartz璋冨害鍣ㄧ殑璁″垝浠诲姟鍒楄〃 + * + * @param job 璋冨害淇℃伅 + * @return + */ + @Override + public List selectJobList(SysJob job) { + return jobMapper.selectJobList(job); + } + + /** + * 閫氳繃璋冨害浠诲姟ID鏌ヨ璋冨害淇℃伅 + * + * @param jobId 璋冨害浠诲姟ID + * @return 璋冨害浠诲姟瀵硅薄淇℃伅 + */ + @Override + public SysJob selectJobById(Long jobId) { + return jobMapper.selectJobById(jobId); + } + + /** + * 鏆傚仠浠诲姟 + * + * @param job 璋冨害淇℃伅 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int pauseJob(SysJob job) throws SchedulerException { + Long jobId = job.getJobId(); + String jobGroup = job.getJobGroup(); + job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); + int rows = jobMapper.updateJob(job); + if (rows > 0) { + scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); + } + return rows; + } + + /** + * 鎭㈠浠诲姟 + * + * @param job 璋冨害淇℃伅 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int resumeJob(SysJob job) throws SchedulerException { + Long jobId = job.getJobId(); + String jobGroup = job.getJobGroup(); + job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); + int rows = jobMapper.updateJob(job); + if (rows > 0) { + scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); + } + return rows; + } + + /** + * 鍒犻櫎浠诲姟鍚庯紝鎵瀵瑰簲鐨則rigger涔熷皢琚垹闄 + * + * @param job 璋冨害淇℃伅 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int deleteJob(SysJob job) throws SchedulerException { + Long jobId = job.getJobId(); + String jobGroup = job.getJobGroup(); + int rows = jobMapper.deleteJobById(jobId); + if (rows > 0) { + scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); + } + return rows; + } + + /** + * 鎵归噺鍒犻櫎璋冨害淇℃伅 + * + * @param jobIds 闇瑕佸垹闄ょ殑浠诲姟ID + * @return 缁撴灉 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteJobByIds(Long[] jobIds) throws SchedulerException { + for (Long jobId : jobIds) { + SysJob job = jobMapper.selectJobById(jobId); + deleteJob(job); + } + } + + /** + * 浠诲姟璋冨害鐘舵佷慨鏀 + * + * @param job 璋冨害淇℃伅 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int changeStatus(SysJob job) throws SchedulerException { + int rows = 0; + String status = job.getStatus(); + if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) { + rows = resumeJob(job); + } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) { + rows = pauseJob(job); + } + return rows; + } + + /** + * 绔嬪嵆杩愯浠诲姟 + * + * @param job 璋冨害淇℃伅 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean run(SysJob job) throws SchedulerException { + boolean result = false; + Long jobId = job.getJobId(); + String jobGroup = job.getJobGroup(); + SysJob properties = selectJobById(job.getJobId()); + // 鍙傛暟 + JobDataMap dataMap = new JobDataMap(); + dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); + JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); + if (scheduler.checkExists(jobKey)) { + result = true; + scheduler.triggerJob(jobKey, dataMap); + } + return result; + } + + /** + * 鏂板浠诲姟 + * + * @param job 璋冨害淇℃伅 璋冨害淇℃伅 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int insertJob(SysJob job) throws SchedulerException, TaskException { + job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); + int rows = jobMapper.insertJob(job); + if (rows > 0) { + ScheduleUtils.createScheduleJob(scheduler, job); + } + return rows; + } + + /** + * 鏇存柊浠诲姟鐨勬椂闂磋〃杈惧紡 + * + * @param job 璋冨害淇℃伅 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int updateJob(SysJob job) throws SchedulerException, TaskException { + SysJob properties = selectJobById(job.getJobId()); + int rows = jobMapper.updateJob(job); + if (rows > 0) { + updateSchedulerJob(job, properties.getJobGroup()); + } + return rows; + } + + /** + * 鏇存柊浠诲姟 + * + * @param job 浠诲姟瀵硅薄 + * @param jobGroup 浠诲姟缁勫悕 + */ + public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException { + Long jobId = job.getJobId(); + // 鍒ゆ柇鏄惁瀛樺湪 + JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); + if (scheduler.checkExists(jobKey)) { + // 闃叉鍒涘缓鏃跺瓨鍦ㄦ暟鎹棶棰 鍏堢Щ闄わ紝鐒跺悗鍦ㄦ墽琛屽垱寤烘搷浣 + scheduler.deleteJob(jobKey); + } + ScheduleUtils.createScheduleJob(scheduler, job); + } + + /** + * 鏍¢獙cron琛ㄨ揪寮忔槸鍚︽湁鏁 + * + * @param cronExpression 琛ㄨ揪寮 + * @return 缁撴灉 + */ + @Override + public boolean checkCronExpressionIsValid(String cronExpression) { + return CronUtils.isValid(cronExpression); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/task/JsowellTask.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/task/JsowellTask.java new file mode 100644 index 000000000..c0b6069ea --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/task/JsowellTask.java @@ -0,0 +1,39 @@ +package com.jsowell.quartz.task; + +import com.jsowell.common.util.DateUtils; +import com.jsowell.pile.service.IOrderBasicInfoService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; + +@Component("jsowellTask") +public class JsowellTask { + + private final Logger log = LoggerFactory.getLogger(JsowellTask.class); + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + /** + * 鍏抽棴15鍒嗛挓鏈敮浠樼殑璁㈠崟 + * close15MinutesOfUnpaidOrders + */ + public void close15MinutesOfUnpaidOrders() { + // log.info("鍏抽棴15鍒嗛挓鏈敮浠樼殑璁㈠崟"); + orderBasicInfoService.close15MinutesOfUnpaidOrders(); + } + + /** + * 鍏抽棴鍚姩澶辫触鐨勮鍗 + * 璁㈠崟鏀粯鎴愬姛锛屽湪15鍒嗛挓鍐呮湭鍚姩锛 + */ + public void closeStartFailedOrder() { + // 鏌ヨ鍑烘渶杩2澶╂敮浠樻垚鍔燂紝骞朵笖璁㈠崟鐘舵佷负鏈惎鍔ㄧ殑璁㈠崟 + String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addDays(new Date(), -2)); + String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date()); + orderBasicInfoService.closeStartFailedOrder(startTime, endTime); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/task/RyTask.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/task/RyTask.java new file mode 100644 index 000000000..a2993dbae --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/task/RyTask.java @@ -0,0 +1,24 @@ +package com.jsowell.quartz.task; + +import org.springframework.stereotype.Component; +import com.jsowell.common.util.StringUtils; + +/** + * 瀹氭椂浠诲姟璋冨害娴嬭瘯 + * + * @author jsowell + */ +@Component("ryTask") +public class RyTask { + public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { + System.out.println(StringUtils.format("鎵ц澶氬弬鏂规硶锛 瀛楃涓茬被鍨媨}锛屽竷灏旂被鍨媨}锛岄暱鏁村瀷{}锛屾诞鐐瑰瀷{}锛屾暣褰}", s, b, l, d, i)); + } + + public void ryParams(String params) { + System.out.println("鎵ц鏈夊弬鏂规硶锛" + params); + } + + public void ryNoParams() { + System.out.println("鎵ц鏃犲弬鏂规硶"); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/util/AbstractQuartzJob.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/AbstractQuartzJob.java new file mode 100644 index 000000000..e8ea1d839 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/AbstractQuartzJob.java @@ -0,0 +1,97 @@ +package com.jsowell.quartz.util; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.constant.ScheduleConstants; +import com.jsowell.common.util.ExceptionUtil; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.bean.BeanUtils; +import com.jsowell.common.util.spring.SpringUtils; +import com.jsowell.quartz.domain.SysJob; +import com.jsowell.quartz.domain.SysJobLog; +import com.jsowell.quartz.service.ISysJobLogService; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +/** + * 鎶借薄quartz璋冪敤 + * + * @author jsowell + */ +public abstract class AbstractQuartzJob implements Job { + private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class); + + /** + * 绾跨▼鏈湴鍙橀噺 + */ + private static ThreadLocal threadLocal = new ThreadLocal<>(); + + @Override + public void execute(JobExecutionContext context) throws JobExecutionException { + SysJob sysJob = new SysJob(); + BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES)); + try { + before(context, sysJob); + if (sysJob != null) { + doExecute(context, sysJob); + } + after(context, sysJob, null); + } catch (Exception e) { + log.error("浠诲姟鎵ц寮傚父 - 锛", e); + after(context, sysJob, e); + } + } + + /** + * 鎵ц鍓 + * + * @param context 宸ヤ綔鎵ц涓婁笅鏂囧璞 + * @param sysJob 绯荤粺璁″垝浠诲姟 + */ + protected void before(JobExecutionContext context, SysJob sysJob) { + threadLocal.set(new Date()); + } + + /** + * 鎵ц鍚 + * + * @param context 宸ヤ綔鎵ц涓婁笅鏂囧璞 + * @param sysJob 绯荤粺璁″垝浠诲姟 + */ + protected void after(JobExecutionContext context, SysJob sysJob, Exception e) { + Date startTime = threadLocal.get(); + threadLocal.remove(); + + final SysJobLog sysJobLog = new SysJobLog(); + sysJobLog.setJobName(sysJob.getJobName()); + sysJobLog.setJobGroup(sysJob.getJobGroup()); + sysJobLog.setInvokeTarget(sysJob.getInvokeTarget()); + sysJobLog.setStartTime(startTime); + sysJobLog.setStopTime(new Date()); + long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime(); + sysJobLog.setJobMessage(sysJobLog.getJobName() + " 鎬诲叡鑰楁椂锛" + runMs + "姣"); + if (e != null) { + sysJobLog.setStatus(Constants.FAIL); + String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000); + sysJobLog.setExceptionInfo(errorMsg); + } else { + sysJobLog.setStatus(Constants.SUCCESS); + } + + // 鍐欏叆鏁版嵁搴撳綋涓 + SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); + } + + /** + * 鎵ц鏂规硶锛岀敱瀛愮被閲嶈浇 + * + * @param context 宸ヤ綔鎵ц涓婁笅鏂囧璞 + * @param sysJob 绯荤粺璁″垝浠诲姟 + * @throws Exception 鎵ц杩囩▼涓殑寮傚父 + */ + protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception; +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/util/CronUtils.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/CronUtils.java new file mode 100644 index 000000000..7b80a9f14 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/CronUtils.java @@ -0,0 +1,53 @@ +package com.jsowell.quartz.util; + +import org.quartz.CronExpression; + +import java.text.ParseException; +import java.util.Date; + +/** + * cron琛ㄨ揪寮忓伐鍏风被 + * + * @author jsowell + */ +public class CronUtils { + /** + * 杩斿洖涓涓竷灏斿间唬琛ㄤ竴涓粰瀹氱殑Cron琛ㄨ揪寮忕殑鏈夋晥鎬 + * + * @param cronExpression Cron琛ㄨ揪寮 + * @return boolean 琛ㄨ揪寮忔槸鍚︽湁鏁 + */ + public static boolean isValid(String cronExpression) { + return CronExpression.isValidExpression(cronExpression); + } + + /** + * 杩斿洖涓涓瓧绗︿覆鍊,琛ㄧず璇ユ秷鎭棤鏁圕ron琛ㄨ揪寮忕粰鍑烘湁鏁堟 + * + * @param cronExpression Cron琛ㄨ揪寮 + * @return String 鏃犳晥鏃惰繑鍥炶〃杈惧紡閿欒鎻忚堪,濡傛灉鏈夋晥杩斿洖null + */ + public static String getInvalidMessage(String cronExpression) { + try { + new CronExpression(cronExpression); + return null; + } catch (ParseException pe) { + return pe.getMessage(); + } + } + + /** + * 杩斿洖涓嬩竴涓墽琛屾椂闂存牴鎹粰瀹氱殑Cron琛ㄨ揪寮 + * + * @param cronExpression Cron琛ㄨ揪寮 + * @return Date 涓嬫Cron琛ㄨ揪寮忔墽琛屾椂闂 + */ + public static Date getNextExecution(String cronExpression) { + try { + CronExpression cron = new CronExpression(cronExpression); + return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); + } catch (ParseException e) { + throw new IllegalArgumentException(e.getMessage()); + } + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/util/JobInvokeUtil.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/JobInvokeUtil.java new file mode 100644 index 000000000..4340497bc --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/JobInvokeUtil.java @@ -0,0 +1,159 @@ +package com.jsowell.quartz.util; + +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.spring.SpringUtils; +import com.jsowell.quartz.domain.SysJob; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.LinkedList; +import java.util.List; + +/** + * 浠诲姟鎵ц宸ュ叿 + * + * @author jsowell + */ +public class JobInvokeUtil { + /** + * 鎵ц鏂规硶 + * + * @param sysJob 绯荤粺浠诲姟 + */ + public static void invokeMethod(SysJob sysJob) throws Exception { + String invokeTarget = sysJob.getInvokeTarget(); + String beanName = getBeanName(invokeTarget); + String methodName = getMethodName(invokeTarget); + List methodParams = getMethodParams(invokeTarget); + + if (!isValidClassName(beanName)) { + Object bean = SpringUtils.getBean(beanName); + invokeMethod(bean, methodName, methodParams); + } else { + Object bean = Class.forName(beanName).newInstance(); + invokeMethod(bean, methodName, methodParams); + } + } + + /** + * 璋冪敤浠诲姟鏂规硶 + * + * @param bean 鐩爣瀵硅薄 + * @param methodName 鏂规硶鍚嶇О + * @param methodParams 鏂规硶鍙傛暟 + */ + private static void invokeMethod(Object bean, String methodName, List methodParams) + throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) { + Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams)); + method.invoke(bean, getMethodParamsValue(methodParams)); + } else { + Method method = bean.getClass().getDeclaredMethod(methodName); + method.invoke(bean); + } + } + + /** + * 鏍¢獙鏄惁涓轰负class鍖呭悕 + * + * @param invokeTarget 鍚嶇О + * @return true鏄 false鍚 + */ + public static boolean isValidClassName(String invokeTarget) { + return StringUtils.countMatches(invokeTarget, ".") > 1; + } + + /** + * 鑾峰彇bean鍚嶇О + * + * @param invokeTarget 鐩爣瀛楃涓 + * @return bean鍚嶇О + */ + public static String getBeanName(String invokeTarget) { + String beanName = StringUtils.substringBefore(invokeTarget, "("); + return StringUtils.substringBeforeLast(beanName, "."); + } + + /** + * 鑾峰彇bean鏂规硶 + * + * @param invokeTarget 鐩爣瀛楃涓 + * @return method鏂规硶 + */ + public static String getMethodName(String invokeTarget) { + String methodName = StringUtils.substringBefore(invokeTarget, "("); + return StringUtils.substringAfterLast(methodName, "."); + } + + /** + * 鑾峰彇method鏂规硶鍙傛暟鐩稿叧鍒楄〃 + * + * @param invokeTarget 鐩爣瀛楃涓 + * @return method鏂规硶鐩稿叧鍙傛暟鍒楄〃 + */ + public static List getMethodParams(String invokeTarget) { + String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")"); + if (StringUtils.isEmpty(methodStr)) { + return null; + } + String[] methodParams = methodStr.split(",(?=([^\"']*[\"'][^\"']*[\"'])*[^\"']*$)"); + List classs = new LinkedList<>(); + for (int i = 0; i < methodParams.length; i++) { + String str = StringUtils.trimToEmpty(methodParams[i]); + // String瀛楃涓茬被鍨嬶紝浠'鎴"寮澶 + if (StringUtils.startsWithAny(str, "'", "\"")) { + classs.add(new Object[]{StringUtils.substring(str, 1, str.length() - 1), String.class}); + } + // boolean甯冨皵绫诲瀷锛岀瓑浜巘rue鎴栬協alse + else if ("true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str)) { + classs.add(new Object[]{Boolean.valueOf(str), Boolean.class}); + } + // long闀挎暣褰紝浠缁撳熬 + else if (StringUtils.endsWith(str, "L")) { + classs.add(new Object[]{Long.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Long.class}); + } + // double娴偣绫诲瀷锛屼互D缁撳熬 + else if (StringUtils.endsWith(str, "D")) { + classs.add(new Object[]{Double.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Double.class}); + } + // 鍏朵粬绫诲瀷褰掔被涓烘暣褰 + else { + classs.add(new Object[]{Integer.valueOf(str), Integer.class}); + } + } + return classs; + } + + /** + * 鑾峰彇鍙傛暟绫诲瀷 + * + * @param methodParams 鍙傛暟鐩稿叧鍒楄〃 + * @return 鍙傛暟绫诲瀷鍒楄〃 + */ + public static Class[] getMethodParamsType(List methodParams) { + Class[] classs = new Class[methodParams.size()]; + int index = 0; + for (Object[] os : methodParams) { + classs[index] = (Class) os[1]; + index++; + } + return classs; + } + + /** + * 鑾峰彇鍙傛暟鍊 + * + * @param methodParams 鍙傛暟鐩稿叧鍒楄〃 + * @return 鍙傛暟鍊煎垪琛 + */ + public static Object[] getMethodParamsValue(List methodParams) { + Object[] classs = new Object[methodParams.size()]; + int index = 0; + for (Object[] os : methodParams) { + classs[index] = (Object) os[0]; + index++; + } + return classs; + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/util/QuartzDisallowConcurrentExecution.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/QuartzDisallowConcurrentExecution.java new file mode 100644 index 000000000..03cff007d --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/QuartzDisallowConcurrentExecution.java @@ -0,0 +1,18 @@ +package com.jsowell.quartz.util; + +import org.quartz.DisallowConcurrentExecution; +import org.quartz.JobExecutionContext; +import com.jsowell.quartz.domain.SysJob; + +/** + * 瀹氭椂浠诲姟澶勭悊锛堢姝㈠苟鍙戞墽琛岋級 + * + * @author jsowell + */ +@DisallowConcurrentExecution +public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob { + @Override + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception { + JobInvokeUtil.invokeMethod(sysJob); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/util/QuartzJobExecution.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/QuartzJobExecution.java new file mode 100644 index 000000000..c6302e16b --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/QuartzJobExecution.java @@ -0,0 +1,16 @@ +package com.jsowell.quartz.util; + +import org.quartz.JobExecutionContext; +import com.jsowell.quartz.domain.SysJob; + +/** + * 瀹氭椂浠诲姟澶勭悊锛堝厑璁稿苟鍙戞墽琛岋級 + * + * @author jsowell + */ +public class QuartzJobExecution extends AbstractQuartzJob { + @Override + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception { + JobInvokeUtil.invokeMethod(sysJob); + } +} diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/util/ScheduleUtils.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/ScheduleUtils.java new file mode 100644 index 000000000..3bd9fff82 --- /dev/null +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/util/ScheduleUtils.java @@ -0,0 +1,126 @@ +package com.jsowell.quartz.util; + +import org.quartz.CronScheduleBuilder; +import org.quartz.CronTrigger; +import org.quartz.Job; +import org.quartz.JobBuilder; +import org.quartz.JobDetail; +import org.quartz.JobKey; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.TriggerBuilder; +import org.quartz.TriggerKey; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.constant.ScheduleConstants; +import com.jsowell.common.exception.job.TaskException; +import com.jsowell.common.exception.job.TaskException.Code; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.spring.SpringUtils; +import com.jsowell.quartz.domain.SysJob; + +/** + * 瀹氭椂浠诲姟宸ュ叿绫 + * + * @author jsowell + */ +public class ScheduleUtils { + /** + * 寰楀埌quartz浠诲姟绫 + * + * @param sysJob 鎵ц璁″垝 + * @return 鍏蜂綋鎵ц浠诲姟绫 + */ + private static Class getQuartzJobClass(SysJob sysJob) { + boolean isConcurrent = "0".equals(sysJob.getConcurrent()); + return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class; + } + + /** + * 鏋勫缓浠诲姟瑙﹀彂瀵硅薄 + */ + public static TriggerKey getTriggerKey(Long jobId, String jobGroup) { + return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); + } + + /** + * 鏋勫缓浠诲姟閿璞 + */ + public static JobKey getJobKey(Long jobId, String jobGroup) { + return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); + } + + /** + * 鍒涘缓瀹氭椂浠诲姟 + */ + public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException { + Class jobClass = getQuartzJobClass(job); + // 鏋勫缓job淇℃伅 + Long jobId = job.getJobId(); + String jobGroup = job.getJobGroup(); + JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); + + // 琛ㄨ揪寮忚皟搴︽瀯寤哄櫒 + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); + cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder); + + // 鎸夋柊鐨刢ronExpression琛ㄨ揪寮忔瀯寤轰竴涓柊鐨則rigger + CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) + .withSchedule(cronScheduleBuilder).build(); + + // 鏀惧叆鍙傛暟锛岃繍琛屾椂鐨勬柟娉曞彲浠ヨ幏鍙 + jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); + + // 鍒ゆ柇鏄惁瀛樺湪 + if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { + // 闃叉鍒涘缓鏃跺瓨鍦ㄦ暟鎹棶棰 鍏堢Щ闄わ紝鐒跺悗鍦ㄦ墽琛屽垱寤烘搷浣 + scheduler.deleteJob(getJobKey(jobId, jobGroup)); + } + + // 鍒ゆ柇浠诲姟鏄惁杩囨湡 + if (StringUtils.isNotNull(CronUtils.getNextExecution(job.getCronExpression()))) { + // 鎵ц璋冨害浠诲姟 + scheduler.scheduleJob(jobDetail, trigger); + } + + // 鏆傚仠浠诲姟 + if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) { + scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); + } + } + + /** + * 璁剧疆瀹氭椂浠诲姟绛栫暐 + */ + public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb) + throws TaskException { + switch (job.getMisfirePolicy()) { + case ScheduleConstants.MISFIRE_DEFAULT: + return cb; + case ScheduleConstants.MISFIRE_IGNORE_MISFIRES: + return cb.withMisfireHandlingInstructionIgnoreMisfires(); + case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED: + return cb.withMisfireHandlingInstructionFireAndProceed(); + case ScheduleConstants.MISFIRE_DO_NOTHING: + return cb.withMisfireHandlingInstructionDoNothing(); + default: + throw new TaskException("The task misfire policy '" + job.getMisfirePolicy() + + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR); + } + } + + /** + * 妫鏌ュ寘鍚嶆槸鍚︿负鐧藉悕鍗曢厤缃 + * + * @param invokeTarget 鐩爣瀛楃涓 + * @return 缁撴灉 + */ + public static boolean whiteList(String invokeTarget) { + String packageName = StringUtils.substringBefore(invokeTarget, "("); + int count = StringUtils.countMatches(packageName, "."); + if (count > 1) { + return StringUtils.containsAnyIgnoreCase(invokeTarget, Constants.JOB_WHITELIST_STR); + } + Object obj = SpringUtils.getBean(StringUtils.split(invokeTarget, ".")[0]); + return StringUtils.containsAnyIgnoreCase(obj.getClass().getPackage().getName(), Constants.JOB_WHITELIST_STR); + } +} diff --git a/jsowell-quartz/src/main/resources/mapper/quartz/SysJobLogMapper.xml b/jsowell-quartz/src/main/resources/mapper/quartz/SysJobLogMapper.xml new file mode 100644 index 000000000..1bf62e7a1 --- /dev/null +++ b/jsowell-quartz/src/main/resources/mapper/quartz/SysJobLogMapper.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + select job_log_id, job_name, job_group, invoke_target, job_message, status, exception_info, create_time + from sys_job_log + + + + + + + + + + delete from sys_job_log where job_log_id = #{jobLogId} + + + + delete from sys_job_log where job_log_id in + + #{jobLogId} + + + + + truncate table sys_job_log + + + + insert into sys_job_log( + job_log_id, + job_name, + job_group, + invoke_target, + job_message, + status, + exception_info, + create_time + )values( + #{jobLogId}, + #{jobName}, + #{jobGroup}, + #{invokeTarget}, + #{jobMessage}, + #{status}, + #{exceptionInfo}, + sysdate() + ) + + + \ No newline at end of file diff --git a/jsowell-quartz/src/main/resources/mapper/quartz/SysJobMapper.xml b/jsowell-quartz/src/main/resources/mapper/quartz/SysJobMapper.xml new file mode 100644 index 000000000..80bde7a65 --- /dev/null +++ b/jsowell-quartz/src/main/resources/mapper/quartz/SysJobMapper.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark + from sys_job + + + + + + + + + + delete from sys_job where job_id = #{jobId} + + + + delete from sys_job where job_id in + + #{jobId} + + + + + update sys_job + + job_name = #{jobName}, + job_group = #{jobGroup}, + invoke_target = #{invokeTarget}, + cron_expression = #{cronExpression}, + misfire_policy = #{misfirePolicy}, + concurrent = #{concurrent}, + status = #{status}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where job_id = #{jobId} + + + + insert into sys_job( + job_id, + job_name, + job_group, + invoke_target, + cron_expression, + misfire_policy, + concurrent, + status, + remark, + create_by, + create_time + )values( + #{jobId}, + #{jobName}, + #{jobGroup}, + #{invokeTarget}, + #{cronExpression}, + #{misfirePolicy}, + #{concurrent}, + #{status}, + #{remark}, + #{createBy}, + sysdate() + ) + + + \ No newline at end of file diff --git a/jsowell-system/pom.xml b/jsowell-system/pom.xml new file mode 100644 index 000000000..15d524f04 --- /dev/null +++ b/jsowell-system/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + jsowell-charger-web + com.jsowell + 1.0.0 + + + jsowell-system + + + system绯荤粺妯″潡 + + + + + + + com.jsowell + jsowell-common + + + + org.projectlombok + lombok + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + /src/test/** + + utf-8 + + + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysCache.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysCache.java new file mode 100644 index 000000000..298000e2f --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysCache.java @@ -0,0 +1,77 @@ +package com.jsowell.system.domain; + +import com.jsowell.common.util.StringUtils; + +/** + * 缂撳瓨淇℃伅 + * + * @author jsowell + */ +public class SysCache { + /** + * 缂撳瓨鍚嶇О + */ + private String cacheName = ""; + + /** + * 缂撳瓨閿悕 + */ + private String cacheKey = ""; + + /** + * 缂撳瓨鍐呭 + */ + private String cacheValue = ""; + + /** + * 澶囨敞 + */ + private String remark = ""; + + public SysCache() { + + } + + public SysCache(String cacheName, String remark) { + this.cacheName = cacheName; + this.remark = remark; + } + + public SysCache(String cacheName, String cacheKey, String cacheValue) { + this.cacheName = StringUtils.replace(cacheName, ":", ""); + this.cacheKey = StringUtils.replace(cacheKey, cacheName, ""); + this.cacheValue = cacheValue; + } + + public String getCacheName() { + return cacheName; + } + + public void setCacheName(String cacheName) { + this.cacheName = cacheName; + } + + public String getCacheKey() { + return cacheKey; + } + + public void setCacheKey(String cacheKey) { + this.cacheKey = cacheKey; + } + + public String getCacheValue() { + return cacheValue; + } + + public void setCacheValue(String cacheValue) { + this.cacheValue = cacheValue; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysConfig.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysConfig.java new file mode 100644 index 000000000..adb5dadce --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysConfig.java @@ -0,0 +1,111 @@ +package com.jsowell.system.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +/** + * 鍙傛暟閰嶇疆琛 sys_config + * + * @author jsowell + */ +public class SysConfig extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 鍙傛暟涓婚敭 + */ + @Excel(name = "鍙傛暟涓婚敭", cellType = ColumnType.NUMERIC) + private Long configId; + + /** + * 鍙傛暟鍚嶇О + */ + @Excel(name = "鍙傛暟鍚嶇О") + private String configName; + + /** + * 鍙傛暟閿悕 + */ + @Excel(name = "鍙傛暟閿悕") + private String configKey; + + /** + * 鍙傛暟閿 + */ + @Excel(name = "鍙傛暟閿") + private String configValue; + + /** + * 绯荤粺鍐呯疆锛圷鏄 N鍚︼級 + */ + @Excel(name = "绯荤粺鍐呯疆", readConverterExp = "Y=鏄,N=鍚") + private String configType; + + public Long getConfigId() { + return configId; + } + + public void setConfigId(Long configId) { + this.configId = configId; + } + + @NotBlank(message = "鍙傛暟鍚嶇О涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "鍙傛暟鍚嶇О涓嶈兘瓒呰繃100涓瓧绗") + public String getConfigName() { + return configName; + } + + public void setConfigName(String configName) { + this.configName = configName; + } + + @NotBlank(message = "鍙傛暟閿悕闀垮害涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "鍙傛暟閿悕闀垮害涓嶈兘瓒呰繃100涓瓧绗") + public String getConfigKey() { + return configKey; + } + + public void setConfigKey(String configKey) { + this.configKey = configKey; + } + + @NotBlank(message = "鍙傛暟閿间笉鑳戒负绌") + @Size(min = 0, max = 500, message = "鍙傛暟閿奸暱搴︿笉鑳借秴杩500涓瓧绗") + public String getConfigValue() { + return configValue; + } + + public void setConfigValue(String configValue) { + this.configValue = configValue; + } + + public String getConfigType() { + return configType; + } + + public void setConfigType(String configType) { + this.configType = configType; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("configId", getConfigId()) + .append("configName", getConfigName()) + .append("configKey", getConfigKey()) + .append("configValue", getConfigValue()) + .append("configType", getConfigType()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysLogininfor.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysLogininfor.java new file mode 100644 index 000000000..cb880e4ef --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysLogininfor.java @@ -0,0 +1,144 @@ +package com.jsowell.system.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.core.domain.BaseEntity; + +import java.util.Date; + +/** + * 绯荤粺璁块棶璁板綍琛 sys_logininfor + * + * @author jsowell + */ +public class SysLogininfor extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @Excel(name = "搴忓彿", cellType = ColumnType.NUMERIC) + private Long infoId; + + /** + * 鐢ㄦ埛璐﹀彿 + */ + @Excel(name = "鐢ㄦ埛璐﹀彿") + private String userName; + + /** + * 鐧诲綍鐘舵 0鎴愬姛 1澶辫触 + */ + @Excel(name = "鐧诲綍鐘舵", readConverterExp = "0=鎴愬姛,1=澶辫触") + private String status; + + /** + * 鐧诲綍IP鍦板潃 + */ + @Excel(name = "鐧诲綍鍦板潃") + private String ipaddr; + + /** + * 鐧诲綍鍦扮偣 + */ + @Excel(name = "鐧诲綍鍦扮偣") + private String loginLocation; + + /** + * 娴忚鍣ㄧ被鍨 + */ + @Excel(name = "娴忚鍣") + private String browser; + + /** + * 鎿嶄綔绯荤粺 + */ + @Excel(name = "鎿嶄綔绯荤粺") + private String os; + + /** + * 鎻愮ず娑堟伅 + */ + @Excel(name = "鎻愮ず娑堟伅") + private String msg; + + /** + * 璁块棶鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "璁块棶鏃堕棿", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date loginTime; + + public Long getInfoId() { + return infoId; + } + + public void setInfoId(Long infoId) { + this.infoId = infoId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getIpaddr() { + return ipaddr; + } + + public void setIpaddr(String ipaddr) { + this.ipaddr = ipaddr; + } + + public String getLoginLocation() { + return loginLocation; + } + + public void setLoginLocation(String loginLocation) { + this.loginLocation = loginLocation; + } + + public String getBrowser() { + return browser; + } + + public void setBrowser(String browser) { + this.browser = browser; + } + + public String getOs() { + return os; + } + + public void setOs(String os) { + this.os = os; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public Date getLoginTime() { + return loginTime; + } + + public void setLoginTime(Date loginTime) { + this.loginTime = loginTime; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysNotice.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysNotice.java new file mode 100644 index 000000000..bc034672e --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysNotice.java @@ -0,0 +1,102 @@ +package com.jsowell.system.domain; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.jsowell.common.core.domain.BaseEntity; +import com.jsowell.common.xss.Xss; + +/** + * 閫氱煡鍏憡琛 sys_notice + * + * @author jsowell + */ +public class SysNotice extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 鍏憡ID + */ + private Long noticeId; + + /** + * 鍏憡鏍囬 + */ + private String noticeTitle; + + /** + * 鍏憡绫诲瀷锛1閫氱煡 2鍏憡锛 + */ + private String noticeType; + + /** + * 鍏憡鍐呭 + */ + private String noticeContent; + + /** + * 鍏憡鐘舵侊紙0姝e父 1鍏抽棴锛 + */ + private String status; + + public Long getNoticeId() { + return noticeId; + } + + public void setNoticeId(Long noticeId) { + this.noticeId = noticeId; + } + + public void setNoticeTitle(String noticeTitle) { + this.noticeTitle = noticeTitle; + } + + @Xss(message = "鍏憡鏍囬涓嶈兘鍖呭惈鑴氭湰瀛楃") + @NotBlank(message = "鍏憡鏍囬涓嶈兘涓虹┖") + @Size(min = 0, max = 50, message = "鍏憡鏍囬涓嶈兘瓒呰繃50涓瓧绗") + public String getNoticeTitle() { + return noticeTitle; + } + + public void setNoticeType(String noticeType) { + this.noticeType = noticeType; + } + + public String getNoticeType() { + return noticeType; + } + + public void setNoticeContent(String noticeContent) { + this.noticeContent = noticeContent; + } + + public String getNoticeContent() { + return noticeContent; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("noticeId", getNoticeId()) + .append("noticeTitle", getNoticeTitle()) + .append("noticeType", getNoticeType()) + .append("noticeContent", getNoticeContent()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysOperLog.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysOperLog.java new file mode 100644 index 000000000..ec7bd2cc1 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysOperLog.java @@ -0,0 +1,255 @@ +package com.jsowell.system.domain; + +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.core.domain.BaseEntity; + +/** + * 鎿嶄綔鏃ュ織璁板綍琛 oper_log + * + * @author jsowell + */ +public class SysOperLog extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 鏃ュ織涓婚敭 + */ + @Excel(name = "鎿嶄綔搴忓彿", cellType = ColumnType.NUMERIC) + private Long operId; + + /** + * 鎿嶄綔妯″潡 + */ + @Excel(name = "鎿嶄綔妯″潡") + private String title; + + /** + * 涓氬姟绫诲瀷锛0鍏跺畠 1鏂板 2淇敼 3鍒犻櫎锛 + */ + @Excel(name = "涓氬姟绫诲瀷", readConverterExp = "0=鍏跺畠,1=鏂板,2=淇敼,3=鍒犻櫎,4=鎺堟潈,5=瀵煎嚭,6=瀵煎叆,7=寮洪,8=鐢熸垚浠g爜,9=娓呯┖鏁版嵁") + private Integer businessType; + + /** + * 涓氬姟绫诲瀷鏁扮粍 + */ + private Integer[] businessTypes; + + /** + * 璇锋眰鏂规硶 + */ + @Excel(name = "璇锋眰鏂规硶") + private String method; + + /** + * 璇锋眰鏂瑰紡 + */ + @Excel(name = "璇锋眰鏂瑰紡") + private String requestMethod; + + /** + * 鎿嶄綔绫诲埆锛0鍏跺畠 1鍚庡彴鐢ㄦ埛 2鎵嬫満绔敤鎴凤級 + */ + @Excel(name = "鎿嶄綔绫诲埆", readConverterExp = "0=鍏跺畠,1=鍚庡彴鐢ㄦ埛,2=鎵嬫満绔敤鎴") + private Integer operatorType; + + /** + * 鎿嶄綔浜哄憳 + */ + @Excel(name = "鎿嶄綔浜哄憳") + private String operName; + + /** + * 閮ㄩ棬鍚嶇О + */ + @Excel(name = "閮ㄩ棬鍚嶇О") + private String deptName; + + /** + * 璇锋眰url + */ + @Excel(name = "璇锋眰鍦板潃") + private String operUrl; + + /** + * 鎿嶄綔鍦板潃 + */ + @Excel(name = "鎿嶄綔鍦板潃") + private String operIp; + + /** + * 鎿嶄綔鍦扮偣 + */ + @Excel(name = "鎿嶄綔鍦扮偣") + private String operLocation; + + /** + * 璇锋眰鍙傛暟 + */ + @Excel(name = "璇锋眰鍙傛暟") + private String operParam; + + /** + * 杩斿洖鍙傛暟 + */ + @Excel(name = "杩斿洖鍙傛暟") + private String jsonResult; + + /** + * 鎿嶄綔鐘舵侊紙0姝e父 1寮傚父锛 + */ + @Excel(name = "鐘舵", readConverterExp = "0=姝e父,1=寮傚父") + private Integer status; + + /** + * 閿欒娑堟伅 + */ + @Excel(name = "閿欒娑堟伅") + private String errorMsg; + + /** + * 鎿嶄綔鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "鎿嶄綔鏃堕棿", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date operTime; + + public Long getOperId() { + return operId; + } + + public void setOperId(Long operId) { + this.operId = operId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Integer getBusinessType() { + return businessType; + } + + public void setBusinessType(Integer businessType) { + this.businessType = businessType; + } + + public Integer[] getBusinessTypes() { + return businessTypes; + } + + public void setBusinessTypes(Integer[] businessTypes) { + this.businessTypes = businessTypes; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public String getRequestMethod() { + return requestMethod; + } + + public void setRequestMethod(String requestMethod) { + this.requestMethod = requestMethod; + } + + public Integer getOperatorType() { + return operatorType; + } + + public void setOperatorType(Integer operatorType) { + this.operatorType = operatorType; + } + + public String getOperName() { + return operName; + } + + public void setOperName(String operName) { + this.operName = operName; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getOperUrl() { + return operUrl; + } + + public void setOperUrl(String operUrl) { + this.operUrl = operUrl; + } + + public String getOperIp() { + return operIp; + } + + public void setOperIp(String operIp) { + this.operIp = operIp; + } + + public String getOperLocation() { + return operLocation; + } + + public void setOperLocation(String operLocation) { + this.operLocation = operLocation; + } + + public String getOperParam() { + return operParam; + } + + public void setOperParam(String operParam) { + this.operParam = operParam; + } + + public String getJsonResult() { + return jsonResult; + } + + public void setJsonResult(String jsonResult) { + this.jsonResult = jsonResult; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public String getErrorMsg() { + return errorMsg; + } + + public void setErrorMsg(String errorMsg) { + this.errorMsg = errorMsg; + } + + public Date getOperTime() { + return operTime; + } + + public void setOperTime(Date operTime) { + this.operTime = operTime; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysPost.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysPost.java new file mode 100644 index 000000000..3ef9fc6d4 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysPost.java @@ -0,0 +1,123 @@ +package com.jsowell.system.domain; + +import com.jsowell.common.annotation.Excel; +import com.jsowell.common.annotation.Excel.ColumnType; +import com.jsowell.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +/** + * 宀椾綅琛 sys_post + * + * @author jsowell + */ +public class SysPost extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 宀椾綅搴忓彿 + */ + @Excel(name = "宀椾綅搴忓彿", cellType = ColumnType.NUMERIC) + private Long postId; + + /** + * 宀椾綅缂栫爜 + */ + @Excel(name = "宀椾綅缂栫爜") + private String postCode; + + /** + * 宀椾綅鍚嶇О + */ + @Excel(name = "宀椾綅鍚嶇О") + private String postName; + + /** + * 宀椾綅鎺掑簭 + */ + @Excel(name = "宀椾綅鎺掑簭") + private String postSort; + + /** + * 鐘舵侊紙0姝e父 1鍋滅敤锛 + */ + @Excel(name = "鐘舵", readConverterExp = "0=姝e父,1=鍋滅敤") + private String status; + + /** + * 鐢ㄦ埛鏄惁瀛樺湪姝ゅ矖浣嶆爣璇 榛樿涓嶅瓨鍦 + */ + private boolean flag = false; + + public Long getPostId() { + return postId; + } + + public void setPostId(Long postId) { + this.postId = postId; + } + + @NotBlank(message = "宀椾綅缂栫爜涓嶈兘涓虹┖") + @Size(min = 0, max = 64, message = "宀椾綅缂栫爜闀垮害涓嶈兘瓒呰繃64涓瓧绗") + public String getPostCode() { + return postCode; + } + + public void setPostCode(String postCode) { + this.postCode = postCode; + } + + @NotBlank(message = "宀椾綅鍚嶇О涓嶈兘涓虹┖") + @Size(min = 0, max = 50, message = "宀椾綅鍚嶇О闀垮害涓嶈兘瓒呰繃50涓瓧绗") + public String getPostName() { + return postName; + } + + public void setPostName(String postName) { + this.postName = postName; + } + + @NotBlank(message = "鏄剧ず椤哄簭涓嶈兘涓虹┖") + public String getPostSort() { + return postSort; + } + + public void setPostSort(String postSort) { + this.postSort = postSort; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public boolean isFlag() { + return flag; + } + + public void setFlag(boolean flag) { + this.flag = flag; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("postId", getPostId()) + .append("postCode", getPostCode()) + .append("postName", getPostName()) + .append("postSort", getPostSort()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysRoleDept.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysRoleDept.java new file mode 100644 index 000000000..c47603301 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysRoleDept.java @@ -0,0 +1,45 @@ +package com.jsowell.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 瑙掕壊鍜岄儴闂ㄥ叧鑱 sys_role_dept + * + * @author jsowell + */ +public class SysRoleDept { + /** + * 瑙掕壊ID + */ + private Long roleId; + + /** + * 閮ㄩ棬ID + */ + private Long deptId; + + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("roleId", getRoleId()) + .append("deptId", getDeptId()) + .toString(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysRoleMenu.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysRoleMenu.java new file mode 100644 index 000000000..3fcd1678d --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysRoleMenu.java @@ -0,0 +1,45 @@ +package com.jsowell.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 瑙掕壊鍜岃彍鍗曞叧鑱 sys_role_menu + * + * @author jsowell + */ +public class SysRoleMenu { + /** + * 瑙掕壊ID + */ + private Long roleId; + + /** + * 鑿滃崟ID + */ + private Long menuId; + + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + public Long getMenuId() { + return menuId; + } + + public void setMenuId(Long menuId) { + this.menuId = menuId; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("roleId", getRoleId()) + .append("menuId", getMenuId()) + .toString(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserOnline.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserOnline.java new file mode 100644 index 000000000..1d8c9512f --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserOnline.java @@ -0,0 +1,112 @@ +package com.jsowell.system.domain; + +/** + * 褰撳墠鍦ㄧ嚎浼氳瘽 + * + * @author jsowell + */ +public class SysUserOnline { + /** + * 浼氳瘽缂栧彿 + */ + private String tokenId; + + /** + * 閮ㄩ棬鍚嶇О + */ + private String deptName; + + /** + * 鐢ㄦ埛鍚嶇О + */ + private String userName; + + /** + * 鐧诲綍IP鍦板潃 + */ + private String ipaddr; + + /** + * 鐧诲綍鍦板潃 + */ + private String loginLocation; + + /** + * 娴忚鍣ㄧ被鍨 + */ + private String browser; + + /** + * 鎿嶄綔绯荤粺 + */ + private String os; + + /** + * 鐧诲綍鏃堕棿 + */ + private Long loginTime; + + public String getTokenId() { + return tokenId; + } + + public void setTokenId(String tokenId) { + this.tokenId = tokenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getIpaddr() { + return ipaddr; + } + + public void setIpaddr(String ipaddr) { + this.ipaddr = ipaddr; + } + + public String getLoginLocation() { + return loginLocation; + } + + public void setLoginLocation(String loginLocation) { + this.loginLocation = loginLocation; + } + + public String getBrowser() { + return browser; + } + + public void setBrowser(String browser) { + this.browser = browser; + } + + public String getOs() { + return os; + } + + public void setOs(String os) { + this.os = os; + } + + public Long getLoginTime() { + return loginTime; + } + + public void setLoginTime(Long loginTime) { + this.loginTime = loginTime; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserPost.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserPost.java new file mode 100644 index 000000000..2e0322eb4 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserPost.java @@ -0,0 +1,45 @@ +package com.jsowell.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 鐢ㄦ埛鍜屽矖浣嶅叧鑱 sys_user_post + * + * @author jsowell + */ +public class SysUserPost { + /** + * 鐢ㄦ埛ID + */ + private Long userId; + + /** + * 宀椾綅ID + */ + private Long postId; + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getPostId() { + return postId; + } + + public void setPostId(Long postId) { + this.postId = postId; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("userId", getUserId()) + .append("postId", getPostId()) + .toString(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserRole.java b/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserRole.java new file mode 100644 index 000000000..a8de814d8 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/domain/SysUserRole.java @@ -0,0 +1,45 @@ +package com.jsowell.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 鐢ㄦ埛鍜岃鑹插叧鑱 sys_user_role + * + * @author jsowell + */ +public class SysUserRole { + /** + * 鐢ㄦ埛ID + */ + private Long userId; + + /** + * 瑙掕壊ID + */ + private Long roleId; + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) + .append("userId", getUserId()) + .append("roleId", getRoleId()) + .toString(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysConfigMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysConfigMapper.java new file mode 100644 index 000000000..aedfa29b6 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysConfigMapper.java @@ -0,0 +1,68 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysConfig; + +import java.util.List; + +/** + * 鍙傛暟閰嶇疆 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysConfigMapper { + /** + * 鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 鍙傛暟閰嶇疆淇℃伅 + */ + public SysConfig selectConfig(SysConfig config); + + /** + * 鏌ヨ鍙傛暟閰嶇疆鍒楄〃 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 鍙傛暟閰嶇疆闆嗗悎 + */ + public List selectConfigList(SysConfig config); + + /** + * 鏍规嵁閿悕鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configKey 鍙傛暟閿悕 + * @return 鍙傛暟閰嶇疆淇℃伅 + */ + public SysConfig checkConfigKeyUnique(String configKey); + + /** + * 鏂板鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + public int insertConfig(SysConfig config); + + /** + * 淇敼鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + public int updateConfig(SysConfig config); + + /** + * 鍒犻櫎鍙傛暟閰嶇疆 + * + * @param configId 鍙傛暟ID + * @return 缁撴灉 + */ + public int deleteConfigById(Long configId); + + /** + * 鎵归噺鍒犻櫎鍙傛暟淇℃伅 + * + * @param configIds 闇瑕佸垹闄ょ殑鍙傛暟ID + * @return 缁撴灉 + */ + public int deleteConfigByIds(Long[] configIds); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDeptMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDeptMapper.java new file mode 100644 index 000000000..c5f2604e1 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDeptMapper.java @@ -0,0 +1,118 @@ +package com.jsowell.system.mapper; + +import com.jsowell.common.core.domain.entity.SysDept; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 閮ㄩ棬绠$悊 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysDeptMapper { + /** + * 鏌ヨ閮ㄩ棬绠$悊鏁版嵁 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 閮ㄩ棬淇℃伅闆嗗悎 + */ + public List selectDeptList(SysDept dept); + + /** + * 鏍规嵁瑙掕壊ID鏌ヨ閮ㄩ棬鏍戜俊鎭 + * + * @param roleId 瑙掕壊ID + * @param deptCheckStrictly 閮ㄩ棬鏍戦夋嫨椤规槸鍚﹀叧鑱旀樉绀 + * @return 閫変腑閮ㄩ棬鍒楄〃 + */ + public List selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly); + + /** + * 鏍规嵁閮ㄩ棬ID鏌ヨ淇℃伅 + * + * @param deptId 閮ㄩ棬ID + * @return 閮ㄩ棬淇℃伅 + */ + public SysDept selectDeptById(Long deptId); + + /** + * 鏍规嵁ID鏌ヨ鎵鏈夊瓙閮ㄩ棬 + * + * @param deptId 閮ㄩ棬ID + * @return 閮ㄩ棬鍒楄〃 + */ + public List selectChildrenDeptById(Long deptId); + + /** + * 鏍规嵁ID鏌ヨ鎵鏈夊瓙閮ㄩ棬锛堟甯哥姸鎬侊級 + * + * @param deptId 閮ㄩ棬ID + * @return 瀛愰儴闂ㄦ暟 + */ + public int selectNormalChildrenDeptById(Long deptId); + + /** + * 鏄惁瀛樺湪瀛愯妭鐐 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 + */ + public int hasChildByDeptId(Long deptId); + + /** + * 鏌ヨ閮ㄩ棬鏄惁瀛樺湪鐢ㄦ埛 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 + */ + public int checkDeptExistUser(Long deptId); + + /** + * 鏍¢獙閮ㄩ棬鍚嶇О鏄惁鍞竴 + * + * @param deptName 閮ㄩ棬鍚嶇О + * @param parentId 鐖堕儴闂↖D + * @return 缁撴灉 + */ + public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); + + /** + * 鏂板閮ㄩ棬淇℃伅 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 缁撴灉 + */ + public int insertDept(SysDept dept); + + /** + * 淇敼閮ㄩ棬淇℃伅 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 缁撴灉 + */ + public int updateDept(SysDept dept); + + /** + * 淇敼鎵鍦ㄩ儴闂ㄦ甯哥姸鎬 + * + * @param deptIds 閮ㄩ棬ID缁 + */ + public void updateDeptStatusNormal(Long[] deptIds); + + /** + * 淇敼瀛愬厓绱犲叧绯 + * + * @param depts 瀛愬厓绱 + * @return 缁撴灉 + */ + public int updateDeptChildren(@Param("depts") List depts); + + /** + * 鍒犻櫎閮ㄩ棬绠$悊淇℃伅 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 + */ + public int deleteDeptById(Long deptId); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDictDataMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDictDataMapper.java new file mode 100644 index 000000000..8477cae79 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDictDataMapper.java @@ -0,0 +1,95 @@ +package com.jsowell.system.mapper; + +import com.jsowell.common.core.domain.entity.SysDictData; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 瀛楀吀琛 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysDictDataMapper { + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀鏁版嵁 + * + * @param dictData 瀛楀吀鏁版嵁淇℃伅 + * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅 + */ + public List selectDictDataList(SysDictData dictData); + + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅 + */ + public List selectDictDataByType(String dictType); + + /** + * 鏍规嵁瀛楀吀绫诲瀷鍜屽瓧鍏搁敭鍊兼煡璇㈠瓧鍏告暟鎹俊鎭 + * + * @param dictType 瀛楀吀绫诲瀷 + * @param dictValue 瀛楀吀閿 + * @return 瀛楀吀鏍囩 + */ + public String selectDictLabel(@Param("dictType") String dictType, @Param("dictValue") String dictValue); + + /** + * 鏍规嵁瀛楀吀鏁版嵁ID鏌ヨ淇℃伅 + * + * @param dictCode 瀛楀吀鏁版嵁ID + * @return 瀛楀吀鏁版嵁 + */ + public SysDictData selectDictDataById(Long dictCode); + + /** + * 鏌ヨ瀛楀吀鏁版嵁 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀鏁版嵁 + */ + public int countDictDataByType(String dictType); + + /** + * 閫氳繃瀛楀吀ID鍒犻櫎瀛楀吀鏁版嵁淇℃伅 + * + * @param dictCode 瀛楀吀鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteDictDataById(Long dictCode); + + /** + * 鎵归噺鍒犻櫎瀛楀吀鏁版嵁淇℃伅 + * + * @param dictCodes 闇瑕佸垹闄ょ殑瀛楀吀鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteDictDataByIds(Long[] dictCodes); + + /** + * 鏂板瀛楀吀鏁版嵁淇℃伅 + * + * @param dictData 瀛楀吀鏁版嵁淇℃伅 + * @return 缁撴灉 + */ + public int insertDictData(SysDictData dictData); + + /** + * 淇敼瀛楀吀鏁版嵁淇℃伅 + * + * @param dictData 瀛楀吀鏁版嵁淇℃伅 + * @return 缁撴灉 + */ + public int updateDictData(SysDictData dictData); + + /** + * 鍚屾淇敼瀛楀吀绫诲瀷 + * + * @param oldDictType 鏃у瓧鍏哥被鍨 + * @param newDictType 鏂版棫瀛楀吀绫诲瀷 + * @return 缁撴灉 + */ + public int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDictTypeMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDictTypeMapper.java new file mode 100644 index 000000000..7ac992590 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysDictTypeMapper.java @@ -0,0 +1,83 @@ +package com.jsowell.system.mapper; + +import com.jsowell.common.core.domain.entity.SysDictType; + +import java.util.List; + +/** + * 瀛楀吀琛 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysDictTypeMapper { + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀绫诲瀷 + * + * @param dictType 瀛楀吀绫诲瀷淇℃伅 + * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 + */ + public List selectDictTypeList(SysDictType dictType); + + /** + * 鏍规嵁鎵鏈夊瓧鍏哥被鍨 + * + * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 + */ + public List selectDictTypeAll(); + + /** + * 鏍规嵁瀛楀吀绫诲瀷ID鏌ヨ淇℃伅 + * + * @param dictId 瀛楀吀绫诲瀷ID + * @return 瀛楀吀绫诲瀷 + */ + public SysDictType selectDictTypeById(Long dictId); + + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ淇℃伅 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀绫诲瀷 + */ + public SysDictType selectDictTypeByType(String dictType); + + /** + * 閫氳繃瀛楀吀ID鍒犻櫎瀛楀吀淇℃伅 + * + * @param dictId 瀛楀吀ID + * @return 缁撴灉 + */ + public int deleteDictTypeById(Long dictId); + + /** + * 鎵归噺鍒犻櫎瀛楀吀绫诲瀷淇℃伅 + * + * @param dictIds 闇瑕佸垹闄ょ殑瀛楀吀ID + * @return 缁撴灉 + */ + public int deleteDictTypeByIds(Long[] dictIds); + + /** + * 鏂板瀛楀吀绫诲瀷淇℃伅 + * + * @param dictType 瀛楀吀绫诲瀷淇℃伅 + * @return 缁撴灉 + */ + public int insertDictType(SysDictType dictType); + + /** + * 淇敼瀛楀吀绫诲瀷淇℃伅 + * + * @param dictType 瀛楀吀绫诲瀷淇℃伅 + * @return 缁撴灉 + */ + public int updateDictType(SysDictType dictType); + + /** + * 鏍¢獙瀛楀吀绫诲瀷绉版槸鍚﹀敮涓 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 缁撴灉 + */ + public SysDictType checkDictTypeUnique(String dictType); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysLogininforMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysLogininforMapper.java new file mode 100644 index 000000000..2be3106ac --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysLogininforMapper.java @@ -0,0 +1,42 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysLogininfor; + +import java.util.List; + +/** + * 绯荤粺璁块棶鏃ュ織鎯呭喌淇℃伅 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysLogininforMapper { + /** + * 鏂板绯荤粺鐧诲綍鏃ュ織 + * + * @param logininfor 璁块棶鏃ュ織瀵硅薄 + */ + public void insertLogininfor(SysLogininfor logininfor); + + /** + * 鏌ヨ绯荤粺鐧诲綍鏃ュ織闆嗗悎 + * + * @param logininfor 璁块棶鏃ュ織瀵硅薄 + * @return 鐧诲綍璁板綍闆嗗悎 + */ + public List selectLogininforList(SysLogininfor logininfor); + + /** + * 鎵归噺鍒犻櫎绯荤粺鐧诲綍鏃ュ織 + * + * @param infoIds 闇瑕佸垹闄ょ殑鐧诲綍鏃ュ織ID + * @return 缁撴灉 + */ + public int deleteLogininforByIds(Long[] infoIds); + + /** + * 娓呯┖绯荤粺鐧诲綍鏃ュ織 + * + * @return 缁撴灉 + */ + public int cleanLogininfor(); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysMenuMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysMenuMapper.java new file mode 100644 index 000000000..b102d1eca --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysMenuMapper.java @@ -0,0 +1,117 @@ +package com.jsowell.system.mapper; + +import com.jsowell.common.core.domain.entity.SysMenu; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 鑿滃崟琛 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysMenuMapper { + /** + * 鏌ヨ绯荤粺鑿滃崟鍒楄〃 + * + * @param menu 鑿滃崟淇℃伅 + * @return 鑿滃崟鍒楄〃 + */ + public List selectMenuList(SysMenu menu); + + /** + * 鏍规嵁鐢ㄦ埛鎵鏈夋潈闄 + * + * @return 鏉冮檺鍒楄〃 + */ + public List selectMenuPerms(); + + /** + * 鏍规嵁鐢ㄦ埛鏌ヨ绯荤粺鑿滃崟鍒楄〃 + * + * @param menu 鑿滃崟淇℃伅 + * @return 鑿滃崟鍒楄〃 + */ + public List selectMenuListByUserId(SysMenu menu); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鏉冮檺 + * + * @param userId 鐢ㄦ埛ID + * @return 鏉冮檺鍒楄〃 + */ + public List selectMenuPermsByUserId(Long userId); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鑿滃崟 + * + * @return 鑿滃崟鍒楄〃 + */ + public List selectMenuTreeAll(); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鑿滃崟 + * + * @param userId 鐢ㄦ埛ID + * @return 鑿滃崟鍒楄〃 + */ + public List selectMenuTreeByUserId(Long userId); + + /** + * 鏍规嵁瑙掕壊ID鏌ヨ鑿滃崟鏍戜俊鎭 + * + * @param roleId 瑙掕壊ID + * @param menuCheckStrictly 鑿滃崟鏍戦夋嫨椤规槸鍚﹀叧鑱旀樉绀 + * @return 閫変腑鑿滃崟鍒楄〃 + */ + public List selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly); + + /** + * 鏍规嵁鑿滃崟ID鏌ヨ淇℃伅 + * + * @param menuId 鑿滃崟ID + * @return 鑿滃崟淇℃伅 + */ + public SysMenu selectMenuById(Long menuId); + + /** + * 鏄惁瀛樺湪鑿滃崟瀛愯妭鐐 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 + */ + public int hasChildByMenuId(Long menuId); + + /** + * 鏂板鑿滃崟淇℃伅 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + public int insertMenu(SysMenu menu); + + /** + * 淇敼鑿滃崟淇℃伅 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + public int updateMenu(SysMenu menu); + + /** + * 鍒犻櫎鑿滃崟绠$悊淇℃伅 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 + */ + public int deleteMenuById(Long menuId); + + /** + * 鏍¢獙鑿滃崟鍚嶇О鏄惁鍞竴 + * + * @param menuName 鑿滃崟鍚嶇О + * @param parentId 鐖惰彍鍗旾D + * @return 缁撴灉 + */ + public SysMenu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysNoticeMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysNoticeMapper.java new file mode 100644 index 000000000..73c808545 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysNoticeMapper.java @@ -0,0 +1,60 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysNotice; + +import java.util.List; + +/** + * 閫氱煡鍏憡琛 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysNoticeMapper { + /** + * 鏌ヨ鍏憡淇℃伅 + * + * @param noticeId 鍏憡ID + * @return 鍏憡淇℃伅 + */ + public SysNotice selectNoticeById(Long noticeId); + + /** + * 鏌ヨ鍏憡鍒楄〃 + * + * @param notice 鍏憡淇℃伅 + * @return 鍏憡闆嗗悎 + */ + public List selectNoticeList(SysNotice notice); + + /** + * 鏂板鍏憡 + * + * @param notice 鍏憡淇℃伅 + * @return 缁撴灉 + */ + public int insertNotice(SysNotice notice); + + /** + * 淇敼鍏憡 + * + * @param notice 鍏憡淇℃伅 + * @return 缁撴灉 + */ + public int updateNotice(SysNotice notice); + + /** + * 鎵归噺鍒犻櫎鍏憡 + * + * @param noticeId 鍏憡ID + * @return 缁撴灉 + */ + public int deleteNoticeById(Long noticeId); + + /** + * 鎵归噺鍒犻櫎鍏憡淇℃伅 + * + * @param noticeIds 闇瑕佸垹闄ょ殑鍏憡ID + * @return 缁撴灉 + */ + public int deleteNoticeByIds(Long[] noticeIds); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysOperLogMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysOperLogMapper.java new file mode 100644 index 000000000..edef0b756 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysOperLogMapper.java @@ -0,0 +1,48 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysOperLog; + +import java.util.List; + +/** + * 鎿嶄綔鏃ュ織 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysOperLogMapper { + /** + * 鏂板鎿嶄綔鏃ュ織 + * + * @param operLog 鎿嶄綔鏃ュ織瀵硅薄 + */ + public void insertOperlog(SysOperLog operLog); + + /** + * 鏌ヨ绯荤粺鎿嶄綔鏃ュ織闆嗗悎 + * + * @param operLog 鎿嶄綔鏃ュ織瀵硅薄 + * @return 鎿嶄綔鏃ュ織闆嗗悎 + */ + public List selectOperLogList(SysOperLog operLog); + + /** + * 鎵归噺鍒犻櫎绯荤粺鎿嶄綔鏃ュ織 + * + * @param operIds 闇瑕佸垹闄ょ殑鎿嶄綔鏃ュ織ID + * @return 缁撴灉 + */ + public int deleteOperLogByIds(Long[] operIds); + + /** + * 鏌ヨ鎿嶄綔鏃ュ織璇︾粏 + * + * @param operId 鎿嶄綔ID + * @return 鎿嶄綔鏃ュ織瀵硅薄 + */ + public SysOperLog selectOperLogById(Long operId); + + /** + * 娓呯┖鎿嶄綔鏃ュ織 + */ + public void cleanOperLog(); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysPostMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysPostMapper.java new file mode 100644 index 000000000..e7c722feb --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysPostMapper.java @@ -0,0 +1,99 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysPost; + +import java.util.List; + +/** + * 宀椾綅淇℃伅 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysPostMapper { + /** + * 鏌ヨ宀椾綅鏁版嵁闆嗗悎 + * + * @param post 宀椾綅淇℃伅 + * @return 宀椾綅鏁版嵁闆嗗悎 + */ + public List selectPostList(SysPost post); + + /** + * 鏌ヨ鎵鏈夊矖浣 + * + * @return 宀椾綅鍒楄〃 + */ + public List selectPostAll(); + + /** + * 閫氳繃宀椾綅ID鏌ヨ宀椾綅淇℃伅 + * + * @param postId 宀椾綅ID + * @return 瑙掕壊瀵硅薄淇℃伅 + */ + public SysPost selectPostById(Long postId); + + /** + * 鏍规嵁鐢ㄦ埛ID鑾峰彇宀椾綅閫夋嫨妗嗗垪琛 + * + * @param userId 鐢ㄦ埛ID + * @return 閫変腑宀椾綅ID鍒楄〃 + */ + public List selectPostListByUserId(Long userId); + + /** + * 鏌ヨ鐢ㄦ埛鎵灞炲矖浣嶇粍 + * + * @param userName 鐢ㄦ埛鍚 + * @return 缁撴灉 + */ + public List selectPostsByUserName(String userName); + + /** + * 鍒犻櫎宀椾綅淇℃伅 + * + * @param postId 宀椾綅ID + * @return 缁撴灉 + */ + public int deletePostById(Long postId); + + /** + * 鎵归噺鍒犻櫎宀椾綅淇℃伅 + * + * @param postIds 闇瑕佸垹闄ょ殑宀椾綅ID + * @return 缁撴灉 + */ + public int deletePostByIds(Long[] postIds); + + /** + * 淇敼宀椾綅淇℃伅 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + public int updatePost(SysPost post); + + /** + * 鏂板宀椾綅淇℃伅 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + public int insertPost(SysPost post); + + /** + * 鏍¢獙宀椾綅鍚嶇О + * + * @param postName 宀椾綅鍚嶇О + * @return 缁撴灉 + */ + public SysPost checkPostNameUnique(String postName); + + /** + * 鏍¢獙宀椾綅缂栫爜 + * + * @param postCode 宀椾綅缂栫爜 + * @return 缁撴灉 + */ + public SysPost checkPostCodeUnique(String postCode); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleDeptMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleDeptMapper.java new file mode 100644 index 000000000..bd80611f5 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleDeptMapper.java @@ -0,0 +1,44 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysRoleDept; + +import java.util.List; + +/** + * 瑙掕壊涓庨儴闂ㄥ叧鑱旇〃 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysRoleDeptMapper { + /** + * 閫氳繃瑙掕壊ID鍒犻櫎瑙掕壊鍜岄儴闂ㄥ叧鑱 + * + * @param roleId 瑙掕壊ID + * @return 缁撴灉 + */ + public int deleteRoleDeptByRoleId(Long roleId); + + /** + * 鎵归噺鍒犻櫎瑙掕壊閮ㄩ棬鍏宠仈淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteRoleDept(Long[] ids); + + /** + * 鏌ヨ閮ㄩ棬浣跨敤鏁伴噺 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 + */ + public int selectCountRoleDeptByDeptId(Long deptId); + + /** + * 鎵归噺鏂板瑙掕壊閮ㄩ棬淇℃伅 + * + * @param roleDeptList 瑙掕壊閮ㄩ棬鍒楄〃 + * @return 缁撴灉 + */ + public int batchRoleDept(List roleDeptList); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleMapper.java new file mode 100644 index 000000000..525234c7a --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleMapper.java @@ -0,0 +1,107 @@ +package com.jsowell.system.mapper; + +import com.jsowell.common.core.domain.entity.SysRole; + +import java.util.List; + +/** + * 瑙掕壊琛 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysRoleMapper { + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瑙掕壊鏁版嵁 + * + * @param role 瑙掕壊淇℃伅 + * @return 瑙掕壊鏁版嵁闆嗗悎淇℃伅 + */ + public List selectRoleList(SysRole role); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ瑙掕壊 + * + * @param userId 鐢ㄦ埛ID + * @return 瑙掕壊鍒楄〃 + */ + public List selectRolePermissionByUserId(Long userId); + + /** + * 鏌ヨ鎵鏈夎鑹 + * + * @return 瑙掕壊鍒楄〃 + */ + public List selectRoleAll(); + + /** + * 鏍规嵁鐢ㄦ埛ID鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛 + * + * @param userId 鐢ㄦ埛ID + * @return 閫変腑瑙掕壊ID鍒楄〃 + */ + public List selectRoleListByUserId(Long userId); + + /** + * 閫氳繃瑙掕壊ID鏌ヨ瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @return 瑙掕壊瀵硅薄淇℃伅 + */ + public SysRole selectRoleById(Long roleId); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ瑙掕壊 + * + * @param userName 鐢ㄦ埛鍚 + * @return 瑙掕壊鍒楄〃 + */ + public List selectRolesByUserName(String userName); + + /** + * 鏍¢獙瑙掕壊鍚嶇О鏄惁鍞竴 + * + * @param roleName 瑙掕壊鍚嶇О + * @return 瑙掕壊淇℃伅 + */ + public SysRole checkRoleNameUnique(String roleName); + + /** + * 鏍¢獙瑙掕壊鏉冮檺鏄惁鍞竴 + * + * @param roleKey 瑙掕壊鏉冮檺 + * @return 瑙掕壊淇℃伅 + */ + public SysRole checkRoleKeyUnique(String roleKey); + + /** + * 淇敼瑙掕壊淇℃伅 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + public int updateRole(SysRole role); + + /** + * 鏂板瑙掕壊淇℃伅 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + public int insertRole(SysRole role); + + /** + * 閫氳繃瑙掕壊ID鍒犻櫎瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @return 缁撴灉 + */ + public int deleteRoleById(Long roleId); + + /** + * 鎵归噺鍒犻櫎瑙掕壊淇℃伅 + * + * @param roleIds 闇瑕佸垹闄ょ殑瑙掕壊ID + * @return 缁撴灉 + */ + public int deleteRoleByIds(Long[] roleIds); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleMenuMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleMenuMapper.java new file mode 100644 index 000000000..69ac6ec99 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysRoleMenuMapper.java @@ -0,0 +1,44 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysRoleMenu; + +import java.util.List; + +/** + * 瑙掕壊涓庤彍鍗曞叧鑱旇〃 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysRoleMenuMapper { + /** + * 鏌ヨ鑿滃崟浣跨敤鏁伴噺 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 + */ + public int checkMenuExistRole(Long menuId); + + /** + * 閫氳繃瑙掕壊ID鍒犻櫎瑙掕壊鍜岃彍鍗曞叧鑱 + * + * @param roleId 瑙掕壊ID + * @return 缁撴灉 + */ + public int deleteRoleMenuByRoleId(Long roleId); + + /** + * 鎵归噺鍒犻櫎瑙掕壊鑿滃崟鍏宠仈淇℃伅 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteRoleMenu(Long[] ids); + + /** + * 鎵归噺鏂板瑙掕壊鑿滃崟淇℃伅 + * + * @param roleMenuList 瑙掕壊鑿滃崟鍒楄〃 + * @return 缁撴灉 + */ + public int batchRoleMenu(List roleMenuList); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserMapper.java new file mode 100644 index 000000000..3c24176f4 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserMapper.java @@ -0,0 +1,127 @@ +package com.jsowell.system.mapper; + +import com.jsowell.common.core.domain.entity.SysUser; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 鐢ㄦ埛琛 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysUserMapper { + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鐢ㄦ埛鍒楄〃 + * + * @param sysUser 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + List selectUserList(SysUser sysUser); + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ宸查厤鐢ㄦ埛瑙掕壊鍒楄〃 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + List selectAllocatedList(SysUser user); + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + List selectUnallocatedList(SysUser user); + + /** + * 閫氳繃鐢ㄦ埛鍚嶆煡璇㈢敤鎴 + * + * @param userName 鐢ㄦ埛鍚 + * @return 鐢ㄦ埛瀵硅薄淇℃伅 + */ + SysUser selectUserByUserName(String userName); + + /** + * 閫氳繃鐢ㄦ埛ID鏌ヨ鐢ㄦ埛 + * + * @param userId 鐢ㄦ埛ID + * @return 鐢ㄦ埛瀵硅薄淇℃伅 + */ + SysUser selectUserById(Long userId); + + /** + * 鏂板鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + int insertUser(SysUser user); + + /** + * 淇敼鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + int updateUser(SysUser user); + + /** + * 淇敼鐢ㄦ埛澶村儚 + * + * @param userName 鐢ㄦ埛鍚 + * @param avatar 澶村儚鍦板潃 + * @return 缁撴灉 + */ + int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar); + + /** + * 閲嶇疆鐢ㄦ埛瀵嗙爜 + * + * @param userName 鐢ㄦ埛鍚 + * @param password 瀵嗙爜 + * @return 缁撴灉 + */ + int resetUserPwd(@Param("userName") String userName, @Param("password") String password); + + /** + * 閫氳繃鐢ㄦ埛ID鍒犻櫎鐢ㄦ埛 + * + * @param userId 鐢ㄦ埛ID + * @return 缁撴灉 + */ + int deleteUserById(Long userId); + + /** + * 鎵归噺鍒犻櫎鐢ㄦ埛淇℃伅 + * + * @param userIds 闇瑕佸垹闄ょ殑鐢ㄦ埛ID + * @return 缁撴灉 + */ + int deleteUserByIds(Long[] userIds); + + /** + * 鏍¢獙鐢ㄦ埛鍚嶇О鏄惁鍞竴 + * + * @param userName 鐢ㄦ埛鍚嶇О + * @return 缁撴灉 + */ + int checkUserNameUnique(String userName); + + /** + * 鏍¢獙鎵嬫満鍙风爜鏄惁鍞竴 + * + * @param phone 鎵嬫満鍙风爜 + * @return 缁撴灉 + */ + SysUser checkPhoneUnique(String phone); + + /** + * 鏍¢獙email鏄惁鍞竴 + * + * @param email 鐢ㄦ埛閭 + * @return 缁撴灉 + */ + SysUser checkEmailUnique(String email); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserPostMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserPostMapper.java new file mode 100644 index 000000000..a7d87c47c --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserPostMapper.java @@ -0,0 +1,44 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysUserPost; + +import java.util.List; + +/** + * 鐢ㄦ埛涓庡矖浣嶅叧鑱旇〃 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysUserPostMapper { + /** + * 閫氳繃鐢ㄦ埛ID鍒犻櫎鐢ㄦ埛鍜屽矖浣嶅叧鑱 + * + * @param userId 鐢ㄦ埛ID + * @return 缁撴灉 + */ + public int deleteUserPostByUserId(Long userId); + + /** + * 閫氳繃宀椾綅ID鏌ヨ宀椾綅浣跨敤鏁伴噺 + * + * @param postId 宀椾綅ID + * @return 缁撴灉 + */ + public int countUserPostById(Long postId); + + /** + * 鎵归噺鍒犻櫎鐢ㄦ埛鍜屽矖浣嶅叧鑱 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteUserPost(Long[] ids); + + /** + * 鎵归噺鏂板鐢ㄦ埛宀椾綅淇℃伅 + * + * @param userPostList 鐢ㄦ埛瑙掕壊鍒楄〃 + * @return 缁撴灉 + */ + public int batchUserPost(List userPostList); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserRoleMapper.java b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserRoleMapper.java new file mode 100644 index 000000000..cd2d7214e --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/mapper/SysUserRoleMapper.java @@ -0,0 +1,62 @@ +package com.jsowell.system.mapper; + +import com.jsowell.system.domain.SysUserRole; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 鐢ㄦ埛涓庤鑹插叧鑱旇〃 鏁版嵁灞 + * + * @author jsowell + */ +public interface SysUserRoleMapper { + /** + * 閫氳繃鐢ㄦ埛ID鍒犻櫎鐢ㄦ埛鍜岃鑹插叧鑱 + * + * @param userId 鐢ㄦ埛ID + * @return 缁撴灉 + */ + public int deleteUserRoleByUserId(Long userId); + + /** + * 鎵归噺鍒犻櫎鐢ㄦ埛鍜岃鑹插叧鑱 + * + * @param ids 闇瑕佸垹闄ょ殑鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteUserRole(Long[] ids); + + /** + * 閫氳繃瑙掕壊ID鏌ヨ瑙掕壊浣跨敤鏁伴噺 + * + * @param roleId 瑙掕壊ID + * @return 缁撴灉 + */ + public int countUserRoleByRoleId(Long roleId); + + /** + * 鎵归噺鏂板鐢ㄦ埛瑙掕壊淇℃伅 + * + * @param userRoleList 鐢ㄦ埛瑙掕壊鍒楄〃 + * @return 缁撴灉 + */ + public int batchUserRole(List userRoleList); + + /** + * 鍒犻櫎鐢ㄦ埛鍜岃鑹插叧鑱斾俊鎭 + * + * @param userRole 鐢ㄦ埛鍜岃鑹插叧鑱斾俊鎭 + * @return 缁撴灉 + */ + public int deleteUserRoleInfo(SysUserRole userRole); + + /** + * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇瑕佸垹闄ょ殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysConfigService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysConfigService.java new file mode 100644 index 000000000..0227798a5 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysConfigService.java @@ -0,0 +1,89 @@ +package com.jsowell.system.service; + +import com.jsowell.system.domain.SysConfig; + +import java.util.List; + +/** + * 鍙傛暟閰嶇疆 鏈嶅姟灞 + * + * @author jsowell + */ +public interface SysConfigService { + /** + * 鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configId 鍙傛暟閰嶇疆ID + * @return 鍙傛暟閰嶇疆淇℃伅 + */ + public SysConfig selectConfigById(Long configId); + + /** + * 鏍规嵁閿悕鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configKey 鍙傛暟閿悕 + * @return 鍙傛暟閿 + */ + public String selectConfigByKey(String configKey); + + /** + * 鑾峰彇楠岃瘉鐮佸紑鍏 + * + * @return true寮鍚紝false鍏抽棴 + */ + public boolean selectCaptchaEnabled(); + + /** + * 鏌ヨ鍙傛暟閰嶇疆鍒楄〃 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 鍙傛暟閰嶇疆闆嗗悎 + */ + public List selectConfigList(SysConfig config); + + /** + * 鏂板鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + public int insertConfig(SysConfig config); + + /** + * 淇敼鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + public int updateConfig(SysConfig config); + + /** + * 鎵归噺鍒犻櫎鍙傛暟淇℃伅 + * + * @param configIds 闇瑕佸垹闄ょ殑鍙傛暟ID + */ + public void deleteConfigByIds(Long[] configIds); + + /** + * 鍔犺浇鍙傛暟缂撳瓨鏁版嵁 + */ + public void loadingConfigCache(); + + /** + * 娓呯┖鍙傛暟缂撳瓨鏁版嵁 + */ + public void clearConfigCache(); + + /** + * 閲嶇疆鍙傛暟缂撳瓨鏁版嵁 + */ + public void resetConfigCache(); + + /** + * 鏍¢獙鍙傛暟閿悕鏄惁鍞竴 + * + * @param config 鍙傛暟淇℃伅 + * @return 缁撴灉 + */ + public String checkConfigKeyUnique(SysConfig config); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysDeptService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysDeptService.java new file mode 100644 index 000000000..fab3db6c8 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysDeptService.java @@ -0,0 +1,116 @@ +package com.jsowell.system.service; + +import com.jsowell.common.core.domain.TreeSelect; +import com.jsowell.common.core.domain.entity.SysDept; + +import java.util.List; + +/** + * 閮ㄩ棬绠$悊 鏈嶅姟灞 + * + * @author jsowell + */ +public interface SysDeptService { + /** + * 鏌ヨ閮ㄩ棬绠$悊鏁版嵁 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 閮ㄩ棬淇℃伅闆嗗悎 + */ + public List selectDeptList(SysDept dept); + + /** + * 鏋勫缓鍓嶇鎵闇瑕佹爲缁撴瀯 + * + * @param depts 閮ㄩ棬鍒楄〃 + * @return 鏍戠粨鏋勫垪琛 + */ + public List buildDeptTree(List depts); + + /** + * 鏋勫缓鍓嶇鎵闇瑕佷笅鎷夋爲缁撴瀯 + * + * @param depts 閮ㄩ棬鍒楄〃 + * @return 涓嬫媺鏍戠粨鏋勫垪琛 + */ + public List buildDeptTreeSelect(List depts); + + /** + * 鏍规嵁瑙掕壊ID鏌ヨ閮ㄩ棬鏍戜俊鎭 + * + * @param roleId 瑙掕壊ID + * @return 閫変腑閮ㄩ棬鍒楄〃 + */ + public List selectDeptListByRoleId(Long roleId); + + /** + * 鏍规嵁閮ㄩ棬ID鏌ヨ淇℃伅 + * + * @param deptId 閮ㄩ棬ID + * @return 閮ㄩ棬淇℃伅 + */ + public SysDept selectDeptById(Long deptId); + + /** + * 鏍规嵁ID鏌ヨ鎵鏈夊瓙閮ㄩ棬锛堟甯哥姸鎬侊級 + * + * @param deptId 閮ㄩ棬ID + * @return 瀛愰儴闂ㄦ暟 + */ + public int selectNormalChildrenDeptById(Long deptId); + + /** + * 鏄惁瀛樺湪閮ㄩ棬瀛愯妭鐐 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 + */ + public boolean hasChildByDeptId(Long deptId); + + /** + * 鏌ヨ閮ㄩ棬鏄惁瀛樺湪鐢ㄦ埛 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 true 瀛樺湪 false 涓嶅瓨鍦 + */ + public boolean checkDeptExistUser(Long deptId); + + /** + * 鏍¢獙閮ㄩ棬鍚嶇О鏄惁鍞竴 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 缁撴灉 + */ + public String checkDeptNameUnique(SysDept dept); + + /** + * 鏍¢獙閮ㄩ棬鏄惁鏈夋暟鎹潈闄 + * + * @param deptId 閮ㄩ棬id + */ + public void checkDeptDataScope(Long deptId); + + /** + * 鏂板淇濆瓨閮ㄩ棬淇℃伅 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 缁撴灉 + */ + public int insertDept(SysDept dept); + + /** + * 淇敼淇濆瓨閮ㄩ棬淇℃伅 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 缁撴灉 + */ + public int updateDept(SysDept dept); + + /** + * 鍒犻櫎閮ㄩ棬绠$悊淇℃伅 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 + */ + public int deleteDeptById(Long deptId); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysDictDataService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysDictDataService.java new file mode 100644 index 000000000..6329d5132 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysDictDataService.java @@ -0,0 +1,60 @@ +package com.jsowell.system.service; + +import com.jsowell.common.core.domain.entity.SysDictData; + +import java.util.List; + +/** + * 瀛楀吀 涓氬姟灞 + * + * @author jsowell + */ +public interface SysDictDataService { + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀鏁版嵁 + * + * @param dictData 瀛楀吀鏁版嵁淇℃伅 + * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅 + */ + public List selectDictDataList(SysDictData dictData); + + /** + * 鏍规嵁瀛楀吀绫诲瀷鍜屽瓧鍏搁敭鍊兼煡璇㈠瓧鍏告暟鎹俊鎭 + * + * @param dictType 瀛楀吀绫诲瀷 + * @param dictValue 瀛楀吀閿 + * @return 瀛楀吀鏍囩 + */ + public String selectDictLabel(String dictType, String dictValue); + + /** + * 鏍规嵁瀛楀吀鏁版嵁ID鏌ヨ淇℃伅 + * + * @param dictCode 瀛楀吀鏁版嵁ID + * @return 瀛楀吀鏁版嵁 + */ + public SysDictData selectDictDataById(Long dictCode); + + /** + * 鎵归噺鍒犻櫎瀛楀吀鏁版嵁淇℃伅 + * + * @param dictCodes 闇瑕佸垹闄ょ殑瀛楀吀鏁版嵁ID + */ + public void deleteDictDataByIds(Long[] dictCodes); + + /** + * 鏂板淇濆瓨瀛楀吀鏁版嵁淇℃伅 + * + * @param dictData 瀛楀吀鏁版嵁淇℃伅 + * @return 缁撴灉 + */ + public int insertDictData(SysDictData dictData); + + /** + * 淇敼淇濆瓨瀛楀吀鏁版嵁淇℃伅 + * + * @param dictData 瀛楀吀鏁版嵁淇℃伅 + * @return 缁撴灉 + */ + public int updateDictData(SysDictData dictData); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysDictTypeService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysDictTypeService.java new file mode 100644 index 000000000..1a8c9b63b --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysDictTypeService.java @@ -0,0 +1,98 @@ +package com.jsowell.system.service; + +import com.jsowell.common.core.domain.entity.SysDictData; +import com.jsowell.common.core.domain.entity.SysDictType; + +import java.util.List; + +/** + * 瀛楀吀 涓氬姟灞 + * + * @author jsowell + */ +public interface SysDictTypeService { + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀绫诲瀷 + * + * @param dictType 瀛楀吀绫诲瀷淇℃伅 + * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 + */ + public List selectDictTypeList(SysDictType dictType); + + /** + * 鏍规嵁鎵鏈夊瓧鍏哥被鍨 + * + * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 + */ + public List selectDictTypeAll(); + + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅 + */ + public List selectDictDataByType(String dictType); + + /** + * 鏍规嵁瀛楀吀绫诲瀷ID鏌ヨ淇℃伅 + * + * @param dictId 瀛楀吀绫诲瀷ID + * @return 瀛楀吀绫诲瀷 + */ + public SysDictType selectDictTypeById(Long dictId); + + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ淇℃伅 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀绫诲瀷 + */ + public SysDictType selectDictTypeByType(String dictType); + + /** + * 鎵归噺鍒犻櫎瀛楀吀淇℃伅 + * + * @param dictIds 闇瑕佸垹闄ょ殑瀛楀吀ID + */ + public void deleteDictTypeByIds(Long[] dictIds); + + /** + * 鍔犺浇瀛楀吀缂撳瓨鏁版嵁 + */ + public void loadingDictCache(); + + /** + * 娓呯┖瀛楀吀缂撳瓨鏁版嵁 + */ + public void clearDictCache(); + + /** + * 閲嶇疆瀛楀吀缂撳瓨鏁版嵁 + */ + public void resetDictCache(); + + /** + * 鏂板淇濆瓨瀛楀吀绫诲瀷淇℃伅 + * + * @param dictType 瀛楀吀绫诲瀷淇℃伅 + * @return 缁撴灉 + */ + public int insertDictType(SysDictType dictType); + + /** + * 淇敼淇濆瓨瀛楀吀绫诲瀷淇℃伅 + * + * @param dictType 瀛楀吀绫诲瀷淇℃伅 + * @return 缁撴灉 + */ + public int updateDictType(SysDictType dictType); + + /** + * 鏍¢獙瀛楀吀绫诲瀷绉版槸鍚﹀敮涓 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 缁撴灉 + */ + public String checkDictTypeUnique(SysDictType dictType); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysLogininforService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysLogininforService.java new file mode 100644 index 000000000..a9da7232e --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysLogininforService.java @@ -0,0 +1,40 @@ +package com.jsowell.system.service; + +import com.jsowell.system.domain.SysLogininfor; + +import java.util.List; + +/** + * 绯荤粺璁块棶鏃ュ織鎯呭喌淇℃伅 鏈嶅姟灞 + * + * @author jsowell + */ +public interface SysLogininforService { + /** + * 鏂板绯荤粺鐧诲綍鏃ュ織 + * + * @param logininfor 璁块棶鏃ュ織瀵硅薄 + */ + public void insertLogininfor(SysLogininfor logininfor); + + /** + * 鏌ヨ绯荤粺鐧诲綍鏃ュ織闆嗗悎 + * + * @param logininfor 璁块棶鏃ュ織瀵硅薄 + * @return 鐧诲綍璁板綍闆嗗悎 + */ + public List selectLogininforList(SysLogininfor logininfor); + + /** + * 鎵归噺鍒犻櫎绯荤粺鐧诲綍鏃ュ織 + * + * @param infoIds 闇瑕佸垹闄ょ殑鐧诲綍鏃ュ織ID + * @return 缁撴灉 + */ + public int deleteLogininforByIds(Long[] infoIds); + + /** + * 娓呯┖绯荤粺鐧诲綍鏃ュ織 + */ + public void cleanLogininfor(); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysMenuService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysMenuService.java new file mode 100644 index 000000000..e208b6e88 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysMenuService.java @@ -0,0 +1,136 @@ +package com.jsowell.system.service; + +import com.jsowell.common.core.domain.TreeSelect; +import com.jsowell.common.core.domain.entity.SysMenu; +import com.jsowell.system.vo.RouterVO; + +import java.util.List; +import java.util.Set; + +/** + * 鑿滃崟 涓氬姟灞 + * + * @author jsowell + */ +public interface SysMenuService { + /** + * 鏍规嵁鐢ㄦ埛鏌ヨ绯荤粺鑿滃崟鍒楄〃 + * + * @param userId 鐢ㄦ埛ID + * @return 鑿滃崟鍒楄〃 + */ + public List selectMenuList(Long userId); + + /** + * 鏍规嵁鐢ㄦ埛鏌ヨ绯荤粺鑿滃崟鍒楄〃 + * + * @param menu 鑿滃崟淇℃伅 + * @param userId 鐢ㄦ埛ID + * @return 鑿滃崟鍒楄〃 + */ + public List selectMenuList(SysMenu menu, Long userId); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鏉冮檺 + * + * @param userId 鐢ㄦ埛ID + * @return 鏉冮檺鍒楄〃 + */ + public Set selectMenuPermsByUserId(Long userId); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鑿滃崟鏍戜俊鎭 + * + * @param userId 鐢ㄦ埛ID + * @return 鑿滃崟鍒楄〃 + */ + public List selectMenuTreeByUserId(Long userId); + + /** + * 鏍规嵁瑙掕壊ID鏌ヨ鑿滃崟鏍戜俊鎭 + * + * @param roleId 瑙掕壊ID + * @return 閫変腑鑿滃崟鍒楄〃 + */ + public List selectMenuListByRoleId(Long roleId); + + /** + * 鏋勫缓鍓嶇璺敱鎵闇瑕佺殑鑿滃崟 + * + * @param menus 鑿滃崟鍒楄〃 + * @return 璺敱鍒楄〃 + */ + public List buildMenus(List menus); + + /** + * 鏋勫缓鍓嶇鎵闇瑕佹爲缁撴瀯 + * + * @param menus 鑿滃崟鍒楄〃 + * @return 鏍戠粨鏋勫垪琛 + */ + public List buildMenuTree(List menus); + + /** + * 鏋勫缓鍓嶇鎵闇瑕佷笅鎷夋爲缁撴瀯 + * + * @param menus 鑿滃崟鍒楄〃 + * @return 涓嬫媺鏍戠粨鏋勫垪琛 + */ + public List buildMenuTreeSelect(List menus); + + /** + * 鏍规嵁鑿滃崟ID鏌ヨ淇℃伅 + * + * @param menuId 鑿滃崟ID + * @return 鑿滃崟淇℃伅 + */ + public SysMenu selectMenuById(Long menuId); + + /** + * 鏄惁瀛樺湪鑿滃崟瀛愯妭鐐 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 true 瀛樺湪 false 涓嶅瓨鍦 + */ + public boolean hasChildByMenuId(Long menuId); + + /** + * 鏌ヨ鑿滃崟鏄惁瀛樺湪瑙掕壊 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 true 瀛樺湪 false 涓嶅瓨鍦 + */ + public boolean checkMenuExistRole(Long menuId); + + /** + * 鏂板淇濆瓨鑿滃崟淇℃伅 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + public int insertMenu(SysMenu menu); + + /** + * 淇敼淇濆瓨鑿滃崟淇℃伅 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + public int updateMenu(SysMenu menu); + + /** + * 鍒犻櫎鑿滃崟绠$悊淇℃伅 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 + */ + public int deleteMenuById(Long menuId); + + /** + * 鏍¢獙鑿滃崟鍚嶇О鏄惁鍞竴 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + public String checkMenuNameUnique(SysMenu menu); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysNoticeService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysNoticeService.java new file mode 100644 index 000000000..40ea05766 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysNoticeService.java @@ -0,0 +1,60 @@ +package com.jsowell.system.service; + +import com.jsowell.system.domain.SysNotice; + +import java.util.List; + +/** + * 鍏憡 鏈嶅姟灞 + * + * @author jsowell + */ +public interface SysNoticeService { + /** + * 鏌ヨ鍏憡淇℃伅 + * + * @param noticeId 鍏憡ID + * @return 鍏憡淇℃伅 + */ + public SysNotice selectNoticeById(Long noticeId); + + /** + * 鏌ヨ鍏憡鍒楄〃 + * + * @param notice 鍏憡淇℃伅 + * @return 鍏憡闆嗗悎 + */ + public List selectNoticeList(SysNotice notice); + + /** + * 鏂板鍏憡 + * + * @param notice 鍏憡淇℃伅 + * @return 缁撴灉 + */ + public int insertNotice(SysNotice notice); + + /** + * 淇敼鍏憡 + * + * @param notice 鍏憡淇℃伅 + * @return 缁撴灉 + */ + public int updateNotice(SysNotice notice); + + /** + * 鍒犻櫎鍏憡淇℃伅 + * + * @param noticeId 鍏憡ID + * @return 缁撴灉 + */ + public int deleteNoticeById(Long noticeId); + + /** + * 鎵归噺鍒犻櫎鍏憡淇℃伅 + * + * @param noticeIds 闇瑕佸垹闄ょ殑鍏憡ID + * @return 缁撴灉 + */ + public int deleteNoticeByIds(Long[] noticeIds); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysOperLogService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysOperLogService.java new file mode 100644 index 000000000..94e033618 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysOperLogService.java @@ -0,0 +1,48 @@ +package com.jsowell.system.service; + +import com.jsowell.system.domain.SysOperLog; + +import java.util.List; + +/** + * 鎿嶄綔鏃ュ織 鏈嶅姟灞 + * + * @author jsowell + */ +public interface SysOperLogService { + /** + * 鏂板鎿嶄綔鏃ュ織 + * + * @param operLog 鎿嶄綔鏃ュ織瀵硅薄 + */ + public void insertOperlog(SysOperLog operLog); + + /** + * 鏌ヨ绯荤粺鎿嶄綔鏃ュ織闆嗗悎 + * + * @param operLog 鎿嶄綔鏃ュ織瀵硅薄 + * @return 鎿嶄綔鏃ュ織闆嗗悎 + */ + public List selectOperLogList(SysOperLog operLog); + + /** + * 鎵归噺鍒犻櫎绯荤粺鎿嶄綔鏃ュ織 + * + * @param operIds 闇瑕佸垹闄ょ殑鎿嶄綔鏃ュ織ID + * @return 缁撴灉 + */ + public int deleteOperLogByIds(Long[] operIds); + + /** + * 鏌ヨ鎿嶄綔鏃ュ織璇︾粏 + * + * @param operId 鎿嶄綔ID + * @return 鎿嶄綔鏃ュ織瀵硅薄 + */ + public SysOperLog selectOperLogById(Long operId); + + /** + * 娓呯┖鎿嶄綔鏃ュ織 + */ + public void cleanOperLog(); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysPostService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysPostService.java new file mode 100644 index 000000000..67d5d6dd6 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysPostService.java @@ -0,0 +1,99 @@ +package com.jsowell.system.service; + +import com.jsowell.system.domain.SysPost; + +import java.util.List; + +/** + * 宀椾綅淇℃伅 鏈嶅姟灞 + * + * @author jsowell + */ +public interface SysPostService { + /** + * 鏌ヨ宀椾綅淇℃伅闆嗗悎 + * + * @param post 宀椾綅淇℃伅 + * @return 宀椾綅鍒楄〃 + */ + public List selectPostList(SysPost post); + + /** + * 鏌ヨ鎵鏈夊矖浣 + * + * @return 宀椾綅鍒楄〃 + */ + public List selectPostAll(); + + /** + * 閫氳繃宀椾綅ID鏌ヨ宀椾綅淇℃伅 + * + * @param postId 宀椾綅ID + * @return 瑙掕壊瀵硅薄淇℃伅 + */ + public SysPost selectPostById(Long postId); + + /** + * 鏍规嵁鐢ㄦ埛ID鑾峰彇宀椾綅閫夋嫨妗嗗垪琛 + * + * @param userId 鐢ㄦ埛ID + * @return 閫変腑宀椾綅ID鍒楄〃 + */ + public List selectPostListByUserId(Long userId); + + /** + * 鏍¢獙宀椾綅鍚嶇О + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + public String checkPostNameUnique(SysPost post); + + /** + * 鏍¢獙宀椾綅缂栫爜 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + public String checkPostCodeUnique(SysPost post); + + /** + * 閫氳繃宀椾綅ID鏌ヨ宀椾綅浣跨敤鏁伴噺 + * + * @param postId 宀椾綅ID + * @return 缁撴灉 + */ + public int countUserPostById(Long postId); + + /** + * 鍒犻櫎宀椾綅淇℃伅 + * + * @param postId 宀椾綅ID + * @return 缁撴灉 + */ + public int deletePostById(Long postId); + + /** + * 鎵归噺鍒犻櫎宀椾綅淇℃伅 + * + * @param postIds 闇瑕佸垹闄ょ殑宀椾綅ID + * @return 缁撴灉 + */ + public int deletePostByIds(Long[] postIds); + + /** + * 鏂板淇濆瓨宀椾綅淇℃伅 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + public int insertPost(SysPost post); + + /** + * 淇敼淇濆瓨宀椾綅淇℃伅 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + public int updatePost(SysPost post); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysRoleService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysRoleService.java new file mode 100644 index 000000000..4a3f40a36 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysRoleService.java @@ -0,0 +1,173 @@ +package com.jsowell.system.service; + +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.system.domain.SysUserRole; + +import java.util.List; +import java.util.Set; + +/** + * 瑙掕壊涓氬姟灞 + * + * @author jsowell + */ +public interface SysRoleService { + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瑙掕壊鏁版嵁 + * + * @param role 瑙掕壊淇℃伅 + * @return 瑙掕壊鏁版嵁闆嗗悎淇℃伅 + */ + public List selectRoleList(SysRole role); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ瑙掕壊鍒楄〃 + * + * @param userId 鐢ㄦ埛ID + * @return 瑙掕壊鍒楄〃 + */ + public List selectRolesByUserId(Long userId); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ瑙掕壊鏉冮檺 + * + * @param userId 鐢ㄦ埛ID + * @return 鏉冮檺鍒楄〃 + */ + public Set selectRolePermissionByUserId(Long userId); + + /** + * 鏌ヨ鎵鏈夎鑹 + * + * @return 瑙掕壊鍒楄〃 + */ + public List selectRoleAll(); + + /** + * 鏍规嵁鐢ㄦ埛ID鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛 + * + * @param userId 鐢ㄦ埛ID + * @return 閫変腑瑙掕壊ID鍒楄〃 + */ + public List selectRoleListByUserId(Long userId); + + /** + * 閫氳繃瑙掕壊ID鏌ヨ瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @return 瑙掕壊瀵硅薄淇℃伅 + */ + public SysRole selectRoleById(Long roleId); + + /** + * 鏍¢獙瑙掕壊鍚嶇О鏄惁鍞竴 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + public String checkRoleNameUnique(SysRole role); + + /** + * 鏍¢獙瑙掕壊鏉冮檺鏄惁鍞竴 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + public String checkRoleKeyUnique(SysRole role); + + /** + * 鏍¢獙瑙掕壊鏄惁鍏佽鎿嶄綔 + * + * @param role 瑙掕壊淇℃伅 + */ + public void checkRoleAllowed(SysRole role); + + /** + * 鏍¢獙瑙掕壊鏄惁鏈夋暟鎹潈闄 + * + * @param roleId 瑙掕壊id + */ + public void checkRoleDataScope(Long roleId); + + /** + * 閫氳繃瑙掕壊ID鏌ヨ瑙掕壊浣跨敤鏁伴噺 + * + * @param roleId 瑙掕壊ID + * @return 缁撴灉 + */ + public int countUserRoleByRoleId(Long roleId); + + /** + * 鏂板淇濆瓨瑙掕壊淇℃伅 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + public int insertRole(SysRole role); + + /** + * 淇敼淇濆瓨瑙掕壊淇℃伅 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + public int updateRole(SysRole role); + + /** + * 淇敼瑙掕壊鐘舵 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + public int updateRoleStatus(SysRole role); + + /** + * 淇敼鏁版嵁鏉冮檺淇℃伅 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + public int authDataScope(SysRole role); + + /** + * 閫氳繃瑙掕壊ID鍒犻櫎瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @return 缁撴灉 + */ + public int deleteRoleById(Long roleId); + + /** + * 鎵归噺鍒犻櫎瑙掕壊淇℃伅 + * + * @param roleIds 闇瑕佸垹闄ょ殑瑙掕壊ID + * @return 缁撴灉 + */ + public int deleteRoleByIds(Long[] roleIds); + + /** + * 鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param userRole 鐢ㄦ埛鍜岃鑹插叧鑱斾俊鎭 + * @return 缁撴灉 + */ + public int deleteAuthUser(SysUserRole userRole); + + /** + * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇瑕佸彇娑堟巿鏉冪殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteAuthUsers(Long roleId, Long[] userIds); + + /** + * 鎵归噺閫夋嫨鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇瑕佸垹闄ょ殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + public int insertAuthUsers(Long roleId, Long[] userIds); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysUserOnlineService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysUserOnlineService.java new file mode 100644 index 000000000..4c4af1f4a --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysUserOnlineService.java @@ -0,0 +1,47 @@ +package com.jsowell.system.service; + +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.system.domain.SysUserOnline; + +/** + * 鍦ㄧ嚎鐢ㄦ埛 鏈嶅姟灞 + * + * @author jsowell + */ +public interface SysUserOnlineService { + /** + * 閫氳繃鐧诲綍鍦板潃鏌ヨ淇℃伅 + * + * @param ipaddr 鐧诲綍鍦板潃 + * @param user 鐢ㄦ埛淇℃伅 + * @return 鍦ㄧ嚎鐢ㄦ埛淇℃伅 + */ + public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user); + + /** + * 閫氳繃鐢ㄦ埛鍚嶇О鏌ヨ淇℃伅 + * + * @param userName 鐢ㄦ埛鍚嶇О + * @param user 鐢ㄦ埛淇℃伅 + * @return 鍦ㄧ嚎鐢ㄦ埛淇℃伅 + */ + public SysUserOnline selectOnlineByUserName(String userName, LoginUser user); + + /** + * 閫氳繃鐧诲綍鍦板潃/鐢ㄦ埛鍚嶇О鏌ヨ淇℃伅 + * + * @param ipaddr 鐧诲綍鍦板潃 + * @param userName 鐢ㄦ埛鍚嶇О + * @param user 鐢ㄦ埛淇℃伅 + * @return 鍦ㄧ嚎鐢ㄦ埛淇℃伅 + */ + public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user); + + /** + * 璁剧疆鍦ㄧ嚎鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鍦ㄧ嚎鐢ㄦ埛 + */ + public SysUserOnline loginUserToUserOnline(LoginUser user); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/SysUserService.java b/jsowell-system/src/main/java/com/jsowell/system/service/SysUserService.java new file mode 100644 index 000000000..ff1c475ed --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/SysUserService.java @@ -0,0 +1,206 @@ +package com.jsowell.system.service; + +import com.jsowell.common.core.domain.entity.SysUser; + +import java.util.List; + +/** + * 鐢ㄦ埛 涓氬姟灞 + * + * @author jsowell + */ +public interface SysUserService { + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鐢ㄦ埛鍒楄〃 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + public List selectUserList(SysUser user); + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + public List selectAllocatedList(SysUser user); + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + public List selectUnallocatedList(SysUser user); + + /** + * 閫氳繃鐢ㄦ埛鍚嶆煡璇㈢敤鎴 + * + * @param userName 鐢ㄦ埛鍚 + * @return 鐢ㄦ埛瀵硅薄淇℃伅 + */ + public SysUser selectUserByUserName(String userName); + + /** + * 閫氳繃鐢ㄦ埛ID鏌ヨ鐢ㄦ埛 + * + * @param userId 鐢ㄦ埛ID + * @return 鐢ㄦ埛瀵硅薄淇℃伅 + */ + public SysUser selectUserById(Long userId); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鐢ㄦ埛鎵灞炶鑹茬粍 + * + * @param userName 鐢ㄦ埛鍚 + * @return 缁撴灉 + */ + public String selectUserRoleGroup(String userName); + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鐢ㄦ埛鎵灞炲矖浣嶇粍 + * + * @param userName 鐢ㄦ埛鍚 + * @return 缁撴灉 + */ + public String selectUserPostGroup(String userName); + + /** + * 鏍¢獙鐢ㄦ埛鍚嶇О鏄惁鍞竴 + * + * @param userName 鐢ㄦ埛鍚嶇О + * @return 缁撴灉 + */ + public String checkUserNameUnique(String userName); + + /** + * 鏍¢獙鎵嬫満鍙风爜鏄惁鍞竴 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + public String checkPhoneUnique(SysUser user); + + /** + * 鏍¢獙email鏄惁鍞竴 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + public String checkEmailUnique(SysUser user); + + /** + * 鏍¢獙鐢ㄦ埛鏄惁鍏佽鎿嶄綔 + * + * @param user 鐢ㄦ埛淇℃伅 + */ + public void checkUserAllowed(SysUser user); + + /** + * 鏍¢獙鐢ㄦ埛鏄惁鏈夋暟鎹潈闄 + * + * @param userId 鐢ㄦ埛id + */ + public void checkUserDataScope(Long userId); + + /** + * 鏂板鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + public int insertUser(SysUser user); + + /** + * 娉ㄥ唽鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + public boolean registerUser(SysUser user); + + /** + * 淇敼鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + public int updateUser(SysUser user); + + /** + * 鐢ㄦ埛鎺堟潈瑙掕壊 + * + * @param userId 鐢ㄦ埛ID + * @param roleIds 瑙掕壊缁 + */ + public void insertUserAuth(Long userId, Long[] roleIds); + + /** + * 淇敼鐢ㄦ埛鐘舵 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + public int updateUserStatus(SysUser user); + + /** + * 淇敼鐢ㄦ埛鍩烘湰淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + public int updateUserProfile(SysUser user); + + /** + * 淇敼鐢ㄦ埛澶村儚 + * + * @param userName 鐢ㄦ埛鍚 + * @param avatar 澶村儚鍦板潃 + * @return 缁撴灉 + */ + public boolean updateUserAvatar(String userName, String avatar); + + /** + * 閲嶇疆鐢ㄦ埛瀵嗙爜 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + public int resetPwd(SysUser user); + + /** + * 閲嶇疆鐢ㄦ埛瀵嗙爜 + * + * @param userName 鐢ㄦ埛鍚 + * @param password 瀵嗙爜 + * @return 缁撴灉 + */ + public int resetUserPwd(String userName, String password); + + /** + * 閫氳繃鐢ㄦ埛ID鍒犻櫎鐢ㄦ埛 + * + * @param userId 鐢ㄦ埛ID + * @return 缁撴灉 + */ + public int deleteUserById(Long userId); + + /** + * 鎵归噺鍒犻櫎鐢ㄦ埛淇℃伅 + * + * @param userIds 闇瑕佸垹闄ょ殑鐢ㄦ埛ID + * @return 缁撴灉 + */ + public int deleteUserByIds(Long[] userIds); + + /** + * 瀵煎叆鐢ㄦ埛鏁版嵁 + * + * @param userList 鐢ㄦ埛鏁版嵁鍒楄〃 + * @param isUpdateSupport 鏄惁鏇存柊鏀寔锛屽鏋滃凡瀛樺湪锛屽垯杩涜鏇存柊鏁版嵁 + * @param operName 鎿嶄綔鐢ㄦ埛 + * @return 缁撴灉 + */ + public String importUser(List userList, Boolean isUpdateSupport, String operName); +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysConfigServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysConfigServiceImpl.java new file mode 100644 index 000000000..ba95e2b87 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysConfigServiceImpl.java @@ -0,0 +1,204 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.common.annotation.DataSource; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.core.text.Convert; +import com.jsowell.common.enums.DataSourceType; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.domain.SysConfig; +import com.jsowell.system.mapper.SysConfigMapper; +import com.jsowell.system.service.SysConfigService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.Collection; +import java.util.List; + +/** + * 鍙傛暟閰嶇疆 鏈嶅姟灞傚疄鐜 + * + * @author jsowell + */ +@Service +public class SysConfigServiceImpl implements SysConfigService { + @Autowired + private SysConfigMapper configMapper; + + @Autowired + private RedisCache redisCache; + + /** + * 椤圭洰鍚姩鏃讹紝鍒濆鍖栧弬鏁板埌缂撳瓨 + */ + @PostConstruct + public void init() { + loadingConfigCache(); + } + + /** + * 鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configId 鍙傛暟閰嶇疆ID + * @return 鍙傛暟閰嶇疆淇℃伅 + */ + @Override + @DataSource(DataSourceType.MASTER) + public SysConfig selectConfigById(Long configId) { + SysConfig config = new SysConfig(); + config.setConfigId(configId); + return configMapper.selectConfig(config); + } + + /** + * 鏍规嵁閿悕鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configKey 鍙傛暟key + * @return 鍙傛暟閿 + */ + @Override + public String selectConfigByKey(String configKey) { + String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey))); + if (StringUtils.isNotEmpty(configValue)) { + return configValue; + } + SysConfig config = new SysConfig(); + config.setConfigKey(configKey); + SysConfig retConfig = configMapper.selectConfig(config); + if (StringUtils.isNotNull(retConfig)) { + redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue()); + return retConfig.getConfigValue(); + } + return StringUtils.EMPTY; + } + + /** + * 鑾峰彇楠岃瘉鐮佸紑鍏 + * + * @return true寮鍚紝false鍏抽棴 + */ + @Override + public boolean selectCaptchaEnabled() { + String captchaEnabled = selectConfigByKey("sys.account.captchaEnabled"); + if (StringUtils.isEmpty(captchaEnabled)) { + return true; + } + return Convert.toBool(captchaEnabled); + } + + /** + * 鏌ヨ鍙傛暟閰嶇疆鍒楄〃 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 鍙傛暟閰嶇疆闆嗗悎 + */ + @Override + public List selectConfigList(SysConfig config) { + return configMapper.selectConfigList(config); + } + + /** + * 鏂板鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertConfig(SysConfig config) { + int row = configMapper.insertConfig(config); + if (row > 0) { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + return row; + } + + /** + * 淇敼鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateConfig(SysConfig config) { + int row = configMapper.updateConfig(config); + if (row > 0) { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + return row; + } + + /** + * 鎵归噺鍒犻櫎鍙傛暟淇℃伅 + * + * @param configIds 闇瑕佸垹闄ょ殑鍙傛暟ID + */ + @Override + public void deleteConfigByIds(Long[] configIds) { + for (Long configId : configIds) { + SysConfig config = selectConfigById(configId); + if (StringUtils.equals(UserConstants.YES, config.getConfigType())) { + throw new ServiceException(String.format("鍐呯疆鍙傛暟銆%1$s銆戜笉鑳藉垹闄 ", config.getConfigKey())); + } + configMapper.deleteConfigById(configId); + redisCache.deleteObject(getCacheKey(config.getConfigKey())); + } + } + + /** + * 鍔犺浇鍙傛暟缂撳瓨鏁版嵁 + */ + @Override + public void loadingConfigCache() { + List configsList = configMapper.selectConfigList(new SysConfig()); + for (SysConfig config : configsList) { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + } + + /** + * 娓呯┖鍙傛暟缂撳瓨鏁版嵁 + */ + @Override + public void clearConfigCache() { + Collection keys = redisCache.keys(CacheConstants.SYS_CONFIG_KEY + "*"); + redisCache.deleteObject(keys); + } + + /** + * 閲嶇疆鍙傛暟缂撳瓨鏁版嵁 + */ + @Override + public void resetConfigCache() { + clearConfigCache(); + loadingConfigCache(); + } + + /** + * 鏍¢獙鍙傛暟閿悕鏄惁鍞竴 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkConfigKeyUnique(SysConfig config) { + Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId(); + SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey()); + if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 璁剧疆cache key + * + * @param configKey 鍙傛暟閿 + * @return 缂撳瓨閿甼ey + */ + private String getCacheKey(String configKey) { + return CacheConstants.SYS_CONFIG_KEY + configKey; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDeptServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDeptServiceImpl.java new file mode 100644 index 000000000..176529a67 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDeptServiceImpl.java @@ -0,0 +1,295 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.common.annotation.DataScope; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.domain.TreeSelect; +import com.jsowell.common.core.domain.entity.SysDept; +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.core.text.Convert; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.spring.SpringUtils; +import com.jsowell.system.mapper.SysDeptMapper; +import com.jsowell.system.mapper.SysRoleMapper; +import com.jsowell.system.service.SysDeptService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 閮ㄩ棬绠$悊 鏈嶅姟瀹炵幇 + * + * @author jsowell + */ +@Service +public class SysDeptServiceImpl implements SysDeptService { + @Autowired + private SysDeptMapper deptMapper; + + @Autowired + private SysRoleMapper roleMapper; + + /** + * 鏌ヨ閮ㄩ棬绠$悊鏁版嵁 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 閮ㄩ棬淇℃伅闆嗗悎 + */ + @Override + @DataScope(deptAlias = "d") + public List selectDeptList(SysDept dept) { + return deptMapper.selectDeptList(dept); + } + + /** + * 鏋勫缓鍓嶇鎵闇瑕佹爲缁撴瀯 + * + * @param depts 閮ㄩ棬鍒楄〃 + * @return 鏍戠粨鏋勫垪琛 + */ + @Override + public List buildDeptTree(List depts) { + List returnList = new ArrayList(); + List tempList = new ArrayList(); + for (SysDept dept : depts) { + tempList.add(dept.getDeptId()); + } + for (SysDept dept : depts) { + // 濡傛灉鏄《绾ц妭鐐, 閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣 + if (!tempList.contains(dept.getParentId())) { + recursionFn(depts, dept); + returnList.add(dept); + } + } + if (returnList.isEmpty()) { + returnList = depts; + } + return returnList; + } + + /** + * 鏋勫缓鍓嶇鎵闇瑕佷笅鎷夋爲缁撴瀯 + * + * @param depts 閮ㄩ棬鍒楄〃 + * @return 涓嬫媺鏍戠粨鏋勫垪琛 + */ + @Override + public List buildDeptTreeSelect(List depts) { + List deptTrees = buildDeptTree(depts); + return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + /** + * 鏍规嵁瑙掕壊ID鏌ヨ閮ㄩ棬鏍戜俊鎭 + * + * @param roleId 瑙掕壊ID + * @return 閫変腑閮ㄩ棬鍒楄〃 + */ + @Override + public List selectDeptListByRoleId(Long roleId) { + SysRole role = roleMapper.selectRoleById(roleId); + return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); + } + + /** + * 鏍规嵁閮ㄩ棬ID鏌ヨ淇℃伅 + * + * @param deptId 閮ㄩ棬ID + * @return 閮ㄩ棬淇℃伅 + */ + @Override + public SysDept selectDeptById(Long deptId) { + return deptMapper.selectDeptById(deptId); + } + + /** + * 鏍规嵁ID鏌ヨ鎵鏈夊瓙閮ㄩ棬锛堟甯哥姸鎬侊級 + * + * @param deptId 閮ㄩ棬ID + * @return 瀛愰儴闂ㄦ暟 + */ + @Override + public int selectNormalChildrenDeptById(Long deptId) { + return deptMapper.selectNormalChildrenDeptById(deptId); + } + + /** + * 鏄惁瀛樺湪瀛愯妭鐐 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 + */ + @Override + public boolean hasChildByDeptId(Long deptId) { + int result = deptMapper.hasChildByDeptId(deptId); + return result > 0; + } + + /** + * 鏌ヨ閮ㄩ棬鏄惁瀛樺湪鐢ㄦ埛 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 true 瀛樺湪 false 涓嶅瓨鍦 + */ + @Override + public boolean checkDeptExistUser(Long deptId) { + int result = deptMapper.checkDeptExistUser(deptId); + return result > 0; + } + + /** + * 鏍¢獙閮ㄩ棬鍚嶇О鏄惁鍞竴 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkDeptNameUnique(SysDept dept) { + Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); + SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId()); + if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鏍¢獙閮ㄩ棬鏄惁鏈夋暟鎹潈闄 + * + * @param deptId 閮ㄩ棬id + */ + @Override + public void checkDeptDataScope(Long deptId) { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) { + SysDept dept = new SysDept(); + dept.setDeptId(deptId); + List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + if (StringUtils.isEmpty(depts)) { + throw new ServiceException("娌℃湁鏉冮檺璁块棶閮ㄩ棬鏁版嵁锛"); + } + } + } + + /** + * 鏂板淇濆瓨閮ㄩ棬淇℃伅 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertDept(SysDept dept) { + SysDept info = deptMapper.selectDeptById(dept.getParentId()); + // 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬,鍒欎笉鍏佽鏂板瀛愯妭鐐 + if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { + throw new ServiceException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板"); + } + dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); + return deptMapper.insertDept(dept); + } + + /** + * 淇敼淇濆瓨閮ㄩ棬淇℃伅 + * + * @param dept 閮ㄩ棬淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateDept(SysDept dept) { + SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); + SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); + if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) { + String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); + String oldAncestors = oldDept.getAncestors(); + dept.setAncestors(newAncestors); + updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); + } + int result = deptMapper.updateDept(dept); + if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) + && !StringUtils.equals("0", dept.getAncestors())) { + // 濡傛灉璇ラ儴闂ㄦ槸鍚敤鐘舵侊紝鍒欏惎鐢ㄨ閮ㄩ棬鐨勬墍鏈変笂绾ч儴闂 + updateParentDeptStatusNormal(dept); + } + return result; + } + + /** + * 淇敼璇ラ儴闂ㄧ殑鐖剁骇閮ㄩ棬鐘舵 + * + * @param dept 褰撳墠閮ㄩ棬 + */ + private void updateParentDeptStatusNormal(SysDept dept) { + String ancestors = dept.getAncestors(); + Long[] deptIds = Convert.toLongArray(ancestors); + deptMapper.updateDeptStatusNormal(deptIds); + } + + /** + * 淇敼瀛愬厓绱犲叧绯 + * + * @param deptId 琚慨鏀圭殑閮ㄩ棬ID + * @param newAncestors 鏂扮殑鐖禝D闆嗗悎 + * @param oldAncestors 鏃х殑鐖禝D闆嗗悎 + */ + public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { + List children = deptMapper.selectChildrenDeptById(deptId); + for (SysDept child : children) { + child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); + } + if (children.size() > 0) { + deptMapper.updateDeptChildren(children); + } + } + + /** + * 鍒犻櫎閮ㄩ棬绠$悊淇℃伅 + * + * @param deptId 閮ㄩ棬ID + * @return 缁撴灉 + */ + @Override + public int deleteDeptById(Long deptId) { + return deptMapper.deleteDeptById(deptId); + } + + /** + * 閫掑綊鍒楄〃 + */ + private void recursionFn(List list, SysDept t) { + // 寰楀埌瀛愯妭鐐瑰垪琛 + List childList = getChildList(list, t); + t.setChildren(childList); + for (SysDept tChild : childList) { + if (hasChild(list, tChild)) { + recursionFn(list, tChild); + } + } + } + + /** + * 寰楀埌瀛愯妭鐐瑰垪琛 + */ + private List getChildList(List list, SysDept t) { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) { + SysDept n = (SysDept) it.next(); + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { + tlist.add(n); + } + } + return tlist; + } + + /** + * 鍒ゆ柇鏄惁鏈夊瓙鑺傜偣 + */ + private boolean hasChild(List list, SysDept t) { + return getChildList(list, t).size() > 0; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDictDataServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDictDataServiceImpl.java new file mode 100644 index 000000000..3c3eed963 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDictDataServiceImpl.java @@ -0,0 +1,102 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.common.core.domain.entity.SysDictData; +import com.jsowell.common.util.DictUtils; +import com.jsowell.system.mapper.SysDictDataMapper; +import com.jsowell.system.service.SysDictDataService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 瀛楀吀 涓氬姟灞傚鐞 + * + * @author jsowell + */ +@Service +public class SysDictDataServiceImpl implements SysDictDataService { + @Autowired + private SysDictDataMapper dictDataMapper; + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀鏁版嵁 + * + * @param dictData 瀛楀吀鏁版嵁淇℃伅 + * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅 + */ + @Override + public List selectDictDataList(SysDictData dictData) { + return dictDataMapper.selectDictDataList(dictData); + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷鍜屽瓧鍏搁敭鍊兼煡璇㈠瓧鍏告暟鎹俊鎭 + * + * @param dictType 瀛楀吀绫诲瀷 + * @param dictValue 瀛楀吀閿 + * @return 瀛楀吀鏍囩 + */ + @Override + public String selectDictLabel(String dictType, String dictValue) { + return dictDataMapper.selectDictLabel(dictType, dictValue); + } + + /** + * 鏍规嵁瀛楀吀鏁版嵁ID鏌ヨ淇℃伅 + * + * @param dictCode 瀛楀吀鏁版嵁ID + * @return 瀛楀吀鏁版嵁 + */ + @Override + public SysDictData selectDictDataById(Long dictCode) { + return dictDataMapper.selectDictDataById(dictCode); + } + + /** + * 鎵归噺鍒犻櫎瀛楀吀鏁版嵁淇℃伅 + * + * @param dictCodes 闇瑕佸垹闄ょ殑瀛楀吀鏁版嵁ID + */ + @Override + public void deleteDictDataByIds(Long[] dictCodes) { + for (Long dictCode : dictCodes) { + SysDictData data = selectDictDataById(dictCode); + dictDataMapper.deleteDictDataById(dictCode); + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); + } + } + + /** + * 鏂板淇濆瓨瀛楀吀鏁版嵁淇℃伅 + * + * @param data 瀛楀吀鏁版嵁淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertDictData(SysDictData data) { + int row = dictDataMapper.insertDictData(data); + if (row > 0) { + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); + } + return row; + } + + /** + * 淇敼淇濆瓨瀛楀吀鏁版嵁淇℃伅 + * + * @param data 瀛楀吀鏁版嵁淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateDictData(SysDictData data) { + int row = dictDataMapper.updateDictData(data); + if (row > 0) { + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); + } + return row; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDictTypeServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDictTypeServiceImpl.java new file mode 100644 index 000000000..f26c79526 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysDictTypeServiceImpl.java @@ -0,0 +1,202 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.domain.entity.SysDictData; +import com.jsowell.common.core.domain.entity.SysDictType; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.DictUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.mapper.SysDictDataMapper; +import com.jsowell.system.mapper.SysDictTypeMapper; +import com.jsowell.system.service.SysDictTypeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.PostConstruct; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 瀛楀吀 涓氬姟灞傚鐞 + * + * @author jsowell + */ +@Service +public class SysDictTypeServiceImpl implements SysDictTypeService { + @Autowired + private SysDictTypeMapper dictTypeMapper; + + @Autowired + private SysDictDataMapper dictDataMapper; + + /** + * 椤圭洰鍚姩鏃讹紝鍒濆鍖栧瓧鍏稿埌缂撳瓨 + */ + @PostConstruct + public void init() { + loadingDictCache(); + } + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀绫诲瀷 + * + * @param dictType 瀛楀吀绫诲瀷淇℃伅 + * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 + */ + @Override + public List selectDictTypeList(SysDictType dictType) { + return dictTypeMapper.selectDictTypeList(dictType); + } + + /** + * 鏍规嵁鎵鏈夊瓧鍏哥被鍨 + * + * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 + */ + @Override + public List selectDictTypeAll() { + return dictTypeMapper.selectDictTypeAll(); + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅 + */ + @Override + public List selectDictDataByType(String dictType) { + List dictDatas = DictUtils.getDictCache(dictType); + if (StringUtils.isNotEmpty(dictDatas)) { + return dictDatas; + } + dictDatas = dictDataMapper.selectDictDataByType(dictType); + if (StringUtils.isNotEmpty(dictDatas)) { + DictUtils.setDictCache(dictType, dictDatas); + return dictDatas; + } + return null; + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷ID鏌ヨ淇℃伅 + * + * @param dictId 瀛楀吀绫诲瀷ID + * @return 瀛楀吀绫诲瀷 + */ + @Override + public SysDictType selectDictTypeById(Long dictId) { + return dictTypeMapper.selectDictTypeById(dictId); + } + + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ淇℃伅 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀绫诲瀷 + */ + @Override + public SysDictType selectDictTypeByType(String dictType) { + return dictTypeMapper.selectDictTypeByType(dictType); + } + + /** + * 鎵归噺鍒犻櫎瀛楀吀绫诲瀷淇℃伅 + * + * @param dictIds 闇瑕佸垹闄ょ殑瀛楀吀ID + */ + @Override + public void deleteDictTypeByIds(Long[] dictIds) { + for (Long dictId : dictIds) { + SysDictType dictType = selectDictTypeById(dictId); + if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) { + throw new ServiceException(String.format("%1$s宸插垎閰,涓嶈兘鍒犻櫎", dictType.getDictName())); + } + dictTypeMapper.deleteDictTypeById(dictId); + DictUtils.removeDictCache(dictType.getDictType()); + } + } + + /** + * 鍔犺浇瀛楀吀缂撳瓨鏁版嵁 + */ + @Override + public void loadingDictCache() { + SysDictData dictData = new SysDictData(); + dictData.setStatus("0"); + Map> dictDataMap = dictDataMapper.selectDictDataList(dictData).stream().collect(Collectors.groupingBy(SysDictData::getDictType)); + for (Map.Entry> entry : dictDataMap.entrySet()) { + DictUtils.setDictCache(entry.getKey(), entry.getValue().stream().sorted(Comparator.comparing(SysDictData::getDictSort)).collect(Collectors.toList())); + } + } + + /** + * 娓呯┖瀛楀吀缂撳瓨鏁版嵁 + */ + @Override + public void clearDictCache() { + DictUtils.clearDictCache(); + } + + /** + * 閲嶇疆瀛楀吀缂撳瓨鏁版嵁 + */ + @Override + public void resetDictCache() { + clearDictCache(); + loadingDictCache(); + } + + /** + * 鏂板淇濆瓨瀛楀吀绫诲瀷淇℃伅 + * + * @param dict 瀛楀吀绫诲瀷淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertDictType(SysDictType dict) { + int row = dictTypeMapper.insertDictType(dict); + if (row > 0) { + DictUtils.setDictCache(dict.getDictType(), null); + } + return row; + } + + /** + * 淇敼淇濆瓨瀛楀吀绫诲瀷淇℃伅 + * + * @param dict 瀛楀吀绫诲瀷淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public int updateDictType(SysDictType dict) { + SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId()); + dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType()); + int row = dictTypeMapper.updateDictType(dict); + if (row > 0) { + List dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType()); + DictUtils.setDictCache(dict.getDictType(), dictDatas); + } + return row; + } + + /** + * 鏍¢獙瀛楀吀绫诲瀷绉版槸鍚﹀敮涓 + * + * @param dict 瀛楀吀绫诲瀷 + * @return 缁撴灉 + */ + @Override + public String checkDictTypeUnique(SysDictType dict) { + Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); + SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); + if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysLogininforServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysLogininforServiceImpl.java new file mode 100644 index 000000000..deb9bb02e --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysLogininforServiceImpl.java @@ -0,0 +1,61 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.system.domain.SysLogininfor; +import com.jsowell.system.mapper.SysLogininforMapper; +import com.jsowell.system.service.SysLogininforService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 绯荤粺璁块棶鏃ュ織鎯呭喌淇℃伅 鏈嶅姟灞傚鐞 + * + * @author jsowell + */ +@Service +public class SysLogininforServiceImpl implements SysLogininforService { + + @Autowired + private SysLogininforMapper logininforMapper; + + /** + * 鏂板绯荤粺鐧诲綍鏃ュ織 + * + * @param logininfor 璁块棶鏃ュ織瀵硅薄 + */ + @Override + public void insertLogininfor(SysLogininfor logininfor) { + logininforMapper.insertLogininfor(logininfor); + } + + /** + * 鏌ヨ绯荤粺鐧诲綍鏃ュ織闆嗗悎 + * + * @param logininfor 璁块棶鏃ュ織瀵硅薄 + * @return 鐧诲綍璁板綍闆嗗悎 + */ + @Override + public List selectLogininforList(SysLogininfor logininfor) { + return logininforMapper.selectLogininforList(logininfor); + } + + /** + * 鎵归噺鍒犻櫎绯荤粺鐧诲綍鏃ュ織 + * + * @param infoIds 闇瑕佸垹闄ょ殑鐧诲綍鏃ュ織ID + * @return 缁撴灉 + */ + @Override + public int deleteLogininforByIds(Long[] infoIds) { + return logininforMapper.deleteLogininforByIds(infoIds); + } + + /** + * 娓呯┖绯荤粺鐧诲綍鏃ュ織 + */ + @Override + public void cleanLogininfor() { + logininforMapper.cleanLogininfor(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysMenuServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysMenuServiceImpl.java new file mode 100644 index 000000000..ba4b5a896 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysMenuServiceImpl.java @@ -0,0 +1,457 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.common.constant.Constants; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.domain.TreeSelect; +import com.jsowell.common.core.domain.entity.SysMenu; +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.mapper.SysMenuMapper; +import com.jsowell.system.mapper.SysRoleMapper; +import com.jsowell.system.mapper.SysRoleMenuMapper; +import com.jsowell.system.service.SysMenuService; +import com.jsowell.system.vo.MetaVO; +import com.jsowell.system.vo.RouterVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * 鑿滃崟 涓氬姟灞傚鐞 + * + * @author jsowell + */ +@Slf4j +@Service +public class SysMenuServiceImpl implements SysMenuService { + public static final String PREMISSION_STRING = "perms[\"{0}\"]"; + + @Autowired + private SysMenuMapper menuMapper; + + @Autowired + private SysRoleMapper roleMapper; + + @Autowired + private SysRoleMenuMapper roleMenuMapper; + + /** + * 鏍规嵁鐢ㄦ埛鏌ヨ绯荤粺鑿滃崟鍒楄〃 + * + * @param userId 鐢ㄦ埛ID + * @return 鑿滃崟鍒楄〃 + */ + @Override + public List selectMenuList(Long userId) { + return selectMenuList(new SysMenu(), userId); + } + + /** + * 鏌ヨ绯荤粺鑿滃崟鍒楄〃 + * + * @param menu 鑿滃崟淇℃伅 + * @return 鑿滃崟鍒楄〃 + */ + @Override + public List selectMenuList(SysMenu menu, Long userId) { + List menuList = null; + // 绠$悊鍛樻樉绀烘墍鏈夎彍鍗曚俊鎭 + if (SysUser.isAdmin(userId)) { + menuList = menuMapper.selectMenuList(menu); + } else { + menu.getParams().put("userId", userId); + menuList = menuMapper.selectMenuListByUserId(menu); + } + return menuList; + } + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鏉冮檺 + * + * @param userId 鐢ㄦ埛ID + * @return 鏉冮檺鍒楄〃 + */ + @Override + public Set selectMenuPermsByUserId(Long userId) { + List perms = menuMapper.selectMenuPermsByUserId(userId); + Set permsSet = new HashSet<>(); + for (String perm : perms) { + if (StringUtils.isNotEmpty(perm)) { + permsSet.addAll(Arrays.asList(perm.trim().split(","))); + } + } + return permsSet; + } + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鑿滃崟 + * + * @param userId 鐢ㄦ埛鍚嶇О + * @return 鑿滃崟鍒楄〃 + */ + @Override + public List selectMenuTreeByUserId(Long userId) { + List menus = null; + if (SecurityUtils.isAdmin(userId)) { + menus = menuMapper.selectMenuTreeAll(); + } else { + menus = menuMapper.selectMenuTreeByUserId(userId); + } + return getChildPerms(menus, 0); + } + + /** + * 鏍规嵁瑙掕壊ID鏌ヨ鑿滃崟鏍戜俊鎭 + * + * @param roleId 瑙掕壊ID + * @return 閫変腑鑿滃崟鍒楄〃 + */ + @Override + public List selectMenuListByRoleId(Long roleId) { + SysRole role = roleMapper.selectRoleById(roleId); + return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly()); + } + + /** + * 鏋勫缓鍓嶇璺敱鎵闇瑕佺殑鑿滃崟 + * + * @param menus 鑿滃崟鍒楄〃 + * @return 璺敱鍒楄〃 + */ + @Override + public List buildMenus(List menus) { + List routers = new LinkedList(); + for (SysMenu menu : menus) { + RouterVO router = new RouterVO(); + router.setHidden("1".equals(menu.getVisible())); + router.setName(getRouteName(menu)); + router.setPath(getRouterPath(menu)); + router.setComponent(getComponent(menu)); + router.setQuery(menu.getQuery()); + router.setMeta(new MetaVO(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); + List cMenus = menu.getChildren(); + if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { + router.setAlwaysShow(true); + router.setRedirect("noRedirect"); + router.setChildren(buildMenus(cMenus)); + } else if (isMenuFrame(menu)) { + router.setMeta(null); + List childrenList = new ArrayList(); + RouterVO children = new RouterVO(); + children.setPath(menu.getPath()); + children.setComponent(menu.getComponent()); + children.setName(StringUtils.capitalize(menu.getPath())); + children.setMeta(new MetaVO(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); + children.setQuery(menu.getQuery()); + childrenList.add(children); + router.setChildren(childrenList); + } else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) { + router.setMeta(new MetaVO(menu.getMenuName(), menu.getIcon())); + router.setPath("/"); + List childrenList = new ArrayList(); + RouterVO children = new RouterVO(); + String routerPath = innerLinkReplaceEach(menu.getPath()); + children.setPath(routerPath); + children.setComponent(UserConstants.INNER_LINK); + children.setName(StringUtils.capitalize(routerPath)); + children.setMeta(new MetaVO(menu.getMenuName(), menu.getIcon(), menu.getPath())); + childrenList.add(children); + router.setChildren(childrenList); + } + routers.add(router); + } + return routers; + } + + /** + * 鏋勫缓鍓嶇鎵闇瑕佹爲缁撴瀯 + * + * @param menus 鑿滃崟鍒楄〃 + * @return 鏍戠粨鏋勫垪琛 + */ + @Override + public List buildMenuTree(List menus) { + List returnList = new ArrayList(); + List tempList = new ArrayList(); + for (SysMenu dept : menus) { + tempList.add(dept.getMenuId()); + } + for (Iterator iterator = menus.iterator(); iterator.hasNext(); ) { + SysMenu menu = (SysMenu) iterator.next(); + // 濡傛灉鏄《绾ц妭鐐, 閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣 + if (!tempList.contains(menu.getParentId())) { + recursionFn(menus, menu); + returnList.add(menu); + } + } + if (returnList.isEmpty()) { + returnList = menus; + } + return returnList; + } + + /** + * 鏋勫缓鍓嶇鎵闇瑕佷笅鎷夋爲缁撴瀯 + * + * @param menus 鑿滃崟鍒楄〃 + * @return 涓嬫媺鏍戠粨鏋勫垪琛 + */ + @Override + public List buildMenuTreeSelect(List menus) { + List menuTrees = buildMenuTree(menus); + return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + /** + * 鏍规嵁鑿滃崟ID鏌ヨ淇℃伅 + * + * @param menuId 鑿滃崟ID + * @return 鑿滃崟淇℃伅 + */ + @Override + public SysMenu selectMenuById(Long menuId) { + return menuMapper.selectMenuById(menuId); + } + + /** + * 鏄惁瀛樺湪鑿滃崟瀛愯妭鐐 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 + */ + @Override + public boolean hasChildByMenuId(Long menuId) { + int result = menuMapper.hasChildByMenuId(menuId); + return result > 0; + } + + /** + * 鏌ヨ鑿滃崟浣跨敤鏁伴噺 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 + */ + @Override + public boolean checkMenuExistRole(Long menuId) { + int result = roleMenuMapper.checkMenuExistRole(menuId); + return result > 0; + } + + /** + * 鏂板淇濆瓨鑿滃崟淇℃伅 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertMenu(SysMenu menu) { + return menuMapper.insertMenu(menu); + } + + /** + * 淇敼淇濆瓨鑿滃崟淇℃伅 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateMenu(SysMenu menu) { + return menuMapper.updateMenu(menu); + } + + /** + * 鍒犻櫎鑿滃崟绠$悊淇℃伅 + * + * @param menuId 鑿滃崟ID + * @return 缁撴灉 + */ + @Override + public int deleteMenuById(Long menuId) { + return menuMapper.deleteMenuById(menuId); + } + + /** + * 鏍¢獙鑿滃崟鍚嶇О鏄惁鍞竴 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkMenuNameUnique(SysMenu menu) { + Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); + SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId()); + if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鑾峰彇璺敱鍚嶇О + * + * @param menu 鑿滃崟淇℃伅 + * @return 璺敱鍚嶇О + */ + public String getRouteName(SysMenu menu) { + String routerName = StringUtils.capitalize(menu.getPath()); + // 闈炲閾惧苟涓旀槸涓绾х洰褰曪紙绫诲瀷涓虹洰褰曪級 + if (isMenuFrame(menu)) { + routerName = StringUtils.EMPTY; + } + return routerName; + } + + /** + * 鑾峰彇璺敱鍦板潃 + * + * @param menu 鑿滃崟淇℃伅 + * @return 璺敱鍦板潃 + */ + public String getRouterPath(SysMenu menu) { + String routerPath = menu.getPath(); + // 鍐呴摼鎵撳紑澶栫綉鏂瑰紡 + if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) { + routerPath = innerLinkReplaceEach(routerPath); + } + // 闈炲閾惧苟涓旀槸涓绾х洰褰曪紙绫诲瀷涓虹洰褰曪級 + if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) + && UserConstants.NO_FRAME.equals(menu.getIsFrame())) { + routerPath = "/" + menu.getPath(); + } + // 闈炲閾惧苟涓旀槸涓绾х洰褰曪紙绫诲瀷涓鸿彍鍗曪級 + else if (isMenuFrame(menu)) { + routerPath = "/"; + } + return routerPath; + } + + /** + * 鑾峰彇缁勪欢淇℃伅 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁勪欢淇℃伅 + */ + public String getComponent(SysMenu menu) { + String component = UserConstants.LAYOUT; + if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) { + component = menu.getComponent(); + } else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) { + component = UserConstants.INNER_LINK; + } else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) { + component = UserConstants.PARENT_VIEW; + } + return component; + } + + /** + * 鏄惁涓鸿彍鍗曞唴閮ㄨ烦杞 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + public boolean isMenuFrame(SysMenu menu) { + return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType()) + && menu.getIsFrame().equals(UserConstants.NO_FRAME); + } + + /** + * 鏄惁涓哄唴閾剧粍浠 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + public boolean isInnerLink(SysMenu menu) { + return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.isHttp(menu.getPath()); + } + + /** + * 鏄惁涓簆arent_view缁勪欢 + * + * @param menu 鑿滃崟淇℃伅 + * @return 缁撴灉 + */ + public boolean isParentView(SysMenu menu) { + return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()); + } + + /** + * 鏍规嵁鐖惰妭鐐圭殑ID鑾峰彇鎵鏈夊瓙鑺傜偣 + * + * @param list 鍒嗙被琛 + * @param parentId 浼犲叆鐨勭埗鑺傜偣ID + * @return String + */ + public List getChildPerms(List list, int parentId) { + List returnList = new ArrayList(); + for (Iterator iterator = list.iterator(); iterator.hasNext(); ) { + SysMenu t = (SysMenu) iterator.next(); + // 涓銆佹牴鎹紶鍏ョ殑鏌愪釜鐖惰妭鐐笽D,閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣 + if (t.getParentId() == parentId) { + recursionFn(list, t); + returnList.add(t); + } + } + return returnList; + } + + /** + * 閫掑綊鍒楄〃 + * + * @param list + * @param t + */ + private void recursionFn(List list, SysMenu t) { + // 寰楀埌瀛愯妭鐐瑰垪琛 + List childList = getChildList(list, t); + t.setChildren(childList); + for (SysMenu tChild : childList) { + if (hasChild(list, tChild)) { + recursionFn(list, tChild); + } + } + } + + /** + * 寰楀埌瀛愯妭鐐瑰垪琛 + */ + private List getChildList(List list, SysMenu t) { + // log.info("寰楀埌瀛愯妭鐐瑰垪琛 list:{}, SysMenu:{}", JSONObject.toJSONString(list), JSONObject.toJSONString(t)); + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) { + SysMenu n = (SysMenu) it.next(); + if (n.getParentId().longValue() == t.getMenuId().longValue()) { + tlist.add(n); + } + } + return tlist; + } + + /** + * 鍒ゆ柇鏄惁鏈夊瓙鑺傜偣 + */ + private boolean hasChild(List list, SysMenu t) { + return getChildList(list, t).size() > 0; + } + + /** + * 鍐呴摼鍩熷悕鐗规畩瀛楃鏇挎崲 + * + * @return + */ + public String innerLinkReplaceEach(String path) { + return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS}, + new String[]{"", ""}); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysNoticeServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysNoticeServiceImpl.java new file mode 100644 index 000000000..c74fad41d --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysNoticeServiceImpl.java @@ -0,0 +1,86 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.system.domain.SysNotice; +import com.jsowell.system.mapper.SysNoticeMapper; +import com.jsowell.system.service.SysNoticeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 鍏憡 鏈嶅姟灞傚疄鐜 + * + * @author jsowell + */ +@Service +public class SysNoticeServiceImpl implements SysNoticeService { + @Autowired + private SysNoticeMapper noticeMapper; + + /** + * 鏌ヨ鍏憡淇℃伅 + * + * @param noticeId 鍏憡ID + * @return 鍏憡淇℃伅 + */ + @Override + public SysNotice selectNoticeById(Long noticeId) { + return noticeMapper.selectNoticeById(noticeId); + } + + /** + * 鏌ヨ鍏憡鍒楄〃 + * + * @param notice 鍏憡淇℃伅 + * @return 鍏憡闆嗗悎 + */ + @Override + public List selectNoticeList(SysNotice notice) { + return noticeMapper.selectNoticeList(notice); + } + + /** + * 鏂板鍏憡 + * + * @param notice 鍏憡淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertNotice(SysNotice notice) { + return noticeMapper.insertNotice(notice); + } + + /** + * 淇敼鍏憡 + * + * @param notice 鍏憡淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateNotice(SysNotice notice) { + return noticeMapper.updateNotice(notice); + } + + /** + * 鍒犻櫎鍏憡瀵硅薄 + * + * @param noticeId 鍏憡ID + * @return 缁撴灉 + */ + @Override + public int deleteNoticeById(Long noticeId) { + return noticeMapper.deleteNoticeById(noticeId); + } + + /** + * 鎵归噺鍒犻櫎鍏憡淇℃伅 + * + * @param noticeIds 闇瑕佸垹闄ょ殑鍏憡ID + * @return 缁撴灉 + */ + @Override + public int deleteNoticeByIds(Long[] noticeIds) { + return noticeMapper.deleteNoticeByIds(noticeIds); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysOperLogServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysOperLogServiceImpl.java new file mode 100644 index 000000000..b273276b5 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysOperLogServiceImpl.java @@ -0,0 +1,71 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.system.domain.SysOperLog; +import com.jsowell.system.mapper.SysOperLogMapper; +import com.jsowell.system.service.SysOperLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 鎿嶄綔鏃ュ織 鏈嶅姟灞傚鐞 + * + * @author jsowell + */ +@Service +public class SysOperLogServiceImpl implements SysOperLogService { + @Autowired + private SysOperLogMapper operLogMapper; + + /** + * 鏂板鎿嶄綔鏃ュ織 + * + * @param operLog 鎿嶄綔鏃ュ織瀵硅薄 + */ + @Override + public void insertOperlog(SysOperLog operLog) { + operLogMapper.insertOperlog(operLog); + } + + /** + * 鏌ヨ绯荤粺鎿嶄綔鏃ュ織闆嗗悎 + * + * @param operLog 鎿嶄綔鏃ュ織瀵硅薄 + * @return 鎿嶄綔鏃ュ織闆嗗悎 + */ + @Override + public List selectOperLogList(SysOperLog operLog) { + return operLogMapper.selectOperLogList(operLog); + } + + /** + * 鎵归噺鍒犻櫎绯荤粺鎿嶄綔鏃ュ織 + * + * @param operIds 闇瑕佸垹闄ょ殑鎿嶄綔鏃ュ織ID + * @return 缁撴灉 + */ + @Override + public int deleteOperLogByIds(Long[] operIds) { + return operLogMapper.deleteOperLogByIds(operIds); + } + + /** + * 鏌ヨ鎿嶄綔鏃ュ織璇︾粏 + * + * @param operId 鎿嶄綔ID + * @return 鎿嶄綔鏃ュ織瀵硅薄 + */ + @Override + public SysOperLog selectOperLogById(Long operId) { + return operLogMapper.selectOperLogById(operId); + } + + /** + * 娓呯┖鎿嶄綔鏃ュ織 + */ + @Override + public void cleanOperLog() { + operLogMapper.cleanOperLog(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysPostServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysPostServiceImpl.java new file mode 100644 index 000000000..1116617a3 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysPostServiceImpl.java @@ -0,0 +1,163 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.domain.SysPost; +import com.jsowell.system.mapper.SysPostMapper; +import com.jsowell.system.mapper.SysUserPostMapper; +import com.jsowell.system.service.SysPostService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 宀椾綅淇℃伅 鏈嶅姟灞傚鐞 + * + * @author jsowell + */ +@Service +public class SysPostServiceImpl implements SysPostService { + @Autowired + private SysPostMapper postMapper; + + @Autowired + private SysUserPostMapper userPostMapper; + + /** + * 鏌ヨ宀椾綅淇℃伅闆嗗悎 + * + * @param post 宀椾綅淇℃伅 + * @return 宀椾綅淇℃伅闆嗗悎 + */ + @Override + public List selectPostList(SysPost post) { + return postMapper.selectPostList(post); + } + + /** + * 鏌ヨ鎵鏈夊矖浣 + * + * @return 宀椾綅鍒楄〃 + */ + @Override + public List selectPostAll() { + return postMapper.selectPostAll(); + } + + /** + * 閫氳繃宀椾綅ID鏌ヨ宀椾綅淇℃伅 + * + * @param postId 宀椾綅ID + * @return 瑙掕壊瀵硅薄淇℃伅 + */ + @Override + public SysPost selectPostById(Long postId) { + return postMapper.selectPostById(postId); + } + + /** + * 鏍规嵁鐢ㄦ埛ID鑾峰彇宀椾綅閫夋嫨妗嗗垪琛 + * + * @param userId 鐢ㄦ埛ID + * @return 閫変腑宀椾綅ID鍒楄〃 + */ + @Override + public List selectPostListByUserId(Long userId) { + return postMapper.selectPostListByUserId(userId); + } + + /** + * 鏍¢獙宀椾綅鍚嶇О鏄惁鍞竴 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkPostNameUnique(SysPost post) { + Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); + SysPost info = postMapper.checkPostNameUnique(post.getPostName()); + if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鏍¢獙宀椾綅缂栫爜鏄惁鍞竴 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkPostCodeUnique(SysPost post) { + Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); + SysPost info = postMapper.checkPostCodeUnique(post.getPostCode()); + if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 閫氳繃宀椾綅ID鏌ヨ宀椾綅浣跨敤鏁伴噺 + * + * @param postId 宀椾綅ID + * @return 缁撴灉 + */ + @Override + public int countUserPostById(Long postId) { + return userPostMapper.countUserPostById(postId); + } + + /** + * 鍒犻櫎宀椾綅淇℃伅 + * + * @param postId 宀椾綅ID + * @return 缁撴灉 + */ + @Override + public int deletePostById(Long postId) { + return postMapper.deletePostById(postId); + } + + /** + * 鎵归噺鍒犻櫎宀椾綅淇℃伅 + * + * @param postIds 闇瑕佸垹闄ょ殑宀椾綅ID + * @return 缁撴灉 + */ + @Override + public int deletePostByIds(Long[] postIds) { + for (Long postId : postIds) { + SysPost post = selectPostById(postId); + if (countUserPostById(postId) > 0) { + throw new ServiceException(String.format("%1$s宸插垎閰,涓嶈兘鍒犻櫎", post.getPostName())); + } + } + return postMapper.deletePostByIds(postIds); + } + + /** + * 鏂板淇濆瓨宀椾綅淇℃伅 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertPost(SysPost post) { + return postMapper.insertPost(post); + } + + /** + * 淇敼淇濆瓨宀椾綅淇℃伅 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updatePost(SysPost post) { + return postMapper.updatePost(post); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysRoleServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysRoleServiceImpl.java new file mode 100644 index 000000000..1e0e34a1a --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysRoleServiceImpl.java @@ -0,0 +1,381 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.common.annotation.DataScope; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.spring.SpringUtils; +import com.jsowell.system.domain.SysRoleDept; +import com.jsowell.system.domain.SysRoleMenu; +import com.jsowell.system.domain.SysUserRole; +import com.jsowell.system.mapper.SysRoleDeptMapper; +import com.jsowell.system.mapper.SysRoleMapper; +import com.jsowell.system.mapper.SysRoleMenuMapper; +import com.jsowell.system.mapper.SysUserRoleMapper; +import com.jsowell.system.service.SysRoleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +/** + * 瑙掕壊 涓氬姟灞傚鐞 + * + * @author jsowell + */ +@Service +public class SysRoleServiceImpl implements SysRoleService { + @Autowired + private SysRoleMapper roleMapper; + + @Autowired + private SysRoleMenuMapper roleMenuMapper; + + @Autowired + private SysUserRoleMapper userRoleMapper; + + @Autowired + private SysRoleDeptMapper roleDeptMapper; + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瑙掕壊鏁版嵁 + * + * @param role 瑙掕壊淇℃伅 + * @return 瑙掕壊鏁版嵁闆嗗悎淇℃伅 + */ + @Override + @DataScope(deptAlias = "d") + public List selectRoleList(SysRole role) { + return roleMapper.selectRoleList(role); + } + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ瑙掕壊 + * + * @param userId 鐢ㄦ埛ID + * @return 瑙掕壊鍒楄〃 + */ + @Override + public List selectRolesByUserId(Long userId) { + List userRoles = roleMapper.selectRolePermissionByUserId(userId); + List roles = selectRoleAll(); + for (SysRole role : roles) { + for (SysRole userRole : userRoles) { + if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) { + role.setFlag(true); + break; + } + } + } + return roles; + } + + /** + * 鏍规嵁鐢ㄦ埛ID鏌ヨ鏉冮檺 + * + * @param userId 鐢ㄦ埛ID + * @return 鏉冮檺鍒楄〃 + */ + @Override + public Set selectRolePermissionByUserId(Long userId) { + List perms = roleMapper.selectRolePermissionByUserId(userId); + Set permsSet = new HashSet<>(); + for (SysRole perm : perms) { + if (StringUtils.isNotNull(perm)) { + permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); + } + } + return permsSet; + } + + /** + * 鏌ヨ鎵鏈夎鑹 + * + * @return 瑙掕壊鍒楄〃 + */ + @Override + public List selectRoleAll() { + return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); + } + + /** + * 鏍规嵁鐢ㄦ埛ID鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛 + * + * @param userId 鐢ㄦ埛ID + * @return 閫変腑瑙掕壊ID鍒楄〃 + */ + @Override + public List selectRoleListByUserId(Long userId) { + return roleMapper.selectRoleListByUserId(userId); + } + + /** + * 閫氳繃瑙掕壊ID鏌ヨ瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @return 瑙掕壊瀵硅薄淇℃伅 + */ + @Override + public SysRole selectRoleById(Long roleId) { + return roleMapper.selectRoleById(roleId); + } + + /** + * 鏍¢獙瑙掕壊鍚嶇О鏄惁鍞竴 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkRoleNameUnique(SysRole role) { + Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); + SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName()); + if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鏍¢獙瑙掕壊鏉冮檺鏄惁鍞竴 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkRoleKeyUnique(SysRole role) { + Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); + SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey()); + if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鏍¢獙瑙掕壊鏄惁鍏佽鎿嶄綔 + * + * @param role 瑙掕壊淇℃伅 + */ + @Override + public void checkRoleAllowed(SysRole role) { + if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) { + throw new ServiceException("涓嶅厑璁告搷浣滆秴绾х鐞嗗憳瑙掕壊"); + } + } + + /** + * 鏍¢獙瑙掕壊鏄惁鏈夋暟鎹潈闄 + * + * @param roleId 瑙掕壊id + */ + @Override + public void checkRoleDataScope(Long roleId) { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) { + SysRole role = new SysRole(); + role.setRoleId(roleId); + List roles = SpringUtils.getAopProxy(this).selectRoleList(role); + if (StringUtils.isEmpty(roles)) { + throw new ServiceException("娌℃湁鏉冮檺璁块棶瑙掕壊鏁版嵁锛"); + } + } + } + + /** + * 閫氳繃瑙掕壊ID鏌ヨ瑙掕壊浣跨敤鏁伴噺 + * + * @param roleId 瑙掕壊ID + * @return 缁撴灉 + */ + @Override + public int countUserRoleByRoleId(Long roleId) { + return userRoleMapper.countUserRoleByRoleId(roleId); + } + + /** + * 鏂板淇濆瓨瑙掕壊淇℃伅 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public int insertRole(SysRole role) { + // 鏂板瑙掕壊淇℃伅 + roleMapper.insertRole(role); + return insertRoleMenu(role); + } + + /** + * 淇敼淇濆瓨瑙掕壊淇℃伅 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public int updateRole(SysRole role) { + // 淇敼瑙掕壊淇℃伅 + roleMapper.updateRole(role); + // 鍒犻櫎瑙掕壊涓庤彍鍗曞叧鑱 + roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId()); + return insertRoleMenu(role); + } + + /** + * 淇敼瑙掕壊鐘舵 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateRoleStatus(SysRole role) { + return roleMapper.updateRole(role); + } + + /** + * 淇敼鏁版嵁鏉冮檺淇℃伅 + * + * @param role 瑙掕壊淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public int authDataScope(SysRole role) { + // 淇敼瑙掕壊淇℃伅 + roleMapper.updateRole(role); + // 鍒犻櫎瑙掕壊涓庨儴闂ㄥ叧鑱 + roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId()); + // 鏂板瑙掕壊鍜岄儴闂ㄤ俊鎭紙鏁版嵁鏉冮檺锛 + return insertRoleDept(role); + } + + /** + * 鏂板瑙掕壊鑿滃崟淇℃伅 + * + * @param role 瑙掕壊瀵硅薄 + */ + public int insertRoleMenu(SysRole role) { + int rows = 1; + // 鏂板鐢ㄦ埛涓庤鑹茬鐞 + List list = new ArrayList(); + for (Long menuId : role.getMenuIds()) { + SysRoleMenu rm = new SysRoleMenu(); + rm.setRoleId(role.getRoleId()); + rm.setMenuId(menuId); + list.add(rm); + } + if (list.size() > 0) { + rows = roleMenuMapper.batchRoleMenu(list); + } + return rows; + } + + /** + * 鏂板瑙掕壊閮ㄩ棬淇℃伅(鏁版嵁鏉冮檺) + * + * @param role 瑙掕壊瀵硅薄 + */ + public int insertRoleDept(SysRole role) { + int rows = 1; + // 鏂板瑙掕壊涓庨儴闂紙鏁版嵁鏉冮檺锛夌鐞 + List list = new ArrayList(); + for (Long deptId : role.getDeptIds()) { + SysRoleDept rd = new SysRoleDept(); + rd.setRoleId(role.getRoleId()); + rd.setDeptId(deptId); + list.add(rd); + } + if (list.size() > 0) { + rows = roleDeptMapper.batchRoleDept(list); + } + return rows; + } + + /** + * 閫氳繃瑙掕壊ID鍒犻櫎瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @return 缁撴灉 + */ + @Override + @Transactional + public int deleteRoleById(Long roleId) { + // 鍒犻櫎瑙掕壊涓庤彍鍗曞叧鑱 + roleMenuMapper.deleteRoleMenuByRoleId(roleId); + // 鍒犻櫎瑙掕壊涓庨儴闂ㄥ叧鑱 + roleDeptMapper.deleteRoleDeptByRoleId(roleId); + return roleMapper.deleteRoleById(roleId); + } + + /** + * 鎵归噺鍒犻櫎瑙掕壊淇℃伅 + * + * @param roleIds 闇瑕佸垹闄ょ殑瑙掕壊ID + * @return 缁撴灉 + */ + @Override + @Transactional + public int deleteRoleByIds(Long[] roleIds) { + for (Long roleId : roleIds) { + checkRoleAllowed(new SysRole(roleId)); + checkRoleDataScope(roleId); + SysRole role = selectRoleById(roleId); + if (countUserRoleByRoleId(roleId) > 0) { + throw new ServiceException(String.format("%1$s宸插垎閰,涓嶈兘鍒犻櫎", role.getRoleName())); + } + } + // 鍒犻櫎瑙掕壊涓庤彍鍗曞叧鑱 + roleMenuMapper.deleteRoleMenu(roleIds); + // 鍒犻櫎瑙掕壊涓庨儴闂ㄥ叧鑱 + roleDeptMapper.deleteRoleDept(roleIds); + return roleMapper.deleteRoleByIds(roleIds); + } + + /** + * 鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param userRole 鐢ㄦ埛鍜岃鑹插叧鑱斾俊鎭 + * @return 缁撴灉 + */ + @Override + public int deleteAuthUser(SysUserRole userRole) { + return userRoleMapper.deleteUserRoleInfo(userRole); + } + + /** + * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇瑕佸彇娑堟巿鏉冪殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + @Override + public int deleteAuthUsers(Long roleId, Long[] userIds) { + return userRoleMapper.deleteUserRoleInfos(roleId, userIds); + } + + /** + * 鎵归噺閫夋嫨鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇瑕佹巿鏉冪殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + @Override + public int insertAuthUsers(Long roleId, Long[] userIds) { + // 鏂板鐢ㄦ埛涓庤鑹茬鐞 + List list = new ArrayList(); + for (Long userId : userIds) { + SysUserRole ur = new SysUserRole(); + ur.setUserId(userId); + ur.setRoleId(roleId); + list.add(ur); + } + return userRoleMapper.batchUserRole(list); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysUserOnlineServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysUserOnlineServiceImpl.java new file mode 100644 index 000000000..d55050497 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysUserOnlineServiceImpl.java @@ -0,0 +1,86 @@ +package com.jsowell.system.service.impl; + +import org.springframework.stereotype.Service; +import com.jsowell.common.core.domain.model.LoginUser; +import com.jsowell.common.util.StringUtils; +import com.jsowell.system.domain.SysUserOnline; +import com.jsowell.system.service.SysUserOnlineService; + +/** + * 鍦ㄧ嚎鐢ㄦ埛 鏈嶅姟灞傚鐞 + * + * @author jsowell + */ +@Service +public class SysUserOnlineServiceImpl implements SysUserOnlineService { + /** + * 閫氳繃鐧诲綍鍦板潃鏌ヨ淇℃伅 + * + * @param ipaddr 鐧诲綍鍦板潃 + * @param user 鐢ㄦ埛淇℃伅 + * @return 鍦ㄧ嚎鐢ㄦ埛淇℃伅 + */ + @Override + public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) { + if (StringUtils.equals(ipaddr, user.getIpaddr())) { + return loginUserToUserOnline(user); + } + return null; + } + + /** + * 閫氳繃鐢ㄦ埛鍚嶇О鏌ヨ淇℃伅 + * + * @param userName 鐢ㄦ埛鍚嶇О + * @param user 鐢ㄦ埛淇℃伅 + * @return 鍦ㄧ嚎鐢ㄦ埛淇℃伅 + */ + @Override + public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) { + if (StringUtils.equals(userName, user.getUsername())) { + return loginUserToUserOnline(user); + } + return null; + } + + /** + * 閫氳繃鐧诲綍鍦板潃/鐢ㄦ埛鍚嶇О鏌ヨ淇℃伅 + * + * @param ipaddr 鐧诲綍鍦板潃 + * @param userName 鐢ㄦ埛鍚嶇О + * @param user 鐢ㄦ埛淇℃伅 + * @return 鍦ㄧ嚎鐢ㄦ埛淇℃伅 + */ + @Override + public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) { + if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) { + return loginUserToUserOnline(user); + } + return null; + } + + /** + * 璁剧疆鍦ㄧ嚎鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鍦ㄧ嚎鐢ㄦ埛 + */ + @Override + public SysUserOnline loginUserToUserOnline(LoginUser user) { + if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) { + return null; + } + SysUserOnline sysUserOnline = new SysUserOnline(); + sysUserOnline.setTokenId(user.getToken()); + sysUserOnline.setUserName(user.getUsername()); + sysUserOnline.setIpaddr(user.getIpaddr()); + sysUserOnline.setLoginLocation(user.getLoginLocation()); + sysUserOnline.setBrowser(user.getBrowser()); + sysUserOnline.setOs(user.getOs()); + sysUserOnline.setLoginTime(user.getLoginTime()); + if (StringUtils.isNotNull(user.getUser().getDept())) { + sysUserOnline.setDeptName(user.getUser().getDept().getDeptName()); + } + return sysUserOnline; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysUserServiceImpl.java b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysUserServiceImpl.java new file mode 100644 index 000000000..0eb094008 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/service/impl/SysUserServiceImpl.java @@ -0,0 +1,483 @@ +package com.jsowell.system.service.impl; + +import com.jsowell.common.annotation.DataScope; +import com.jsowell.common.constant.UserConstants; +import com.jsowell.common.core.domain.entity.SysRole; +import com.jsowell.common.core.domain.entity.SysUser; +import com.jsowell.common.exception.ServiceException; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.bean.BeanValidators; +import com.jsowell.common.util.spring.SpringUtils; +import com.jsowell.system.domain.SysPost; +import com.jsowell.system.domain.SysUserPost; +import com.jsowell.system.domain.SysUserRole; +import com.jsowell.system.mapper.*; +import com.jsowell.system.service.SysConfigService; +import com.jsowell.system.service.SysUserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import javax.validation.Validator; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 鐢ㄦ埛 涓氬姟灞傚鐞 + * + * @author jsowell + */ +@Service +public class SysUserServiceImpl implements SysUserService { + private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); + + @Autowired + private SysUserMapper userMapper; + + @Autowired + private SysRoleMapper roleMapper; + + @Autowired + private SysPostMapper postMapper; + + @Autowired + private SysUserRoleMapper userRoleMapper; + + @Autowired + private SysUserPostMapper userPostMapper; + + @Autowired + private SysConfigService configService; + + @Autowired + protected Validator validator; + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鐢ㄦ埛鍒楄〃 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + @Override + @DataScope(deptAlias = "d", userAlias = "u") + public List selectUserList(SysUser user) { + return userMapper.selectUserList(user); + } + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + @Override + @DataScope(deptAlias = "d", userAlias = "u") + public List selectAllocatedList(SysUser user) { + return userMapper.selectAllocatedList(user); + } + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + @Override + @DataScope(deptAlias = "d", userAlias = "u") + public List selectUnallocatedList(SysUser user) { + return userMapper.selectUnallocatedList(user); + } + + /** + * 閫氳繃鐢ㄦ埛鍚嶆煡璇㈢敤鎴 + * + * @param userName 鐢ㄦ埛鍚 + * @return 鐢ㄦ埛瀵硅薄淇℃伅 + */ + @Override + public SysUser selectUserByUserName(String userName) { + return userMapper.selectUserByUserName(userName); + } + + /** + * 閫氳繃鐢ㄦ埛ID鏌ヨ鐢ㄦ埛 + * + * @param userId 鐢ㄦ埛ID + * @return 鐢ㄦ埛瀵硅薄淇℃伅 + */ + @Override + public SysUser selectUserById(Long userId) { + return userMapper.selectUserById(userId); + } + + /** + * 鏌ヨ鐢ㄦ埛鎵灞炶鑹茬粍 + * + * @param userName 鐢ㄦ埛鍚 + * @return 缁撴灉 + */ + @Override + public String selectUserRoleGroup(String userName) { + List list = roleMapper.selectRolesByUserName(userName); + if (CollectionUtils.isEmpty(list)) { + return StringUtils.EMPTY; + } + return list.stream().map(SysRole::getRoleName).collect(Collectors.joining(",")); + } + + /** + * 鏌ヨ鐢ㄦ埛鎵灞炲矖浣嶇粍 + * + * @param userName 鐢ㄦ埛鍚 + * @return 缁撴灉 + */ + @Override + public String selectUserPostGroup(String userName) { + List list = postMapper.selectPostsByUserName(userName); + if (CollectionUtils.isEmpty(list)) { + return StringUtils.EMPTY; + } + return list.stream().map(SysPost::getPostName).collect(Collectors.joining(",")); + } + + /** + * 鏍¢獙鐢ㄦ埛鍚嶇О鏄惁鍞竴 + * + * @param userName 鐢ㄦ埛鍚嶇О + * @return 缁撴灉 + */ + @Override + public String checkUserNameUnique(String userName) { + int count = userMapper.checkUserNameUnique(userName); + if (count > 0) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鏍¢獙鎵嬫満鍙风爜鏄惁鍞竴 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return + */ + @Override + public String checkPhoneUnique(SysUser user) { + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + SysUser info = userMapper.checkPhoneUnique(user.getPhone()); + if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鏍¢獙email鏄惁鍞竴 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return + */ + @Override + public String checkEmailUnique(SysUser user) { + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + SysUser info = userMapper.checkEmailUnique(user.getEmail()); + if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鏍¢獙鐢ㄦ埛鏄惁鍏佽鎿嶄綔 + * + * @param user 鐢ㄦ埛淇℃伅 + */ + @Override + public void checkUserAllowed(SysUser user) { + if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) { + // throw new ServiceException("涓嶅厑璁告搷浣滆秴绾х鐞嗗憳鐢ㄦ埛"); + } + } + + /** + * 鏍¢獙鐢ㄦ埛鏄惁鏈夋暟鎹潈闄 + * + * @param userId 鐢ㄦ埛id + */ + @Override + public void checkUserDataScope(Long userId) { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) { + SysUser user = new SysUser(); + user.setUserId(userId); + List users = SpringUtils.getAopProxy(this).selectUserList(user); + if (StringUtils.isEmpty(users)) { + throw new ServiceException("娌℃湁鏉冮檺璁块棶鐢ㄦ埛鏁版嵁锛"); + } + } + } + + /** + * 鏂板淇濆瓨鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public int insertUser(SysUser user) { + // 鏂板鐢ㄦ埛淇℃伅 + int rows = userMapper.insertUser(user); + // 鏂板鐢ㄦ埛宀椾綅鍏宠仈 + insertUserPost(user); + // 鏂板鐢ㄦ埛涓庤鑹茬鐞 + insertUserRole(user); + return rows; + } + + /** + * 娉ㄥ唽鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + @Override + public boolean registerUser(SysUser user) { + return userMapper.insertUser(user) > 0; + } + + /** + * 淇敼淇濆瓨鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public int updateUser(SysUser user) { + Long userId = user.getUserId(); + // 鍒犻櫎鐢ㄦ埛涓庤鑹插叧鑱 + userRoleMapper.deleteUserRoleByUserId(userId); + // 鏂板鐢ㄦ埛涓庤鑹茬鐞 + insertUserRole(user); + // 鍒犻櫎鐢ㄦ埛涓庡矖浣嶅叧鑱 + userPostMapper.deleteUserPostByUserId(userId); + // 鏂板鐢ㄦ埛涓庡矖浣嶇鐞 + insertUserPost(user); + return userMapper.updateUser(user); + } + + /** + * 鐢ㄦ埛鎺堟潈瑙掕壊 + * + * @param userId 鐢ㄦ埛ID + * @param roleIds 瑙掕壊缁 + */ + @Override + @Transactional + public void insertUserAuth(Long userId, Long[] roleIds) { + userRoleMapper.deleteUserRoleByUserId(userId); + insertUserRole(userId, roleIds); + } + + /** + * 淇敼鐢ㄦ埛鐘舵 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateUserStatus(SysUser user) { + return userMapper.updateUser(user); + } + + /** + * 淇敼鐢ㄦ埛鍩烘湰淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateUserProfile(SysUser user) { + return userMapper.updateUser(user); + } + + /** + * 淇敼鐢ㄦ埛澶村儚 + * + * @param userName 鐢ㄦ埛鍚 + * @param avatar 澶村儚鍦板潃 + * @return 缁撴灉 + */ + @Override + public boolean updateUserAvatar(String userName, String avatar) { + return userMapper.updateUserAvatar(userName, avatar) > 0; + } + + /** + * 閲嶇疆鐢ㄦ埛瀵嗙爜 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + @Override + public int resetPwd(SysUser user) { + return userMapper.updateUser(user); + } + + /** + * 閲嶇疆鐢ㄦ埛瀵嗙爜 + * + * @param userName 鐢ㄦ埛鍚 + * @param password 瀵嗙爜 + * @return 缁撴灉 + */ + @Override + public int resetUserPwd(String userName, String password) { + return userMapper.resetUserPwd(userName, password); + } + + /** + * 鏂板鐢ㄦ埛瑙掕壊淇℃伅 + * + * @param user 鐢ㄦ埛瀵硅薄 + */ + public void insertUserRole(SysUser user) { + this.insertUserRole(user.getUserId(), user.getRoleIds()); + } + + /** + * 鏂板鐢ㄦ埛宀椾綅淇℃伅 + * + * @param user 鐢ㄦ埛瀵硅薄 + */ + public void insertUserPost(SysUser user) { + Long[] posts = user.getPostIds(); + if (StringUtils.isNotEmpty(posts)) { + // 鏂板鐢ㄦ埛涓庡矖浣嶇鐞 + List list = new ArrayList(posts.length); + for (Long postId : posts) { + SysUserPost up = new SysUserPost(); + up.setUserId(user.getUserId()); + up.setPostId(postId); + list.add(up); + } + userPostMapper.batchUserPost(list); + } + } + + /** + * 鏂板鐢ㄦ埛瑙掕壊淇℃伅 + * + * @param userId 鐢ㄦ埛ID + * @param roleIds 瑙掕壊缁 + */ + public void insertUserRole(Long userId, Long[] roleIds) { + if (StringUtils.isNotEmpty(roleIds)) { + // 鏂板鐢ㄦ埛涓庤鑹茬鐞 + List list = new ArrayList(roleIds.length); + for (Long roleId : roleIds) { + SysUserRole ur = new SysUserRole(); + ur.setUserId(userId); + ur.setRoleId(roleId); + list.add(ur); + } + userRoleMapper.batchUserRole(list); + } + } + + /** + * 閫氳繃鐢ㄦ埛ID鍒犻櫎鐢ㄦ埛 + * + * @param userId 鐢ㄦ埛ID + * @return 缁撴灉 + */ + @Override + @Transactional + public int deleteUserById(Long userId) { + // 鍒犻櫎鐢ㄦ埛涓庤鑹插叧鑱 + userRoleMapper.deleteUserRoleByUserId(userId); + // 鍒犻櫎鐢ㄦ埛涓庡矖浣嶈〃 + userPostMapper.deleteUserPostByUserId(userId); + return userMapper.deleteUserById(userId); + } + + /** + * 鎵归噺鍒犻櫎鐢ㄦ埛淇℃伅 + * + * @param userIds 闇瑕佸垹闄ょ殑鐢ㄦ埛ID + * @return 缁撴灉 + */ + @Override + @Transactional + public int deleteUserByIds(Long[] userIds) { + for (Long userId : userIds) { + checkUserAllowed(new SysUser(userId)); + checkUserDataScope(userId); + } + // 鍒犻櫎鐢ㄦ埛涓庤鑹插叧鑱 + userRoleMapper.deleteUserRole(userIds); + // 鍒犻櫎鐢ㄦ埛涓庡矖浣嶅叧鑱 + userPostMapper.deleteUserPost(userIds); + return userMapper.deleteUserByIds(userIds); + } + + /** + * 瀵煎叆鐢ㄦ埛鏁版嵁 + * + * @param userList 鐢ㄦ埛鏁版嵁鍒楄〃 + * @param isUpdateSupport 鏄惁鏇存柊鏀寔锛屽鏋滃凡瀛樺湪锛屽垯杩涜鏇存柊鏁版嵁 + * @param operName 鎿嶄綔鐢ㄦ埛 + * @return 缁撴灉 + */ + @Override + public String importUser(List userList, Boolean isUpdateSupport, String operName) { + if (StringUtils.isNull(userList) || userList.size() == 0) { + throw new ServiceException("瀵煎叆鐢ㄦ埛鏁版嵁涓嶈兘涓虹┖锛"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + String password = configService.selectConfigByKey("sys.user.initPassword"); + for (SysUser user : userList) { + try { + // 楠岃瘉鏄惁瀛樺湪杩欎釜鐢ㄦ埛 + SysUser u = userMapper.selectUserByUserName(user.getUserName()); + if (StringUtils.isNull(u)) { + BeanValidators.validateWithException(validator, user); + user.setPassword(SecurityUtils.encryptPassword(password)); + user.setCreateBy(operName); + this.insertUser(user); + successNum++; + successMsg.append("
" + successNum + "銆佽处鍙 " + user.getUserName() + " 瀵煎叆鎴愬姛"); + } else if (isUpdateSupport) { + BeanValidators.validateWithException(validator, user); + user.setUpdateBy(operName); + this.updateUser(user); + successNum++; + successMsg.append("
" + successNum + "銆佽处鍙 " + user.getUserName() + " 鏇存柊鎴愬姛"); + } else { + failureNum++; + failureMsg.append("
" + failureNum + "銆佽处鍙 " + user.getUserName() + " 宸插瓨鍦"); + } + } catch (Exception e) { + failureNum++; + String msg = "
" + failureNum + "銆佽处鍙 " + user.getUserName() + " 瀵煎叆澶辫触锛"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) { + failureMsg.insert(0, "寰堟姳姝夛紝瀵煎叆澶辫触锛佸叡 " + failureNum + " 鏉℃暟鎹牸寮忎笉姝g‘锛岄敊璇涓嬶細"); + throw new ServiceException(failureMsg.toString()); + } else { + successMsg.insert(0, "鎭枩鎮紝鏁版嵁宸插叏閮ㄥ鍏ユ垚鍔燂紒鍏 " + successNum + " 鏉★紝鏁版嵁濡備笅锛"); + } + return successMsg.toString(); + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/vo/MetaVO.java b/jsowell-system/src/main/java/com/jsowell/system/vo/MetaVO.java new file mode 100644 index 000000000..6e0b6f9d4 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/vo/MetaVO.java @@ -0,0 +1,91 @@ +package com.jsowell.system.vo; + +import com.jsowell.common.util.StringUtils; + +/** + * 璺敱鏄剧ず淇℃伅 + * + * @author jsowell + */ +public class MetaVO { + /** + * 璁剧疆璇ヨ矾鐢卞湪渚ц竟鏍忓拰闈㈠寘灞戜腑灞曠ず鐨勫悕瀛 + */ + private String title; + + /** + * 璁剧疆璇ヨ矾鐢辩殑鍥炬爣锛屽搴旇矾寰剆rc/assets/icons/svg + */ + private String icon; + + /** + * 璁剧疆涓簍rue锛屽垯涓嶄細琚 缂撳瓨 + */ + private boolean noCache; + + /** + * 鍐呴摼鍦板潃锛坔ttp(s)://寮澶达級 + */ + private String link; + + public MetaVO() { + } + + public MetaVO(String title, String icon) { + this.title = title; + this.icon = icon; + } + + public MetaVO(String title, String icon, boolean noCache) { + this.title = title; + this.icon = icon; + this.noCache = noCache; + } + + public MetaVO(String title, String icon, String link) { + this.title = title; + this.icon = icon; + this.link = link; + } + + public MetaVO(String title, String icon, boolean noCache, String link) { + this.title = title; + this.icon = icon; + this.noCache = noCache; + if (StringUtils.isHttp(link)) { + this.link = link; + } + } + + public boolean isNoCache() { + return noCache; + } + + public void setNoCache(boolean noCache) { + this.noCache = noCache; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getLink() { + return link; + } + + public void setLink(String link) { + this.link = link; + } +} diff --git a/jsowell-system/src/main/java/com/jsowell/system/vo/RouterVO.java b/jsowell-system/src/main/java/com/jsowell/system/vo/RouterVO.java new file mode 100644 index 000000000..998310bf9 --- /dev/null +++ b/jsowell-system/src/main/java/com/jsowell/system/vo/RouterVO.java @@ -0,0 +1,130 @@ +package com.jsowell.system.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.List; + +/** + * 璺敱閰嶇疆淇℃伅 + * + * @author jsowell + */ +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class RouterVO { + /** + * 璺敱鍚嶅瓧 + */ + private String name; + + /** + * 璺敱鍦板潃 + */ + private String path; + + /** + * 鏄惁闅愯棌璺敱锛屽綋璁剧疆 true 鐨勬椂鍊欒璺敱涓嶄細鍐嶄晶杈规爮鍑虹幇 + */ + private boolean hidden; + + /** + * 閲嶅畾鍚戝湴鍧锛屽綋璁剧疆 noRedirect 鐨勬椂鍊欒璺敱鍦ㄩ潰鍖呭睉瀵艰埅涓笉鍙鐐瑰嚮 + */ + private String redirect; + + /** + * 缁勪欢鍦板潃 + */ + private String component; + + /** + * 璺敱鍙傛暟锛氬 {"id": 1, "name": "ry"} + */ + private String query; + + /** + * 褰撲綘涓涓矾鐢变笅闈㈢殑 children 澹版槑鐨勮矾鐢卞ぇ浜1涓椂锛岃嚜鍔ㄤ細鍙樻垚宓屽鐨勬ā寮--濡傜粍浠堕〉闈 + */ + private Boolean alwaysShow; + + /** + * 鍏朵粬鍏冪礌 + */ + private MetaVO meta; + + /** + * 瀛愯矾鐢 + */ + private List children; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public boolean getHidden() { + return hidden; + } + + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + public String getRedirect() { + return redirect; + } + + public void setRedirect(String redirect) { + this.redirect = redirect; + } + + public String getComponent() { + return component; + } + + public void setComponent(String component) { + this.component = component; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public Boolean getAlwaysShow() { + return alwaysShow; + } + + public void setAlwaysShow(Boolean alwaysShow) { + this.alwaysShow = alwaysShow; + } + + public MetaVO getMeta() { + return meta; + } + + public void setMeta(MetaVO meta) { + this.meta = meta; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/jsowell-system/src/main/resources/mapper/system/SysConfigMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysConfigMapper.xml new file mode 100644 index 000000000..b8497000c --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysConfigMapper.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark + from sys_config + + + + + + + and config_id = #{configId} + + + and config_key = #{configKey} + + + + + + + + + + + + insert into sys_config ( + config_name, + config_key, + config_value, + config_type, + create_by, + remark, + create_time + )values( + #{configName}, + #{configKey}, + #{configValue}, + #{configType}, + #{createBy}, + #{remark}, + sysdate() + ) + + + + update sys_config + + config_name = #{configName}, + config_key = #{configKey}, + config_value = #{configValue}, + config_type = #{configType}, + update_by = #{updateBy}, + remark = #{remark}, + update_time = sysdate() + + where config_id = #{configId} + + + + delete from sys_config where config_id = #{configId} + + + + delete from sys_config where config_id in + + #{configId} + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysDeptMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysDeptMapper.xml new file mode 100644 index 000000000..34cf61028 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time + from sys_dept d + + + + + + + + + + + + + + + + + + + + insert into sys_dept( + + dept_id, + parent_id, + dept_name, + ancestors, + order_num, + leader, + phone, + email, + status, + create_by, + + )values( + + #{deptId}, + #{parentId}, + #{deptName}, + #{ancestors}, + #{orderNum}, + #{leader}, + #{phone}, + #{email}, + #{status}, + #{createBy}, + + ) + + + + update sys_dept + + parent_id = #{parentId}, + dept_name = #{deptName}, + ancestors = #{ancestors}, + order_num = #{orderNum}, + leader = #{leader}, + phone = #{phone}, + email = #{email}, + status = #{status}, + update_by = #{updateBy}, + + where dept_id = #{deptId} + + + + update sys_dept set ancestors = + + when #{item.deptId} then #{item.ancestors} + + where dept_id in + + #{item.deptId} + + + + + update sys_dept set status = '0' where dept_id in + + #{deptId} + + + + + update sys_dept set del_flag = '2' where dept_id = #{deptId} + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysDictDataMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysDictDataMapper.xml new file mode 100644 index 000000000..b96ca9f24 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysDictDataMapper.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark + from sys_dict_data + + + + + + + + + + + + + + delete from sys_dict_data where dict_code = #{dictCode} + + + + delete from sys_dict_data where dict_code in + + #{dictCode} + + + + + update sys_dict_data + + dict_sort = #{dictSort}, + dict_label = #{dictLabel}, + dict_value = #{dictValue}, + dict_type = #{dictType}, + css_class = #{cssClass}, + list_class = #{listClass}, + is_default = #{isDefault}, + status = #{status}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where dict_code = #{dictCode} + + + + update sys_dict_data set dict_type = #{newDictType} where dict_type = #{oldDictType} + + + + insert into sys_dict_data( + dict_sort, + dict_label, + dict_value, + dict_type, + css_class, + list_class, + is_default, + status, + remark, + create_by, + create_time + )values( + #{dictSort}, + #{dictLabel}, + #{dictValue}, + #{dictType}, + #{cssClass}, + #{listClass}, + #{isDefault}, + #{status}, + #{remark}, + #{createBy}, + sysdate() + ) + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysDictTypeMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysDictTypeMapper.xml new file mode 100644 index 000000000..4992a4d0d --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysDictTypeMapper.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + select dict_id, dict_name, dict_type, status, create_by, create_time, remark + from sys_dict_type + + + + + + + + + + + + + + delete from sys_dict_type where dict_id = #{dictId} + + + + delete from sys_dict_type where dict_id in + + #{dictId} + + + + + update sys_dict_type + + dict_name = #{dictName}, + dict_type = #{dictType}, + status = #{status}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where dict_id = #{dictId} + + + + insert into sys_dict_type( + dict_name, + dict_type, + status, + remark, + create_by, + create_time + )values( + #{dictName}, + #{dictType}, + #{status}, + #{remark}, + #{createBy}, + sysdate() + ) + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysLogininforMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysLogininforMapper.xml new file mode 100644 index 000000000..26014b6c0 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysLogininforMapper.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + insert into sys_logininfor (user_name, status, ipaddr, login_location, browser, os, msg, login_time) + values (#{userName}, #{status}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, #{msg}, sysdate()) + + + + + + delete from sys_logininfor where info_id in + + #{infoId} + + + + + truncate table sys_logininfor + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysMenuMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysMenuMapper.xml new file mode 100644 index 000000000..5f349b452 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select menu_id, menu_name, parent_id, order_num, path, component, `query`, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time + from sys_menu + + + + + + + + + + + + + + + + + + + + + + + + update sys_menu + + menu_name = #{menuName}, + parent_id = #{parentId}, + order_num = #{orderNum}, + path = #{path}, + component = #{component}, + `query` = #{query}, + is_frame = #{isFrame}, + is_cache = #{isCache}, + menu_type = #{menuType}, + visible = #{visible}, + status = #{status}, + perms = #{perms}, + icon = #{icon}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where menu_id = #{menuId} + + + + insert into sys_menu( + menu_id, + parent_id, + menu_name, + order_num, + path, + component, + `query`, + is_frame, + is_cache, + menu_type, + visible, + status, + perms, + icon, + remark, + create_by, + create_time + )values( + #{menuId}, + #{parentId}, + #{menuName}, + #{orderNum}, + #{path}, + #{component}, + #{query}, + #{isFrame}, + #{isCache}, + #{menuType}, + #{visible}, + #{status}, + #{perms}, + #{icon}, + #{remark}, + #{createBy}, + sysdate() + ) + + + + delete from sys_menu where menu_id = #{menuId} + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysNoticeMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysNoticeMapper.xml new file mode 100644 index 000000000..ee1d2251b --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysNoticeMapper.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + select notice_id, notice_title, notice_type, cast(notice_content as char) as notice_content, status, create_by, create_time, update_by, update_time, remark + from sys_notice + + + + + + + + insert into sys_notice ( + notice_title, + notice_type, + notice_content, + status, + remark, + create_by, + create_time + )values( + #{noticeTitle}, + #{noticeType}, + #{noticeContent}, + #{status}, + #{remark}, + #{createBy}, + sysdate() + ) + + + + update sys_notice + + notice_title = #{noticeTitle}, + notice_type = #{noticeType}, + notice_content = #{noticeContent}, + status = #{status}, + update_by = #{updateBy}, + update_time = sysdate() + + where notice_id = #{noticeId} + + + + delete from sys_notice where notice_id = #{noticeId} + + + + delete from sys_notice where notice_id in + + #{noticeId} + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysOperLogMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysOperLogMapper.xml new file mode 100644 index 000000000..e2b4c6635 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysOperLogMapper.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time + from sys_oper_log + + + + insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time) + values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, sysdate()) + + + + + + delete from sys_oper_log where oper_id in + + #{operId} + + + + + + + truncate table sys_oper_log + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysPostMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysPostMapper.xml new file mode 100644 index 000000000..c847fb9e8 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysPostMapper.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + select post_id, post_code, post_name, post_sort, status, create_by, create_time, remark + from sys_post + + + + + + + + + + + + + + + + + + update sys_post + + post_code = #{postCode}, + post_name = #{postName}, + post_sort = #{postSort}, + status = #{status}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where post_id = #{postId} + + + + insert into sys_post( + post_id, + post_code, + post_name, + post_sort, + status, + remark, + create_by, + create_time + )values( + #{postId}, + #{postCode}, + #{postName}, + #{postSort}, + #{status}, + #{remark}, + #{createBy}, + sysdate() + ) + + + + delete from sys_post where post_id = #{postId} + + + + delete from sys_post where post_id in + + #{postId} + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml new file mode 100644 index 000000000..9a1baa729 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + delete from sys_role_dept where role_id=#{roleId} + + + + + + delete from sys_role_dept where role_id in + + #{roleId} + + + + + insert into sys_role_dept(role_id, dept_id) values + + (#{item.roleId},#{item.deptId}) + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysRoleMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysRoleMapper.xml new file mode 100644 index 000000000..ffeec6825 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly, + r.status, r.del_flag, r.create_time, r.remark + from sys_role r + left join sys_user_role ur on ur.role_id = r.role_id + left join sys_user u on u.user_id = ur.user_id + left join sys_dept d on u.dept_id = d.dept_id + + + + + + + + + + + + + + + + + + + + insert into sys_role( + role_id, + role_name, + role_key, + role_sort, + data_scope, + menu_check_strictly, + dept_check_strictly, + status, + remark, + create_by, + create_time + )values( + #{roleId}, + #{roleName}, + #{roleKey}, + #{roleSort}, + #{dataScope}, + #{menuCheckStrictly}, + #{deptCheckStrictly}, + #{status}, + #{remark}, + #{createBy}, + sysdate() + ) + + + + update sys_role + + role_name = #{roleName}, + role_key = #{roleKey}, + role_sort = #{roleSort}, + data_scope = #{dataScope}, + menu_check_strictly = #{menuCheckStrictly}, + dept_check_strictly = #{deptCheckStrictly}, + status = #{status}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where role_id = #{roleId} + + + + update sys_role set del_flag = '2' where role_id = #{roleId} + + + + update sys_role set del_flag = '2' where role_id in + + #{roleId} + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml new file mode 100644 index 000000000..e6edab66f --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + delete from sys_role_menu where role_id=#{roleId} + + + + delete from sys_role_menu where role_id in + + #{roleId} + + + + + insert into sys_role_menu(role_id, menu_id) values + + (#{item.roleId},#{item.menuId}) + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysUserMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysUserMapper.xml new file mode 100644 index 000000000..c0d443f41 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select + u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phone, u.password, u.sex, u.status, + u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, + d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status, + r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status + from sys_user u + left join sys_dept d on u.dept_id = d.dept_id + left join sys_user_role ur on u.user_id = ur.user_id + left join sys_role r on r.role_id = ur.role_id + + + + + + + + + + + + + + + + + + + + insert into sys_user( + user_id, + dept_id, + user_name, + nick_name, + email, + avatar, + phone, + sex, + password, + status, + create_by, + remark, + create_time + )values( + #{userId}, + #{deptId}, + #{userName}, + #{nickName}, + #{email}, + #{avatar}, + #{phone}, + #{sex}, + #{password}, + #{status}, + #{createBy}, + #{remark}, + sysdate() + ) + + + + update sys_user + + dept_id = #{deptId}, + user_name = #{userName}, + nick_name = #{nickName}, + email = #{email}, + phone = #{phone}, + sex = #{sex}, + avatar = #{avatar}, + password = #{password}, + status = #{status}, + login_ip = #{loginIp}, + login_date = #{loginDate}, + update_by = #{updateBy}, + remark = #{remark}, + update_time = sysdate() + + where user_id = #{userId} + + + + update sys_user set status = #{status} where user_id = #{userId} + + + + update sys_user set avatar = #{avatar} where user_name = #{userName} + + + + update sys_user set password = #{password} where user_name = #{userName} + + + + update sys_user set del_flag = '2' where user_id = #{userId} + + + + update sys_user set del_flag = '2' where user_id in + + #{userId} + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysUserPostMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysUserPostMapper.xml new file mode 100644 index 000000000..957980e51 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysUserPostMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + delete from sys_user_post where user_id=#{userId} + + + + + + delete from sys_user_post where user_id in + + #{userId} + + + + + insert into sys_user_post(user_id, post_id) values + + (#{item.userId},#{item.postId}) + + + + \ No newline at end of file diff --git a/jsowell-system/src/main/resources/mapper/system/SysUserRoleMapper.xml b/jsowell-system/src/main/resources/mapper/system/SysUserRoleMapper.xml new file mode 100644 index 000000000..b82560873 --- /dev/null +++ b/jsowell-system/src/main/resources/mapper/system/SysUserRoleMapper.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + delete from sys_user_role where user_id=#{userId} + + + + + + delete from sys_user_role where user_id in + + #{userId} + + + + + insert into sys_user_role(user_id, role_id) values + + (#{item.userId},#{item.roleId}) + + + + + delete from sys_user_role where user_id=#{userId} and role_id=#{roleId} + + + + delete from sys_user_role where role_id=#{roleId} and user_id in + + #{userId} + + + \ No newline at end of file diff --git a/jsowell-thirdparty/pom.xml b/jsowell-thirdparty/pom.xml new file mode 100644 index 000000000..ff891a05d --- /dev/null +++ b/jsowell-thirdparty/pom.xml @@ -0,0 +1,51 @@ + + + + jsowell-charger-web + com.jsowell + 1.0.0 + + 4.0.0 + + jsowell-thirdparty + + + + com.jsowell + jsowell-pile + 1.0.0 + + + + org.projectlombok + lombok + + + + + + 8 + 8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + /src/test/** + + utf-8 + + + + + + \ No newline at end of file diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/LianLianService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/LianLianService.java new file mode 100644 index 000000000..c297691f7 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/LianLianService.java @@ -0,0 +1,10 @@ +package com.jsowell.thirdparty.service; + +public interface LianLianService { + + /** + * 鏍规嵁杩愯惀鍟唅d锛屾帹閫佽繍钀ュ晢淇℃伅 + * @param merchantId + */ + void pushMerchantInfo(Long merchantId); +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/impl/LianLianServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/impl/LianLianServiceImpl.java new file mode 100644 index 000000000..464f8f7f7 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/impl/LianLianServiceImpl.java @@ -0,0 +1,25 @@ +package com.jsowell.thirdparty.service.impl; + +import com.jsowell.pile.service.IPileMerchantInfoService; +import com.jsowell.thirdparty.service.LianLianService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class LianLianServiceImpl implements LianLianService { + + @Autowired + private IPileMerchantInfoService pileMerchantInfoService; + + + @Override + public void pushMerchantInfo(Long merchantId) { + // 閫氳繃id鏌ヨ杩愯惀鍟嗕俊鎭 + + // 缁勮鑱旇仈骞冲彴鎵闇瑕佺殑鏁版嵁鏍煎紡 + + // 璋冪敤鑱旇仈骞冲彴鎺ュ彛 + + + } +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ChargeDetail.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ChargeDetail.java new file mode 100644 index 000000000..5a799d8fc --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ChargeDetail.java @@ -0,0 +1,54 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 鍏呯數鏄庣粏淇℃伅浣 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class ChargeDetail { + /** + * 寮濮嬫椂闂 Y + * 鏍煎紡鈥測yyy-MM-dd HH:mm:ss鈥 + */ + private String DetailStartTime; + + /** + * 缁撴潫鏃堕棿 Y + * 鏍煎紡鈥測yyy-MM-dd HH:mm:ss鈥 + */ + private String DetailEndTime; + + /** + * 鏃舵鐢典环(灏忔暟鐐瑰悗4浣) Y + */ + private BigDecimal ElecPrice; + + /** + * 鏃舵鏈嶅姟璐逛环鏍(灏忔暟鐐瑰悗4浣) Y + */ + private BigDecimal SevicePrice; + + /** + * 鏃舵鍏呯數閲(鍗曚綅锛氬害锛屽皬鏁扮偣鍚2浣) Y + */ + private BigDecimal DetailPower; + + /** + * 鏃舵鐢佃垂(灏忔暟鐐瑰悗2浣) Y + */ + private BigDecimal DetailElecMoney; + + /** + * 鏃舵鏈嶅姟璐(灏忔暟鐐瑰悗2浣) Y + */ + private BigDecimal DetailSeviceMoney; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorChargeStatusInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorChargeStatusInfo.java new file mode 100644 index 000000000..a55c509ba --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorChargeStatusInfo.java @@ -0,0 +1,122 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 鍏呯數璁惧鎺ュ彛鍏呯數涓姸鎬佷俊鎭 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class ConnectorChargeStatusInfo { + /** + * 鍏呯數璁㈠崟鍙 Y + * 瀵规帴骞冲彴绯荤粺璁㈠崟缂栧彿 + */ + private String StartChargeSeq; + + /** + * 鍏呯數璁惧鎺ュ彛缂栫爜 Y + * 骞冲彴涓嬪敮涓鏋彛鍙 + */ + private String ConnectorID; + + /** + * 鍏呯數璁惧鎺ュ彛鐘舵 Y + * 1锛氱┖闂 + * 2锛氬崰鐢紙鏈厖鐢碉級 + * 3锛氬崰鐢紙鍏呯數涓級 + * 4锛氬崰鐢紙棰勭害閿佸畾锛 + * 255锛氭晠闅 + */ + private Integer ConnectorStatus; + + /** + * 杞﹁締璇嗗埆鐮 N + * 杞﹁締璇嗗埆鍙风爜鎴栬溅鏋跺彿鐮侊紝鐢17浣嶈嫳鏁扮粍鎴 + */ + private String Vin; + + /** + * A鐩哥數娴 Y + * 鍗曚綅锛欰锛岄粯璁わ細0 鍚洿娴(杈撳嚭) + */ + private BigDecimal CurrentA; + + /** + * B鐩哥數娴 N + * 鍗曚綅锛欰锛岄粯璁わ細0 + */ + private BigDecimal CurrentB; + + /** + * C鐩哥數娴 N + * 鍗曚綅锛欰锛岄粯璁わ細0 + */ + private BigDecimal CurrentC; + + /** + * A鐩哥數鍘 Y + * 鍗曚綅锛歏锛岄粯璁わ細0鍚洿娴(杈撳嚭) + */ + private BigDecimal VoltageA; + + /** + * B鐩哥數鍘 N + * 鍗曚綅锛歏锛岄粯璁わ細0 + */ + private BigDecimal VoltageB; + + /** + * C鐩哥數鍘 N + * 鍗曚綅锛歏锛岄粯璁わ細0 + */ + private BigDecimal VoltageC; + + /** + * 鐢垫睜鍓╀綑鐢甸噺(榛樿锛0) Y + */ + private BigDecimal Soc; + + /** + * 寮濮嬪厖鐢垫椂闂 Y + * 鏍煎紡鈥測yyy-MM-dd HH:mm:ss鈥 + */ + private String StartTime; + + /** + * 鏈閲囨牱鏃堕棿 Y + * 鏍煎紡鈥測yyy-MM-dd HH:mm:ss鈥 + */ + private String EndTime; + + /** + * 绱鍏呯數閲 Y + * 鍗曚綅锛氬害锛屽皬鏁扮偣鍚2浣 + */ + private BigDecimal TotalPower; + + /** + * 绱鐢佃垂 Y + * 鍗曚綅锛氬厓锛屽皬鏁扮偣鍚2浣 + */ + private BigDecimal ElecMoney; + + /** + * 绱鏈嶅姟璐 Y + * 鍗曚綅锛氬厓锛屽皬鏁扮偣鍚2浣 + */ + private BigDecimal SeviceMoney; + + /** + * 绱鎬婚噾棰 Y + * 鍗曚綅锛氬厓锛屽皬鏁扮偣鍚2浣 + */ + private BigDecimal TotalMoney; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorInfo.java new file mode 100644 index 000000000..8a468b627 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorInfo.java @@ -0,0 +1,64 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 鍏呯數璁惧鎺ュ彛淇℃伅 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class ConnectorInfo { + /** + * 鍏呯數璁惧鎺ュ彛缂栫爜 Y + * 鍏呯數璁惧鎺ュ彛缂栫爜锛屽悓涓瀵规帴骞冲彴鍐呭敮涓 + */ + private String ConnectorID; + + /** + * 鍏呯數璁惧鎺ュ彛鍚嶇О N + */ + private String ConnectorName; + + /** + * 鍏呯數璁惧鎺ュ彛绫诲瀷 Y + * 1锛氬鐢ㄦ彃搴э紙妯″紡2锛 + * 2锛氫氦娴佹帴鍙f彃搴э紙妯″紡3锛岃繛鎺ユ柟寮廈 锛 + * 3锛氫氦娴佹帴鍙f彃澶达紙甯︽灙绾匡紝妯″紡3锛岃繛鎺ユ柟寮廋锛 + * 4锛氱洿娴佹帴鍙f灙澶达紙甯︽灙绾匡紝妯″紡4锛 + */ + private Integer ConnectorType; + + /** + * 棰濆畾鐢靛帇涓婇檺(鍗曚綅锛歏) Y + */ + private Integer VoltageUpperLimits; + + /** + * 棰濆畾鐢靛帇涓嬮檺(鍗曚綅锛歏) Y + */ + private Integer VoltageLowerLimits; + + /** + * 棰濆畾鐢垫祦(鍗曚綅锛欰) Y + */ + private Integer Current; + + /** + * 棰濆畾鍔熺巼(鍗曚綅锛歬W) Y + */ + private BigDecimal Power; + + /** + * 杞︿綅鍙 N + * 鍋滆溅鍦鸿溅浣嶇紪鍙 + */ + private String ParkNo; + +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorStatsInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorStatsInfo.java new file mode 100644 index 000000000..e2a6efb60 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorStatsInfo.java @@ -0,0 +1,29 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * 鍏呯數璁惧鎺ュ彛缁熻淇℃伅 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class ConnectorStatsInfo { + /** + * 鍏呯數璁惧鎺ュ彛缂栫爜 Y + * 鍏呯數璁惧鎺ュ彛缂栫爜锛屽悓涓瀵规帴骞冲彴鍐呭敮涓 + */ + private String ConnectorID; + + /** + * 鍏呯數璁惧鎺ュ彛绱鐢甸噺 + * 绱鐢甸噺锛屽崟浣峩Wh锛岀簿搴0.1 + */ + private BigDecimal ConnectorElectricity; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorStatusInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorStatusInfo.java new file mode 100644 index 000000000..88aae08c2 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/ConnectorStatusInfo.java @@ -0,0 +1,42 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 鍏呯數璁惧鎺ュ彛鐘舵佷俊鎭 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class ConnectorStatusInfo { + /** + * 鍏呯數璁惧鎺ュ彛缂栫爜 Y + * 鍏呯數璁惧鎺ュ彛缂栫爜锛屽悓涓瀵规帴骞冲彴鍐呭敮涓 + */ + private String ConnectorID; + + /** + * 鍏呯數璁惧鎺ュ彛鐘舵 Y + * 0锛氱缃 + * 1锛氱┖闂 + * 2锛氬崰鐢紙鏈厖鐢碉級 + * 3锛氬崰鐢紙鍏呯數涓級 + * 4锛氬崰鐢紙棰勭害閿佸畾锛 + * 255锛氭晠闅 + */ + private String Status; + + /** + * 杞︿綅鐘舵(0-鏈煡锛10-绌洪棽锛50-鍗犵敤) N + */ + private String ParkStatus; + + /** + * 鍦伴攣鐘舵(0-鏈煡锛10-宸茶В閿侊紱50-鍗犵敤) N + */ + private String LockStatus; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/EquipmentInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/EquipmentInfo.java new file mode 100644 index 000000000..e4f7becf7 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/EquipmentInfo.java @@ -0,0 +1,102 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 鍏呯數璁惧淇℃伅 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class EquipmentInfo { + /** + * 璁惧缂栫爜 Y + * 璁惧鍞竴缂栫爜锛屽鍚屼竴瀵规帴骞冲彴锛屼繚璇佸敮涓 + */ + private String EquipmentID; + + /** + * 璁惧鐢熶骇鍟嗙粍缁囨満鏋勪唬鐮 Y + */ + private String ManufacturerID; + + /** + * 璁惧鍨嬪彿 N + * 鐢辫澶囩敓鍘傚晢瀹氫箟鐨勮澶囧瀷鍙 + */ + private String EquipmentModel; + + /** + * 璁惧鍚嶇О N + */ + private String EquipmentName; + + /** + * 璁惧鐢熶骇鏃ユ湡 N + * YYYY-MM-DD + */ + private String ProductionDate; + + /** + * 寤鸿鏃堕棿 Y + * YYYY-MM-DD + */ + private String ConstructionTime; + + /** + * 璁惧绫诲瀷(1-鐩存祦璁惧锛2-浜ゆ祦璁惧锛3-浜ょ洿娴佷竴浣撹澶) Y + */ + private Integer EquipmentType; + + /** + * 璁惧鐘舵 Y + * 0锛氭湭鐭 + * 1锛氬缓璁句腑 + * 5锛氬叧闂笅绾 + * 6锛氱淮鎶や腑 + * 50锛氭甯镐娇鐢 + */ + private Integer EquipmentStatus; + + /** + * 棰濆畾鍔熺巼(鍗曚綅锛歬W) Y + */ + private BigDecimal EquipmentPower; + + /** + * 鏂板浗鏍(0-鍚︼紱1-鏄) Y + * 鏄惁鏂板浗鏍 + */ + private Integer NewNationalStandard; + + /** + * 鍏呯數璁惧鎺ュ彛鍒楄〃 Y + * 璇ュ厖鐢佃澶囨墍鏈夌殑鍏呯數璁惧鎺ュ彛鐨勪俊鎭璞¢泦鍚 + */ + private List ConnectorInfos; + + /** + * 鍏呯數璁惧缁忓害 N + * GCJ-02鍧愭爣绯 + */ + private BigDecimal EquipmentLng; + + /** + * 鍏呯數璁惧绾害 N + * GCJ-02鍧愭爣绯 + */ + private BigDecimal EquipmentLat; + + /** + * 鏄惁鏀寔VIN鐮佽瘑鍒(0-鍚︼紱1-鏄) Y + */ + private Integer VinFlag; + +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/EquipmentStatsInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/EquipmentStatsInfo.java new file mode 100644 index 000000000..5a225e844 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/EquipmentStatsInfo.java @@ -0,0 +1,36 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 鍏呯數璁惧缁熻淇℃伅 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class EquipmentStatsInfo { + /** + * 璁惧缂栫爜 Y + * 璁惧鍞竴缂栫爜锛屽鍚屼竴瀵规帴骞冲彴锛屼繚璇佸敮涓 + */ + private String EquipmentID; + + /** + * 鍏呯數璁惧绱鐢甸噺 Y + * 绱鐢甸噺锛屽崟浣峩Wh锛岀簿搴0.1 + */ + private BigDecimal EquipmentElectricity; + + /** + * 鍏呯數璁惧鎺ュ彛缁熻淇℃伅鍒楄〃 Y + * 鍏呰澶囩殑鎵鏈夊厖鐢佃澶囨帴鍙g粺璁″璞¢泦鍚 + */ + private List ConnectorStatsInfos; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/OperatorInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/OperatorInfo.java new file mode 100644 index 000000000..d3239f693 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/OperatorInfo.java @@ -0,0 +1,45 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 鍏呯數瀵规帴骞冲彴淇℃伅 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class OperatorInfo { + /** + * 瀵规帴骞冲彴ID锛堢粍缁囨満鏋勪唬鐮侊級 Y + */ + private String OperatorID; + + /** + * 瀵规帴骞冲彴鍚嶇О锛堟満鏋勫叏绉帮級 Y + */ + private String OperatorName; + + /** + * 瀵规帴骞冲彴鐢佃瘽锛堝鎺ュ钩鍙板鏈嶇數璇1锛 Y + */ + private String OperatorTel1; + + /** + * 瀵规帴骞冲彴鐢佃瘽2锛堝鎺ュ钩鍙板鏈嶇數璇2 锛 N + */ + private String OperatorTel2; + + /** + * 瀵规帴骞冲彴娉ㄥ唽鍦板潃 N + */ + private String OperatorRegAddress; + + /** + * 澶囨敞 N + */ + private String OperatorNote; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/OrderInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/OrderInfo.java new file mode 100644 index 000000000..ea113e8f2 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/OrderInfo.java @@ -0,0 +1,150 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 璁㈠崟淇℃伅 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class OrderInfo { + /** + * 瀵规帴骞冲彴ID Y + * 缁勭粐鏈烘瀯浠g爜 + */ + private String OperatorID; + + /** + * 璁惧鎵灞炶繍钀ュ晢ID Y + * 璁惧鎵灞炶繍钀ュ晢缁勭粐鏈烘瀯浠g爜 + */ + private String EquipmentOwnerID; + + /** + * 鍏呯數绔橧D Y + * 瀵规帴骞冲彴鑷畾涔夌殑鍞竴缂栫爜 + */ + private String StationID; + + /** + * 璁惧缂栫爜 Y + * 璁惧鍞竴缂栫爜锛屽鍚屼竴瀵规帴骞冲彴锛屼繚璇佸敮涓 + */ + private String EquipmentID; + + /** + * 鍏呯數璁惧鎺ュ彛缂栫爜 Y + * 鍏呯數璁惧鎺ュ彛缂栫爜锛屽悓涓瀵规帴骞冲彴鍐呭敮涓 + */ + private String ConnectorID; + + /** + * 鍏呯數璁㈠崟鍙 Y + * 瀵规帴骞冲彴绯荤粺璁㈠崟缂栧彿 + */ + private String StartChargeSeq; + + /** + * 鐢ㄦ埛鍙戣捣鍏呯數绫诲瀷 Y + * 1:鏈钩鍙版敞鍐岀敤鎴 + * 2:鍗$敤鎴 + * 3锛氫簰鑱斾簰閫氱敤鎴 + * 10:鍏朵粬 + */ + private Integer UserChargeType; + + /** + * 鐢ㄦ埛鎵嬫満鍙 N + * 鑻ョ敤鎴峰彂璧峰厖鐢电被鍨嬩负 APP锛岀敤鎴锋墜鏈哄彿蹇呭~ + */ + private String MobileNumber; + + /** + * 鏈鍏呯數娑堣垂鎬婚噾棰(鍗曚綅锛氬厓,淇濈暀灏忔暟鐐瑰悗2浣) Y + */ + private BigDecimal Money; + + /** + * 鏈鍏呯數鐢佃垂鎬婚噾棰(鍗曚綅锛氬厓,淇濈暀灏忔暟鐐瑰悗2浣) Y + */ + private BigDecimal ElectMoney; + + /** + * 鏈鍏呯數鏈嶅姟璐归噾棰(鍗曚綅锛氬厓,淇濈暀灏忔暟鐐瑰悗2浣) Y + */ + private BigDecimal ServiceMoney; + + /** + * 鏈鍏呯數鐢甸噺 Y + * 鍗曚綅kWh锛岀簿搴0.01,淇濈暀灏忔暟鐐瑰悗2浣 + */ + private BigDecimal Elect; + + /** + * 鏈鍏呯數寮濮嬫椂闂 Y + * 鏍煎紡鈥測yyy-MM-dd HH:mm:ss鈥 + */ + private String StartTime; + + /** + * 鏈鍏呯數缁撴潫鏃堕棿 Y + * 鏍煎紡鈥測yyy-MM-dd HH:mm:ss鈥 + */ + private String EndTime; + + /** + * 鏀粯閲戦 Y + */ + private BigDecimal PaymentAmount; + + /** + * 鏀粯鏃堕棿 N + */ + private String PayTime; + + /** + * 鏀粯鏂瑰紡 Y + * 1锛氭敮浠樺疂 + * 2锛氬井淇℃敮浠 + * 3锛氫氦閫氬崱 + * 4锛氶鍏呭崱 + * 5锛氶摱鑱 + * 6锛氬叾浠栬嚜瀹氫箟 + */ + private Integer PayChannel; + + /** + * 浼樻儬淇℃伅鎻忚堪 N + * 鎻忚堪鏀粯鐨勭浉鍏充紭鎯犱俊鎭紝濡備紭鎯犲埜锛屾姌鎵g瓑 + */ + private String DiscountInfo; + + /** + * 鍏呯數缁撴潫鍘熷洜 Y + * 0:鐢ㄦ埛鎵嬪姩鍋滄鍏呯數 + * 1:瀹㈡埛褰掑睘鍦拌繍钀ュ晢骞冲彴鍋滄鍏呯數 + * 2:BMS鍋滄鍏呯數 + * 3:鍏呯數鏈鸿澶囨晠闅 + * 4:杩炴帴鍣ㄦ柇寮 + * 5-99鑷畾涔 + */ + private Integer StopReason; + + /** + * 鏃舵鏁癗,鑼冨洿锛0锝32 N + */ + private Integer SumPeriod; + + /** + * 鍏呯數鏄庣粏淇℃伅 Y + */ + private List ChargeDetails; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/StationInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/StationInfo.java new file mode 100644 index 000000000..8e6f667fd --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/StationInfo.java @@ -0,0 +1,318 @@ +package com.jsowell.thirdparty.vo; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 鍏呯數绔欎俊鎭 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class StationInfo { + /** + * 鍏呯數绔橧D Y + * 瀵规帴骞冲彴鑷畾涔夌殑鍞竴缂栫爜 + */ + private String StationID; + + /** + * 瀵规帴骞冲彴ID Y + * 缁勭粐鏈烘瀯浠g爜 + */ + private String OperatorID; + + /** + * 璁惧鎵灞炶繍钀ュ晢ID Y + * 璁惧鎵灞炶繍钀ュ晢缁勭粐鏈烘瀯浠g爜 + */ + private String EquipmentOwnerID; + + /** + * 鍏呯數绔欏悕绉 Y + * 鍏呯數绔欏悕绉扮殑鎻忚堪 + */ + private String StationName; + + /** + * 鏄惁鐙珛鎶ユ々 (0-鍚;1-鏄) Y + * 濡傛灉鏄嫭绔嬫姤妗╅渶瑕佸~鍐欐埛鍙蜂互鍙婂閲 + */ + private Integer IsAloneApply; + + /** + * 鎴峰彿 N + * 鍥界綉鐢佃垂璐﹀崟鎴峰彿 + */ + private String AccountNumber; + + /** + * 瀹归噺(鍗曚綅KW) N + * 鐙珛鐢佃〃鐢宠鐨勫姛鐜 + */ + private BigDecimal Capacity; + + /** + * 鏄惁鏄叕鍏卞仠杞﹀満搴 (0-鍚;1-鏄) Y + * 濡傛灉鏄叕鍏卞仠杞﹀満搴撻渶瑕佸~鍐欏満搴撶紪鍙 + */ + private Integer IsPublicParkingLot; + + /** + * 鍋滆溅鍦哄簱缂栧彿 N + * 鍏叡鍋滆溅鍦哄簱缂栧彿 + */ + private String ParkingLotNumber; + + /** + * 鍏呯數绔欏浗瀹朵唬鐮 Y + * 姣斿CN + */ + private String CountryCode; + + /** + * 鍏呯數绔欑渷甯傝緰鍖虹紪鐮 Y + * 濉啓鍐呭涓哄弬鐓 GB/T2260-2015 + */ + private String AreaCode; + + /** + * 璇︾粏鍦板潃 Y + */ + private String Address; + + /** + * 绔欑偣鐢佃瘽 N + * 鑳藉鑱旂郴鍦虹珯宸ヤ綔浜哄憳杩涜鍗忓姪鐨勮仈绯荤數璇 + */ + private String StationTel; + + /** + * 鏈嶅姟鐢佃瘽 Y + * 骞冲彴鏈嶅姟鐢佃瘽锛屼緥濡400 鐨勭數璇 + */ + private String ServiceTel; + + /** + * 绔欑偣绫诲瀷 Y + * 1-鍏叡 + * 50-涓汉 + * 100-鍏氦锛堜笓鐢級 + * 101-鐜崼锛堜笓鐢級 + * 102-鐗╂祦锛堜笓鐢級 + * 103-鍑虹杞︼紙涓撶敤锛 + * 104-鍒嗘椂绉熻祦锛堜笓鐢級 + * 105-灏忓尯鍏变韩锛堜笓鐢級 + * 106-鍗曚綅锛堜笓鐢級 + * 255-鍏朵粬 + */ + private Integer StationType; + + /** + * 绔欑偣鐘舵 Y + * 0锛氭湭鐭 + * 1锛氬缓璁句腑 + * 5锛氬叧闂笅绾 + * 6锛氱淮鎶や腑 + * 50锛氭甯镐娇鐢 + */ + private Integer StationStatus; + + /** + * 杞︿綅鏁伴噺 Y + * 鍙仠鏀捐繘琛屽厖鐢电殑杞︿綅鎬绘暟(榛樿锛0-鏈煡) + */ + private Integer ParkNums; + + /** + * 缁忓害 Y + * GCJ-02鍧愭爣绯 + */ + private BigDecimal StationLng; + + /** + * 绾害 Y + * GCJ-02鍧愭爣绯 + */ + private BigDecimal StationLat; + + /** + * 绔欑偣寮曞 N + * 鎻忚堪鎬ф枃瀛楋紝鐢ㄤ簬寮曞杞︿富鎵惧埌鍏呯數杞︿綅 + */ + private String SiteGuide; + + /** + * 寤鸿鍦烘墍 Y + * 1锛氬眳姘戝尯 + * 2锛氬叕鍏辨満鏋 + * 3锛氫紒浜嬩笟鍗曚綅 + * 4锛氬啓瀛楁ゼ + * 5锛氬伐涓氬洯鍖 + * 6锛氫氦閫氭灑绾 + * 7锛氬ぇ鍨嬫枃浣撹鏂 + * 8锛氬煄甯傜豢鍦 + * 9锛氬ぇ鍨嬪缓绛戦厤寤哄仠杞﹀満 + * 10锛氳矾杈瑰仠杞︿綅 + * 11锛氬煄闄呴珮閫熸湇鍔″尯 + * 12锛氶鏅尯 + * 13锛氬叕浜ゅ満绔 + * 14锛氬姞娌瑰姞姘旂珯 + * 15锛氬嚭绉熻溅 + * 255锛氬叾浠 + */ + private Integer Construction; + + /** + * 绔欑偣鐓х墖 N + * 鍏呯數璁惧鐓х墖銆佸厖鐢佃溅浣嶇収鐗囥佸仠杞﹀満鍏ュ彛鐓х墖 + */ + private List Pictures; + + /** + * 浣跨敤杞﹀瀷鎻忚堪 N + * 鎻忚堪璇ョ珯鐐规帴鍙楃殑杞﹀ぇ灏忎互鍙婄被鍨嬶紝濡傚ぇ宸淬佺墿娴佽溅銆佺瀹朵箻鐢ㄨ溅銆佸嚭绉熻溅绛 + */ + private String MatchCars; + + /** + * 杞︿綅妤煎眰鍙婃暟閲忔弿杩 N + * 杞︿綅妤煎眰浠ュ強鏁伴噺淇℃伅 + */ + private String ParkInfo; + + /** + * 鍋滆溅鍦轰骇鏉冩柟 N + * 鍋滆溅鍦轰骇鏉冧汉 + */ + private String ParkOwner; + + /** + * 鍋滆溅鍦虹鐞嗘柟 N + * 鍋滆溅鍦虹鐞嗕汉锛堝锛歑X 鐗╀笟锛 + */ + private String ParkManager; + + /** + * 鍏ㄥぉ寮鏀 Y + * 鏄惁鍏ㄥぉ寮鏀(0-鍚︼紱1-鏄),濡傛灉涓0锛屽垯钀ヤ笟鏃堕棿蹇呭~ + */ + private Integer OpenAllDay; + + /** + * 钀ヤ笟鏃堕棿 N + * 钀ヤ笟鏃堕棿鎻忚堪,鎺ㄨ崘鏍煎紡锛氬懆涓鑷冲懆鏃00:00-24:00 + */ + private String BusineHours; + + /** + * 鏈浣庡崟浠 Y + * 鏈浣庡厖鐢电數璐圭巼 + */ + private BigDecimal MinElectricityPrice; + + /** + * 鍏呯數鐢佃垂鐜 Y + * 鍏呯數璐规弿杩,鎺ㄨ崘鏍煎紡锛歑X 鍏/搴 + */ + private String ElectricityFee; + + /** + * 鏈嶅姟璐圭巼 Y + * 鏈嶅姟璐圭巼鎻忚堪,鎺ㄨ崘鏍煎紡锛歑X 鍏/搴 + */ + private String ServiceFee; + + /** + * 鍏嶈垂鍋滆溅 Y + * 鏄惁鍋滆溅鍏嶈垂(0-鍚︼紱1-鏄) + */ + private Integer ParkFree; + + /** + * 鍋滆溅璐 N + * 鍋滆溅璐圭巼鎻忚堪 + */ + private String ParkFee; + + /** + * 鏀粯鏂瑰紡 Y + * 鏀粯鏂瑰紡:鍒峰崱銆佺嚎涓娿佺幇閲 鍏朵腑鐢靛瓙閽卞寘绫诲崱涓哄埛鍗★紝韬唤閴存潈鍗°佸井淇/ 鏀粯瀹濄丄PP涓虹嚎涓 + */ + private String Payment; + + /** + * 鏄惁鏀寔棰勭害 Y + * 鍏呯數璁惧鏄惁闇瑕佹彁鍓嶉绾﹀悗鎵嶈兘浣跨敤銆(0-涓嶆敮鎸侀绾;1-鏀寔棰勭害) 涓嶅~榛樿涓0 + */ + private Integer SupportOrder; + + /** + * 澶囨敞 N + * 鍏朵粬澶囨敞淇℃伅 + */ + private String Remark; + + /** + * 鍏呯數璁惧淇℃伅鍒楄〃 Y + * 璇ュ厖鐢电珯鎵鏈夊厖鐢佃澶囦俊鎭璞¢泦鍚 + */ + private List EquipmentInfos; + + /** + * 鍋滆溅鏀惰垂绫诲瀷 Y + * 0:鍋滆溅鏀惰垂; + * 1:鍋滆溅鍏嶈垂; + * 2:闄愭椂鍏嶈垂; + * 3:鍏呯數闄愬厤 + */ + private Integer ParkFeeType; + + /** + * 鏄惁闈犺繎鍗敓闂(0-鍚︼紱1-鏄) Y + */ + private Integer ToiletFlag; + + /** + * 鏄惁闈犺繎渚垮埄搴(0-鍚︼紱1-鏄) Y + */ + private Integer StoreFlag; + + /** + * 鏄惁闈犺繎椁愬巺(0-鍚︼紱1-鏄) Y + */ + private Integer RestaurantFlag; + + /** + * 鏄惁闈犺繎浼戞伅瀹(0-鍚︼紱1-鏄) Y + */ + private Integer LoungeFlag; + + /** + * 鏄惁鏈夐洦妫(0-鍚︼紱1-鏄) Y + */ + private Integer CanopyFlag; + + /** + * 鏄惁鏈夊皬绁ㄦ満(0-鍚︼紱1-鏄) Y + */ + private Integer PrinterFlag; + + /** + * 鏄惁鏈夐亾闂(0-鍚︼紱1-鏄) Y + */ + private Integer BarrierFlag; + + /** + * 鏄惁鏈夊湴閿(0-鍚︼紱1-鏄) Y + */ + private Integer ParkingLockFlag; + +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/StationStatusInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/StationStatusInfo.java new file mode 100644 index 000000000..55fb432a7 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/StationStatusInfo.java @@ -0,0 +1,29 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 鍏呯數绔欑姸鎬佷俊鎭 + */ +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Data +public class StationStatusInfo { + /** + * 鍏呯數绔橧D Y + * 瀵规帴骞冲彴鑷畾涔夌殑鍞竴缂栫爜锛屼笉瓒抽暱搴﹀湪鍓嶆柟琛0 + */ + private String StationID; + + /** + * 鍏呯數璁惧鎺ュ彛鐘舵佸垪琛 Y + * 鎵鏈夊厖鐢佃澶囨帴鍙g殑鐘舵 + */ + private List ConnectorStatusInfos; +} diff --git a/jsowell-ui/.editorconfig b/jsowell-ui/.editorconfig new file mode 100644 index 000000000..7034f9bf3 --- /dev/null +++ b/jsowell-ui/.editorconfig @@ -0,0 +1,22 @@ +# 鍛婅瘔EditorConfig鎻掍欢锛岃繖鏄牴鏂囦欢锛屼笉鐢ㄧ户缁線涓婃煡鎵 +root = true + +# 鍖归厤鍏ㄩ儴鏂囦欢 +[*] +# 璁剧疆瀛楃闆 +charset = utf-8 +# 缂╄繘椋庢牸锛屽彲閫塻pace銆乼ab +indent_style = space +# 缂╄繘鐨勭┖鏍兼暟 +indent_size = 2 +# 缁撳熬鎹㈣绗︼紝鍙塴f銆乧r銆乧rlf +end_of_line = lf +# 鍦ㄦ枃浠剁粨灏炬彃鍏ユ柊琛 +insert_final_newline = true +# 鍒犻櫎涓琛屼腑鐨勫墠鍚庣┖鏍 +trim_trailing_whitespace = true + +# 鍖归厤md缁撳熬鐨勬枃浠 +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/jsowell-ui/.env.development b/jsowell-ui/.env.development new file mode 100644 index 000000000..8bd201e1c --- /dev/null +++ b/jsowell-ui/.env.development @@ -0,0 +1,11 @@ +# 椤甸潰鏍囬 +VUE_APP_TITLE = 涓捐鍚庡彴绠$悊绯荤粺 + +# 寮鍙戠幆澧冮厤缃 +ENV = 'development' + +# 涓捐鍚庡彴绠$悊绯荤粺/寮鍙戠幆澧 +VUE_APP_BASE_API = '/dev-api' + +# 璺敱鎳掑姞杞 +VUE_CLI_BABEL_TRANSPILE_MODULES = true diff --git a/jsowell-ui/.env.production b/jsowell-ui/.env.production new file mode 100644 index 000000000..ce94db862 --- /dev/null +++ b/jsowell-ui/.env.production @@ -0,0 +1,8 @@ +# 椤甸潰鏍囬 +VUE_APP_TITLE = 涓捐鍚庡彴绠$悊绯荤粺 + +# 鐢熶骇鐜閰嶇疆 +ENV = 'production' + +# 涓捐鍚庡彴绠$悊绯荤粺/鐢熶骇鐜 +VUE_APP_BASE_API = '/prod-api' diff --git a/jsowell-ui/.env.staging b/jsowell-ui/.env.staging new file mode 100644 index 000000000..c740e5668 --- /dev/null +++ b/jsowell-ui/.env.staging @@ -0,0 +1,10 @@ +# 椤甸潰鏍囬 +VUE_APP_TITLE = 涓捐鍚庡彴绠$悊绯荤粺 + +NODE_ENV = production + +# 娴嬭瘯鐜閰嶇疆 +ENV = 'staging' + +# 涓捐鍚庡彴绠$悊绯荤粺/娴嬭瘯鐜 +VUE_APP_BASE_API = '/stage-api' diff --git a/jsowell-ui/.eslintignore b/jsowell-ui/.eslintignore new file mode 100644 index 000000000..89be6f659 --- /dev/null +++ b/jsowell-ui/.eslintignore @@ -0,0 +1,10 @@ +# 蹇界暐build鐩綍涓嬬被鍨嬩负js鐨勬枃浠剁殑璇硶妫鏌 +build/*.js +# 蹇界暐src/assets鐩綍涓嬫枃浠剁殑璇硶妫鏌 +src/assets +# 蹇界暐public鐩綍涓嬫枃浠剁殑璇硶妫鏌 +public +# 蹇界暐褰撳墠鐩綍涓嬩负js鐨勬枃浠剁殑璇硶妫鏌 +*.js +# 蹇界暐褰撳墠鐩綍涓嬩负vue鐨勬枃浠剁殑璇硶妫鏌 +*.vue \ No newline at end of file diff --git a/jsowell-ui/.eslintrc.js b/jsowell-ui/.eslintrc.js new file mode 100644 index 000000000..b27a7fe76 --- /dev/null +++ b/jsowell-ui/.eslintrc.js @@ -0,0 +1,279 @@ +// ESlint 妫鏌ラ厤缃 +module.exports = { + root: true, + parserOptions: { + parser: "babel-eslint", + sourceType: "module", + }, + env: { + browser: true, + node: true, + es6: true, + }, + // globals: { + // AMap: "true", + // }, + extends: ["plugin:vue/recommended", "eslint:recommended"], + + // add your custom rules here + //it is base on https://github.com/vuejs/eslint-config-vue + rules: { + "vue/max-attributes-per-line": [ + 2, + { + singleline: 10, + multiline: { + max: 1, + allowFirstLine: false, + }, + }, + ], + "vue/singleline-html-element-content-newline": "off", + "vue/multiline-html-element-content-newline": "off", + "vue/name-property-casing": ["error", "PascalCase"], + "vue/no-v-html": "off", + "accessor-pairs": 2, + "arrow-spacing": [ + 2, + { + before: true, + after: true, + }, + ], + "block-spacing": [2, "always"], + "brace-style": [ + 2, + "1tbs", + { + allowSingleLine: true, + }, + ], + camelcase: [ + 0, + { + properties: "always", + }, + ], + "comma-dangle": [2, "never"], + "comma-spacing": [ + 2, + { + before: false, + after: true, + }, + ], + "comma-style": [2, "last"], + "constructor-super": 2, + curly: [2, "multi-line"], + "dot-location": [2, "property"], + "eol-last": 2, + eqeqeq: ["error", "always", { null: "ignore" }], + "generator-star-spacing": [ + 2, + { + before: true, + after: true, + }, + ], + "handle-callback-err": [2, "^(err|error)$"], + indent: [ + 2, + 2, + { + SwitchCase: 1, + }, + ], + "jsx-quotes": [2, "prefer-single"], + "key-spacing": [ + 2, + { + beforeColon: false, + afterColon: true, + }, + ], + "keyword-spacing": [ + 2, + { + before: true, + after: true, + }, + ], + "new-cap": [ + 2, + { + newIsCap: true, + capIsNew: false, + }, + ], + "new-parens": 2, + "no-array-constructor": 2, + "no-caller": 2, + "no-console": "off", + "no-class-assign": 2, + "no-cond-assign": 2, + "no-const-assign": 2, + "no-control-regex": 0, + "no-delete-var": 2, + "no-dupe-args": 2, + "no-dupe-class-members": 2, + "no-dupe-keys": 2, + "no-duplicate-case": 2, + "no-empty-character-class": 2, + "no-empty-pattern": 2, + "no-eval": 2, + "no-ex-assign": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-extra-boolean-cast": 2, + "no-extra-parens": [2, "functions"], + "no-fallthrough": 2, + "no-floating-decimal": 2, + "no-func-assign": 2, + "no-implied-eval": 2, + "no-inner-declarations": [2, "functions"], + "no-invalid-regexp": 2, + "no-irregular-whitespace": 2, + "no-iterator": 2, + "no-label-var": 2, + "no-labels": [ + 2, + { + allowLoop: false, + allowSwitch: false, + }, + ], + "no-lone-blocks": 2, + "no-mixed-spaces-and-tabs": 2, + "no-multi-spaces": 2, + "no-multi-str": 2, + "no-multiple-empty-lines": [ + 2, + { + max: 1, + }, + ], + "no-native-reassign": 2, + "no-negated-in-lhs": 2, + "no-new-object": 2, + "no-new-require": 2, + "no-new-symbol": 2, + "no-new-wrappers": 2, + "no-obj-calls": 2, + "no-octal": 2, + "no-octal-escape": 2, + "no-path-concat": 2, + "no-proto": 2, + "no-redeclare": 2, + "no-regex-spaces": 2, + "no-return-assign": [2, "except-parens"], + "no-self-assign": 2, + "no-self-compare": 2, + "no-sequences": 2, + "no-shadow-restricted-names": 2, + "no-spaced-func": 2, + "no-sparse-arrays": 2, + "no-this-before-super": 2, + "no-throw-literal": 2, + "no-trailing-spaces": 2, + "no-undef": 2, + "no-undef-init": 2, + "no-unexpected-multiline": 2, + "no-unmodified-loop-condition": 2, + "no-unneeded-ternary": [ + 2, + { + defaultAssignment: false, + }, + ], + "no-unreachable": 2, + "no-unsafe-finally": 2, + "no-unused-vars": [ + 2, + { + vars: "all", + args: "none", + }, + ], + "no-useless-call": 2, + "no-useless-computed-key": 2, + "no-useless-constructor": 2, + "no-useless-escape": 0, + "no-whitespace-before-property": 2, + "no-with": 2, + "one-var": [ + 2, + { + initialized: "never", + }, + ], + "operator-linebreak": [ + 2, + "after", + { + overrides: { + "?": "before", + ":": "before", + }, + }, + ], + "padded-blocks": [2, "never"], + quotes: [ + 2, + "single", + { + avoidEscape: true, + allowTemplateLiterals: true, + }, + ], + semi: [2, "never"], + "semi-spacing": [ + 2, + { + before: false, + after: true, + }, + ], + "space-before-blocks": [2, "always"], + "space-before-function-paren": [2, "never"], + "space-in-parens": [2, "never"], + "space-infix-ops": 2, + "space-unary-ops": [ + 2, + { + words: true, + nonwords: false, + }, + ], + "spaced-comment": [ + 2, + "always", + { + markers: [ + "global", + "globals", + "eslint", + "eslint-disable", + "*package", + "!", + ",", + ], + }, + ], + "template-curly-spacing": [2, "never"], + "use-isnan": 2, + "valid-typeof": 2, + "wrap-iife": [2, "any"], + "yield-star-spacing": [2, "both"], + yoda: [2, "never"], + "prefer-const": 2, + "no-debugger": process.env.NODE_ENV === "production" ? 2 : 0, + "object-curly-spacing": [ + 2, + "always", + { + objectsInObjects: false, + }, + ], + "array-bracket-spacing": [2, "never"], + }, +}; diff --git a/jsowell-ui/.gitignore b/jsowell-ui/.gitignore new file mode 100644 index 000000000..78a752d87 --- /dev/null +++ b/jsowell-ui/.gitignore @@ -0,0 +1,23 @@ +.DS_Store +node_modules/ +dist/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* +**/*.log + +tests/**/coverage/ +tests/e2e/reports +selenium-debug.log + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.local + +package-lock.json +yarn.lock diff --git a/jsowell-ui/README.md b/jsowell-ui/README.md new file mode 100644 index 000000000..2f227da3d --- /dev/null +++ b/jsowell-ui/README.md @@ -0,0 +1,26 @@ +## 寮鍙 + +# 杩涘叆椤圭洰鐩綍 +cd jsowell-ui + +# 瀹夎渚濊禆 +npm install + +# 寤鸿涓嶈鐩存帴浣跨敤 cnpm 瀹夎渚濊禆锛屼細鏈夊悇绉嶈寮傜殑 bug銆傚彲浠ラ氳繃濡備笅鎿嶄綔瑙e喅 npm 涓嬭浇閫熷害鎱㈢殑闂 +npm install --registry=https://registry.npmmirror.com + +# 鍚姩鏈嶅姟 +npm run dev +``` + +娴忚鍣ㄨ闂 http://localhost:80 + +## 鍙戝竷 + +```bash +# 鏋勫缓娴嬭瘯鐜 +npm run build:stage + +# 鏋勫缓鐢熶骇鐜 +npm run build:prod +``` \ No newline at end of file diff --git a/jsowell-ui/babel.config.js b/jsowell-ui/babel.config.js new file mode 100644 index 000000000..c8267b2dd --- /dev/null +++ b/jsowell-ui/babel.config.js @@ -0,0 +1,13 @@ +module.exports = { + presets: [ + // https://github.com/vuejs/vue-cli/tree/master/packages/@vue/babel-preset-app + '@vue/cli-plugin-babel/preset' + ], + 'env': { + 'development': { + // babel-plugin-dynamic-import-node plugin only does one thing by converting all import() to require(). + // This plugin can significantly increase the speed of hot updates, when you have a large number of pages. + 'plugins': ['dynamic-import-node'] + } + } +} \ No newline at end of file diff --git a/jsowell-ui/bin/build-sit.bat b/jsowell-ui/bin/build-sit.bat new file mode 100644 index 000000000..56aa9b136 --- /dev/null +++ b/jsowell-ui/bin/build-sit.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [信息] 打包Web工程,生成dist文件。 +echo. + +%~d0 +cd %~dp0 + +cd .. +npm run build:stage + +pause \ No newline at end of file diff --git a/jsowell-ui/bin/build.bat b/jsowell-ui/bin/build.bat new file mode 100644 index 000000000..dda590d22 --- /dev/null +++ b/jsowell-ui/bin/build.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [信息] 打包Web工程,生成dist文件。 +echo. + +%~d0 +cd %~dp0 + +cd .. +npm run build:prod + +pause \ No newline at end of file diff --git a/jsowell-ui/bin/package.bat b/jsowell-ui/bin/package.bat new file mode 100644 index 000000000..0e5bc0fb5 --- /dev/null +++ b/jsowell-ui/bin/package.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [信息] 安装Web工程,生成node_modules文件。 +echo. + +%~d0 +cd %~dp0 + +cd .. +npm install --registry=https://registry.npmmirror.com + +pause \ No newline at end of file diff --git a/jsowell-ui/bin/run-web.bat b/jsowell-ui/bin/run-web.bat new file mode 100644 index 000000000..d30deae79 --- /dev/null +++ b/jsowell-ui/bin/run-web.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [信息] 使用 Vue CLI 命令运行 Web 工程。 +echo. + +%~d0 +cd %~dp0 + +cd .. +npm run dev + +pause \ No newline at end of file diff --git a/jsowell-ui/package.json b/jsowell-ui/package.json new file mode 100644 index 000000000..f47a91539 --- /dev/null +++ b/jsowell-ui/package.json @@ -0,0 +1,89 @@ +{ + "name": "jsowell", + "version": "1.0.0", + "description": "涓捐绠$悊绯荤粺", + "scripts": { + "dev": "vue-cli-service serve", + "build:prod": "vue-cli-service build", + "build:stage": "vue-cli-service build --mode staging", + "preview": "node build/index.js --preview", + "lint": "eslint --ext .js,.vue src" + }, + "husky": { + "hooks": { + "pre-commit": "lint-staged" + } + }, + "lint-staged": { + "src/**/*.{js,vue}": [ + "eslint --fix", + "git add" + ] + }, + "keywords": [ + "vue", + "admin", + "dashboard", + "element-ui", + "boilerplate", + "admin-template", + "management-system" + ], + "dependencies": { + "@amap/amap-jsapi-loader": "^1.0.1", + "@riophae/vue-treeselect": "0.4.0", + "axios": "0.24.0", + "clipboard": "2.0.8", + "copy-webpack-plugin": "^6.0.3", + "core-js": "3.19.1", + "echarts": "^4.9.0", + "element-china-area-data": "^5.0.2", + "element-ui": "2.15.8", + "file-saver": "2.0.5", + "fuse.js": "6.4.3", + "highlight.js": "9.18.5", + "js-beautify": "1.13.0", + "js-cookie": "3.0.1", + "jsencrypt": "3.0.0-rc.1", + "nprogress": "0.2.0", + "qrcodejs2": "^0.0.2", + "quill": "1.3.7", + "screenfull": "5.0.2", + "sortablejs": "1.10.2", + "vue": "2.6.12", + "vue-count-to": "1.0.13", + "vue-cropper": "0.5.5", + "vue-meta": "2.4.0", + "vue-qr": "^4.0.9", + "vue-router": "3.4.9", + "vuedraggable": "2.24.3", + "vuex": "3.6.0" + }, + "devDependencies": { + "@vue/cli-plugin-babel": "4.4.6", + "@vue/cli-plugin-eslint": "4.4.6", + "@vue/cli-service": "4.4.6", + "babel-eslint": "10.1.0", + "babel-plugin-dynamic-import-node": "2.3.3", + "chalk": "4.1.0", + "compression-webpack-plugin": "5.0.2", + "connect": "3.6.6", + "eslint": "^7.15.0", + "eslint-plugin-vue": "7.2.0", + "lint-staged": "10.5.3", + "runjs": "4.4.2", + "sass": "1.32.13", + "sass-loader": "10.1.1", + "script-ext-html-webpack-plugin": "2.1.5", + "svg-sprite-loader": "5.1.1", + "vue-template-compiler": "2.6.12" + }, + "engines": { + "node": ">=8.9", + "npm": ">= 3.0.0" + }, + "browserslist": [ + "> 1%", + "last 2 versions" + ] +} diff --git a/jsowell-ui/public/favicon.ico b/jsowell-ui/public/favicon.ico new file mode 100644 index 000000000..225d890c2 Binary files /dev/null and b/jsowell-ui/public/favicon.ico differ diff --git a/jsowell-ui/public/html/ie.html b/jsowell-ui/public/html/ie.html new file mode 100644 index 000000000..052ffcd64 --- /dev/null +++ b/jsowell-ui/public/html/ie.html @@ -0,0 +1,46 @@ + + + + + + 璇峰崌绾ф偍鐨勬祻瑙堝櫒 + + + + + + +

璇峰崌绾ф偍鐨勬祻瑙堝櫒锛屼互渚挎垜浠洿濂界殑涓烘偍鎻愪緵鏈嶅姟锛

+

鎮ㄦ鍦ㄤ娇鐢 Internet Explorer 鐨勬棭鏈熺増鏈紙IE11浠ヤ笅鐗堟湰鎴栦娇鐢ㄨ鍐呮牳鐨勬祻瑙堝櫒锛夈傝繖鎰忓懗鐫鍦ㄥ崌绾ф祻瑙堝櫒鍓嶏紝鎮ㄥ皢鏃犳硶璁块棶姝ょ綉绔欍

+
+

璇锋敞鎰忥細寰蒋鍏徃瀵筗indows XP 鍙 Internet Explorer 鏃╂湡鐗堟湰鐨勬敮鎸佸凡缁忕粨鏉

+

鑷 2016 骞 1 鏈 12 鏃ヨ捣锛孧icrosoft 涓嶅啀涓 IE 11 浠ヤ笅鐗堟湰鎻愪緵鐩稿簲鏀寔鍜屾洿鏂般傛病鏈夊叧閿殑娴忚鍣ㄥ畨鍏ㄦ洿鏂帮紝鎮ㄧ殑鐢佃剳鍙兘鏄撳彈鏈夊鐥呮瘨銆侀棿璋嶈蒋浠跺拰鍏朵粬鎭舵剰杞欢鐨勬敾鍑伙紝瀹冧滑鍙互绐冨彇鎴栨崯瀹虫偍鐨勪笟鍔℃暟鎹拰淇℃伅銆傝鍙傞槄 寰蒋瀵 Internet Explorer 鏃╂湡鐗堟湰鐨勬敮鎸佸皢浜 2016 骞 1 鏈 12 鏃ョ粨鏉熺殑璇存槑

+
+

鎮ㄥ彲浠ラ夋嫨鏇村厛杩涚殑娴忚鍣

+

鎺ㄨ崘浣跨敤浠ヤ笅娴忚鍣ㄧ殑鏈鏂扮増鏈傚鏋滄偍鐨勭數鑴戝凡鏈変互涓嬫祻瑙堝櫒鐨勬渶鏂扮増鏈垯鐩存帴浣跨敤璇ユ祻瑙堝櫒璁块棶鍗冲彲銆

+ +
+ + \ No newline at end of file diff --git a/jsowell-ui/public/index.html b/jsowell-ui/public/index.html new file mode 100644 index 000000000..8ed4d7375 --- /dev/null +++ b/jsowell-ui/public/index.html @@ -0,0 +1,213 @@ + + + + + + + + + <%= webpackConfig.name %> + + + + + +
+
+
+
+
+
姝e湪鍔犺浇绯荤粺璧勬簮锛岃鑰愬績绛夊緟
+
+
+ + diff --git a/jsowell-ui/public/robots.txt b/jsowell-ui/public/robots.txt new file mode 100644 index 000000000..77470cb39 --- /dev/null +++ b/jsowell-ui/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / \ No newline at end of file diff --git a/jsowell-ui/src/App.vue b/jsowell-ui/src/App.vue new file mode 100644 index 000000000..391d951c4 --- /dev/null +++ b/jsowell-ui/src/App.vue @@ -0,0 +1,19 @@ + + + diff --git a/jsowell-ui/src/api/billing/template.js b/jsowell-ui/src/api/billing/template.js new file mode 100644 index 000000000..b6620c847 --- /dev/null +++ b/jsowell-ui/src/api/billing/template.js @@ -0,0 +1,100 @@ +import request from "@/utils/request"; + +// 鏌ヨ璁¤垂妯℃澘鍒楄〃 +export function listTemplate(query) { + return request({ + url: "/billing/template/list", + method: "get", + params: query, + }); +} + +// 澧炲姞璁¤垂妯℃澘 +export function addBillingTemplate(data) { + console.log("澧炲姞璁¤垂妯℃澘", JSON.stringify(data)); + return request({ + method: "post", + url: "/billing/template/createBillingTemplate", + data, + }); +} + +// 鏇存柊璁¤垂妯℃澘 +export function updateBillingTemplate(data) { + console.log("鏇存柊璁¤垂妯℃澘", JSON.stringify(data)); + return request({ + method: "post", + url: "/billing/template/updateBillingTemplate", + data, + }); +} + +// 鏌ヨ璁¤垂妯℃澘璇︾粏 +export function getTemplate(id) { + return request({ + url: "/billing/template/" + id, + method: "get", + }); +} + +// 鏂板璁¤垂妯℃澘 +export function addTemplate(data) { + return request({ + url: "/billing/template", + method: "post", + data: data, + }); +} + +// 淇敼璁¤垂妯℃澘 +export function updateTemplate(data) { + return request({ + url: "/billing/template", + method: "put", + data: data, + }); +} + +// 鍒犻櫎璁¤垂妯℃澘 +export function delTemplate(id) { + return request({ + url: "/billing/template/" + id, + method: "delete", + }); +} + +// 鏌ヨ鍏叡璁¤垂妯℃澘 +export function queryPublicBillingTemplateList() { + return request({ + url: "/billing/template/queryPublicBillingTemplateList", + method: "get", + }); +} + +// 鏌ヨ绔欑偣璁¤垂妯℃澘 +export function queryStationBillingTemplateList(stationId) { + return request({ + url: "/billing/template/queryStationBillingTemplateList/" + stationId, + method: "get", + }); +} + +// 绔欑偣瀵煎叆璁¤垂妯℃澘鎺ュ彛 +export function stationImportBillingTemplate(data) { + return request({ + url: "/billing/template/stationImportBillingTemplate", + method: "post", + data: data, + }); +} + +// 鍙戝竷璁¤垂妯℃澘 +export function publishBillingTemplate(data) { + return request({ + url: "/billing/template/publishBillingTemplate", + method: "post", + data: data, + }); +} + +// 鏌ヨ鍏ㄩ儴璁¤垂妯℃澘 diff --git a/jsowell-ui/src/api/index/index.js b/jsowell-ui/src/api/index/index.js new file mode 100644 index 000000000..a9c62d454 --- /dev/null +++ b/jsowell-ui/src/api/index/index.js @@ -0,0 +1,17 @@ +import request from '@/utils/request' + +// 鏌ヨ棣栭〉淇℃伅 +export function getGeneralSituation(data) { + return request({ + url: '/index/getGeneralSituation', + method: 'post', + data: data + }) +} +export function getOrderInfo(data) { + return request({ + url: '/index/getOrderInfo', + method: 'post', + data: data + }) +} diff --git a/jsowell-ui/src/api/login.js b/jsowell-ui/src/api/login.js new file mode 100644 index 000000000..649f59c81 --- /dev/null +++ b/jsowell-ui/src/api/login.js @@ -0,0 +1,59 @@ +import request from '@/utils/request' + +// 鐧诲綍鏂规硶 +export function login(username, password, code, uuid) { + const data = { + username, + password, + code, + uuid + } + return request({ + url: '/login', + headers: { + isToken: false + }, + method: 'post', + data: data + }) +} + +// 娉ㄥ唽鏂规硶 +export function register(data) { + return request({ + url: '/register', + headers: { + isToken: false + }, + method: 'post', + data: data + }) +} + +// 鑾峰彇鐢ㄦ埛璇︾粏淇℃伅 +export function getInfo() { + return request({ + url: '/getInfo', + method: 'get' + }) +} + +// 閫鍑烘柟娉 +export function logout() { + return request({ + url: '/logout', + method: 'post' + }) +} + +// 鑾峰彇楠岃瘉鐮 +export function getCodeImg() { + return request({ + url: '/captchaImage', + headers: { + isToken: false + }, + method: 'get', + timeout: 20000 + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/member/info.js b/jsowell-ui/src/api/member/info.js new file mode 100644 index 000000000..94f80e563 --- /dev/null +++ b/jsowell-ui/src/api/member/info.js @@ -0,0 +1,79 @@ +import request from '@/utils/request' + +// 鏌ヨ浼氬憳鍩虹淇℃伅鍒楄〃 +export function listInfo(query) { + return request({ + url: '/member/info/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ浼氬憳鍩虹淇℃伅璇︾粏 +export function getInfo(id) { + return request({ + url: '/member/info/' + id, + method: 'get' + }) +} + +// 鏌ヨ浼氬憳涓汉妗╀俊鎭 +export function getMemberPersonPileInfo(id) { + return request({ + url: '/member/info/getMemberPersonPileInfo/' + id, + method: 'get' + }) +} + +// 鏂板浼氬憳鍩虹淇℃伅 +export function addInfo(data) { + return request({ + url: '/member/info', + method: 'post', + data: data + }) +} + +// 淇敼浼氬憳鍩虹淇℃伅 +export function updateInfo(data) { + return request({ + url: '/member/info', + method: 'put', + data: data + }) +} + +// 鍒犻櫎浼氬憳鍩虹淇℃伅 +export function delInfo(id) { + return request({ + url: '/member/info/' + id, + method: 'delete' + }) +} + +// 淇敼浼氬憳鍩虹淇℃伅 +export function updateGiftBalance(data) { + return request({ + url: '/member/info/updateGiftBalance', + method: 'put', + data: data + }) +} + +// 鑾峰彇鐢ㄦ埛璐︽埛浣欓鍙樺姩淇℃伅 +export function getMemberBalanceChanges(data) { + return request({ + url: '/member/info/queryMemberBalanceChanges', + method: 'post', + data: data + }) +} + +// 鑾峰彇浼氬憳浜ゆ槗娴佹按 +export function getMemberTransactionRecordList(data) { + return request({ + url: '/member/info/selectMemberTransactionRecordList', + method: 'post', + data: data + }) +} diff --git a/jsowell-ui/src/api/menu.js b/jsowell-ui/src/api/menu.js new file mode 100644 index 000000000..faef101c4 --- /dev/null +++ b/jsowell-ui/src/api/menu.js @@ -0,0 +1,9 @@ +import request from '@/utils/request' + +// 鑾峰彇璺敱 +export const getRouters = () => { + return request({ + url: '/getRouters', + method: 'get' + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/monitor/cache.js b/jsowell-ui/src/api/monitor/cache.js new file mode 100644 index 000000000..72c5f6a3e --- /dev/null +++ b/jsowell-ui/src/api/monitor/cache.js @@ -0,0 +1,57 @@ +import request from '@/utils/request' + +// 鏌ヨ缂撳瓨璇︾粏 +export function getCache() { + return request({ + url: '/monitor/cache', + method: 'get' + }) +} + +// 鏌ヨ缂撳瓨鍚嶇О鍒楄〃 +export function listCacheName() { + return request({ + url: '/monitor/cache/getNames', + method: 'get' + }) +} + +// 鏌ヨ缂撳瓨閿悕鍒楄〃 +export function listCacheKey(cacheName) { + return request({ + url: '/monitor/cache/getKeys/' + cacheName, + method: 'get' + }) +} + +// 鏌ヨ缂撳瓨鍐呭 +export function getCacheValue(cacheName, cacheKey) { + return request({ + url: '/monitor/cache/getValue/' + cacheName + '/' + cacheKey, + method: 'get' + }) +} + +// 娓呯悊鎸囧畾鍚嶇О缂撳瓨 +export function clearCacheName(cacheName) { + return request({ + url: '/monitor/cache/clearCacheName/' + cacheName, + method: 'delete' + }) +} + +// 娓呯悊鎸囧畾閿悕缂撳瓨 +export function clearCacheKey(cacheKey) { + return request({ + url: '/monitor/cache/clearCacheKey/' + cacheKey, + method: 'delete' + }) +} + +// 娓呯悊鍏ㄩ儴缂撳瓨 +export function clearCacheAll() { + return request({ + url: '/monitor/cache/clearCacheAll', + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/monitor/job.js b/jsowell-ui/src/api/monitor/job.js new file mode 100644 index 000000000..38155693a --- /dev/null +++ b/jsowell-ui/src/api/monitor/job.js @@ -0,0 +1,71 @@ +import request from '@/utils/request' + +// 鏌ヨ瀹氭椂浠诲姟璋冨害鍒楄〃 +export function listJob(query) { + return request({ + url: '/monitor/job/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ瀹氭椂浠诲姟璋冨害璇︾粏 +export function getJob(jobId) { + return request({ + url: '/monitor/job/' + jobId, + method: 'get' + }) +} + +// 鏂板瀹氭椂浠诲姟璋冨害 +export function addJob(data) { + return request({ + url: '/monitor/job', + method: 'post', + data: data + }) +} + +// 淇敼瀹氭椂浠诲姟璋冨害 +export function updateJob(data) { + return request({ + url: '/monitor/job', + method: 'put', + data: data + }) +} + +// 鍒犻櫎瀹氭椂浠诲姟璋冨害 +export function delJob(jobId) { + return request({ + url: '/monitor/job/' + jobId, + method: 'delete' + }) +} + +// 浠诲姟鐘舵佷慨鏀 +export function changeJobStatus(jobId, status) { + const data = { + jobId, + status + } + return request({ + url: '/monitor/job/changeStatus', + method: 'put', + data: data + }) +} + + +// 瀹氭椂浠诲姟绔嬪嵆鎵ц涓娆 +export function runJob(jobId, jobGroup) { + const data = { + jobId, + jobGroup + } + return request({ + url: '/monitor/job/run', + method: 'put', + data: data + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/monitor/jobLog.js b/jsowell-ui/src/api/monitor/jobLog.js new file mode 100644 index 000000000..6e0be6166 --- /dev/null +++ b/jsowell-ui/src/api/monitor/jobLog.js @@ -0,0 +1,26 @@ +import request from '@/utils/request' + +// 鏌ヨ璋冨害鏃ュ織鍒楄〃 +export function listJobLog(query) { + return request({ + url: '/monitor/jobLog/list', + method: 'get', + params: query + }) +} + +// 鍒犻櫎璋冨害鏃ュ織 +export function delJobLog(jobLogId) { + return request({ + url: '/monitor/jobLog/' + jobLogId, + method: 'delete' + }) +} + +// 娓呯┖璋冨害鏃ュ織 +export function cleanJobLog() { + return request({ + url: '/monitor/jobLog/clean', + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/monitor/logininfor.js b/jsowell-ui/src/api/monitor/logininfor.js new file mode 100644 index 000000000..4d112b78a --- /dev/null +++ b/jsowell-ui/src/api/monitor/logininfor.js @@ -0,0 +1,34 @@ +import request from '@/utils/request' + +// 鏌ヨ鐧诲綍鏃ュ織鍒楄〃 +export function list(query) { + return request({ + url: '/monitor/logininfor/list', + method: 'get', + params: query + }) +} + +// 鍒犻櫎鐧诲綍鏃ュ織 +export function delLogininfor(infoId) { + return request({ + url: '/monitor/logininfor/' + infoId, + method: 'delete' + }) +} + +// 瑙i攣鐢ㄦ埛鐧诲綍鐘舵 +export function unlockLogininfor(userName) { + return request({ + url: '/monitor/logininfor/unlock/' + userName, + method: 'get' + }) +} + +// 娓呯┖鐧诲綍鏃ュ織 +export function cleanLogininfor() { + return request({ + url: '/monitor/logininfor/clean', + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/monitor/online.js b/jsowell-ui/src/api/monitor/online.js new file mode 100644 index 000000000..bd2213780 --- /dev/null +++ b/jsowell-ui/src/api/monitor/online.js @@ -0,0 +1,18 @@ +import request from '@/utils/request' + +// 鏌ヨ鍦ㄧ嚎鐢ㄦ埛鍒楄〃 +export function list(query) { + return request({ + url: '/monitor/online/list', + method: 'get', + params: query + }) +} + +// 寮洪鐢ㄦ埛 +export function forceLogout(tokenId) { + return request({ + url: '/monitor/online/' + tokenId, + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/monitor/operlog.js b/jsowell-ui/src/api/monitor/operlog.js new file mode 100644 index 000000000..a04bca840 --- /dev/null +++ b/jsowell-ui/src/api/monitor/operlog.js @@ -0,0 +1,26 @@ +import request from '@/utils/request' + +// 鏌ヨ鎿嶄綔鏃ュ織鍒楄〃 +export function list(query) { + return request({ + url: '/monitor/operlog/list', + method: 'get', + params: query + }) +} + +// 鍒犻櫎鎿嶄綔鏃ュ織 +export function delOperlog(operId) { + return request({ + url: '/monitor/operlog/' + operId, + method: 'delete' + }) +} + +// 娓呯┖鎿嶄綔鏃ュ織 +export function cleanOperlog() { + return request({ + url: '/monitor/operlog/clean', + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/monitor/server.js b/jsowell-ui/src/api/monitor/server.js new file mode 100644 index 000000000..e1f9ca214 --- /dev/null +++ b/jsowell-ui/src/api/monitor/server.js @@ -0,0 +1,9 @@ +import request from '@/utils/request' + +// 鑾峰彇鏈嶅姟淇℃伅 +export function getServer() { + return request({ + url: '/monitor/server', + method: 'get' + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/order/abnormalRecord.js b/jsowell-ui/src/api/order/abnormalRecord.js new file mode 100644 index 000000000..52ca7d242 --- /dev/null +++ b/jsowell-ui/src/api/order/abnormalRecord.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 鏌ヨ璁㈠崟寮傚父璁板綍鍒楄〃 +export function listAbnormalRecord(query) { + return request({ + url: '/order/abnormalRecord/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ璁㈠崟寮傚父璁板綍璇︾粏 +export function getAbnormalRecord(id) { + return request({ + url: '/order/abnormalRecord/' + id, + method: 'get' + }) +} + +// 鏂板璁㈠崟寮傚父璁板綍 +export function addAbnormalRecord(data) { + return request({ + url: '/order/abnormalRecord', + method: 'post', + data: data + }) +} + +// 淇敼璁㈠崟寮傚父璁板綍 +export function updateAbnormalRecord(data) { + return request({ + url: '/order/abnormalRecord', + method: 'put', + data: data + }) +} + +// 鍒犻櫎璁㈠崟寮傚父璁板綍 +export function delAbnormalRecord(id) { + return request({ + url: '/order/abnormalRecord/' + id, + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/order/order.js b/jsowell-ui/src/api/order/order.js new file mode 100644 index 000000000..47a4c1412 --- /dev/null +++ b/jsowell-ui/src/api/order/order.js @@ -0,0 +1,53 @@ +import request from '@/utils/request' + +// 鏌ヨ璁㈠崟鍒楄〃 +export function listOrder(query) { + return request({ + url: '/order/order/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ璁㈠崟璇︾粏 +export function getOrder(orderCode) { + return request({ + url: '/order/orderDetail/' + orderCode, + method: 'get' + }) +} + +// 鏂板璁㈠崟 +export function addOrder(data) { + return request({ + url: '/order/order', + method: 'post', + data: data + }) +} + +// 淇敼璁㈠崟 +export function updateOrder(data) { + return request({ + url: '/order/order', + method: 'put', + data: data + }) +} + +// 鍒犻櫎璁㈠崟 +export function delOrder(id) { + return request({ + url: '/order/order/' + id, + method: 'delete' + }) +} + +// 鑾峰彇璁㈠崟鎬婚噾棰 +export function totalData(query) { + return request({ + url: '/order/order/totalData', + method: 'get', + params: query + }) +} diff --git a/jsowell-ui/src/api/pile/basic.js b/jsowell-ui/src/api/pile/basic.js new file mode 100644 index 000000000..329dbe311 --- /dev/null +++ b/jsowell-ui/src/api/pile/basic.js @@ -0,0 +1,88 @@ +import request from '@/utils/request' + +// 鏌ヨ璁惧绠$悊鍒楄〃 +export function listBasic(query) { + return request({ + url: '/pile/basic/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ璁惧绠$悊璇︾粏 +export function getBasic(id) { + return request({ + url: '/pile/basic/' + id, + method: 'get' + }) +} + +// 鏂板璁惧绠$悊 +export function addBasic(data) { + return request({ + url: '/pile/basic', + method: 'post', + data: data + }) +} + +export function batchAddBasic(data) { + console.log("鎵归噺鏂板鎺ュ彛", data); + return request({ + url: '/pile/basic/batchAdd', + method: 'post', + data: data + }) +} + +// 淇敼璁惧绠$悊 +export function updateBasic(data) { + return request({ + url: '/pile/basic', + method: 'put', + data: data + }) +} + +// 鍒犻櫎璁惧绠$悊 +export function delBasic(id) { + return request({ + url: '/pile/basic/' + id, + method: 'delete' + }) +} + +// 鏌ヨ璁惧绠$悊璇︾粏 +export function getPileDetailById(data) { + return request({ + url: '/pile/basic/getPileDetailById', + method: 'post', + data: data + }) +} + +// 閫氳繃鍏呯數绔檌d鏌ヨ鎵鏈夊厖鐢垫々鍒楄〃 +export function queryPileListByStationId(stationId) { + return request({ + url: '/pile/basic/queryPileListByStationId/' + stationId, + method: 'get' + }) +} + +// 鎵归噺鏇存柊鍏呯數妗 +export function batchUpdatePileList(data) { + return request({ + url: '/pile/basic/batchUpdatePileList', + method: 'post', + data: data + }) +} + +// 鏌ヨ鍏呯數妗╅氳鏃ュ織 +export function getPileFeedList(data) { + return request({ + url: '/pile/basic/getPileFeedList', + method: 'post', + data: data + }) +} diff --git a/jsowell-ui/src/api/pile/connector.js b/jsowell-ui/src/api/pile/connector.js new file mode 100644 index 000000000..f8fa22a59 --- /dev/null +++ b/jsowell-ui/src/api/pile/connector.js @@ -0,0 +1,54 @@ +import request from '@/utils/request' + +// 鏌ヨ鍏呯數妗╂灙鍙d俊鎭垪琛 +export function listConnector(query) { + return request({ + url: '/pile/connector/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ鍏呯數妗╂灙鍙d俊鎭缁 +export function getConnector(id) { + return request({ + url: '/pile/connector/' + id, + method: 'get' + }) +} + +// 鏂板鍏呯數妗╂灙鍙d俊鎭 +export function addConnector(data) { + return request({ + url: '/pile/connector', + method: 'post', + data: data + }) +} + +// 淇敼鍏呯數妗╂灙鍙d俊鎭 +export function updateConnector(data) { + return request({ + url: '/pile/connector', + method: 'put', + data: data + }) +} + +// 鍒犻櫎鍏呯數妗╂灙鍙d俊鎭 +export function delConnector(id) { + return request({ + url: '/pile/connector/' + id, + method: 'delete' + }) +} + +// 閫氳繃鍏ュ弬鏌ヨ鎺ュ彛鍒楄〃 +export function queryConnectorListByParams(data) { + console.log("閫氳繃鍏ュ弬鏌ヨ鎺ュ彛鍒楄〃", data); + return request({ + url: '/pile/connector/getConnectorInfoListByParams', + method: 'post', + data: data + }) +} diff --git a/jsowell-ui/src/api/pile/merchant.js b/jsowell-ui/src/api/pile/merchant.js new file mode 100644 index 000000000..90e08fa33 --- /dev/null +++ b/jsowell-ui/src/api/pile/merchant.js @@ -0,0 +1,53 @@ +import request from '@/utils/request' + +// 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅鍒楄〃 +export function listMerchant(query) { + return request({ + url: '/pile/merchant/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ鍏呯數妗╄繍钀ュ晢淇℃伅璇︾粏 +export function getMerchant(id) { + return request({ + url: '/pile/merchant/' + id, + method: 'get' + }) +} + +// 鏂板鍏呯數妗╄繍钀ュ晢淇℃伅 +export function addMerchant(data) { + return request({ + url: '/pile/merchant', + method: 'post', + data: data + }) +} + +// 淇敼鍏呯數妗╄繍钀ュ晢淇℃伅 +export function updateMerchant(data) { + return request({ + url: '/pile/merchant', + method: 'put', + data: data + }) +} + +// 鍒犻櫎鍏呯數妗╄繍钀ュ晢淇℃伅 +export function delMerchant(id) { + return request({ + url: '/pile/merchant/' + id, + method: 'delete' + }) +} + +// 鑾峰彇杩愯惀鍟嗗垪琛 涓嶅垎椤 +export function getMerchantList(query) { + return request({ + url: '/pile/merchant/getMerchantList', + method: 'get', + params: query + }) +} diff --git a/jsowell-ui/src/api/pile/model.js b/jsowell-ui/src/api/pile/model.js new file mode 100644 index 000000000..673321734 --- /dev/null +++ b/jsowell-ui/src/api/pile/model.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭垪琛 +export function listModel(query) { + return request({ + url: '/pile/model/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ鍏呯數妗╁瀷鍙蜂俊鎭缁 +export function getModel(id) { + return request({ + url: '/pile/model/' + id, + method: 'get' + }) +} + +// 鏂板鍏呯數妗╁瀷鍙蜂俊鎭 +export function addModel(data) { + return request({ + url: '/pile/model', + method: 'post', + data: data + }) +} + +// 淇敼鍏呯數妗╁瀷鍙蜂俊鎭 +export function updateModel(data) { + return request({ + url: '/pile/model', + method: 'put', + data: data + }) +} + +// 鍒犻櫎鍏呯數妗╁瀷鍙蜂俊鎭 +export function delModel(id) { + return request({ + url: '/pile/model/' + id, + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/pile/sim.js b/jsowell-ui/src/api/pile/sim.js new file mode 100644 index 000000000..79194c565 --- /dev/null +++ b/jsowell-ui/src/api/pile/sim.js @@ -0,0 +1,61 @@ +import request from '@/utils/request' + +// 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭垪琛 +export function listSim(query) { + return request({ + url: '/pile/sim/list', + method: 'get', + params: query + }) +} + +// 鍚庣鏌ヨ鍏呯數妗㏒IM鍗′俊鎭垪琛 +export function getSimInfo(data) { + return request({ + url: '/pile/sim/getSimInfo', + method: 'post', + params: data + }) +} + +// 鏌ヨ鍏呯數妗㏒IM鍗′俊鎭缁 +export function getSim(id) { + return request({ + url: '/pile/sim/' + id, + method: 'get' + }) +} + +// 鏂板鍏呯數妗㏒IM鍗′俊鎭 +export function addSim(data) { + return request({ + url: '/pile/sim', + method: 'post', + data: data + }) +} + +// 淇敼鍏呯數妗㏒IM鍗′俊鎭 +export function updateSim(data) { + return request({ + url: '/pile/sim', + method: 'put', + data: data + }) +} + +// 鍒犻櫎鍏呯數妗㏒IM鍗′俊鎭 +export function delSim(id) { + return request({ + url: '/pile/sim/' + id, + method: 'delete' + }) +} + +export function simRenew(data) { + return request({ + url: '/pile/sim/simRenew', + method: 'post', + data: data + }) +} diff --git a/jsowell-ui/src/api/pile/station.js b/jsowell-ui/src/api/pile/station.js new file mode 100644 index 000000000..17bde61bf --- /dev/null +++ b/jsowell-ui/src/api/pile/station.js @@ -0,0 +1,74 @@ +import request from "@/utils/request"; +import {parseTime} from "@/utils/common"; + +// 鏌ヨ鍏呯數绔欎俊鎭垪琛 +export function listStation(query) { + return request({ + url: "/pile/station/list", + method: "get", + params: query, + }); +} + +// 鏌ヨ鍏呯數绔欎俊鎭缁 +export function getStation(id) { + return request({ + url: "/pile/station/" + id, + method: "get", + }); +} + +// 鏌ヨ鍏呯數绔欎俊鎭缁 +export function getStationInfo(stationId) { + return request({ + url: "/pile/station/getStationInfo/" + stationId, + method: "get", + }); +} + +// 鏍规嵁杩愯惀鍟唅d 鏌ヨ鍏呯數绔欏垪琛 +export function getStationListByMerchantId(merchantId) { + return request({ + url: "/pile/station/selectStationListByMerchantId", + method: "post", + data: { + merchantId: merchantId, + }, + }); +} + +// 鏂板鍏呯數绔欎俊鎭 +export function addStation(data) { + return request({ + url: "/pile/station", + method: "post", + data: data, + }); +} + +// 淇敼鍏呯數绔欎俊鎭 +export function updateStation(data) { + console.log("淇敼鍏呯數绔欎俊鎭痙ata", data) + return request({ + url: "/pile/station", + method: "put", + data: data, + }); +} + +// 鍒犻櫎鍏呯數绔欎俊鎭 +export function delStation(id) { + return request({ + url: "/pile/station/" + id, + method: "delete", + }); +} + +// 蹇熷缓绔欐帴鍙 +export function fastCreateStation(data) { + return request({ + url: "/pile/station/fastCreateStation", + method: "post", + data: data, + }); +} diff --git a/jsowell-ui/src/api/system/config.js b/jsowell-ui/src/api/system/config.js new file mode 100644 index 000000000..a404d8254 --- /dev/null +++ b/jsowell-ui/src/api/system/config.js @@ -0,0 +1,60 @@ +import request from '@/utils/request' + +// 鏌ヨ鍙傛暟鍒楄〃 +export function listConfig(query) { + return request({ + url: '/system/config/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ鍙傛暟璇︾粏 +export function getConfig(configId) { + return request({ + url: '/system/config/' + configId, + method: 'get' + }) +} + +// 鏍规嵁鍙傛暟閿悕鏌ヨ鍙傛暟鍊 +export function getConfigKey(configKey) { + return request({ + url: '/system/config/configKey/' + configKey, + method: 'get' + }) +} + +// 鏂板鍙傛暟閰嶇疆 +export function addConfig(data) { + return request({ + url: '/system/config', + method: 'post', + data: data + }) +} + +// 淇敼鍙傛暟閰嶇疆 +export function updateConfig(data) { + return request({ + url: '/system/config', + method: 'put', + data: data + }) +} + +// 鍒犻櫎鍙傛暟閰嶇疆 +export function delConfig(configId) { + return request({ + url: '/system/config/' + configId, + method: 'delete' + }) +} + +// 鍒锋柊鍙傛暟缂撳瓨 +export function refreshCache() { + return request({ + url: '/system/config/refreshCache', + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/system/dept.js b/jsowell-ui/src/api/system/dept.js new file mode 100644 index 000000000..2804676ff --- /dev/null +++ b/jsowell-ui/src/api/system/dept.js @@ -0,0 +1,68 @@ +import request from '@/utils/request' + +// 鏌ヨ閮ㄩ棬鍒楄〃 +export function listDept(query) { + return request({ + url: '/system/dept/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ閮ㄩ棬鍒楄〃锛堟帓闄よ妭鐐癸級 +export function listDeptExcludeChild(deptId) { + return request({ + url: '/system/dept/list/exclude/' + deptId, + method: 'get' + }) +} + +// 鏌ヨ閮ㄩ棬璇︾粏 +export function getDept(deptId) { + return request({ + url: '/system/dept/' + deptId, + method: 'get' + }) +} + +// 鏌ヨ閮ㄩ棬涓嬫媺鏍戠粨鏋 +export function treeselect() { + return request({ + url: '/system/dept/treeselect', + method: 'get' + }) +} + +// 鏍规嵁瑙掕壊ID鏌ヨ閮ㄩ棬鏍戠粨鏋 +export function roleDeptTreeselect(roleId) { + return request({ + url: '/system/dept/roleDeptTreeselect/' + roleId, + method: 'get' + }) +} + +// 鏂板閮ㄩ棬 +export function addDept(data) { + return request({ + url: '/system/dept', + method: 'post', + data: data + }) +} + +// 淇敼閮ㄩ棬 +export function updateDept(data) { + return request({ + url: '/system/dept', + method: 'put', + data: data + }) +} + +// 鍒犻櫎閮ㄩ棬 +export function delDept(deptId) { + return request({ + url: '/system/dept/' + deptId, + method: 'delete' + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/system/dict/data.js b/jsowell-ui/src/api/system/dict/data.js new file mode 100644 index 000000000..6c9eb79b4 --- /dev/null +++ b/jsowell-ui/src/api/system/dict/data.js @@ -0,0 +1,52 @@ +import request from '@/utils/request' + +// 鏌ヨ瀛楀吀鏁版嵁鍒楄〃 +export function listData(query) { + return request({ + url: '/system/dict/data/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ瀛楀吀鏁版嵁璇︾粏 +export function getData(dictCode) { + return request({ + url: '/system/dict/data/' + dictCode, + method: 'get' + }) +} + +// 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁淇℃伅 +export function getDicts(dictType) { + return request({ + url: '/system/dict/data/type/' + dictType, + method: 'get' + }) +} + +// 鏂板瀛楀吀鏁版嵁 +export function addData(data) { + return request({ + url: '/system/dict/data', + method: 'post', + data: data + }) +} + +// 淇敼瀛楀吀鏁版嵁 +export function updateData(data) { + return request({ + url: '/system/dict/data', + method: 'put', + data: data + }) +} + +// 鍒犻櫎瀛楀吀鏁版嵁 +export function delData(dictCode) { + return request({ + url: '/system/dict/data/' + dictCode, + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/system/dict/type.js b/jsowell-ui/src/api/system/dict/type.js new file mode 100644 index 000000000..a7a6e01fc --- /dev/null +++ b/jsowell-ui/src/api/system/dict/type.js @@ -0,0 +1,60 @@ +import request from '@/utils/request' + +// 鏌ヨ瀛楀吀绫诲瀷鍒楄〃 +export function listType(query) { + return request({ + url: '/system/dict/type/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ瀛楀吀绫诲瀷璇︾粏 +export function getType(dictId) { + return request({ + url: '/system/dict/type/' + dictId, + method: 'get' + }) +} + +// 鏂板瀛楀吀绫诲瀷 +export function addType(data) { + return request({ + url: '/system/dict/type', + method: 'post', + data: data + }) +} + +// 淇敼瀛楀吀绫诲瀷 +export function updateType(data) { + return request({ + url: '/system/dict/type', + method: 'put', + data: data + }) +} + +// 鍒犻櫎瀛楀吀绫诲瀷 +export function delType(dictId) { + return request({ + url: '/system/dict/type/' + dictId, + method: 'delete' + }) +} + +// 鍒锋柊瀛楀吀缂撳瓨 +export function refreshCache() { + return request({ + url: '/system/dict/type/refreshCache', + method: 'delete' + }) +} + +// 鑾峰彇瀛楀吀閫夋嫨妗嗗垪琛 +export function optionselect() { + return request({ + url: '/system/dict/type/optionselect', + method: 'get' + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/system/menu.js b/jsowell-ui/src/api/system/menu.js new file mode 100644 index 000000000..f6415c656 --- /dev/null +++ b/jsowell-ui/src/api/system/menu.js @@ -0,0 +1,60 @@ +import request from '@/utils/request' + +// 鏌ヨ鑿滃崟鍒楄〃 +export function listMenu(query) { + return request({ + url: '/system/menu/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ鑿滃崟璇︾粏 +export function getMenu(menuId) { + return request({ + url: '/system/menu/' + menuId, + method: 'get' + }) +} + +// 鏌ヨ鑿滃崟涓嬫媺鏍戠粨鏋 +export function treeselect() { + return request({ + url: '/system/menu/treeselect', + method: 'get' + }) +} + +// 鏍规嵁瑙掕壊ID鏌ヨ鑿滃崟涓嬫媺鏍戠粨鏋 +export function roleMenuTreeselect(roleId) { + return request({ + url: '/system/menu/roleMenuTreeselect/' + roleId, + method: 'get' + }) +} + +// 鏂板鑿滃崟 +export function addMenu(data) { + return request({ + url: '/system/menu', + method: 'post', + data: data + }) +} + +// 淇敼鑿滃崟 +export function updateMenu(data) { + return request({ + url: '/system/menu', + method: 'put', + data: data + }) +} + +// 鍒犻櫎鑿滃崟 +export function delMenu(menuId) { + return request({ + url: '/system/menu/' + menuId, + method: 'delete' + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/system/notice.js b/jsowell-ui/src/api/system/notice.js new file mode 100644 index 000000000..c274ea5ba --- /dev/null +++ b/jsowell-ui/src/api/system/notice.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 鏌ヨ鍏憡鍒楄〃 +export function listNotice(query) { + return request({ + url: '/system/notice/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ鍏憡璇︾粏 +export function getNotice(noticeId) { + return request({ + url: '/system/notice/' + noticeId, + method: 'get' + }) +} + +// 鏂板鍏憡 +export function addNotice(data) { + return request({ + url: '/system/notice', + method: 'post', + data: data + }) +} + +// 淇敼鍏憡 +export function updateNotice(data) { + return request({ + url: '/system/notice', + method: 'put', + data: data + }) +} + +// 鍒犻櫎鍏憡 +export function delNotice(noticeId) { + return request({ + url: '/system/notice/' + noticeId, + method: 'delete' + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/system/post.js b/jsowell-ui/src/api/system/post.js new file mode 100644 index 000000000..1a8e9ca04 --- /dev/null +++ b/jsowell-ui/src/api/system/post.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 鏌ヨ宀椾綅鍒楄〃 +export function listPost(query) { + return request({ + url: '/system/post/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ宀椾綅璇︾粏 +export function getPost(postId) { + return request({ + url: '/system/post/' + postId, + method: 'get' + }) +} + +// 鏂板宀椾綅 +export function addPost(data) { + return request({ + url: '/system/post', + method: 'post', + data: data + }) +} + +// 淇敼宀椾綅 +export function updatePost(data) { + return request({ + url: '/system/post', + method: 'put', + data: data + }) +} + +// 鍒犻櫎宀椾綅 +export function delPost(postId) { + return request({ + url: '/system/post/' + postId, + method: 'delete' + }) +} diff --git a/jsowell-ui/src/api/system/role.js b/jsowell-ui/src/api/system/role.js new file mode 100644 index 000000000..4b455e130 --- /dev/null +++ b/jsowell-ui/src/api/system/role.js @@ -0,0 +1,111 @@ +import request from '@/utils/request' + +// 鏌ヨ瑙掕壊鍒楄〃 +export function listRole(query) { + return request({ + url: '/system/role/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ瑙掕壊璇︾粏 +export function getRole(roleId) { + return request({ + url: '/system/role/' + roleId, + method: 'get' + }) +} + +// 鏂板瑙掕壊 +export function addRole(data) { + return request({ + url: '/system/role', + method: 'post', + data: data + }) +} + +// 淇敼瑙掕壊 +export function updateRole(data) { + return request({ + url: '/system/role', + method: 'put', + data: data + }) +} + +// 瑙掕壊鏁版嵁鏉冮檺 +export function dataScope(data) { + return request({ + url: '/system/role/dataScope', + method: 'put', + data: data + }) +} + +// 瑙掕壊鐘舵佷慨鏀 +export function changeRoleStatus(roleId, status) { + const data = { + roleId, + status + } + return request({ + url: '/system/role/changeStatus', + method: 'put', + data: data + }) +} + +// 鍒犻櫎瑙掕壊 +export function delRole(roleId) { + return request({ + url: '/system/role/' + roleId, + method: 'delete' + }) +} + +// 鏌ヨ瑙掕壊宸叉巿鏉冪敤鎴峰垪琛 +export function allocatedUserList(query) { + return request({ + url: '/system/role/authUser/allocatedList', + method: 'get', + params: query + }) +} + +// 鏌ヨ瑙掕壊鏈巿鏉冪敤鎴峰垪琛 +export function unallocatedUserList(query) { + return request({ + url: '/system/role/authUser/unallocatedList', + method: 'get', + params: query + }) +} + +// 鍙栨秷鐢ㄦ埛鎺堟潈瑙掕壊 +export function authUserCancel(data) { + return request({ + url: '/system/role/authUser/cancel', + method: 'put', + data: data + }) +} + +// 鎵归噺鍙栨秷鐢ㄦ埛鎺堟潈瑙掕壊 +export function authUserCancelAll(data) { + return request({ + url: '/system/role/authUser/cancelAll', + method: 'put', + params: data + }) +} + +// 鎺堟潈鐢ㄦ埛閫夋嫨 +export function authUserSelectAll(data) { + return request({ + url: '/system/role/authUser/selectAll', + method: 'put', + params: data + }) +} \ No newline at end of file diff --git a/jsowell-ui/src/api/system/user.js b/jsowell-ui/src/api/system/user.js new file mode 100644 index 000000000..08c317f6b --- /dev/null +++ b/jsowell-ui/src/api/system/user.js @@ -0,0 +1,127 @@ +import request from '@/utils/request' +import { parseStrEmpty } from "@/utils/common"; + +// 鏌ヨ鐢ㄦ埛鍒楄〃 +export function listUser(query) { + return request({ + url: '/system/user/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ鐢ㄦ埛璇︾粏 +export function getUser(userId) { + return request({ + url: '/system/user/' + parseStrEmpty(userId), + method: 'get' + }) +} + +// 鏂板鐢ㄦ埛 +export function addUser(data) { + return request({ + url: '/system/user', + method: 'post', + data: data + }) +} + +// 淇敼鐢ㄦ埛 +export function updateUser(data) { + return request({ + url: '/system/user', + method: 'put', + data: data + }) +} + +// 鍒犻櫎鐢ㄦ埛 +export function delUser(userId) { + return request({ + url: '/system/user/' + userId, + method: 'delete' + }) +} + +// 鐢ㄦ埛瀵嗙爜閲嶇疆 +export function resetUserPwd(userId, password) { + const data = { + userId, + password + } + return request({ + url: '/system/user/resetPwd', + method: 'put', + data: data + }) +} + +// 鐢ㄦ埛鐘舵佷慨鏀 +export function changeUserStatus(userId, status) { + const data = { + userId, + status + } + return request({ + url: '/system/user/changeStatus', + method: 'put', + data: data + }) +} + +// 鏌ヨ鐢ㄦ埛涓汉淇℃伅 +export function getUserProfile() { + return request({ + url: '/system/user/profile', + method: 'get' + }) +} + +// 淇敼鐢ㄦ埛涓汉淇℃伅 +export function updateUserProfile(data) { + return request({ + url: '/system/user/profile', + method: 'put', + data: data + }) +} + +// 鐢ㄦ埛瀵嗙爜閲嶇疆 +export function updateUserPwd(oldPassword, newPassword) { + const data = { + oldPassword, + newPassword + } + return request({ + url: '/system/user/profile/updatePwd', + method: 'put', + params: data + }) +} + +// 鐢ㄦ埛澶村儚涓婁紶 +export function uploadAvatar(data) { + return request({ + url: '/system/user/profile/avatar', + method: 'post', + data: data + }) +} + +// 鏌ヨ鎺堟潈瑙掕壊 +export function getAuthRole(userId) { + return request({ + url: '/system/user/authRole/' + userId, + method: 'get' + }) +} + +// 淇濆瓨鎺堟潈瑙掕壊 +export function updateAuthRole(data) { + return request({ + url: '/system/user/authRole', + method: 'put', + params: data + }) +} diff --git a/jsowell-ui/src/api/tool/gen.js b/jsowell-ui/src/api/tool/gen.js new file mode 100644 index 000000000..45069278f --- /dev/null +++ b/jsowell-ui/src/api/tool/gen.js @@ -0,0 +1,76 @@ +import request from '@/utils/request' + +// 鏌ヨ鐢熸垚琛ㄦ暟鎹 +export function listTable(query) { + return request({ + url: '/tool/gen/list', + method: 'get', + params: query + }) +} +// 鏌ヨdb鏁版嵁搴撳垪琛 +export function listDbTable(query) { + return request({ + url: '/tool/gen/db/list', + method: 'get', + params: query + }) +} + +// 鏌ヨ琛ㄨ缁嗕俊鎭 +export function getGenTable(tableId) { + return request({ + url: '/tool/gen/' + tableId, + method: 'get' + }) +} + +// 淇敼浠g爜鐢熸垚淇℃伅 +export function updateGenTable(data) { + return request({ + url: '/tool/gen', + method: 'put', + data: data + }) +} + +// 瀵煎叆琛 +export function importTable(data) { + return request({ + url: '/tool/gen/importTable', + method: 'post', + params: data + }) +} + +// 棰勮鐢熸垚浠g爜 +export function previewTable(tableId) { + return request({ + url: '/tool/gen/preview/' + tableId, + method: 'get' + }) +} + +// 鍒犻櫎琛ㄦ暟鎹 +export function delTable(tableId) { + return request({ + url: '/tool/gen/' + tableId, + method: 'delete' + }) +} + +// 鐢熸垚浠g爜锛堣嚜瀹氫箟璺緞锛 +export function genCode(tableName) { + return request({ + url: '/tool/gen/genCode/' + tableName, + method: 'get' + }) +} + +// 鍚屾鏁版嵁搴 +export function synchDb(tableName) { + return request({ + url: '/tool/gen/synchDb/' + tableName, + method: 'get' + }) +} diff --git a/jsowell-ui/src/assets/401_images/401.gif b/jsowell-ui/src/assets/401_images/401.gif new file mode 100644 index 000000000..cd6e0d943 Binary files /dev/null and b/jsowell-ui/src/assets/401_images/401.gif differ diff --git a/jsowell-ui/src/assets/404_images/404.png b/jsowell-ui/src/assets/404_images/404.png new file mode 100644 index 000000000..3d8e2305c Binary files /dev/null and b/jsowell-ui/src/assets/404_images/404.png differ diff --git a/jsowell-ui/src/assets/404_images/404_cloud.png b/jsowell-ui/src/assets/404_images/404_cloud.png new file mode 100644 index 000000000..c6281d090 Binary files /dev/null and b/jsowell-ui/src/assets/404_images/404_cloud.png differ diff --git a/jsowell-ui/src/assets/icons/index.js b/jsowell-ui/src/assets/icons/index.js new file mode 100644 index 000000000..2c6b309c9 --- /dev/null +++ b/jsowell-ui/src/assets/icons/index.js @@ -0,0 +1,9 @@ +import Vue from 'vue' +import SvgIcon from '@/components/SvgIcon'// svg component + +// register globally +Vue.component('svg-icon', SvgIcon) + +const req = require.context('./svg', false, /\.svg$/) +const requireAll = requireContext => requireContext.keys().map(requireContext) +requireAll(req) diff --git a/jsowell-ui/src/assets/icons/svg/404.svg b/jsowell-ui/src/assets/icons/svg/404.svg new file mode 100644 index 000000000..6df50190a --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/404.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/bug.svg b/jsowell-ui/src/assets/icons/svg/bug.svg new file mode 100644 index 000000000..d45ff4fd1 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/bug.svg @@ -0,0 +1,15 @@ + + + + + diff --git a/jsowell-ui/src/assets/icons/svg/build.svg b/jsowell-ui/src/assets/icons/svg/build.svg new file mode 100644 index 000000000..97c468863 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/build.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/button.svg b/jsowell-ui/src/assets/icons/svg/button.svg new file mode 100644 index 000000000..904fddc85 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/button.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/cascader.svg b/jsowell-ui/src/assets/icons/svg/cascader.svg new file mode 100644 index 000000000..e256024f9 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/cascader.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/chargeandpark.svg b/jsowell-ui/src/assets/icons/svg/chargeandpark.svg new file mode 100644 index 000000000..5ffc6eb34 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/chargeandpark.svg @@ -0,0 +1,16 @@ + + + + + + diff --git a/jsowell-ui/src/assets/icons/svg/chargingstation.svg b/jsowell-ui/src/assets/icons/svg/chargingstation.svg new file mode 100644 index 000000000..914cfce52 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/chargingstation.svg @@ -0,0 +1,36 @@ + + + + + + diff --git a/jsowell-ui/src/assets/icons/svg/chart.svg b/jsowell-ui/src/assets/icons/svg/chart.svg new file mode 100644 index 000000000..27728fb0b --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/chart.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/checkbox.svg b/jsowell-ui/src/assets/icons/svg/checkbox.svg new file mode 100644 index 000000000..013fd3a27 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/checkbox.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/clipboard.svg b/jsowell-ui/src/assets/icons/svg/clipboard.svg new file mode 100644 index 000000000..90923ff62 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/clipboard.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/code.svg b/jsowell-ui/src/assets/icons/svg/code.svg new file mode 100644 index 000000000..ed4d23cf4 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/code.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/color.svg b/jsowell-ui/src/assets/icons/svg/color.svg new file mode 100644 index 000000000..44a81aab1 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/color.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/component.svg b/jsowell-ui/src/assets/icons/svg/component.svg new file mode 100644 index 000000000..29c345809 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/component.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/dashboard.svg b/jsowell-ui/src/assets/icons/svg/dashboard.svg new file mode 100644 index 000000000..5317d3702 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/dashboard.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/date-range.svg b/jsowell-ui/src/assets/icons/svg/date-range.svg new file mode 100644 index 000000000..fda571e70 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/date-range.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/date.svg b/jsowell-ui/src/assets/icons/svg/date.svg new file mode 100644 index 000000000..52dc73eec --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/date.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/dict.svg b/jsowell-ui/src/assets/icons/svg/dict.svg new file mode 100644 index 000000000..484937730 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/dict.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/documentation.svg b/jsowell-ui/src/assets/icons/svg/documentation.svg new file mode 100644 index 000000000..704312289 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/documentation.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/download.svg b/jsowell-ui/src/assets/icons/svg/download.svg new file mode 100644 index 000000000..c89695134 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/download.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/drag.svg b/jsowell-ui/src/assets/icons/svg/drag.svg new file mode 100644 index 000000000..4185d3cee --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/drag.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/druid.svg b/jsowell-ui/src/assets/icons/svg/druid.svg new file mode 100644 index 000000000..a2b4b4ed2 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/druid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/edit.svg b/jsowell-ui/src/assets/icons/svg/edit.svg new file mode 100644 index 000000000..d26101f29 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/edit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/education.svg b/jsowell-ui/src/assets/icons/svg/education.svg new file mode 100644 index 000000000..7bfb01d18 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/education.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/electric.svg b/jsowell-ui/src/assets/icons/svg/electric.svg new file mode 100644 index 000000000..7dc874c08 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/electric.svg @@ -0,0 +1,33 @@ + + + + + + diff --git a/jsowell-ui/src/assets/icons/svg/email.svg b/jsowell-ui/src/assets/icons/svg/email.svg new file mode 100644 index 000000000..74d25e21a --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/email.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/example.svg b/jsowell-ui/src/assets/icons/svg/example.svg new file mode 100644 index 000000000..46f42b532 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/example.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/excel.svg b/jsowell-ui/src/assets/icons/svg/excel.svg new file mode 100644 index 000000000..74d97b802 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/excel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/exit-fullscreen.svg b/jsowell-ui/src/assets/icons/svg/exit-fullscreen.svg new file mode 100644 index 000000000..485c128b6 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/exit-fullscreen.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/eye-open.svg b/jsowell-ui/src/assets/icons/svg/eye-open.svg new file mode 100644 index 000000000..88dcc98e6 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/eye-open.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/eye.svg b/jsowell-ui/src/assets/icons/svg/eye.svg new file mode 100644 index 000000000..16ed2d872 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/eye.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/form.svg b/jsowell-ui/src/assets/icons/svg/form.svg new file mode 100644 index 000000000..dcbaa185a --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/form.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/fullscreen.svg b/jsowell-ui/src/assets/icons/svg/fullscreen.svg new file mode 100644 index 000000000..0e86b6fa8 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/fullscreen.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/github.svg b/jsowell-ui/src/assets/icons/svg/github.svg new file mode 100644 index 000000000..db0a0d430 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/github.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/guide.svg b/jsowell-ui/src/assets/icons/svg/guide.svg new file mode 100644 index 000000000..b27100179 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/guide.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/icon.svg b/jsowell-ui/src/assets/icons/svg/icon.svg new file mode 100644 index 000000000..82be8eeed --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/icons8-bookmark.svg b/jsowell-ui/src/assets/icons/svg/icons8-bookmark.svg new file mode 100644 index 000000000..33c291cf9 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/icons8-bookmark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/input.svg b/jsowell-ui/src/assets/icons/svg/input.svg new file mode 100644 index 000000000..ab91381e6 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/input.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/international.svg b/jsowell-ui/src/assets/icons/svg/international.svg new file mode 100644 index 000000000..e9b56eee2 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/international.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/job.svg b/jsowell-ui/src/assets/icons/svg/job.svg new file mode 100644 index 000000000..2a93a2519 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/job.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/language.svg b/jsowell-ui/src/assets/icons/svg/language.svg new file mode 100644 index 000000000..0082b577a --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/language.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/link.svg b/jsowell-ui/src/assets/icons/svg/link.svg new file mode 100644 index 000000000..48197ba4d --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/link.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/list.svg b/jsowell-ui/src/assets/icons/svg/list.svg new file mode 100644 index 000000000..20259eddb --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/list.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/lock.svg b/jsowell-ui/src/assets/icons/svg/lock.svg new file mode 100644 index 000000000..74fee543d --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/lock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/log.svg b/jsowell-ui/src/assets/icons/svg/log.svg new file mode 100644 index 000000000..d879d33b6 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/log.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/logininfor.svg b/jsowell-ui/src/assets/icons/svg/logininfor.svg new file mode 100644 index 000000000..267f84474 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/logininfor.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/merchant.svg b/jsowell-ui/src/assets/icons/svg/merchant.svg new file mode 100644 index 000000000..fe6ef90e6 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/merchant.svg @@ -0,0 +1,23 @@ + + + + + + diff --git a/jsowell-ui/src/assets/icons/svg/message.svg b/jsowell-ui/src/assets/icons/svg/message.svg new file mode 100644 index 000000000..14ca81728 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/message.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/money.svg b/jsowell-ui/src/assets/icons/svg/money.svg new file mode 100644 index 000000000..c1580de10 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/money.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/monitor.svg b/jsowell-ui/src/assets/icons/svg/monitor.svg new file mode 100644 index 000000000..bc308cb0f --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/monitor.svg @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/nested.svg b/jsowell-ui/src/assets/icons/svg/nested.svg new file mode 100644 index 000000000..06713a86c --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/nested.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/number.svg b/jsowell-ui/src/assets/icons/svg/number.svg new file mode 100644 index 000000000..ad5ce9af2 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/number.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/online.svg b/jsowell-ui/src/assets/icons/svg/online.svg new file mode 100644 index 000000000..330a20293 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/online.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/password.svg b/jsowell-ui/src/assets/icons/svg/password.svg new file mode 100644 index 000000000..6c64defe3 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/password.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/pdf.svg b/jsowell-ui/src/assets/icons/svg/pdf.svg new file mode 100644 index 000000000..957aa0cc3 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/pdf.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/people.svg b/jsowell-ui/src/assets/icons/svg/people.svg new file mode 100644 index 000000000..2bd54aeb7 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/people.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/peoples.svg b/jsowell-ui/src/assets/icons/svg/peoples.svg new file mode 100644 index 000000000..aab852e52 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/peoples.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/phone.svg b/jsowell-ui/src/assets/icons/svg/phone.svg new file mode 100644 index 000000000..ab8e8c4e5 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/phone.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/post.svg b/jsowell-ui/src/assets/icons/svg/post.svg new file mode 100644 index 000000000..2922c613b --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/post.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/qq.svg b/jsowell-ui/src/assets/icons/svg/qq.svg new file mode 100644 index 000000000..ee13d4ec2 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/qq.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/question.svg b/jsowell-ui/src/assets/icons/svg/question.svg new file mode 100644 index 000000000..cf75bd4be --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/question.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/radio.svg b/jsowell-ui/src/assets/icons/svg/radio.svg new file mode 100644 index 000000000..0cde34521 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/radio.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/rate.svg b/jsowell-ui/src/assets/icons/svg/rate.svg new file mode 100644 index 000000000..aa3b14d7d --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/rate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/redis-list.svg b/jsowell-ui/src/assets/icons/svg/redis-list.svg new file mode 100644 index 000000000..98a15b2a6 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/redis-list.svg @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/redis.svg b/jsowell-ui/src/assets/icons/svg/redis.svg new file mode 100644 index 000000000..2f1d62dfc --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/redis.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/row.svg b/jsowell-ui/src/assets/icons/svg/row.svg new file mode 100644 index 000000000..078099222 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/row.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/search.svg b/jsowell-ui/src/assets/icons/svg/search.svg new file mode 100644 index 000000000..84233ddaa --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/search.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/select.svg b/jsowell-ui/src/assets/icons/svg/select.svg new file mode 100644 index 000000000..d6283828b --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/select.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/server.svg b/jsowell-ui/src/assets/icons/svg/server.svg new file mode 100644 index 000000000..ca37b001e --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/server.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/shopping.svg b/jsowell-ui/src/assets/icons/svg/shopping.svg new file mode 100644 index 000000000..87513e7c5 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/shopping.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/size.svg b/jsowell-ui/src/assets/icons/svg/size.svg new file mode 100644 index 000000000..ddb25b8d5 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/size.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/skill.svg b/jsowell-ui/src/assets/icons/svg/skill.svg new file mode 100644 index 000000000..a3b731218 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/skill.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/slider.svg b/jsowell-ui/src/assets/icons/svg/slider.svg new file mode 100644 index 000000000..fbe4f39f0 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/slider.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/star.svg b/jsowell-ui/src/assets/icons/svg/star.svg new file mode 100644 index 000000000..6cf86e66a --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/star.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/swagger.svg b/jsowell-ui/src/assets/icons/svg/swagger.svg new file mode 100644 index 000000000..05d4e7bce --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/swagger.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/switch.svg b/jsowell-ui/src/assets/icons/svg/switch.svg new file mode 100644 index 000000000..0ba61e38d --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/switch.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/system.svg b/jsowell-ui/src/assets/icons/svg/system.svg new file mode 100644 index 000000000..dba28cf6f --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/system.svg @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/tab.svg b/jsowell-ui/src/assets/icons/svg/tab.svg new file mode 100644 index 000000000..b4b48e480 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/tab.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/table.svg b/jsowell-ui/src/assets/icons/svg/table.svg new file mode 100644 index 000000000..0e3dc9dea --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/table.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/textarea.svg b/jsowell-ui/src/assets/icons/svg/textarea.svg new file mode 100644 index 000000000..2709f292e --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/textarea.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/theme.svg b/jsowell-ui/src/assets/icons/svg/theme.svg new file mode 100644 index 000000000..5982a2f78 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/theme.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/time-range.svg b/jsowell-ui/src/assets/icons/svg/time-range.svg new file mode 100644 index 000000000..13c1202bd --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/time-range.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/time.svg b/jsowell-ui/src/assets/icons/svg/time.svg new file mode 100644 index 000000000..b376e32a6 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/time.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/tool.svg b/jsowell-ui/src/assets/icons/svg/tool.svg new file mode 100644 index 000000000..c813067ef --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/tool.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/toolsbox.svg b/jsowell-ui/src/assets/icons/svg/toolsbox.svg new file mode 100644 index 000000000..24047858f --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/toolsbox.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/jsowell-ui/src/assets/icons/svg/tree-table.svg b/jsowell-ui/src/assets/icons/svg/tree-table.svg new file mode 100644 index 000000000..8aafdb829 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/tree-table.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/tree.svg b/jsowell-ui/src/assets/icons/svg/tree.svg new file mode 100644 index 000000000..dd4b7dd22 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/tree.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/upload.svg b/jsowell-ui/src/assets/icons/svg/upload.svg new file mode 100644 index 000000000..bae49c0a5 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/upload.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/user.svg b/jsowell-ui/src/assets/icons/svg/user.svg new file mode 100644 index 000000000..0ba0716a6 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/user.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/validCode.svg b/jsowell-ui/src/assets/icons/svg/validCode.svg new file mode 100644 index 000000000..cfb10214c --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/validCode.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/wechat.svg b/jsowell-ui/src/assets/icons/svg/wechat.svg new file mode 100644 index 000000000..c586e5511 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/wechat.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svg/zip.svg b/jsowell-ui/src/assets/icons/svg/zip.svg new file mode 100644 index 000000000..f806fc482 --- /dev/null +++ b/jsowell-ui/src/assets/icons/svg/zip.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/jsowell-ui/src/assets/icons/svgo.yml b/jsowell-ui/src/assets/icons/svgo.yml new file mode 100644 index 000000000..d11906aec --- /dev/null +++ b/jsowell-ui/src/assets/icons/svgo.yml @@ -0,0 +1,22 @@ +# replace default config + +# multipass: true +# full: true + +plugins: + + # - name + # + # or: + # - name: false + # - name: true + # + # or: + # - name: + # param1: 1 + # param2: 2 + +- removeAttrs: + attrs: + - 'fill' + - 'fill-rule' diff --git a/jsowell-ui/src/assets/images/dark.svg b/jsowell-ui/src/assets/images/dark.svg new file mode 100644 index 000000000..f646bd7ea --- /dev/null +++ b/jsowell-ui/src/assets/images/dark.svg @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jsowell-ui/src/assets/images/dingdan.png b/jsowell-ui/src/assets/images/dingdan.png new file mode 100644 index 000000000..f52bfa044 Binary files /dev/null and b/jsowell-ui/src/assets/images/dingdan.png differ diff --git a/jsowell-ui/src/assets/images/light.svg b/jsowell-ui/src/assets/images/light.svg new file mode 100644 index 000000000..ab7cc088f --- /dev/null +++ b/jsowell-ui/src/assets/images/light.svg @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jsowell-ui/src/assets/images/lightning.png b/jsowell-ui/src/assets/images/lightning.png new file mode 100644 index 000000000..7252e48f7 Binary files /dev/null and b/jsowell-ui/src/assets/images/lightning.png differ diff --git a/jsowell-ui/src/assets/images/login-background.jpg b/jsowell-ui/src/assets/images/login-background.jpg new file mode 100644 index 000000000..8a89eb829 Binary files /dev/null and b/jsowell-ui/src/assets/images/login-background.jpg differ diff --git a/jsowell-ui/src/assets/images/profile.jpg b/jsowell-ui/src/assets/images/profile.jpg new file mode 100644 index 000000000..b3a940b21 Binary files /dev/null and b/jsowell-ui/src/assets/images/profile.jpg differ diff --git a/jsowell-ui/src/assets/images/qianbao.png b/jsowell-ui/src/assets/images/qianbao.png new file mode 100644 index 000000000..05c301533 Binary files /dev/null and b/jsowell-ui/src/assets/images/qianbao.png differ diff --git a/jsowell-ui/src/assets/images/shebei.png b/jsowell-ui/src/assets/images/shebei.png new file mode 100644 index 000000000..1f42f20b5 Binary files /dev/null and b/jsowell-ui/src/assets/images/shebei.png differ diff --git a/jsowell-ui/src/assets/images/yue.png b/jsowell-ui/src/assets/images/yue.png new file mode 100644 index 000000000..92921aa44 Binary files /dev/null and b/jsowell-ui/src/assets/images/yue.png differ diff --git a/jsowell-ui/src/assets/images/zongfeiyong.png b/jsowell-ui/src/assets/images/zongfeiyong.png new file mode 100644 index 000000000..f3f5183f1 Binary files /dev/null and b/jsowell-ui/src/assets/images/zongfeiyong.png differ diff --git a/jsowell-ui/src/assets/logo/logo.png b/jsowell-ui/src/assets/logo/logo.png new file mode 100644 index 000000000..8d4e1a3de Binary files /dev/null and b/jsowell-ui/src/assets/logo/logo.png differ diff --git a/jsowell-ui/src/assets/styles/btn.scss b/jsowell-ui/src/assets/styles/btn.scss new file mode 100644 index 000000000..e6ba1a8e1 --- /dev/null +++ b/jsowell-ui/src/assets/styles/btn.scss @@ -0,0 +1,99 @@ +@import './variables.scss'; + +@mixin colorBtn($color) { + background: $color; + + &:hover { + color: $color; + + &:before, + &:after { + background: $color; + } + } +} + +.blue-btn { + @include colorBtn($blue) +} + +.light-blue-btn { + @include colorBtn($light-blue) +} + +.red-btn { + @include colorBtn($red) +} + +.pink-btn { + @include colorBtn($pink) +} + +.green-btn { + @include colorBtn($green) +} + +.tiffany-btn { + @include colorBtn($tiffany) +} + +.yellow-btn { + @include colorBtn($yellow) +} + +.pan-btn { + font-size: 14px; + color: #fff; + padding: 14px 36px; + border-radius: 8px; + border: none; + outline: none; + transition: 600ms ease all; + position: relative; + display: inline-block; + + &:hover { + background: #fff; + + &:before, + &:after { + width: 100%; + transition: 600ms ease all; + } + } + + &:before, + &:after { + content: ''; + position: absolute; + top: 0; + right: 0; + height: 2px; + width: 0; + transition: 400ms ease all; + } + + &::after { + right: inherit; + top: inherit; + left: 0; + bottom: 0; + } +} + +.custom-button { + display: inline-block; + line-height: 1; + white-space: nowrap; + cursor: pointer; + background: #fff; + color: #fff; + -webkit-appearance: none; + text-align: center; + box-sizing: border-box; + outline: 0; + margin: 0; + padding: 10px 15px; + font-size: 14px; + border-radius: 4px; +} diff --git a/jsowell-ui/src/assets/styles/common.css b/jsowell-ui/src/assets/styles/common.css new file mode 100644 index 000000000..b1bd1152e --- /dev/null +++ b/jsowell-ui/src/assets/styles/common.css @@ -0,0 +1,282 @@ +@charset "UTF-8"; +/** + * 閫氱敤css鏍峰紡甯冨眬澶勭悊 + */ +/** 鍩虹閫氱敤 **/ +.pt5 { + padding-top: 5px; +} + +.pr5 { + padding-right: 5px; +} + +.pb5 { + padding-bottom: 5px; +} + +.mt5 { + margin-top: 5px; +} + +.mr5 { + margin-right: 5px; +} + +.mb5 { + margin-bottom: 5px; +} + +.mb8 { + margin-bottom: 8px; +} + +.ml5 { + margin-left: 5px; +} + +.mt10 { + margin-top: 10px; +} + +.mr10 { + margin-right: 10px; +} + +.mb10 { + margin-bottom: 10px; +} + +.ml10 { + margin-left: 10px; +} + +.mt20 { + margin-top: 20px; +} + +.mr20 { + margin-right: 20px; +} + +.mb20 { + margin-bottom: 20px; +} + +.ml20 { + margin-left: 20px; +} + +.h1, .h2, .h3, .h4, .h5, .h6, h1, h2, h3, h4, h5, h6 { + font-family: inherit; + font-weight: 500; + line-height: 1.1; + color: inherit; +} + +.el-dialog:not(.is-fullscreen) { + margin-top: 6vh !important; +} + +.el-dialog__wrapper.scrollbar .el-dialog .el-dialog__body { + overflow: auto; + overflow-x: hidden; + max-height: 70vh; + padding: 10px 20px 0; +} + +.el-table .el-table__header-wrapper th, .el-table .el-table__fixed-header-wrapper th { + word-break: break-word; + background-color: #f8f8f9; + color: #515a6e; + height: 40px; + font-size: 13px; +} + +.el-table .el-table__body-wrapper .el-button [class*="el-icon-"] + span { + margin-left: 1px; +} + +/** 琛ㄥ崟甯冨眬 **/ +.form-header { + font-size: 15px; + color: #6379bb; + border-bottom: 1px solid #ddd; + margin: 8px 10px 25px 10px; + padding-bottom: 5px; +} + +/** 琛ㄦ牸甯冨眬 **/ +.pagination-container { + position: relative; + height: 25px; + margin-bottom: 10px; + margin-top: 15px; + padding: 10px 20px !important; +} + +/* tree border */ +.tree-border { + margin-top: 5px; + border: 1px solid #e5e6e7; + background: #FFFFFF none; + border-radius: 4px; +} + +.pagination-container .el-pagination { + right: 0; + position: absolute; +} + +@media (max-width: 768px) { + .pagination-container .el-pagination > .el-pagination__jump { + display: none !important; + } + .pagination-container .el-pagination > .el-pagination__sizes { + display: none !important; + } +} + +.el-table .fixed-width .el-button--mini { + padding-left: 0; + padding-right: 0; + width: inherit; +} + +/** 琛ㄦ牸鏇村鎿嶄綔涓嬫媺鏍峰紡 */ +.el-table .el-dropdown-link { + cursor: pointer; + color: #409EFF; + margin-left: 5px; +} + +.el-table .el-dropdown, .el-icon-arrow-down { + font-size: 12px; +} + +.el-tree-node__content > .el-checkbox { + margin-right: 8px; +} + +.list-group-striped > .list-group-item { + border-left: 0; + border-right: 0; + border-radius: 0; + padding-left: 0; + padding-right: 0; +} + +.list-group { + padding-left: 0px; + list-style: none; +} + +.list-group-item { + border-bottom: 1px solid #e7eaec; + border-top: 1px solid #e7eaec; + margin-bottom: -1px; + padding: 11px 0px; + font-size: 13px; +} + +.pull-right { + float: right !important; +} + +.el-card__header { + padding: 14px 15px 7px; + min-height: 40px; +} + +.el-card__body { + padding: 0 20px; +} + +.card-box { + padding-right: 15px; + padding-left: 15px; + margin-bottom: 10px; +} + +/* button color */ +.el-button--cyan.is-active, +.el-button--cyan:active { + background: #20B2AA; + border-color: #20B2AA; + color: #FFFFFF; +} + +.el-button--cyan:focus, +.el-button--cyan:hover { + background: #48D1CC; + border-color: #48D1CC; + color: #FFFFFF; +} + +.el-button--cyan { + background-color: #20B2AA; + border-color: #20B2AA; + color: #FFFFFF; +} + +/* text color */ +.text-navy { + color: #1ab394; +} + +.text-primary { + color: inherit; +} + +.text-success { + color: #1c84c6; +} + +.text-info { + color: #23c6c8; +} + +.text-warning { + color: #f8ac59; +} + +.text-danger { + color: #ed5565; +} + +.text-muted { + color: #888888; +} + +/* image */ +.img-circle { + border-radius: 50%; +} + +.img-lg { + width: 120px; + height: 120px; +} + +.avatar-upload-preview { + position: absolute; + top: 50%; + transform: translate(50%, -50%); + width: 200px; + height: 200px; + border-radius: 50%; + box-shadow: 0 0 4px #ccc; + overflow: hidden; +} + +/* 鎷栨嫿鍒楁牱寮 */ +.sortable-ghost { + opacity: .8; + color: #fff !important; + background: #42b983 !important; +} + +.top-right-btn { + position: relative; + float: right; +} diff --git a/jsowell-ui/src/assets/styles/common.min.css b/jsowell-ui/src/assets/styles/common.min.css new file mode 100644 index 000000000..2fb7cb79d --- /dev/null +++ b/jsowell-ui/src/assets/styles/common.min.css @@ -0,0 +1 @@ +.pt5{padding-top:5px}.pr5{padding-right:5px}.pb5{padding-bottom:5px}.mt5{margin-top:5px}.mr5{margin-right:5px}.mb5{margin-bottom:5px}.mb8{margin-bottom:8px}.ml5{margin-left:5px}.mt10{margin-top:10px}.mr10{margin-right:10px}.mb10{margin-bottom:10px}.ml10{margin-left:10px}.mt20{margin-top:20px}.mr20{margin-right:20px}.mb20{margin-bottom:20px}.ml20{margin-left:20px}.h1,.h2,.h3,.h4,.h5,.h6,h1,h2,h3,h4,h5,h6{font-family:inherit;font-weight:500;line-height:1.1;color:inherit}.el-dialog:not(.is-fullscreen){margin-top:6vh !important}.el-dialog__wrapper.scrollbar .el-dialog .el-dialog__body{overflow:auto;overflow-x:hidden;max-height:70vh;padding:10px 20px 0}.el-table .el-table__header-wrapper th,.el-table .el-table__fixed-header-wrapper th{word-break:break-word;background-color:#f8f8f9;color:#515a6e;height:40px;font-size:13px}.el-table .el-table__body-wrapper .el-button [class*="el-icon-"]+span{margin-left:1px}.form-header{font-size:15px;color:#6379bb;border-bottom:1px solid #ddd;margin:8px 10px 25px 10px;padding-bottom:5px}.pagination-container{position:relative;height:25px;margin-bottom:10px;margin-top:15px;padding:10px 20px !important}.tree-border{margin-top:5px;border:1px solid #e5e6e7;background:#FFFFFF none;border-radius:4px}.pagination-container .el-pagination{right:0;position:absolute}@media (max-width: 768px){.pagination-container .el-pagination>.el-pagination__jump{display:none !important}.pagination-container .el-pagination>.el-pagination__sizes{display:none !important}}.el-table .fixed-width .el-button--mini{padding-left:0;padding-right:0;width:inherit}.el-table .el-dropdown-link{cursor:pointer;color:#409EFF;margin-left:5px}.el-table .el-dropdown,.el-icon-arrow-down{font-size:12px}.el-tree-node__content>.el-checkbox{margin-right:8px}.list-group-striped>.list-group-item{border-left:0;border-right:0;border-radius:0;padding-left:0;padding-right:0}.list-group{padding-left:0px;list-style:none}.list-group-item{border-bottom:1px solid #e7eaec;border-top:1px solid #e7eaec;margin-bottom:-1px;padding:11px 0px;font-size:13px}.pull-right{float:right !important}.el-card__header{padding:14px 15px 7px;min-height:40px}.el-card__body{padding:0 20px}.card-box{padding-right:15px;padding-left:15px;margin-bottom:10px}.el-button--cyan.is-active,.el-button--cyan:active{background:#20B2AA;border-color:#20B2AA;color:#FFFFFF}.el-button--cyan:focus,.el-button--cyan:hover{background:#48D1CC;border-color:#48D1CC;color:#FFFFFF}.el-button--cyan{background-color:#20B2AA;border-color:#20B2AA;color:#FFFFFF}.text-navy{color:#1ab394}.text-primary{color:inherit}.text-success{color:#1c84c6}.text-info{color:#23c6c8}.text-warning{color:#f8ac59}.text-danger{color:#ed5565}.text-muted{color:#888888}.img-circle{border-radius:50%}.img-lg{width:120px;height:120px}.avatar-upload-preview{position:absolute;top:50%;transform:translate(50%, -50%);width:200px;height:200px;border-radius:50%;box-shadow:0 0 4px #ccc;overflow:hidden}.sortable-ghost{opacity:.8;color:#fff !important;background:#42b983 !important}.top-right-btn{position:relative;float:right} diff --git a/jsowell-ui/src/assets/styles/common.scss b/jsowell-ui/src/assets/styles/common.scss new file mode 100644 index 000000000..c09174da5 --- /dev/null +++ b/jsowell-ui/src/assets/styles/common.scss @@ -0,0 +1,274 @@ + /** + * 閫氱敤css鏍峰紡甯冨眬澶勭悊 + */ + + /** 鍩虹閫氱敤 **/ +.pt5 { + padding-top: 5px; +} +.pr5 { + padding-right: 5px; +} +.pb5 { + padding-bottom: 5px; +} +.mt5 { + margin-top: 5px; +} +.mr5 { + margin-right: 5px; +} +.mb5 { + margin-bottom: 5px; +} +.mb8 { + margin-bottom: 8px; +} +.ml5 { + margin-left: 5px; +} +.mt10 { + margin-top: 10px; +} +.mr10 { + margin-right: 10px; +} +.mb10 { + margin-bottom: 10px; +} +.ml10 { + margin-left: 10px; +} +.mt20 { + margin-top: 20px; +} +.mr20 { + margin-right: 20px; +} +.mb20 { + margin-bottom: 20px; +} +.ml20 { + margin-left: 20px; +} + +.h1, .h2, .h3, .h4, .h5, .h6, h1, h2, h3, h4, h5, h6 { + font-family: inherit; + font-weight: 500; + line-height: 1.1; + color: inherit; +} + +.el-dialog:not(.is-fullscreen) { + margin-top: 6vh !important; +} + +.el-dialog__wrapper.scrollbar .el-dialog .el-dialog__body { + overflow: auto; + overflow-x: hidden; + max-height: 70vh; + padding: 10px 20px 0; +} + +.el-table { + .el-table__header-wrapper, .el-table__fixed-header-wrapper { + th { + word-break: break-word; + background-color: #f8f8f9; + color: #515a6e; + height: 40px; + font-size: 13px; + } + } + .el-table__body-wrapper { + .el-button [class*="el-icon-"] + span { + margin-left: 1px; + } + } +} + +/** 琛ㄥ崟甯冨眬 **/ +.form-header { + font-size:15px; + color:#6379bb; + border-bottom:1px solid #ddd; + margin:8px 10px 25px 10px; + padding-bottom:5px +} + +/** 琛ㄦ牸甯冨眬 **/ +.pagination-container { + position: relative; + height: 25px; + margin-bottom: 10px; + margin-top: 15px; + padding: 10px 20px !important; +} + +/* tree border */ +.tree-border { + margin-top: 5px; + border: 1px solid #e5e6e7; + background: #FFFFFF none; + border-radius:4px; +} + +.pagination-container .el-pagination { + right: 0; + position: absolute; +} + +@media ( max-width : 768px) { + .pagination-container .el-pagination > .el-pagination__jump { + display: none !important; + } + .pagination-container .el-pagination > .el-pagination__sizes { + display: none !important; + } +} + +.el-table .fixed-width .el-button--mini { + padding-left: 0; + padding-right: 0; + width: inherit; +} + +/** 琛ㄦ牸鏇村鎿嶄綔涓嬫媺鏍峰紡 */ +.el-table .el-dropdown-link { + cursor: pointer; + color: #409EFF; + margin-left: 5px; +} + +.el-table .el-dropdown, .el-icon-arrow-down { + font-size: 12px; +} + +.el-tree-node__content > .el-checkbox { + margin-right: 8px; +} + +.list-group-striped > .list-group-item { + border-left: 0; + border-right: 0; + border-radius: 0; + padding-left: 0; + padding-right: 0; +} + +.list-group { + padding-left: 0px; + list-style: none; +} + +.list-group-item { + border-bottom: 1px solid #e7eaec; + border-top: 1px solid #e7eaec; + margin-bottom: -1px; + padding: 11px 0px; + font-size: 13px; +} + +.pull-right { + float: right !important; +} + +.el-card__header { + padding: 14px 15px 7px; + min-height: 40px; +} + +.el-card__body { + // 鍘熸湰鏍峰紡 + // padding: 15px 20px 20px 20px; + padding: 0 20px; +} + +.card-box { + padding-right: 15px; + padding-left: 15px; + margin-bottom: 10px; +} + +/* button color */ +.el-button--cyan.is-active, +.el-button--cyan:active { + background: #20B2AA; + border-color: #20B2AA; + color: #FFFFFF; +} + +.el-button--cyan:focus, +.el-button--cyan:hover { + background: #48D1CC; + border-color: #48D1CC; + color: #FFFFFF; +} + +.el-button--cyan { + background-color: #20B2AA; + border-color: #20B2AA; + color: #FFFFFF; +} + +/* text color */ +.text-navy { + color: #1ab394; +} + +.text-primary { + color: inherit; +} + +.text-success { + color: #1c84c6; +} + +.text-info { + color: #23c6c8; +} + +.text-warning { + color: #f8ac59; +} + +.text-danger { + color: #ed5565; +} + +.text-muted { + color: #888888; +} + +/* image */ +.img-circle { + border-radius: 50%; +} + +.img-lg { + width: 120px; + height: 120px; +} + +.avatar-upload-preview { + position: absolute; + top: 50%; + transform: translate(50%, -50%); + width: 200px; + height: 200px; + border-radius: 50%; + box-shadow: 0 0 4px #ccc; + overflow: hidden; +} + +/* 鎷栨嫿鍒楁牱寮 */ +.sortable-ghost{ + opacity: .8; + color: #fff!important; + background: #42b983!important; +} + +.top-right-btn { + position: relative; + float: right; +} diff --git a/jsowell-ui/src/assets/styles/element-ui.scss b/jsowell-ui/src/assets/styles/element-ui.scss new file mode 100644 index 000000000..363092a63 --- /dev/null +++ b/jsowell-ui/src/assets/styles/element-ui.scss @@ -0,0 +1,92 @@ +// cover some element-ui styles + +.el-breadcrumb__inner, +.el-breadcrumb__inner a { + font-weight: 400 !important; +} + +.el-upload { + input[type="file"] { + display: none !important; + } +} + +.el-upload__input { + display: none; +} + +.cell { + .el-tag { + margin-right: 0px; + } +} + +.small-padding { + .cell { + padding-left: 5px; + padding-right: 5px; + } +} + +.fixed-width { + .el-button--mini { + padding: 7px 10px; + width: 60px; + } +} + +.status-col { + .cell { + padding: 0 10px; + text-align: center; + + .el-tag { + margin-right: 0px; + } + } +} + +// to fixed https://github.com/ElemeFE/element/issues/2461 +.el-dialog { + transform: none; + left: 0; + position: relative; + margin: 0 auto; +} + +// refine element ui upload +.upload-container { + .el-upload { + width: 100%; + + .el-upload-dragger { + width: 100%; + height: 200px; + } + } +} + +// dropdown +.el-dropdown-menu { + a { + display: block + } +} + +// fix date-picker ui bug in filter-item +.el-range-editor.el-input__inner { + display: inline-flex !important; +} + +// to fix el-date-picker css style +.el-range-separator { + box-sizing: content-box; +} + +.el-menu--collapse + > div + > .el-submenu + > .el-submenu__title + .el-submenu__icon-arrow { + display: none; +} \ No newline at end of file diff --git a/jsowell-ui/src/assets/styles/element-variables.scss b/jsowell-ui/src/assets/styles/element-variables.scss new file mode 100644 index 000000000..1615ff289 --- /dev/null +++ b/jsowell-ui/src/assets/styles/element-variables.scss @@ -0,0 +1,31 @@ +/** +* I think element-ui's default theme color is too light for long-term use. +* So I modified the default color and you can modify it to your liking. +**/ + +/* theme color */ +$--color-primary: #1890ff; +$--color-success: #13ce66; +$--color-warning: #ffba00; +$--color-danger: #ff4949; +// $--color-info: #1E1E1E; + +$--button-font-weight: 400; + +// $--color-text-regular: #1f2d3d; + +$--border-color-light: #dfe4ed; +$--border-color-lighter: #e6ebf5; + +$--table-border: 1px solid #dfe6ec; + +/* icon font path, required */ +$--font-path: '~element-ui/lib/theme-chalk/fonts'; + +@import "~element-ui/packages/theme-chalk/src/index"; + +// the :export directive is the magic sauce for webpack +// https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass +:export { + theme: $--color-primary; +} diff --git a/jsowell-ui/src/assets/styles/index.scss b/jsowell-ui/src/assets/styles/index.scss new file mode 100644 index 000000000..96095ef6b --- /dev/null +++ b/jsowell-ui/src/assets/styles/index.scss @@ -0,0 +1,191 @@ +@import './variables.scss'; +@import './mixin.scss'; +@import './transition.scss'; +@import './element-ui.scss'; +@import './sidebar.scss'; +@import './btn.scss'; + +body { + height: 100%; + -moz-osx-font-smoothing: grayscale; + -webkit-font-smoothing: antialiased; + text-rendering: optimizeLegibility; + font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif; +} + +label { + font-weight: 700; +} + +html { + height: 100%; + box-sizing: border-box; +} + +#app { + height: 100%; +} + +*, +*:before, +*:after { + box-sizing: inherit; +} + +.no-padding { + padding: 0px !important; +} + +.padding-content { + padding: 4px 0; +} + +a:focus, +a:active { + outline: none; +} + +a, +a:focus, +a:hover { + cursor: pointer; + color: inherit; + text-decoration: none; +} + +div:focus { + outline: none; +} + +.fr { + float: right; +} + +.fl { + float: left; +} + +.pr-5 { + padding-right: 5px; +} + +.pl-5 { + padding-left: 5px; +} + +.block { + display: block; +} + +.pointer { + cursor: pointer; +} + +.inlineBlock { + display: block; +} + +.clearfix { + &:after { + visibility: hidden; + display: block; + font-size: 0; + content: " "; + clear: both; + height: 0; + } +} + +aside { + background: #eef1f6; + padding: 8px 24px; + margin-bottom: 20px; + border-radius: 2px; + display: block; + line-height: 32px; + font-size: 16px; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + color: #2c3e50; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + + a { + color: #337ab7; + cursor: pointer; + + &:hover { + color: rgb(32, 160, 255); + } + } +} + +//main-container鍏ㄥ眬鏍峰紡 +.app-container { + padding: 20px; +} + +.components-container { + margin: 30px 50px; + position: relative; +} + +.pagination-container { + margin-top: 30px; +} + +.text-center { + text-align: center +} + +.sub-navbar { + height: 50px; + line-height: 50px; + position: relative; + width: 100%; + text-align: right; + padding-right: 20px; + transition: 600ms ease position; + background: linear-gradient(90deg, rgba(32, 182, 249, 1) 0%, rgba(32, 182, 249, 1) 0%, rgba(33, 120, 241, 1) 100%, rgba(33, 120, 241, 1) 100%); + + .subtitle { + font-size: 20px; + color: #fff; + } + + &.draft { + background: #d0d0d0; + } + + &.deleted { + background: #d0d0d0; + } +} + +.link-type, +.link-type:focus { + color: #337ab7; + cursor: pointer; + + &:hover { + color: rgb(32, 160, 255); + } +} + +.filter-container { + padding-bottom: 10px; + + .filter-item { + display: inline-block; + vertical-align: middle; + margin-bottom: 10px; + } +} + +//refine vue-multiselect plugin +.multiselect { + line-height: 16px; +} + +.multiselect--active { + z-index: 1000 !important; +} diff --git a/jsowell-ui/src/assets/styles/mixin.scss b/jsowell-ui/src/assets/styles/mixin.scss new file mode 100644 index 000000000..06fa06125 --- /dev/null +++ b/jsowell-ui/src/assets/styles/mixin.scss @@ -0,0 +1,66 @@ +@mixin clearfix { + &:after { + content: ""; + display: table; + clear: both; + } +} + +@mixin scrollBar { + &::-webkit-scrollbar-track-piece { + background: #d3dce6; + } + + &::-webkit-scrollbar { + width: 6px; + } + + &::-webkit-scrollbar-thumb { + background: #99a9bf; + border-radius: 20px; + } +} + +@mixin relative { + position: relative; + width: 100%; + height: 100%; +} + +@mixin pct($pct) { + width: #{$pct}; + position: relative; + margin: 0 auto; +} + +@mixin triangle($width, $height, $color, $direction) { + $width: $width/2; + $color-border-style: $height solid $color; + $transparent-border-style: $width solid transparent; + height: 0; + width: 0; + + @if $direction==up { + border-bottom: $color-border-style; + border-left: $transparent-border-style; + border-right: $transparent-border-style; + } + + @else if $direction==right { + border-left: $color-border-style; + border-top: $transparent-border-style; + border-bottom: $transparent-border-style; + } + + @else if $direction==down { + border-top: $color-border-style; + border-left: $transparent-border-style; + border-right: $transparent-border-style; + } + + @else if $direction==left { + border-right: $color-border-style; + border-top: $transparent-border-style; + border-bottom: $transparent-border-style; + } +} diff --git a/jsowell-ui/src/assets/styles/sidebar.scss b/jsowell-ui/src/assets/styles/sidebar.scss new file mode 100644 index 000000000..ed308b8dc --- /dev/null +++ b/jsowell-ui/src/assets/styles/sidebar.scss @@ -0,0 +1,227 @@ +#app { + + .main-container { + min-height: 100%; + transition: margin-left .28s; + margin-left: $base-sidebar-width; + position: relative; + } + + .sidebarHide { + margin-left: 0!important; + } + + .sidebar-container { + -webkit-transition: width .28s; + transition: width 0.28s; + width: $base-sidebar-width !important; + background-color: $base-menu-background; + height: 100%; + position: fixed; + font-size: 0px; + top: 0; + bottom: 0; + left: 0; + z-index: 1001; + overflow: hidden; + -webkit-box-shadow: 2px 0 6px rgba(0,21,41,.35); + box-shadow: 2px 0 6px rgba(0,21,41,.35); + + // reset element-ui css + .horizontal-collapse-transition { + transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out; + } + + .scrollbar-wrapper { + overflow-x: hidden !important; + } + + .el-scrollbar__bar.is-vertical { + right: 0px; + } + + .el-scrollbar { + height: 100%; + } + + &.has-logo { + .el-scrollbar { + height: calc(100% - 50px); + } + } + + .is-horizontal { + display: none; + } + + a { + display: inline-block; + width: 100%; + overflow: hidden; + } + + .svg-icon { + margin-right: 16px; + } + + .el-menu { + border: none; + height: 100%; + width: 100% !important; + } + + .el-menu-item, .el-submenu__title { + overflow: hidden !important; + text-overflow: ellipsis !important; + white-space: nowrap !important; + } + + // menu hover + .submenu-title-noDropdown, + .el-submenu__title { + &:hover { + background-color: rgba(0, 0, 0, 0.06) !important; + } + } + + & .theme-dark .is-active > .el-submenu__title { + color: $base-menu-color-active !important; + } + + & .nest-menu .el-submenu>.el-submenu__title, + & .el-submenu .el-menu-item { + min-width: $base-sidebar-width !important; + + &:hover { + background-color: rgba(0, 0, 0, 0.06) !important; + } + } + + & .theme-dark .nest-menu .el-submenu>.el-submenu__title, + & .theme-dark .el-submenu .el-menu-item { + background-color: $base-sub-menu-background !important; + + &:hover { + background-color: $base-sub-menu-hover !important; + } + } + } + + .hideSidebar { + .sidebar-container { + width: 54px !important; + } + + .main-container { + margin-left: 54px; + } + + .submenu-title-noDropdown { + padding: 0 !important; + position: relative; + + .el-tooltip { + padding: 0 !important; + + .svg-icon { + margin-left: 20px; + } + } + } + + .el-submenu { + overflow: hidden; + + &>.el-submenu__title { + padding: 0 !important; + + .svg-icon { + margin-left: 20px; + } + + } + } + + .el-menu--collapse { + .el-submenu { + &>.el-submenu__title { + &>span { + height: 0; + width: 0; + overflow: hidden; + visibility: hidden; + display: inline-block; + } + } + } + } + } + + .el-menu--collapse .el-menu .el-submenu { + min-width: $base-sidebar-width !important; + } + + // mobile responsive + .mobile { + .main-container { + margin-left: 0px; + } + + .sidebar-container { + transition: transform .28s; + width: $base-sidebar-width !important; + } + + &.hideSidebar { + .sidebar-container { + pointer-events: none; + transition-duration: 0.3s; + transform: translate3d(-$base-sidebar-width, 0, 0); + } + } + } + + .withoutAnimation { + + .main-container, + .sidebar-container { + transition: none; + } + } +} + +// when menu collapsed +.el-menu--vertical { + &>.el-menu { + .svg-icon { + margin-right: 16px; + } + } + + .nest-menu .el-submenu>.el-submenu__title, + .el-menu-item { + &:hover { + // you can use $subMenuHover + background-color: rgba(0, 0, 0, 0.06) !important; + } + } + + // the scroll bar appears when the subMenu is too long + >.el-menu--popup { + max-height: 100vh; + overflow-y: auto; + + &::-webkit-scrollbar-track-piece { + background: #d3dce6; + } + + &::-webkit-scrollbar { + width: 6px; + } + + &::-webkit-scrollbar-thumb { + background: #99a9bf; + border-radius: 20px; + } + } +} diff --git a/jsowell-ui/src/assets/styles/transition.scss b/jsowell-ui/src/assets/styles/transition.scss new file mode 100644 index 000000000..4cb27cc81 --- /dev/null +++ b/jsowell-ui/src/assets/styles/transition.scss @@ -0,0 +1,48 @@ +// global transition css + +/* fade */ +.fade-enter-active, +.fade-leave-active { + transition: opacity 0.28s; +} + +.fade-enter, +.fade-leave-active { + opacity: 0; +} + +/* fade-transform */ +.fade-transform-leave-active, +.fade-transform-enter-active { + transition: all .5s; +} + +.fade-transform-enter { + opacity: 0; + transform: translateX(-30px); +} + +.fade-transform-leave-to { + opacity: 0; + transform: translateX(30px); +} + +/* breadcrumb transition */ +.breadcrumb-enter-active, +.breadcrumb-leave-active { + transition: all .5s; +} + +.breadcrumb-enter, +.breadcrumb-leave-active { + opacity: 0; + transform: translateX(20px); +} + +.breadcrumb-move { + transition: all .5s; +} + +.breadcrumb-leave-active { + position: absolute; +} diff --git a/jsowell-ui/src/assets/styles/variables.scss b/jsowell-ui/src/assets/styles/variables.scss new file mode 100644 index 000000000..34484d47e --- /dev/null +++ b/jsowell-ui/src/assets/styles/variables.scss @@ -0,0 +1,54 @@ +// base color +$blue:#324157; +$light-blue:#3A71A8; +$red:#C03639; +$pink: #E65D6E; +$green: #30B08F; +$tiffany: #4AB7BD; +$yellow:#FEC171; +$panGreen: #30B08F; + +// 榛樿鑿滃崟涓婚椋庢牸 +$base-menu-color:#bfcbd9; +$base-menu-color-active:#f4f4f5; +$base-menu-background:#304156; +$base-logo-title-color: #ffffff; + +$base-menu-light-color:rgba(0,0,0,.70); +$base-menu-light-background:#ffffff; +$base-logo-light-title-color: #001529; + +$base-sub-menu-background:#1f2d3d; +$base-sub-menu-hover:#001528; + +// 鑷畾涔夋殫鑹茶彍鍗曢鏍 +/** +$base-menu-color:hsla(0,0%,100%,.65); +$base-menu-color-active:#fff; +$base-menu-background:#001529; +$base-logo-title-color: #ffffff; + +$base-menu-light-color:rgba(0,0,0,.70); +$base-menu-light-background:#ffffff; +$base-logo-light-title-color: #001529; + +$base-sub-menu-background:#000c17; +$base-sub-menu-hover:#001528; +*/ + +$base-sidebar-width: 200px; + +// the :export directive is the magic sauce for webpack +// https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass +:export { + menuColor: $base-menu-color; + menuLightColor: $base-menu-light-color; + menuColorActive: $base-menu-color-active; + menuBackground: $base-menu-background; + menuLightBackground: $base-menu-light-background; + subMenuBackground: $base-sub-menu-background; + subMenuHover: $base-sub-menu-hover; + sideBarWidth: $base-sidebar-width; + logoTitleColor: $base-logo-title-color; + logoLightTitleColor: $base-logo-light-title-color +} diff --git a/jsowell-ui/src/assets/鍥炬爣.webp b/jsowell-ui/src/assets/鍥炬爣.webp new file mode 100644 index 000000000..b3e63fa3d Binary files /dev/null and b/jsowell-ui/src/assets/鍥炬爣.webp differ diff --git a/jsowell-ui/src/bus/bus.js b/jsowell-ui/src/bus/bus.js new file mode 100644 index 000000000..aab9c4fed --- /dev/null +++ b/jsowell-ui/src/bus/bus.js @@ -0,0 +1,3 @@ +import Vue from "vue"; +//鍏勫紵缁勪欢涔嬮棿杩涜閫氳 +export default new Vue(); diff --git a/jsowell-ui/src/components/Breadcrumb/index.vue b/jsowell-ui/src/components/Breadcrumb/index.vue new file mode 100644 index 000000000..1696f5471 --- /dev/null +++ b/jsowell-ui/src/components/Breadcrumb/index.vue @@ -0,0 +1,74 @@ + + + + + diff --git a/jsowell-ui/src/components/Crontab/day.vue b/jsowell-ui/src/components/Crontab/day.vue new file mode 100644 index 000000000..fe3eaf0c4 --- /dev/null +++ b/jsowell-ui/src/components/Crontab/day.vue @@ -0,0 +1,161 @@ + + + diff --git a/jsowell-ui/src/components/Crontab/hour.vue b/jsowell-ui/src/components/Crontab/hour.vue new file mode 100644 index 000000000..4b1f1fcdb --- /dev/null +++ b/jsowell-ui/src/components/Crontab/hour.vue @@ -0,0 +1,114 @@ + + + diff --git a/jsowell-ui/src/components/Crontab/index.vue b/jsowell-ui/src/components/Crontab/index.vue new file mode 100644 index 000000000..3963df28e --- /dev/null +++ b/jsowell-ui/src/components/Crontab/index.vue @@ -0,0 +1,430 @@ + + + + diff --git a/jsowell-ui/src/components/Crontab/min.vue b/jsowell-ui/src/components/Crontab/min.vue new file mode 100644 index 000000000..43cab900d --- /dev/null +++ b/jsowell-ui/src/components/Crontab/min.vue @@ -0,0 +1,116 @@ + + + \ No newline at end of file diff --git a/jsowell-ui/src/components/Crontab/month.vue b/jsowell-ui/src/components/Crontab/month.vue new file mode 100644 index 000000000..fd0ac384f --- /dev/null +++ b/jsowell-ui/src/components/Crontab/month.vue @@ -0,0 +1,114 @@ + + + diff --git a/jsowell-ui/src/components/Crontab/result.vue b/jsowell-ui/src/components/Crontab/result.vue new file mode 100644 index 000000000..aea6e0e46 --- /dev/null +++ b/jsowell-ui/src/components/Crontab/result.vue @@ -0,0 +1,559 @@ + + + diff --git a/jsowell-ui/src/components/Crontab/second.vue b/jsowell-ui/src/components/Crontab/second.vue new file mode 100644 index 000000000..e7b776171 --- /dev/null +++ b/jsowell-ui/src/components/Crontab/second.vue @@ -0,0 +1,117 @@ + + + diff --git a/jsowell-ui/src/components/Crontab/week.vue b/jsowell-ui/src/components/Crontab/week.vue new file mode 100644 index 000000000..1cec700e8 --- /dev/null +++ b/jsowell-ui/src/components/Crontab/week.vue @@ -0,0 +1,202 @@ + + + diff --git a/jsowell-ui/src/components/Crontab/year.vue b/jsowell-ui/src/components/Crontab/year.vue new file mode 100644 index 000000000..5487a6c7f --- /dev/null +++ b/jsowell-ui/src/components/Crontab/year.vue @@ -0,0 +1,131 @@ + + + diff --git a/jsowell-ui/src/components/DictData/index.js b/jsowell-ui/src/components/DictData/index.js new file mode 100644 index 000000000..7b85d4aaa --- /dev/null +++ b/jsowell-ui/src/components/DictData/index.js @@ -0,0 +1,49 @@ +import Vue from 'vue' +import store from '@/store' +import DataDict from '@/utils/dict' +import { getDicts as getDicts } from '@/api/system/dict/data' + +function searchDictByKey(dict, key) { + if (key == null && key == "") { + return null + } + try { + for (let i = 0; i < dict.length; i++) { + if (dict[i].key == key) { + return dict[i].value + } + } + } catch (e) { + return null + } +} + +function install() { + Vue.use(DataDict, { + metas: { + '*': { + labelField: 'dictLabel', + valueField: 'dictValue', + request(dictMeta) { + const storeDict = searchDictByKey(store.getters.dict, dictMeta.type) + if (storeDict) { + return new Promise(resolve => { resolve(storeDict) }) + } else { + return new Promise((resolve, reject) => { + getDicts(dictMeta.type).then(res => { + store.dispatch('dict/setDict', { key: dictMeta.type, value: res.data }) + resolve(res.data) + }).catch(error => { + reject(error) + }) + }) + } + }, + }, + }, + }) +} + +export default { + install, +} \ No newline at end of file diff --git a/jsowell-ui/src/components/DictTag/index.vue b/jsowell-ui/src/components/DictTag/index.vue new file mode 100644 index 000000000..794849bf4 --- /dev/null +++ b/jsowell-ui/src/components/DictTag/index.vue @@ -0,0 +1,58 @@ + + + + diff --git a/jsowell-ui/src/components/Editor/index.vue b/jsowell-ui/src/components/Editor/index.vue new file mode 100644 index 000000000..6bb5a18d3 --- /dev/null +++ b/jsowell-ui/src/components/Editor/index.vue @@ -0,0 +1,272 @@ + + + + + diff --git a/jsowell-ui/src/components/FileUpload/index.vue b/jsowell-ui/src/components/FileUpload/index.vue new file mode 100644 index 000000000..aa2296b93 --- /dev/null +++ b/jsowell-ui/src/components/FileUpload/index.vue @@ -0,0 +1,209 @@ + + + + + diff --git a/jsowell-ui/src/components/Hamburger/index.vue b/jsowell-ui/src/components/Hamburger/index.vue new file mode 100644 index 000000000..368b00215 --- /dev/null +++ b/jsowell-ui/src/components/Hamburger/index.vue @@ -0,0 +1,44 @@ + + + + + diff --git a/jsowell-ui/src/components/HeaderSearch/index.vue b/jsowell-ui/src/components/HeaderSearch/index.vue new file mode 100644 index 000000000..c44eff56e --- /dev/null +++ b/jsowell-ui/src/components/HeaderSearch/index.vue @@ -0,0 +1,190 @@ + + + + + diff --git a/jsowell-ui/src/components/IconSelect/index.vue b/jsowell-ui/src/components/IconSelect/index.vue new file mode 100644 index 000000000..b0ec9fa1a --- /dev/null +++ b/jsowell-ui/src/components/IconSelect/index.vue @@ -0,0 +1,68 @@ + + + + + + diff --git a/jsowell-ui/src/components/IconSelect/requireIcons.js b/jsowell-ui/src/components/IconSelect/requireIcons.js new file mode 100644 index 000000000..99e5c54cc --- /dev/null +++ b/jsowell-ui/src/components/IconSelect/requireIcons.js @@ -0,0 +1,11 @@ + +const req = require.context('../../assets/icons/svg', false, /\.svg$/) +const requireAll = requireContext => requireContext.keys() + +const re = /\.\/(.*)\.svg/ + +const icons = requireAll(req).map(i => { + return i.match(re)[1] +}) + +export default icons diff --git a/jsowell-ui/src/components/ImagePreview/index.vue b/jsowell-ui/src/components/ImagePreview/index.vue new file mode 100644 index 000000000..743d8d51d --- /dev/null +++ b/jsowell-ui/src/components/ImagePreview/index.vue @@ -0,0 +1,84 @@ + + + + + diff --git a/jsowell-ui/src/components/ImageUpload/index.vue b/jsowell-ui/src/components/ImageUpload/index.vue new file mode 100644 index 000000000..4068b6727 --- /dev/null +++ b/jsowell-ui/src/components/ImageUpload/index.vue @@ -0,0 +1,212 @@ + + + + + diff --git a/jsowell-ui/src/components/MapContainer/MapContainer.vue b/jsowell-ui/src/components/MapContainer/MapContainer.vue new file mode 100644 index 000000000..c5b155a46 --- /dev/null +++ b/jsowell-ui/src/components/MapContainer/MapContainer.vue @@ -0,0 +1,235 @@ + + + + + diff --git a/jsowell-ui/src/components/MapContainer/MapContainer11111.vue b/jsowell-ui/src/components/MapContainer/MapContainer11111.vue new file mode 100644 index 000000000..8f6c29149 --- /dev/null +++ b/jsowell-ui/src/components/MapContainer/MapContainer11111.vue @@ -0,0 +1,176 @@ + + + + + diff --git a/jsowell-ui/src/components/Pagination/index.vue b/jsowell-ui/src/components/Pagination/index.vue new file mode 100644 index 000000000..f2696ff0c --- /dev/null +++ b/jsowell-ui/src/components/Pagination/index.vue @@ -0,0 +1,114 @@ + + + + + diff --git a/jsowell-ui/src/components/PanThumb/index.vue b/jsowell-ui/src/components/PanThumb/index.vue new file mode 100644 index 000000000..1bcf41709 --- /dev/null +++ b/jsowell-ui/src/components/PanThumb/index.vue @@ -0,0 +1,142 @@ + + + + + diff --git a/jsowell-ui/src/components/ParentView/index.vue b/jsowell-ui/src/components/ParentView/index.vue new file mode 100644 index 000000000..7bf614897 --- /dev/null +++ b/jsowell-ui/src/components/ParentView/index.vue @@ -0,0 +1,3 @@ + diff --git a/jsowell-ui/src/components/RightPanel/index.vue b/jsowell-ui/src/components/RightPanel/index.vue new file mode 100644 index 000000000..2d6122bc0 --- /dev/null +++ b/jsowell-ui/src/components/RightPanel/index.vue @@ -0,0 +1,112 @@ + + + + + diff --git a/jsowell-ui/src/components/RightToolbar/index.vue b/jsowell-ui/src/components/RightToolbar/index.vue new file mode 100644 index 000000000..358f23cf2 --- /dev/null +++ b/jsowell-ui/src/components/RightToolbar/index.vue @@ -0,0 +1,104 @@ + + + diff --git a/jsowell-ui/src/components/Screenfull/index.vue b/jsowell-ui/src/components/Screenfull/index.vue new file mode 100644 index 000000000..d4e539c26 --- /dev/null +++ b/jsowell-ui/src/components/Screenfull/index.vue @@ -0,0 +1,57 @@ + + + + + diff --git a/jsowell-ui/src/components/SizeSelect/index.vue b/jsowell-ui/src/components/SizeSelect/index.vue new file mode 100644 index 000000000..069b5de9b --- /dev/null +++ b/jsowell-ui/src/components/SizeSelect/index.vue @@ -0,0 +1,56 @@ + + + diff --git a/jsowell-ui/src/components/SvgIcon/index.vue b/jsowell-ui/src/components/SvgIcon/index.vue new file mode 100644 index 000000000..e4bf5ade1 --- /dev/null +++ b/jsowell-ui/src/components/SvgIcon/index.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/jsowell-ui/src/components/ThemePicker/index.vue b/jsowell-ui/src/components/ThemePicker/index.vue new file mode 100644 index 000000000..1714e1f39 --- /dev/null +++ b/jsowell-ui/src/components/ThemePicker/index.vue @@ -0,0 +1,173 @@ + + + + + diff --git a/jsowell-ui/src/components/TopNav/index.vue b/jsowell-ui/src/components/TopNav/index.vue new file mode 100644 index 000000000..0cc24dba8 --- /dev/null +++ b/jsowell-ui/src/components/TopNav/index.vue @@ -0,0 +1,181 @@ + + + + + diff --git a/jsowell-ui/src/components/iFrame/index.vue b/jsowell-ui/src/components/iFrame/index.vue new file mode 100644 index 000000000..426857fb1 --- /dev/null +++ b/jsowell-ui/src/components/iFrame/index.vue @@ -0,0 +1,36 @@ +