📄 clientserviceimpl.java
字号:
e.printStackTrace();
throw new MyException("注册用户时出现异常");
}
}
/**
* 根据种类来获取相册列表
* @param kindId 需要获取的相册种类ID
* @param first 需要显示的第一个相册
* @param pageSize 每页显示的相册数量
* @return 查询到的相册列表
*/
public List<AlbumVO> getAlbumsByKind(Integer kindId, int first, int pageSize)throws MyException
{
try
{
Kind kind = hd.get(kindId);
List<AlbumVO> avos = new ArrayList<AlbumVO>();
List<Album> albums = hd.getAllByKind(kind, first, pageSize);
for (Iterator it = albums.iterator() ; it.hasNext() ; )
{
AlbumVO avo = null;
Album album = (Album)it.next();
if (pd.getCover(album, true) == null)
{
avo = fillAlbumVO(album);
}
else
{
Photo ph = pd.get(pd.getCover(album, true));
avo = fillAlbumVO(album, ph);
}
avos.add(avo);
}
return avos;
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("异常");
}
}
/**
* 获取指定相册分类下的相册数量
* @param kindId 需要查询的相册分类ID
* @return 指定相册分类下的相册数量
*/
public int getAlbumCount(Integer kindId)throws MyException
{
try
{
Kind kind = hd.get(kindId);
return hd.getAmount(kind);
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("查询相册总数异常");
}
}
/**
* 获取指定相册分类ID对应相册分类信息
* @param kindId 需要查询的相册分类ID
* @return 指定相册分类ID对应的相册分类信息
*/
public KindVO getKind(Integer kindId)throws MyException
{
try
{
Kind kind = hd.get(kindId);
return fillKindVO(kind);
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("获取单个种类异常");
}
}
/**
* 根据相册获取该相册包含的相片。
* @param albumId 需要查询的相册ID
* @param first 需要显示的第一张相片
* @param pageCount 每页显示的相片数量
* @return 查询到该相册包含的全部相片。
*/
public List<PhotoVO> getPhotos(Integer albumId, int first, int pageCount)throws MyException
{
try
{
Album album = ad.get(albumId);
List<Photo> result = pd.getPhotos(album, first, pageCount);
List<PhotoVO> pvos = new ArrayList<PhotoVO>();
for (Iterator it = result.iterator() ; it.hasNext() ; )
{
Photo ph = (Photo)it.next();
pvos.add(fillPhotoVO(ph));
}
return pvos;
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("查询该相册相片异常,请重试");
}
}
/**
* 获取指定相册下包含相片数量
* @param albumId 指定相册的ID
* @return 该相册下包含的相片ID。
*/
public int getCount(Integer albumId)throws MyException
{
try
{
Album album = ad.get(albumId);
return pd.getCount(album);
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("获取记录总数异常,请重试");
}
}
/**
* 增加一张相片
* @param title 相片标题
* @param desc 相片描述
* @param times 相片访问次数。
* @param picUrl 相片的URL
* @param bigPicUrl 相片大图的URL
* @param smallPicUrl 相片小图的URL
* @param date 相片的添加日期
* @param cover 是否为相册封面。
* @param albumId 该相片需要添加到的相册ID
*/
public void addPhoto(String title, String desc, long times, String picUrl, String bigPicUrl, String smallPicUrl,
String upDate, boolean cover, Integer albumId)throws MyException
{
try
{
Album album = ad.get(albumId);
Photo ph = new Photo(title, desc, times, picUrl, bigPicUrl, smallPicUrl, upDate, album);
pd.save(ph);
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("添加照片异常,请重试");
}
}
/**
* 判断指定ID对应的相片是否存在。
* @param 需要查询的相片ID
* @return 如果该ID对应的相片存在,返回true,否则返回false。
*/
public boolean checkPhoto(Integer phId)throws MyException
{
try
{
Photo photo = pd.get(phId);
if (photo == null)
{
return false;
}
return true;
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("校验相片出现异常");
}
}
/**
* 删除指定相片
* @param 需要删除的相片ID
*/
public void deletePhoto(int phId)throws MyException
{
try
{
pd.delete(phId);
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("删除照片异常");
}
}
/**
* 判断指定ID获取对应的相片
* @param 需要查询的相片ID
* @return 返回该ID对应的相片
*/
public PhotoVO getPhoto(Integer phId)throws MyException
{
try
{
Photo photo = pd.get(phId);
PhotoVO pvo = fillPhotoVO(photo);
return pvo;
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("查询照片信息异常");
}
}
/**
* 获取指定相片的相片评论
* @param first 需要访问的第一张相片
* @param pageSize 每页显示的相片数量
* @return 根据指定页查询返回的相片评论。
*/
public List<PhotoWordVO> getPhotoWords(Integer photoId, int first, int pageSize)throws MyException
{
try
{
List<PhotoWordVO> pwvos = new ArrayList<PhotoWordVO>();
Photo photo = pd.get(photoId);
List<PhotoWord> pws = pwd.getPhotoWordByPhoto(photo, first, pageSize);
for (Iterator it = pws.iterator() ; it.hasNext() ; )
{
PhotoWord pw = (PhotoWord)it.next();
pwvos.add(fillPhotoVO(pw));
}
return pwvos;
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("查询相片留言异常");
}
}
/**
* 根据相片评论ID获取相片评论总数
* @param photoId 指定相片ID
* @return 该相片对应的相片评论总数。
*/
public int getWordCount(Integer photoId)throws MyException
{
try
{
Photo photo = pd.get(photoId);
return pwd.getCount(photo);
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("查询评论总数异常");
}
}
/**
* 获取相片所属于的相册分类
* @param photoId 需要查询的相片ID
* @return 指定相片对应的相册分类。
*/
public KindVO getKindByPhoto(Integer photoId)throws MyException
{
try
{
Kind kind = pd.get(photoId).getAlbum().getKind();
return fillKindVO(kind);
}
catch (Exception e)
{
throw new MyException("获取相片种类异常");
}
}
/**
* 获取系统中全部相册分类
* @return 系统包含的全部相册分类
*/
public List<KindVO> getAllKind()throws MyException
{
try
{
List<KindVO> result = new ArrayList();
List<Kind> kinds = hd.getAll();
for (Iterator it = kinds.iterator() ; it.hasNext() ; )
{
Kind kind = (Kind)it.next();
result.add(fillKindVO(kind));
}
return result;
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("获取所有种类异常");
}
}
/**
* 修改用户详细信息
* @param cId 用户的主键值。
* @param sex 用户的性别
* @param qq 用户的QQ号
* @param mail 用户的电子邮件
*/
public void updateClient(Integer cId, boolean sex, String qq, String mail)throws MyException
{
try
{
Client client = cd.get(cId);
client.setSex(sex);
client.setMail(mail);
client.setQq(qq);
cd.update(client);
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("修改资料异常");
}
}
/**
* 修改用户的密码
* @param id 需要修改的用户ID信息
* @param pass 需要修改的用户新密码
*/
public void updateClient(Integer id, String pass)throws MyException
{
try
{
Client client = cd.get(id);
client.setPass(pass);
cd.update(client);
}
catch (Exception e)
{
e.printStackTrace();
throw new MyException("修改密码异常");
}
}
//--------------------------------------------------
//下面包含六个用于将PO转换成VO的工具方法。
//--------------------------------------------------
private ClientVO fillClientInfoVO(Client client)throws Exception
{
ClientVO civo = new ClientVO(client.getId(), client.getName(), client.getPass(), client.getSex(),
client.getMail(), client.getQq());
return civo;
}
private AlbumVO fillAlbumVO(Album al, Photo ph)throws Exception
{
AlbumVO avo = null;
avo = new AlbumVO(al.getId(), al.getName(), al.getDesc(), al.getCreateDate(),
al.getTimes(), al.getClient().getId(), al.getClient().getName(),
al.getKind().getId(), al.getKind().getName(), ph.getId(), ph.getSmallPicUrl());
return avo;
}
private AlbumVO fillAlbumVO(Album al)throws Exception
{
AlbumVO avo = null;
avo = new AlbumVO(al.getId(), al.getName(), al.getDesc(), al.getCreateDate(),
al.getTimes(), al.getClient().getId(), al.getClient().getName(),
al.getKind().getId(), al.getKind().getName());
return avo;
}
private KindVO fillKindVO(Kind kind)throws Exception
{
KindVO kvo = new KindVO(kind.getId(), kind.getName(), kind.getDesc());
return kvo;
}
private PhotoVO fillPhotoVO(Photo ph)throws Exception
{
PhotoVO pvo = new PhotoVO(ph.getId(), ph.getTitle(), ph.getDesc(), ph.getTimes(),
ph.getPicUrl(), ph.getBigPicUrl(), ph.getSmallPicUrl(), ph.getUpDate(),
ph.getCover(), ph.getAlbum().getId(), ph.getAlbum().getName());
return pvo;
}
private PhotoWordVO fillPhotoVO(PhotoWord pw)throws Exception
{
PhotoWordVO pwvo = new PhotoWordVO(pw.getId(), pw.getTitle(), pw.getContent(), pw.getAddDate(),
pw.getPhoto().getId(), pw.getPhoto().getTitle(), pw.getClient().getId(), pw.getClient().getName());
return pwvo;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -