adminserviceimpl.java
来自「一个关于tlms的一个小程序 看看能否帮助到别人」· Java 代码 · 共 452 行 · 第 1/2 页
JAVA
452 行
/**
* ================================================================
* Copyright 2006 szmx
* <p/>
* Change Revision
* ---------------------------------------------------------------
* Date Author Remarks
* Mar 20, 2006 BZhang Create class com.szmx.tlms.admin.service.impl.AdminServiceImpl
* ================================================================
*/
package com.szmx.tlms.admin.service.impl;
import com.szmx.tlms.admin.dao.AdminDAO;
import com.szmx.tlms.admin.model.*;
import com.szmx.tlms.admin.service.AdminService;
import com.szmx.tlms.admin.service.MailService;
import com.szmx.tlms.admin.service.LogService;
import com.szmx.tlms.GlobalConstants;
import com.szmx.tlms.TlmsServiceException;
import com.szmx.tlms.TlmsServiceErrorCodes;
import com.szmx.framework.base.model.Pagination;
import com.szmx.framework.base.service.impl.BaseServiceImpl;
import com.szmx.framework.util.StringUtil;
import com.szmx.framework.util.SysPropertiesUtil;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
public class AdminServiceImpl extends BaseServiceImpl implements AdminService {
private AdminDAO adminDao;
private MailService mailService;
private LogService logService;
public void setAdminDao(AdminDAO adminDao) {
this.adminDao = adminDao;
}
public void setMailService(MailService mailService) {
this.mailService = mailService;
}
public void setLogService(LogService logService) {
this.logService = logService;
}
// Employee Managerment: ----------------------------------------
/**
* @throws TlmsServiceException
* @see AdminService#searchEmployees(com.szmx.framework.base.model.Pagination, com.szmx.tlms.admin.model.Employee)
*/
public Pagination searchEmployees(final Pagination pagination,
final Employee employee) throws TlmsServiceException {
Map paraMap = new HashMap();
paraMap.put("empId", employee.getEmpId());
paraMap.put("status", employee.getStatus());
if (! StringUtil.isNull(employee.getName())) {
paraMap.put("empName", "%" + employee.getName().trim() + "%");
}
return adminDao.searchEmployees(pagination, paraMap);
}
/**
* @throws TlmsServiceException
* @see AdminService#getEmployee(Long)
*/
public Employee getEmployee(Long id) throws TlmsServiceException {
return adminDao.getEmployee(id);
}
/**
* @throws TlmsServiceException
* @see AdminService#getEmployee(String)
*/
public Employee getEmployee(String empId) throws TlmsServiceException {
return adminDao.getEmployee(empId);
}
/**
* @throws TlmsServiceException
* @see AdminService#saveEmployee(com.szmx.tlms.admin.model.Employee)
*/
public void saveEmployee(Employee employee) throws TlmsServiceException {
// validate emp_id duplicate:
if (validateConflictEmployeeId(employee.getEmpId())) {
throw new TlmsServiceException(TlmsServiceErrorCodes.SERVICE_ERROR_AD002);
}
// save employee:
employee.setStatus(GlobalConstants.EMP_STATUS_WAITING);
employee.setPassword(newRandomPassword());
adminDao.saveEmployee(employee);
// assign role:
if (! StringUtil.isNull(employee.getRoleId())) {
String role[] = employee.getRoleId().split("~");
for (int i = 0; i < role.length; i++) {
RelEmpRole relEmpRole = new RelEmpRole();
relEmpRole.setEmpId(employee.getId());
relEmpRole.setRoleId(Long.valueOf(role[i]));
adminDao.saveObject(relEmpRole);
}
}
// system log:
Log log = new Log();
log.setEmpId(employee.getEmpId());
log.setActionCode(GlobalConstants.LOG_ACTION_TYPE_CREATE_USER);
Employee actionEmp = getEmployee(employee.getCreatedId());
if (actionEmp != null) {
log.setActionBy(actionEmp.getEmpId());
}
log.populateCreateBean(employee.getCreatedId());
logService.saveLog(log);
// send mail:
String subject = SysPropertiesUtil.getProperty("mail.msg.subject.admin.createEmployee");
String template = SysPropertiesUtil.getProperty("mail.msg.template.admin.createEmployee");
mailService.sendMail(employee.getEmail(), subject, template, new HashMap());
}
/**
* @throws TlmsServiceException
* @see AdminService#updateEmployee(com.szmx.tlms.admin.model.Employee)
*/
public void updateEmployee(Employee employee) throws TlmsServiceException {
// save employee
// employee.setStatus(GlobalConstants.EMP_STATUS_ACTIVE);
adminDao.saveEmployee(employee);
// remove relation of role
adminDao.removeEmpRoleRelation(employee.getId());
// new relation of role
if (! StringUtil.isNull(employee.getRoleId())) {
String role[] = employee.getRoleId().split("~");
for (int i = 0; i < role.length; i++) {
RelEmpRole relEmpRole = new RelEmpRole();
relEmpRole.setEmpId(employee.getId());
relEmpRole.setRoleId(Long.valueOf(role[i]));
adminDao.saveObject(relEmpRole);
}
}
}
/**
* @throws TlmsServiceException
* @see AdminService#removeEmployees(String[], Long)
*/
public void removeEmployees(String[] id, Long userId) throws TlmsServiceException {
for (int i = 0; i < id.length; i++) {
// inactive: [can not inactive admin user]
Employee employee = (Employee) adminDao.getObject(Employee.class, new Long(id[i]));
List roleList = adminDao.searchAssignedRoles(employee.getId());
if (roleList != null) {
for (int j = 0; j < roleList.size(); j++) {
Long roleId = (Long) ((Object[]) roleList.get(j))[1];
if (roleId.longValue() == 1) { // ROLE_ADMIN
throw new TlmsServiceException(TlmsServiceErrorCodes.SERVICE_ERROR_AD003);
}
}
}
employee.populateUpdateBean(userId);
employee.setStatus(GlobalConstants.EMP_STATUS_INACTIVE);
adminDao.saveObject(employee);
// system log:
Log log = new Log();
log.setEmpId(employee.getEmpId());
log.setActionCode(GlobalConstants.LOG_ACTION_TYPE_INACTIVE_USER);
Employee actionEmp = getEmployee(userId);
if (actionEmp != null) {
log.setActionBy(actionEmp.getEmpId());
}
log.populateCreateBean(userId);
logService.saveLog(log);
}
}
/**
* @throws TlmsServiceException
* @see AdminService#activeEmployee(Long, Long)
*/
public void activeEmployee(Long id, Long userId) throws TlmsServiceException {
String newPassword = newRandomPassword();
Employee employee = adminDao.getEmployee(id);
employee.setStatus(GlobalConstants.EMP_STATUS_WAITING);
employee.setPassword(newPassword);
employee.populateUpdateBean(userId);
adminDao.saveEmployee(employee);
// system log:
Log log = new Log();
log.setEmpId(employee.getEmpId());
log.setActionCode(GlobalConstants.LOG_ACTION_TYPE_ACTIVE_USER);
Employee actionEmp = getEmployee(userId);
if (actionEmp != null) {
log.setActionBy(actionEmp.getEmpId());
}
log.populateCreateBean(userId);
logService.saveLog(log);
// send mail:
String subject = SysPropertiesUtil.getProperty("mail.msg.subject.admin.activeEmployee");
String template = SysPropertiesUtil.getProperty("mail.msg.template.admin.activeEmployee");
mailService.sendMail(employee.getEmail(), subject, template, new HashMap());
}
/**
* @throws TlmsServiceException
* @see AdminService#resetPasswordByAdmin(Long, Long)
*/
public void resetPasswordByAdmin(Long id, Long userId) throws TlmsServiceException {
String newPassword = newRandomPassword();
Employee employee = adminDao.getEmployee(id);
employee.setStatus(GlobalConstants.EMP_STATUS_WAITING);
employee.setPassword(newPassword);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?