完善模板

This commit is contained in:
wanggeng888 2021-03-11 16:47:30 +08:00
parent 3c0943d2fa
commit 87684fff27
20 changed files with 2442 additions and 49 deletions

16
pom.xml
View File

@ -40,6 +40,22 @@
</dependency>
<!-- pingyin end -->
<!-- jodatime start -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.4</version>
</dependency>
<!-- jodatime end -->
<!-- freemarker start -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
<!-- freemarker end -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>

View File

@ -1,8 +1,9 @@
package ink.wgink.code.factory.controller;
import freemarker.template.TemplateException;
import ink.wgink.code.factory.factory.ButtonTableCellFactory;
import ink.wgink.code.factory.factory.CheckBoxTableCellFactory;
import ink.wgink.code.factory.factory.ChoiceBoxTableCellFactory;
import ink.wgink.code.factory.factory.RadioButtonTableCellFactory;
import ink.wgink.code.factory.service.FieldService;
import ink.wgink.code.factory.service.GenerateService;
import ink.wgink.code.factory.utils.MsgUtil;
@ -20,6 +21,8 @@ import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ResourceBundle;
@ -70,6 +73,7 @@ public class GenerateController implements Initializable {
@Override
public void initialize(URL location, ResourceBundle resources) {
fieldService = new FieldService();
initTableView();
}
@ -87,18 +91,20 @@ public class GenerateController implements Initializable {
tableColumns.get(9).setCellValueFactory(new CheckBoxTableCellFactory("isListShow"));
tableColumns.get(10).setCellValueFactory(new CheckBoxTableCellFactory("isNotNull"));
tableColumns.get(11).setCellValueFactory(new ChoiceBoxTableCellFactory("formFieldType"));
tableColumns.get(12).setCellValueFactory(new ButtonTableCellFactory("option", fieldService));
}
public void setTableVO(TableVO tableVO) {
public void setTableVO(TableVO tableVO) throws IOException, URISyntaxException {
this.tablePrefixTextField.setText(tableVO.getTableName().split("\\_")[0] + "_");
this.tableVO = tableVO;
fieldService = new FieldService(fieldTableView, tableVO.getTableName());
generateService = new GenerateService(fieldTableView);
fieldService.showField();
this.generateService = new GenerateService(fieldTableView);
this.fieldService.setTableView(fieldTableView);
this.fieldService.setTableName(tableVO.getTableName());
this.fieldService.showField();
}
@FXML
public void onGenerateClick(ActionEvent actionEvent) {
public void onGenerateClick(ActionEvent actionEvent) throws IOException, TemplateException {
ObservableList<FieldVO> items = fieldTableView.getItems();
for (FieldVO fieldVO : items) {
if (StringUtils.isBlank(fieldVO.getFormFieldValue())) {
@ -108,7 +114,7 @@ public class GenerateController implements Initializable {
}
GenerateVO generateVO = new GenerateVO();
generateVO.setHasApi(apiCheckBox.isSelected());
generateVO.setHasApi(appCheckBox.isSelected());
generateVO.setHasApp(appCheckBox.isSelected());
generateVO.setHasResource(resourceCheckBox.isSelected());
generateVO.setHasIService(iServiceCheckBox.isSelected());
generateVO.setHasServiceImpl(serviceImplCheckBox.isSelected());
@ -120,7 +126,12 @@ public class GenerateController implements Initializable {
generateVO.setTablePrefix(tablePrefixTextField.getText());
generateVO.setContext(contextTextField.getText());
generateVO.setCodePackage(packageTextField.getText());
generateService.generateCode(generateVO);
generateService.generateCode(tableVO, generateVO);
}
@FXML
public void onRefreshClick(ActionEvent actionEvent) {
this.fieldService.showField();
}
}

View File

@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ResourceBundle;
@ -102,7 +103,7 @@ public class MainController implements Initializable {
}
@FXML
public void onTableRowClick(MouseEvent event) throws IOException {
public void onTableRowClick(MouseEvent event) throws IOException, URISyntaxException {
if (event.getClickCount() == 2) {
TableVO tableVO = (TableVO) this.dbTableTableView.getSelectionModel().getSelectedItem();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/route/generate.fxml"));

View File

@ -1,5 +1,21 @@
package ink.wgink.code.factory.factory;
import ink.wgink.code.factory.service.FieldService;
import ink.wgink.code.factory.vos.FieldVO;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.util.Callback;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Field;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
@ -10,5 +26,23 @@ package ink.wgink.code.factory.factory;
* @Date: 2021/3/8 22:07
* @Version: 1.0
**/
public class ButtonTableCellFactory {
public class ButtonTableCellFactory implements Callback<TableColumn.CellDataFeatures<FieldVO, String>, ObservableValue<Button>> {
private String property;
private FieldService fieldService;
public ButtonTableCellFactory(String property, FieldService fieldService) {
this.property = property;
this.fieldService = fieldService;
}
@Override
public ObservableValue<Button> call(TableColumn.CellDataFeatures<FieldVO, String> param) {
Button button = new Button("删除");
button.setOnAction(event -> {
fieldService.removeField(param.getValue().getColumnName());
});
return new ReadOnlyObjectWrapper<>(button);
}
}

View File

@ -29,22 +29,22 @@ import java.util.Map;
**/
public class FieldService {
private static final String DEFAULT_FIELD_ID = "id";
private static final String DEFAULT_FIELD_CREATOR = "creator";
private static final String DEFAULT_FIELD_GMT_CREATE = "gmtCreate";
private static final String DEFAULT_FIELD_MODIFIER = "modifier";
private static final String DEFAULT_FIELD_GMT_MODIFIED = "gmtModified";
private static final String DEFAULT_FIELD_IS_DELETE = "isDelete";
public static final String DEFAULT_FIELD_ID = "id";
public static final String DEFAULT_FIELD_CREATOR = "creator";
public static final String DEFAULT_COLUMN_CREATOR = "creator";
public static final String DEFAULT_FIELD_GMT_CREATE = "gmtCreate";
public static final String DEFAULT_COLUMN_GMT_CREATE = "gmt_create";
public static final String DEFAULT_FIELD_MODIFIER = "modifier";
public static final String DEFAULT_COLUMN_MODIFIER = "modifier";
public static final String DEFAULT_FIELD_GMT_MODIFIED = "gmtModified";
public static final String DEFAULT_COLUMN_GMT_MODIFIED = "gmt_modified";
public static final String DEFAULT_FIELD_IS_DELETE = "isDelete";
public static final String DEFAULT_COLUMN_IS_DELETE = "is_delete";
private ObservableList<FieldVO> fieldVOObservableList = FXCollections.observableArrayList();
private ObservableList<FieldVO> fields = FXCollections.observableArrayList();
private TableView tableView;
private String tableName;
public FieldService(TableView tableView, String tableName) {
this.tableView = tableView;
this.tableName = tableName;
}
/**
* 表单字段类型
*
@ -98,11 +98,9 @@ public class FieldService {
@Override
protected Integer call() throws Exception {
List<Map<String, Object>> tableFields = JdbcManager.getInstance().listTableField(tableName);
fieldVOObservableList.clear();
fields.clear();
int fieldIndex = 1;
for (Map<String, Object> field : tableFields) {
System.out.println(field);
String columnName = field.get("COLUMN_NAME").toString();
if (StringUtils.equals(DEFAULT_FIELD_ID, columnName)) {
continue;
@ -124,7 +122,7 @@ public class FieldService {
fieldVO.setNotNull(StringUtils.equalsIgnoreCase(ColumnIsNullableEnum.YES.getValue(), field.get("IS_NULLABLE").toString()) ? false : true);
fieldVO.setPropertyType(getPropertyType(fieldVO.getDataType()));
fieldVO.setFormFieldType(getFormFieldType(fieldVO.getDataType()));
fieldVOObservableList.add(fieldVO);
fields.add(fieldVO);
fieldIndex++;
}
return 0;
@ -134,10 +132,60 @@ public class FieldService {
@Override
protected void succeeded() {
tableView.setItems(fieldVOObservableList);
tableView.setItems(fields);
super.succeeded();
}
}.start();
}
public ObservableList<FieldVO> getFields() {
return fields;
}
public TableView getTableView() {
return tableView;
}
public void setTableView(TableView tableView) {
this.tableView = tableView;
}
public String getTableName() {
return tableName == null ? "" : tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public void removeField(String columnName) {
new Service<Integer>() {
@Override
protected Task<Integer> createTask() {
return new Task<Integer>() {
@Override
protected Integer call() throws Exception {
for (int i = 0; i < fields.size(); i++) {
FieldVO fieldVO = fields.get(i);
if (StringUtils.equals(fieldVO.getColumnName(), columnName)) {
fields.remove(i);
i--;
continue;
}
fieldVO.setRowNumber(i + 1);
}
return 0;
}
@Override
protected void succeeded() {
tableView.setItems(fields);
super.succeeded();
}
};
}
}.start();
}
}

View File

@ -1,12 +1,28 @@
package ink.wgink.code.factory.service;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import ink.wgink.code.factory.utils.DateUtil;
import ink.wgink.code.factory.utils.WStringUtil;
import ink.wgink.code.factory.vos.FieldVO;
import ink.wgink.code.factory.vos.GenerateVO;
import ink.wgink.code.factory.vos.TableVO;
import javafx.collections.ObservableList;
import javafx.scene.control.TableView;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
@ -21,14 +37,344 @@ import org.apache.commons.lang3.StringUtils;
public class GenerateService {
private TableView tableView;
private GenerateVO generateVO;
Configuration freemarkerConfiguration = new Configuration(Configuration.getVersion());
public GenerateService(TableView tableView) {
public GenerateService(TableView tableView) throws URISyntaxException, IOException {
this.tableView = tableView;
this.freemarkerConfiguration.setDirectoryForTemplateLoading(new File(getClass().getResource("/template").toURI()));
this.freemarkerConfiguration.setDefaultEncoding("utf-8");
}
public void generateCode(GenerateVO generateVO) {
ObservableList<FieldVO> items = tableView.getItems();
public void generateCode(TableVO tableVO, GenerateVO generateVO) throws IOException, TemplateException {
String outFolder = "/Users/wanggeng/Desktop/UploadFiles/code/";
// 无前缀表名
String tableFullName = tableVO.getTableName();
String tableNameWithoutPrefix = tableFullName.replaceFirst(generateVO.getTablePrefix(), "");
String tableName = WStringUtil.underLine2LowerUpper(tableNameWithoutPrefix);
// 首字母大写驼峰表名
String firstUpperTableName = WStringUtil.firstToUpper(tableName);
// 首字母小写驼峰表明
String firstLowerTableName = WStringUtil.firstToLower(tableName);
String lowerTableName = tableNameWithoutPrefix.replaceAll("\\_", "").toLowerCase();
Map<String, Object> dataModel = new HashMap<>(16);
dataModel.put("codePackage", generateVO.getCodePackage());
dataModel.put("tableNameWithoutPrefix", tableNameWithoutPrefix);
dataModel.put("lowerTableName", lowerTableName);
dataModel.put("tableName", tableName);
dataModel.put("tableFullName", tableFullName);
dataModel.put("firstUpperTableName", firstUpperTableName);
dataModel.put("firstLowerTableName", firstLowerTableName);
dataModel.put("tableExplain", tableVO.getTableComment());
dataModel.put("author", "CodeFactory");
dataModel.put("date", DateUtil.getTime());
dataModel.put("version", "3.0");
initFieldList(tableNameWithoutPrefix, dataModel, tableView.getItems());
// 生成API
if (generateVO.getHasApi()) {
apiCode("/controller/api-controller.ftl", String.format("%s/controller/api/%s", outFolder, lowerTableName), firstUpperTableName, dataModel);
}
if (generateVO.getHasApi()) {
appCode("/controller/app-controller.ftl", String.format("%s/controller/app/api/%s", outFolder, lowerTableName), firstUpperTableName, dataModel);
}
if (generateVO.getHasResource()) {
resourceCode("/controller/resource-controller.ftl", String.format("%s/controller/resource/%s", outFolder, lowerTableName), firstUpperTableName, dataModel);
}
if (generateVO.getHasIService()) {
iServiceCode("/service/i-service.ftl", String.format("%s/service/%s", outFolder, lowerTableName), firstUpperTableName, dataModel);
}
if (generateVO.getHasServiceImpl()) {
serviceImplCode("/service/service-impl.ftl", String.format("%s/service/%s/impl", outFolder, lowerTableName), firstUpperTableName, dataModel);
}
if (generateVO.getHasIDao()) {
iDaoCode("/dao/i-dao.ftl", String.format("%s/dao/%s", outFolder, lowerTableName), firstUpperTableName, dataModel);
}
if (generateVO.getHasMySQL()) {
mySqlMapperCode("/mapper/mysql-mapper.ftl", String.format("%s/mapper/%s", outFolder, tableName), tableName, dataModel);
}
if (generateVO.getHasHtml()) {
}
if (generateVO.getHasThymeleaf()) {
}
if (generateVO.getHasRoute()) {
}
boCode("/pojo/bo.ftl", String.format("%s/pojo/bos", outFolder, lowerTableName), firstUpperTableName, dataModel);
dtoCode("/pojo/dto.ftl", String.format("%s/pojo/dtos", outFolder, lowerTableName), firstUpperTableName, dataModel);
poCode("/pojo/po.ftl", String.format("%s/pojo/pos", outFolder, lowerTableName), firstUpperTableName, dataModel);
voCode("/pojo/vo.ftl", String.format("%s/pojo/vos", outFolder, lowerTableName), firstUpperTableName, dataModel);
}
/**
* 初始化字段
*
* @param dataModel
*/
private void initFieldList(String tableNameWithoutPrefix, Map<String, Object> dataModel, ObservableList<FieldVO> fields) {
List<Map<String, Object>> fieldList = new ArrayList<>();
boolean hasId = false;
boolean hasGmtCreate = false;
boolean hasCreator = false;
boolean hasGmtModified = false;
boolean hasModifier = false;
boolean hasIsDelete = false;
for (int i = 0; i < fields.size(); i++) {
FieldVO field = fields.get(i);
if (!hasId && StringUtils.equals(String.format("%s_id", tableNameWithoutPrefix), field.getColumnName())) {
hasId = true;
}
if (!hasGmtCreate && StringUtils.equals(FieldService.DEFAULT_FIELD_GMT_CREATE, field.getPropertyName())) {
hasGmtCreate = true;
}
if (!hasCreator && StringUtils.equals(FieldService.DEFAULT_FIELD_CREATOR, field.getPropertyName())) {
hasCreator = true;
}
if (!hasGmtModified && StringUtils.equals(FieldService.DEFAULT_FIELD_GMT_MODIFIED, field.getPropertyName())) {
hasGmtModified = true;
}
if (!hasModifier && StringUtils.equals(FieldService.DEFAULT_FIELD_MODIFIER, field.getPropertyName())) {
hasModifier = true;
}
if (!hasIsDelete && StringUtils.equals(FieldService.DEFAULT_FIELD_IS_DELETE, field.getPropertyName())) {
hasIsDelete = true;
}
Map<String, Object> fieldMap = new HashMap<>(16);
fieldMap.put("columnName", field.getColumnName());
fieldMap.put("propertyName", field.getPropertyName());
fieldMap.put("firstUpperPropertyName", WStringUtil.firstToUpper(field.getPropertyName()));
fieldMap.put("propertyType", field.getPropertyType());
fieldMap.put("columnComment", field.getColumnComment());
fieldMap.put("formFieldValue", field.getFormFieldValue());
fieldMap.put("formShow", field.getFormShow());
fieldMap.put("listShow", field.getListShow());
String fieldSplit = "";
if (i < fields.size() - 1) {
fieldSplit = ",";
}
fieldMap.put("fieldSplit", fieldSplit);
fieldList.add(fieldMap);
}
dataModel.put("hasId", hasId);
dataModel.put("hasGmtCreate", hasGmtCreate);
dataModel.put("hasCreator", hasCreator);
dataModel.put("hasGmtModified", hasGmtModified);
dataModel.put("hasModifier", hasModifier);
dataModel.put("hasIsDelete", hasIsDelete);
dataModel.put("fieldList", fieldList);
}
/**
* api-controller
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void apiCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%sController.java", outFolder, firstUpperTableName), dataModel);
}
/**
* app-controller
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void appCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%sAppController.java", outFolder, firstUpperTableName), dataModel);
}
/**
* resource-controller
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void resourceCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%sResourceController.java", outFolder, firstUpperTableName), dataModel);
}
/**
* i-service
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void iServiceCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/I%sService.java", outFolder, firstUpperTableName), dataModel);
}
/**
* service-impl
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void serviceImplCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%sServiceImpl.java", outFolder, firstUpperTableName), dataModel);
}
/**
* i-dao-impl
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void iDaoCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/I%sDao.java", outFolder, firstUpperTableName), dataModel);
}
/**
* mysql-mapper
*
* @param templateFtl
* @param outFolder
* @param tableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void mySqlMapperCode(String templateFtl, String outFolder, String tableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%s-mapper.xml", outFolder, tableName), dataModel);
}
/**
* bo
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void boCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%sBO.java", outFolder, firstUpperTableName), dataModel);
}
/**
* dto
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void dtoCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%sDTO.java", outFolder, firstUpperTableName), dataModel);
}
/**
* po
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void poCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%sPO.java", outFolder, firstUpperTableName), dataModel);
}
/**
* po
*
* @param templateFtl
* @param outFolder
* @param firstUpperTableName
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void voCode(String templateFtl, String outFolder, String firstUpperTableName, Map<String, Object> dataModel) throws IOException, TemplateException {
File folder = new File(outFolder);
if (!folder.exists()) {
folder.mkdirs();
}
code(templateFtl, String.format("%s/%sVO.java", outFolder, firstUpperTableName), dataModel);
}
/**
* 生成代码
*
* @param templateFtl
* @param outFile
* @param dataModel
* @throws IOException
* @throws TemplateException
*/
private void code(String templateFtl, String outFile, Map<String, Object> dataModel) throws IOException, TemplateException {
Template template = freemarkerConfiguration.getTemplate(templateFtl);
Writer out = new FileWriter(outFile);
template.process(dataModel, out);
out.close();
}
}

View File

@ -0,0 +1,448 @@
package ink.wgink.code.factory.utils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 说明日期处理 创建人CM 修改时间2015年11月24日
*/
public class DateUtil {
public final static String AM = "AM";
public final static String PM = "PM";
public final static SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
public final static SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");
public final static SimpleDateFormat sdfd = new SimpleDateFormat("dd");
public final static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
public final static SimpleDateFormat sdfDayZh = new SimpleDateFormat("yyyy年MM月dd日");
public final static SimpleDateFormat sdfDays = new SimpleDateFormat("yyyyMMdd");
public final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss");
public final static SimpleDateFormat sdfYearMonth = new SimpleDateFormat("yyyyMM");
public static String getZhDate(String date) {
try {
return sdfDayZh.format(sdfDay.parse(date));
} catch (Exception e) {
e.printStackTrace();
return date;
}
}
/**
* 校验日期格式
*
* @param date
* @param simpleDateFormat
* @return
*/
public static boolean checkFormat(String date, SimpleDateFormat simpleDateFormat) {
if (StringUtils.isEmpty(date) || simpleDateFormat == null) {
return false;
}
try {
simpleDateFormat.parse(date);
return true;
} catch (ParseException e) {
return false;
}
}
/**
* 获取YYYYMM格式
*
* @return
*/
public static String getSdfYearMonth() {
return sdfYearMonth.format(new Date());
}
/**
* 获取YYYYMMDDHHMMSS格式
*
* @return
*/
public static String getSdfTimes() {
return sdfTimes.format(new Date());
}
/**
* 获取YYYY格式
*
* @return
*/
public static String getYear() {
return sdfYear.format(new Date());
}
/**
* 获取MM格式
*
* @return
*/
public static String getMonth() {
return sdfMonth.format(new Date());
}
/**
* 获取dd格式
*
* @return
*/
public static String getToday() {
return sdfd.format(new Date());
}
/**
* 获取YYYY-MM-DD格式
*
* @return
*/
public static String getDay() {
return sdfDay.format(new Date());
}
/**
* 获取YYYYMMDD格式
*
* @return
*/
public static String getDays() {
return sdfDays.format(new Date());
}
/**
* 获取YYYY-MM-DD HH:mm:ss格式
*
* @return
*/
public static String getTime() {
return sdfTime.format(new Date());
}
/**
* 截取日期
*
* @param datetime
* @return
*/
public static String getDate(String datetime) {
return datetime.substring(0, 10);
}
/**
* @param s
* @param e
* @return boolean
* @throws @author fh
* @Title: compareDate
* @Description: TODO(日期比较 如果s > = e 返回true 否则返回false)
*/
public static boolean compareDate(String s, String e) {
if (fomatDate(s) == null || fomatDate(e) == null) {
return false;
}
return fomatDate(s).getTime() >= fomatDate(e).getTime();
}
/**
* 格式化日期
*
* @param date
* @return
*/
public static Date fomatDate(String date) {
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try {
return fmt.parse(date);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
/**
* 校验日期是否合法
*
* @param s
* @return
*/
public static boolean isValidDate(String s) {
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try {
fmt.parse(s);
return true;
} catch (Exception e) {
// 如果throw java.text.ParseException或者NullPointerException就说明格式不对
return false;
}
}
/**
* @param startTime
* @param endTime
* @return
*/
public static int getDiffYear(String startTime, String endTime) {
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try {
// long aa=0;
int years = (int) (((fmt.parse(endTime).getTime() - fmt.parse(startTime).getTime()) / (1000 * 60 * 60 * 24))
/ 365);
return years;
} catch (Exception e) {
// 如果throw java.text.ParseException或者NullPointerException就说明格式不对
return 0;
}
}
/**
* <li>功能描述时间相减得到天数
*
* @param beginDateStr
* @param endDateStr
* @return long
* @author Administrator
*/
public static long getDaySub(String beginDateStr, String endDateStr) {
long day = 0;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date beginDate = null;
Date endDate = null;
try {
beginDate = format.parse(beginDateStr);
endDate = format.parse(endDateStr);
} catch (ParseException e) {
e.printStackTrace();
}
day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
// System.out.println("相隔的天数="+day);
return day;
}
/**
* 得到n天之后的日期
*
* @param days
* @return
*/
public static String getAfterDayDate(String days) {
int daysInt = Integer.parseInt(days);
Calendar canlendar = Calendar.getInstance(); // java.util包
canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
Date date = canlendar.getTime();
SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = sdfd.format(date);
return dateStr;
}
/**
* 得到n天之后是周几
*
* @param days
* @return
*/
public static String getAfterDayWeek(String days) {
int daysInt = Integer.parseInt(days);
Calendar canlendar = Calendar.getInstance(); // java.util包
canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
Date date = canlendar.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("E");
String dateStr = sdf.format(date);
return dateStr;
}
/**
* 计算年龄生日格式yyyy-MM-dd
*
* @param birth
* @return
*/
public static String getAge(String birth) {
int cYear = Integer.parseInt(getYear());
String[] births = birth.split("-");
int year = Integer.parseInt(births[0]);
if (cYear <= year) {
return "0";
}
int cMonth = Integer.parseInt(getMonth());
int cDay = Integer.parseInt(getToday());
int month = Integer.parseInt(births[1]);
int day = Integer.parseInt(births[2]);
int age = cYear - year;
if (cMonth - month > 0) {
return String.valueOf(age);
}
if (cDay - day > 0) {
return String.valueOf(age);
}
return String.valueOf(age - 1);
}
/**
* 获取本周周一的日期
*/
public static String weekStartDate(String pattern) {
return new DateTime().dayOfWeek().withMinimumValue().toString(pattern);
}
/**
* 获取本周周一的日期
*/
public static Date weekStartDate() {
return new DateTime().dayOfWeek().withMinimumValue().toDate();
}
/**
* 获取本周最后一天
*
* @return
*/
public static String weekEndDate(String pattern) {
return new DateTime().dayOfWeek().withMaximumValue().toString(pattern);
}
/**
* 获取本周最后一天
*
* @return
*/
public static Date weekEndDate() {
return new DateTime().dayOfWeek().withMaximumValue().toDate();
}
/**
* 获取本月开始日期
*
* @param pattern
* @return
*/
public static String monthStartDate(String pattern) {
return new DateTime().dayOfMonth().withMinimumValue().toString(pattern);
}
/**
* 获取本月开始日期
*
* @param pattern
* @return
*/
public static Date monthStartDate() {
return new DateTime().dayOfMonth().withMinimumValue().toDate();
}
/**
* 获取本月结束日期
*
* @param pattern
* @return
*/
public static String monthEndDate(String pattern) {
return new DateTime().dayOfMonth().withMaximumValue().toString(pattern);
}
/**
* 获取本月结束日期
*
* @return
*/
public static Date monthEndDate() {
return new DateTime().dayOfMonth().withMaximumValue().toDate();
}
/**
* 格式化日期
*
* @param parseLong
* @param format
* @return
*/
public static String formatDate(long parseLong, String format) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
return simpleDateFormat.format(new Date(parseLong));
}
/**
* 获取前几天的日期带格式
*
* @param day
* @param format
* @return
*/
public static String getBeforeDate(int day, String format) {
DateTime time = new DateTime().plusDays(-day);
return sdfDay.format(time.toDate());
}
/**
* 计算时间差
*
* @param startTime
* @param endTime
* @param format
* @return
*/
public static long getTimeConsuming(String startTime, String endTime, String format) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
long start = simpleDateFormat.parse(startTime).getTime();
long end = simpleDateFormat.parse(endTime).getTime();
long useTime = end - start;
return useTime < 0 ? 0 : useTime;
}
/**
* 计算年龄
*
* @param birthday yyyy-MM-dd
* @return
*/
public static int getAgeByBirthday(String birthday) {
int age = 0;
String[] days = getDay().split("-");
String[] births = birthday.split("-");
int year = Integer.parseInt(days[0]);
int birthYear = Integer.parseInt(births[0]);
int month = Integer.parseInt(days[1]);
int birthMonth = Integer.parseInt(births[1]);
int day = Integer.parseInt(days[2]);
int birthDay = Integer.parseInt(births[2]);
// 判断年龄是否相等
if (year - birthYear > 0) {
if (month - birthMonth > 0) {
return year - birthYear;
} else if (month - birthMonth == 0) {
if (day - birthDay > 0) {
return year - birthYear;
}
return year - birthYear - 1;
}
return year - birthYear - 1;
}
return age;
}
/**
* 获得上下午标识
*
* @return
*/
public static String getAmPm() {
DateTime dateTime = new DateTime();
int hour = dateTime.getHourOfDay();
if (hour < 13) {
return AM;
}
return PM;
}
}

View File

@ -189,7 +189,7 @@ public class FieldVO {
}
public Boolean getFormShow() {
return isFormShow;
return isFormShow == null ? true : isFormShow;
}
public void setFormShow(Boolean formShow) {
@ -197,7 +197,7 @@ public class FieldVO {
}
public Boolean getListShow() {
return isListShow;
return isListShow == null ? true : isListShow;
}
public void setListShow(Boolean listShow) {
@ -205,7 +205,7 @@ public class FieldVO {
}
public Boolean getNotNull() {
return isNotNull;
return isNotNull == null ? false : isNotNull;
}
public void setNotNull(Boolean notNull) {

View File

@ -1,13 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<AnchorPane prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ink.wgink.code.factory.controller.GenerateController">
<AnchorPane prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ink.wgink.code.factory.controller.GenerateController">
<children>
<BorderPane layoutX="200.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
@ -152,7 +157,8 @@
</padding>
</Label>
<TextField fx:id="packageTextField" prefWidth="100.0" promptText="代码基础包" text="ink.wgink" />
<Button mnemonicParsing="false" onAction="#onGenerateClick" text="Generator" />
<Button mnemonicParsing="false" onAction="#onGenerateClick" text="生成代码" />
<Button mnemonicParsing="false" onAction="#onRefreshClick" text="重置列表" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
@ -167,17 +173,18 @@
<TableView fx:id="fieldTableView" BorderPane.alignment="CENTER">
<columns>
<TableColumn maxWidth="50.0" minWidth="50.0" prefWidth="50.0" resizable="false" style="-fx-alignment: center;" text="行号" />
<TableColumn prefWidth="250.0" style="-fx-alignment: center;" text="列名" />
<TableColumn prefWidth="250.0" style="-fx-alignment: center;" text="列描述" />
<TableColumn prefWidth="75.0" style="-fx-alignment: center;" text="列默认值" />
<TableColumn prefWidth="150.0" style="-fx-alignment: center;" text="列类型" />
<TableColumn prefWidth="250.0" style="-fx-alignment: center;" text="属性名" />
<TableColumn prefWidth="100.0" style="-fx-alignment: center;" text="属性类型" />
<TableColumn prefWidth="100.0" style="-fx-alignment: center;" text="属性长度" />
<TableColumn prefWidth="150.0" style="-fx-alignment: center;" text="列名" />
<TableColumn prefWidth="150.0" style="-fx-alignment: center;" text="列描述" />
<TableColumn prefWidth="70.0" style="-fx-alignment: center;" text="列默认值" />
<TableColumn style="-fx-alignment: center;" text="列类型" />
<TableColumn prefWidth="150.0" style="-fx-alignment: center;" text="属性名" />
<TableColumn style="-fx-alignment: center;" text="属性类型" />
<TableColumn style="-fx-alignment: center;" text="属性长度" />
<TableColumn style="-fx-alignment: center;" text="表单显示" />
<TableColumn style="-fx-alignment: center;" text="列表显示" />
<TableColumn style="-fx-alignment: center;" text="不可空" />
<TableColumn prefWidth="150.0" style="-fx-alignment: center;" text="表单字段类型" />
<TableColumn prefWidth="75.0" style="-fx-alignment: center;" text="操作" />
</columns>
</TableView>
</children>

View File

@ -0,0 +1,113 @@
package ${codePackage}.controller.api.${lowerTableName};
import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import ${codePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}BO;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}PO;
import ${codePackage}.service.${lowerTableName}.I${firstUpperTableName}Service;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @ClassName: ${firstUpperTableName}Controller
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "${tableExplain}接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/${lowerTableName}")
public class ${firstUpperTableName}Controller extends AbstractController {
@Autowired
private I${firstUpperTableName}Service ${firstLowerTableName}Service;
@ApiOperation(value = "新增${tableExplain}", notes = "新增${tableExplain}接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("save")
@CheckRequestBodyAnnotation
public SuccessResult save(@RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) {
${firstLowerTableName}Service.save(${firstLowerTableName}VO);
return new SuccessResult();
}
@ApiOperation(value = "删除${tableExplain}", notes = "删除${tableExplain}接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "ID列表用下划线分隔", paramType = "path", example = "1_2_3")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@DeleteMapping("remove/{ids}")
public SuccessResult remove(@PathVariable("ids") String ids) {
${firstLowerTableName}Service.remove(ids);
return new SuccessResult();
}
@ApiOperation(value = "修改${tableExplain}", notes = "修改${tableExplain}接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PutMapping("update/{${firstLowerTableName}Id}")
@CheckRequestBodyAnnotation
public SuccessResult update(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id, @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) {
${firstLowerTableName}Service.update(${firstLowerTableName}Id, ${firstLowerTableName}VO);
return new SuccessResult();
}
@ApiOperation(value = "${tableExplain}详情", notes = "${tableExplain}详情接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("get/{${firstLowerTableName}Id}")
public ${firstUpperTableName}DTO get(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id) {
return ${firstLowerTableName}Service.get(${firstLowerTableName}Id);
}
@ApiOperation(value = "${tableExplain}列表", notes = "${tableExplain}列表接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("list")
public List<${firstUpperTableName}DTO> list() {
Map<String, Object> params = requestParams();
return ${firstLowerTableName}Service.list(params);
}
@ApiOperation(value = "${tableExplain}分页列表", notes = "${tableExplain}分页列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpage")
public SuccessResultList<List<${firstUpperTableName}DTO>> listPage(ListPage page) {
Map<String, Object> params = requestParams();
page.setParams(params);
return ${firstLowerTableName}Service.listPage(page);
}
@ApiOperation(value = "${tableExplain}统计", notes = "${tableExplain}统计接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("count")
SuccessResultData<Integer> count() {
Map<String, Object> params = requestParams();
return new SuccessResultData<>(${firstLowerTableName}Service.count(params));
}
}

View File

@ -0,0 +1,121 @@
package ${codePackage}.controller.app.api.${lowerTableName};
import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import ${codePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO;
import ${codePackage}.service.${lowerTableName}.I${firstUpperTableName}Service;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @ClassName: ${firstUpperTableName}AppController
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "${tableExplain}接口")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/${lowerTableName}")
public class ${firstUpperTableName}AppController extends AbstractController {
@Autowired
private I${firstUpperTableName}Service ${firstLowerTableName}Service;
@ApiOperation(value = "新增${tableExplain}", notes = "新增${tableExplain}接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("save")
@CheckRequestBodyAnnotation
public SuccessResult save(@RequestHeader("token") String token, @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) {
${firstLowerTableName}Service.save(token, ${firstLowerTableName}VO);
return new SuccessResult();
}
@ApiOperation(value = "删除${tableExplain}(id列表)", notes = "删除${tableExplain}(id列表)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "ids", value = "ID列表用下划线分隔", paramType = "path", example = "1_2_3")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@DeleteMapping("remove/{ids}")
public SuccessResult remove(@RequestHeader("token") String token, @PathVariable("ids") String ids) {
${firstLowerTableName}Service.remove(token, ids);
return new SuccessResult();
}
@ApiOperation(value = "修改${tableExplain}", notes = "修改${tableExplain}接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PutMapping("update${lowerTableName}/{${firstLowerTableName}Id}")
@CheckRequestBodyAnnotation
public SuccessResult update${firstUpperTableName}(@RequestHeader("token") String token, @PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id, @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) {
${firstLowerTableName}Service.update(token, ${firstLowerTableName}Id, ${firstLowerTableName}VO);
return new SuccessResult();
}
@ApiOperation(value = "${tableExplain}详情(通过ID)", notes = "${tableExplain}详情(通过ID)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("get/{${firstLowerTableName}Id}")
public ${firstUpperTableName}DTO get(@RequestHeader("token") String token, @PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id) {
return ${firstLowerTableName}Service.get(${firstLowerTableName}Id);
}
@ApiOperation(value = "${tableExplain}列表", notes = "${tableExplain}列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("list")
public List<${firstUpperTableName}DTO> list(@RequestHeader("token") String token) {
Map<String, Object> params = requestParams();
return ${firstLowerTableName}Service.list(params);
}
@ApiOperation(value = "${tableExplain}分页列表", notes = "${tableExplain}分页列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpage${lowerTableName}")
public SuccessResultList<List<${firstUpperTableName}DTO>> listPage(@RequestHeader("token") String token, ListPage page) throws SearchException {
Map<String, Object> params = requestParams();
page.setParams(params);
return ${firstLowerTableName}Service.listPage(page);
}
@ApiOperation(value = "${tableExplain}统计", notes = "${tableExplain}统计接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("count")
SuccessResultData<Integer> count() throws SearchException {
Map<String, Object> params = requestParams();
return return new SuccessResultData<>(${firstLowerTableName}Service.count(params));
}
}

View File

@ -0,0 +1,121 @@
package ${codePackage}.controller.resource.${lowerTableName};
import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import ${codePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO;
import ${codePackage}.service.${lowerTableName}.I${firstUpperTableName}Service;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @ClassName: ${firstUpperTableName}ResourceController
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "${tableExplain}接口")
@RestController
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/${lowerTableName}")
public class ${firstUpperTableName}ResourceController extends AbstractController {
@Autowired
private I${firstUpperTableName}Service ${firstLowerTableName}Service;
@ApiOperation(value = "新增${tableExplain}", notes = "新增${tableExplain}接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("save")
@CheckRequestBodyAnnotation
public SuccessResult save(@RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) {
${firstLowerTableName}Service.save(${firstLowerTableName}VO);
return new SuccessResult();
}
@ApiOperation(value = "删除${tableExplain}(id列表)", notes = "删除${tableExplain}(id列表)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"),
@ApiImplicitParam(name = "ids", value = "ID列表用下划线分隔", paramType = "path", example = "1_2_3")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@DeleteMapping("remove/{ids}")
public SuccessResult remove(@PathVariable("ids") String ids) {
${firstLowerTableName}Service.remove(ids);
return new SuccessResult();
}
@ApiOperation(value = "修改${tableExplain}", notes = "修改${tableExplain}接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"),
@ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PutMapping("update/{${firstLowerTableName}Id}")
@CheckRequestBodyAnnotation
public SuccessResult update(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id, @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) {
${firstLowerTableName}Service.update(${firstLowerTableName}Id, ${firstLowerTableName}VO);
return new SuccessResult();
}
@ApiOperation(value = "${tableExplain}详情", notes = "${tableExplain}详情接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"),
@ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("get/{${firstLowerTableName}Id}")
public ${firstUpperTableName}DTO get(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id) {
return ${firstLowerTableName}Service.get(${firstLowerTableName}Id);
}
@ApiOperation(value = "${tableExplain}列表", notes = "${tableExplain}列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("list")
public List<${firstUpperTableName}DTO> list() {
Map<String, Object> params = requestParams();
return ${firstLowerTableName}Service.list(params);
}
@ApiOperation(value = "${tableExplain}分页列表", notes = "${tableExplain}分页列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"),
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpage")
public SuccessResultList<List<${firstUpperTableName}DTO>> listPage(ListPage page) throws SearchException {
Map<String, Object> params = requestParams();
page.setParams(params);
return ${firstLowerTableName}Service.listPage(page);
}
@ApiOperation(value = "${tableExplain}统计", notes = "${tableExplain}统计接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("count")
SuccessResultData<Integer> count() throws SearchException {
Map<String, Object> params = requestParams();
return return new SuccessResultData<>(${firstLowerTableName}Service.count(params));
}
}

View File

@ -0,0 +1,120 @@
package ${codePackage}.dao.${lowerTableName};
import com.cm.common.exception.RemoveException;
import com.cm.common.exception.SaveException;
import com.cm.common.exception.SearchException;
import com.cm.common.exception.UpdateException;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}BO;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}PO;
import ${codePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
/**
* @ClassName: I${firstUpperTableName}Dao
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@Repository
public interface I${firstUpperTableName}Dao {
/**
* 新增${tableExplain}
*
* @param params
* @throws SaveException
*/
void save(Map<String, Object> params) throws SaveException;
/**
* 删除${tableExplain}
*
* @param params
* @throws RemoveException
*/
void remove(Map<String, Object> params) throws RemoveException;
/**
* 删除${tableExplain}(物理)
*
* @param params
* @throws RemoveException
*/
void delete(Map<String, Object> params) throws RemoveException;
/**
* 修改${tableExplain}
*
* @param params
* @throws UpdateException
*/
void update(Map<String, Object> params) throws UpdateException;
/**
* ${tableExplain}详情
*
* @param params
* @return
* @throws SearchException
*/
${firstUpperTableName}DTO get(Map<String, Object> params) throws SearchException;
/**
* ${tableExplain}详情
*
* @param params
* @return
* @throws SearchException
*/
${firstUpperTableName}BO getBO(Map<String, Object> params) throws SearchException;
/**
* ${tableExplain}详情
*
* @param params
* @return
* @throws SearchException
*/
${firstUpperTableName}PO getPO(Map<String, Object> params) throws SearchException;
/**
* ${tableExplain}列表
*
* @param params
* @return
* @throws SearchException
*/
List<${firstUpperTableName}DTO> list(Map<String, Object> params) throws SearchException;
/**
* ${tableExplain}列表
*
* @param params
* @return
* @throws SearchException
*/
List<${firstUpperTableName}BO> listBO(Map<String, Object> params) throws SearchException;
/**
* ${tableExplain}列表
*
* @param params
* @return
* @throws SearchException
*/
List<${firstUpperTableName}PO> listPO(Map<String, Object> params) throws SearchException;
/**
* ${tableExplain}统计
*
* @param params
* @return
* @throws SearchException
*/
Integer count(Map<String, Object> params) throws SearchException;
}

View File

@ -0,0 +1,327 @@
<?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="${codePackage}.dao.${lowerTableName}.I${firstUpperTableName}Dao">
<resultMap id="${firstLowerTableName}DTO" type="${codePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO">
<#list fieldList! as field>
<result column="${field.columnName}" property="${field.propertyName}"/>
</#list>
</resultMap>
<resultMap id="${firstLowerTableName}BO" type="${codePackage}.pojo.bos.${lowerTableName}.${firstUpperTableName}BO">
<#list fieldList! as field>
<result column="${field.columnName}" property="${field.propertyName}"/>
</#list>
</resultMap>
<resultMap id="${firstLowerTableName}PO" type="${codePackage}.pojo.pos.${lowerTableName}.${firstUpperTableName}PO">
<#list fieldList! as field>
<result column="${field.columnName}" property="${field.propertyName}"/>
</#list>
</resultMap>
<!-- 新增${tableExplain} -->
<insert id="save" parameterType="map">
INSERT INTO ${tableFullName}(
<#list fieldList! as field>
${field.columnName}${field.fieldSplit}
</#list>
) VALUES(
<#list fieldList! as field>
${r"#{"}${field.propertyName}${r"}"}${field.fieldSplit}
</#list>
)
</insert>
<#if hasIsDelete>
<!-- 删除${tableExplain} -->
<update id="remove" parameterType="map">
UPDATE
${tableFullName}
SET
<#if hasGmtModified>
gmt_modified = ${r"#{gmtModified}"},
</#if>
<#if hasModifier>
modifier = ${r"#{modifier}"},
</#if>
is_delete = 1
WHERE
<#if hasId>
${tableName}_id IN
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
<#else>
<!-- 添加条件 -->
</#if>
</update>
</#if>
<!-- 删除${tableExplain}(物理) -->
<update id="delete" parameterType="map">
DELETE FROM
${tableFullName}
WHERE
<#if hasId>
${tableName}_id IN
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
<#else>
<!-- 添加条件 -->
</#if>
</update>
<!-- 修改${tableExplain} -->
<update id="update" parameterType="map">
UPDATE
${tableFullName}
SET
<#list fieldList! as field>
<#if field.formFieldValue == "number" || field.formFieldValue == "double">
<if test="${field.propertyName} != null">
${field.columnName} = ${r"#{"}${field.propertyName}${r"}"}${field.fieldSplit}
</if>
<#elseif field.formFieldValue == "radio" || field.formFieldValue == "checkbox" || field.formFieldValue == "select">
<if test="${field.propertyName} != null">
${field.columnName} = ${r"#{"}${field.propertyName}${r"}"}${field.fieldSplit}
</if>
<#else>
<if test="${field.propertyName} != null and ${field.propertyName} != ''">
${field.columnName} = ${r"#{"}${field.propertyName}${r"}"}${field.fieldSplit}
</if>
</#if>
</#list>
WHERE
<#if hasId>
${tableName}_id = ${r"#{"}${firstLowerTableName}${r"Id}"}
<#else>
<!-- 添加条件 -->
</#if>
</update>
<!-- ${tableExplain}详情 -->
<select id="get" parameterType="map" resultMap="${firstLowerTableName}DTO">
SELECT
<#list fieldList! as field>
<#if field.formShow>
t1.${field.columnName},
</#if>
</#list>
<#if hasId>
t1.${tableName}_id
<#else>
1
</#if>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<#if hasId>
<if test="${firstLowerTableName}Id != null and ${firstLowerTableName}Id != ''">
AND
t1.${tableName}_id = ${r"#{"}${firstLowerTableName}${r"Id}"}
</if>
<#else>
<!-- 添加条件 -->
</#if>
</select>
<!-- ${tableExplain}详情 -->
<select id="getBO" parameterType="map" resultMap="${firstLowerTableName}BO">
SELECT
<#list fieldList! as field>
t1.${field.columnName}${field.fieldSplit}
</#list>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<#if hasId>
<if test="${firstLowerTableName}Id != null and ${firstLowerTableName}Id != ''">
AND
t1.${tableName}_id = ${r"#{"}${firstLowerTableName}${r"Id}"}
</if>
<#else>
<!-- 添加条件 -->
</#if>
</select>
<!-- ${tableExplain}详情 -->
<select id="getPO" parameterType="map" resultMap="${firstLowerTableName}PO">
SELECT
<#list fieldList! as field>
t1.${field.columnName}${field.fieldSplit}
</#list>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<#if hasId>
<if test="${firstLowerTableName}Id != null and ${firstLowerTableName}Id != ''">
AND
t1.${tableName}_id = ${r"#{"}${firstLowerTableName}${r"Id}"}
</if>
<#else>
<!-- 添加条件 -->
</#if>
</select>
<!-- ${tableExplain}列表 -->
<select id="list" parameterType="map" resultMap="${firstLowerTableName}DTO">
SELECT
<#list fieldList! as field>
<#if field.listShow>
t1.${field.columnName},
</#if>
</#list>
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.id LIKE CONCAT('%', ${r"#{keywords}"}, '%')
)
</if>
<#if hasGmtCreate>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> ${r"#{startTime}"}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> ${r"#{endTime}"}
</if>
</#if>
<#if hasId>
<if test="${firstLowerTableName}Ids != null and ${firstLowerTableName}Ids.size > 0">
AND
t1.${tableName}_id IN
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
</if>
</#if>
</select>
<!-- ${tableExplain}列表 -->
<select id="listBO" parameterType="map" resultMap="${firstLowerTableName}BO">
SELECT
<#list fieldList! as field>
t1.${field.columnName}${field.fieldSplit}
</#list>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.id LIKE CONCAT('%', ${r"#{keywords}"}, '%')
)
</if>
<#if hasGmtCreate>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> ${r"#{startTime}"}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> ${r"#{endTime}"}
</if>
</#if>
<#if hasId>
<if test="${firstLowerTableName}Ids != null and ${firstLowerTableName}Ids.size > 0">
AND
t1.${tableName}_id IN
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
</if>
</#if>
</select>
<!-- ${tableExplain}列表 -->
<select id="listPO" parameterType="map" resultMap="${firstLowerTableName}PO">
SELECT
<#list fieldList! as field>
t1.${field.columnName}${field.fieldSplit}
</#list>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.id LIKE CONCAT('%', ${r"#{keywords}"}, '%')
)
</if>
<#if hasGmtCreate>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> ${r"#{startTime}"}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> ${r"#{endTime}"}
</if>
</#if>
<#if hasId>
<if test="${firstLowerTableName}Ids != null and ${firstLowerTableName}Ids.size > 0">
AND
t1.${tableName}_id IN
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
</if>
</#if>
</select>
<!-- ${tableExplain}统计 -->
<select id="count" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
</select>
</mapper>

View File

@ -0,0 +1,72 @@
package ${codePackage}.pojo.vos.${lowerTableName};
import com.cm.common.annotation.CheckEmptyAnnotation;
import com.cm.common.annotation.CheckNumberAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
*
* @ClassName: ${firstUpperTableName}BO
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
public class ${firstUpperTableName}BO {
<#list fieldList! as field>
<#if field.formFieldValue == "number">
private Integer ${field.propertyName};
<#elseif field.formFieldValue == "double">
private Double ${field.propertyName};
<#elseif field.formFieldValue == "date">
private String ${field.propertyName};
<#elseif field.formFieldValue == "datetime">
private String ${field.propertyName};
<#else>
private String ${field.propertyName};
</#if>
</#list>
<#list fieldList! as field>
<#if field.formFieldValue == "number">
public Integer get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? 0 : ${field.propertyName};
}
public void set${field.firstUpperPropertyName}(Integer ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#elseif field.formFieldValue == "double">
public Double get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? 0D : ${field.propertyName};
}
public void set${field.firstUpperPropertyName}(Double ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#elseif field.formFieldValue == "date" || field.formFieldValue == "datetime">
public String get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? "" : ${field.propertyName}.trim();
}
public void set${field.firstUpperPropertyName}(String ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#else>
public String get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? "" : ${field.propertyName}.trim();
}
public void set${field.firstUpperPropertyName}(String ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
</#if>
</#list>
}

View File

@ -0,0 +1,74 @@
package ${codePackage}.pojo.dtos.${lowerTableName};
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
*
* @ClassName: ${firstUpperTableName}DTO
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@ApiModel
public class ${firstUpperTableName}DTO {
<#list fieldList! as field>
<#if field.formFieldValue == "number">
@ApiModelProperty(name = "${field.propertyName}", value = "${field.columnComment}")
private Integer ${field.propertyName};
<#elseif field.formFieldValue == "double">
@ApiModelProperty(name = "${field.propertyName}", value = "${field.columnComment}")
private Double ${field.propertyName};
<#elseif field.formFieldValue == "radio" || field.formFieldValue == "checkbox" || field.formFieldValue == "select">
@ApiModelProperty(name = "${field.propertyName}", value = "${field.columnComment}")
private String ${field.propertyName};
<#else>
@ApiModelProperty(name = "${field.propertyName}", value = "${field.columnComment}")
private String ${field.propertyName};
</#if>
</#list>
<#list fieldList! as field>
<#if field.formFieldValue == "number">
public Integer get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? 0 : ${field.propertyName};
}
public void set${field.firstUpperPropertyName}(Integer ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#elseif field.formFieldValue == "double">
public Double get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? 0D : ${field.propertyName};
}
public void set${field.firstUpperPropertyName}(Double ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#elseif field.formFieldValue == "radio" || field.formFieldValue == "checkbox" || field.formFieldValue == "select">
public String get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? "" : ${field.propertyName}.trim();
}
public void set${field.firstUpperPropertyName}(String ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#else>
public String get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? "" : ${field.propertyName}.trim();
}
public void set${field.firstUpperPropertyName}(String ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
</#if>
</#list>
}

View File

@ -0,0 +1,73 @@
package ${codePackage}.pojo.vos.${lowerTableName};
import com.cm.common.annotation.CheckEmptyAnnotation;
import com.cm.common.annotation.CheckNumberAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
*
* @ClassName: ${firstUpperTableName}PO
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@ApiModel
public class ${firstUpperTableName}PO {
<#list fieldList! as field>
<#if field.formFieldValue == "number">
private Integer ${field.propertyName};
<#elseif field.formFieldValue == "double">
private Double ${field.propertyName};
<#elseif field.formFieldValue == "date">
private String ${field.propertyName};
<#elseif field.formFieldValue == "datetime">
private String ${field.propertyName};
<#else>
private String ${field.propertyName};
</#if>
</#list>
<#list fieldList! as field>
<#if field.formFieldValue == "number">
public Integer get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? 0 : ${field.propertyName};
}
public void set${field.firstUpperPropertyName}(Integer ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#elseif field.formFieldValue == "double">
public Double get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? 0D : ${field.propertyName};
}
public void set${field.firstUpperPropertyName}(Double ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#elseif field.formFieldValue == "date" || field.formFieldValue == "datetime">
public String get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? "" : ${field.propertyName}.trim();
}
public void set${field.firstUpperPropertyName}(String ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#else>
public String get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? "" : ${field.propertyName}.trim();
}
public void set${field.firstUpperPropertyName}(String ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
</#if>
</#list>
}

View File

@ -0,0 +1,99 @@
package ${codePackage}.pojo.vos.${lowerTableName};
import com.cm.common.annotation.CheckEmptyAnnotation;
import com.cm.common.annotation.CheckNumberAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
*
* @ClassName: ${firstUpperTableName}VO
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@ApiModel
public class ${firstUpperTableName}VO {
<#list fieldList! as field>
@ApiModelProperty(name = "${field.propertyName}", value = "${field.columnComment}")
<#if field.formFieldValue == "number">
@CheckNumberAnnotation(name = "${field.columnComment}")
private Integer ${field.propertyName};
<#elseif field.formFieldValue == "double">
@CheckNumberAnnotation(name = "${field.columnComment}")
private Double ${field.propertyName};
<#elseif field.formFieldValue == "date">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "date")
private String ${field.propertyName};
<#elseif field.formFieldValue == "datetime">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "datetime")
private String ${field.propertyName};
<#else>
<#if field.formFieldValue == "string">
<#if field.verifyType?? && field.verifyType != "none">
<#if field.verifyType == "phone">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "phone")
<#elseif field.verifyType == "email">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "email")
<#elseif field.verifyType == "url">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "url")
<#elseif field.verifyType == "number">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "number")
<#elseif field.verifyType == "date">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "date")
<#elseif field.verifyType == "identity">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "identity")
<#elseif field.verifyType == "custom">
@CheckEmptyAnnotation(name = "${field.columnComment}", verifyType = "custom", regex = "${field.verifyType}")
<#elseif field.verifyType == "required">
@CheckEmptyAnnotation(name = "${field.columnComment}")
</#if>
</#if>
</#if>
private String ${field.propertyName};
</#if>
</#list>
<#list fieldList! as field>
<#if field.formFieldValue == "number">
public Integer get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? 0 : ${field.propertyName};
}
public void set${field.firstUpperPropertyName}(Integer ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#elseif field.formFieldValue == "double">
public Double get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? 0D : ${field.propertyName};
}
public void set${field.firstUpperPropertyName}(Double ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#elseif field.formFieldValue == "date" || field.formFieldValue == "datetime">
public String get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? "" : ${field.propertyName}.trim();
}
public void set${field.firstUpperPropertyName}(String ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
<#else>
public String get${field.firstUpperPropertyName}() {
return ${field.propertyName} == null ? "" : ${field.propertyName}.trim();
}
public void set${field.firstUpperPropertyName}(String ${field.propertyName}) {
this.${field.propertyName} = ${field.propertyName};
}
</#if>
</#list>
}

View File

@ -0,0 +1,191 @@
package ${codePackage}.service.${lowerTableName};
import com.cm.common.pojo.ListPage;
import com.cm.common.result.SuccessResultList;
import ${codePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO;
import ${codePackage}.pojo.bos.${lowerTableName}.${firstUpperTableName}BO;
import ${codePackage}.pojo.pos.${lowerTableName}.${firstUpperTableName}PO;
import java.util.List;
import java.util.Map;
/**
* @ClassName: I${firstUpperTableName}Service
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
public interface I${firstUpperTableName}Service {
/**
* 新增${tableExplain}
*
* @param ${firstLowerTableName}VO
* @return
*/
void save(${firstUpperTableName}VO ${firstLowerTableName}VO);
/**
* 新增${tableExplain}
*
* @param token
* @param ${firstLowerTableName}VO
* @return
*/
void save(String token, ${firstUpperTableName}VO ${firstLowerTableName}VO);
/**
* 新增${tableExplain}
*
* @param ${firstLowerTableName}VO
* @return ${firstLowerTableName}Id
*/
String saveReturnId(${firstUpperTableName}VO ${firstLowerTableName}VO);
/**
* 新增${tableExplain}
*
* @param token
* @param ${firstLowerTableName}VO
* @return ${firstLowerTableName}Id
*/
String saveReturnId(String token, ${firstUpperTableName}VO ${firstLowerTableName}VO);
/**
* 删除${tableExplain}
*
* @param ids id列表
* @return
*/
void remove(List<String> ids);
/**
* 删除${tableExplain}
*
* @param token
* @param ids id列表
* @return
*/
void remove(String token, List<String> ids);
/**
* 删除${tableExplain}(物理删除)
*
* @param ids id列表
* @throws RemoveException
*/
void delete(List<String> ids);
/**
* 修改${tableExplain}
*
* @param ${firstLowerTableName}Id
* @param ${firstLowerTableName}VO
* @return
*/
void update(String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO);
/**
* 修改${tableExplain}
*
* @param token
* @param ${firstLowerTableName}Id
* @param ${firstLowerTableName}VO
* @return
*/
void update(String token, String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO);
/**
* ${tableExplain}详情
*
* @param params 参数Map
* @return
*/
${firstUpperTableName}DTO get(Map<String, Object> params);
/**
* ${tableExplain}详情
*
* @param ${firstLowerTableName}Id
* @return
*/
${firstUpperTableName}DTO get(String ${firstLowerTableName}Id);
/**
* ${tableExplain}详情
*
* @param params 参数Map
* @return
*/
${firstUpperTableName}BO getBO(Map<String, Object> params);
/**
* ${tableExplain}详情
*
* @param ${firstLowerTableName}Id
* @return
*/
${firstUpperTableName}BO getBO(String ${firstLowerTableName}Id);
/**
* ${tableExplain}详情
*
* @param params 参数Map
* @return
*/
${firstUpperTableName}PO getPO(Map<String, Object> params);
/**
* ${tableExplain}详情
*
* @param ${firstLowerTableName}Id
* @return
*/
${firstUpperTableName}PO getPO(String ${firstLowerTableName}Id);
/**
* ${tableExplain}列表
*
* @param params
* @return
*/
List<${firstUpperTableName}DTO> list(Map<String, Object> params);
/**
* ${tableExplain}列表
*
* @param params
* @return
*/
List<${firstUpperTableName}BO> listBO(Map<String, Object> params);
/**
* ${tableExplain}列表
*
* @param params
* @return
*/
List<${firstUpperTableName}PO> listPO(Map<String, Object> params);
/**
* ${tableExplain}分页列表
*
* @param page
* @return
* @throws SearchException
*/
SuccessResultList<List<${firstUpperTableName}DTO>> listPage(ListPage page);
/**
* ${tableExplain}统计
*
* @param params
* @return
* @throws SearchException
*/
Integer count(Map<String, Object> params);
}

View File

@ -0,0 +1,171 @@
package ${codePackage}.service.${lowerTableName}.impl;
import com.cm.common.base.AbstractService;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultList;
import com.cm.common.utils.HashMapUtil;
import com.cm.common.utils.UUIDUtil;
import ${codePackage}.dao.${lowerTableName}.I${firstUpperTableName}Dao;
import ${codePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO;
import ${codePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO;
import ${codePackage}.pojo.bos.${lowerTableName}.${firstUpperTableName}BO;
import ${codePackage}.pojo.pos.${lowerTableName}.${firstUpperTableName}PO;
import ${codePackage}.service.${lowerTableName}.I${firstUpperTableName}Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* @ClassName: ${firstUpperTableName}ServiceImpl
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@Service
public class ${firstUpperTableName}ServiceImpl extends AbstractService implements I${firstUpperTableName}Service {
@Autowired
private I${firstUpperTableName}Dao ${firstLowerTableName}Dao;
@Override
public SuccessResult save(${firstUpperTableName}VO ${firstLowerTableName}VO) {
saveReturnId(${firstLowerTableName}VO);
}
@Override
public SuccessResult save(String token, ${firstUpperTableName}VO ${firstLowerTableName}VO) {
saveReturnId(token, ${firstLowerTableName}VO);
}
@Override
public String saveReturnId(${firstUpperTableName}VO ${firstLowerTableName}VO) {
return saveReturnId(null, ${firstLowerTableName}VO);
}
@Override
public String saveReturnId(String token, ${firstUpperTableName}VO ${firstLowerTableName}VO) {
String ${firstLowerTableName}Id = UUIDUtil.getUUID();
Map<String, Object> params = HashMapUtil.beanToMap(${firstLowerTableName}VO);
params.put("${firstLowerTableName}Id", ${firstLowerTableName}Id);
if (StringUtils.isBlank(token)) {
setSaveInfo(params);
} else {
setAppSaveInfo(params, token);
}
${firstLowerTableName}Dao.save(params);
return ${firstLowerTableName}Id;
}
@Override
public void remove(String ids) {
remove(null, ids);
}
@Override
public void remove(String token, String ids) {
Map<String, Object> params = getHashMap(2);
params.put("${firstLowerTableName}Ids", ids);
if (StringUtils.isBlank(token)) {
setUpdateInfo(params);
} else {
setAppUpdateInfo(params, token);
}
userDao.remove(params);
}
@Override
public void delete(List<String> ids) {
Map<String, Object> params = getHashMap(2);
params.put("${firstLowerTableName}Ids", ids);
${firstLowerTableName}Dao.delete(params);
}
@Override
public void update(String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO) {
update(null, ${firstLowerTableName}Id, ${firstLowerTableName}VO);
}
@Override
public void update(String token, String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO) {
Map<String, Object> params = HashMapUtil.beanToMap(${firstLowerTableName}VO);
params.put("${firstLowerTableName}Id", ${firstLowerTableName}Id);
if (StringUtils.isBlank(token)) {
setUpdateInfo(params);
} else {
setAppUpdateInfo(token, params);
}
${firstLowerTableName}Dao.update(params);
}
@Override
public ${firstUpperTableName}DTO get(Map<String, Object> params) throws SearchException {
return ${firstLowerTableName}Dao.get(params);
}
@Override
public ${firstUpperTableName}DTO get(String ${firstLowerTableName}Id) throws SearchException {
Map<String, Object> params = super.getHashMap(2);
params.put("${firstLowerTableName}Id", ${firstLowerTableName}Id);
return get(params);
}
@Override
public ${firstUpperTableName}BO getBO(Map<String, Object> params) throws SearchException {
return ${firstLowerTableName}Dao.getBO(params);
}
@Override
public ${firstUpperTableName}BO getBO(String ${firstLowerTableName}Id) throws SearchException {
Map<String, Object> params = super.getHashMap(2);
params.put("${firstLowerTableName}Id", ${firstLowerTableName}Id);
return getBO(params);
}
@Override
public ${firstUpperTableName}PO getPO(Map<String, Object> params) throws SearchException {
return ${firstLowerTableName}Dao.getPO(params);
}
@Override
public ${firstUpperTableName}PO getPO(String ${firstLowerTableName}Id) throws SearchException {
Map<String, Object> params = super.getHashMap(2);
params.put("${firstLowerTableName}Id", ${firstLowerTableName}Id);
return getPO(params);
}
@Override
public List<${firstUpperTableName}DTO> list(Map<String, Object> params) throws SearchException {
return ${firstLowerTableName}Dao.list(params);
}
@Override
public List<${firstUpperTableName}BO> listBO(Map<String, Object> params) throws SearchException {
return ${firstLowerTableName}Dao.listBO(params);
}
@Override
public List<${firstUpperTableName}PO> listPO(Map<String, Object> params) throws SearchException {
return ${firstLowerTableName}Dao.listPO(params);
}
@Override
public SuccessResultList<List<${firstUpperTableName}DTO>> listPage(ListPage page) throws SearchException {
PageHelper.startPage(page.getPage(), page.getRows());
List<${firstUpperTableName}DTO> ${firstLowerTableName}DTOs = list(page.getParams());
PageInfo<${firstUpperTableName}DTO> pageInfo = new PageInfo<>(${firstLowerTableName}DTOs);
return new SuccessResultList<>(${firstLowerTableName}DTOs, pageInfo.getPageNum(), pageInfo.getTotal());
}
@Override
public Integer count(Map<String, Object> params) throws SearchException {
Integer count = ${firstLowerTableName}Dao.count${firstUpperTableName}(params);
return count == null ? 0 : count;
}
}