📄 petbusinessimpl.java
字号:
package com.hzxh.pet.model;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.util.Map;/** * 业务接口实现类 * * @author yuq * */public class PetBusinessImpl implements IPetBusiness { private PetinfoDAO petdao; private PetdiaryDAO petdiarydao; public PetinfoDAO getPetdao() { return petdao; } public void setPetdao(PetinfoDAO petdao) { this.petdao = petdao; } public PetdiaryDAO getPetdiarydao() { return petdiarydao; } public void setPetdiarydao(PetdiaryDAO petdiarydao) { this.petdiarydao = petdiarydao; } public void savePet(PetInfo p) throws Exception { petdao.save(p); } public List getDiaryList(Map keys, String orderby) throws Exception { String hsql = "from Petdiary where 1=1"; ArrayList param = new ArrayList(); String diaryTitle = (String) keys.get("diaryTitle"); if (diaryTitle != null && diaryTitle.length() > 0) { param.add("%" + diaryTitle + "%"); hsql += " and diaryTitle like ?"; } String diaryAuthor = (String) keys.get("diaryAuthor"); if (diaryAuthor != null && diaryAuthor.length() > 0) { param.add(diaryAuthor); hsql += " and diaryAuthor = ?"; } Date diaryDate = (Date) keys.get("diaryDate"); if (diaryDate != null) { param.add(diaryDate); hsql += " and diaryDate = ?"; } String diaryContext = (String) keys.get("diaryContext"); if (diaryContext != null && diaryContext.length() > 0) { param.add("%" + diaryContext + "%"); hsql += " and diaryContext like ?"; } hsql += " order by " + orderby; return petdiarydao.getHibernateTemplate().find(hsql, param.toArray()); } public Petdiary getPetDiary(int diaryId) throws Exception { return petdiarydao.findById(new Integer(diaryId)); } public List getPetList(Map keys, String orderby) throws Exception { String hsql = "from PetInfo where 1=1"; ArrayList param = new ArrayList(); String petName = (String) keys.get("petName"); if (petName != null && petName.length() > 0) { param.add("%" + petName + "%"); hsql += " and petName like ?"; } Integer petType = (Integer) keys.get("petType"); if (petType != null) { param.add(petType); hsql += " and petType = ?"; } String petOwnerName = (String) keys.get("petOwnerName"); if (petOwnerName != null && petOwnerName.length() > 0) { param.add(petOwnerName); hsql += " and petOwnerName = ?"; } hsql += " order by " + orderby; return petdao.getHibernateTemplate().find(hsql, param.toArray()); } public PetInfo getPetinfo(int petId) throws Exception { return petdao.findById(new Integer(petId)); } public PetInfo getLogin(String petname, String password) throws Exception { List list = petdao.findByPetName(petname); if (list != null && list.size() == 1) { PetInfo pet = (PetInfo) list.get(0); if (pet.getPetPassword().equals(password)) { return pet; } else { throw new RuntimeException("密码不正确"); } } else { throw new RuntimeException("登录名不正确"); } } public void updatePetinfo(PetInfo p) throws Exception { petdao.attachDirty(p); } public void saveDiary(Petdiary p) throws Exception { petdiarydao.save(p); } public Boolean getCheckName(String petName) { List list = petdao.findByPetName(petName); if (list != null && list.size() == 1) { return new Boolean(true); } else { return new Boolean(false); } } public void updateTraining(int petId, String type) { PetInfo pet = null; try { pet = getPetinfo(petId); if (type.equals("TRANING_TYPE_FEED")) { pet.setPetStrength(new Integer( pet.getPetStrength().intValue() + 30)); } else if (type.equals("TRANING_TYPE_STORY")) { pet.setPetCute(new Integer(pet.getPetCute().intValue() + 1)); pet.setPetLove(new Integer(pet.getPetLove().intValue() + 3)); pet.setPetStrength(new Integer( pet.getPetStrength().intValue() - 5)); } else if (type.equals("TRANING_TYPE_STORY")) { pet.setPetCute(new Integer(pet.getPetCute().intValue() + 3)); pet.setPetLove(new Integer(pet.getPetLove().intValue() + 1)); pet.setPetStrength(new Integer( pet.getPetStrength().intValue() - 5)); } } catch (Exception e) { e.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -