master
周文涛 2 years ago
parent 9202ddf94c
commit 643d516be0

@ -35,6 +35,8 @@ public class Main {
//实体类模板
private static String bussi_entity_template = "XXXEntity.javai";
private static String bussi_entity_excel_template = "XXXEntityExcel.javai";
private static String bussi_entity_dto_template = "XXXEntityDTO.javai";
private static String bussi_entity_vo_template = "XXXEntityVO.javai";
private static String bussi_entity_add_vo_template = "XXXEntityAddPVO.javai";
@ -66,9 +68,9 @@ public class Main {
String user = "enjoy";
String password = "Nomi1234";
//2.选择表配置
String table= "oqc_lnspection_template";
String entityName="OqcLnspectionTemplate";//实体类
String description = "检验模板表";//备注
String table= "oqc_report_template";
String entityName="OqcReportTemplate";//实体类
String description = "报告模板";//备注
String primaryKeyField = "id";//主键
List<TableEntityVo> tableEntityVoList = printTableStructure(driver, url, user, password, table);
//3.生成
@ -88,6 +90,7 @@ public class Main {
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("bussiPackage", bussiPackage);//包
dataMap.put("entityPackage", "domain");//实体类包名 domain/entity
dataMap.put("excelPackage","oqcExcel");//导出Excel类的包
dataMap.put("tableName", tableName);//表名称
dataMap.put("tableVo", tableVo);//表属性
//主键
@ -109,6 +112,11 @@ public class Main {
MarkerGenerate.generate(templatepath, bussi_entity_template, entityParsePath, entityName + ".java", dataMap);
String dtoParsePath = parsePath + "dto" + File.separator;
MarkerGenerate.generate(templatepath, bussi_entity_dto_template, dtoParsePath, entityName + "DTO.java", dataMap);
//excel
String excelParsePath=parsePath +(String) dataMap.get("excelPackage")+ File.separator;;
MarkerGenerate.generate(templatepath, bussi_entity_excel_template, excelParsePath, entityName + "Excel.java", dataMap);
String voParsePath = parsePath + "vo" + File.separator;
//MarkerGenerate.generate(templatepath, bussi_entity_vo_template, voParsePath, entityName + "VO.java", dataMap);
//add_pvo

@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.multipart.MultipartFile;
/**
* @Description: ${tableVo.ftlDescription}
@ -117,4 +118,22 @@ public class ${entityName}Controller extends BaseController {
return this.${entityName?uncap_first}Service.delete${entityName}(Arrays.asList(ids.split(",")));
}
/**
* 导出
*/
@ApiOperation( value ="导出", notes ="导出", httpMethod ="POST")
@PostMapping("/export")
public void export(HttpServletResponse response,Query${entityName}VO query${entityName}VO){
${entityName?uncap_first}Service.export(response,query${entityName}VO);
}
/**
* 导入
*/
@ApiOperation( value ="导入", notes ="导入", httpMethod ="POST")
@PostMapping("/import")
public AjaxResult import${entityName}(@RequestPart("file") MultipartFile file) throws Exception {
return ${entityName?uncap_first}Service.import${entityName}(file);
}
}

@ -0,0 +1,62 @@
package ${bussiPackage}.${excelPackage};
import com.enjoy.common.core.annotation.Excel;
import com.enjoy.common.core.utils.iqc.ExcelImport;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @Description: ${tableVo.ftlDescription}
* @Author: ${author}
* @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0
*/
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class ${entityName}Excel{
private static final long serialVersionUID = 1L;
<#list originalColumns as po>
<#if po.fieldName =='id'|| po.fieldName=='delFlag' || po.fieldName == 'creatorId' || po.fieldName == 'createBy' || po.fieldName == 'createTime' || po.fieldName == 'updaterId' || po.fieldName == 'updateBy' || po.fieldName == 'updateTime' || po.fieldName == 'tenantId'><#else>
/**${po.filedComment}*/
<#if po.fieldName == primaryKeyField>
@TableId(type = IdType.ASSIGN_ID)
<#else>
<#if po.fieldType =='Date'>
<#if po.fieldDbType =='date'>
@Excel(name = "${po.filedComment}", width = 15)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
<#elseif po.fieldDbType =='datetime'>
@Excel(name = "${po.filedComment}", width = 20)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
<#elseif po.fieldDbType =='timestamp'>
@Excel(name = "${po.filedComment}", width = 20)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
</#if>
<#else>
@Excel(name = "${po.filedComment}", width = 15)
@ExcelImport("${po.filedComment}")
</#if>
</#if>
@ApiModelProperty(value = "${po.filedComment}",example = "${po.filedComment}")
<#if po.fieldName == 'delFlag'>
@TableLogic
</#if>
private <#if po.fieldType=='java.sql.Blob'>byte[]<#else>${po.fieldType}</#if> ${po.fieldName};
</#if>
</#list>
}

@ -8,6 +8,8 @@ import ${bussiPackage}.vo.Add${entityName}PVO;
import ${bussiPackage}.vo.Edit${entityName}PVO;
import ${bussiPackage}.${entityPackage}.${entityName};
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@ -51,4 +53,14 @@ public interface I${entityName}Service extends IService<${entityName}> {
* 批量删除
*/
AjaxResult delete${entityName}(List<String> ids);
/**
* 导出
*/
void export(HttpServletResponse response, Query${entityName}VO query${entityName}VO);
/**
* 导入
*/
AjaxResult import${entityName}(MultipartFile file);
}

@ -1,5 +1,9 @@
package ${bussiPackage}.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.enjoy.common.core.utils.iqc.IQCExcelUtils;
import com.enjoy.common.core.web.domain.AjaxResult;
import com.enjoy.common.security.utils.ExcelUtil;
import com.enjoy.common.core.web.domain.AjaxResult;
import com.enjoy.oqc.utils.BeanHkUtils;
import com.enjoy.oqc.utils.CollectionUtil;
@ -13,6 +17,8 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
@ -23,6 +29,7 @@ import ${bussiPackage}.mapper.${entityName}Mapper;
import ${bussiPackage}.service.I${entityName}Service;
import ${bussiPackage}.vo.Add${entityName}PVO;
import ${bussiPackage}.vo.Edit${entityName}PVO;
import ${bussiPackage}.oqcExcel.${entityName}Excel;
/**
@ -55,7 +62,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
if (CollectionUtil.isNotEmpty(dbEntityList)) {
dbEntityList.stream().forEach(entity->{
${entityName}DTO ${uncap_first}DTO=new ${entityName}DTO();
BeanHkUtils.copyProperties(entity,${uncap_first}DTO);
${uncap_first}DTO = (${entityName}DTO) BeanHkUtils.copyProperties(entity,${uncap_first}DTO);
list.add(${uncap_first}DTO);
});
}
@ -83,7 +90,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
if (CollectionUtil.isNotEmpty(dbEntityList)) {
dbEntityList.stream().forEach(entity->{
${entityName}DTO ${uncap_first}DTO=new ${entityName}DTO();
BeanHkUtils.copyProperties(entity,${uncap_first}DTO);
${uncap_first}DTO = (${entityName}DTO) BeanHkUtils.copyProperties(entity,${uncap_first}DTO);
list.add(${uncap_first}DTO);
});
}
@ -145,4 +152,38 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
this.update(updateWrapper);
return AjaxResult.success("删除成功!");
}
/**
* 导出
*/
@Override
public void export(HttpServletResponse response, Query${entityName}VO query${entityName}VO){
List<${entityName}Excel> list=new ArrayList();
QueryWrapper<${entityName}> queryWrapper=new QueryWrapper();
List<${entityName}> dbEntityList = this.list(queryWrapper);
if (CollectionUtil.isNotEmpty(dbEntityList)) {
dbEntityList.stream().forEach(entity->{
${entityName}Excel ${uncap_first}Excel=new ${entityName}Excel();
${uncap_first}Excel = (${entityName}Excel) BeanHkUtils.copyProperties(entity,${uncap_first}Excel);
list.add(${uncap_first}Excel);
});
}
ExcelUtil<${entityName}Excel> util = new ExcelUtil<${entityName}Excel>(${entityName}Excel.class);
util.exportExcel(response, list, "${tableVo.ftlDescription}");
}
/**
* 导入
*/
@Override
public AjaxResult import${entityName}(MultipartFile file){
try {
List<${entityName}Excel> excelList = IQCExcelUtils.readMultipartFile(file, ${entityName}Excel.class);
List<${entityName}> entityList = BeanUtil.copyToList(excelList, ${entityName}.class);
this.saveBatch(entityList);
}catch (Exception e){
log.error("导入 异常:",e);
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success("导入成功");
}
}

Loading…
Cancel
Save