新增组织机构导入导出
This commit is contained in:
@@ -85,16 +85,7 @@ public class EmpUser extends User {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String[] codes; // 查询用
|
||||
|
||||
public EmpUser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public EmpUser(String id){
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Valid
|
||||
@ExcelFields({
|
||||
@ExcelField(title="归属机构", attrName="employee.office", align=Align.CENTER, sort=10, fieldType=OfficeType.class),
|
||||
@ExcelField(title="归属公司", attrName="employee.company", align = Align.CENTER, sort=20, fieldType=CompanyType.class),
|
||||
@@ -110,6 +101,15 @@ public class EmpUser extends User {
|
||||
@ExcelField(title="建档日期", attrName="createDate", align=Align.CENTER, words=15, sort=900, type=ExcelField.Type.EXPORT, dataFormat="yyyy-MM-dd"),
|
||||
@ExcelField(title="最后登录", attrName="lastLoginDate", align=Align.CENTER, words=20, sort=900, type=ExcelField.Type.EXPORT),
|
||||
})
|
||||
public EmpUser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public EmpUser(String id){
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Valid
|
||||
public Employee getEmployee(){
|
||||
Employee employee = super.getRefObj();
|
||||
if (employee == null){
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
*/
|
||||
package com.jeesite.modules.sys.entity;
|
||||
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.jeesite.common.entity.BaseEntity;
|
||||
@@ -16,6 +15,9 @@ import com.jeesite.common.entity.TreeEntity;
|
||||
import com.jeesite.common.mybatis.annotation.Column;
|
||||
import com.jeesite.common.mybatis.annotation.Table;
|
||||
import com.jeesite.common.mybatis.mapper.query.QueryType;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Align;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelFields;
|
||||
import com.jeesite.modules.sys.utils.EmpUtils;
|
||||
|
||||
/**
|
||||
@@ -38,7 +40,7 @@ import com.jeesite.modules.sys.utils.EmpUtils;
|
||||
@Column(name="zip_code", attrName="zipCode", label="邮政编码", queryType=QueryType.LIKE),
|
||||
@Column(name="email", attrName="email", label="邮箱", queryType=QueryType.LIKE),
|
||||
@Column(includeEntity=Extend.class, attrName="extend"),
|
||||
}, extWhereKeys="dsf", orderBy="a.tree_sort, a.office_code"
|
||||
}, extWhereKeys="dsf", orderBy="a.tree_sorts, a.office_code"
|
||||
)
|
||||
public class Office extends TreeEntity<Office> {
|
||||
|
||||
@@ -56,7 +58,19 @@ public class Office extends TreeEntity<Office> {
|
||||
private Extend extend; // 扩展字段
|
||||
|
||||
private String companyCode; // 根据公司查询机构,组织机构所属公司
|
||||
|
||||
|
||||
@ExcelFields({
|
||||
@ExcelField(title="上级编码", attrName="parentCode", align=Align.LEFT, sort=10),
|
||||
@ExcelField(title="机构编码", attrName="officeCode", align=Align.LEFT, sort=20),
|
||||
@ExcelField(title="显示编码", attrName="viewCode", align = Align.LEFT, sort=30),
|
||||
@ExcelField(title="机构名称", attrName="officeName", align=Align.LEFT, sort=40),
|
||||
@ExcelField(title="机构全称", attrName="fullName", align=Align.LEFT, sort=50),
|
||||
@ExcelField(title="机构类型", attrName="officeType", align=Align.CENTER, sort=60, dictType="sys_office_type"),
|
||||
@ExcelField(title="负责人", attrName="leader", align=Align.CENTER, sort=70),
|
||||
@ExcelField(title="电话", attrName="phone", align=Align.CENTER, sort=80),
|
||||
@ExcelField(title="联系地址", attrName="address", align=Align.CENTER, sort=90),
|
||||
@ExcelField(title="邮箱", attrName="email", align=Align.CENTER, sort=90),
|
||||
})
|
||||
public Office() {
|
||||
this(null);
|
||||
}
|
||||
@@ -74,7 +88,7 @@ public class Office extends TreeEntity<Office> {
|
||||
public void setParent(Office parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
|
||||
public String getOfficeCode() {
|
||||
return officeCode;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ package com.jeesite.modules.sys.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.jeesite.common.service.api.TreeServiceApi;
|
||||
import com.jeesite.modules.sys.entity.Office;
|
||||
|
||||
@@ -39,6 +41,13 @@ public interface OfficeService extends TreeServiceApi<Office> {
|
||||
@Override
|
||||
public void save(Office office);
|
||||
|
||||
/**
|
||||
* 导入机构数据
|
||||
* @param file 导入的用户数据文件
|
||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||
*/
|
||||
public String importData(MultipartFile file, Boolean isUpdateSupport);
|
||||
|
||||
/**
|
||||
* 更新部门状态
|
||||
*/
|
||||
|
||||
@@ -5,10 +5,18 @@ package com.jeesite.modules.sys.service.support;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.service.ServiceException;
|
||||
import com.jeesite.common.service.TreeService;
|
||||
import com.jeesite.common.utils.excel.ExcelImport;
|
||||
import com.jeesite.common.validator.ValidatorUtils;
|
||||
import com.jeesite.modules.sys.dao.OfficeDao;
|
||||
import com.jeesite.modules.sys.entity.Office;
|
||||
import com.jeesite.modules.sys.service.DataScopeService;
|
||||
@@ -69,6 +77,69 @@ public class OfficeServiceSupport extends TreeService<OfficeDao, Office>
|
||||
clearOfficeCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入机构数据
|
||||
* @param file 导入的机构数据文件
|
||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||
*/
|
||||
@Transactional(readOnly=false)
|
||||
public String importData(MultipartFile file, Boolean isUpdateSupport) {
|
||||
if (file == null){
|
||||
throw new ServiceException(text("请选择导入的数据文件!"));
|
||||
}
|
||||
int successNum = 0; int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
||||
List<Office> list = ei.getDataList(Office.class);
|
||||
for (Office office : list) {
|
||||
try{
|
||||
// 验证数据文件
|
||||
ValidatorUtils.validateWithException(office);
|
||||
// 验证是否存在这个机构
|
||||
Office e = get(office.getOfficeCode());
|
||||
if (e == null){
|
||||
office.setIsNewRecord(true);
|
||||
this.save(office);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、机构 " + office.getOfficeCode() + " 导入成功");
|
||||
} else if (isUpdateSupport){
|
||||
office.setOfficeCode(e.getOfficeCode());
|
||||
this.save(office);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、机构 " + office.getOfficeCode() + " 更新成功");
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、机构 " + office.getOfficeCode() + " 已存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、机构 " + office.getOfficeCode() + " 导入失败:";
|
||||
if (e instanceof ConstraintViolationException){
|
||||
ConstraintViolationException cve = (ConstraintViolationException)e;
|
||||
for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
|
||||
msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
|
||||
}
|
||||
}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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部门状态
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,8 @@ package com.jeesite.modules.sys.web;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -16,12 +18,16 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.jeesite.common.collect.ListUtils;
|
||||
import com.jeesite.common.collect.MapUtils;
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.idgen.IdGen;
|
||||
import com.jeesite.common.lang.DateUtils;
|
||||
import com.jeesite.common.lang.StringUtils;
|
||||
import com.jeesite.common.utils.excel.ExcelExport;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
|
||||
import com.jeesite.common.web.BaseController;
|
||||
import com.jeesite.modules.sys.entity.Office;
|
||||
import com.jeesite.modules.sys.service.OfficeService;
|
||||
@@ -163,6 +169,53 @@ public class OfficeController extends BaseController {
|
||||
return renderResult(Global.TRUE, text("保存机构''{0}''成功", office.getOfficeName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出机构数据
|
||||
*/
|
||||
@RequiresPermissions("sys:office:view")
|
||||
@RequestMapping(value = "exportData")
|
||||
public void exportData(Office office, Boolean isAll, String ctrlPermi, HttpServletResponse response) {
|
||||
if (!(isAll != null && isAll) || Global.isStrictMode()){
|
||||
officeService.addDataScopeFilter(office, ctrlPermi);
|
||||
}
|
||||
office.getSqlMap().getOrder().setOrderBy("a.tree_sorts");
|
||||
List<Office> list = officeService.findList(office);
|
||||
String fileName = "机构数据" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
||||
try(ExcelExport ee = new ExcelExport("机构数据", Office.class)){
|
||||
ee.setDataList(list).write(response, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载导入机构数据模板
|
||||
*/
|
||||
@RequiresPermissions("sys:office:view")
|
||||
@RequestMapping(value = "importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
Office office = new Office();
|
||||
List<Office> list = ListUtils.newArrayList(office);
|
||||
String fileName = "机构数据模板.xlsx";
|
||||
try(ExcelExport ee = new ExcelExport("机构数据", Office.class, Type.IMPORT)){
|
||||
ee.setDataList(list).write(response, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入机构数据
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequiresPermissions("sys:office:edit")
|
||||
@PostMapping(value = "importData")
|
||||
public String importData(MultipartFile file, String updateSupport) {
|
||||
try {
|
||||
boolean isUpdateSupport = Global.YES.equals(updateSupport);
|
||||
String message = officeService.importData(file, isUpdateSupport);
|
||||
return renderResult(Global.TRUE, "posfull:"+message);
|
||||
} catch (Exception ex) {
|
||||
return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用机构
|
||||
* @param office
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
<a href="#" class="btn btn-default" id="btnRefreshTree" title="${text('刷新')}"><i class="fa fa-refresh"></i> ${text('刷新')}</a>
|
||||
<a href="#" class="btn btn-default" id="btnExpandTreeNode" title="${text('展开一级')}"><i class="fa fa-angle-double-down"></i> ${text('展开')}</a>
|
||||
<a href="#" class="btn btn-default" id="btnCollapseTreeNode" title="${text('折叠全部')}"><i class="fa fa-angle-double-up"></i> ${text('折叠')}</a>
|
||||
<a href="#" class="btn btn-default" id="btnExport"><i class="glyphicon glyphicon-export"></i> ${text('导出')}</a>
|
||||
<% if(hasPermi('sys:office:edit')){ %>
|
||||
<a href="#" class="btn btn-default" id="btnImport"><i class="glyphicon glyphicon-import"></i> ${text('导入')}</a>
|
||||
<a href="${ctx}/sys/office/form" class="btn btn-default btnTool" title="${text('新增机构')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
|
||||
<% } %>
|
||||
<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
|
||||
@@ -104,4 +106,61 @@ $('#dataGrid').dataGrid({
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
$('#btnExport').click(function(){
|
||||
js.ajaxSubmitForm($('#searchForm'), {
|
||||
url:'${ctx}/sys/office/exportData',
|
||||
downloadFile:true
|
||||
});
|
||||
});
|
||||
$('#btnImport').click(function(){
|
||||
js.layer.open({
|
||||
type: 1,
|
||||
area: ['400px'],
|
||||
title: '${text("导入机构数据")}',
|
||||
resize: false,
|
||||
scrollbar: true,
|
||||
content: js.template('importTpl'),
|
||||
success: function(layero, index){
|
||||
layero.find('input[type="checkbox"]').iCheck();
|
||||
},
|
||||
btn: ['<i class="fa fa-check"></i> ${text("导入")}',
|
||||
'<i class="fa fa-remove"></i> ${text("关闭")}'],
|
||||
btn1: function(index, layero){
|
||||
var form = {
|
||||
inputForm: layero.find('#inputForm'),
|
||||
file: layero.find('#file').val()
|
||||
};
|
||||
if (form.file == '' || (!js.endWith(form.file, '.xls') && !js.endWith(form.file, '.xlsx'))){
|
||||
js.showMessage("${text('文件不正确,请选择后缀为“xls”或“xlsx”的文件。')}", null, 'warning');
|
||||
return false;
|
||||
}
|
||||
js.ajaxSubmitForm(form.inputForm, function(data){
|
||||
js.showMessage(data.message);
|
||||
if(data.result == Global.TRUE){
|
||||
js.layer.closeAll();
|
||||
}
|
||||
page();
|
||||
}, "json");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script id="importTpl" type="text/template">//<!--
|
||||
<form id="inputForm" action="${ctx}/sys/office/importData" method="post" enctype="multipart/form-data"
|
||||
class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-xs-offset-1">
|
||||
<input type="file" id="file" name="file" class="form-file"/>
|
||||
<div class="mt10 pt5">
|
||||
<#form:checkbox name="updateSupport" label="${text('是否更新已经存在的机构数据')}" class="form-control"
|
||||
title="${text('如果机构编码已经存在,更新这条数据。')}"/>
|
||||
<a href="${ctx}/sys/office/importTemplate" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> ${text('下载模板')}</a>
|
||||
</div>
|
||||
<font color="red" class="pull-left mt10">
|
||||
${text('提示:仅允许导入“xls”或“xlsx”格式文件!')}
|
||||
</font>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
//--></script>
|
||||
Reference in New Issue
Block a user