代码优化

This commit is contained in:
thinkgem
2019-05-13 23:36:28 +08:00
parent 5da0520832
commit a2d9c846bf
6 changed files with 8 additions and 312 deletions

View File

@@ -1,74 +0,0 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
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.service.CrudService;
import com.jeesite.modules.sys.dao.EmployeeOfficeDao;
import com.jeesite.modules.sys.entity.EmployeeOffice;
/**
* 附属机构Service
* @author ThinkGem
* @version 2019-05-05
*/
@Service
@Transactional(readOnly=true)
public class EmployeeOfficeService extends CrudService<EmployeeOfficeDao, EmployeeOffice> {
/**
* 获取单条数据
* @param employeeOffice
* @return
*/
@Override
public EmployeeOffice get(EmployeeOffice employeeOffice) {
return super.get(employeeOffice);
}
/**
* 查询分页数据
* @param employeeOffice 查询条件
* @param employeeOffice.page 分页对象
* @return
*/
@Override
public Page<EmployeeOffice> findPage(EmployeeOffice employeeOffice) {
return super.findPage(employeeOffice);
}
/**
* 保存数据(插入或更新)
* @param employeeOffice
*/
@Override
@Transactional(readOnly=false)
public void save(EmployeeOffice employeeOffice) {
super.save(employeeOffice);
}
/**
* 更新状态
* @param employeeOffice
*/
@Override
@Transactional(readOnly=false)
public void updateStatus(EmployeeOffice employeeOffice) {
super.updateStatus(employeeOffice);
}
/**
* 删除数据
* @param employeeOffice
*/
@Override
@Transactional(readOnly=false)
public void delete(EmployeeOffice employeeOffice) {
super.delete(employeeOffice);
}
}

View File

@@ -14,7 +14,7 @@ import com.jeesite.modules.sys.entity.EmployeeOffice;
import com.jeesite.modules.sys.entity.Office;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.service.CompanyService;
import com.jeesite.modules.sys.service.EmployeeOfficeService;
import com.jeesite.modules.sys.service.EmployeeService;
import com.jeesite.modules.sys.service.OfficeService;
/**
@@ -31,6 +31,7 @@ public class EmpUtils {
// 部门和公司缓存常量
public static final String CACHE_OFFICE_ALL_LIST = "officeAllList";
public static final String CACHE_COMPANY_ALL_LIST = "companyAllList";
public static final String CACHE_COMPANY_OFFICE_LIST = "employeeOfficeList";
/**
* 静态内部类,延迟加载,懒汉式,线程安全的单例模式
@@ -38,7 +39,7 @@ public class EmpUtils {
private static final class Static {
private static OfficeService officeService = SpringUtils.getBean(OfficeService.class);
private static CompanyService companyService = SpringUtils.getBean(CompanyService.class);
private static EmployeeOfficeService employeeOfficeService = SpringUtils.getBean(EmployeeOfficeService.class);
private static EmployeeService employeeService = SpringUtils.getBean(EmployeeService.class);
}
/**
@@ -61,12 +62,10 @@ public class EmpUtils {
* 获取当前附属部门对象列表
*/
public static List<EmployeeOffice> getEmployeeOfficeList(){
List<EmployeeOffice> list = UserUtils.getCache("employeeOfficeList");
List<EmployeeOffice> list = UserUtils.getCache(CACHE_COMPANY_OFFICE_LIST);
if (list == null){
EmployeeOffice where = new EmployeeOffice();
where.setEmpCode(getEmployee().getEmpCode());
list = Static.employeeOfficeService.findList(where);
UserUtils.putCache("employeeOfficeList", list);
list = Static.employeeService.findEmployeeOfficeList(getEmployee());
UserUtils.putCache(CACHE_COMPANY_OFFICE_LIST, list);
}
return list;
}

View File

@@ -1,107 +0,0 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
package com.jeesite.modules.sys.web.user;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
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 com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sys.entity.EmployeeOffice;
import com.jeesite.modules.sys.entity.Post;
import com.jeesite.modules.sys.service.EmployeeOfficeService;
import com.jeesite.modules.sys.service.PostService;
/**
* 附属机构Controller
* @author ThinkGem
* @version 2019-05-05
*/
@Controller
@RequestMapping(value = "${adminPath}/sys/empOffice")
public class EmpOfficeController extends BaseController {
@Autowired
private EmployeeOfficeService employeeOfficeService;
@Autowired
private PostService postService;
/**
* 获取数据
*/
@ModelAttribute
public EmployeeOffice get(String empCode, String officeCode, boolean isNewRecord) {
return employeeOfficeService.get(new Class<?>[]{String.class, String.class},
new Object[]{empCode, officeCode}, isNewRecord);
}
/**
* 查询列表
*/
@RequiresPermissions("sys:empUser:view")
@RequestMapping(value = {"list", ""})
public String list(EmployeeOffice employeeOffice, Model model) {
model.addAttribute("employeeOffice", employeeOffice);
return "modules/sys/user/empOfficeList";
}
/**
* 查询列表数据
*/
@RequiresPermissions("sys:empUser:view")
@RequestMapping(value = "listData")
@ResponseBody
public Page<EmployeeOffice> listData(EmployeeOffice employeeOffice, HttpServletRequest request, HttpServletResponse response) {
employeeOffice.setPage(new Page<>(request, response));
Page<EmployeeOffice> page = employeeOfficeService.findPage(employeeOffice);
return page;
}
/**
* 查看编辑表单
*/
@RequiresPermissions("sys:empUser:view")
@RequestMapping(value = "form")
public String form(EmployeeOffice employeeOffice, Model model) {
// 获取岗位列表
Post post = new Post();
model.addAttribute("postList", postService.findList(post));
model.addAttribute("employeeOffice", employeeOffice);
return "modules/sys/user/empOfficeForm";
}
/**
* 保存附属机构
*/
@RequiresPermissions("sys:empUser:edit")
@PostMapping(value = "save")
@ResponseBody
public String save(@Validated EmployeeOffice employeeOffice) {
employeeOfficeService.save(employeeOffice);
return renderResult(Global.TRUE, text("保存附属机构成功!"));
}
/**
* 删除附属机构
*/
@RequiresPermissions("sys:empUser:edit")
@RequestMapping(value = "delete")
@ResponseBody
public String delete(EmployeeOffice employeeOffice) {
employeeOfficeService.delete(employeeOffice);
return renderResult(Global.TRUE, text("删除附属机构成功!"));
}
}

View File

@@ -1,69 +0,0 @@
<% layout('/layouts/default.html', {title: '附属机构管理', libs: ['validate']}){ %>
<div class="main-content">
<div class="box box-main">
<div class="box-header with-border">
<div class="box-title">
<i class="fa fa-list-alt"></i> ${text(employeeOffice.isNewRecord ? '新增附属机构' : '编辑附属机构')}
</div>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div>
</div>
<#form:form id="inputForm" model="${employeeOffice}" action="${ctx}/sys/empOffice/save" method="post" class="form-horizontal">
<#form:hidden path="empCode"/>
<#form:hidden path="isNewRecord"/>
<div class="box-body"><br/>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label class="control-label col-sm-2" title="">
<span class="required hide">*</span> ${text('附属机构')}<i class="fa icon-question hide"></i></label>
<div class="col-sm-5">
<#form:treeselect id="office" title="${text('机构选择')}"
path="officeCode" labelPath="officeName" readonly="${!employeeOffice.isNewRecord}"
url="${ctx}/sys/office/treeData?ctrlPermi=${@Global.getConfig('user.adminCtrlPermi', '2')}" class="required" allowClear="false"/>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label class="control-label col-sm-2" title="">
<span class="required hide">*</span> ${text('岗位编码')}<i class="fa icon-question hide"></i></label>
<div class="col-sm-5">
<#form:select name="postCode" items="${postList}"
itemLabel="postName" itemValue="postCode" class="form-control"/>
</div>
</div>
</div>
</div>
</div>
<div class="box-footer">
<div class="row">
<div class="col-sm-offset-2 col-sm-10">
<% if (hasPermi('sys:empUser:view')){ %>
<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
<% } %>
<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
</div>
</div>
</div>
</#form:form>
</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
submitHandler: function(form){
js.ajaxSubmitForm($(form), function(data){
js.showMessage(data.message);
if(data.result == Global.TRUE){
js.closeCurrentTabPage(function(contentWindow){
contentWindow.page();
});
}
}, "json");
}
});
</script>

View File

@@ -1,53 +0,0 @@
<% layout('/layouts/default.html', {title: '附属机构管理', libs: ['dataGrid']}){ %>
<div class="main-content">
<div class="box box-main">
<div class="box-header">
<div class="box-title">
<i class="fa fa-list-alt"></i> ${text('附属机构管理')}
</div>
<div class="box-tools pull-right">
<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
<% if(hasPermi('sys:empUser:view')){ %>
<a href="${ctx}/sys/empOffice/form?empCode=1&isNewRecord=true" class="btn btn-default btnTool" title="${text('新增附属机构')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
<% } %>
</div>
</div>
<div class="box-body">
<#form:form id="searchForm" model="${employeeOffice}" action="${ctx}/sys/empOffice/listData" method="post" class="form-inline hide"
data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
<#form:hidden path="empCode"/>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
</div>
</#form:form>
<table id="dataGrid"></table>
<div id="dataGridPage"></div>
</div>
</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
searchForm: $("#searchForm"),
columnModel: [
{header:'${text("附属机构")}', name:'officeCode', index:'a.office_code', width:200, align:"center", frozen:true, formatter: function(val, obj, row, act){
return '<a href="${ctx}/sys/empOffice/form?empCode='+row.empCode+'&officeCode='+row.officeCode+'" class="btnList" data-title="${text("编辑附属机构")}">'+(val||row.id)+'</a>';
}},
{header:'${text("岗位编码")}', name:'postCode', index:'a.post_code', width:200, align:"center"},
{header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
var actions = [];
<% if(hasPermi('sys:empUser:view')){ %>
actions.push('<a href="${ctx}/sys/empOffice/form?empCode='+row.empCode+'&officeCode='+row.officeCode+'" class="btnList" title="${text("编辑附属机构")}"><i class="fa fa-pencil"></i></a>&nbsp;');
actions.push('<a href="${ctx}/sys/empOffice/delete?empCode='+row.empCode+'&officeCode='+row.officeCode+'" class="btnList" title="${text("删除附属机构")}" data-confirm="${text("确认要删除该附属机构吗?")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
<% } %>
return actions.join('');
}}
],
// 加载成功后执行事件
ajaxSuccess: function(data){
}
});
</script>