提交 998ef1d6 作者: 史连宁

init

上级 da66be47
......@@ -82,6 +82,10 @@
<artifactId>jackson-databind</artifactId>
<version>2.12.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
......
package com.reconciliation.recfj.Controller;
import com.reconciliation.recfj.entity.RecExcel;
import com.reconciliation.recfj.entity.ReturnValue;
import com.reconciliation.recfj.service.RecService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
* @author 史连宁
*/
@Controller
@RequestMapping("rec")
public class RecController {
@Resource
private RecService recService;
@RequestMapping("/create_rec_data_to_excel")
@ResponseBody
public ReturnValue createRecDataToExcel(RecExcel rec) {
if (rec == null) {
rec = new RecExcel();
}
return recService.createRecDataToExcel(rec);
}
}
......@@ -2,10 +2,7 @@ package com.reconciliation.recfj.entity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.*;
import java.util.Date;
......@@ -14,6 +11,7 @@ import java.util.Date;
* @author 史连宁
*/
@Data
@Builder
@EqualsAndHashCode()
@AllArgsConstructor()
@NoArgsConstructor()
......
package com.reconciliation.recfj.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 返回值
* @author 史连宁
*/
@Data
@Builder
@AllArgsConstructor()
@NoArgsConstructor()
public class ReturnValue {
private boolean success;
private String msg;
private Object data;
public static ReturnValue ok() {
return ReturnValue.builder().success(true).build();
}
public static ReturnValue ok(String msg) {
return ReturnValue.builder().success(true).msg(msg).build();
}
public static ReturnValue fail() {
return ReturnValue.builder().success(false).build();
}
public static ReturnValue fail(String msg) {
return ReturnValue.builder().success(false).msg(msg).build();
}
}
......@@ -5,23 +5,25 @@ package com.reconciliation.recfj.enums;
* @author 史连宁
*/
public enum RecItem {
IDX1("IDX1", "IDX1数据总量"),
IDX2("IDX2", "IDX2创建时间月统计值"),
IDX3("IDX3", "IDX3创建时间日统计值(近30天)"),
IDX4("IDX4", "IDX4更新时间月统计值"),
IDX5("IDX5", "IDX5更新时间日统计值(近30天)");
IDX1("IDX1", "IDX1数据总量", "getRecAll"),
IDX2("IDX2", "IDX2创建时间月统计值", "getRecMon"),
IDX3("IDX3", "IDX3创建时间日统计值(近30天)", "getRecDay"),
IDX4("IDX4", "IDX4更新时间月统计值", "getRecMon"),
IDX5("IDX5", "IDX5更新时间日统计值(近30天)", "getRecDay");
private final String id;
private final String name;
private final String func;
/**
* 对账指标枚举类
* @param id 编码
* @param name 名称
*/
RecItem(String id, String name) {
RecItem(String id, String name, String func) {
this.id = id;
this.name = name;
this.func = func;
}
public String getId() {
......@@ -31,4 +33,17 @@ public enum RecItem {
public String getName() {
return name;
}
public String getFunc() {
return func;
}
public static RecItem parse(String str) throws EnumConstantNotPresentException {
for (RecItem rec : RecItem.values()) {
if (rec.id.equals(str)) {
return rec;
}
}
throw new EnumConstantNotPresentException(RecItem.class, str);
}
}
package com.reconciliation.recfj.enums;
/**
* 对账表枚举类
* @author 史连宁
*/
public enum RecTable {
SD_MS_DFS("table34904", "SD_MS_DFS", "稻飞虱模式报表", "1"),
SD_MS_ZJYM("table34903", "SD_MS_ZJYM", "纵卷叶螟模式报表", "1"),
SD_MS_MCDCYC("table34905", "SD_MS_MCDCYC", "螟虫各代调查及下代预测模式报表", "1"),
SD_MS_YHPKQSW("table34909", "SD_MS_YHPKQSW", "孕穗-破口期稻瘟病发生情况和穗瘟发生预测模式报表", "1"),
SD_MS_WKB("table34902", "SD_MS_WKB", "水稻纹枯病模式报表", "1"),
FJ_DSZBB_SDBCZBB3("table34906", "FJ_DSZBB_SDBCZBB3", "中稻及一季晚稻主要病虫周报表一", "2"),
FJ_DSZBB_SDBCZBB4("table34907", "FJ_DSZBB_SDBCZBB4", "中稻及一季晚稻主要病虫周报表二", "2"),
FJ_DSZBB_SDBCZBB5("table34901", "FJ_DSZBB_SDBCZBB5", "双季晚稻主要病虫周报表一", "2"),
FJ_DSZBB_SDBCZBB6("table34911", "FJ_DSZBB_SDBCZBB6", "双季晚稻主要病虫周报表二", "2"),
FJ_DSZBB_SDBCZBBY("table34908", "FJ_DSZBB_SDBCZBBY", "双季早稻主要病虫周报表一", "2"),
FJ_DSZBB_SDBCZBBE("table34910", "FJ_DSZBB_SDBCZBBE", "双季早稻主要病虫周报表二", "2");
private final String hjTable;
private final String sysTable;
private final String tableName;
private final String sqlType;
/**
* 对账表枚举类
* @param hjTable 汇聚平台表名
* @param sysTable 系统表名
* @param tableName 表中文名
* @param sqlType sql处理类型
*/
RecTable(String hjTable, String sysTable, String tableName, String sqlType) {
this.hjTable = hjTable;
this.tableName = tableName;
this.sqlType = sqlType;
this.sysTable = sysTable;
}
public String getHjTable() {
return hjTable;
}
public String getSysTable() {
return sysTable;
}
public String getTableName() {
return tableName;
}
public String getSqlType() {
return sqlType;
}
public static RecTable parse(String str) throws EnumConstantNotPresentException {
for (RecTable rec : RecTable.values()) {
if (rec.hjTable.equals(str) || rec.sysTable.equals(str)) {
return rec;
}
}
throw new EnumConstantNotPresentException(RecTable.class, str);
}
}
package com.reconciliation.recfj.mapper;
import com.reconciliation.recfj.entity.RecExcel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 对账mapper
* @author 史连宁
*/
@Mapper
public interface RecMapper {
@Select("<script>" +
" select count(*) value, max(tbrq) latestUpdateDate from ${table} t " +
"</script")
List<RecExcel> getRecAll1(String table);
@Select("<script>" +
" select count(*) value, max(t.tbrq) latestUpdateDate from ${table} t, ${table}_D d where t.recordid=d.recordid" +
"</script")
List<RecExcel> getRecAll2(String table);
@Select("<script>" +
" " +
"</script")
List<RecExcel> getRecMon1(String table);
@Select("<script>" +
" " +
"</script")
List<RecExcel> getRecMon2(String table);
@Select("<script>" +
" " +
"</script")
List<RecExcel> getRecDay1(String table);
@Select("<script>" +
" " +
"</script")
List<RecExcel> getRecDay2(String table);
}
package com.reconciliation.recfj.service;
import com.reconciliation.recfj.entity.RecExcel;
import com.reconciliation.recfj.entity.ReturnValue;
import com.reconciliation.recfj.enums.RecItem;
import com.reconciliation.recfj.enums.RecTable;
import com.reconciliation.recfj.mapper.RecMapper;
import io.micrometer.common.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 对账实现类
* @author 史连宁
*/
@Service
public class RecService {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private RecMapper recMapper;
public ReturnValue createRecDataToExcel(RecExcel rec) {
ReturnValue rtv = ReturnValue.fail();
try {
RecTable[] recTableList = RecTable.values();
RecItem[] recItemList = RecItem.values();
if (rec != null && StringUtils.isNotBlank(rec.getThirdTable())) {
recTableList = new RecTable[]{RecTable.parse(rec.getThirdTable())};
}
if (rec != null && StringUtils.isNotBlank(rec.getRecItem())) {
recItemList = new RecItem[]{RecItem.parse(rec.getRecItem())};
}
List<RecExcel> list = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (RecTable recTable : recTableList) {
for (RecItem recItem : recItemList) {
Date now = new Date();
}
}
rtv.setSuccess(true);
} catch (Exception e) {
logger.error("汇聚平台对账数据生成失败", e);
rtv.setMsg(e.getMessage());
}
return rtv;
}
}
package com.reconciliation.recfj.task;
import com.reconciliation.recfj.entity.RecExcel;
import com.reconciliation.recfj.entity.ReturnValue;
import com.reconciliation.recfj.service.RecService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 对账定时任务
* @author 史连宁
......@@ -10,4 +20,27 @@ import org.springframework.stereotype.Component;
@EnableScheduling
@Component("RecTask")
public class RecTask {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private RecService recService;
@Scheduled(cron = "${task.rec.default}")
public void createRecDataToExcel() {
ReturnValue rtv = recService.createRecDataToExcel(new RecExcel());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (rtv.isSuccess()) {
logger.info(
"[{}]汇聚平台对账数据生成成功",
sdf.format(new Date())
);
} else {
logger.warn(
"[{}]汇聚平台对账数据生成失败: {}",
sdf.format(new Date()),
rtv.getMsg()
);
}
}
}
spring:
application:
name: rec-fj
datasource:
driver-class-name: com.kingbase.Driver
url: jdbc:kingbase://10.51.210.2:54321/FJZX
username: NYBDB
password: Fjny6467
mybatis-plus:
mapper-locations:
- "classpath*:mappers/**/*.xml"
logging:
level:
com.reconciliation.recfj: DEBUG
task:
rec:
default: 0 0 6 * * ?
spring:
application:
name: rec-fj
datasource:
driver-class-name: com.kingbase.Driver
url: jdbc:kingbase://127.0.0.1:54321/FJZX
username: NYBDB
password: Fjny6467
mybatis-plus:
mapper-locations:
- "classpath*:mappers/**/*.xml"
logging:
level:
com.reconciliation.recfj: DEBUG
task:
rec:
default: 0 0 6 * * ?
spring:
application:
name: rec-fj
datasource:
driver-class-name: com.kingbase.Driver
url: jdbc:kingbase://127.0.0.1:54321/FJZX
username: NYBDB
password: Fjny6467
mybatis-plus:
mapper-locations:
- "classpath*:mappers/**/*.xml"
logging:
level:
com.reconciliation.recfj: DEBUG
task:
rec:
default: 0 0 6 * * ?
profiles:
active: dev
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论