From 5be90b09bd999cd380cf13acbbf09ed7246a9cc3 Mon Sep 17 00:00:00 2001 From: shikeyin <pxzsky@163.com> Date: 星期三, 17 一月 2024 14:40:13 +0800 Subject: [PATCH] 添加mybatis支持 2 --- deploy-jar-template/src/main/resources/application-master.yml | 11 iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java | 55 +++- deploy-jar-template/src/main/resources/application-test.yml | 13 iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/ExcelHandlerAdapter.java | 19 + deploy-jar-template/src/main/resources/application-slave.yml | 13 iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/BaseEntity.java | 27 +- deploy-jar-template/src/main/resources/application-dev.yml | 13 deploy-jar-template/src/main/java/com/iplatform/IplatformApplication.java | 2 iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/config/MybatisPlusConfig.java | 102 +++++++++ iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/CreateAndUpdateMetaObjectHandler.java | 62 +++++ pom.xml | 19 + iplatform-support-mybatis/pom.xml | 15 + deploy-jar-template/src/main/resources/application-prod.yml | 16 iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/Excel.java | 187 +++++++++++++++++ iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/TableDataInfo.java | 85 +++++++ 15 files changed, 569 insertions(+), 70 deletions(-) diff --git a/deploy-jar-template/src/main/java/com/iplatform/IplatformApplication.java b/deploy-jar-template/src/main/java/com/iplatform/IplatformApplication.java index 21ff3f1..9159e94 100644 --- a/deploy-jar-template/src/main/java/com/iplatform/IplatformApplication.java +++ b/deploy-jar-template/src/main/java/com/iplatform/IplatformApplication.java @@ -1,11 +1,13 @@ package com.iplatform; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages = {"com.walker","com.iplatform" // ,"org.jeecg.modules.jmreport" , "com.ishop"}) +@MapperScan("com.iplatform.**.mapper") public class IplatformApplication { public static void main(String[] args) throws Exception{ diff --git a/deploy-jar-template/src/main/resources/application-dev.yml b/deploy-jar-template/src/main/resources/application-dev.yml index a7780a4..09b2b89 100644 --- a/deploy-jar-template/src/main/resources/application-dev.yml +++ b/deploy-jar-template/src/main/resources/application-dev.yml @@ -11,12 +11,8 @@ # interactive_timeout: 瀹㈡埛绔伐鍏蜂氦浜掕秴杩囪繖涓椂闂�(绉�)浼氱鍙o紝琛ㄧ幇涓簄avicat username: root - password: Yanglin@123456 - url: jdbc:mysql://101.43.168.96:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false - -# username: root -# password: Bjjmy_2020 -# url: jdbc:mysql://116.198.40.76:3306/iplatform?useUnicode=true&characterEncoding=UTF-8&useSSL=false + password: Bjjmy_2020 + url: jdbc:mysql://116.198.40.76:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false # 杈炬ⅵ鏁版嵁搴� # driver-class-name: dm.jdbc.driver.DmDriver @@ -88,8 +84,10 @@ multi-statement-allow: false redis: - host: localhost + host: 116.198.40.76 port: 6379 + password: Jmy2019. + database: 2 mvc: pathmatch: @@ -210,6 +208,7 @@ - /front/login/** - /front/wechat/get/** - /front/article/** + - /tool/generate/** # 鏂癿ybatis鐢熸垚鍣ㄦ祴璇曪紝2024-01-17銆� # 鍏佽鎵�鏈夎璇佺敤鎴烽兘鍙闂湴鍧�锛岃鎱庨噸鍚﹀垯鏉冮檺閮借繃澶э紝涓�鑸珹PI閮藉簲璇ヨ缃湪杩欓噷 permit-list: diff --git a/deploy-jar-template/src/main/resources/application-master.yml b/deploy-jar-template/src/main/resources/application-master.yml index 37c5286..f81b81e 100644 --- a/deploy-jar-template/src/main/resources/application-master.yml +++ b/deploy-jar-template/src/main/resources/application-master.yml @@ -17,12 +17,9 @@ # password: Yanglin@123456 # url: jdbc:mysql://101.43.168.96:3306/iplatform?useUnicode=true&characterEncoding=UTF-8&useSSL=false -# username: root -# password: Bjjmy_2020 -# url: jdbc:mysql://116.198.40.76:3306/iplatform?useUnicode=true&characterEncoding=UTF-8&useSSL=false username: root - password: Yanglin@123456 - url: jdbc:mysql://101.43.168.96:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false + password: Bjjmy_2020 + url: jdbc:mysql://116.198.40.76:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false # type: com.walker.jdbc.ds.DefaultDataSource # hikari: @@ -95,8 +92,10 @@ # cache: # type: redis redis: - host: localhost + host: 116.198.40.76 port: 6379 + password: Jmy2019. + database: 2 # 閰嶇疆娉ㄥ唽鏈嶅姟鍦板潃锛屾妸鏈嶅姟娉ㄥ唽鍒癗acos涓��2022-12-28 cloud: diff --git a/deploy-jar-template/src/main/resources/application-prod.yml b/deploy-jar-template/src/main/resources/application-prod.yml index cd27231..17edbd4 100644 --- a/deploy-jar-template/src/main/resources/application-prod.yml +++ b/deploy-jar-template/src/main/resources/application-prod.yml @@ -10,13 +10,13 @@ # wait_timeout: 瓒呰繃鏀规椂闂�(绉�)鏈嶅姟绔富鍔ㄦ柇寮� # interactive_timeout: 瀹㈡埛绔伐鍏蜂氦浜掕秴杩囪繖涓椂闂�(绉�)浼氱鍙o紝琛ㄧ幇涓簄avicat - username: root - password: Yanglin@123456 - url: jdbc:mysql://127.0.0.1:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false +# username: root +# password: Yanglin@123456 +# url: jdbc:mysql://127.0.0.1:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false - # username: root - # password: Bjjmy_2020 - # url: jdbc:mysql://116.198.40.76:3306/iplatform?useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: root + password: Bjjmy_2020 + url: jdbc:mysql://116.198.40.76:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false # 杈炬ⅵ鏁版嵁搴� # driver-class-name: dm.jdbc.driver.DmDriver @@ -68,8 +68,10 @@ use-global-data-source-stat: true redis: - host: localhost + host: 116.198.40.76 port: 6379 + password: Jmy2019. + database: 2 mvc: pathmatch: diff --git a/deploy-jar-template/src/main/resources/application-slave.yml b/deploy-jar-template/src/main/resources/application-slave.yml index b09aee1..4ff29b2 100644 --- a/deploy-jar-template/src/main/resources/application-slave.yml +++ b/deploy-jar-template/src/main/resources/application-slave.yml @@ -11,13 +11,8 @@ # interactive_timeout: 瀹㈡埛绔伐鍏蜂氦浜掕秴杩囪繖涓椂闂�(绉�)浼氱鍙o紝琛ㄧ幇涓簄avicat username: root - password: Yanglin@123456 - # url: jdbc:mysql://127.0.0.1:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false - url: jdbc:mysql://101.43.168.96:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false - - # username: root - # password: Bjjmy_2020 - # url: jdbc:mysql://116.198.40.76:3306/iplatform?useUnicode=true&characterEncoding=UTF-8&useSSL=false + password: Bjjmy_2020 + url: jdbc:mysql://116.198.40.76:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false # 杈炬ⅵ鏁版嵁搴� # driver-class-name: dm.jdbc.driver.DmDriver @@ -69,8 +64,10 @@ use-global-data-source-stat: true redis: - host: localhost + host: 116.198.40.76 port: 6379 + password: Jmy2019. + database: 2 mvc: pathmatch: diff --git a/deploy-jar-template/src/main/resources/application-test.yml b/deploy-jar-template/src/main/resources/application-test.yml index 2d4df05..8ab1628 100644 --- a/deploy-jar-template/src/main/resources/application-test.yml +++ b/deploy-jar-template/src/main/resources/application-test.yml @@ -11,13 +11,8 @@ # interactive_timeout: 瀹㈡埛绔伐鍏蜂氦浜掕秴杩囪繖涓椂闂�(绉�)浼氱鍙o紝琛ㄧ幇涓簄avicat username: root - password: Yanglin@123456 -# url: jdbc:mysql://127.0.0.1:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false - url: jdbc:mysql://101.43.168.96:3306/iplatform_test?useUnicode=true&characterEncoding=UTF-8&useSSL=false - - # username: root - # password: Bjjmy_2020 - # url: jdbc:mysql://116.198.40.76:3306/iplatform?useUnicode=true&characterEncoding=UTF-8&useSSL=false + password: Bjjmy_2020 + url: jdbc:mysql://116.198.40.76:3306/iplatform_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false # 杈炬ⅵ鏁版嵁搴� # driver-class-name: dm.jdbc.driver.DmDriver @@ -69,8 +64,10 @@ use-global-data-source-stat: true redis: - host: localhost + host: 116.198.40.76 port: 6379 + password: Jmy2019. + database: 2 mvc: pathmatch: diff --git a/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java b/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java index 9d59fed..1c557bc 100644 --- a/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java +++ b/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java @@ -1,17 +1,16 @@ package com.iplatform.base.controller; -import com.insurance.common.annotation.Log; -import com.insurance.common.core.domain.AjaxResult; -import com.insurance.common.core.page.TableDataInfo; -import com.insurance.common.enums.BusinessType; import com.iplatform.base.SystemController; import com.iplatform.core.util.Convert; import com.iplatform.mybatis.domain.GenTable; import com.iplatform.mybatis.domain.GenTableColumn; +import com.iplatform.mybatis.domain.TableDataInfo; import com.iplatform.mybatis.service.IGenTableColumnService; import com.iplatform.mybatis.service.IGenTableService; +import com.walker.web.ResponseValue; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -41,7 +40,7 @@ */ //@Api(value = "浠g爜鐢熸垚绠$悊", tags = {"浠g爜鐢熸垚绠$悊"}) @RestController -@RequestMapping("/tool/gen") +@RequestMapping("/tool/generate") public class GenController extends SystemController { @Autowired @@ -67,7 +66,7 @@ */ // @PreAuthorize("@ss.hasPermi('tool:gen:query')") @GetMapping(value = "/{tableId}") - public AjaxResult getInfo(@PathVariable Long tableId) + public ResponseValue getInfo(@PathVariable Long tableId) { GenTable table = genTableService.selectGenTableById(tableId); List<GenTable> tables = genTableService.selectGenTableAll(); @@ -76,7 +75,8 @@ map.put("info", table); map.put("rows", list); map.put("tables", tables); - return success(map); +// return success(map); + return ResponseValue.success(map); } /** @@ -111,13 +111,13 @@ // @PreAuthorize("@ss.hasPermi('tool:gen:import')") // @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.IMPORT) @PostMapping("/importTable") - public AjaxResult importTableSave(String tables) + public ResponseValue importTableSave(String tables) { String[] tableNames = Convert.toStrArray(tables); // 鏌ヨ琛ㄤ俊鎭� List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); genTableService.importGenTable(tableList); - return success(); + return ResponseValue.success(); } /** @@ -126,11 +126,11 @@ // @PreAuthorize("@ss.hasPermi('tool:gen:edit')") // @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult editSave(@Validated @RequestBody GenTable genTable) + public ResponseValue editSave(@Validated @RequestBody GenTable genTable) { genTableService.validateEdit(genTable); genTableService.updateGenTable(genTable); - return success(); + return ResponseValue.success(); } /** @@ -139,10 +139,10 @@ // @PreAuthorize("@ss.hasPermi('tool:gen:remove')") // @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.DELETE) @DeleteMapping("/{tableIds}") - public AjaxResult remove(@PathVariable Long[] tableIds) + public ResponseValue remove(@PathVariable Long[] tableIds) { genTableService.deleteGenTableByIds(tableIds); - return success(); + return ResponseValue.success(); } /** @@ -150,17 +150,17 @@ */ // @PreAuthorize("@ss.hasPermi('tool:gen:preview')") @GetMapping("/preview/{tableId}") - public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException + public ResponseValue preview(@PathVariable("tableId") Long tableId) throws IOException { Map<String, String> dataMap = genTableService.previewCode(tableId); - return success(dataMap); + return ResponseValue.success(dataMap); } /** * 鐢熸垚浠g爜锛堜笅杞芥柟寮忥級 */ // @PreAuthorize("@ss.hasPermi('tool:gen:code')") - @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.GENCODE) +// @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.GENCODE) @GetMapping("/download/{tableName}") public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { @@ -174,10 +174,10 @@ // @PreAuthorize("@ss.hasPermi('tool:gen:code')") // @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.GENCODE) @GetMapping("/genCode/{tableName}") - public AjaxResult genCode(@PathVariable("tableName") String tableName) + public ResponseValue genCode(@PathVariable("tableName") String tableName) { genTableService.generatorCode(tableName); - return success(); + return ResponseValue.success(); } /** @@ -186,10 +186,10 @@ // @PreAuthorize("@ss.hasPermi('tool:gen:edit')") // @Log(title = "浠g爜鐢熸垚", businessType = BusinessType.UPDATE) @GetMapping("/synchDb/{tableName}") - public AjaxResult synchDb(@PathVariable("tableName") String tableName) + public ResponseValue synchDb(@PathVariable("tableName") String tableName) { genTableService.synchDb(tableName); - return success(); + return ResponseValue.success(); } /** @@ -218,4 +218,19 @@ response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); } + + /** + * 鍝嶅簲璇锋眰鍒嗛〉鏁版嵁 + */ + @SuppressWarnings({ "rawtypes"}) + protected TableDataInfo getDataTable(List<?> list) + { + TableDataInfo rspData = new TableDataInfo(); + rspData.setCode(HttpStatus.OK.value()); + rspData.setMsg("鏌ヨ鎴愬姛"); + rspData.setRows(list); +// rspData.setTotal(page.getTotal()); + rspData.setTotal(0); + return rspData; + } } diff --git a/iplatform-support-mybatis/pom.xml b/iplatform-support-mybatis/pom.xml index 728bac1..c16d53b 100644 --- a/iplatform-support-mybatis/pom.xml +++ b/iplatform-support-mybatis/pom.xml @@ -70,6 +70,21 @@ <artifactId>walker-jdbc-generator</artifactId> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + </dependency> + <dependency> + <groupId>cn.hutool</groupId> + <artifactId>hutool-core</artifactId> + </dependency> + + <!-- 鐢熸垚domain涓紝excel瀵煎嚭浣跨敤锛�2024-01-17 --> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-ooxml</artifactId> + </dependency> + </dependencies> </project> diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/CreateAndUpdateMetaObjectHandler.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/CreateAndUpdateMetaObjectHandler.java new file mode 100644 index 0000000..bee854c --- /dev/null +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/CreateAndUpdateMetaObjectHandler.java @@ -0,0 +1,62 @@ +package com.iplatform.mybatis; + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.iplatform.core.util.StringUtils; +import org.apache.ibatis.reflection.MetaObject; + +import java.util.Date; + +/** + * @author woo + * @date 2021/3/11 + */ +public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { + @Override + public void insertFill(MetaObject metaObject) { + //region 澶勭悊鍒涘缓浜轰俊鎭� + String createBy = (String) this.getFieldValByName("createBy", metaObject); + Object createTime = this.getFieldValByName("createTime", metaObject); + if (StringUtils.isEmpty(createBy)) { +// createBy = SecurityUtils.getLoginUser().getUser().getNickName(); + createBy = "none"; + this.setFieldValByName("createBy", createBy, metaObject); + } + if (createTime == null) { + createTime = new Date(); + this.setFieldValByName("createTime", createTime, metaObject); + } + //endregion + //region 澶勭悊淇敼浜轰俊鎭� + Object updateBy = this.getFieldValByName("updateBy", metaObject); + Object updateTime = this.getFieldValByName("updateTime", metaObject); + if (updateBy == null) { + updateBy = createBy; + this.setFieldValByName("updateBy", updateBy, metaObject); + } + if (updateTime == null) { + updateTime = createTime; + this.setFieldValByName("updateTime", updateTime, metaObject); + } + //endregion + } + + @Override + public void updateFill(MetaObject metaObject) { + //region 澶勭悊淇敼浜轰俊鎭� +// String updateBy = SecurityUtils.getLoginUser().getUser().getNickName(); +// this.setFieldValByName("updateBy", updateBy, metaObject); + Date updateTime = new Date(); + this.setFieldValByName("updateTime", updateTime, metaObject); + //endregion + } + + @Override + public boolean openInsertFill() { + return true; + } + + @Override + public boolean openUpdateFill() { + return true; + } +} diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/Excel.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/Excel.java new file mode 100644 index 0000000..f5c8af1 --- /dev/null +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/Excel.java @@ -0,0 +1,187 @@ +package com.iplatform.mybatis; + +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 insurance + */ +@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; + } + } +} diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/ExcelHandlerAdapter.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/ExcelHandlerAdapter.java new file mode 100644 index 0000000..be90b75 --- /dev/null +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/ExcelHandlerAdapter.java @@ -0,0 +1,19 @@ +package com.iplatform.mybatis; + +/** + * Excel鏁版嵁鏍煎紡澶勭悊閫傞厤鍣� + * + * @author insurance + */ +public interface ExcelHandlerAdapter +{ + /** + * 鏍煎紡鍖� + * + * @param value 鍗曞厓鏍兼暟鎹�� + * @param args excel娉ㄨВargs鍙傛暟缁� + * + * @return 澶勭悊鍚庣殑鍊� + */ + Object format(Object value, String[] args); +} diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/config/MybatisPlusConfig.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/config/MybatisPlusConfig.java new file mode 100644 index 0000000..b33f045 --- /dev/null +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/config/MybatisPlusConfig.java @@ -0,0 +1,102 @@ +package com.iplatform.mybatis.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.iplatform.core.PlatformConfiguration; +import com.iplatform.mybatis.CreateAndUpdateMetaObjectHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@EnableTransactionManagement(proxyTargetClass = true) +@Configuration +public class MybatisPlusConfig extends PlatformConfiguration { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 鍒嗛〉鎻掍欢 + interceptor.addInnerInterceptor(paginationInnerInterceptor()); + // 涔愯閿佹彃浠� + interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); + // 闃绘柇鎻掍欢 +// interceptor.addInnerInterceptor(blockAttackInnerInterceptor()); + return interceptor; + } + + /** + * 鍒嗛〉鎻掍欢锛岃嚜鍔ㄨ瘑鍒暟鎹簱绫诲瀷 + * https://baomidou.com/guide/interceptor-pagination.html + */ + public PaginationInnerInterceptor paginationInnerInterceptor() { + PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); + // 璁剧疆鏁版嵁搴撶被鍨嬩负mysql + paginationInnerInterceptor.setDbType(DbType.MYSQL); + // 璁剧疆鏈�澶у崟椤甸檺鍒舵暟閲忥紝榛樿 500 鏉★紝-1 涓嶅彈闄愬埗 + paginationInnerInterceptor.setMaxLimit(-1L); + return paginationInnerInterceptor; + } + + /** + * 涔愯閿佹彃浠� + * https://baomidou.com/guide/interceptor-optimistic-locker.html + */ + public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() { + return new OptimisticLockerInnerInterceptor(); + } + + /** + * 濡傛灉鏄鍏ㄨ〃鐨勫垹闄ゆ垨鏇存柊鎿嶄綔锛屽氨浼氱粓姝㈣鎿嶄綔 + * https://baomidou.com/guide/interceptor-block-attack.html + */ +// public BlockAttackInnerInterceptor blockAttackInnerInterceptor() { +// return new BlockAttackInnerInterceptor(); +// } + + /** + * sql鎬ц兘瑙勮寖鎻掍欢(鍨冨溇SQL鎷︽埅) + * 濡傛湁闇�瑕佸彲浠ュ惎鐢� + */ +// public IllegalSQLInnerInterceptor illegalSQLInnerInterceptor() { +// return new IllegalSQLInnerInterceptor(); +// } + + + /** + * 鑷畾涔変富閿瓥鐣� + * https://baomidou.com/guide/id-generator.html + */ +// @Bean +// public IdentifierGenerator idGenerator() { +// return new CustomIdGenerator(); +// } + + /** + * 鍏冨璞″瓧娈靛~鍏呮帶鍒跺櫒 + * https://baomidou.com/guide/auto-fill-metainfo.html + */ + @Bean + public MetaObjectHandler metaObjectHandler() { + return new CreateAndUpdateMetaObjectHandler(); + } + + /** + * sql娉ㄥ叆鍣ㄩ厤缃� + * https://baomidou.com/guide/sql-injector.html + */ +// @Bean +// public ISqlInjector sqlInjector() { +// return new DefaultSqlInjector(); +// } + + /** + * TenantLineInnerInterceptor 澶氱鎴锋彃浠� + * https://baomidou.com/guide/interceptor-tenant-line.html + * DynamicTableNameInnerInterceptor 鍔ㄦ�佽〃鍚嶆彃浠� + * https://baomidou.com/guide/interceptor-dynamic-table-name.html + */ + +} diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/BaseEntity.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/BaseEntity.java index ad0595e..a57b0b4 100644 --- a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/BaseEntity.java +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/BaseEntity.java @@ -1,12 +1,11 @@ package com.iplatform.mybatis.domain; -import java.io.Serializable; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; /** * Entity鍩虹被 @@ -25,15 +24,17 @@ private String createBy; /** 鍒涘缓鏃堕棿 */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date createTime; +// @JsonFormat(pattern = "yyyyMMddHHmmss") +// private Date createTime; + private Long createTime; /** 鏇存柊鑰� */ private String updateBy; /** 鏇存柊鏃堕棿 */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date updateTime; +// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") +// private Date updateTime; + private Long updateTime; /** 澶囨敞 */ private String remark; @@ -62,12 +63,12 @@ this.createBy = createBy; } - public Date getCreateTime() + public Long getCreateTime() { return createTime; } - public void setCreateTime(Date createTime) + public void setCreateTime(Long createTime) { this.createTime = createTime; } @@ -82,12 +83,12 @@ this.updateBy = updateBy; } - public Date getUpdateTime() + public Long getUpdateTime() { return updateTime; } - public void setUpdateTime(Date updateTime) + public void setUpdateTime(Long updateTime) { this.updateTime = updateTime; } diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/TableDataInfo.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/TableDataInfo.java new file mode 100644 index 0000000..2c9e850 --- /dev/null +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/domain/TableDataInfo.java @@ -0,0 +1,85 @@ +package com.iplatform.mybatis.domain; + +import java.io.Serializable; +import java.util.List; + +/** + * 琛ㄦ牸鍒嗛〉鏁版嵁瀵硅薄 + * + * @author insurance + */ +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/pom.xml b/pom.xml index 2ba981f..5110464 100644 --- a/pom.xml +++ b/pom.xml @@ -77,6 +77,8 @@ <mybatis-plus-boot-starter.version>3.5.3.1</mybatis-plus-boot-starter.version> <mybatis-plus-annotation.version>3.5.5</mybatis-plus-annotation.version> <fastjson.version>2.0.23</fastjson.version> + <lombok.version>1.18.24</lombok.version> + <hutool.version>5.8.9</hutool.version> </properties> <dependencyManagement> @@ -332,13 +334,28 @@ <type>jar.sha256</type> </dependency> - <!-- 闃块噷JSON瑙f瀽鍣� --> + <!-- 闃块噷JSON瑙f瀽鍣紝2024-01-15 --> <dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>${fastjson.version}</version> </dependency> + <!-- lombok锛�2024-01-17 --> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + </dependency> + + <!-- hutool锛屾殏鏃跺彧寮曞叆鏍稿績鍖咃紝2024-01-17 --> + <dependency> + <groupId>cn.hutool</groupId> + <artifactId>hutool-core</artifactId> + <version>${hutool.version}</version> +<!-- <type>pom</type>--> + </dependency> + </dependencies> </dependencyManagement> -- Gitblit v1.9.1