📄 friendlabelserviceimpl.java
字号:
/*
* Created on 2007-4-26
* Last modified on 2007-4-26
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.user;
import java.util.ArrayList;
import java.util.List;
import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.cache.CacheFactory;
import com.yeqiangwei.club.cache.CacheKeys;
import com.yeqiangwei.club.cache.CacheRegion;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.dao.FriendLabelDAO;
import com.yeqiangwei.club.dao.model.FriendLabel;
import com.yeqiangwei.club.param.FriendParameter;
import com.yeqiangwei.club.service.model.FriendLabelModel;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.TypeChange;
import com.yeqiangwei.util.Validator;
public class FriendLabelServiceImpl extends MessageUtils implements FriendLabelService{
private static Cache cache = CacheFactory.creator(CacheRegion.FRIEND_LABEL);
public static void main(String args[]){
FriendLabelServiceImpl f = new FriendLabelServiceImpl();
FriendLabelModel m = new FriendLabelModel();
m.setLabelName("dddddddddd");
System.out.println(f.create(m));
System.out.println(m.getUserId());
}
public FriendLabelModel createOrUpdate(FriendLabelModel model) {
if(model.getFriendLabelId()>0){
return this.update(model);
}else{
return this.create(model);
}
}
public FriendLabelModel create(FriendLabelModel model) {
if(!Validator.isEmpty(model)){
if(!Validator.isEmpty(model.getLabelName())){
FriendLabel item = new FriendLabel();
BeanUtils.copyProperties(item,model);
if(this.getFriendLabelDAO().create(item)!=null){
BeanUtils.copyProperties(model,item);
cache.put(CacheKeys.getKey(model),model);
this.setMessage(MessageUtils.getMessage("success"));
}else{
model = null;
this.setMessage(MessageUtils.getMessage("error"));
}
}else{
model = null;
this.setMessage(MessageUtils.getMessage("error_empty"));
}
}
return model;
}
public FriendLabelModel update(FriendLabelModel model) {
if(!Validator.isEmpty(model)||model.getFriendLabelId()>0){
if(!Validator.isEmpty(model.getLabelName())){
FriendLabel item = this.getFriendLabelDAO().findById(model.getFriendLabelId());
BeanUtils.copyProperties(item,model);
if(this.getFriendLabelDAO().create(item)!=null){
BeanUtils.copyProperties(model,item);
cache.put(CacheKeys.getKey(model),model);
this.setMessage(MessageUtils.getMessage("success"));
}else{
model = null;
this.setMessage(MessageUtils.getMessage("error"));
}
}else{
model = null;
this.setMessage(MessageUtils.getMessage("error_empty"));
}
}
return model;
}
public int delete(FriendLabelModel model) {
int c = 0;
if(!Validator.isEmpty(model)&&model.getFriendLabelId()>0){
FriendLabel item = new FriendLabel();
BeanUtils.copyProperties(item,model);
c = this.getFriendLabelDAO().delete(item);
if(c>0){
cache.remove(model);
this.setMessage(MessageUtils.getMessage("success"));
}else{
this.setMessage(MessageUtils.getMessage("error"));
}
}
return c;
}
public int delete(String[] ids) {
int s = 0;
int e = 0;
if(!Validator.isEmpty(ids)){
for(int i=0; i<ids.length; i++){
int id = TypeChange.stringToInt(ids[i]);
FriendLabelModel model = new FriendLabelModel();
model.setFriendLabelId(id);
if(this.delete(model)>0){
s++;
}else{
e++;
}
}
}
this.setMessage(MessageUtils.getMessage(s,e));
return s;
}
public FriendLabelModel findById(int id) {
FriendLabelModel model = null;
if(id>0){
FriendLabel item = this.getFriendLabelDAO().findById(id);
if(!Validator.isEmpty(item)){
model = new FriendLabelModel();
BeanUtils.copyProperties(model,item);
cache.put(CacheKeys.getKey(model),model);
}
}
return model;
}
public List<FriendLabelModel> findByParameter(FriendParameter param) {
List<FriendLabel> list = this.getFriendLabelDAO().findByParameter(param);
List<FriendLabelModel> mlist = new ArrayList<FriendLabelModel>();
if(!Validator.isEmpty(list)){
for(int i=0; i<list.size(); i++){
FriendLabel item = list.get(i);
FriendLabelModel model = new FriendLabelModel();
com.yeqiangwei.util.BeanUtils.copyProperties(model,item);
mlist.add(i,model);
cache.put(CacheKeys.getKey(model),model);
}
}
return mlist;
}
public long countByParameter(FriendParameter param) {
return this.getFriendLabelDAO().countByParameter(param);
}
public FriendLabelDAO getFriendLabelDAO() {
return DAOWrapper.<FriendLabelDAO>getDAO(DAOLocator.FRIENDLABEL);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -