将公司、部门、员工、用户、岗位、日志分离出接口方便用户扩展
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.autoconfigure.sys;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import com.jeesite.modules.sys.service.AreaService;
|
||||||
|
import com.jeesite.modules.sys.service.CompanyService;
|
||||||
|
import com.jeesite.modules.sys.service.EmpUserService;
|
||||||
|
import com.jeesite.modules.sys.service.EmployeeService;
|
||||||
|
import com.jeesite.modules.sys.service.LogService;
|
||||||
|
import com.jeesite.modules.sys.service.OfficeService;
|
||||||
|
import com.jeesite.modules.sys.service.PostService;
|
||||||
|
import com.jeesite.modules.sys.service.support.AreaServiceSupport;
|
||||||
|
import com.jeesite.modules.sys.service.support.CompanyServiceSupport;
|
||||||
|
import com.jeesite.modules.sys.service.support.EmpUserServiceSupport;
|
||||||
|
import com.jeesite.modules.sys.service.support.EmployeeServiceSupport;
|
||||||
|
import com.jeesite.modules.sys.service.support.LogServiceSupport;
|
||||||
|
import com.jeesite.modules.sys.service.support.OfficeServiceSupport;
|
||||||
|
import com.jeesite.modules.sys.service.support.PostServiceSupport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统核心实现类
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2018-10-13
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SysAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public AreaService areaService(){
|
||||||
|
return new AreaServiceSupport();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public CompanyService companyService(){
|
||||||
|
return new CompanyServiceSupport();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public EmployeeService employeeService(){
|
||||||
|
return new EmployeeServiceSupport();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public EmpUserService empUserService(){
|
||||||
|
return new EmpUserServiceSupport();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public LogService logService(){
|
||||||
|
return new LogServiceSupport();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public OfficeService officeService(){
|
||||||
|
return new OfficeServiceSupport();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public PostService postService(){
|
||||||
|
return new PostServiceSupport();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,57 +5,38 @@ package com.jeesite.modules.sys.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import com.jeesite.common.service.api.TreeServiceApi;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.service.TreeService;
|
|
||||||
import com.jeesite.modules.sys.dao.AreaDao;
|
|
||||||
import com.jeesite.modules.sys.entity.Area;
|
import com.jeesite.modules.sys.entity.Area;
|
||||||
import com.jeesite.modules.sys.utils.AreaUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行政区划Service
|
* 行政区划Service
|
||||||
* @author ThinkGem
|
* @author ThinkGem
|
||||||
* @version 2014-8-19
|
* @version 2014-8-19
|
||||||
*/
|
*/
|
||||||
@Service
|
public interface AreaService extends TreeServiceApi<Area> {
|
||||||
@Transactional(readOnly=true)
|
|
||||||
public class AreaService extends TreeService<AreaDao, Area> {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取区划
|
* 获取区划
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Area get(Area area) {
|
public Area get(Area area);
|
||||||
return super.get(area);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询区划
|
* 查询区划
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Area> findList(Area area) {
|
public List<Area> findList(Area area);
|
||||||
return super.findList(area);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存区划
|
* 保存区划
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void save(Area area);
|
||||||
public void save(Area area) {
|
|
||||||
super.save(area);
|
|
||||||
AreaUtils.clearCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除区划
|
* 删除区划
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void delete(Area area);
|
||||||
public void delete(Area area) {
|
|
||||||
super.delete(area);
|
|
||||||
AreaUtils.clearCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,112 +5,50 @@ package com.jeesite.modules.sys.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import com.jeesite.common.service.api.TreeServiceApi;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.collect.ListUtils;
|
|
||||||
import com.jeesite.common.service.TreeService;
|
|
||||||
import com.jeesite.modules.sys.dao.CompanyDao;
|
|
||||||
import com.jeesite.modules.sys.dao.CompanyOfficeDao;
|
|
||||||
import com.jeesite.modules.sys.entity.Company;
|
import com.jeesite.modules.sys.entity.Company;
|
||||||
import com.jeesite.modules.sys.entity.CompanyOffice;
|
|
||||||
import com.jeesite.modules.sys.utils.EmpUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公司管理Service
|
* 公司管理Service
|
||||||
* @author thinkgem
|
* @author ThinkGem
|
||||||
* @version 2016-4-23
|
* @version 2016-4-23
|
||||||
*/
|
*/
|
||||||
@Service
|
public interface CompanyService extends TreeServiceApi<Company> {
|
||||||
@Transactional(readOnly=true)
|
|
||||||
public class CompanyService extends TreeService<CompanyDao, Company> {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CompanyOfficeDao companyOfficeDao;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DataScopeService dataScopeService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单条数据
|
* 获取单条数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Company get(Company company) {
|
public Company get(Company company);
|
||||||
return super.get(company);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加数据权限过滤条件
|
* 添加数据权限过滤条件
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addDataScopeFilter(Company company, String ctrlPermi) {
|
public void addDataScopeFilter(Company company, String ctrlPermi);
|
||||||
company.getSqlMap().getDataScope().addFilter("dsf", "Company", "a.company_code", ctrlPermi);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询公司列表
|
* 查询公司列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Company> findList(Company company) {
|
public List<Company> findList(Company company);
|
||||||
return super.findList(company);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存公司
|
* 保存公司
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void save(Company company);
|
||||||
public void save(Company company) {
|
|
||||||
if (company.getIsNewRecord()){
|
|
||||||
genIdAndValid(company, company.getViewCode());
|
|
||||||
// 当前新数据授权,如果用户有上级数据权限,则当前数据也有相应的数据权限
|
|
||||||
dataScopeService.insertIfParentExists(company, "Company");
|
|
||||||
}
|
|
||||||
super.save(company);
|
|
||||||
// 重新绑定组织和公司之间的关系
|
|
||||||
if (StringUtils.isBlank(company.getCompanyCode())){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CompanyOffice where = new CompanyOffice();
|
|
||||||
where.setCompanyCode(company.getCompanyCode());
|
|
||||||
companyOfficeDao.deleteByEntity(where);
|
|
||||||
if (ListUtils.isNotEmpty(company.getCompanyOfficeList())){
|
|
||||||
companyOfficeDao.insertBatch(company.getCompanyOfficeList());
|
|
||||||
}
|
|
||||||
// 清理公司相关缓存
|
|
||||||
clearCompanyCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除公司
|
* 删除公司
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void delete(Company company);
|
||||||
public void delete(Company company) {
|
|
||||||
super.delete(company);
|
|
||||||
// 清理公司相关缓存
|
|
||||||
clearCompanyCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停用当前节点
|
* 停用当前节点
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void updateStatus(Company company);
|
||||||
public void updateStatus(Company company) {
|
|
||||||
dao.updateStatus(company);
|
|
||||||
// 清理公司相关缓存
|
|
||||||
clearCompanyCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理公司相关缓存
|
|
||||||
*/
|
|
||||||
private void clearCompanyCache(){
|
|
||||||
// EmpUtils.removeCache(EmpUtils.CACHE_COMPANY_LIST);
|
|
||||||
EmpUtils.removeCache(EmpUtils.CACHE_COMPANY_ALL_LIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,51 +3,24 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.sys.service;
|
package com.jeesite.modules.sys.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.validation.ConstraintViolationException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import com.jeesite.common.entity.Page;
|
import com.jeesite.common.entity.Page;
|
||||||
import com.jeesite.common.idgen.IdGen;
|
import com.jeesite.common.service.api.CrudServiceApi;
|
||||||
import com.jeesite.common.lang.StringUtils;
|
|
||||||
import com.jeesite.common.service.CrudService;
|
|
||||||
import com.jeesite.common.service.ServiceException;
|
|
||||||
import com.jeesite.common.utils.excel.ExcelImport;
|
|
||||||
import com.jeesite.common.validator.ValidatorUtils;
|
|
||||||
import com.jeesite.modules.sys.dao.EmpUserDao;
|
|
||||||
import com.jeesite.modules.sys.entity.EmpUser;
|
import com.jeesite.modules.sys.entity.EmpUser;
|
||||||
import com.jeesite.modules.sys.entity.Employee;
|
|
||||||
import com.jeesite.modules.sys.entity.User;
|
|
||||||
import com.jeesite.modules.sys.utils.EmpUtils;
|
|
||||||
import com.jeesite.modules.sys.utils.UserUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 员工管理Service
|
* 员工管理Service
|
||||||
* @author ThinkGem
|
* @author ThinkGem
|
||||||
* @version 2017-03-25
|
* @version 2017-03-25
|
||||||
*/
|
*/
|
||||||
@Service
|
public interface EmpUserService extends CrudServiceApi<EmpUser> {
|
||||||
@Transactional(readOnly=true)
|
|
||||||
public class EmpUserService extends CrudService<EmpUserDao, EmpUser> {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmployeeService employeeService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单条数据
|
* 获取单条数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public EmpUser get(EmpUser empUser) {
|
public EmpUser get(EmpUser empUser);
|
||||||
return super.get(empUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加数据权限过滤条件
|
* 添加数据权限过滤条件
|
||||||
@@ -55,134 +28,37 @@ public class EmpUserService extends CrudService<EmpUserDao, EmpUser> {
|
|||||||
* @param ctrlPermi 控制权限类型(拥有的数据权限:DataScope.CTRL_PERMI_HAVE、可管理的数据权限:DataScope.CTRL_PERMI_HAVE)
|
* @param ctrlPermi 控制权限类型(拥有的数据权限:DataScope.CTRL_PERMI_HAVE、可管理的数据权限:DataScope.CTRL_PERMI_HAVE)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addDataScopeFilter(EmpUser empUser, String ctrlPermi) {
|
public void addDataScopeFilter(EmpUser empUser, String ctrlPermi);
|
||||||
empUser.getSqlMap().getDataScope().addFilter("dsfOffice",
|
|
||||||
"Office", "e.office_code", "a.create_by", ctrlPermi);
|
|
||||||
if (StringUtils.isNotBlank(EmpUtils.getCompany().getCompanyCode())){
|
|
||||||
empUser.getSqlMap().getDataScope().addFilter("dsfCompany",
|
|
||||||
"Company", "e.company_code", "a.create_by", ctrlPermi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询数据
|
* 分页查询数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Page<EmpUser> findPage(EmpUser empUser) {
|
public Page<EmpUser> findPage(EmpUser empUser);
|
||||||
return super.findPage(empUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存用户员工
|
* 保存用户员工
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void save(EmpUser user);
|
||||||
public void save(EmpUser user) {
|
|
||||||
// 1、初始化用户信息
|
|
||||||
if (user.getIsNewRecord()){
|
|
||||||
userService.genId(user, user.getLoginCode());
|
|
||||||
user.setUserCode(user.getUserCode()+"_"+IdGen.randomBase62(4).toLowerCase());
|
|
||||||
user.setUserType(EmpUser.USER_TYPE_EMPLOYEE);
|
|
||||||
user.setMgrType(EmpUser.MGR_TYPE_NOT_ADMIN);
|
|
||||||
}
|
|
||||||
Employee employee = user.getEmployee();
|
|
||||||
// 如果员工编码为空,则使用用户编码
|
|
||||||
if (StringUtils.isBlank(employee.getEmpCode())){
|
|
||||||
employee.setEmpCode(user.getUserCode());
|
|
||||||
}
|
|
||||||
// 如果员工姓名为空,则使用昵称名
|
|
||||||
if (StringUtils.isBlank(employee.getEmpName())){
|
|
||||||
employee.setEmpName(user.getUserName());
|
|
||||||
}
|
|
||||||
// 2、保存用户
|
|
||||||
user.setRefCode(employee.getEmpCode());
|
|
||||||
user.setRefName(employee.getEmpName());
|
|
||||||
userService.save(user);
|
|
||||||
// 3、保存员工
|
|
||||||
employee.setIsNewRecord(user.getIsNewRecord());
|
|
||||||
employeeService.save(employee);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入用户数据
|
* 导入用户数据
|
||||||
* @param file 导入的用户数据文件
|
* @param file 导入的用户数据文件
|
||||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly=false)
|
public String importData(MultipartFile file, Boolean isUpdateSupport);
|
||||||
public String importData(MultipartFile file, Boolean isUpdateSupport) {
|
|
||||||
if (file == null){
|
|
||||||
throw new ServiceException("请选择导入的数据文件!");
|
|
||||||
}
|
|
||||||
int successNum = 0; int failureNum = 0;
|
|
||||||
StringBuilder successMsg = new StringBuilder();
|
|
||||||
StringBuilder failureMsg = new StringBuilder();
|
|
||||||
try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
|
||||||
List<EmpUser> list = ei.getDataList(EmpUser.class);
|
|
||||||
for (EmpUser user : list) {
|
|
||||||
try{
|
|
||||||
// 验证数据文件
|
|
||||||
ValidatorUtils.validateWithException(user);
|
|
||||||
// 验证是否存在这个用户
|
|
||||||
User u = UserUtils.getByLoginCode(user.getLoginCode());
|
|
||||||
if (u == null){
|
|
||||||
this.save(user);
|
|
||||||
successNum++;
|
|
||||||
successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginCode() + " 导入成功");
|
|
||||||
} else if (isUpdateSupport){
|
|
||||||
user.setUserCode(u.getUserCode());
|
|
||||||
this.save(user);
|
|
||||||
successNum++;
|
|
||||||
successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginCode() + " 更新成功");
|
|
||||||
} else {
|
|
||||||
failureNum++;
|
|
||||||
failureMsg.append("<br/>" + failureNum + "、账号 " + user.getLoginCode() + " 已存在");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
failureNum++;
|
|
||||||
String msg = "<br/>" + failureNum + "、账号 " + user.getLoginCode() + " 导入失败:";
|
|
||||||
if (e instanceof ConstraintViolationException){
|
|
||||||
List<String> messageList = ValidatorUtils.extractPropertyAndMessageAsList((ConstraintViolationException)e, ": ");
|
|
||||||
for (String message : messageList) {
|
|
||||||
msg += message + "; ";
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
msg += e.getMessage();
|
|
||||||
}
|
|
||||||
failureMsg.append(msg);
|
|
||||||
logger.error(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
failureMsg.append(e.getMessage());
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
if (failureNum > 0) {
|
|
||||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
||||||
throw new ServiceException(failureMsg.toString());
|
|
||||||
}else{
|
|
||||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
||||||
}
|
|
||||||
return successMsg.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新状态
|
* 更新状态
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void updateStatus(EmpUser empUser);
|
||||||
public void updateStatus(EmpUser empUser) {
|
|
||||||
userService.delete(empUser);
|
|
||||||
employeeService.delete(empUser.getEmployee());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除用户
|
* 删除用户
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void delete(EmpUser empUser);
|
||||||
public void delete(EmpUser empUser) {
|
|
||||||
userService.delete(empUser);
|
|
||||||
employeeService.delete(empUser.getEmployee());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,15 +5,8 @@ package com.jeesite.modules.sys.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.collect.ListUtils;
|
|
||||||
import com.jeesite.common.entity.Page;
|
import com.jeesite.common.entity.Page;
|
||||||
import com.jeesite.common.service.CrudService;
|
import com.jeesite.common.service.api.CrudServiceApi;
|
||||||
import com.jeesite.modules.sys.dao.EmployeeDao;
|
|
||||||
import com.jeesite.modules.sys.dao.EmployeePostDao;
|
|
||||||
import com.jeesite.modules.sys.entity.Employee;
|
import com.jeesite.modules.sys.entity.Employee;
|
||||||
import com.jeesite.modules.sys.entity.EmployeePost;
|
import com.jeesite.modules.sys.entity.EmployeePost;
|
||||||
|
|
||||||
@@ -22,68 +15,35 @@ import com.jeesite.modules.sys.entity.EmployeePost;
|
|||||||
* @author ThinkGem
|
* @author ThinkGem
|
||||||
* @version 2017-03-25
|
* @version 2017-03-25
|
||||||
*/
|
*/
|
||||||
@Service
|
public interface EmployeeService extends CrudServiceApi<Employee> {
|
||||||
@Transactional(readOnly=true)
|
|
||||||
public class EmployeeService extends CrudService<EmployeeDao, Employee> {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmployeePostDao employeePostDao;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单条数据
|
* 获取单条数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Employee get(Employee employee) {
|
public Employee get(Employee employee);
|
||||||
return super.get(employee);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询分页数据
|
* 查询分页数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Page<Employee> findPage(Employee employee) {
|
public Page<Employee> findPage(Employee employee);
|
||||||
return super.findPage(employee);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存数据(插入或更新)
|
* 保存数据(插入或更新)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void save(Employee employee);
|
||||||
public void save(Employee employee) {
|
|
||||||
if (employee.getIsNewRecord()){
|
|
||||||
if (dao.get(employee) != null){
|
|
||||||
throw newValidationException("员工编码已存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.save(employee);
|
|
||||||
// 保存员工岗位
|
|
||||||
EmployeePost where = new EmployeePost();
|
|
||||||
where.setEmpCode(employee.getEmpCode());
|
|
||||||
employeePostDao.deleteByEntity(where);
|
|
||||||
if (ListUtils.isNotEmpty(employee.getEmployeePostList())){
|
|
||||||
for (EmployeePost e : employee.getEmployeePostList()){
|
|
||||||
e.setEmpCode(employee.getEmpCode());
|
|
||||||
}
|
|
||||||
employeePostDao.insertBatch(employee.getEmployeePostList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除数据
|
* 删除数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void delete(Employee employee);
|
||||||
public void delete(Employee employee) {
|
|
||||||
super.delete(employee);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询当前员工关联的岗位信息
|
* 查询当前员工关联的岗位信息
|
||||||
*/
|
*/
|
||||||
public List<EmployeePost> findEmployeePostList(Employee employee){
|
public List<EmployeePost> findEmployeePostList(Employee employee);
|
||||||
EmployeePost employeePost = new EmployeePost();
|
|
||||||
employeePost.setEmpCode(employee.getEmpCode());
|
|
||||||
return employeePostDao.findList(employeePost);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.sys.service;
|
package com.jeesite.modules.sys.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.entity.Page;
|
import com.jeesite.common.entity.Page;
|
||||||
import com.jeesite.common.service.CrudService;
|
import com.jeesite.common.service.api.CrudServiceApi;
|
||||||
import com.jeesite.modules.sys.dao.LogDao;
|
|
||||||
import com.jeesite.modules.sys.entity.Log;
|
import com.jeesite.modules.sys.entity.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,36 +12,17 @@ import com.jeesite.modules.sys.entity.Log;
|
|||||||
* @author ThinkGem
|
* @author ThinkGem
|
||||||
* @version 2014-05-16
|
* @version 2014-05-16
|
||||||
*/
|
*/
|
||||||
@Service
|
public interface LogService extends CrudServiceApi<Log> {
|
||||||
@Transactional(readOnly=true)
|
|
||||||
public class LogService extends CrudService<LogDao, Log> {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询日志记录
|
* 查询日志记录
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Page<Log> findPage(Log log) {
|
public Page<Log> findPage(Log log);
|
||||||
// // 设置默认时间范围,默认当前月
|
|
||||||
// if (log.getCreateDate_gte() == null){
|
|
||||||
// log.setCreateDate_gte(DateUtils.setDays(new Date(), 1));
|
|
||||||
// }
|
|
||||||
// if (log.getCreateDate_lte() == null){
|
|
||||||
// log.setCreateDate_lte(DateUtils.addDays(DateUtils.addMonths(log.getCreateDate_gte(), 1), -1));
|
|
||||||
// }
|
|
||||||
// 普通用户看自己的,管理员看全部的。
|
|
||||||
if (!log.getCurrentUser().isAdmin()){
|
|
||||||
log.setCreateBy(log.getCurrentUser().getUserCode());
|
|
||||||
}
|
|
||||||
return super.findPage(log);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不使用数据库事务,执行插入日志
|
* 不使用数据库事务,执行插入日志
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly=false, propagation=Propagation.NOT_SUPPORTED)
|
public void insertLog(Log entity);
|
||||||
public void insertLog(Log entity) {
|
|
||||||
dao.insert(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,95 +5,50 @@ package com.jeesite.modules.sys.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import com.jeesite.common.service.api.TreeServiceApi;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.service.TreeService;
|
|
||||||
import com.jeesite.modules.sys.dao.OfficeDao;
|
|
||||||
import com.jeesite.modules.sys.entity.Office;
|
import com.jeesite.modules.sys.entity.Office;
|
||||||
import com.jeesite.modules.sys.utils.EmpUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机构Service
|
* 机构Service
|
||||||
* @author ThinkGem
|
* @author ThinkGem
|
||||||
* @version 2016-4-23
|
* @version 2016-4-23
|
||||||
*/
|
*/
|
||||||
@Service
|
public interface OfficeService extends TreeServiceApi<Office> {
|
||||||
@Transactional(readOnly=true)
|
|
||||||
public class OfficeService extends TreeService<OfficeDao, Office> {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DataScopeService dataScopeService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单条数据
|
* 获取单条数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Office get(Office office) {
|
public Office get(Office office);
|
||||||
return super.get(office);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加数据权限过滤条件
|
* 添加数据权限过滤条件
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addDataScopeFilter(Office office, String ctrlPermi) {
|
public void addDataScopeFilter(Office office, String ctrlPermi);
|
||||||
office.getSqlMap().getDataScope().addFilter("dsf", "Office", "a.office_code", ctrlPermi);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询组织机构列表
|
* 查询组织机构列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Office> findList(Office office) {
|
public List<Office> findList(Office office);
|
||||||
return super.findList(office);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存数据(插入或更新)
|
* 保存数据(插入或更新)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void save(Office office);
|
||||||
public void save(Office office) {
|
|
||||||
if (office.getIsNewRecord()){
|
|
||||||
genIdAndValid(office, office.getViewCode());
|
|
||||||
// 当前新数据授权,如果用户有上级数据权限,则当前数据也有相应的数据权限
|
|
||||||
dataScopeService.insertIfParentExists(office, "Office");
|
|
||||||
}
|
|
||||||
super.save(office);
|
|
||||||
// 清理部门相关缓存
|
|
||||||
clearOfficeCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新部门状态
|
* 更新部门状态
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void updateStatus(Office office);
|
||||||
public void updateStatus(Office office) {
|
|
||||||
super.updateStatus(office);
|
|
||||||
// 清理部门相关缓存
|
|
||||||
clearOfficeCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除数据
|
* 删除数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void delete(Office office);
|
||||||
public void delete(Office office) {
|
|
||||||
super.delete(office);
|
|
||||||
// 清理部门相关缓存
|
|
||||||
clearOfficeCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理部门相关缓存
|
|
||||||
*/
|
|
||||||
private void clearOfficeCache(){
|
|
||||||
// EmpUtils.removeCache(EmpUtils.CACHE_OFFICE_LIST);
|
|
||||||
EmpUtils.removeCache(EmpUtils.CACHE_OFFICE_ALL_LIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.sys.service;
|
package com.jeesite.modules.sys.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.entity.Page;
|
import com.jeesite.common.entity.Page;
|
||||||
import com.jeesite.common.service.CrudService;
|
import com.jeesite.common.service.api.CrudServiceApi;
|
||||||
import com.jeesite.modules.sys.dao.PostDao;
|
|
||||||
import com.jeesite.modules.sys.entity.Post;
|
import com.jeesite.modules.sys.entity.Post;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,60 +12,41 @@ import com.jeesite.modules.sys.entity.Post;
|
|||||||
* @author ThinkGem
|
* @author ThinkGem
|
||||||
* @version 2017-03-25
|
* @version 2017-03-25
|
||||||
*/
|
*/
|
||||||
@Service
|
public interface PostService extends CrudServiceApi<Post> {
|
||||||
@Transactional(readOnly=true)
|
|
||||||
public class PostService extends CrudService<PostDao, Post> {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询岗位
|
* 查询岗位
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Post get(Post post) {
|
public Post get(Post post);
|
||||||
return super.get(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据名称查询岗位
|
* 根据名称查询岗位
|
||||||
*/
|
*/
|
||||||
public Post getByPostName(Post post) {
|
public Post getByPostName(Post post);
|
||||||
Post where = new Post();
|
|
||||||
where.setPostName(post.getPostName());
|
|
||||||
return dao.getByEntity(where);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询岗位
|
* 查询岗位
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Page<Post> findPage(Post post) {
|
public Page<Post> findPage(Post post);
|
||||||
return super.findPage(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存岗位
|
* 保存岗位
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void save(Post post);
|
||||||
public void save(Post post) {
|
|
||||||
super.save(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新岗位状态
|
* 更新岗位状态
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void updateStatus(Post post);
|
||||||
public void updateStatus(Post post) {
|
|
||||||
super.updateStatus(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除岗位
|
* 删除岗位
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly=false)
|
public void delete(Post post);
|
||||||
public void delete(Post post) {
|
|
||||||
super.delete(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.jeesite.common.service.TreeService;
|
||||||
|
import com.jeesite.modules.sys.dao.AreaDao;
|
||||||
|
import com.jeesite.modules.sys.entity.Area;
|
||||||
|
import com.jeesite.modules.sys.service.AreaService;
|
||||||
|
import com.jeesite.modules.sys.utils.AreaUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行政区划Service
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2014-8-19
|
||||||
|
*/
|
||||||
|
@Transactional(readOnly=true)
|
||||||
|
public class AreaServiceSupport extends TreeService<AreaDao, Area>
|
||||||
|
implements AreaService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取区划
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Area get(Area area) {
|
||||||
|
return super.get(area);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询区划
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Area> findList(Area area) {
|
||||||
|
return super.findList(area);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存区划
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void save(Area area) {
|
||||||
|
super.save(area);
|
||||||
|
AreaUtils.clearCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除区划
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void delete(Area area) {
|
||||||
|
super.delete(area);
|
||||||
|
AreaUtils.clearCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.jeesite.common.collect.ListUtils;
|
||||||
|
import com.jeesite.common.service.TreeService;
|
||||||
|
import com.jeesite.modules.sys.dao.CompanyDao;
|
||||||
|
import com.jeesite.modules.sys.dao.CompanyOfficeDao;
|
||||||
|
import com.jeesite.modules.sys.entity.Company;
|
||||||
|
import com.jeesite.modules.sys.entity.CompanyOffice;
|
||||||
|
import com.jeesite.modules.sys.service.CompanyService;
|
||||||
|
import com.jeesite.modules.sys.service.DataScopeService;
|
||||||
|
import com.jeesite.modules.sys.utils.EmpUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司管理Service
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2016-4-23
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly=true)
|
||||||
|
public class CompanyServiceSupport extends TreeService<CompanyDao, Company>
|
||||||
|
implements CompanyService{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyOfficeDao companyOfficeDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataScopeService dataScopeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单条数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Company get(Company company) {
|
||||||
|
return super.get(company);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加数据权限过滤条件
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addDataScopeFilter(Company company, String ctrlPermi) {
|
||||||
|
company.getSqlMap().getDataScope().addFilter("dsf", "Company", "a.company_code", ctrlPermi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询公司列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Company> findList(Company company) {
|
||||||
|
return super.findList(company);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存公司
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void save(Company company) {
|
||||||
|
if (company.getIsNewRecord()){
|
||||||
|
genIdAndValid(company, company.getViewCode());
|
||||||
|
// 当前新数据授权,如果用户有上级数据权限,则当前数据也有相应的数据权限
|
||||||
|
dataScopeService.insertIfParentExists(company, "Company");
|
||||||
|
}
|
||||||
|
super.save(company);
|
||||||
|
// 重新绑定组织和公司之间的关系
|
||||||
|
if (StringUtils.isBlank(company.getCompanyCode())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CompanyOffice where = new CompanyOffice();
|
||||||
|
where.setCompanyCode(company.getCompanyCode());
|
||||||
|
companyOfficeDao.deleteByEntity(where);
|
||||||
|
if (ListUtils.isNotEmpty(company.getCompanyOfficeList())){
|
||||||
|
companyOfficeDao.insertBatch(company.getCompanyOfficeList());
|
||||||
|
}
|
||||||
|
// 清理公司相关缓存
|
||||||
|
clearCompanyCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除公司
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void delete(Company company) {
|
||||||
|
super.delete(company);
|
||||||
|
// 清理公司相关缓存
|
||||||
|
clearCompanyCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停用当前节点
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void updateStatus(Company company) {
|
||||||
|
dao.updateStatus(company);
|
||||||
|
// 清理公司相关缓存
|
||||||
|
clearCompanyCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理公司相关缓存
|
||||||
|
*/
|
||||||
|
private void clearCompanyCache(){
|
||||||
|
// EmpUtils.removeCache(EmpUtils.CACHE_COMPANY_LIST);
|
||||||
|
EmpUtils.removeCache(EmpUtils.CACHE_COMPANY_ALL_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import com.jeesite.common.entity.Page;
|
||||||
|
import com.jeesite.common.idgen.IdGen;
|
||||||
|
import com.jeesite.common.lang.StringUtils;
|
||||||
|
import com.jeesite.common.service.CrudService;
|
||||||
|
import com.jeesite.common.service.ServiceException;
|
||||||
|
import com.jeesite.common.utils.excel.ExcelImport;
|
||||||
|
import com.jeesite.common.validator.ValidatorUtils;
|
||||||
|
import com.jeesite.modules.sys.dao.EmpUserDao;
|
||||||
|
import com.jeesite.modules.sys.entity.EmpUser;
|
||||||
|
import com.jeesite.modules.sys.entity.Employee;
|
||||||
|
import com.jeesite.modules.sys.entity.User;
|
||||||
|
import com.jeesite.modules.sys.service.EmpUserService;
|
||||||
|
import com.jeesite.modules.sys.service.EmployeeService;
|
||||||
|
import com.jeesite.modules.sys.service.UserService;
|
||||||
|
import com.jeesite.modules.sys.utils.EmpUtils;
|
||||||
|
import com.jeesite.modules.sys.utils.UserUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工管理Service
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2017-03-25
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly=true)
|
||||||
|
public class EmpUserServiceSupport extends CrudService<EmpUserDao, EmpUser>
|
||||||
|
implements EmpUserService{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmployeeService employeeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单条数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EmpUser get(EmpUser empUser) {
|
||||||
|
return super.get(empUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加数据权限过滤条件
|
||||||
|
* @param entity 控制对象
|
||||||
|
* @param ctrlPermi 控制权限类型(拥有的数据权限:DataScope.CTRL_PERMI_HAVE、可管理的数据权限:DataScope.CTRL_PERMI_HAVE)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addDataScopeFilter(EmpUser empUser, String ctrlPermi) {
|
||||||
|
empUser.getSqlMap().getDataScope().addFilter("dsfOffice",
|
||||||
|
"Office", "e.office_code", "a.create_by", ctrlPermi);
|
||||||
|
if (StringUtils.isNotBlank(EmpUtils.getCompany().getCompanyCode())){
|
||||||
|
empUser.getSqlMap().getDataScope().addFilter("dsfCompany",
|
||||||
|
"Company", "e.company_code", "a.create_by", ctrlPermi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Page<EmpUser> findPage(EmpUser empUser) {
|
||||||
|
return super.findPage(empUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存用户员工
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void save(EmpUser user) {
|
||||||
|
// 1、初始化用户信息
|
||||||
|
if (user.getIsNewRecord()){
|
||||||
|
userService.genId(user, user.getLoginCode());
|
||||||
|
user.setUserCode(user.getUserCode()+"_"+IdGen.randomBase62(4).toLowerCase());
|
||||||
|
user.setUserType(EmpUser.USER_TYPE_EMPLOYEE);
|
||||||
|
user.setMgrType(EmpUser.MGR_TYPE_NOT_ADMIN);
|
||||||
|
}
|
||||||
|
Employee employee = user.getEmployee();
|
||||||
|
// 如果员工编码为空,则使用用户编码
|
||||||
|
if (StringUtils.isBlank(employee.getEmpCode())){
|
||||||
|
employee.setEmpCode(user.getUserCode());
|
||||||
|
}
|
||||||
|
// 如果员工姓名为空,则使用昵称名
|
||||||
|
if (StringUtils.isBlank(employee.getEmpName())){
|
||||||
|
employee.setEmpName(user.getUserName());
|
||||||
|
}
|
||||||
|
// 2、保存用户
|
||||||
|
user.setRefCode(employee.getEmpCode());
|
||||||
|
user.setRefName(employee.getEmpName());
|
||||||
|
userService.save(user);
|
||||||
|
// 3、保存员工
|
||||||
|
employee.setIsNewRecord(user.getIsNewRecord());
|
||||||
|
employeeService.save(employee);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入用户数据
|
||||||
|
* @param file 导入的用户数据文件
|
||||||
|
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||||
|
*/
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public String importData(MultipartFile file, Boolean isUpdateSupport) {
|
||||||
|
if (file == null){
|
||||||
|
throw new ServiceException("请选择导入的数据文件!");
|
||||||
|
}
|
||||||
|
int successNum = 0; int failureNum = 0;
|
||||||
|
StringBuilder successMsg = new StringBuilder();
|
||||||
|
StringBuilder failureMsg = new StringBuilder();
|
||||||
|
try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
||||||
|
List<EmpUser> list = ei.getDataList(EmpUser.class);
|
||||||
|
for (EmpUser user : list) {
|
||||||
|
try{
|
||||||
|
// 验证数据文件
|
||||||
|
ValidatorUtils.validateWithException(user);
|
||||||
|
// 验证是否存在这个用户
|
||||||
|
User u = UserUtils.getByLoginCode(user.getLoginCode());
|
||||||
|
if (u == null){
|
||||||
|
this.save(user);
|
||||||
|
successNum++;
|
||||||
|
successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginCode() + " 导入成功");
|
||||||
|
} else if (isUpdateSupport){
|
||||||
|
user.setUserCode(u.getUserCode());
|
||||||
|
this.save(user);
|
||||||
|
successNum++;
|
||||||
|
successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginCode() + " 更新成功");
|
||||||
|
} else {
|
||||||
|
failureNum++;
|
||||||
|
failureMsg.append("<br/>" + failureNum + "、账号 " + user.getLoginCode() + " 已存在");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
failureNum++;
|
||||||
|
String msg = "<br/>" + failureNum + "、账号 " + user.getLoginCode() + " 导入失败:";
|
||||||
|
if (e instanceof ConstraintViolationException){
|
||||||
|
List<String> messageList = ValidatorUtils.extractPropertyAndMessageAsList((ConstraintViolationException)e, ": ");
|
||||||
|
for (String message : messageList) {
|
||||||
|
msg += message + "; ";
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
msg += e.getMessage();
|
||||||
|
}
|
||||||
|
failureMsg.append(msg);
|
||||||
|
logger.error(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
failureMsg.append(e.getMessage());
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
if (failureNum > 0) {
|
||||||
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||||
|
throw new ServiceException(failureMsg.toString());
|
||||||
|
}else{
|
||||||
|
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||||
|
}
|
||||||
|
return successMsg.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void updateStatus(EmpUser empUser) {
|
||||||
|
userService.delete(empUser);
|
||||||
|
employeeService.delete(empUser.getEmployee());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void delete(EmpUser empUser) {
|
||||||
|
userService.delete(empUser);
|
||||||
|
employeeService.delete(empUser.getEmployee());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.jeesite.common.collect.ListUtils;
|
||||||
|
import com.jeesite.common.entity.Page;
|
||||||
|
import com.jeesite.common.service.CrudService;
|
||||||
|
import com.jeesite.modules.sys.dao.EmployeeDao;
|
||||||
|
import com.jeesite.modules.sys.dao.EmployeePostDao;
|
||||||
|
import com.jeesite.modules.sys.entity.Employee;
|
||||||
|
import com.jeesite.modules.sys.entity.EmployeePost;
|
||||||
|
import com.jeesite.modules.sys.service.EmployeeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工管理Service
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2017-03-25
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly=true)
|
||||||
|
public class EmployeeServiceSupport extends CrudService<EmployeeDao, Employee>
|
||||||
|
implements EmployeeService{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmployeePostDao employeePostDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单条数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Employee get(Employee employee) {
|
||||||
|
return super.get(employee);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询分页数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Page<Employee> findPage(Employee employee) {
|
||||||
|
return super.findPage(employee);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存数据(插入或更新)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void save(Employee employee) {
|
||||||
|
if (employee.getIsNewRecord()){
|
||||||
|
if (dao.get(employee) != null){
|
||||||
|
throw newValidationException("员工编码已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.save(employee);
|
||||||
|
// 保存员工岗位
|
||||||
|
EmployeePost where = new EmployeePost();
|
||||||
|
where.setEmpCode(employee.getEmpCode());
|
||||||
|
employeePostDao.deleteByEntity(where);
|
||||||
|
if (ListUtils.isNotEmpty(employee.getEmployeePostList())){
|
||||||
|
for (EmployeePost e : employee.getEmployeePostList()){
|
||||||
|
e.setEmpCode(employee.getEmpCode());
|
||||||
|
}
|
||||||
|
employeePostDao.insertBatch(employee.getEmployeePostList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void delete(Employee employee) {
|
||||||
|
super.delete(employee);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前员工关联的岗位信息
|
||||||
|
*/
|
||||||
|
public List<EmployeePost> findEmployeePostList(Employee employee){
|
||||||
|
EmployeePost employeePost = new EmployeePost();
|
||||||
|
employeePost.setEmpCode(employee.getEmpCode());
|
||||||
|
return employeePostDao.findList(employeePost);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.jeesite.common.entity.Page;
|
||||||
|
import com.jeesite.common.service.CrudService;
|
||||||
|
import com.jeesite.modules.sys.dao.LogDao;
|
||||||
|
import com.jeesite.modules.sys.entity.Log;
|
||||||
|
import com.jeesite.modules.sys.service.LogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志Service
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2014-05-16
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly=true)
|
||||||
|
public class LogServiceSupport extends CrudService<LogDao, Log>
|
||||||
|
implements LogService{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询日志记录
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Page<Log> findPage(Log log) {
|
||||||
|
// // 设置默认时间范围,默认当前月
|
||||||
|
// if (log.getCreateDate_gte() == null){
|
||||||
|
// log.setCreateDate_gte(DateUtils.setDays(new Date(), 1));
|
||||||
|
// }
|
||||||
|
// if (log.getCreateDate_lte() == null){
|
||||||
|
// log.setCreateDate_lte(DateUtils.addDays(DateUtils.addMonths(log.getCreateDate_gte(), 1), -1));
|
||||||
|
// }
|
||||||
|
// 普通用户看自己的,管理员看全部的。
|
||||||
|
if (!log.getCurrentUser().isAdmin()){
|
||||||
|
log.setCreateBy(log.getCurrentUser().getUserCode());
|
||||||
|
}
|
||||||
|
return super.findPage(log);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不使用数据库事务,执行插入日志
|
||||||
|
*/
|
||||||
|
@Transactional(readOnly=false, propagation=Propagation.NOT_SUPPORTED)
|
||||||
|
public void insertLog(Log entity) {
|
||||||
|
dao.insert(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.jeesite.common.service.TreeService;
|
||||||
|
import com.jeesite.modules.sys.dao.OfficeDao;
|
||||||
|
import com.jeesite.modules.sys.entity.Office;
|
||||||
|
import com.jeesite.modules.sys.service.DataScopeService;
|
||||||
|
import com.jeesite.modules.sys.service.OfficeService;
|
||||||
|
import com.jeesite.modules.sys.utils.EmpUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机构Service
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2016-4-23
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly=true)
|
||||||
|
public class OfficeServiceSupport extends TreeService<OfficeDao, Office>
|
||||||
|
implements OfficeService{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataScopeService dataScopeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单条数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Office get(Office office) {
|
||||||
|
return super.get(office);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加数据权限过滤条件
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addDataScopeFilter(Office office, String ctrlPermi) {
|
||||||
|
office.getSqlMap().getDataScope().addFilter("dsf", "Office", "a.office_code", ctrlPermi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询组织机构列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Office> findList(Office office) {
|
||||||
|
return super.findList(office);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存数据(插入或更新)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void save(Office office) {
|
||||||
|
if (office.getIsNewRecord()){
|
||||||
|
genIdAndValid(office, office.getViewCode());
|
||||||
|
// 当前新数据授权,如果用户有上级数据权限,则当前数据也有相应的数据权限
|
||||||
|
dataScopeService.insertIfParentExists(office, "Office");
|
||||||
|
}
|
||||||
|
super.save(office);
|
||||||
|
// 清理部门相关缓存
|
||||||
|
clearOfficeCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新部门状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void updateStatus(Office office) {
|
||||||
|
super.updateStatus(office);
|
||||||
|
// 清理部门相关缓存
|
||||||
|
clearOfficeCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void delete(Office office) {
|
||||||
|
super.delete(office);
|
||||||
|
// 清理部门相关缓存
|
||||||
|
clearOfficeCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理部门相关缓存
|
||||||
|
*/
|
||||||
|
private void clearOfficeCache(){
|
||||||
|
// EmpUtils.removeCache(EmpUtils.CACHE_OFFICE_LIST);
|
||||||
|
EmpUtils.removeCache(EmpUtils.CACHE_OFFICE_ALL_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.jeesite.common.entity.Page;
|
||||||
|
import com.jeesite.common.service.CrudService;
|
||||||
|
import com.jeesite.modules.sys.dao.PostDao;
|
||||||
|
import com.jeesite.modules.sys.entity.Post;
|
||||||
|
import com.jeesite.modules.sys.service.PostService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 岗位管理Service
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2017-03-25
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly=true)
|
||||||
|
public class PostServiceSupport extends CrudService<PostDao, Post>
|
||||||
|
implements PostService{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询岗位
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Post get(Post post) {
|
||||||
|
return super.get(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据名称查询岗位
|
||||||
|
*/
|
||||||
|
public Post getByPostName(Post post) {
|
||||||
|
Post where = new Post();
|
||||||
|
where.setPostName(post.getPostName());
|
||||||
|
return dao.getByEntity(where);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询岗位
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Page<Post> findPage(Post post) {
|
||||||
|
return super.findPage(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存岗位
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void save(Post post) {
|
||||||
|
super.save(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新岗位状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void updateStatus(Post post) {
|
||||||
|
super.updateStatus(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除岗位
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly=false)
|
||||||
|
public void delete(Post post) {
|
||||||
|
super.delete(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Auto Configure
|
||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
com.jeesite.autoconfigure.sys.SysAutoConfiguration
|
||||||
Reference in New Issue
Block a user