package com.fgkj.services;
|
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.User_task_batt_template;
|
import com.fgkj.mapper.impl.User_task_batt_templateMapper;
|
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.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
@Service
|
public class User_task_batt_templateService {
|
|
@Resource
|
private User_task_batt_templateMapper mapper;
|
@Autowired
|
DataSourceTransactionManager dataSourceTransactionManager;
|
@Autowired
|
TransactionDefinition transactionDefinition;
|
|
//4.4作业模板管理(新建模板)
|
public ServiceModel add(User_task_batt_template obj) {
|
ServiceModel model = new ServiceModel();
|
Boolean bl= null;
|
try {
|
bl = mapper.add(obj);
|
} catch (Exception e) {
|
e.printStackTrace();
|
model.setMsg("添加失败!");
|
return model;
|
}
|
if(bl){
|
model.setCode(1);
|
model.setMsg("添加成功!");
|
}
|
else{
|
model.setMsg("添加失败!");
|
}
|
return model;
|
|
}
|
//4.4 作业模板管理(修改模板/重命名)<多条修改>
|
public ServiceModel update(List<User_task_batt_template> list) {
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
ServiceModel model = new ServiceModel();
|
boolean bl = true;
|
if (list != null && list.size() > 0) {
|
for (int i = 0; i < list.size(); i++) {
|
try {
|
bl = mapper.updatePro(list.get(i));
|
} catch (Exception e) {
|
e.printStackTrace();
|
dataSourceTransactionManager.rollback(transactionStatus);
|
model.setMsg("修改失败!");
|
return model;
|
}
|
}
|
}
|
if (bl) {
|
dataSourceTransactionManager.commit(transactionStatus);
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
} else {
|
dataSourceTransactionManager.rollback(transactionStatus);
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
//4.4 作业模板管理(删除)
|
public ServiceModel delete(User_task_batt_template obj) {
|
ServiceModel model = new ServiceModel();
|
Boolean bl=mapper.del(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
}
|
else{
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
//4.4根据模板id查询模板的信息
|
public ServiceModel serchByCondition(User_task_batt_template obj){
|
ServiceModel model = new ServiceModel();
|
List list=mapper.serchByCondition(obj);
|
// for (Object object : list) {
|
// System.out.println(object);
|
// }
|
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}
|
// System.out.println(model);
|
return model;
|
}
|
//4.4查询所有的模板
|
public ServiceModel searchAll(){
|
ServiceModel model = new ServiceModel();
|
List list=mapper.searchAll();
|
// for (Object object : list) {
|
// System.out.println(object);
|
// }
|
//System.out.println(list);
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}
|
return model;
|
}
|
|
}
|