language
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package ${package}.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.base.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import ${package}.service.I${className}Service;
|
||||
import ${package}.service.dao.${className};
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/${changeClassName}")
|
||||
public class ${className}Controller {
|
||||
|
||||
@Autowired
|
||||
private I${className}Service ${changeClassName}Service;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询${apiAlias}")
|
||||
//@SaCheckPermission("${changeClassName}:list")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page){
|
||||
return new ResponseEntity<>(TableDataInfo.build(${changeClassName}Service.queryAll(whereJson,page)),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增${apiAlias}")
|
||||
//@SaCheckPermission("${changeClassName}:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody ${className} entity){
|
||||
${changeClassName}Service.create(entity);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改${apiAlias}")
|
||||
//@SaCheckPermission("${changeClassName}:edit")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody ${className} entity){
|
||||
${changeClassName}Service.update(entity);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除${apiAlias}")
|
||||
//@SaCheckPermission("${changeClassName}:del")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
|
||||
${changeClassName}Service.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package ${package}.service.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
<#if hasTimestamp>
|
||||
import java.sql.Timestamp;
|
||||
</#if>
|
||||
<#if hasBigDecimal>
|
||||
import java.math.BigDecimal;
|
||||
</#if>
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description /
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Data
|
||||
public class ${className}Dto implements Serializable {
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
|
||||
<#if column.remark?has_content>
|
||||
/** ${column.remark} */
|
||||
</#if>
|
||||
<#if column.columnKey = 'PRI'>
|
||||
<#if !auto && pkColumnType = 'Long'>
|
||||
/** 防止精度丢失 */
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
</#if>
|
||||
</#if>
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package ${package}.service.dao;
|
||||
|
||||
<#if hasPk>
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
</#if>
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
<#if hasTimestamp>
|
||||
import java.sql.Timestamp;
|
||||
</#if>
|
||||
<#if hasBigDecimal>
|
||||
import java.math.BigDecimal;
|
||||
</#if>
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description /
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("${tableName}")
|
||||
public class ${className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.columnKey = 'PRI'>
|
||||
@TableId(value = "${column.columnName}", type = <#if auto>IdType.AUTO<#else>IdType.NONE</#if>)
|
||||
</#if>
|
||||
<#if column.remark?has_content>
|
||||
/** ${column.remark} */
|
||||
<#else>
|
||||
/** ${column.changeColumnName} */
|
||||
</#if>
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package ${package}.service.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import ${package}.service.dao.${className};
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
public interface ${className}Mapper extends BaseMapper<${className}> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${package}.service.dao.mapper.${className}Mapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,12 @@
|
||||
package ${package}.service.dto;
|
||||
|
||||
import org.nl.common.domain.query.BaseQuery;
|
||||
import ${package}.service.dao.${className};
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
public class ${className}Query extends BaseQuery<${className}> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
package ${package}.repository;
|
||||
|
||||
import ${package}.domain.${className};
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
public interface ${className}Repository extends JpaRepository<${className}, ${pkColumnType}>, JpaSpecificationExecutor<${className}> {
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.columnKey = 'UNI'>
|
||||
/**
|
||||
* 根据 ${column.capitalColumnName} 查询
|
||||
* @param ${column.columnName} /
|
||||
* @return /
|
||||
*/
|
||||
${className} findBy${column.capitalColumnName}(${column.columnType} ${column.columnName});
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package ${package}.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import ${package}.service.dao.${className};
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @description 服务接口
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
public interface I${className}Service extends IService<${className}> {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param whereJson 条件
|
||||
* @param pageable 分页参数
|
||||
* @return IPage<${className}>
|
||||
*/
|
||||
IPage<${className}> queryAll(Map whereJson, PageQuery pageable);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param entity /
|
||||
*/
|
||||
void create(${className} entity);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param entity /
|
||||
*/
|
||||
void update(${className} entity);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(Set<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package ${package}.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import ${package}.service.I${className}Service;
|
||||
import ${package}.service.dao.mapper.${className}Mapper;
|
||||
import ${package}.service.dao.${className};
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @description 服务实现
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements I${className}Service {
|
||||
|
||||
@Autowired
|
||||
private ${className}Mapper ${changeClassName}Mapper;
|
||||
|
||||
@Override
|
||||
public IPage<${className}> queryAll(Map whereJson, PageQuery page){
|
||||
LambdaQueryWrapper<${className}> lam = new LambdaQueryWrapper<>();
|
||||
IPage<${className}> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
${changeClassName}Mapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(${className} entity) {
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
|
||||
entity.set${pkChangeColName ? cap_first }(IdUtil.getSnowflake(1, 1).nextIdStr());
|
||||
entity.setCreate_id(currentUserId);
|
||||
entity.setCreate_name(nickName);
|
||||
entity.setCreate_time(now);
|
||||
entity.setUpdate_id(currentUserId);
|
||||
entity.setUpdate_name(nickName);
|
||||
entity.setUpdate_time(now);
|
||||
${changeClassName}Mapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(${className} entity) {
|
||||
${className} dto = ${changeClassName}Mapper.selectById(entity.get${pkChangeColName ? cap_first }());
|
||||
if (dto == null) throw new BadRequestException(LangProcess.msg("error_SystemAuthError"));
|
||||
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
entity.setUpdate_id(currentUserId);
|
||||
entity.setUpdate_name(nickName);
|
||||
entity.setUpdate_time(now);
|
||||
|
||||
${changeClassName}Mapper.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Set<String> ids) {
|
||||
// 真删除
|
||||
${changeClassName}Mapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user