| | |
| | | |
| | | import com.fgkj.dto.Batt_discharge; |
| | | import com.fgkj.dto.ServiceModel; |
| | | import com.fgkj.dto.User_log; |
| | | import com.fgkj.mapper.UinfDaoFactory; |
| | | import com.fgkj.mapper.impl.Batt_dischargeMapper; |
| | | 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; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private Batt_dischargeMapper mapper; |
| | | @Resource |
| | | private User_logService uservice; |
| | | @Autowired |
| | | DataSourceTransactionManager dataSourceTransactionManager; |
| | | @Autowired |
| | | TransactionDefinition transactionDefinition; |
| | | |
| | | ServiceModel model = new ServiceModel(); |
| | | |
| | | //批量添加 |
| | | public ServiceModel add(List<Batt_discharge> listdischarge) { |
| | | boolean bl = false; |
| | | boolean bl = true; |
| | | ServiceModel model = new ServiceModel(); |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | for (int i = 0; i < listdischarge.size(); i++) { |
| | | bl = mapper.add(listdischarge.get(i)); |
| | | if (!bl) { |
| | | continue; |
| | | } |
| | | Batt_discharge bdischarge = listdischarge.get(i); |
| | | try { |
| | | bl = mapper.add(bdischarge); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | bl=false; |
| | | } |
| | | String msg = "添加" + bdischarge.getDev_id() + "机房至放电黑名单!"; |
| | | User_log ulog = UinfDaoFactory.CreateULog(UinfDaoFactory.Increase, msg); |
| | | uservice.add(ulog); |
| | | } |
| | | if(bl){ |
| | | if (bl) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | model.setCode(1); |
| | | model.setMsg("添加成功!"); |
| | | }else{ |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | model.setCode(0); |
| | | model.setMsg("添加失败!"); |
| | | } |
| | |
| | | //移除黑名单 |
| | | public ServiceModel del(List<Batt_discharge> listdischarge) { |
| | | boolean bl = false; |
| | | ServiceModel model = new ServiceModel(); |
| | | for (int i = 0; i < listdischarge.size(); i++) { |
| | | bl = mapper.del(listdischarge.get(i)); |
| | | } |