diff --git a/src/main/java/org/yangliu/codegenerate/Main.java b/src/main/java/org/yangliu/codegenerate/Main.java index 27cf7b0..a662e86 100644 --- a/src/main/java/org/yangliu/codegenerate/Main.java +++ b/src/main/java/org/yangliu/codegenerate/Main.java @@ -69,8 +69,7 @@ public class Main { String user = "enjoy"; String password = "Nomi1234"; //2.选择表配置 - //String json="{\"oqc_spot_check_record\":\"抽检记录\",\"oqc_shipment_record\":\"成品出货记录\",\"oqc_1008_record\":\"1008仓台账\",\"oqc_after_sales_record\":\"售后记录\",\"oqc_special_sample\":\"特殊样件\",\"oqc_product_record\":\"产品追溯\",\"oqc_ncr_record\":\"NCR明细\",\"oqc_qrqc_record\":\"QRQC明细\"}"; - String json="{\"oqc_inspection_appearance\":\"检验任务-外观\"}"; + String json="{\"oqc_shipment_record\":\"成品出货记录\"}"; JSONObject tables = JSONObject.parseObject(json); for (String table : tables.keySet()) { String entityName = TableFieldUtil.tableNameToEntityName(table); @@ -81,17 +80,6 @@ public class Main { //3.生成 generate(bussi_package, table,primaryKeyField,entityName,description, tableEntityVoList); } - - /*if(!true){ - String table= "oqc_nspection_level_cl"; - String entityName="OqcNspectionLevelCl";//实体类 - String description = "检验水平-样本代字";//备注 - String primaryKeyField = "id";//主键 - List tableEntityVoList = printTableStructure(driver, url, user, password, table); - //3.生成 - generate(bussi_package, table,primaryKeyField,entityName,description, tableEntityVoList); - }*/ - } /** diff --git a/src/main/resources/yangliu/XXXController.javai b/src/main/resources/yangliu/XXXController.javai index 5781c8c..36bd159 100644 --- a/src/main/resources/yangliu/XXXController.javai +++ b/src/main/resources/yangliu/XXXController.javai @@ -5,24 +5,17 @@ import com.enjoy.common.core.web.domain.AjaxResult; import com.enjoy.common.core.web.page.TableDataInfo; import com.enjoy.common.log.annotation.Log; import com.enjoy.common.log.enums.BusinessType; -import ${bussiPackage}.${entityPackage}.${entityName}; -import ${bussiPackage}.dto.${entityName}DTO; import ${bussiPackage}.vo.Add${entityName}PVO; import ${bussiPackage}.vo.Edit${entityName}PVO; import ${bussiPackage}.vo.Query${entityName}VO; import ${bussiPackage}.service.I${entityName}Service; import java.util.Arrays; -import java.util.List; -import java.util.Map; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; +import javax.annotation.Resource; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -39,7 +32,7 @@ import org.springframework.web.multipart.MultipartFile; @RestController @RequestMapping("/${entityName?uncap_first}") public class ${entityName}Controller extends BaseController { - @Autowired + @Resource private I${entityName}Service ${entityName?uncap_first}Service; /** @@ -51,11 +44,9 @@ public class ${entityName}Controller extends BaseController { @ApiImplicitParam(name = "pageSize", value = "分页参数:每页数量", dataType = "String", paramType = "query") }) @GetMapping(value = "/list") - public TableDataInfo queryPageList(Query${entityName}VO query${entityName}VO, - HttpServletRequest req) { + public TableDataInfo queryPageList(Query${entityName}VO query${entityName}VO) { startPage(); - TableDataInfo tableDataInfo = ${entityName?uncap_first}Service.pageList(query${entityName}VO); - return tableDataInfo; + return ${entityName?uncap_first}Service.pageList(query${entityName}VO); } /** @@ -102,7 +93,7 @@ public class ${entityName}Controller extends BaseController { @Log(title = "删除", businessType = BusinessType.DELETE) @ApiOperation(value="删除", notes="删除") @DeleteMapping(value = "/delete") - public AjaxResult delete(@RequestParam(name="id",required=true) String id) { + public AjaxResult delete(@RequestParam(name="id") String id) { return ${entityName?uncap_first}Service.delete${entityName}(id); } @@ -112,7 +103,7 @@ public class ${entityName}Controller extends BaseController { @Log(title = "批量删除", businessType = BusinessType.DELETE) @ApiOperation(value="批量删除", notes="批量删除") @DeleteMapping(value = "/deleteBatch") - public AjaxResult deleteBatch(@RequestParam(name="ids",required=true) String ids) { + public AjaxResult deleteBatch(@RequestParam(name="ids") String ids) { return this.${entityName?uncap_first}Service.delete${entityName}(Arrays.asList(ids.split(","))); } @@ -131,7 +122,7 @@ public class ${entityName}Controller extends BaseController { */ @ApiOperation( value ="导入", notes ="导入", httpMethod ="POST") @PostMapping("/import") - public AjaxResult import${entityName}(@RequestPart("file") MultipartFile file) throws Exception { + public AjaxResult import${entityName}(@RequestPart("file") MultipartFile file) { return ${entityName?uncap_first}Service.import${entityName}(file); } diff --git a/src/main/resources/yangliu/XXXEntity.javai b/src/main/resources/yangliu/XXXEntity.javai index 7b35b1f..7328547 100644 --- a/src/main/resources/yangliu/XXXEntity.javai +++ b/src/main/resources/yangliu/XXXEntity.javai @@ -1,9 +1,6 @@ package ${bussiPackage}.${entityPackage}; import com.baomidou.mybatisplus.annotation.*; -import com.enjoy.common.core.annotation.Excel; -import com.enjoy.common.core.utils.iqc.ExcelImport; -import com.enjoy.oqc.domain.BaseEntity; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/resources/yangliu/XXXMapper.javai b/src/main/resources/yangliu/XXXMapper.javai index 0fbd648..4133803 100644 --- a/src/main/resources/yangliu/XXXMapper.javai +++ b/src/main/resources/yangliu/XXXMapper.javai @@ -1,7 +1,5 @@ package ${bussiPackage}.mapper; -import java.util.List; -import org.apache.ibatis.annotations.Param; import ${bussiPackage}.${entityPackage}.${entityName}; import com.baomidou.mybatisplus.core.mapper.BaseMapper; diff --git a/src/main/resources/yangliu/XXXService.javai b/src/main/resources/yangliu/XXXService.javai index 6e17ac3..6d2d907 100644 --- a/src/main/resources/yangliu/XXXService.javai +++ b/src/main/resources/yangliu/XXXService.javai @@ -2,7 +2,6 @@ package ${bussiPackage}.service; import com.enjoy.common.core.web.domain.AjaxResult; import com.enjoy.common.core.web.page.TableDataInfo; -import ${bussiPackage}.dto.${entityName}DTO; import ${bussiPackage}.vo.Query${entityName}VO; import ${bussiPackage}.vo.Add${entityName}PVO; import ${bussiPackage}.vo.Edit${entityName}PVO; diff --git a/src/main/resources/yangliu/XXXServiceImpl.javai b/src/main/resources/yangliu/XXXServiceImpl.javai index e00d78b..16d7bcb 100644 --- a/src/main/resources/yangliu/XXXServiceImpl.javai +++ b/src/main/resources/yangliu/XXXServiceImpl.javai @@ -4,7 +4,6 @@ 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; import com.enjoy.common.core.i18n.InternationalizationService; @@ -12,7 +11,7 @@ import com.enjoy.common.core.constant.Constants; import com.enjoy.common.core.constant.HttpStatus; import com.enjoy.common.core.web.page.TableDataInfo; import com.github.pagehelper.PageInfo; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; @@ -52,17 +51,17 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $ public TableDataInfo pageList(Query${entityName}VO query${entityName}VO){ TableDataInfo rspData=new TableDataInfo(); try{ - List<${entityName}DTO> list=new ArrayList(); - QueryWrapper<${entityName}> queryWrapper=new QueryWrapper(); + List<${entityName}DTO> list=new ArrayList<>(); + LambdaQueryWrapper<${entityName}> queryWrapper=new LambdaQueryWrapper<>(); <#list originalColumns as po> <#if po.fieldColumn == 'create_time'> - queryWrapper.orderByDesc("update_time","create_time"); + queryWrapper.orderByDesc(${entityName}::getCreateTime); <#else> List<${entityName}> dbEntityList = this.list(queryWrapper); if (CollectionUtil.isNotEmpty(dbEntityList)) { - dbEntityList.stream().forEach(entity->{ + dbEntityList.forEach(entity->{ ${entityName}DTO ${uncap_first}DTO=new ${entityName}DTO(); ${uncap_first}DTO = (${entityName}DTO) BeanHkUtils.copyProperties(entity,${uncap_first}DTO); list.add(${uncap_first}DTO); @@ -70,7 +69,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $ } rspData.setCode(HttpStatus.SUCCESS); rspData.setRows(list); - rspData.setTotal(new PageInfo(dbEntityList).getTotal()); + rspData.setTotal(new PageInfo<>(dbEntityList).getTotal()); rspData.setMsg(internationalizationService.getMessage(Constants.QUERY_SUCCESS)); return rspData; }catch(Exception e){ @@ -87,11 +86,10 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $ */ @Override public AjaxResult listAll(Query${entityName}VO query${entityName}VO){ - List<${entityName}DTO> list=new ArrayList(); - QueryWrapper<${entityName}> queryWrapper=new QueryWrapper(); - List<${entityName}> dbEntityList = this.list(queryWrapper); + List<${entityName}DTO> list=new ArrayList<>(); + List<${entityName}> dbEntityList = this.list(new LambdaQueryWrapper<>()); if (CollectionUtil.isNotEmpty(dbEntityList)) { - dbEntityList.stream().forEach(entity->{ + dbEntityList.forEach(entity->{ ${entityName}DTO ${uncap_first}DTO=new ${entityName}DTO(); ${uncap_first}DTO = (${entityName}DTO) BeanHkUtils.copyProperties(entity,${uncap_first}DTO); list.add(${uncap_first}DTO); @@ -135,7 +133,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $ */ @Override public AjaxResult delete${entityName}(String id){ - UpdateWrapper<${entityName}> updateWrapper=new UpdateWrapper(); + UpdateWrapper<${entityName}> updateWrapper=new UpdateWrapper<>(); updateWrapper.set("del_flag","1"); updateWrapper.eq("id",id); this.update(updateWrapper); @@ -150,7 +148,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $ if(!CollectionUtil.isNotEmpty(ids)){ return AjaxResult.error("id不可为空"); } - UpdateWrapper<${entityName}> updateWrapper=new UpdateWrapper(); + UpdateWrapper<${entityName}> updateWrapper=new UpdateWrapper<>(); updateWrapper.set("del_flag","1"); updateWrapper.in("id",ids); this.update(updateWrapper); @@ -161,21 +159,21 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $ */ @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}Excel> list=new ArrayList<>(); + LambdaQueryWrapper<${entityName}> queryWrapper=new LambdaQueryWrapper<>(); //根据选中项导出 if(StringUtils.isNotBlank(query${entityName}VO.getIds())){ - queryWrapper.in("id", Arrays.asList(query${entityName}VO.getIds().split(","))); + queryWrapper.in(${entityName}::getId, Arrays.asList(query${entityName}VO.getIds().split(","))); } List<${entityName}> dbEntityList = this.list(queryWrapper); if (CollectionUtil.isNotEmpty(dbEntityList)) { - dbEntityList.stream().forEach(entity->{ + dbEntityList.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); + ExcelUtil<${entityName}Excel> util = new ExcelUtil<>(${entityName}Excel.class); util.exportExcel(response, list, "${tableVo.ftlDescription}"); } @@ -200,7 +198,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $ */ @Override public void importTemplateExcel(HttpServletResponse response){ - ExcelUtil<${entityName}Excel> util = new ExcelUtil<${entityName}Excel>(${entityName}Excel.class); + ExcelUtil<${entityName}Excel> util = new ExcelUtil<>(${entityName}Excel.class); util.importTemplateExcel(response, "${tableVo.ftlDescription}"); }