diff --git a/iot-module/iot-generator/pom.xml b/iot-module/iot-generator/pom.xml index 97b6f0ec..fb3a9299 100644 --- a/iot-module/iot-generator/pom.xml +++ b/iot-module/iot-generator/pom.xml @@ -107,6 +107,7 @@ + diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityUtils.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityUtils.java index d0102736..47cdc631 100644 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityUtils.java +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityUtils.java @@ -121,6 +121,7 @@ public class VelocityUtils { templates.add("vm/java/idata.java.vm"); templates.add("vm/java/idataimpl.java.vm"); templates.add("vm/java/tbmodel.java.vm"); + templates.add("vm/java/repository.java.vm"); if (DataBaseHelper.isOracle()) { templates.add("vm/sql/oracle/sql.vm"); } else if (DataBaseHelper.isPostgerSql()) { @@ -162,11 +163,24 @@ public class VelocityUtils { if (template.contains("domain.java.vm")) { fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); } + if (template.endsWith("tbmodel.java.vm")) { + fileName = StringUtils.format("{}/data/model/Tb{}.java", javaPath, className); + } else if (template.endsWith("model.java.vm")) { + fileName = StringUtils.format("{}/model/{}.java", javaPath, className); + } + if (template.endsWith("repository.java.vm")) { + fileName = StringUtils.format("{}/repository/{}Repository.java", javaPath, className); + } + if (template.endsWith("idata.java.vm")) { + fileName = StringUtils.format("{}/data/I{}Data.java", javaPath, className); + } else if (template.endsWith("idataimpl.java.vm")) { + fileName = StringUtils.format("{}/data/impl/{}DataImpl.java", javaPath, className); + } if (template.contains("vo.java.vm")) { - fileName = StringUtils.format("{}/domain/vo/{}Vo.java", javaPath, className); + fileName = StringUtils.format("{}/dto/vo/{}Vo.java", javaPath, className); } if (template.contains("bo.java.vm")) { - fileName = StringUtils.format("{}/domain/bo/{}Bo.java", javaPath, className); + fileName = StringUtils.format("{}/dto/bo/{}Bo.java", javaPath, className); } if (template.contains("mapper.java.vm")) { fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); diff --git a/iot-module/iot-generator/src/main/resources/vm/java/bo.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/bo.java.vm index c82a9c1b..c8c73860 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/bo.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/bo.java.vm @@ -1,6 +1,6 @@ -package ${packageName}.domain.bo; +package ${packageName}.dto.bo; -import ${packageName}.domain.${ClassName}; +import ${packageName}.model.${ClassName}; import cc.iotkit.common.api.BaseDto; import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.Paging; diff --git a/iot-module/iot-generator/src/main/resources/vm/java/controller.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/controller.java.vm index eeaccc3f..b9ca0049 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/controller.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/controller.java.vm @@ -5,7 +5,7 @@ import java.util.List; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; -import jakarta.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponse; import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; import org.springframework.web.bind.annotation.*; @@ -19,8 +19,8 @@ import cc.iotkit.common.validate.AddGroup; import cc.iotkit.common.validate.EditGroup; import cc.iotkit.common.log.enums.BusinessType; import cc.iotkit.common.excel.utils.ExcelUtil; -import ${packageName}.domain.vo.${ClassName}Vo; -import ${packageName}.domain.bo.${ClassName}Bo; +import ${packageName}.dto.vo.${ClassName}Vo; +import ${packageName}.dto.bo.${ClassName}Bo; import ${packageName}.service.I${ClassName}Service; @@ -70,12 +70,11 @@ public class ${ClassName}Controller extends BaseController { /** * 获取${functionName}详细信息 * - * @param ${pkColumn.javaField} 主键 */ @SaCheckPermission("${permissionPrefix}:query") @PostMapping("/getDetail") @ApiOperation("获取${functionName}详细信息") - public R<${ClassName}Vo> getDetail(@Validated @RequestBody Request request) { + public ${ClassName}Vo getDetail(@Validated @RequestBody Request request) { return ${className}Service.queryById(request.getData()); } @@ -97,20 +96,19 @@ public class ${ClassName}Controller extends BaseController { @Log(title = "${functionName}", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ApiOperation("修改${functionName}") - public boolean edit(@Validated(EditGroup.class) @RequestBody Request<${ClassName}Bo> bo) { - return ${className}Service.updateByBo(bo); + public boolean edit(@Validated(EditGroup.class) @RequestBody Request<${ClassName}Bo> request) { + return ${className}Service.updateByBo(request.getData()); } /** * 删除${functionName} * - * @param ${pkColumn.javaField}s 主键串 */ @SaCheckPermission("${permissionPrefix}:remove") @Log(title = "${functionName}", businessType = BusinessType.DELETE) @PostMapping("/delete") @ApiOperation("删除${functionName}") public boolean remove(@Validated @RequestBody Request> query) { - return ${className}Service.deleteWithValidByIds(query.getData()); + return ${className}Service.deleteWithValidByIds(query.getData(), true); } } diff --git a/iot-module/iot-generator/src/main/resources/vm/java/idata.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/idata.java.vm index 423160aa..9dcec7e3 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/idata.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/idata.java.vm @@ -1,8 +1,7 @@ package ${packageName}.data; import cc.iotkit.data.ICommonData; -import cc.iotkit.model.system.SysRole; - +import ${packageName}.model.${ClassName}; import java.util.List; /** diff --git a/iot-module/iot-generator/src/main/resources/vm/java/idataimpl.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/idataimpl.java.vm index 557da813..bbf2cd95 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/idataimpl.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/idataimpl.java.vm @@ -2,12 +2,24 @@ package ${packageName}.data; import cc.iotkit.data.ICommonData; import ${packageName}.data.I${ClassName}Data; -import ${packageName}.data.${ClassName}; +import ${packageName}.data.model.Tb${ClassName}; +import ${packageName}.model.${ClassName}; import java.util.List; +import com.querydsl.core.QueryResults; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; +import cc.iotkit.data.util.PredicateBuilder; import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.StringUtils; +import java.util.Collection; +import cc.iotkit.common.utils.MapstructUtils; import static ${packageName}.data.model.QTb${ClassName}.tb${ClassName}; @@ -20,27 +32,11 @@ import static ${packageName}.data.model.QTb${ClassName}.tb${ClassName}; @Primary @Service @RequiredArgsConstructor -public class ${ClassName}DataImpl implements I${ClassName}Data, IJPACommData<${ClassName}, Long> { +public class ${ClassName}DataImpl implements I${ClassName}Data { private final ${ClassName}Repository baseRepository; - - - @Override - public JpaRepository getBaseRepository() { - return baseRepository; - } - - @Override - public Class getJpaRepositoryClass() { - return Tb${ClassName}.class; - } - - @Override - public Class getTClass() { - return ${ClassName}.class; - } - + private final JPAQueryFactory jpaQueryFactory; @Override public Paging<${ClassName}> findAll(PageRequest<${ClassName}> pageRequest) { @@ -73,4 +69,37 @@ public class ${ClassName}DataImpl implements I${ClassName}Data, IJPACommData<${C return builder.build(); } + @Override + public List<${ClassName}> findByIds(Collection id) { + List allById = baseRepository.findAllById(id); + return MapstructUtils.convert(allById, ${ClassName}.class); + } + + @Override + public ${ClassName} save(${ClassName} data) { + Object o = baseRepository.save(MapstructUtils.convert(data, Tb${ClassName}.class)); + return MapstructUtils.convert(o, ${ClassName}.class); + } + + @Override + public void batchSave(List<${ClassName}> data) { + baseRepository.saveAll(MapstructUtils.convert(data, Tb${ClassName}.class)); + } + + @Override + public void deleteById(Long id) { + baseRepository.deleteById(id); + } + + @Override + public void deleteByIds(Collection ids) { + baseRepository.deleteAllById(ids); + } + + @Override + public ${ClassName} findById(Long id) { + Tb${ClassName} ret = jpaQueryFactory.select(tb${ClassName}).from(tb${ClassName}).where(tb${ClassName}.id.eq(id)).fetchOne(); + ${ClassName} convert = MapstructUtils.convert(ret, ${ClassName}.class); + return convert; + } } diff --git a/iot-module/iot-generator/src/main/resources/vm/java/model.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/model.java.vm index 1fa1d167..6b75cdbb 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/model.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/model.java.vm @@ -9,7 +9,7 @@ import cc.iotkit.model.Id; #if($IsTenant==1) import cc.iotkit.model.TenantModel; #else -import cc.iotkit.data.model.BaseEntity; +import cc.iotkit.model.BaseModel; #end import lombok.Data; import lombok.EqualsAndHashCode; @@ -17,7 +17,8 @@ import lombok.EqualsAndHashCode; import ${import}; #end -import java.io.Serial; +import java.io.Serializable; + /** * ${functionName}对象 ${tableName} @@ -34,7 +35,6 @@ import java.io.Serial; @EqualsAndHashCode(callSuper = true) public class ${ClassName} extends ${Entity} implements Id, Serializable{ - @Serial private static final long serialVersionUID = 1L; #foreach ($column in $columns) diff --git a/iot-module/iot-generator/src/main/resources/vm/java/repository.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/repository.java.vm new file mode 100644 index 00000000..8453d1e0 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/repository.java.vm @@ -0,0 +1,15 @@ +package ${packageName}.data.dao; + +import cc.iotkit.data.model.Tb${ClassName}; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +/** + * ${functionName}对象 ${tableName} + * + * @author ${author} + * @date ${datetime} + */ +public interface ${ClassName}Repository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/service.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/service.java.vm index 03de0de9..d789b777 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/service.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/service.java.vm @@ -1,12 +1,12 @@ package ${packageName}.service; -import ${packageName}.domain.${ClassName}; -import ${packageName}.domain.vo.${ClassName}Vo; -import ${packageName}.domain.bo.${ClassName}Bo; +import ${packageName}.dto.vo.${ClassName}Vo; +import ${packageName}.dto.bo.${ClassName}Bo; #if($table.crud || $table.sub) -import cc.iotkit.common.mybatis.core.page.TableDataInfo; -import cc.iotkit.common.mybatis.core.page.PageQuery; + #end +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.PageRequest; import java.util.Collection; import java.util.List; diff --git a/iot-module/iot-generator/src/main/resources/vm/java/serviceImpl.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/serviceImpl.java.vm index 337dfbb3..d9651498 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/serviceImpl.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/serviceImpl.java.vm @@ -1,7 +1,7 @@ package ${packageName}.service.impl; -import cc.iotkit.common.core.utils.MapstructUtils; -import cc.iotkit.common.core.utils.StringUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; #if($table.crud || $table.sub) import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.Paging; @@ -9,14 +9,17 @@ import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Request; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import ${packageName}.domain.bo.${ClassName}Bo; -import ${packageName}.domain.vo.${ClassName}Vo; -import ${packageName}.domain.${ClassName}; +import ${packageName}.dto.bo.${ClassName}Bo; +import ${packageName}.dto.vo.${ClassName}Vo; +import ${packageName}.model.${ClassName}; import ${packageName}.service.I${ClassName}Service; +import ${packageName}.data.I${ClassName}Data; import java.util.List; import java.util.Map; import java.util.Collection; +import cc.iotkit.common.exception.BizException; + /** * ${functionName}Service业务层处理 @@ -35,7 +38,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service { */ @Override public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){ - return baseData.selectVoById(${pkColumn.javaField}); + return MapstructUtils.convert(baseData.findById(${pkColumn.javaField}), ${ClassName}Vo.class); } #if($table.crud || $table.sub) @@ -43,9 +46,8 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service { * 查询${functionName}列表 */ @Override - public Paging<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery) { - LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo); - Paging<${ClassName}Vo> result = baseData.selectVoPage(pageQuery.build(), lqw); + public Paging<${ClassName}Vo> queryPageList(PageRequest<${ClassName}Bo> pageQuery) { + Paging<${ClassName}Vo> result = baseData.findAll(pageQuery.to(${ClassName}.class)).to(${ClassName}Vo.class); return result; } #end @@ -56,22 +58,22 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service { @Override public List<${ClassName}Vo> queryList(${ClassName}Bo bo) { - return baseData.selectVoList(bo); + return MapstructUtils.convert(baseData.findAllByCondition(bo.to(${ClassName}.class)), ${ClassName}Vo.class); } /** * 新增${functionName} */ @Override - public Boolean insertByBo(${ClassName}Bo bo) { + public Long insertByBo(${ClassName}Bo bo) { ${ClassName} add = MapstructUtils.convert(bo, ${ClassName}.class); validEntityBeforeSave(add); - boolean flag = baseData.insert(add) > 0; -#set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)}) - if (flag) { - bo.set$pk(add.get$pk()); + baseData.save(add); + if (add == null) { + throw new BizException("新增失败"); } - return flag; + #set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)}) + return add.get$pk(); } /** @@ -81,7 +83,11 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service { public Boolean updateByBo(${ClassName}Bo bo) { ${ClassName} update = MapstructUtils.convert(bo, ${ClassName}.class); validEntityBeforeSave(update); - return baseData.updateById(update) > 0; + ${ClassName} ret = baseData.save(update); + if(ret == null){ + return false; + } + return true; } /** @@ -99,6 +105,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service { if(isValid){ //TODO 做一些业务上的校验,判断是否需要校验 } - return baseData.deleteBatchIds(ids) > 0; + baseData.deleteByIds(ids); + return true; } } diff --git a/iot-module/iot-generator/src/main/resources/vm/java/tbmodel.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/tbmodel.java.vm index b7901184..bef8d246 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/tbmodel.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/tbmodel.java.vm @@ -6,6 +6,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; #foreach ($column in $columns) #if($column.javaField=='tenantId') #set($IsTenant=1) @@ -22,7 +24,6 @@ import lombok.EqualsAndHashCode; import ${import}; #end -import java.io.Serial; /** * ${functionName}对象 ${tableName} @@ -43,8 +44,7 @@ import java.io.Serial; @AutoMapper(target = ${ClassName}.class) public class Tb${ClassName} extends ${Entity} { - @Serial - private static final long serialVersionUID = 1L; + #foreach ($column in $columns) #if(!$table.isSuperColumn($column.javaField)) diff --git a/iot-module/iot-generator/src/main/resources/vm/java/vo.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/vo.java.vm index 5635d53c..c9b222e4 100644 --- a/iot-module/iot-generator/src/main/resources/vm/java/vo.java.vm +++ b/iot-module/iot-generator/src/main/resources/vm/java/vo.java.vm @@ -1,9 +1,9 @@ -package ${packageName}.domain.vo; +package ${packageName}.dto.vo; #foreach ($import in $importList) import ${import}; #end -import ${packageName}.domain.${ClassName}; +import ${packageName}.model.${ClassName}; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import cc.iotkit.common.excel.annotation.ExcelDictFormat; @@ -28,7 +28,7 @@ import java.util.Date; @AutoMapper(target = ${ClassName}.class) public class ${ClassName}Vo implements Serializable { - @Serial + private static final long serialVersionUID = 1L; #foreach ($column in $columns)