package com.fgkj.services;
|
|
import com.fgkj.dto.Batt_history;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.mapper.impl.Batt_historyMapper;
|
import com.fgkj.util.ActionUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
@Service
|
public class Batt_historyService {
|
|
@Resource
|
private Batt_historyMapper mapper;;
|
|
ServiceModel model = new ServiceModel();
|
|
//查询所有的历史实时数据
|
public ServiceModel searchAll(){
|
List<Batt_history> list=mapper.searchAll();
|
/*for (Batt_history batt : list) {
|
System.out.println(ActionUtil.getDateMonth(batt.getRec_datetime()));
|
}*/
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
model.setMsg("查询成功!");
|
}else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
//查询所有的历史实时数据
|
// TODO tb_batt_realdata_1000003_2020_09 ip222 参数对不上
|
// tb_batt_910000001_2017_12
|
|
//TODO 数据库表格字段不一致 使用这个表名测试 db_batt_history.tb_batt_910000001_2017_12
|
|
/**
|
* {
|
* "dev_id": 910000001,
|
* "battGroupId": 1005059,
|
* "rec_datetime": "2017-12-29 09:28:31",
|
* "rec_datetime1": "2018-12-29 09:28:31"
|
* }
|
* @param obj
|
* @return
|
*/
|
public ServiceModel serchByCondition(Batt_history obj){
|
ServiceModel model = new ServiceModel();
|
int year= ActionUtil.getDateYear(obj.getRec_datetime());
|
int month=ActionUtil.getDateMonth(obj.getRec_datetime());
|
// String tbname = "tb_batt_";
|
String tbnamesuffix = "";
|
tbnamesuffix+=obj.getDev_id()+"_"+year+"_"+month;
|
System.out.println("tbnamesuffix = " + tbnamesuffix);
|
obj.setTbname(tbnamesuffix);
|
// obj.setTbname("910000001_2017_12");//TODO 测试用表名后缀
|
List list=mapper.serchByCondition(obj);
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
model.setMsg("查询成功!");
|
}else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
/*public static void main(String[] args) throws ParseException {
|
Batt_historyService hservice=new Batt_historyService();
|
Batt_history bh=new Batt_history();
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date1 = sdf.parse("2018-01-01 00:00:00");
|
Date date2 = sdf.parse("2018-01-03 23:59:59");
|
bh.setRec_datetime(new Date());
|
bh.setDev_id(910000001);
|
bh.setBattGroupId(1005058);
|
bh.setRec_datetime(ActionUtil.getSimpDate(date1));
|
bh.setRec_datetime1(ActionUtil.getSimpDate(date2));
|
System.out.println(bh);
|
ServiceModel model=hservice.serchByCondition(bh);
|
System.out.println(model.getData());
|
//hservice.searchAll();
|
}*/
|
}
|