package com.terra.bigdata.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.terra.bigdata.domain.Yssh2dreli;
import com.terra.bigdata.domain.Yssh3dreli;
import com.terra.bigdata.mapper.Yssh3dreliMapper;
import com.terra.bigdata.service.Yssh3dreliService;
import lombok.Synchronized;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
*
* 前端控制器
*
*
* @author hyy
* @since 2022-12-22
*/
@Service
public class Yssh3dreliServiceImpl extends ServiceImpl implements Yssh3dreliService {
@Autowired
private Yssh3dreliMapper yssh3dreliMapper;
/**
* 创建3维热力表接口
*/
/*@Transactional(rollbackFor = Exception.class)
@Synchronized
@Override
public int create3dreliTable() {
String tablePrefix = "yssh_3dreli_";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Calendar calendar = Calendar.getInstance();
//明天
calendar.add(Calendar.DATE, +1);
Date start = calendar.getTime();
String tomorrow = dateFormat.format(start);
String tableName = tablePrefix + tomorrow;
System.out.println("tableName = " + tableName);
return yssh3dreliMapper.create3dreliTable(tableName);
}
*/
/**
* 创建3维热力表接口
*/
@Transactional(rollbackFor = Exception.class)
@Synchronized
@Override
public int create3dreliTable() {
String tablePrefix = "yssh_3dreli_";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Calendar calendar = Calendar.getInstance();
//明天
calendar.add(Calendar.DATE, +1);
Date start = calendar.getTime();
String tomorrow = dateFormat.format(start);
String tableName = tablePrefix + tomorrow;
System.out.println("tableName = " + tableName);
//把新增的表增加到字典表中
/*DictRecord dictRecord =new DictRecord();
dictRecord.setTableName(tableName);
dictRecord.setResOne("3");
dictRecord.setResTwo(tomorrow);
dictRecordMapper.insertDictRecord(dictRecord);*/
return yssh3dreliMapper.create3dreliTable(tableName);
}
/**
* 创建2维热力表接口
*/
@Transactional(rollbackFor = Exception.class)
@Synchronized
@Override
public int create2dreliTable() {
String tablePrefix = "yssh_2dreli_";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Calendar calendar = Calendar.getInstance();
//明天
calendar.add(Calendar.DATE, +1);
Date start = calendar.getTime();
String tomorrow = dateFormat.format(start);
String tableName = tablePrefix + tomorrow;
System.out.println("tableName = " + tableName);
return yssh3dreliMapper.create2dreliTable(tableName);
}
/**
* 新增3维热力记录
*
* @param yssh3dreli 3维热力记录
* @return 结果
*/
@Override
public int insert3dreliData(Yssh3dreli yssh3dreli) {
String tablePrefix = "yssh_3dreli_";
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String localDday = dateFormat.format(date);
System.out.println("localDday = " + localDday);
String tableName = tablePrefix + localDday;
return yssh3dreliMapper.insert3dreliData(tableName, yssh3dreli);
}
/**
* 批量新增3维热力记录
*
* @param yssh3dreli 3维热力记录
* @return 结果
*/
@Transactional(rollbackFor = Exception.class)
@Synchronized
@Override
public int batchInsert3dreliData(List yssh3dreli) {
/*Yssh3dreli yssh3dreli1 =new Yssh3dreli();
for (Yssh3dreli yssh3dre2: yssh3dreli) {
System.out.println("yssh3dre2 = " + yssh3dre2.getName());
yssh3dreli1.setName(yssh3dre2.getName());
yssh3dreli1.setLat(yssh3dre2.getLat());
yssh3dreli1.setLon(yssh3dre2.getLon());
yssh3dreli1.setHeight0(yssh3dre2.getHeight0());
yssh3dreli1.setHeight10(yssh3dre2.getHeight10());
yssh3dreli1.setHeight20(yssh3dre2.getHeight20());
yssh3dreli1.setHeight30(yssh3dre2.getHeight30());
yssh3dreli1.setHeight40(yssh3dre2.getHeight40());
yssh3dreli1.setHeight50(yssh3dre2.getHeight50());
yssh3dreli1.setHeight60(yssh3dre2.getHeight60());
yssh3dreli1.setHeight70(yssh3dre2.getHeight70());
yssh3dreli1.setHeight80(yssh3dre2.getHeight80());
yssh3dreli1.setHeight90(yssh3dre2.getHeight90());
yssh3dreli1.setTime(yssh3dre2.getTime());
}*/
String tablePrefix = "yssh_3dreli_";
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String localDday = dateFormat.format(date);
String tableName = tablePrefix + localDday;
return yssh3dreliMapper.batchInsert3dreliData(tableName, yssh3dreli);
}
/**
* 批量新增2维热力记录
*
* @param yssh2drelis 2维热力记录
* @return 结果
*/
@Transactional(rollbackFor = Exception.class)
@Synchronized
@Override
public int batchInsert2dreliData(List yssh2drelis) {
String tablePrefix = "yssh_2dreli_";
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String localDday = dateFormat.format(date);
String tableName = tablePrefix + localDday;
return yssh3dreliMapper.batchInsert2dreliData(tableName, yssh2drelis);
}
/**
* 删除3维热力表接口
*/
@Transactional(rollbackFor = Exception.class)
@Synchronized
@Override
public int drop3dreliTable() {
String tablePrefix = "yssh_3dreli_";
//定义日期格式
SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMdd");
Calendar calendar = Calendar.getInstance();
//前一年
calendar.add(Calendar.YEAR, -1);
Date start = calendar.getTime();
String yearBefore = format2.format(start);
String tableName = tablePrefix + yearBefore;
return yssh3dreliMapper.drop3dreliTable(tableName);
}
}