📄 operatorbusidao.java
字号:
package com.ufmobile.business.operator.bo.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import com.ufmobile.business.operator.entity.OperatorBusiEntity;
import com.ufmobile.common.dao.UFMobileDAO;
import com.ufmobile.mstreet.util.SqlUtil;
import com.ufmobile.platform.Exception.BusinessException;
public class OperatorBusiDAO extends UFMobileDAO {
public OperatorBusiDAO() {
super();
}
public OperatorBusiDAO(EntityManager manager) {
super(manager);
}
public OperatorBusiEntity addOperator(OperatorBusiEntity operatorEntity) throws BusinessException {
if (operatorEntity == null)
throw new BusinessException(this.getClass(), "操作员不能为空");
this.getManager().persist(operatorEntity);
return operatorEntity;
}
public void updateOperator(OperatorBusiEntity operatorEntity) throws BusinessException {
if (operatorEntity == null)
throw new BusinessException(this.getClass(), "操作员不能为空");
this.getManager().merge(operatorEntity);
}
public OperatorBusiEntity findOperatorById(Long id) throws BusinessException {
if (id == null)
throw new BusinessException(this.getClass(), "操作员id不能为空");
return this.getManager().find(OperatorBusiEntity.class, id);
}
public List<OperatorBusiEntity> queryOperatorByPage(int beginIndex, int maxNumber, String loginName, String name, Integer sex, Boolean state) throws BusinessException {
StringBuffer buf = constructQueryString(false, loginName, name, sex, state);
Query query = this.getManager().createQuery(buf.toString());
if (beginIndex > -1)
query.setFirstResult(beginIndex);
if (maxNumber > -1)
query.setMaxResults(maxNumber);
return query.getResultList();
}
public int queryOperatorTotal(String loginName, String name, Integer sex, Boolean state) throws BusinessException {
StringBuffer buf = constructQueryString(true, loginName, name, sex, state);
Query query = this.getManager().createQuery(buf.toString());
return ((Long) query.getSingleResult()).intValue();
}
private StringBuffer constructQueryString(boolean bCountTotal, String loginName, String name, Integer sex, Boolean state) {
StringBuffer buf = new StringBuffer();
if (bCountTotal)
buf.append("select count(*) from OperatorBusiEntity where 1=1");
else
buf.append(" from OperatorBusiEntity where 1=1");
if (loginName != null && loginName.trim().length() != 0)
buf.append(" and loginname like '%").append(SqlUtil.convert2SqlStr(loginName)).append("%'");
if (name != null && name.trim().length() != 0)
buf.append(" and realname like '%").append(SqlUtil.convert2SqlStr(name)).append("%'");
if (sex != null)
buf.append(" and sex=").append(sex.intValue()).append("");
if (state != null)
buf.append(" and state=").append(state).append("");
return buf;
}
public void deleteOperator(long... id) throws BusinessException {
if (id == null || id.length == 0)
return;
//删除一个
if (id.length == 1) {
OperatorBusiEntity o = this.getManager().find(OperatorBusiEntity.class,id[0]);
this.getManager().remove(o);
return ;
}
//批量删除
StringBuffer buf = new StringBuffer();
buf.append("delete from tb_business_operator where id in ('");
for (int i = 0; i < id.length; i++) {
buf.append(id[i]);
if (i < id.length - 1)
buf.append("','");
else
buf.append("')");
}
getManager().createNativeQuery(buf.toString()).executeUpdate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -