📄 goodsserviceimpl.java
字号:
package com.shunshi.ssh.service;
import java.util.List;
import org.extremecomponents.table.limit.Limit;
import com.shunshi.ssh.dao.IAllInfoDao;
import com.shunshi.ssh.dao.IGoodsDao;
import com.shunshi.ssh.entity.AllInfo;
import com.shunshi.ssh.entity.Goods;
import com.shunshi.ssh.entity.Page;
import com.shunshi.ssh.exception.GoodsDaoException;
import com.shunshi.ssh.exception.GoodsServiceException;
public class GoodsServiceImpl implements IGoodsService {
private IGoodsDao dao;
private IAllInfoDao dao1;
public final static int DEFAULT_PAGE_SIZE=5;
public IGoodsDao getDao() {
return dao;
}
public void setDao(IGoodsDao dao) {
this.dao = dao;
}
public IAllInfoDao getDao1() {
return dao1;
}
public void setDao1(IAllInfoDao dao1) {
this.dao1 = dao1;
}
public void addGoods(Goods goods) throws GoodsServiceException {
try {
System.out.println("service addGoods run");
dao.add(goods);
} catch (GoodsDaoException e) {
throw new GoodsServiceException("添加失败!");
}
}
public void deleteGoods(Long[] ids) {
try {
for (long id : ids) {
dao.delete(id);
}
} catch (GoodsDaoException e) {
e.printStackTrace();
}
}
public List findAllGoods() {
List l=null;
try {
// System.out.println("service findAllGoods run");
l= dao.findAll();
} catch (GoodsDaoException e) {
e.printStackTrace();
}
return l;
}
public Goods findGoodsById(long id) {
Goods g=null;
try {
// System.out.println("service findGoodsById run");
g=dao.findById(id);
} catch (GoodsDaoException e) {
e.printStackTrace();
}
return g;
}
public List findGoodsByUserId(long userId) {
List l=null;
try {
// System.out.println("service findGoodsByUserId run");
l=dao.findByUserId(userId);
} catch (GoodsDaoException e) {
e.printStackTrace();
}
return l;
}
public void updateState(long id, int state) {
try {
System.out.println("service updateState run");
dao.updateState(id, state);
} catch (GoodsDaoException e) {
e.printStackTrace();
}
}
public Page findByState(int state, Limit size, int totalRows)throws GoodsServiceException {
try {
if (totalRows < 0) {
totalRows = dao.getTotalRowsByState(state).intValue();
}
size.setRowAttributes(totalRows, DEFAULT_PAGE_SIZE);
int[] startAndEnd = new int[] { size.getRowStart(),
size.getCurrentRowsDisplayed() };
List l = dao.findByState(state, startAndEnd[0], startAndEnd[1]);
Page page = new Page(size.getRowStart(), totalRows, size.getPage(),l);
return page;
} catch (GoodsDaoException e) {
throw new GoodsServiceException(e.getMessage());
}
}
public void updateGoods(Goods goods) throws GoodsServiceException {
try {
dao.updateGoods(goods);
} catch (GoodsDaoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public AllInfo getAllInfo() {
Goods goods=null;
try {
goods = dao.findGoodsByMaxId();
} catch (GoodsDaoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AllInfo info=new AllInfo();
info.setName(goods.getTopic());
info.setType("货源信息");
info.setClassType("goods");
info.setUserId(goods.getUserId());
info.setBid(goods.getId());
return info;
}
public void saveAllInfo(AllInfo allInfo){
dao1.addInfo(allInfo);
}
public void deleteAll(Long id, String type) throws GoodsServiceException {
dao1.deleteObject(dao1.findAllInfo(type, id));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -