Browse Source
Merge branch 'master' of http://120.76.47.59:3000/liu_li/yxk_StoreroomSystem into master
master
Merge branch 'master' of http://120.76.47.59:3000/liu_li/yxk_StoreroomSystem into master
master
xia
3 years ago
13 changed files with 453 additions and 19 deletions
-
67archives/src/main/java/com/storeroom/modules/common/ArchivesListToMap.java
-
45archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java
-
4archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java
-
6archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java
-
32archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/NewTableVo.java
-
8archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java
-
31archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java
-
58archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java
-
9archives/src/test/java/ArchivesTypeTest.java
-
189common/src/main/java/com/storeroom/utils/DateUtils.java
-
15common/src/test/java/TestDate.java
-
1system/src/main/java/com/storeroom/modules/system/controller/TestController.java
-
5system/src/main/resources/application.yml
@ -0,0 +1,67 @@ |
|||
package com.storeroom.modules.common; |
|||
|
|||
|
|||
import com.storeroom.modules.dictionary.domain.vo.FieldVO; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
|
|||
import java.lang.reflect.Field; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
public class ArchivesListToMap { |
|||
|
|||
|
|||
public static String getMaps(List<FieldVO> lists, String tableName) { |
|||
|
|||
StringBuilder stringBuilder = new StringBuilder("create table " + tableName + "(id varchar(100) primary key not null,"); |
|||
|
|||
List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>(); |
|||
for (Object obj : lists) { |
|||
Class c = obj.getClass(); |
|||
Field[] f = c.getDeclaredFields(); |
|||
Map<String, Object> map = new HashMap<String, Object>(); |
|||
for (Field fie : f) { |
|||
try { |
|||
fie.setAccessible(true); |
|||
map.put(fie.getName(), fie.get(obj)); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
} |
|||
//获取父类的私有属性 |
|||
for (Field fie : c.getSuperclass().getDeclaredFields()) { |
|||
try { |
|||
fie.setAccessible(true);//取消语言访问检查 |
|||
map.put(fie.getName(), fie.get(obj));//获取私有变量值 |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
maps.add(map); |
|||
} |
|||
List<Map<String, Object>> list = maps; |
|||
for (int i = 0; i < list.size(); i++) { |
|||
stringBuilder.append(list.get(i).get("fieldName")); |
|||
stringBuilder.append(" "); |
|||
stringBuilder.append(list.get(i).get("fieldType")); |
|||
stringBuilder.append("("); |
|||
stringBuilder.append(list.get(i).get("fieldExtent")); |
|||
stringBuilder.append(")"); |
|||
if (list.size() - 1 != i) { |
|||
stringBuilder.append(","); |
|||
} |
|||
if (list.size() - 1 == i) { |
|||
stringBuilder.append(")"); |
|||
} |
|||
|
|||
} |
|||
return stringBuilder.toString(); |
|||
} |
|||
} |
|||
|
|||
|
@ -0,0 +1,32 @@ |
|||
package com.storeroom.modules.dictionary.domain.vo; |
|||
|
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class NewTableVo { |
|||
|
|||
public NewTableVo() { |
|||
|
|||
} |
|||
|
|||
public NewTableVo(String tableName) { |
|||
this.tableName = tableName; |
|||
} |
|||
|
|||
private String tableName; |
|||
private List<Vo> list; |
|||
|
|||
@Data |
|||
static class Vo { |
|||
//字段名称 |
|||
private String fieldName; |
|||
//字段类型 |
|||
private String fieldType; |
|||
//数据长度 |
|||
private Integer fieldExtent; |
|||
} |
|||
|
|||
} |
@ -1,8 +1,14 @@ |
|||
package com.storeroom.modules.dictionary.service; |
|||
|
|||
import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO; |
|||
|
|||
public interface ArchivesTypeService { |
|||
|
|||
|
|||
void create(); |
|||
/** |
|||
* 创建门类 |
|||
* @param archivesTypeDTO |
|||
*/ |
|||
void create(ArchivesTypeDTO archivesTypeDTO); |
|||
|
|||
} |
@ -1,13 +1,69 @@ |
|||
package com.storeroom.modules.dictionary.service.impl; |
|||
|
|||
import com.storeroom.modules.common.ArchivesListToMap; |
|||
import com.storeroom.modules.dictionary.domain.ArchivesType; |
|||
import com.storeroom.modules.dictionary.domain.vo.FieldVO; |
|||
import com.storeroom.modules.dictionary.service.ArchivesTypeService; |
|||
import com.storeroom.modules.dictionary.service.FieldService; |
|||
import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO; |
|||
import com.storeroom.modules.dictionary.service.mapstruct.ArchivesTypeMapper; |
|||
import com.storeroom.utils.DateUtils; |
|||
import lombok.RequiredArgsConstructor; |
|||
|
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.lang.reflect.Field; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class ArchivesTypeServiceImpl implements ArchivesTypeService { |
|||
|
|||
|
|||
private final ArchivesTypeMapper archivesTypeMapper; |
|||
|
|||
private final FieldService fieldService; |
|||
|
|||
private final JdbcTemplate jdbcTemplate; |
|||
|
|||
@Value("${table-template.name}") |
|||
private String tableName; |
|||
|
|||
|
|||
|
|||
@Override |
|||
public void create() { |
|||
public void create(ArchivesTypeDTO archivesTypeDTO) { |
|||
|
|||
ArchivesType archivesType = archivesTypeMapper.toEntity(archivesTypeDTO); |
|||
switch (archivesType.getIsType()) { |
|||
case 1 -> dynamicSystemTable(archivesType.getIsType()); |
|||
case 2 -> dynameicTemplateTable(archivesType.getIsType()); |
|||
} |
|||
|
|||
} |
|||
|
|||
public void dynamicSystemTable(Integer type) { |
|||
tableName += tableName + DateUtils.getNowDateTime(); |
|||
|
|||
List<FieldVO> list = fieldService.findGroupType(type); |
|||
if (!list.isEmpty()) { |
|||
String sqlstr = ArchivesListToMap.getMaps(list, tableName); |
|||
jdbcTemplate.execute(sqlstr); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
public void dynameicTemplateTable(Integer type) { |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
public class ArchivesTypeTest { |
|||
|
|||
@Test |
|||
public void dynamicSystemTableTest() { |
|||
|
|||
} |
|||
} |
@ -0,0 +1,189 @@ |
|||
package com.storeroom.utils; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.time.*; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.Calendar; |
|||
import java.util.Date; |
|||
|
|||
|
|||
/** |
|||
* 时间工具类 |
|||
*/ |
|||
public class DateUtils { |
|||
|
|||
|
|||
public static final DateTimeFormatter DFY_MD_HMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|||
public static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
|
|||
/** |
|||
* LocalDateTime 转时间戳 |
|||
* |
|||
* @param localDateTime / |
|||
* @return / |
|||
*/ |
|||
public static Long getTimeStamp(LocalDateTime localDateTime) { |
|||
return localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond(); |
|||
} |
|||
|
|||
/** |
|||
* 时间戳转LocalDateTime |
|||
* |
|||
* @param timeStamp / |
|||
* @return / |
|||
*/ |
|||
public static LocalDateTime fromTimeStamp(Long timeStamp) { |
|||
return LocalDateTime.ofEpochSecond(timeStamp, 0, OffsetDateTime.now().getOffset()); |
|||
} |
|||
|
|||
/** |
|||
* LocalDateTime 转 Date |
|||
* Jdk8 后 不推荐使用 {@link Date} Date |
|||
* |
|||
* @param localDateTime / |
|||
* @return / |
|||
*/ |
|||
public static Date toDate(LocalDateTime localDateTime) { |
|||
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); |
|||
} |
|||
|
|||
/** |
|||
* LocalDate 转 Date |
|||
* Jdk8 后 不推荐使用 {@link Date} Date |
|||
* |
|||
* @param localDate / |
|||
* @return / |
|||
*/ |
|||
public static Date toDate(LocalDate localDate) { |
|||
return toDate(localDate.atTime(LocalTime.now(ZoneId.systemDefault()))); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Date转 LocalDateTime |
|||
* Jdk8 后 不推荐使用 {@link Date} Date |
|||
* |
|||
* @param date / |
|||
* @return / |
|||
*/ |
|||
public static LocalDateTime toLocalDateTime(Date date) { |
|||
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); |
|||
} |
|||
|
|||
/** |
|||
* 日期 格式化 |
|||
* |
|||
* @param localDateTime / |
|||
* @param patten / |
|||
* @return / |
|||
*/ |
|||
public static String localDateTimeFormat(LocalDateTime localDateTime, String patten) { |
|||
DateTimeFormatter df = DateTimeFormatter.ofPattern(patten); |
|||
return df.format(localDateTime); |
|||
} |
|||
|
|||
/** |
|||
* 日期 格式化 |
|||
* |
|||
* @param localDateTime / |
|||
* @param df / |
|||
* @return / |
|||
*/ |
|||
public static String localDateTimeFormat(LocalDateTime localDateTime, DateTimeFormatter df) { |
|||
return df.format(localDateTime); |
|||
} |
|||
|
|||
/** |
|||
* 日期格式化 yyyy-MM-dd HH:mm:ss |
|||
* |
|||
* @param localDateTime / |
|||
* @return / |
|||
*/ |
|||
public static String localDateTimeFormatyMdHms(LocalDateTime localDateTime) { |
|||
return DFY_MD_HMS.format(localDateTime); |
|||
} |
|||
|
|||
/** |
|||
* 日期格式化 yyyy-MM-dd |
|||
* |
|||
* @param localDateTime / |
|||
* @return / |
|||
*/ |
|||
public String localDateTimeFormatyMd(LocalDateTime localDateTime) { |
|||
return DFY_MD.format(localDateTime); |
|||
} |
|||
|
|||
/** |
|||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd |
|||
* |
|||
* @param localDateTime / |
|||
* @return / |
|||
*/ |
|||
public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, String pattern) { |
|||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern); |
|||
return LocalDateTime.from(dateTimeFormatter.parse(localDateTime)); |
|||
} |
|||
|
|||
/** |
|||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd |
|||
* |
|||
* @param localDateTime / |
|||
* @return / |
|||
*/ |
|||
public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, DateTimeFormatter dateTimeFormatter) { |
|||
return LocalDateTime.from(dateTimeFormatter.parse(localDateTime)); |
|||
} |
|||
|
|||
/** |
|||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd HH:mm:ss |
|||
* |
|||
* @param localDateTime / |
|||
* @return / |
|||
*/ |
|||
public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) { |
|||
return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime)); |
|||
} |
|||
|
|||
/** |
|||
* 获取当前年 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static int getNowYear() { |
|||
Calendar d = Calendar.getInstance(); |
|||
return d.get(Calendar.YEAR); |
|||
} |
|||
|
|||
/** |
|||
* 获取当前月份 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static int getNowMonth() { |
|||
Calendar d = Calendar.getInstance(); |
|||
return d.get(Calendar.MONTH) + 1; |
|||
} |
|||
|
|||
/** |
|||
* 获取当月天数 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static int getNowMonthDay() { |
|||
Calendar d = Calendar.getInstance(); |
|||
return d.getActualMaximum(Calendar.DATE); |
|||
} |
|||
|
|||
/** |
|||
* 生成表获取当前时间和时间戳 |
|||
* @return |
|||
*/ |
|||
public static String getNowDateTime(){ |
|||
Calendar d = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_"); |
|||
return formatter.format(d.getTime()) + d.getTimeInMillis(); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,15 @@ |
|||
import com.storeroom.utils.DateUtils; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Calendar; |
|||
|
|||
public class TestDate { |
|||
|
|||
@Test |
|||
public void getDate() { |
|||
Calendar calendar = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_"); |
|||
System.out.println("tb_" + formatter.format(calendar.getTime()) + calendar.getTimeInMillis()); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue