diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md new file mode 100644 index 0000000000000000000000000000000000000000..2c87cb9e81c19ca5275902e352f3a9d498b7eb3e --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE.zh-CN.md @@ -0,0 +1,22 @@ +### 该问题是怎么引起的? + + + +### 浏览器类型 + + + +### Vue版本 + + + +### .NetCore版本 + + + +### 报错信息 + + + + +### 拉取代码时间 diff --git a/.gitignore b/.gitignore index 91c5d327fb3cb2ecc8a49c66640e148c679055ed..82f0e6ab91662de342a95fa92f43468c18155d58 100644 --- a/.gitignore +++ b/.gitignore @@ -271,3 +271,4 @@ __pycache__/ /ZR.Admin.WebApi/DataProtection /Quartz.NET.WindowsService /ZRAdmin-vue +/ZR.Admin.WebApi/ZRModel.xml diff --git a/Infrastructure/Constant/HttpStatus.cs b/Infrastructure/Constant/HttpStatus.cs index 3643b823f9c1e2d7552e84e04a3d30bd77bb9d65..34fe7dc4dc179bba220816a08744bbbda3c23104 100644 --- a/Infrastructure/Constant/HttpStatus.cs +++ b/Infrastructure/Constant/HttpStatus.cs @@ -40,9 +40,9 @@ namespace Infrastructure.Constant /// public static readonly int NOT_MODIFIED = 304; - /** - * 鍙傛暟鍒楄〃閿欒锛堢己灏戯紝鏍煎紡涓嶅尮閰嶏級 - */ + /// + /// 鍙傛暟鍒楄〃閿欒锛堢己灏戯紝鏍煎紡涓嶅尮閰嶏級 + /// public static readonly int BAD_REQUEST = 400; /// @@ -50,39 +50,39 @@ namespace Infrastructure.Constant /// public static readonly int UNAUTHORIZED = 401; - /** - * 璁块棶鍙楅檺锛屾巿鏉冭繃鏈 - */ + /// + /// 璁块棶鍙楅檺锛屾巿鏉冭繃鏈 + /// public static readonly int FORBIDDEN = 403; - /** - * 璧勬簮锛屾湇鍔℃湭鎵惧埌 - */ + /// + /// 璧勬簮锛屾湇鍔℃湭鎵惧埌 + /// public static readonly int NOT_FOUND = 404; - /** - * 涓嶅厑璁哥殑http鏂规硶 - */ + /// + /// 涓嶅厑璁哥殑http鏂规硶 + /// public static readonly int BAD_METHOD = 405; - /** - * 璧勬簮鍐茬獊锛屾垨鑰呰祫婧愯閿 - */ + /// + /// 璧勬簮鍐茬獊锛屾垨鑰呰祫婧愯閿 + /// public static readonly int CONFLICT = 409; - /** - * 涓嶆敮鎸佺殑鏁版嵁锛屽獟浣撶被鍨 - */ + /// + /// 涓嶆敮鎸佺殑鏁版嵁锛屽獟浣撶被鍨 + /// public static readonly int UNSUPPORTED_TYPE = 415; - /** - * 绯荤粺鍐呴儴閿欒 - */ + /// + /// 绯荤粺鍐呴儴閿欒 + /// public static readonly int ERROR = 500; - /** - * 鎺ュ彛鏈疄鐜 - */ + /// + /// 鎺ュ彛鏈疄鐜 + /// public static readonly int NOT_IMPLEMENTED = 501; } } diff --git a/Infrastructure/Enums/BusinessType.cs b/Infrastructure/Enums/BusinessType.cs index 5f4195a7f3195bfda3ea9cee7c7f8a6353b24e64..a4f09e1cb5b7f677861533a05fe71adeb4034388 100644 --- a/Infrastructure/Enums/BusinessType.cs +++ b/Infrastructure/Enums/BusinessType.cs @@ -1,64 +1,58 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Text; - -namespace Infrastructure.Enums +锘縩amespace Infrastructure.Enums { - /** - * 涓氬姟鎿嶄綔绫诲瀷 - * 0=鍏跺畠,1=鏂板,2=淇敼,3=鍒犻櫎,4=鎺堟潈,5=瀵煎嚭,6=瀵煎叆,7=寮洪,8=鐢熸垚浠g爜,9=娓呯┖鏁版嵁 - * @author zrry - */ + /// + /// 涓氬姟鎿嶄綔绫诲瀷 0=鍏跺畠,1=鏂板,2=淇敼,3=鍒犻櫎,4=鎺堟潈,5=瀵煎嚭,6=瀵煎叆,7=寮洪,8=鐢熸垚浠g爜,9=娓呯┖鏁版嵁 + /// public enum BusinessType { - /** - * 鍏跺畠 - */ + /// + /// 鍏跺畠 + /// OTHER = 0, - /** - * 鏂板 - */ + /// + /// 鏂板 + /// INSERT = 1, - /** - * 淇敼 - */ + /// + /// 淇敼 + /// UPDATE = 2, - /** - * 鍒犻櫎 - */ + /// + /// 鍒犻櫎 + /// DELETE = 3, - /** - * 鎺堟潈 - */ + /// + /// 鎺堟潈 + /// GRANT = 4, - /** - * 瀵煎嚭 - */ + /// + /// 瀵煎嚭 + /// EXPORT = 5, - /** - * 瀵煎叆 - */ + /// + /// 瀵煎叆 + /// IMPORT = 6, - /** - * 寮洪 - */ + /// + /// 寮洪 + /// FORCE = 7, - /** - * 鐢熸垚浠g爜 - */ + /// + /// 鐢熸垚浠g爜 + /// GENCODE = 8, - /** - * 娓呯┖鏁版嵁 - */ + /// + /// 娓呯┖鏁版嵁 + /// CLEAN = 9, } } diff --git a/Infrastructure/Helper/HttpHelper.cs b/Infrastructure/Helper/HttpHelper.cs index a42482b7be0a52cf0f5aca720365ba15bc759920..f9c042c38e7e6ce28b4e7748017cbb4de6a52c12 100644 --- a/Infrastructure/Helper/HttpHelper.cs +++ b/Infrastructure/Helper/HttpHelper.cs @@ -109,7 +109,6 @@ namespace Infrastructure /// /// /// - /// /// public static async Task HttpGetAsync(string url, Dictionary headers = null) { diff --git a/Infrastructure/Infrastructure.csproj b/Infrastructure/Infrastructure.csproj index c696460755fc23f90514be73cc8bd268e9d0ac19..bb06ce9469a96d2a3a0978cf7ecf12608894c045 100644 --- a/Infrastructure/Infrastructure.csproj +++ b/Infrastructure/Infrastructure.csproj @@ -1,18 +1,18 @@ - - net5.0 - + + net5.0 + - - - + + + - - - - - - + + + + + + diff --git a/Infrastructure/OptionsSetting.cs b/Infrastructure/OptionsSetting.cs index c6cf6f0749dea5f9c0ec12f34d70c59c93bf24d8..fd00be33c797f25cd1da08b3cdeb0ded2ebb333f 100644 --- a/Infrastructure/OptionsSetting.cs +++ b/Infrastructure/OptionsSetting.cs @@ -12,7 +12,7 @@ namespace Infrastructure public bool DemoMode { get; set; } public MailOptions MailOptions { get; set; } public Upload Upload { get; set; } - public ALYUN_OCS ALYUN_OCS { get; set; } + public ALIYUN_OSS ALIYUN_OSS { get; set; } public JwtSettings JwtSettings { get; set; } } /// @@ -33,15 +33,20 @@ namespace Infrastructure { public string UploadUrl { get; set; } public string LocalSavePath { get; set; } + public int MaxSize { get; set; } + public string[] NotAllowedExt { get; set; } = new string[0]; } /// /// 闃块噷浜戝瓨鍌 /// - public class ALYUN_OCS + public class ALIYUN_OSS { public string REGIONID { get; set; } public string KEY { get; set; } public string SECRET { get; set; } + public string BucketName { get; set; } + public string DomainUrl { get; set; } + public int MaxSize { get; set; } = 100; } /// diff --git a/README.md b/README.md index fae192b729ea295e5a31713650af1d1871655e44..9470202a844857865c6569465db08bf2a286414d 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,65 @@ -

ZRAdmin.NET鍚庡彴绠$悊绯荤粺

-

鍩轰簬.NET5/.NET6 + vue2.x/vue3.x鍓嶅悗绔垎绂荤殑.net蹇熷紑鍙戞鏋

- +

ZR.Admin.NET鍚庡彴绠$悊绯荤粺

+

鍩轰簬.NET5/.Net7 + vue2.x/vue3.x鍓嶅悗绔垎绂荤殑.net蹇熷紑鍙戞鏋

+fork +

-## 馃崯姒傝堪 -* 鏈」鐩傚悎鏈変竴瀹歂etCore鍜 vue鍩虹鐨勫紑鍙戜汉鍛 -* 鍩轰簬.NET5/.NET6瀹炵幇鐨勯氱敤鏉冮檺绠$悊骞冲彴锛圧BAC妯″紡锛夈傛暣鍚堟渶鏂版妧鏈珮鏁堝揩閫熷紑鍙戯紝鍓嶅悗绔垎绂绘ā寮忥紝寮绠卞嵆鐢ㄣ -* 浠g爜閲忓皯銆佸涔犵畝鍗曘侀氫織鏄撴噦銆佸姛鑳藉己澶с佹槗鎵╁睍銆佽交閲忕骇锛岃web寮鍙戞洿蹇熴佺畝鍗曢珮鏁堬紙浠庢鍛婂埆996锛夛紝瑙e喅70%鐨勯噸澶嶅伐浣滐紝涓撴敞鎮ㄧ殑涓氬姟锛岃交鏉惧紑鍙戜粠鐜板湪寮濮嬶紒 -* 鎻愪緵浜嗘妧鏈爤(Ant Design Vue)鐗圼Ant Design Vue](https://gitee.com/billzh/mc-dull.git) -* 涓冪墰浜戦氱敤浜戜骇鍝佷紭鎯犲埜锛歔鐐规垜杩涘叆](https://s.qiniu.com/FzEfay)銆 -* 鑵捐浜戠鏉鍦猴細[鐐规垜杩涘叆](https://curl.qcloud.com/4yEoRquq)銆 -* 鑵捐浜戜紭鎯犲埜锛歔鐐规垜棰嗗彇](https://curl.qcloud.com/5J4nag8D)銆 +## 馃崯 姒傝堪 + +- 鏈」鐩傚悎鏈変竴瀹 NetCore 鍜 vue 鍩虹鐨勫紑鍙戜汉鍛 +- 鍩轰簬.NET5/.NET7 瀹炵幇鐨勯氱敤鏉冮檺绠$悊骞冲彴锛圧BAC 妯″紡锛夈傛暣鍚堟渶鏂版妧鏈珮鏁堝揩閫熷紑鍙戯紝鍓嶅悗绔垎绂绘ā寮忥紝寮绠卞嵆鐢ㄣ +- 浠g爜閲忓皯銆佸涔犵畝鍗曘侀氫織鏄撴噦銆佸姛鑳藉己澶с佹槗鎵╁睍銆佽交閲忕骇锛岃 web 寮鍙戞洿蹇熴佺畝鍗曢珮鏁堬紙浠庢鍛婂埆 996锛夛紝瑙e喅 70%鐨勯噸澶嶅伐浣滐紝涓撴敞鎮ㄧ殑涓氬姟锛岃交鏉惧紑鍙戜粠鐜板湪寮濮嬶紒 +- 鎻愪緵浜嗘妧鏈爤(Ant Design Vue)鐗圼Ant Design Vue](https://gitee.com/billzh/mc-dull.git) +- 涓冪墰浜戦氱敤浜戜骇鍝佷紭鎯犲埜锛歔鐐规垜杩涘叆](https://s.qiniu.com/FzEfay)銆 +- 鑵捐浜戠鏉鍦猴細[鐐规垜杩涘叆](https://curl.qcloud.com/4yEoRquq)銆 +- 鑵捐浜戜紭鎯犲埜锛歔鐐规垜棰嗗彇](https://curl.qcloud.com/5J4nag8D)銆 ``` 濡傛灉瀵规偍鏈夊府鍔╋紝鎮ㄥ彲浠ョ偣鍙充笂瑙 鈥淪tar鈥 鏀惰棌涓涓 锛岃繖鏍蜂綔鑰呮墠鏈夌户缁厤璐逛笅鍘荤殑鍔ㄥ姏锛岃阿璋紒~ ``` -## 馃嵖鍦ㄧ嚎浣撻獙 +## 馃嵖 鍦ㄧ嚎浣撻獙 + - 瀹樻柟鏂囨。锛歨ttp://www.izhaorui.cn/doc -- vue3.x鐗堟湰浣撻獙锛歨ttp://www.izhaorui.cn/vue3 -- vue2.x鐗堟湰浣撻獙锛歨ttp://www.izhaorui.cn/admin +- vue3.x 鐗堟湰浣撻獙锛歨ttp://www.izhaorui.cn/vue3 +- vue2.x 鐗堟湰浣撻獙锛歨ttp://www.izhaorui.cn/admin - 璐﹀彿瀵嗙爜锛歛dmin/123456 - ``` 鐢变簬鏄釜浜洪」鐩紝璧勯噾鏈夐檺锛屼綋楠屾湇鏄綆閰嶏紝璇峰ぇ瀹剁埍鎯滐紝杞绘埑锛屼笉鑳滄劅婵锛侊紒锛 ``` -## 馃拻浠g爜浠撳簱 -| 浠撳簱 | Github | Gitee | -| ----------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | -| Vue2 + Net5 | | [鍏嬮殕/涓嬭浇](https://gitee.com/izory/ZrAdminNetCore/) | -| Vue2 + Net6 | [鍏嬮殕/涓嬭浇](https://github.com/izhaorui/ZrAdmin.NET/tree/net6.0) | [鍏嬮殕/涓嬭浇](https://gitee.com/izory/ZrAdminNetCore/tree/net6.0/) | -| Vue3 | [鍏嬮殕/涓嬭浇](https://github.com/izhaorui/ZRAdminVue) | [鍏嬮殕/涓嬭浇](https://gitee.com/izory/ZRAdmin-vue) - -## 馃崄鍓嶇鎶鏈 -Vue鐗堝墠绔妧鏈爤 锛氬熀浜巚ue2.x/vue3.x銆乿uex銆乿ue-router 銆乿ue-cli 銆乤xios銆 element-ui銆乪chats銆乮18n鍥介檯鍖栫瓑锛屽墠绔噰鐢╲scode宸ュ叿寮鍙 - -## 馃崁鍚庣鎶鏈 -- 鏍稿績妗嗘灦锛.Net5.0/.Net6.0 + Web API + sqlsugar + swagger + signalR + IpRateLimit + Quartz.net + Redis -- 瀹氭椂璁″垝浠诲姟锛歈uartz.Net缁勪欢锛屾敮鎸佹墽琛岀▼搴忛泦鎴栬卙ttp缃戠粶璇锋眰 -- 瀹夊叏鏀寔锛氳繃婊ゅ櫒(鏁版嵁鏉冮檺杩囨护)銆丼ql娉ㄥ叆銆佽姹備吉閫 + +## 馃拻 浠g爜浠撳簱 + +| 浠撳簱 | Github | Gitee | +| ----------- | ------ | ---------------------------------------------------------------- | +| Vue2 + Net5 | | [鍏嬮殕/涓嬭浇](https://gitee.com/izory/ZrAdminNetCore/) | +| Vue3 | | [鍏嬮殕/涓嬭浇](https://gitee.com/izory/ZRAdmin-vue) | +| Vue2 + Net7 | | [鍏嬮殕/涓嬭浇](https://gitee.com/izory/ZrAdminNetCore/tree/net7.0/) | + +## 馃崄 鍓嶇鎶鏈 + +Vue 鐗堝墠绔妧鏈爤 锛氬熀浜 vue2.x/vue3.x銆乿uex銆乿ue-router 銆乿ue-cli 銆乤xios銆 element-ui銆乪chats銆乮18n 鍥介檯鍖栫瓑锛屽墠绔噰鐢 vscode 宸ュ叿寮鍙 + +## 馃崁 鍚庣鎶鏈 + +- 鏍稿績妗嗘灦锛.Net5.0/.Net7.0 + Web API + sqlsugar + swagger + signalR + IpRateLimit + Quartz.net + Redis +- 瀹氭椂璁″垝浠诲姟锛歈uartz.Net 缁勪欢锛屾敮鎸佹墽琛岀▼搴忛泦鎴栬 http 缃戠粶璇锋眰 +- 瀹夊叏鏀寔锛氳繃婊ゅ櫒(鏁版嵁鏉冮檺杩囨护)銆丼ql 娉ㄥ叆銆佽姹備吉閫 - 鏃ュ織绠$悊锛歂Log銆佺櫥褰曟棩蹇椼佹搷浣滄棩蹇椼佸畾鏃朵换鍔℃棩蹇 - 宸ュ叿绫伙細楠岃瘉鐮併佷赴瀵屽叕鍏卞姛鑳 - 鎺ュ彛闄愭祦锛氭敮鎸佹帴鍙i檺娴侊紝閬垮厤鎭舵剰璇锋眰瀵艰嚧鏈嶅姟灞傚帇鍔涜繃澶 - 浠g爜鐢熸垚锛氶珮鏁堢巼寮鍙戯紝浠g爜鐢熸垚鍣ㄥ彲浠ヤ竴閿敓鎴愭墍鏈夊墠鍚庣浠g爜 - 鏁版嵁瀛楀吀锛氭敮鎸佹暟鎹瓧鍏革紝鍙互鏂逛究瀵逛竴浜涚姸鎬佽繘琛岀鐞 -- 鍒嗗簱鍒嗚〃锛氫娇鐢╫rm sqlsugar鍙互寰堣交鏉剧殑瀹炵幇鍒嗗簱鍒嗗簱鎬ц兘浼樿秺 +- 鍒嗗簱鍒嗚〃锛氫娇鐢 orm sqlsugar 鍙互寰堣交鏉剧殑瀹炵幇鍒嗗簱鍒嗗簱鎬ц兘浼樿秺 - 澶 绉 鎴凤細鏀寔澶氱鎴峰姛鑳 -- 缂撳瓨鏁版嵁锛氬唴缃唴瀛樼紦瀛樺拰Redis +- 缂撳瓨鏁版嵁锛氬唴缃唴瀛樼紦瀛樺拰 Redis - -## 馃崠鍐呯疆鍔熻兘 +## 馃崠 鍐呯疆鍔熻兘 1. 鐢ㄦ埛绠$悊锛氱敤鎴锋槸绯荤粺鎿嶄綔鑰咃紝璇ュ姛鑳戒富瑕佸畬鎴愮郴缁熺敤鎴烽厤缃 2. 閮ㄩ棬绠$悊锛氶厤缃郴缁熺粍缁囨満鏋勶紙鍏徃銆侀儴闂ㄣ佸皬缁勶級锛屾爲缁撴瀯灞曠幇銆 @@ -66,30 +71,31 @@ Vue鐗堝墠绔妧鏈爤 锛氬熀浜巚ue2.x/vue3.x銆乿uex銆乿ue-router 銆乿ue-cli 銆乤 8. 鐧诲綍鏃ュ織锛氱郴缁熺櫥褰曟棩蹇楄褰曟煡璇㈠寘鍚櫥褰曞紓甯搞 9. 绯荤粺鎺ュ彛锛氫娇鐢 swagger 鐢熸垚鐩稿叧 api 鎺ュ彛鏂囨。銆 10. 鏈嶅姟鐩戞帶锛氱洃瑙嗗綋鍓嶇郴缁 CPU銆佸唴瀛樸佺鐩樸佸爢鏍堢瓑鐩稿叧淇℃伅銆 -11. 鍦ㄧ嚎鏋勫缓鍣細鎷栧姩琛ㄥ崟鍏冪礌鐢熸垚鐩稿簲鐨 VUE 浠g爜銆 +11. 鍦ㄧ嚎鏋勫缓鍣細鎷栧姩琛ㄥ崟鍏冪礌鐢熸垚鐩稿簲鐨 VUE 浠g爜(浠呮敮鎸 vue2)銆 12. 浠诲姟绯荤粺锛氬熀浜 Quartz.NET锛屽彲浠ュ湪绾匡紙娣诲姞銆佷慨鏀广佸垹闄ゃ佹墜鍔ㄦ墽琛)浠诲姟璋冨害鍖呭惈鎵ц缁撴灉鏃ュ織銆 13. 鏂囩珷绠$悊锛氬彲浠ュ啓鏂囩珷璁板綍銆 -14. 浠g爜鐢熸垚锛氬彲浠ヤ竴閿敓鎴愬墠鍚庣浠g爜(.cs銆.vue銆.js銆乻ql绛)鏀寔涓嬭浇锛岃嚜瀹氫箟閰嶇疆鍓嶇灞曠ず鎺т欢銆佽寮鍙戞洿蹇嵎楂樻晥銆 +14. 浠g爜鐢熸垚锛氬彲浠ヤ竴閿敓鎴愬墠鍚庣浠g爜(.cs銆.vue銆.js銆.sql 绛)鏀寔涓嬭浇锛岃嚜瀹氫箟閰嶇疆鍓嶇灞曠ず鎺т欢銆佽寮鍙戞洿蹇嵎楂樻晥锛堝彶涓婃渶寮猴級銆 15. 鍙傛暟绠$悊锛氬绯荤粺鍔ㄦ侀厤缃父鐢ㄥ弬鏁般 16. 鍙戦侀偖浠讹細鍙互瀵瑰涓敤鎴疯繘琛屽彂閫侀偖浠躲 17. 鏂囦欢绠$悊锛氬彲浠ヨ繘琛屼笂浼犳枃浠剁鐞嗭紝鐩墠鏀寔涓婁紶鍒版湰鍦般侀樋閲屼簯銆 18. 閫氱煡绠$悊锛氱郴缁熼氱煡鍏憡淇℃伅鍙戝竷缁存姢锛屼娇鐢 signalr 瀹炵幇瀵圭敤鎴峰疄鏃堕氱煡銆 19. 璐﹀彿娉ㄥ唽锛氬彲浠ユ敞鍐岃处鍙风櫥褰曠郴缁熴 -20. 澶氳瑷绠$悊锛氭敮鎸侀潤鎬併佸悗绔姩鎬侀厤缃浗闄呭寲銆傜洰鍓嶅彧鏀寔涓佽嫳銆佺箒浣 +20. 澶氳瑷绠$悊锛氭敮鎸侀潤鎬併佸悗绔姩鎬侀厤缃浗闄呭寲銆傜洰鍓嶅彧鏀寔涓佽嫳銆佺箒浣(浠呮敮鎸 vue3) -## 馃嵒椤圭洰缁撴瀯 +## 馃嵒 椤圭洰缁撴瀯 ``` -鈹溾攢ZR.Service ->[鏈嶅姟灞傜被搴揮锛氭彁渚沇ebApi鎺ュ彛璋冪敤锛 +鈹溾攢ZR.Service ->[鏈嶅姟灞傜被搴揮锛氭彁渚沇ebApi鎺ュ彛璋冪敤锛 鈹溾攢ZR.Repository ->[浠撳簱灞傜被搴揮锛氭柟渚挎彁渚涙湁鎵ц瀛樺偍杩囩▼鐨勬搷浣滐紱 -鈹溾攢ZR.Model ->[瀹炰綋灞傜被搴揮锛氭彁渚涢」鐩腑鐨勬暟鎹簱琛ㄣ佹暟鎹紶杈撳璞★紱 +鈹溾攢ZR.Model ->[瀹炰綋灞傜被搴揮锛氭彁渚涢」鐩腑鐨勬暟鎹簱琛ㄣ佹暟鎹紶杈撳璞★紱 鈹溾攢ZR.Admin.WebApi ->[webapi鎺ュ彛]锛氫负Vue鐗堟垨鍏朵粬涓夋柟绯荤粺鎻愪緵鎺ュ彛鏈嶅姟銆 -鈹溾攢ZR.Tasks ->[瀹氭椂浠诲姟绫诲簱]锛氭彁渚涢」鐩畾鏃朵换鍔″疄鐜板姛鑳斤紱 +鈹溾攢ZR.Tasks ->[瀹氭椂浠诲姟绫诲簱]锛氭彁渚涢」鐩畾鏃朵换鍔″疄鐜板姛鑳斤紱 鈹溾攢ZR.CodeGenerator ->[浠g爜鐢熸垚鍔熻兘]锛氬寘鍚唬鐮佺敓鎴愮殑妯℃澘銆佹柟娉曘佷唬鐮佺敓鎴愮殑涓嬭浇銆 -鈹溾攢ZR.Vue ->[鍓嶇UI]锛歷ue2.0鐗堟湰UI灞傘 +鈹溾攢ZR.Vue ->[鍓嶇UI]锛歷ue2.0鐗堟湰UI灞傘 +鈹溾攢document ->[鏂囨。]锛氭暟鎹簱鑴氭湰 ``` -## 馃崕婕旂ず鍥 +## 馃崕 婕旂ず鍥 @@ -134,24 +140,30 @@ Vue鐗堝墠绔妧鏈爤 锛氬熀浜巚ue2.x/vue3.x銆乿uex銆乿ue-router 銆乿ue-cli 銆乤
-## 馃帀浼樺娍 +## 馃帀 浼樺娍 1. 鍓嶅彴绯荤粺涓嶇敤缂栧啓鐧诲綍銆佹巿鏉冦佽璇佹ā鍧楋紱鍙礋璐g紪鍐欎笟鍔℃ā鍧楀嵆鍙 2. 鍚庡彴绯荤粺鏃犻渶浠讳綍浜屾寮鍙戯紝鐩存帴鍙戝竷鍗冲彲浣跨敤 3. 鍓嶅彴涓庡悗鍙扮郴缁熷垎绂伙紝鍒嗗埆涓轰笉鍚岀殑绯荤粺锛堝煙鍚嶅彲鐙珛锛 4. 鍏ㄥ眬寮傚父缁熶竴澶勭悊 5. 鑷畾涔夌殑浠g爜鐢熸垚鍔熻兘 +6. 渚濊禆灏戯紝涓婃墜瀹规槗 ## 馃拹 鐗瑰埆楦h阿 + - 馃憠Ruoyi.vue锛歔Ruoyi](http://www.ruoyi.vip/) - 馃憠SqlSugar锛歔SqlSugar](https://gitee.com/dotnetchina/SqlSugar) - 馃憠vue-element-admin锛歔vue-element-admin](https://github.com/PanJiaChen/vue-element-admin) +- 馃憠Meiam.System锛歔Meiam.System](https://github.com/91270/Meiam.System) + +## 馃巰 鎹愯禒 -## 馃巰鎹愯禒 濡傛灉浣犺寰楄繖涓」鐩府鍔╁埌浜嗕綘锛屼綘鍙互璇蜂綔鑰呭枬鏉挅鍟¤〃绀洪紦鍔 鈽曪笍 -## 馃敡浣跨敤璇存槑 -濡傛灉閮ㄧ讲iis璁块棶涓嶄簡鎯呭喌鍙互鏈変互涓嬩袱绉嶅姙娉曪細 -1. 鐩存帴鎵撳紑ZR.Admin.WebApi.exe鏂囦欢鐒跺悗鐪嬫帶鍒跺彴鐨勯敊璇棩蹇 -2. web.config閲岄潰鏈変釜false 鏀逛负 true锛宨is閲嶅惎椤圭洰鍚庤繍琛岀綉绔欏悗锛岃窡鐩綍涓嬮潰 鏈変釜鏂囦欢澶 log 閲岄潰鏈夐敊璇棩蹇楁枃浠 +## 馃敡 浣跨敤璇存槑 + +濡傛灉閮ㄧ讲 iis 璁块棶涓嶄簡鎯呭喌鍙互鏈変互涓嬩袱绉嶅姙娉曪細 + +1. 鐩存帴鎵撳紑 ZR.Admin.WebApi.exe 鏂囦欢鐒跺悗鐪嬫帶鍒跺彴鐨勯敊璇棩蹇 +2. web.config 閲岄潰鏈変釜 false 鏀逛负 true锛宨is 閲嶅惎椤圭洰鍚庤繍琛岀綉绔欏悗锛岃窡鐩綍涓嬮潰 鏈変釜鏂囦欢澶 log 閲岄潰鏈夐敊璇棩蹇楁枃浠 diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index 2038e6ab2e70a11266718722cad4d07145e6ba56..4b98568b902f1e12876c590b7238dccd4ea6002c 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -2,12 +2,14 @@ using Infrastructure.Model; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; +using MiniExcelLibs; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -using OfficeOpenXml; using System; using System.Collections.Generic; using System.IO; +using System.Web; +using ff = System.IO; namespace ZR.Admin.WebApi.Controllers { @@ -53,6 +55,21 @@ namespace ZR.Admin.WebApi.Controllers return ToResponse(GetApiResult(resultCode, msg)); } + /// + /// 瀵煎嚭Excel + /// + /// 瀹屾暣鏂囦欢璺緞 + /// 甯︽墿灞曟枃浠跺悕 + /// + protected IActionResult ExportExcel(string path, string fileName) + { + //IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); + //string fileDir = Path.Combine(webHostEnvironment.WebRootPath, path, fileName); + + var stream = ff.File.OpenRead(path); //鍒涘缓鏂囦欢娴 + return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName)); + } + #region 鏂规硶 /// @@ -112,25 +129,38 @@ namespace ZR.Admin.WebApi.Controllers /// /// protected string ExportExcel(List list, string sheetName, string fileName) + { + return ExportExcelMini(list, sheetName, fileName).Item1; + } + + protected (string, string) ExportExcelMini(List list, string sheetName, string fileName) { IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); - string sFileName = $"{fileName}{DateTime.Now:MMddHHmmss}.xlsx"; - string newFileName = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName); - //璋冭瘯妯″紡闇瑕佸姞涓 - ExcelPackage.LicenseContext = LicenseContext.NonCommercial; - Directory.CreateDirectory(Path.GetDirectoryName(newFileName)); - using (ExcelPackage package = new(new FileInfo(newFileName))) - { - // 娣诲姞worksheet - ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(sheetName); - //鍗曞厓鏍艰嚜鍔ㄩ傚簲澶у皬 - worksheet.Cells.Style.ShrinkToFit = true; - //鍏ㄩ儴瀛楁瀵煎嚭 - worksheet.Cells.LoadFromCollection(list, true, OfficeOpenXml.Table.TableStyles.Light13); - package.Save(); - } + string sFileName = $"{fileName}{DateTime.Now:MM-dd-HHmmss}.xlsx"; + string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName); + + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); - return sFileName; + MiniExcel.SaveAs(fullPath, list, sheetName: sheetName); + return (sFileName, fullPath); + } + + /// + /// 瀵煎嚭澶氫釜宸ヤ綔琛(Sheet) + /// + /// + /// + /// + protected (string, string) ExportExcelMini(Dictionary sheets, string fileName) + { + IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); + string sFileName = $"{fileName}{DateTime.Now:MM-dd-HHmmss}.xlsx"; + string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName); + + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); + + MiniExcel.SaveAs(fullPath, sheets); + return (sFileName, fullPath); } /// @@ -146,23 +176,12 @@ namespace ZR.Admin.WebApi.Controllers IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); string sFileName = $"{fileName}妯℃澘.xlsx"; string newFileName = Path.Combine(webHostEnvironment.WebRootPath, "importTemplate", sFileName); - //璋冭瘯妯″紡闇瑕佸姞涓 - ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + if (!Directory.Exists(newFileName)) { Directory.CreateDirectory(Path.GetDirectoryName(newFileName)); } - using (ExcelPackage package = new(new FileInfo(newFileName))) - { - // 娣诲姞worksheet - ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(fileName); - //鍗曞厓鏍艰嚜鍔ㄩ傚簲澶у皬 - worksheet.Cells.Style.ShrinkToFit = true; - //鍏ㄩ儴瀛楁瀵煎嚭 - worksheet.Cells.LoadFromCollection(list, true, OfficeOpenXml.Table.TableStyles.Light13); - package.SaveAs(stream); - } - + MiniExcel.SaveAs(newFileName, list); return sFileName; } } diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index 3c549e53dd055816345acd0e275a842862d4f9d5..16d597528a1e6554739f73af9abbbf450116428c 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -16,6 +16,7 @@ using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model.System; +using ZR.Model.System.Dto; using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers @@ -47,7 +48,7 @@ namespace ZR.Admin.WebApi.Controllers public IActionResult Index() { return Ok("鐪嬪埌杩欓噷椤甸潰璇存槑浣犲凡缁忔垚鍔熷惎鍔ㄤ簡鏈」鐩:)\n\n" + - "濡傛灉瑙夊緱椤圭洰鏈夌敤锛屾墦璧忎綔鑰呭枬鏉挅鍟′綔涓哄鍔盶n鈽涒槢http://www.izhaorui.cn/doc\n"); + "濡傛灉瑙夊緱椤圭洰鏈夌敤锛屾墦璧忎綔鑰呭枬鏉挅鍟′綔涓哄鍔盶n鈽涒槢http://www.izhaorui.cn/doc/support.html\n"); } /// @@ -88,44 +89,55 @@ namespace ZR.Admin.WebApi.Controllers /// /// 瀛樺偍鏂囦欢 /// - /// - /// 瀛樺偍鐩綍 - /// 鑷畾涔夋枃浠跺悕 + /// 鑷畾涔夋枃浠跺悕 /// 涓婁紶绫诲瀷1銆佷繚瀛樺埌鏈湴 2銆佷繚瀛樺埌闃块噷浜 /// [HttpPost()] [Verify] [ActionPermissionFilter(Permission = "common")] - public async Task UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileName = "", string fileDir = "", StoreType storeType = StoreType.LOCAL) + public async Task UploadFile([FromForm] UploadDto uploadDto, StoreType storeType = StoreType.LOCAL) { + IFormFile formFile = uploadDto.File; if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "涓婁紶鏂囦欢涓嶈兘涓虹┖"); SysFile file = new(); string fileExt = Path.GetExtension(formFile.FileName);//鏂囦欢鍚庣紑 double fileSize = Math.Round(formFile.Length / 1024.0, 2);//鏂囦欢澶у皬KB - string[] NotAllowedFileExtensions = new string[] { ".bat", ".exe", ".jar", ".js" }; - int MaxContentLength = 15; - if (NotAllowedFileExtensions.Contains(fileExt)) + + if (OptionsSetting.Upload.NotAllowedExt.Contains(fileExt)) { return ToResponse(ResultCode.CUSTOM_ERROR, "涓婁紶澶辫触锛屾湭缁忓厑璁镐笂浼犵被鍨"); } + if (uploadDto.FileNameType == 1) + { + uploadDto.FileName = Path.GetFileNameWithoutExtension(formFile.FileName); + } + else if (uploadDto.FileNameType == 3) + { + uploadDto.FileName = SysFileService.HashFileName(); + } switch (storeType) { case StoreType.LOCAL: string savePath = Path.Combine(WebHostEnvironment.WebRootPath); - if (fileDir.IsEmpty()) + if (uploadDto.FileDir.IsEmpty()) { - fileDir = AppSettings.App(new string[] { "Upload", "localSavePath" }); + uploadDto.FileDir = OptionsSetting.Upload.LocalSavePath; } - file = await SysFileService.SaveFileToLocal(savePath, fileName, fileDir, HttpContext.GetName(), formFile); + file = await SysFileService.SaveFileToLocal(savePath, uploadDto.FileName, uploadDto.FileDir, HttpContext.GetName(), formFile); break; case StoreType.REMOTE: break; case StoreType.ALIYUN: - if ((fileSize / 1024) > MaxContentLength) + int AlimaxContentLength = OptionsSetting.ALIYUN_OSS.MaxSize; + if (OptionsSetting.ALIYUN_OSS.REGIONID.IsEmpty()) { - return ToResponse(ResultCode.CUSTOM_ERROR, "涓婁紶鏂囦欢杩囧ぇ锛屼笉鑳借秴杩 " + MaxContentLength + " MB"); + return ToResponse(ResultCode.CUSTOM_ERROR, "閰嶇疆鏂囦欢缂哄け"); } - file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, HttpContext.GetName()) + if ((fileSize / 1024) > AlimaxContentLength) + { + return ToResponse(ResultCode.CUSTOM_ERROR, "涓婁紶鏂囦欢杩囧ぇ锛屼笉鑳借秴杩 " + AlimaxContentLength + " MB"); + } + file = new(formFile.FileName, uploadDto.FileName, fileExt, fileSize + "kb", uploadDto.FileDir, HttpContext.GetName()) { StoreType = (int)StoreType.ALIYUN, FileType = formFile.ContentType @@ -149,47 +161,23 @@ namespace ZR.Admin.WebApi.Controllers }); } + #endregion + } + + public class UploadDto + { /// - /// 瀛樺偍鏂囦欢鍒伴樋閲屼簯(宸插純鐢) + /// 鑷畾鏂囦欢鍚 /// - /// - /// 鑷畾涔夋枃浠跺悕 - /// 涓婁紶鏂囦欢澶硅矾寰 - /// - [HttpPost] - [Verify] - [ActionPermissionFilter(Permission = "common")] - public async Task UploadFileAliyun([FromForm(Name = "file")] IFormFile formFile, string fileName = "", string fileDir = "") - { - if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "涓婁紶鏂囦欢涓嶈兘涓虹┖"); - string fileExt = Path.GetExtension(formFile.FileName);//鏂囦欢鍚庣紑 - double fileSize = Math.Round(formFile.Length / 1024.0, 2);//鏂囦欢澶у皬KB - string[] NotAllowedFileExtensions = new string[] { ".bat", ".exe", ".jar", ".js" }; - int MaxContentLength = 15; - if (NotAllowedFileExtensions.Contains(fileExt)) - { - return ToResponse(ResultCode.CUSTOM_ERROR, "涓婁紶澶辫触锛屾湭缁忓厑璁镐笂浼犵被鍨"); - } - if ((fileSize / 1024) > MaxContentLength) - { - return ToResponse(ResultCode.CUSTOM_ERROR, "涓婁紶鏂囦欢杩囧ぇ锛屼笉鑳借秴杩 " + MaxContentLength + " MB"); - } - SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, HttpContext.GetName()) - { - StoreType = (int)StoreType.ALIYUN, - FileType = formFile.ContentType - }; - file = await SysFileService.SaveFileToAliyun(file, formFile); - - if (file.Id <= 0) { return ToResponse(ApiResult.Error("闃块噷浜戣繛鎺ュけ璐")); } - - return SUCCESS(new - { - url = file.AccessUrl, - fileName = file.FileName, - fileId = file.Id.ToString() - }); - } - #endregion + public string FileName { get; set; } + /// + /// 瀛樺偍鐩綍 + /// + public string FileDir { get; set; } + /// + /// 鏂囦欢鍚嶇敓鎴愮被鍨 1 鍘熸枃浠跺悕 2 鑷畾涔 3 鑷姩鐢熸垚 + /// + public int FileNameType { get; set; } + public IFormFile File { get; set; } } } diff --git a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs index cb52d64aab894a9f2795266f8f7383201316e9a0..66f75f3ede4a4b02359e1d85186cdd2e4b115b85 100644 --- a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs @@ -1,12 +1,16 @@ -锘縰sing Infrastructure; +锘縰sing Aliyun.OSS; +using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; using Mapster; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SqlSugar; +using System; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; +using ZR.Common; using ZR.Model.System; using ZR.Model.System.Dto; using ZR.Service.System.IService; @@ -40,12 +44,7 @@ namespace ZR.Admin.WebApi.Controllers [ActionPermissionFilter(Permission = "system:article:list")] public IActionResult Query([FromQuery] ArticleQueryDto parm) { - var predicate = Expressionable.Create
(); - - predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Title), m => m.Title.Contains(parm.Title)); - predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Status), m => m.Status == parm.Status); - - var response = _ArticleService.GetPages(predicate.ToExpression(), parm, f => f.Cid, OrderByType.Desc); + var response = _ArticleService.GetList(parm); return SUCCESS(response); } @@ -62,6 +61,7 @@ namespace ZR.Admin.WebApi.Controllers var response = _ArticleService.Queryable() .Where(predicate.ToExpression()) + .Includes(x => x.ArticleCategoryNav) //濉厖瀛愬璞 .Take(10) .OrderBy(f => f.UpdateTime, OrderByType.Desc).ToList(); @@ -74,11 +74,17 @@ namespace ZR.Admin.WebApi.Controllers /// /// [HttpGet("{id}")] + [AllowAnonymous] public IActionResult Get(int id) { var response = _ArticleService.GetId(id); - - return SUCCESS(response); + var model = response.Adapt(); + if (model != null) + { + model.ArticleCategoryNav = _ArticleCategoryService.GetById(model.CategoryId); + model.TagList = model.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries); + } + return SUCCESS(model); } /// @@ -88,7 +94,7 @@ namespace ZR.Admin.WebApi.Controllers [HttpPost("add")] [ActionPermissionFilter(Permission = "system:article:add")] [Log(Title = "鏂囩珷娣诲姞", BusinessType = BusinessType.INSERT)] - public IActionResult Create([FromBody] Article parm) + public IActionResult Create([FromBody] ArticleDto parm) { if (parm == null) { @@ -107,25 +113,16 @@ namespace ZR.Admin.WebApi.Controllers [HttpPut("edit")] [ActionPermissionFilter(Permission = "system:article:update")] [Log(Title = "鏂囩珷淇敼", BusinessType = BusinessType.UPDATE)] - public IActionResult Update([FromBody] Article parm) + public IActionResult Update([FromBody] ArticleDto parm) { if (parm == null) { throw new CustomException("璇锋眰鍙傛暟閿欒"); } parm.AuthorName = HttpContext.GetName(); + var modal = parm.Adapt
().ToUpdate(HttpContext); - var response = _ArticleService.Update(it => it.Cid == parm.Cid, - f => new Article - { - Title = parm.Title, - Content = parm.Content, - Tags = parm.Tags, - Category_Id = parm.Category_Id, - UpdateTime = parm.UpdateTime, - Status = parm.Status, - CoverUrl = parm.CoverUrl - }); + var response = _ArticleService.UpdateArticle(modal); return SUCCESS(response); } diff --git a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs index 75621ad44de7c8c360de3981159bca90b618bdec..67d1fc60cc9b691fc3d11569d740d98f5a0dbc82 100644 --- a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs @@ -54,7 +54,7 @@ namespace ZR.Admin.WebApi.Controllers public IActionResult GetListDataBase() { var dbList = _CodeGeneraterService.GetAllDataBases(); - var defaultDb = dbList.Count > 0 ? dbList[0] : null; + var defaultDb = dbList?[0]; return SUCCESS(new { dbList, defaultDb }); } @@ -94,7 +94,7 @@ namespace ZR.Admin.WebApi.Controllers //鏌ヨ鍘熻〃鏁版嵁锛岄儴鍒嗗瓧娈垫槧灏勫埌浠g爜鐢熸垚琛ㄥ瓧娈 var rows = GenTableService.GetGenTables(new GenTable() { TableName = tableName }, pagerInfo); - return SUCCESS(rows); + return SUCCESS(rows, "MM鏈坉d鏃 HH:mm"); } /// @@ -227,9 +227,11 @@ namespace ZR.Admin.WebApi.Controllers [ActionPermissionFilter(Permission = "tool:gen:preview")] public IActionResult Preview(long tableId = 0, int VueVersion = 0) { - GenerateDto dto = new(); - dto.TableId = tableId; - dto.VueVersion = VueVersion; + GenerateDto dto = new() + { + TableId = tableId, + VueVersion = VueVersion + }; if (dto == null || dto.TableId <= 0) { throw new CustomException(ResultCode.CUSTOM_ERROR, "璇锋眰鍙傛暟涓虹┖"); diff --git a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs index d3b19a5f8cfc2c480a635b47d95a79975aa578ac..8264d0e576b12752d60114eec21eed47f260bcbf 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs @@ -12,7 +12,7 @@ using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model.Dto; using ZR.Model.System; -using ZR.Service.System; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers { diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs index b7b8c3e000b73ddd26eaa12ea262541fba0d1491..56cd88565882db39b35c0c5ed8c4e99ac24102c8 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs @@ -76,6 +76,10 @@ namespace ZR.Admin.WebApi.Controllers.System ColumnName = dic.ColumnName, List = list.FindAll(f => f.DictType == dic.DictType) }; + if (dic.DictType.StartsWith("cus_") || dic.DictType.StartsWith("sql_")) + { + vo.List = SysDictService.SelectDictDataByCustomSql(dic.DictType); + } dataVos.Add(vo); } return SUCCESS(dataVos); diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs index 8c7389baf0126c94578f4a9269fd27c5929d105b..f70cb3cdd3bd923ed122431acd1eff8d2f69198e 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs @@ -1,6 +1,7 @@ 锘縰sing Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; +using Mapster; using Microsoft.AspNetCore.Mvc; using System; using ZR.Admin.WebApi.Extensions; @@ -8,6 +9,7 @@ using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model; using ZR.Model.System; +using ZR.Model.System.Dto; using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System @@ -56,13 +58,14 @@ namespace ZR.Admin.WebApi.Controllers.System /// /// 娣诲姞瀛楀吀绫诲瀷 /// - /// + /// /// [ActionPermissionFilter(Permission = "system:dict:add")] [Log(Title = "瀛楀吀鎿嶄綔", BusinessType = BusinessType.INSERT)] [HttpPost("edit")] - public IActionResult Add([FromBody] SysDictType dict) + public IActionResult Add([FromBody] SysDictTypeDto dto) { + SysDictType dict = dto.Adapt(); if (UserConstants.NOT_UNIQUE.Equals(SysDictService.CheckDictTypeUnique(dict))) { return ToResponse(ApiResult.Error($"鏂板瀛楀吀'{dict.DictName}'澶辫触锛屽瓧鍏哥被鍨嬪凡瀛樺湪")); @@ -75,14 +78,15 @@ namespace ZR.Admin.WebApi.Controllers.System /// /// 淇敼瀛楀吀绫诲瀷 /// - /// + /// /// [ActionPermissionFilter(Permission = "system:dict:edit")] [Log(Title = "瀛楀吀鎿嶄綔", BusinessType = BusinessType.UPDATE)] [Route("edit")] [HttpPut] - public IActionResult Edit([FromBody] SysDictType dict) + public IActionResult Edit([FromBody] SysDictTypeDto dto) { + SysDictType dict = dto.Adapt(); if (UserConstants.NOT_UNIQUE.Equals(SysDictService.CheckDictTypeUnique(dict))) { return ToResponse(ApiResult.Error($"淇敼瀛楀吀'{dict.DictName}'澶辫触锛屽瓧鍏哥被鍨嬪凡瀛樺湪")); diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index ee5bb7a84e1d19f3cf7993dab010cbcf20a6e417..4ec9336ec1ec18449874068973c418a0aa343053 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -67,7 +67,7 @@ namespace ZR.Admin.WebApi.Controllers.System /// [Route("login")] [HttpPost] - //[Log(Title = "鐧诲綍")] + [Log(Title = "鐧诲綍")] public IActionResult Login([FromBody] LoginBodyDto loginBody) { if (loginBody == null) { throw new CustomException("璇锋眰鍙傛暟閿欒"); } @@ -155,7 +155,24 @@ namespace ZR.Admin.WebApi.Controllers.System SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff"); var captchaOff = sysConfig?.ConfigValue ?? "0"; - var code = SecurityCodeHelper.GetRandomEnDigitalText(4); + var length = AppSettings.GetAppConfig("CaptchaOptions:length", 4); + var code = SecurityCodeHelper.GetRandomEnDigitalText(length); + byte[] imgByte = GenerateCaptcha(captchaOff, code); + string base64Str = Convert.ToBase64String(imgByte); + CacheHelper.SetCache(uuid, code); + var obj = new { captchaOff, uuid, img = base64Str };// File(stream, "image/png") + + return ToJson(1, obj); + } + + /// + /// 鐢熸垚鍥剧墖楠岃瘉鐮 + /// + /// + /// + /// + private byte[] GenerateCaptcha(string captchaOff, string code) + { byte[] imgByte; if (captchaOff == "1") { @@ -173,11 +190,8 @@ namespace ZR.Admin.WebApi.Controllers.System { imgByte = SecurityCodeHelper.GetEnDigitalCodeByte(code);//鑻辨枃瀛楁瘝鍔犳暟瀛 } - string base64Str = Convert.ToBase64String(imgByte); - CacheHelper.SetCache(uuid, code); - var obj = new { uuid, img = base64Str };// File(stream, "image/png") - return ToJson(1, obj); + return imgByte; } /// @@ -192,13 +206,13 @@ namespace ZR.Admin.WebApi.Controllers.System ClientInfo clientInfo = context.GetClientInfo(); SysLogininfor sysLogininfor = new() { - browser = clientInfo.Device.Family, - os = clientInfo.OS.ToString(), - ipaddr = ipAddr, - userName = context.GetName(), - loginLocation = ip_info.Province + "-" + ip_info.City + Browser = clientInfo.ToString(), + Os = clientInfo.OS.ToString(), + Ipaddr = ipAddr, + UserName = context.GetName(), + LoginLocation = ip_info?.Province + "-" + ip_info?.City }; - + return sysLogininfor; } diff --git a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs index 7281ead620b816c1651e595d2ff4c42dc131f89b..48f8063d01cc2c82cb1cdaeafc54f060a527a49d 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs @@ -21,13 +21,16 @@ namespace ZR.Admin.WebApi.Controllers.System { private readonly ISysRoleService sysRoleService; private readonly ISysMenuService sysMenuService; + private readonly ISysRoleMenuService sysRoleMenuService; public SysMenuController( ISysRoleService sysRoleService, - ISysMenuService sysMenuService) + ISysMenuService sysMenuService, + ISysRoleMenuService sysRoleMenuService) { this.sysRoleService = sysRoleService; this.sysMenuService = sysMenuService; + this.sysRoleMenuService = sysRoleMenuService; } /// @@ -63,7 +66,8 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:menu:query")] public IActionResult GetMenuList(int menuId = 0) { - return SUCCESS(sysMenuService.GetMenusByMenuId(menuId), "yyyy-MM-dd HH:mm:ss"); + long userId = HttpContext.GetUId(); + return SUCCESS(sysMenuService.GetMenusByMenuId(menuId, userId), "yyyy-MM-dd HH:mm:ss"); } /// @@ -106,11 +110,11 @@ namespace ZR.Admin.WebApi.Controllers.System .NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);//蹇界暐瀛楁鍚嶇О鐨勫ぇ灏忓啓;//蹇界暐闄や互涓婇厤缃殑鎵鏈夊瓧娈 var modal = menuDto.Adapt(config).ToUpdate(HttpContext); - if (UserConstants.YES_FRAME.Equals(modal.isFrame) && !modal.path.StartsWith("http")) + if (UserConstants.YES_FRAME.Equals(modal.IsFrame) && !modal.Path.StartsWith("http")) { return ToResponse(ApiResult.Error($"淇敼鑿滃崟'{modal.MenuName}'澶辫触锛屽湴鍧蹇呴』浠ttp(s)://寮澶")); } - if (modal.MenuId.Equals(modal.parentId)) + if (modal.MenuId.Equals(modal.ParentId)) { return ToResponse(ApiResult.Error($"淇敼鑿滃崟'{modal.MenuName}'澶辫触锛屼笂绾ц彍鍗曚笉鑳介夋嫨鑷繁")); } @@ -141,7 +145,7 @@ namespace ZR.Admin.WebApi.Controllers.System { return ToResponse(ApiResult.Error($"鏂板鑿滃崟'{menu.MenuName}'澶辫触锛岃彍鍗曞悕绉板凡瀛樺湪")); } - if (UserConstants.YES_FRAME.Equals(menu.isFrame) && !menu.path.StartsWith("http")) + if (UserConstants.YES_FRAME.Equals(menu.IsFrame) && !menu.Path.StartsWith("http")) { return ToResponse(ApiResult.Error($"鏂板鑿滃崟'{menu.MenuName}'澶辫触锛屽湴鍧蹇呴』浠ttp(s)://寮澶")); } @@ -166,7 +170,7 @@ namespace ZR.Admin.WebApi.Controllers.System { return ToResponse(ResultCode.CUSTOM_ERROR, "瀛樺湪瀛愯彍鍗,涓嶅厑璁稿垹闄"); } - if (sysMenuService.CheckMenuExistRole(menuId)) + if (sysRoleMenuService.CheckMenuExistRole(menuId)) { return ToResponse(ResultCode.CUSTOM_ERROR, "鑿滃崟宸插垎閰,涓嶅厑璁稿垹闄"); } @@ -189,7 +193,7 @@ namespace ZR.Admin.WebApi.Controllers.System MenuDto MenuDto = new() { MenuId = id, - orderNum = value + OrderNum = value }; if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "璇锋眰鍙傛暟閿欒")); } diff --git a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs index a69dfebd8628f2a61b255dd52681f178b292b437..5527c811a51194ebd9cd6a9b93be12f655a7e3ac 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs @@ -134,8 +134,8 @@ namespace ZR.Admin.WebApi.Controllers.System { var list = PostService.GetAll(); - string sFileName = ExportExcel(list, "syspost", "宀椾綅"); - return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); + var result = ExportExcelMini(list, "post", "宀椾綅鍒楄〃"); + return ExportExcel(result.Item2, result.Item1); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index eb8dea158daa078695daf203d6e49c20d88b09a1..3c1bc18db188bf4701f0d789c358e95b3b27de56 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -93,9 +93,8 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "淇敼瀵嗙爜", BusinessType = BusinessType.UPDATE)] public IActionResult UpdatePwd(string oldPassword, string newPassword) { - LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext); - - SysUser user = UserService.SelectUserById(loginUser.UserId); + long userId = HttpContext.GetUId(); + SysUser user = UserService.SelectUserById(userId); string oldMd5 = NETCore.Encrypt.EncryptProvider.Md5(oldPassword); string newMd5 = NETCore.Encrypt.EncryptProvider.Md5(newPassword); if (!user.Password.Equals(oldMd5, StringComparison.OrdinalIgnoreCase)) @@ -106,7 +105,7 @@ namespace ZR.Admin.WebApi.Controllers.System { return ToResponse(ApiResult.Error("鏂板瘑鐮佷笉鑳藉拰鏃у瘑鐮佺浉鍚")); } - if (UserService.ResetPwd(loginUser.UserId, newMd5) > 0) + if (UserService.ResetPwd(userId, newMd5) > 0) { //TODO 鏇存柊缂撳瓨 @@ -126,12 +125,12 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "淇敼澶村儚", BusinessType = BusinessType.UPDATE, IsSaveRequestData = false)] public async Task Avatar([FromForm(Name = "picture")] IFormFile formFile) { - LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext); + long userId = HttpContext.GetUId(); if (formFile == null) throw new CustomException("璇烽夋嫨鏂囦欢"); SysFile file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, "", "avatar", HttpContext.GetName(), formFile); - UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = loginUser.UserId }); + UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = userId }); return SUCCESS(new { imgUrl = file.AccessUrl }); } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs index 7e6372dae9b944fa08e271fc2f4b9720bf730906..365795a945acb8f0d7b3f365073c6c2d37c76f77 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs @@ -2,17 +2,21 @@ using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using MiniExcelLibs; +using SqlSugar; using System.Collections.Generic; -using System.IO; +using System.Linq; +using System.Web; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model; using ZR.Model.System; using ZR.Service.System.IService; - +using ff = System.IO; namespace ZR.Admin.WebApi.Controllers.System { /// @@ -26,17 +30,18 @@ namespace ZR.Admin.WebApi.Controllers.System private readonly ISysRoleService RoleService; private readonly ISysPostService PostService; private readonly ISysUserPostService UserPostService; - + private readonly IWebHostEnvironment WebHostEnvironment; public SysUserController( ISysUserService userService, ISysRoleService roleService, ISysPostService postService, - ISysUserPostService userPostService) + ISysUserPostService userPostService, IWebHostEnvironment webHostEnvironment) { UserService = userService; RoleService = roleService; PostService = postService; UserPostService = userPostService; + WebHostEnvironment = webHostEnvironment; } /// @@ -60,6 +65,7 @@ namespace ZR.Admin.WebApi.Controllers.System /// [HttpGet("")] [HttpGet("{userId:int=0}")] + [ActionPermissionFilter(Permission = "system:user:query")] public IActionResult GetInfo(int userId) { Dictionary dic = new(); @@ -95,7 +101,10 @@ namespace ZR.Admin.WebApi.Controllers.System { return ToResponse(ApiResult.Error($"鏂板鐢ㄦ埛 '{user.UserName}'澶辫触锛岀櫥褰曡处鍙峰凡瀛樺湪")); } - + if (!Tools.CheckUserName(user.UserName)) + { + return ToResponse(ApiResult.Error($"鐢ㄦ埛鍚嶈浣跨敤瀛楁瘝寮澶村彲鍖呭惈澶у皬鍐欏瓧姣嶆暟瀛梍-")); + } user.Create_by = HttpContext.GetName(); user.Password = NETCore.Encrypt.EncryptProvider.Md5(user.Password); @@ -159,7 +168,7 @@ namespace ZR.Admin.WebApi.Controllers.System /// [HttpPut("resetPwd")] [Log(Title = "閲嶇疆瀵嗙爜", BusinessType = BusinessType.UPDATE)] - [ActionPermissionFilter(Permission = "system:user:update")] + [ActionPermissionFilter(Permission = "system:user:resetPwd")] public IActionResult ResetPwd([FromBody] SysUser sysUser) { //瀵嗙爜md5 @@ -175,14 +184,20 @@ namespace ZR.Admin.WebApi.Controllers.System /// 浣跨敤IFromFile蹇呴』浣跨敤name灞炴у惁鍒欒幏鍙栦笉鍒版枃浠 /// [HttpPost("importData")] - [Log(Title = "鐢ㄦ埛瀵煎叆", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)] + [Log(Title = "鐢ㄦ埛瀵煎叆", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)] [ActionPermissionFilter(Permission = "system:user:import")] public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile) { - IEnumerable users = ExcelHelper.ImportData(formFile.OpenReadStream()); + //List users = (List)ExcelHelper.ImportData(formFile.OpenReadStream()); + List users = new(); + using (var stream = formFile.OpenReadStream()) + { + users = stream.Query().ToList(); + } - //TODO 涓氬姟閫昏緫,鑷鎻掑叆鏁版嵁鍒癲b - return SUCCESS(users); + string msg = UserService.ImportUsers(users); + + return ToResponse(Infrastructure.ResultCode.SUCCESS, msg); } /// @@ -194,11 +209,11 @@ namespace ZR.Admin.WebApi.Controllers.System [AllowAnonymous] public IActionResult ImportTemplateExcel() { - List user = new List(); - MemoryStream stream = new MemoryStream(); + string fileDir = ff.Path.Combine(WebHostEnvironment.WebRootPath, "importTemplate", "user.xlsx"); + + var stream = ff.File.OpenRead(fileDir); //鍒涘缓鏂囦欢娴 - string sFileName = DownloadImportTemplate(user, stream, "鐢ㄦ埛鍒楄〃"); - return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}"); + return File(stream, "text/plain", "user.xlsx"); } /// @@ -213,9 +228,8 @@ namespace ZR.Admin.WebApi.Controllers.System { var list = UserService.SelectUserList(user, new PagerInfo(1, 10000)); - //璋冭瘯妯″紡闇瑕佸姞涓 - string sFileName = ExportExcel(list.Result, "user", "鐢ㄦ埛鍒楄〃"); - return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); + var result = ExportExcelMini(list.Result, "user", "鐢ㄦ埛鍒楄〃"); + return ExportExcel(result.Item2, result.Item1); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/TasksController.cs b/ZR.Admin.WebApi/Controllers/System/TasksController.cs index cbabbb0c696283554d597cb84137dd6cffb5eae1..fa85010ed77144daa1787e11117fe83e3281774e 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksController.cs @@ -14,7 +14,6 @@ using ZR.Model.System.Dto; using ZR.Model.System; using ZR.Service.System.IService; using ZR.Tasks; -using Snowflake.Core; using Infrastructure.Extensions; namespace ZR.Admin.WebApi.Controllers @@ -43,17 +42,18 @@ namespace ZR.Admin.WebApi.Controllers /// [HttpGet("list")] [ActionPermissionFilter(Permission = "monitor:job:list")] - public IActionResult Query([FromQuery] TasksQueryDto parm, [FromQuery] PagerInfo pager) + public IActionResult ListTask([FromQuery] TasksQueryDto parm, [FromQuery] PagerInfo pager) { //寮濮嬫嫾瑁呮煡璇㈡潯浠 - var predicate = Expressionable.Create(); + var predicate = Expressionable.Create(); predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.QueryText), m => m.Name.Contains(parm.QueryText) || m.JobGroup.Contains(parm.QueryText) || m.AssemblyName.Contains(parm.QueryText)); + predicate.AndIF(parm.TaskType != null, m => m.TaskType == parm.TaskType); - var response = _tasksQzService.GetPages(predicate.ToExpression(), pager, f => f.IsStart, OrderByType.Desc); + var response = _tasksQzService.GetPages(predicate.ToExpression(), pager); return SUCCESS(response, TIME_FORMAT_FULL); } @@ -95,15 +95,18 @@ namespace ZR.Admin.WebApi.Controllers { throw new CustomException($"鍦板潃涓嶈兘涓虹┖"); } + if (string.IsNullOrEmpty(parm.SqlText) && parm.TaskType == 3) + { + throw new CustomException($"sql璇彞涓嶈兘涓虹┖"); + } if (parm.TaskType == 1 && (parm.AssemblyName.IsEmpty() || parm.ClassName.IsEmpty())) { throw new CustomException($"绋嬪簭闆嗘垨鑰呯被鍚嶄笉鑳戒负绌"); } //浠 Dto 鏄犲皠鍒 瀹炰綋 - var tasksQz = parm.Adapt().ToCreate(); - var worker = new IdWorker(1, 1); + var tasksQz = parm.Adapt().ToCreate(); tasksQz.Create_by = HttpContext.GetName(); - tasksQz.ID = worker.NextId().ToString(); + tasksQz.ID = SnowFlakeSingle.Instance.NextId().ToString(); return SUCCESS(_tasksQzService.AddTasks(tasksQz)); } @@ -115,7 +118,7 @@ namespace ZR.Admin.WebApi.Controllers [HttpPost("update")] [ActionPermissionFilter(Permission = "monitor:job:edit")] [Log(Title = "淇敼浠诲姟", BusinessType = BusinessType.UPDATE)] - public async Task Update([FromBody] TasksUpdateDto parm) + public async Task Update([FromBody] TasksCreateDto parm) { //鍒ゆ柇鏄惁宸茬粡瀛樺湪 if (_tasksQzService.Any(m => m.Name == parm.Name && m.ID != parm.ID)) @@ -135,16 +138,12 @@ namespace ZR.Admin.WebApi.Controllers { throw new CustomException($"api鍦板潃涓嶈兘涓虹┖"); } - if (parm.ApiUrl.IfNotEmpty() && parm.TaskType == 2) - { - parm.AssemblyName = "ZR.Tasks"; - parm.ClassName = "TaskScheduler.Job_HttpRequest"; - } + if (tasksQz.IsStart) { throw new CustomException($"璇ヤ换鍔℃鍦ㄨ繍琛屼腑锛岃鍏堝仠姝㈠湪鏇存柊"); } - var model = parm.Adapt(); + var model = parm.Adapt(); model.Update_by = HttpContextExtension.GetName(HttpContext); int response = _tasksQzService.UpdateTasks(model); if (response > 0) diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs index f66d19e08bd7891b0703b7c2b4306dda1f36a16e..189a1f5ac5ff639df3e695860c0ff297872239f8 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs @@ -87,7 +87,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor logininfoDto.BeginTime = DateTimeHelper.GetBeginTime(logininfoDto.BeginTime, -1); logininfoDto.EndTime = DateTimeHelper.GetBeginTime(logininfoDto.EndTime, 1); var exp = Expressionable.Create() - .And(it => it.loginTime >= logininfoDto.BeginTime && it.loginTime <= logininfoDto.EndTime); + .And(it => it.LoginTime >= logininfoDto.BeginTime && it.LoginTime <= logininfoDto.EndTime); var list = sysLoginService.Queryable().Where(exp.ToExpression()) .ToList(); diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs index 7712044998d85859571f18c5b9e9c6ec8f09136c..a6fd1a1e55f874d343261eef1ca0ba0fe69600b4 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs @@ -36,12 +36,12 @@ namespace ZR.Admin.WebApi.Controllers.monitor [HttpGet("list")] public IActionResult OperList([FromQuery] SysOperLogDto sysOperLog) { - PagerInfo pagerInfo = new(sysOperLog.pageNum, sysOperLog.PageSize); + PagerInfo pagerInfo = new(sysOperLog.PageNum, sysOperLog.PageSize); - sysOperLog.operName = !HttpContextExtension.IsAdmin(HttpContext) ? HttpContextExtension.GetName(HttpContext) : sysOperLog.operName; + sysOperLog.OperName = !HttpContextExtension.IsAdmin(HttpContext) ? HttpContextExtension.GetName(HttpContext) : sysOperLog.OperName; var list = sysOperLogService.SelectOperLogList(sysOperLog, pagerInfo); - return SUCCESS(list, "MM/dd HH:mm"); + return SUCCESS(list); } /// @@ -90,8 +90,8 @@ namespace ZR.Admin.WebApi.Controllers.monitor public IActionResult Export([FromQuery] SysOperLogDto sysOperLog) { var list = sysOperLogService.SelectOperLogList(sysOperLog, new PagerInfo(1, 10000)); - string sFileName = ExportExcel(list.Result, "operlog", "鎿嶄綔鏃ュ織"); - return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); + var result = ExportExcelMini(list.Result, "鎿嶄綔鏃ュ織", "鎿嶄綔鏃ュ織"); + return ExportExcel(result.Item2, result.Item1); } } diff --git a/Infrastructure/Extensions/AppServiceExtensions.cs b/ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs similarity index 81% rename from Infrastructure/Extensions/AppServiceExtensions.cs rename to ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs index 4f3f5e5be91629809aa8158742d407762fe4bf0f..f888f1fe034fad82896ff2fd984c24e2605b6432 100644 --- a/Infrastructure/Extensions/AppServiceExtensions.cs +++ b/ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs @@ -1,11 +1,13 @@ 锘縰sing Infrastructure.Attribute; using Microsoft.Extensions.DependencyInjection; -using System; using System.Linq; using System.Reflection; -namespace Infrastructure.Extensions +namespace ZR.Admin.WebApi.Extensions { + /// + /// App鏈嶅姟娉ㄥ唽 + /// public static class AppServiceExtensions { /// @@ -14,18 +16,16 @@ namespace Infrastructure.Extensions /// public static void AddAppService(this IServiceCollection services) { - //var assemblies = AppDomain.CurrentDomain.GetAssemblies(); - - string []cls = new string[] { "ZR.Repository", "ZR.Service", "ZR.Tasks" }; + string[] cls = new string[] { "ZR.Repository", "ZR.Service", "ZR.Tasks" }; foreach (var item in cls) { - Assembly assembly = Assembly.Load(item); - Register(services, assembly); + Register(services, item); } } - private static void Register(IServiceCollection services, Assembly assembly) + private static void Register(IServiceCollection services, string item) { + Assembly assembly = Assembly.Load(item); foreach (var type in assembly.GetTypes()) { var serviceAttribute = type.GetCustomAttribute(); @@ -59,11 +59,7 @@ namespace Infrastructure.Extensions services.AddTransient(serviceType, type); break; } - //Console.WriteLine($"娉ㄥ唽锛歿serviceType}"); - } - else - { - //Console.WriteLine($"娉ㄥ唽锛歿serviceType}"); + //System.Console.WriteLine($"娉ㄥ唽锛歿serviceType}"); } } } diff --git a/ZR.Admin.WebApi/Extensions/DbExtension.cs b/ZR.Admin.WebApi/Extensions/DbExtension.cs index 8c1eeaf6150b05f6d22dae598a1bf0b9911734a1..96548a354a8bd62a6cf7c87f9b6a8cbef124a140 100644 --- a/ZR.Admin.WebApi/Extensions/DbExtension.cs +++ b/ZR.Admin.WebApi/Extensions/DbExtension.cs @@ -29,7 +29,7 @@ namespace ZR.Admin.WebApi.Extensions string connStr = Configuration.GetConnectionString("conn_db"); int dbType = Convert.ToInt32(Configuration.GetConnectionString("conn_db_type")); - SugarIocServices.AddSqlSugar(new List() { + var iocList = new List() { new IocConfig() { ConfigId = "0",//榛樿db ConnectionString = connStr, @@ -38,51 +38,46 @@ namespace ZR.Admin.WebApi.Extensions }, new IocConfig() { ConfigId = "1", - ConnectionString = "鏇挎崲鎴愪綘鐨勫瓧绗︿覆", - DbType = IocDbType.MySql, + ConnectionString = connStr, + DbType = (IocDbType)dbType, IsAutoCloseConnection = true } //...澧炲姞鍏朵粬鏁版嵁搴 - }); + }; + SugarIocServices.AddSqlSugar(iocList); SugarIocServices.ConfigurationSugar(db => { //db0鏁版嵁杩囨护 FilterData(0); - - #region db0 - db.GetConnectionScope(0).Aop.OnLogExecuting = (sql, pars) => - { - var param = db.GetConnectionScope(0).Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)); - logger.Info($"銆恠ql璇彞銆憑sql}锛寋param}\n"); - }; - - db.GetConnectionScope(0).Aop.OnError = (e) => - { - logger.Error(e, $"鎵цSQL鍑洪敊锛歿e.Message}"); - }; - //SQL鎵ц瀹 - db.GetConnectionScope(0).Aop.OnLogExecuted = (sql, pars) => + iocList.ForEach(iocConfig => { - //鎵ц瀹屼簡鍙互杈撳嚭SQL鎵ц鏃堕棿 (OnLogExecutedDelegate) - }; - #endregion + SetSugarAop(db, iocConfig); + }); + }); + } - #region db1 - //Db1 - db.GetConnection(1).Aop.OnLogExecuting = (sql, pars) => - { - var param = db.GetConnection(1).Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)); + private static void SetSugarAop(SqlSugarClient db, IocConfig iocConfig) + { + var config = db.GetConnection(iocConfig.ConfigId).CurrentConnectionConfig; + + string configId = config.ConfigId; + db.GetConnectionScope(configId).Aop.OnLogExecuting = (sql, pars) => + { + string log = $"銆恉b{configId} SQL璇彞銆憑UtilMethods.GetSqlString(config.DbType, sql, pars)}\n"; + if (sql.StartsWith("UPDATE", StringComparison.OrdinalIgnoreCase) || sql.StartsWith("INSERT", StringComparison.OrdinalIgnoreCase)) + logger.Warn(log); + else if (sql.StartsWith("DELETE", StringComparison.OrdinalIgnoreCase) || sql.StartsWith("TRUNCATE", StringComparison.OrdinalIgnoreCase)) + logger.Error(log); + else + logger.Info(log); + }; - logger.Info($"銆恠ql璇彞銆憑sql}, {param}"); - }; - //Db1閿欒鏃ュ織 - db.GetConnection(1).Aop.OnError = (e) => - { - logger.Error($"鎵цSql璇彞澶辫触锛歿e.Sql}锛屽師鍥狅細{e.Message}"); - }; - #endregion - }); + db.GetConnectionScope(configId).Aop.OnError = (e) => + { + Console.ForegroundColor = ConsoleColor.Red; + logger.Error(e, $"鎵цSQL鍑洪敊锛歿e.Message}"); + }; } /// @@ -97,7 +92,7 @@ namespace ZR.Admin.WebApi.Extensions var user = JwtUtil.GetLoginUser(App.HttpContext); if (user == null) return; //绠$悊鍛樹笉杩囨护 - if (user.RoleIds.Any(f => f.Equals("admin"))) return; + if (user.RoleIds.Any(f => f.Equals(GlobalConstant.AdminRole))) return; var db = DbScoped.SugarScope.GetConnectionScope(configId); foreach (var role in user.Roles.OrderBy(f => f.DataScope)) { @@ -130,8 +125,9 @@ namespace ZR.Admin.WebApi.Extensions } else if (DATA_SCOPE_SELF.Equals(dataScope))//浠呮湰浜烘暟鎹 { - var filter1 = new TableFilterItem(it => it.UserId == user.UserId, true); - db.QueryFilter.Add(filter1); + db.QueryFilter.AddTableFilter(it => it.UserId == user.UserId); + db.QueryFilter.AddTableFilter(it => user.RoleIds.Contains(it.RoleKey)); + db.QueryFilter.AddTableFilter(it => it.UserName == user.UserName); } } } diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs index 7b4c11fc925f9aa9a899aa1041c507756c08efcb..da5cbaddcdd98e2c13c210036d1ff7196004cfc0 100644 --- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs +++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs @@ -1,5 +1,4 @@ 锘縰sing Microsoft.AspNetCore.Http; -using Snowflake.Core; using System; namespace ZR.Admin.WebApi.Extensions @@ -10,18 +9,9 @@ namespace ZR.Admin.WebApi.Extensions { var types = source.GetType(); - if (types.GetProperty("CreateTime") != null) - { - types.GetProperty("CreateTime").SetValue(source, DateTime.Now, null); - } - if (types.GetProperty("AddTime") != null) - { - types.GetProperty("AddTime").SetValue(source, DateTime.Now, null); - } - if (types.GetProperty("UpdateTime") != null) - { - types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null); - } + types.GetProperty("CreateTime")?.SetValue(source, DateTime.Now, null); + types.GetProperty("AddTime")?.SetValue(source, DateTime.Now, null); + types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); if (types.GetProperty("Create_by") != null && context != null) { types.GetProperty("Create_by").SetValue(source, context.GetName(), null); @@ -37,23 +27,11 @@ namespace ZR.Admin.WebApi.Extensions { var types = source.GetType(); - if (types.GetProperty("UpdateTime") != null) - { - types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null); - } - if (types.GetProperty("Update_time") != null) - { - types.GetProperty("Update_time").SetValue(source, DateTime.Now, null); - } + types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); + types.GetProperty("Update_time")?.SetValue(source, DateTime.Now, null); - if (types.GetProperty("UpdateBy") != null) - { - types.GetProperty("UpdateBy").SetValue(source,context.GetName(), null); - } - if (types.GetProperty("Update_by") != null) - { - types.GetProperty("Update_by").SetValue(source, context.GetName(), null); - } + types.GetProperty("UpdateBy")?.SetValue(source,context.GetName(), null); + types.GetProperty("Update_by")?.SetValue(source, context.GetName(), null); return source; } diff --git a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs index dea415d72bc90a81a98de554a85f5afa76d56d6b..486aec9360f4e4d47c4f1c7570bb5f639e53f6bc 100644 --- a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs +++ b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs @@ -1,5 +1,5 @@ -锘縰sing Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.JwtBearer; +锘縰sing Infrastructure; +using Infrastructure.Extensions; using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; @@ -8,7 +8,6 @@ using System.Linq; using System.Security.Claims; using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; using UAParser; using ZR.Model.System; @@ -63,12 +62,22 @@ namespace ZR.Admin.WebApi.Extensions return Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"); } + /// + /// 鑾峰彇鐧诲綍鐢ㄦ埛id + /// + /// + /// public static long GetUId(this HttpContext context) { var uid = context.User.FindFirstValue(ClaimTypes.PrimarySid); - return !string.IsNullOrEmpty(uid) ? long.Parse(uid) : 0; } + + /// + /// 鑾峰彇鐧诲綍鐢ㄦ埛鍚 + /// + /// + /// public static string GetName(this HttpContext context) { var uid = context.User?.Identity?.Name; @@ -76,10 +85,15 @@ namespace ZR.Admin.WebApi.Extensions return uid; } + /// + /// 鍒ゆ柇鏄惁鏄鐞嗗憳 + /// + /// + /// public static bool IsAdmin(this HttpContext context) { - long id = GetUId(context); - return id == 1; + var userName = GetName(context); + return userName == GlobalConstant.AdminRole; } /// @@ -126,7 +140,10 @@ namespace ZR.Admin.WebApi.Extensions { return context != null ? context.Request.Path.Value : ""; } - + public static string GetQueryString(this HttpContext context) + { + return context != null ? context.Request.QueryString.Value : ""; + } /// /// 璁剧疆璇锋眰鍙傛暟 /// @@ -134,21 +151,25 @@ namespace ZR.Admin.WebApi.Extensions /// public static void GetRequestValue(this HttpContext context, SysOperLog operLog) { - string reqMethod = operLog.requestMethod; + string reqMethod = operLog.RequestMethod; string param; - if (HttpMethods.IsPost(reqMethod) || HttpMethods.IsPut(reqMethod)) + if (HttpMethods.IsPost(reqMethod) || HttpMethods.IsPut(reqMethod) || HttpMethods.IsDelete(reqMethod)) { context.Request.Body.Seek(0, SeekOrigin.Begin); using var reader = new StreamReader(context.Request.Body, Encoding.UTF8); //闇瑕佷娇鐢ㄥ紓姝ユ柟寮忔墠鑳借幏鍙 param = reader.ReadToEndAsync().Result; + if (param.IsEmpty()) + { + param = GetQueryString(context); + } } else { - param = context.Request.QueryString.Value.ToString(); + param = GetQueryString(context); } - operLog.operParam = param; + operLog.OperParam = param; } } diff --git a/ZR.Admin.WebApi/Extensions/LogoExtension.cs b/ZR.Admin.WebApi/Extensions/LogoExtension.cs new file mode 100644 index 0000000000000000000000000000000000000000..46f7ddd39c1d35c3845dba7304a9644777d0b8b3 --- /dev/null +++ b/ZR.Admin.WebApi/Extensions/LogoExtension.cs @@ -0,0 +1,23 @@ +锘縰sing JinianNet.JNTemplate; +using Microsoft.Extensions.DependencyInjection; +using System; +using ZR.Common; + +namespace ZR.Admin.WebApi.Extensions +{ + public static class LogoExtension + { + public static void AddLogo(this IServiceCollection services) + { + Console.ForegroundColor = ConsoleColor.Blue; + var contentTpl = JnHelper.ReadTemplate("", "logo.txt"); + var content = contentTpl?.Render(); + + Console.WriteLine(content); + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine("婧愮爜鍦板潃: https://gitee.com/izory/ZrAdminNetCore"); + Console.WriteLine("瀹樻柟鏂囨。锛歨ttp://www.izhaorui.cn/doc"); + Console.WriteLine("鎵撹祻浣滆咃細http://www.izhaorui.cn/doc/support.html"); + } + } +} diff --git a/ZR.Admin.WebApi/Extensions/SwaggerExtension.cs b/ZR.Admin.WebApi/Extensions/SwaggerExtension.cs index 13598a42bc62145554cf630a01b2a4e60bf2b8d1..e0b57887227aac72365673bb44905fb5d274b162 100644 --- a/ZR.Admin.WebApi/Extensions/SwaggerExtension.cs +++ b/ZR.Admin.WebApi/Extensions/SwaggerExtension.cs @@ -27,8 +27,7 @@ namespace ZR.Admin.WebApi.Extensions var url = $"{httpReq.Scheme}://{httpReq.Host.Value}"; var referer = httpReq.Headers["Referer"].ToString(); if (referer.Contains(GlobalConstant.DevApiProxy)) - url = referer.Substring(0, - referer.IndexOf(GlobalConstant.DevApiProxy, StringComparison.InvariantCulture) + GlobalConstant.DevApiProxy.Length - 1); + url = referer[..(referer.IndexOf(GlobalConstant.DevApiProxy, StringComparison.InvariantCulture) + GlobalConstant.DevApiProxy.Length - 1)]; swaggerDoc.Servers = new List { @@ -57,8 +56,11 @@ namespace ZR.Admin.WebApi.Extensions }); try { + var tempPath = hostEnvironment.ContentRootPath; //娣诲姞鏂囨。娉ㄩ噴 - c.IncludeXmlComments(Path.Combine(hostEnvironment.ContentRootPath, "ZRAdmin.xml"), true); + c.IncludeXmlComments(Path.Combine(tempPath, "ZRAdmin.xml"), true); + c.IncludeXmlComments(Path.Combine(tempPath, "ZRModel.xml"), true); + //c.IncludeXmlComments(Path.Combine(Directory.GetParent(tempPath).FullName, "ZR.Model", "ZRModel.xml"), true); } catch (Exception ex) { diff --git a/ZR.Admin.WebApi/Extensions/TasksExtension.cs b/ZR.Admin.WebApi/Extensions/TasksExtension.cs index 018a19c115b21f214d49b0a8f37d6090b152a6f5..fb8d509c89dfa4c522c1a738d247db011546fd1c 100644 --- a/ZR.Admin.WebApi/Extensions/TasksExtension.cs +++ b/ZR.Admin.WebApi/Extensions/TasksExtension.cs @@ -3,8 +3,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Quartz.Spi; using System; -using System.Threading.Tasks; -using ZR.Service.System.IService; using ZR.Tasks; namespace ZR.Admin.WebApi.Extensions @@ -20,9 +18,6 @@ namespace ZR.Admin.WebApi.Extensions //娣诲姞Quartz鏈嶅姟 services.AddSingleton(); - //娣诲姞鎴戜滑鐨勬湇鍔 - //services.AddTransient(); - services.AddTransient(); } @@ -38,7 +33,7 @@ namespace ZR.Admin.WebApi.Extensions ITaskSchedulerServer _schedulerServer = App.GetRequiredService(); //var tasks = _tasksQzService.GetList(m => m.IsStart); - var tasks = SqlSugar.IOC.DbScoped.SugarScope.Queryable().Where(m => m.IsStart).ToList(); + var tasks = SqlSugar.IOC.DbScoped.SugarScope.Queryable().Where(m => m.IsStart).ToList(); //绋嬪簭鍚姩鍚庢敞鍐屾墍鏈夊畾鏃朵换鍔 foreach (var task in tasks) diff --git a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs index 3c596c1a154d6291e686d2f0b57bb5c6babd02f2..194618b56e9cb9e4c0543c3a1ff38f446060d47a 100644 --- a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs +++ b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs @@ -61,7 +61,7 @@ namespace ZR.Admin.WebApi.Filters bool isDemoMode = AppSettings.GetAppConfig("DemoMode", false); var url = context.HttpContext.Request.Path; //婕旂ず鍏紑鐜灞忚斀鏉冮檺 - string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send", "export", "upload", "common" }; + string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send", "export", "upload", "common", "gencode" }; if (isDemoMode && denyPerms.Any(f => Permission.ToLower().Contains(f))) { context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "婕旂ず妯″紡 , 涓嶅厑璁告搷浣" }); diff --git a/ZR.Admin.WebApi/Filters/GlobalActionMonitor.cs b/ZR.Admin.WebApi/Filters/GlobalActionMonitor.cs index 19efe966ba3793a93062aa2636296227bcf7f1f3..01a5fc15bae99ddd727c34ff66023a3f7bcede1e 100644 --- a/ZR.Admin.WebApi/Filters/GlobalActionMonitor.cs +++ b/ZR.Admin.WebApi/Filters/GlobalActionMonitor.cs @@ -101,31 +101,31 @@ namespace ZR.Admin.WebApi.Filters SysOperLog sysOperLog = new() { - status = 0, - operName = userName, - operIp = ip, - operUrl = HttpContextExtension.GetRequestUrl(context.HttpContext), - requestMethod = method, - jsonResult = jsonResult, - operLocation = ip_info.Province + " " + ip_info.City, - method = controller + "." + action + "()", + Status = 0, + OperName = userName, + OperIp = ip, + OperUrl = HttpContextExtension.GetRequestUrl(context.HttpContext), + RequestMethod = method, + JsonResult = jsonResult, + OperLocation = ip_info.Province + " " + ip_info.City, + Method = controller + "." + action + "()", //Elapsed = _stopwatch.ElapsedMilliseconds, - operTime = DateTime.Now + OperTime = DateTime.Now }; HttpContextExtension.GetRequestValue(context.HttpContext, sysOperLog); if (logAttribute != null) { - sysOperLog.title = logAttribute?.Title; - sysOperLog.businessType = (int)logAttribute?.BusinessType; - sysOperLog.operParam = logAttribute.IsSaveRequestData ? sysOperLog.operParam : ""; - sysOperLog.jsonResult = logAttribute.IsSaveResponseData ? sysOperLog.jsonResult : ""; + sysOperLog.Title = logAttribute?.Title; + sysOperLog.BusinessType = (int)logAttribute?.BusinessType; + sysOperLog.OperParam = logAttribute.IsSaveRequestData ? sysOperLog.OperParam : ""; + sysOperLog.JsonResult = logAttribute.IsSaveResponseData ? sysOperLog.JsonResult : ""; } LogEventInfo ei = new(LogLevel.Info, "GlobalActionMonitor", ""); ei.Properties["jsonResult"] = !HttpMethods.IsGet(method) ? jsonResult : ""; - ei.Properties["requestParam"] = sysOperLog.operParam; + ei.Properties["requestParam"] = sysOperLog.OperParam; ei.Properties["user"] = userName; logger.Log(ei); diff --git a/ZR.Admin.WebApi/Framework/JwtUtil.cs b/ZR.Admin.WebApi/Framework/JwtUtil.cs index 590b615287df1bec22d8766027ebe1406479343a..92c1ea190b791be91a21d1d1609ae090876f08c1 100644 --- a/ZR.Admin.WebApi/Framework/JwtUtil.cs +++ b/ZR.Admin.WebApi/Framework/JwtUtil.cs @@ -132,7 +132,7 @@ namespace ZR.Admin.WebApi.Framework var userData = jwtToken.FirstOrDefault(x => x.Type == ClaimTypes.UserData).Value; var loginUser = JsonConvert.DeserializeObject(userData); var permissions = CacheService.GetUserPerms(GlobalConstant.UserPermKEY + loginUser?.UserId); - if (loginUser?.UserName == "admin") + if (loginUser?.UserName == GlobalConstant.AdminRole) { permissions = new List() { GlobalConstant.AdminPerm }; } diff --git a/ZR.Admin.WebApi/Hubs/MessageHub.cs b/ZR.Admin.WebApi/Hubs/MessageHub.cs index 6ffa95e945425a777104a9d09cd261b828798b96..a1f0419f13c71c5ed0d6f1225e085cb8e6804864 100644 --- a/ZR.Admin.WebApi/Hubs/MessageHub.cs +++ b/ZR.Admin.WebApi/Hubs/MessageHub.cs @@ -6,6 +6,7 @@ using Infrastructure; using Infrastructure.Constant; using Infrastructure.Model; using IPTools.Core; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SignalR; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Framework; @@ -46,12 +47,12 @@ namespace ZR.Admin.WebApi.Hubs var ip = HttpContextExtension.GetClientUserIp(App.HttpContext); var ip_info = IpTool.Search(ip); - LoginUser loginUser = JwtUtil.GetLoginUser(App.HttpContext); + var userid = HttpContextExtension.GetUId(App.HttpContext); var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId); //鍒ゆ柇鐢ㄦ埛鏄惁瀛樺湪锛屽惁鍒欐坊鍔犻泦鍚 if (!user && Context.User.Identity.IsAuthenticated) { - OnlineUsers users = new(Context.ConnectionId, name, loginUser?.UserId, ip) + OnlineUsers users = new(Context.ConnectionId, name, userid, ip) { Location = ip_info.City }; @@ -97,12 +98,7 @@ namespace ZR.Admin.WebApi.Hubs public async Task SendMessage(string connectId, string userName, string message) { Console.WriteLine($"{connectId},message={message}"); - bool isDemoMode = AppSettings.GetAppConfig("DemoMode", true); - if (isDemoMode) - { - await Clients.Caller.SendAsync("receiveChat", new { userName, message = "褰撳墠鐜涓烘紨绀虹幆澧冿紝娑堟伅涓嶄細鍙戦佺粰瀵规柟" }); - return; - } + await Clients.Client(connectId).SendAsync("receiveChat", new { userName, message }); } } diff --git a/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs b/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs index cdc619ae83651e14abe2898084c7a3d78b17d229..b0a1d2285401e313f0e76ae5a7a918dd60679866 100644 --- a/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs +++ b/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs @@ -10,6 +10,7 @@ using System.Text.Encodings.Web; using System.Text.Json; using System.Threading.Tasks; using ZR.Admin.WebApi.Extensions; +using ZR.Common; using ZR.Model.System; using ZR.Service.System.IService; @@ -83,15 +84,15 @@ namespace ZR.Admin.WebApi.Middleware SysOperLog sysOperLog = new() { - status = 1, - operIp = ip, - operUrl = HttpContextExtension.GetRequestUrl(context), - requestMethod = context.Request.Method, - jsonResult = responseResult, - errorMsg = string.IsNullOrEmpty(error) ? msg : error, - operName = context.User.Identity.Name, - operLocation = ip_info.Province + " " + ip_info.City, - operTime = DateTime.Now + Status = 1, + OperIp = ip, + OperUrl = HttpContextExtension.GetRequestUrl(context), + RequestMethod = context.Request.Method, + JsonResult = responseResult, + ErrorMsg = string.IsNullOrEmpty(error) ? msg : error, + OperName = context.User.Identity.Name, + OperLocation = ip_info.Province + " " + ip_info.City, + OperTime = DateTime.Now }; HttpContextExtension.GetRequestValue(context, sysOperLog); var endpoint = GetEndpoint(context); @@ -100,10 +101,10 @@ namespace ZR.Admin.WebApi.Middleware var logAttribute = endpoint.Metadata.GetMetadata(); if (logAttribute != null) { - sysOperLog.businessType = (int)logAttribute?.BusinessType; - sysOperLog.title = logAttribute?.Title; - sysOperLog.operParam = logAttribute.IsSaveRequestData ? sysOperLog.operParam : ""; - sysOperLog.jsonResult = logAttribute.IsSaveResponseData ? sysOperLog.jsonResult : ""; + sysOperLog.BusinessType = (int)logAttribute?.BusinessType; + sysOperLog.Title = logAttribute?.Title; + sysOperLog.OperParam = logAttribute.IsSaveRequestData ? sysOperLog.OperParam : ""; + sysOperLog.JsonResult = logAttribute.IsSaveResponseData ? sysOperLog.JsonResult : ""; } } LogEventInfo ei = new(logLevel, "GlobalExceptionMiddleware", error) @@ -113,13 +114,13 @@ namespace ZR.Admin.WebApi.Middleware }; ei.Properties["status"] = 1;//璧版甯歌繑鍥為兘鏄氳繃璧癎lobalExceptionFilter涓嶉氳繃 ei.Properties["jsonResult"] = responseResult; - ei.Properties["requestParam"] = sysOperLog.operParam; + ei.Properties["requestParam"] = sysOperLog.OperParam; ei.Properties["user"] = HttpContextExtension.GetName(context); Logger.Log(ei); context.Response.ContentType = "text/json;charset=utf-8"; await context.Response.WriteAsync(responseResult, System.Text.Encoding.UTF8); - + WxNoticeHelper.SendMsg("绯荤粺鍑洪敊", sysOperLog.ErrorMsg); SysOperLogService.InsertOperlog(sysOperLog); } diff --git a/ZR.Admin.WebApi/NLog.config b/ZR.Admin.WebApi/NLog.config index f96caf96e30acd61a2f53dc024445f081adb6b57..f52f6b317cdc9e8ec47530d8755a552bb586a738 100644 --- a/ZR.Admin.WebApi/NLog.config +++ b/ZR.Admin.WebApi/NLog.config @@ -32,7 +32,7 @@ keepFileOpen="true" layout="${longdate} | ${event-properties:item=EventId_Id} | ${uppercase:${level}} | ${logger} | ${aspnet-request-iP:CheckForwardedForHeader=true} | ${event-properties:item=user} | ${aspnet-request-url} | ${message} | ${event-properties:item=requestParam} | ${event-properties:item=jsonResult} | ${onexception:${exception:format=tostring}"/> - + + layout="${longdate} ${aspnet-request-iP} ${aspnet-request-headers:HeaderNames=userid} ${aspnet-request-url} ${newline} ${message}"/> - - + + + + + + + + + - @@ -62,10 +69,9 @@ - - - - + + + diff --git a/ZR.Admin.WebApi/Properties/launchSettings.json b/ZR.Admin.WebApi/Properties/launchSettings.json index 7f6746e6963b37b4d75b1709891e783e89e0267a..2045353942ea7440029f1f09c21387ef7f7e27ff 100644 --- a/ZR.Admin.WebApi/Properties/launchSettings.json +++ b/ZR.Admin.WebApi/Properties/launchSettings.json @@ -2,7 +2,6 @@ "profiles": { "ZRAdmin": { "commandName": "Project", - "launchBrowser": false, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "" }, diff --git a/ZR.Admin.WebApi/Startup.cs b/ZR.Admin.WebApi/Startup.cs index d1263efcfdacde56b603143e615e28e0b3bbc2b3..d7b096a4d39ef5e1ccae4adef2f7b4b007b507d8 100644 --- a/ZR.Admin.WebApi/Startup.cs +++ b/ZR.Admin.WebApi/Startup.cs @@ -12,12 +12,12 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; using System.IO; -using System.Threading.Tasks; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Framework; using ZR.Admin.WebApi.Hubs; using ZR.Admin.WebApi.Middleware; +using ZR.Common.Cache; namespace ZR.Admin.WebApi { @@ -61,7 +61,8 @@ namespace ZR.Admin.WebApi services.AddSession(); services.AddMemoryCache(); services.AddHttpContextAccessor(); - + // 鏄剧ずlogo + services.AddLogo(); //缁戝畾鏁翠釜瀵硅薄鍒癕odel涓 services.Configure(Configuration); @@ -151,18 +152,21 @@ namespace ZR.Admin.WebApi /// private void InjectServices(IServiceCollection services, IConfiguration configuration) { + //娉ㄥ唽绯荤粺鎺ュ彛鏈嶅姟 services.AddAppService(); + //娉ㄥ唽鑾峰彇閰嶇疆鏂囦欢 services.AddSingleton(new AppSettings(configuration)); - //寮鍚鍒掍换鍔 + //娉ㄥ唽璁″垝浠诲姟 services.AddTaskSchedulers(); //鍒濆鍖杁b DbExtension.AddDb(configuration); - + //娉ㄥ唽REDIS 鏈嶅姟 - Task.Run(() => + var openRedis = configuration["RedisServer:open"]; + if (openRedis == "1") { - //RedisServer.Initalize(); - }); + RedisServer.Initalize(); + } } } } diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index 33f4e7295c0bda36f11a8a95333cd5c5da78bd99..b7b6780b65f13ac3f7f6aefcd5ae1003e9411c40 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -5,6 +5,7 @@ bc51af00-60b6-4e2a-935e-267c368c890a false zh-Hans + True @@ -14,19 +15,18 @@ - - + - - - - - - - + + + + + + + @@ -58,11 +58,11 @@ - + - + diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index 33712f769a54cd8dde7240dd2c331b16b4e692f9..732b31fd3c302719072cc8dadf705ef8a1dd068f 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -8,7 +8,7 @@ }, "ConnectionStrings": { "conn_db": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", //鍏朵粬杩炴帴瀛楃涓茶鐪嬪畼鏂规枃妗 - "conn_db_type": "1" //鏁版嵁搴撶被鍨 MySql = 0, SqlServer = 1 + "conn_db_type": "1" //鏁版嵁搴撶被鍨 MySql = 0, SqlServer = 1, Oracle = 3锛孭gSql = 4 }, "urls": "http://localhost:8888", //椤圭洰鍚姩url锛屽鏋滄敼鍔ㄧ鍙e墠绔搴攄evServer涔熼渶瑕佽繘琛屼慨鏀 "corsUrls": "http://localhost:8887", //璺ㄥ煙鍦板潃锛堝墠绔惎鍔ㄩ」鐩紝鍓嶅悗绔垎绂诲崟鐙儴缃查渶瑕佽缃級锛屽涓敤","闅斿紑 @@ -20,16 +20,26 @@ }, "DemoMode": false, //鏄惁婕旂ず妯″紡 "Upload": { - "UploadUrl": "http://localhost:8888", //鏈湴瀛樺偍璧勬簮璁块棶璺緞 - "localSavePath": "uploads" //鏈湴涓婁紶榛樿鏂囦欢瀛樺偍鐩綍 wwwroot/uploads + "uploadUrl": "http://localhost:8888", //鏈湴瀛樺偍璧勬簮璁块棶璺緞 + "localSavePath": "uploads", //鏈湴涓婁紶榛樿鏂囦欢瀛樺偍鐩綍 wwwroot/uploads + "maxSize": 15, //涓婁紶鏂囦欢澶у皬闄愬埗 15M + "notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ] }, //闃块噷浜戝瓨鍌ㄩ厤缃 "ALIYUN_OSS": { - "REGIONID": "cn-hangzhou", + "REGIONID": "", //eg锛歝n-hangzhou "KEY": "XX", "SECRET": "XX", "bucketName": "bucketName", - "domainUrl": "http://xxx.xxx.com" //璁块棶璧勬簮鍩熷悕 + "domainUrl": "http://xxx.xxx.com", //璁块棶璧勬簮鍩熷悕 + "maxSize": 100 //涓婁紶鏂囦欢澶у皬闄愬埗 100M + }, + //浼佷笟寰俊閫氱煡閰嶇疆 + "WxCorp": { + "AgentID": "", + "CorpID": "", + "CorpSecret": "", + "SendUser": "@all" }, "gen": { "conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", @@ -37,7 +47,8 @@ "autoPre": true, //鑷姩鍘婚櫎琛ㄥ墠缂 "author": "admin", "tablePrefix": "sys_", //"琛ㄥ墠缂锛堢敓鎴愮被鍚嶄笉浼氬寘鍚〃鍓嶇紑锛屽涓敤閫楀彿鍒嗛殧锛", - "vuePath": "" //鍓嶇浠g爜瀛樺偍璺緞eg锛欴:\Work\ZRAdmin-Vue3 + "vuePath": "", //鍓嶇浠g爜瀛樺偍璺緞eg锛欴:\Work\ZRAdmin-Vue3 + "oracle_db": "" }, //閭閰嶇疆淇℃伅 "MailOptions": { @@ -52,6 +63,7 @@ }, //redis鏈嶅姟閰嶇疆 "RedisServer": { + "open": 0,//鏄惁鍚敤redis "Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:", "Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:" }, @@ -62,7 +74,7 @@ "RealIpHeader": "X-Real-IP", "ClientIdHeader": "X-ClientId", "HttpStatusCode": 429, - "EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut" ], + "EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut", "*:/common/uploadfile" ], "QuotaExceededResponse": { "Content": "{{\"code\":429,\"msg\":\"璁块棶杩囦簬棰戠箒锛岃绋嶅悗閲嶈瘯\"}}", "ContentType": "application/json", @@ -77,14 +89,7 @@ "Limit": 5 }, { - "Endpoint": "post:*", - //鏃堕棿娈碉紝鏍煎紡锛歿鏁板瓧}{鍗曚綅}锛涘彲浣跨敤鍗曚綅锛歴, m, h, d - "Period": "3s", - "Limit": 1 - }, - { - "Endpoint": "put:*", - //鏃堕棿娈碉紝鏍煎紡锛歿鏁板瓧}{鍗曚綅}锛涘彲浣跨敤鍗曚綅锛歴, m, h, d + "Endpoint": "((post)|(put)):*", "Period": "3s", "Limit": 1 } @@ -94,5 +99,9 @@ "IpRules": [ ] } + }, + //楠岃瘉鐮侀厤缃 + "CaptchaOptions": { + "length": 4//楠岃瘉鐮侀暱搴 } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt index 51d5983363c872585892ad662fe54166105392f3..5debb700d645d51dfbb943fcd7d2266e0cb84427 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt @@ -1,11 +1,11 @@ -锘縰sing Infrastructure; +using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; using Mapster; using Microsoft.AspNetCore.Mvc; -using ${options.ModelsNamespace}.Dto; -using ${options.ModelsNamespace}.Models; +using ${options.DtosNamespace}; +using ${options.ModelsNamespace}.${options.SubNamespace}; using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service; using ${options.ApiControllerNamespace}.Extensions; using ${options.ApiControllerNamespace}.Filters; @@ -144,16 +144,40 @@ $if(replaceDto.ShowBtnExport) /// 瀵煎嚭${genTable.FunctionName} /// /// - [Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)] + [Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.EXPORT)] [HttpGet("export")] [ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:export")] public IActionResult Export([FromQuery] ${replaceDto.ModelTypeName}QueryDto parm) { - parm.PageSize = 10000; + parm.PageNum = 1; + parm.PageSize = 100000; var list = _${replaceDto.ModelTypeName}Service.GetList(parm).Result; + if (list == null || list.Count <= 0) + { + return ToResponse(ResultCode.FAIL, "娌℃湁瑕佸鍑虹殑鏁版嵁"); + } + var result = ExportExcelMini(list, "${genTable.FunctionName}", "${genTable.FunctionName}"); + return ExportExcel(result.Item2, result.Item1); + } +$end + +$if(replaceDto.ShowBtnTruncate) + /// + /// 娓呯┖${genTable.FunctionName} + /// + /// + [Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.CLEAN)] + [ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:delete")] + [HttpDelete("clean")] + public ApiResult Clear() + { + if (!HttpContextExtension.IsAdmin(HttpContext)) + { + return ApiResult.Error("鎿嶄綔澶辫触"); + } + _${replaceDto.ModelTypeName}Service.Truncate${replaceDto.ModelTypeName}(); - string sFileName = ExportExcel(list, "${replaceDto.ModelTypeName}", "${genTable.FunctionName}"); - return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); + return ToJson(1); } $end diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplDto.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplDto.txt index f697b72ae874ad5e9e8c7498819cf0f1c3efff91..aaf50e2c1ad4a2d9b96a2d0fbf79233c285aaee2 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplDto.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplDto.txt @@ -1,38 +1,67 @@ 锘縰sing System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using ${options.ModelsNamespace}.Dto; -using ${options.ModelsNamespace}.Models; +//using ${options.ModelsNamespace}.${options.SubNamespace}; +$if(replaceDto.ShowBtnExport) +using MiniExcelLibs.Attributes; +$end +$if(null != genTable.SubTableName && "" != genTable.SubTableName) +using ${subTableOptions.ModelsNamespace}.${subTableOptions.SubNamespace}; +$end -namespace ${options.DtosNamespace}.Dto +namespace ${options.DtosNamespace} { /// - /// ${genTable.FunctionName}杈撳叆瀵硅薄 + /// ${genTable.FunctionName}鏌ヨ瀵硅薄 /// - public class ${replaceDto.ModelTypeName}Dto + public class ${replaceDto.ModelTypeName}QueryDto : PagerInfo { $foreach(item in genTable.Columns) -$if((item.IsInsert || item.IsEdit || item.IsPk || item.IsIncrement)) -$if(item.IsRequired) - [Required(ErrorMessage = "${item.ColumnComment}涓嶈兘涓虹┖")] +$if(item.IsQuery) +$if(item.htmlType == "datetime") + public DateTime? Begin$item.CsharpField { get; set; } + public DateTime? End$item.CsharpField { get; set; } +$elseif(item.htmlType == "selectMulti") + public ${item.CsharpType}[] $item.CsharpField { get; set; } +$else + public $item.CsharpType$if(item.CsharpType != "string")?$end $item.CsharpField { get; set; } $end - public $item.CsharpType$item.RequiredStr $item.CsharpField { get; set; } $end $end } /// - /// ${genTable.FunctionName}鏌ヨ瀵硅薄 + /// ${genTable.FunctionName}杈撳叆杈撳嚭瀵硅薄 /// - public class ${replaceDto.ModelTypeName}QueryDto : PagerInfo + public class ${replaceDto.ModelTypeName}Dto { $foreach(item in genTable.Columns) -$if(item.IsQuery && item.htmlType == "datetime") - public DateTime? Begin$item.CsharpField { get; set; } - public DateTime? End$item.CsharpField { get; set; } -$elseif(item.IsQuery) - public $item.CsharpType$if(item.CsharpType != "string")?$end $item.CsharpField { get; set; } +$if(item.IsRequired) + [Required(ErrorMessage = "${item.ColumnComment}涓嶈兘涓虹┖")] +$end +$if(replaceDto.ShowBtnExport) +$if(item.IsExport) + [ExcelColumn(Name = "$if(item.ColumnComment == "")${item.CsharpField}${else}${item.ColumnComment}${end}"$if(item.CsharpType == "DateTime"), Format = "yyyy-MM-dd HH:mm:ss"$end)] +$else + [ExcelIgnore] +$end +$end + public $item.CsharpType$item.RequiredStr $item.CsharpField { get; set; } + +$end + +$if(genTable.TplCategory == "subNav" && genTable.SubTable != null) +$if(replaceDto.ShowBtnExport) + [ExcelIgnore] +$end + public ${genTable.SubTable.ClassName} ${genTable.SubTable.ClassName}Nav { get; set; } +$end + +$if(genTable.TplCategory == "subNavMore" && genTable.SubTable != null) +$if(replaceDto.ShowBtnExport) + [ExcelIgnore] $end + public List<${genTable.SubTable.ClassName}> ${genTable.SubTable.ClassName}Nav { get; set; } $end } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt index f30aecd2f8de9b122d82aa95ce248014c604ea5b..03599635694b7884379306dcf1eb2759b11780ff 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt @@ -1,7 +1,7 @@ 锘縰sing System; -using ${options.ModelsNamespace}; -using ${options.ModelsNamespace}.Dto; -using ${options.ModelsNamespace}.Models; +using ${options.BaseNamespace}Model; +using ${options.DtosNamespace}; +using ${options.ModelsNamespace}.${options.SubNamespace}; using System.Collections.Generic; namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service @@ -14,7 +14,7 @@ namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNam /// public interface I${replaceDto.ModelTypeName}Service : IBaseService<${replaceDto.ModelTypeName}> { - PagedInfo<${replaceDto.ModelTypeName}> GetList(${replaceDto.ModelTypeName}QueryDto parm); + PagedInfo<${replaceDto.ModelTypeName}Dto> GetList(${replaceDto.ModelTypeName}QueryDto parm); $if(genTable.TplCategory == "tree") List<${replaceDto.ModelTypeName}> GetTreeList(${replaceDto.ModelTypeName}QueryDto parm); @@ -22,5 +22,8 @@ $end int Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm); int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm); +$if(replaceDto.ShowBtnTruncate) + void Truncate${replaceDto.ModelTypeName}(); +$end } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt index b779e2afef89f487a6093996595f69feca741875..bb30e0ce28f451347167049f0cc1f1f0d3aec854 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt @@ -1,9 +1,11 @@ 锘縰sing System; -using System.Collections.Generic; using SqlSugar; -using OfficeOpenXml.Attributes; +using System.Collections.Generic; +$if(genTable.TplCategory.Contains("subNav") && genTable.SubTable != null) +using ${subTableOptions.ModelsNamespace}.${subTableOptions.SubNamespace}; +$end -namespace ${options.ModelsNamespace}.Models +namespace ${options.ModelsNamespace}.${options.SubNamespace} { /// /// ${genTable.FunctionName}锛屾暟鎹疄浣撳璞 @@ -14,36 +16,37 @@ namespace ${options.ModelsNamespace}.Models [SugarTable("${genTable.TableName}")] public class ${replaceDto.ModelTypeName} { -$foreach(item in genTable.Columns) +${foreach(item in genTable.Columns)} /// - /// 鎻忚堪 :${item.ColumnComment} ${item.Remark} - /// 绌哄 :$if(item.IsRequired == "True") false $else true $end + /// ${item.ColumnComment} ${item.Remark} /// -$if(replaceDto.ShowBtnExport) - [EpplusTableColumn(Header = "$if(item.ColumnComment == "")${item.CsharpField}${else}${item.ColumnComment}${end}"$if(item.CsharpType == "DateTime"), NumberFormat = "yyyy-MM-dd HH:mm:ss"$end)] -$end $if(item.IsPk || item.IsIncrement) [SugarColumn(IsPrimaryKey = ${item.IsPk.ToString().ToLower()}, IsIdentity = ${item.IsIncrement.ToString().ToLower()}$if(item.CsharpField.ToLower() != item.ColumnName.ToLower()), ColumnName = "$item.ColumnName"$end)] $elseif(item.CsharpField.ToLower() != item.ColumnName.ToLower()) [SugarColumn(ColumnName = "$item.ColumnName")] +$elseif(item.AutoFillType == 1 && item.CsharpType == "DateTime") + [SugarColumn(InsertServerTime = true, IsOnlyIgnoreUpdate = true)] +$elseif(item.AutoFillType == 2 && item.CsharpType == "DateTime") + [SugarColumn(UpdateServerTime = true, IsOnlyIgnoreInsert = true)] +$elseif(item.AutoFillType == 3 && item.CsharpType == "DateTime") + [SugarColumn(InsertServerTime = true, UpdateServerTime = true)] +$elseif(item.AutoFillType == 1) + [SugarColumn(IsOnlyIgnoreUpdate = true)] $end public $item.CsharpType$item.RequiredStr $item.CsharpField { get; set; } ${end} $if(genTable.TplCategory == "tree") - [SugarColumn(IsIgnore = true)] public List<${replaceDto.ModelTypeName}> Children { get; set; } $end - $if(genTable.TplCategory == "subNav" && genTable.SubTable != null) - [Navigate(NavigateType.Dynamic, null)] //鑷畾涔夊叧绯绘槧灏 - public ${genTable.SubTable.ClassName} ${genTable.SubTable.ClassName} { get; set; } + [Navigate(NavigateType.OneToOne, nameof(${replaceDto.PKName}))] //鑷畾涔夊叧绯绘槧灏 + public ${genTable.SubTable.ClassName} ${genTable.SubTable.ClassName}Nav { get; set; } $end - $if(genTable.TplCategory == "subNavMore" && genTable.SubTable != null) - [Navigate(NavigateType.Dynamic, null)] //鑷畾涔夊叧绯绘槧灏 - public List<${genTable.SubTable.ClassName}> ${genTable.SubTable.ClassName} { get; set; } + [Navigate(NavigateType.OneToMany, nameof(${genTable.SubTable.ClassName}.${genTable.SubTableFkName}), nameof(${replaceDto.PKName}))] //鑷畾涔夊叧绯绘槧灏 + public List<${genTable.SubTable.ClassName}> ${genTable.SubTable.ClassName}Nav { get; set; } $end } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplRepository.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplRepository.txt index cd43d7709da719759edef818e3d14fa6883bfafb..f020491be06621c4fdb70cf338d03f80fee1eed9 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplRepository.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplRepository.txt @@ -1,7 +1,5 @@ -锘縰sing System; -using Infrastructure.Attribute; -using ${options.RepositoriesNamespace}.System; -using ${options.ModelsNamespace}.Models; +锘縰sing Infrastructure.Attribute; +using ${options.ModelsNamespace}.${options.SubNamespace}; namespace ${options.RepositoriesNamespace} { @@ -14,7 +12,5 @@ namespace ${options.RepositoriesNamespace} [AppService(ServiceLifetime = LifeTime.Transient)] public class ${replaceDto.ModelTypeName}Repository : BaseRepository<${replaceDto.ModelTypeName}> { - #region 涓氬姟閫昏緫浠g爜 - #endregion } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt index ce428f3ca510beba43e59c0cac50f16bfd7b3148..ebe697236cbba2a5237a58b87e88d8ebab2b9813 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt @@ -1,13 +1,15 @@ 锘縰sing System; using SqlSugar; -using System.Collections.Generic; -using Infrastructure; using Infrastructure.Attribute; -using ${options.ModelsNamespace}; -using ${options.ModelsNamespace}.Dto; -using ${options.ModelsNamespace}.Models; -using ${options.IRepositoriesNamespace}; +using ${options.BaseNamespace}Model; +using ${options.DtosNamespace}; +using ${options.ModelsNamespace}.${options.SubNamespace}; +using ${options.RepositoriesNamespace}; using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service; +using System.Linq; +$if(genTable.TplCategory == "tree") +using System.Collections.Generic; +$end namespace ${options.ServicesNamespace}.${options.SubNamespace} { @@ -20,12 +22,6 @@ namespace ${options.ServicesNamespace}.${options.SubNamespace} [AppService(ServiceType = typeof(I${replaceDto.ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)] public class ${replaceDto.ModelTypeName}Service : BaseService<${replaceDto.ModelTypeName}>, I${replaceDto.ModelTypeName}Service { - private readonly ${replaceDto.ModelTypeName}Repository _${replaceDto.ModelTypeName}Repository; - public ${replaceDto.ModelTypeName}Service(${replaceDto.ModelTypeName}Repository repository) - { - _${replaceDto.ModelTypeName}Repository = repository; - } - #region 涓氬姟閫昏緫浠g爜 /// @@ -33,7 +29,7 @@ namespace ${options.ServicesNamespace}.${options.SubNamespace} /// /// /// - public PagedInfo<${replaceDto.ModelTypeName}> GetList(${replaceDto.ModelTypeName}QueryDto parm) + public PagedInfo<${replaceDto.ModelTypeName}Dto> GetList(${replaceDto.ModelTypeName}QueryDto parm) { //寮濮嬫嫾瑁呮煡璇㈡潯浠 var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>(); @@ -41,7 +37,9 @@ namespace ${options.ServicesNamespace}.${options.SubNamespace} //鎼滅储鏉′欢鏌ヨ璇硶鍙傝僑qlsugar $foreach(column in genTable.Columns) $if(column.IsQuery) -$if(column.CsharpType == "string") +$if(column.HtmlType == "selectMulti") + predicate = predicate.AndIF(parm.${column.CsharpField} != null, it => parm.${column.CsharpField}.Contains(it.${column.CsharpField})); +$elseif(column.CsharpType == "string") predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.${column.CsharpField}), ${codeTool.QueryExp(column.CsharpField, column.QueryType)}; $elseif(column.CsharpType == "DateTime") predicate = predicate.AndIF(parm.Begin${column.CsharpField} == null, it => it.${column.CsharpField} >= DateTime.Now.AddDays(-1)); @@ -51,16 +49,15 @@ $elseif(column.CsharpType == "int" || column.CsharpType == "long") $end $end $end - var response = _${replaceDto.ModelTypeName}Repository - .Queryable() + var response = Queryable() $if(null != genTable.SubTableName && "" != genTable.SubTableName) - .Includes(it => it.${genTable.SubTable.ClassName}.MappingField(z => z.${genTable.SubTableFkName}, () => it.${replaceDto.PKName})) + .Includes(x => x.${genTable.SubTable.ClassName}Nav) //濉厖瀛愬璞 $end $if(genTable.Options.SortField != "" && genTable.Options.SortField != null) - .OrderBy("${genTable.Options.SortField} ${genTable.Options.SortType}") + //.OrderBy("${genTable.Options.SortField} ${genTable.Options.SortType}") $end .Where(predicate.ToExpression()) - .ToPage(parm); + .ToPage<${replaceDto.ModelTypeName}, ${replaceDto.ModelTypeName}Dto>(parm); return response; } @@ -87,47 +84,52 @@ $end $end $end - var response = _${replaceDto.ModelTypeName}Repository.Queryable().Where(predicate.ToExpression()) + var response = Queryable() + .Where(predicate.ToExpression()) .ToTree(it => it.Children, it => it.${genTable.Options.TreeParentCode}, 0); return response; } $end + /// /// 娣诲姞${genTable.FunctionName} /// - /// + /// /// - public int Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm) + public int Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} model) { - var response = _${replaceDto.ModelTypeName}Repository.Insert(parm, it => new - { -${foreach(item in genTable.Columns)} -$if((item.IsInsert)) - it.$item.CsharpField, -$end -${end} - }); - return response; + return Add(model, true); } /// /// 淇敼${genTable.FunctionName} /// - /// + /// /// - public int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm) + public int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} model) { - var response = _${replaceDto.ModelTypeName}Repository.Update(w => w.${replaceDto.PKName} == parm.${replaceDto.PKName}, it => new ${replaceDto.ModelTypeName}() - { + //var response = Update(w => w.${replaceDto.PKName} == model.${replaceDto.PKName}, it => new ${replaceDto.ModelTypeName}() + //{ $foreach(item in genTable.Columns) $if((item.IsEdit)) - $item.CsharpField = parm.$item.CsharpField, + // $item.CsharpField = model.$item.CsharpField, $end ${end} - }); - return response; + //}); + //return response; + return Update(model, true); } +$if(replaceDto.ShowBtnTruncate) + /// + /// 娓呯┖${genTable.FunctionName} + /// + /// + public void Truncate${replaceDto.ModelTypeName}() + { + Truncate(); + } +$end #endregion } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplTreeVue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplTreeVue.txt index 72cfae30f0968e714f0c8e0986be45161a7d876c..b942c65d99899ee8d034e512625f4c03d02cbdc7 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplTreeVue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplTreeVue.txt @@ -40,7 +40,7 @@ $end -${VueViewListContent} +${replaceDto.VueViewListHtml}