package com.fgkj.services;
|
|
import com.fgkj.dto.Batt_param_low;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.mapper.impl.Batt_param_lowMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionStatus;
|
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
@Service
|
public class Batt_param_lowService {
|
|
ServiceModel model = new ServiceModel();
|
|
@Resource
|
private Batt_param_lowMapper mapper;;
|
@Autowired
|
DataSourceTransactionManager dataSourceTransactionManager;
|
@Autowired
|
TransactionDefinition transactionDefinition;
|
|
public ServiceModel add(Object obj) {
|
Boolean bl=mapper.add(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("添加成功!");
|
}
|
else{
|
model.setMsg("添加失败!");
|
}
|
return model;
|
|
}
|
public ServiceModel update(List<Batt_param_low> list) {
|
ServiceModel model = new ServiceModel();
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
Boolean bl = true;
|
for (int i = 0; i < list.size(); i++) {
|
if (!(mapper.update(list.get(i)) > 0)) {
|
bl = false;
|
}
|
}
|
if (bl) {
|
dataSourceTransactionManager.commit(transactionStatus);
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
} else {
|
dataSourceTransactionManager.rollback(transactionStatus);
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
|
|
|
public ServiceModel delete(Object obj) {
|
Boolean bl=mapper.del(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
}
|
else{
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
public ServiceModel serchByCondition(Object obj) {
|
List<Batt_param_low> list = mapper.serchByCondition(obj);
|
// for (Batt_param_low u : list) {
|
// System.out.println(u);
|
// }
|
|
if (list != null && list.size() > 0) {
|
model.setCode(1);
|
model.setData(list);
|
}else{
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
//根据low_type,low_nametype查阈值
|
public ServiceModel serchByLow(Object obj) {
|
List<Batt_param_low> list = mapper.serchByLow(obj);
|
/*for (Batt_param_low u : list) {
|
System.out.println(u);
|
}*/
|
if (list != null && list.size() > 0) {
|
model.setCode(1);
|
model.setData(list);
|
}else{
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
|
public ServiceModel searchAll(){
|
ServiceModel model = new ServiceModel();
|
List<Batt_param_low> list=mapper.searchAll();
|
//System.out.println(list);
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}
|
return model;
|
}
|
public static void main(String[] args) {
|
//new Batt_param_lowService().searchAll();
|
Batt_param_low b=new Batt_param_low();
|
b.setNum(2);
|
new Batt_param_lowService().serchByCondition(b);
|
}
|
}
|