一级部门配置

master
OathK1per 2022-09-09 16:02:55 +08:00
parent ccd379d545
commit 72ead4d14c
5 changed files with 523 additions and 0 deletions

View File

@ -0,0 +1,122 @@
package cn.palmte.work.controller.backend;
import cn.palmte.work.bean.ResponseMsg;
import cn.palmte.work.model.Dept;
import cn.palmte.work.model.ProcurementType;
import cn.palmte.work.model.Project;
import cn.palmte.work.service.DeptService;
import cn.palmte.work.service.ProcurementTypeService;
import cn.palmte.work.utils.Utils;
import cn.palmte.work.utils.excel.ExportUtils;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import top.jfunc.common.db.bean.Page;
import top.jfunc.common.utils.CollectionUtil;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/department")
public class DepartmentController extends BaseController{
@Autowired
private DeptService deptService;
/**
*
* @param keywords
* @param pageNumber
* @param pageSize
* @param model
* @return
*/
@RequestMapping("/list")
public String list(@RequestParam(value = "keywords",required = false) String keywords,
@RequestParam(value = PAGE_NUMBER, defaultValue = DEFAULT_PAGE_NUMBER) int pageNumber,
@RequestParam(value = PAGE_SIZE, defaultValue = DEFAULT_PAGE_SIZE) int pageSize,
Map<String, Object> model) {
model.put("keywords",keywords);
ConcurrentHashMap<String, String> searchInfo = getSearchInfo(keywords,model);
Page<Dept> page = deptService.list(searchInfo, pageNumber, pageSize);
List<Dept> list = page.getList();
if(CollectionUtil.isNotEmpty(list)){
int offset = (pageNumber - 1) * pageSize;
for (int i = 0 , size = list.size(); i < size; i++) {
list.get(i).setTempId(i+1 + offset);
}
}
model.put("pager", page);
return "/admin/department_list";
}
/**
*
* @param model
* @return
*/
@GetMapping(value = "/add")
public String add( Map<String, Object> model){
Dept department = new Dept();
model.put("deptId",-1);
model.put("department",department);
return "/admin/department_input";
}
/**
*
* @param deptId
* @param dept
* @param model
* @return
*/
@PostMapping(value = "/save")
public String save(@RequestParam("deptId") int deptId,
Dept dept, Map<String, Object> model){
deptService.saveOtUpdate(deptId,dept);
return "redirect:/department/list";
}
/**
*
*/
@RequestMapping("/enableOrDisable")
@ResponseBody
public ResponseMsg enableOrDisable(@RequestParam("id") int id,
@RequestParam("status") int status, RedirectAttributes attr) {
boolean isSuccess = false;
try {
isSuccess = deptService.enableOrDisable(status, id);
} catch (Exception e) {
e.getMessage();
}
if (isSuccess) {
return ResponseMsg.buildSuccessMsg("操作成功");
} else {
return ResponseMsg.buildSuccessMsg("操作失败");
}
}
/**
*
*/
@RequestMapping("/export")
public void export(@RequestParam(value = "keywords",required = false) String keywords, HttpServletResponse httpServletResponse) throws IOException {
Map<String, String> searchInfo = getSearchInfo(keywords);
downloadHeader(httpServletResponse , Utils.generateExcelName("部门表"), "application/octet-stream");
String[] headers = {"部门名称","创建人","创建时间"};
String[] exportColumns = {"name","createdBy","createdTime"};
ExportUtils.exportToExcel(headers, exportColumns, 1, 10000,
httpServletResponse.getOutputStream(), (pN, pS) -> deptService.list(searchInfo, pN, pS).getList());
}
}

View File

@ -3,6 +3,7 @@ package cn.palmte.work.model;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.Date;
/**
*
@ -22,6 +23,21 @@ public class Dept {
private String name;
private int enabled;
@Column(name = "created_by")
private String createdBy;
/**
*
*/
@Column(name = "created_time")
@Temporal(TemporalType.TIMESTAMP)
private Date createdTime;
@Transient
private int tempId;
public Integer getId() {
return id;
}
@ -37,4 +53,36 @@ public class Dept {
public void setName(String name) {
this.name = name;
}
public int getEnabled() {
return enabled;
}
public void setEnabled(int enabled) {
this.enabled = enabled;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
public int getTempId() {
return tempId;
}
public void setTempId(int tempId) {
this.tempId = tempId;
}
}

View File

@ -3,10 +3,18 @@ package cn.palmte.work.service;
import cn.palmte.work.model.Admin;
import cn.palmte.work.model.Dept;
import cn.palmte.work.model.DeptRepository;
import cn.palmte.work.model.ProcurementType;
import cn.palmte.work.utils.InterfaceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jfunc.common.db.QueryHelper;
import top.jfunc.common.db.bean.Page;
import top.jfunc.common.db.utils.Pagination;
import top.jfunc.common.utils.CollectionUtil;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author xiongshiyan at 2021/10/29 , contact me with email yanshixiong@126.com or phone 15208384257
@ -16,6 +24,9 @@ public class DeptService {
@Autowired
private DeptRepository deptRepository;
@Autowired
private Pagination pagination;
public List<Dept> findAll(){
return deptRepository.findAll();
}
@ -24,4 +35,43 @@ public class DeptService {
return deptRepository.findOne(admin.getDeptId());
}
public Page<Dept> list(Map<String, String> searchInfo, int pageNumber, int pageSize){
QueryHelper queryHelper = new QueryHelper("SELECT *","dept");
queryHelper.addCondition(searchInfo.containsKey("name"), "name like ?", "%" +
searchInfo.get("name") + "%");
queryHelper.addCondition(searchInfo.containsKey("enabled") && !"-1".equals(searchInfo.get("enabled")),
"enabled=" + searchInfo.get("enabled"));
queryHelper.addCondition(searchInfo.containsKey("startTime"), "created_time >= ?", searchInfo.get("startTime") + " 00:00:00");
queryHelper.addCondition(searchInfo.containsKey("endTime"), "created_time <= ?", searchInfo.get("endTime") + " 23:59:59");
queryHelper.addOrderProperty("created_time", false);
Page<Dept> paginate = pagination.paginate(queryHelper.getSql(), Dept.class, pageNumber, pageSize);
return paginate;
}
public Dept findOne(int id) {
return deptRepository.findOne(id);
}
public void saveOtUpdate(int deptId, Dept dept) {
Dept obj = deptRepository.findOne(deptId);
if(null == obj){
obj = new Dept();
obj.setName(dept.getName());
obj.setEnabled(dept.getEnabled());
obj.setCreatedBy(InterfaceUtil.getAdmin().getRealName());
obj.setCreatedTime(new Date());
}else {
obj.setName(dept.getName());
obj.setEnabled(dept.getEnabled());
}
deptRepository.saveAndFlush(obj);
}
public boolean enableOrDisable(int status, int id) {
Dept one = deptRepository.findOne(id);
one.setEnabled(status);
Dept dept = deptRepository.saveAndFlush(one);
return null != dept;
}
}

View File

@ -0,0 +1,84 @@
<#assign base=request.contextPath />
<#import "../common/defaultLayout.ftl" as defaultLayout>
<@defaultLayout.layout>
<link rel="stylesheet" href="${base}/assets/css/amazeui.switch.css"/>
<script type="text/javascript">
var base = '${base}';
</script>
<div class="admin-content">
<div class="admin-content-body">
<div class="am-cf am-padding">
<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">配置管理</strong> /
<small>部门配置</small>
</div>
</div>
<form method="post" class="am-form" id="tmpForm"
action="${base}/department/save">
<input name="deptId" id="deptId" type="hidden" value="${deptId!}"/>
<div class="am-tabs am-margin" data-am-tabs>
<ul class="am-tabs-nav am-nav am-nav-tabs">
<li class="am-active"><a href="#tab1">新增</a></li>
</ul>
<div class="am-tabs-bd">
<div class="am-tab-panel am-fade am-in am-active" id="tab1">
<div class="am-g am-form-group am-margin-top" style="display: flex;">
<div class="am-u-sm-4 am-u-md-2 am-text-right">
<span style="color: red;">*</span>部门名称</div>
<div class="am-u-sm-6 am-u-md-6">
<input class="js-ajax-validate" name="name" data-validation-message="请输入部门名称20字符以内"
minlength="1" maxlength="10"
value="${department.name!}" type="text" required/>
</div>
<div class="am-u-sm-2 am-u-md-4 input-msg"></div>
</div>
<div class="am-g am-form-group am-margin-top">
<div class="am-u-sm-4 am-u-md-2 am-text-right">启用/禁用</div>
<div class="am-u-sm-12 am-u-md-4 switch-button" style="height: 25px;">
<input id="switch" name="switch" type="checkbox" data-size='xs'
data-am-switch data-off-text="禁用" data-on-text="启用"
<#if department.enabled==1 >checked</#if>
/>
<input type="hidden" class="am-input-sm" name="enabled" id="enabled"
value="${department.enabled!1}"/>
</div>
<div class="am-hide-sm-only am-u-md-1" style="color: red;"></div>
<div class="am-u-sm-2 am-u-md-5 input-msg"></div>
</div>
</div>
</div>
</div>
<!--选项卡tabsend-->
<div class="am-margin">
<button type="submit" id="submitBtn" class="am-btn am-btn-primary am-btn-xs">提交保存</button>
<button type="button" class="am-btn am-btn-warning am-btn-xs"
onclick="javascript:history.go(-1);">返回上一级
</button>
</div>
</form>
</div>
</div>
</@defaultLayout.layout>
<script src="${base}/assets/js/amazeui.switch.js"></script>
<script>
var $mycheckbox = $('.switch-button');
$mycheckbox.each(function () {
$("#switch").on({
'switchChange.bootstrapSwitch': function (event, state) {
if (state.toString() == "true") {
$("#enabled").val("1");
} else {
$("#enabled").val("0");
}
}
});
});
</script>

View File

@ -0,0 +1,219 @@
<#assign base=request.contextPath />
<#import "../common/defaultLayout.ftl" as defaultLayout>
<@defaultLayout.layout>
<link rel="stylesheet" href="${base}/assets/css/amazeui.switch.css"/>
<div class="admin-content">
<div class="am-cf am-padding" style="padding:1rem 1.6rem 1.6rem 1rem;margin:0px;">
<!-- padding:1px 2px 3px 4px;上、右、下,和左 -->
<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">配置管理</strong> /
<small>部门配置</small>
</div>
</div>
<div class="am-g">
<div class="am-u-sm-12">
<form class="am-form" id="listForm" action="${base}/department/list" method="POST">
<input type="hidden" id="keywords" name="keywords" value='${keywords!""}'/>
<table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
<tbody>
<tr>
<th class="am-text-middle">部门名称</th>
<td>
<div class="am-u-sm-10">
<input type="text" id="name" class="am-form-field am-input-sm"
value="${name!}"/>
</div>
</td>
<th class="am-text-middle">启用状态</th>
<td>
<div class="am-u-sm-10">
<select data-am-selected="{btnWidth: '40%', btnSize: 'sm'" id="enabled">
<option value="-1">全部</option>
<option value="1" <#if enabled! == "1">selected</#if> >启用</option>
<option value="0" <#if enabled! == "0">selected</#if> >禁用</option>
</select>
</div>
</td>
</tr>
<tr>
<th class="am-text-middle">创建时间</th>
<td>
<div class="am-u-sm-10">
<div class="am-form am-form-inline">
<div class="am-form-group am-form-icon">
<i class="am-icon-calendar"></i>
<input type="text" class="am-form-field am-input-sm" id="startTime" readonly
value="${startTime!}" placeholder="开始日期" data-am-datepicker>
</div>
<div class="am-form-group">至</div>
<div class="am-form-group am-form-icon">
<i class="am-icon-calendar"></i>
<input type="text" class="am-form-field am-input-sm" id="endTime"
value="${endTime!}" readonly
placeholder="结束日期" data-am-datepicker>
</div>
</div>
</div>
</td>
<td colspan="2">
<div align='right'>
<button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary"
id="submit-btn" onclick="sub_function('query')">搜索
</button>
<@shiro.hasPermission name="DEPARTMENT_EXPORT">
<button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary"
id="submit-btn-export" onclick="sub_function('export')">导出
</button>
</@shiro.hasPermission>
</div>
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="am-btn-toolbar" style="padding-left:.5rem;">
<div class="am-btn-group am-btn-group-xs">
<@shiro.hasPermission name="DEPARTMENT_ADD">
<button type="button" class="am-btn am-btn-default"
onclick="location.href='${base}/department/add'">
<span class="am-icon-plus"></span> 新增
</button>
</@shiro.hasPermission>
</div>
</div>
</div>
<div class="am-g">
<div class="am-u-sm-12">
<div class="am-scrollable-horizontal">
<table class="am-table am-table-striped am-table-hover table-main">
<thead>
<tr class="am-text-nowrap">
<th class="table-title">序号</th>
<th class="table-title">部门名称</th>
<th class="table-title">创建人</th>
<th class="table-title">创建时间</th>
<th class="table-title">操作</th>
</tr>
</thead>
<tbody>
<#if (pager.list)?exists && (pager.list?size>0)>
<#list pager.list as list>
<tr>
<td>${list.tempId!}</td>
<td>${list.name!}</td>
<td>${list.createdBy!}</td>
<td><#if list.createdTime??>${list.createdTime?datetime}</#if></td>
<td>
<div id="edit-div" class="am-btn-toolbar switch-button">
<div class="am-btn-group am-btn-group-xs">
<input id="${list.id}" type="checkbox" data-size='xs'
data-am-switch data-off-text="已禁用" data-on-text="已启用"
<#if list.enabled==1 >checked</#if>
/>
</div>
</div>
</td>
</tr>
</#list>
</#if>
</tbody>
</table>
</div>
<div class="am-cf">
<!-- 分页 -->
<#if (pager.list)?exists && (pager.list?size>0) >
<div class="am-fr">
<#include "../common/order_list_pager.ftl">
</div>
<#else>
<div class="am-kai" align="center">
<h3>没有找到任何记录!</h3>
</div>
</#if>
</div>
</div>
</div>
</div>
</@defaultLayout.layout>
<script src="${base}/assets/js/amazeui.switch.js"></script>
<script type="text/javascript">
var sub_function = function (type) {
initSearch();
if (type == 'export') {
$("#listForm").attr("action", "${base}/department/export");
} else {
$("#listForm").attr("action", "${base}/department/list");
}
$("#listForm").submit();
};
function initSearch() {
var keywordsObj = {};
if ($("#name").val())
keywordsObj.name = $("#name").val();
if ($("#type").val())
keywordsObj.type = $("#type").val();
if ($("#enabled").val())
keywordsObj.enabled = $("#enabled").val();
if ($("#startTime").val())
keywordsObj.startTime = $("#startTime").val();
if ($("#endTime").val())
keywordsObj.endTime = $("#endTime").val();
var keywords = "";
if (!$.isEmptyObject(keywordsObj)) {
keywords = JSON.stringify(keywordsObj);
}
console.log("keywords = " + keywords);
$("#keywords").val(keywords);
}
$(function () {
//为每个启用或禁用按钮增加事件
var $mycheckbox = $('.switch-button').find("input[type='checkbox']");
$mycheckbox.each(function () {
var myid = $(this).attr("id");
var prop = $(this).attr("prop");
$(this).on({
'switchChange.bootstrapSwitch': function (event, state) {
toggle(myid, state ? 1 : 0);
}
});
});
});
//启用或者禁用
var toggle = function (id, status) {
$.ajax({
url: "${base}/department/enableOrDisable",
data: {id: id, status: status},
type: "post",
dataType: "json",
async: false,
success: function (data) {
parent.layer.msg(data.msg);
}
});
};
</script>