package com.lgx8.gateway.service.impl;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import com.lgx8.common.PageArgument;
import com.lgx8.common.PageList;
import com.lgx8.gateway.dao.IAddressDao;
import com.lgx8.gateway.entities.Address;
import com.lgx8.gateway.service.IAddressService;
public class AddressService implements IAddressService {
IAddressDao addressDao ;
public PageList queryAddress(String hql, Object[] values,
PageArgument argment) {
if(null==argment) return new PageList();
return addressDao.findByPage4Report(hql, values, argment.getCurPage(), argment.getPageSize());
}
@Transactional
public boolean deleteAddress(int id){
try{
Address address = new Address();
address.setId(id);
addressDao.deleteAddress(address);
return true;
}catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Transactional
public boolean addAddress(Address addr){
try{
addressDao.save(addr);
//
// String hql = " from Address a where a.user.id = " + addr.getUser().getId() + " a.id <> " + addr.getId();
//
// List<Address> list = addressDao.findAddress(hql);
//
// for(Address a : list)
// {
// a.setIsdefault(0);
// addressDao.updateAddress(addr);
// }
return true;
}catch (Exception e) {
e.printStackTrace();
}
return false;
}
public IAddressDao getAddressDao() {
return addressDao;
}
public void setAddressDao(IAddressDao addressDao) {
this.addressDao = addressDao;
}
public List getAddress(String hql, Object[] values) {
// TODO Auto-generated method stub
return addressDao.findAddress(hql, values);
}
@Transactional
public boolean modifyAddress(Address addr) {
try{
addressDao.updateAddress(addr);
// if(addr.getIsdefault() == 1)
// {
// String hql = " from Address a where a.user.id = " + addr.getUser().getId() + " a.id <> " + addr.getId();
//
// List<Address> list = addressDao.findAddress(hql);
//
// for(Address a : list)
// {
// a.setIsdefault(0);
// addressDao.updateAddress(addr);
// }
// }
return true;
}catch (Exception e) {
e.printStackTrace();
}
return false;
}
}