Commit 504d7e2e authored by 赵啸非's avatar 赵啸非

修改新闻相关

parent 01ce88ac
......@@ -294,8 +294,16 @@ CREATE TABLE mortals_xhx_news(
`createTime` datetime NOT NULL COMMENT '创建时间',
`updateUserId` bigint(20) COMMENT '更新用户',
`updateTime` datetime COMMENT '更新时间',
`editor` varchar(64) NOT NULL COMMENT '责任编辑',
`shareNums` tinyint(4) NOT NULL DEFAULT '0' COMMENT '分享次数',
`deptId` bigint(20) COMMENT '发布部门',
`deptName` varchar(128) COMMENT '所属部门名称',
`statement` varchar(255) COMMENT '声明',
`source` varchar(255) COMMENT '文章来源',
`remark` varchar(255) COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='新闻';
-- ----------------------------
-- 新闻访问记录信息表
-- ----------------------------
......
......@@ -57,7 +57,7 @@ const router = new Router({
...restBuilder('news/category', 'news/category'),//新闻频道分类
...restBuilder("dept", "dept"), //部门
//以下为基础路由配置
builder('/', 'Home'),
builder('/home', 'Home'),
......
<template>
<!-- 弹出框表单 -->
<el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<el-col :span="22" v-if="form.parentId !== 0">
<el-form-item label="上级节点" prop="parentId">
<treeselect
v-model="form.parentId"
:options="deptOptions"
:normalizer="normalizer"
placeholder="选择上级部门信息"
/>
</el-form-item>
</el-col>
<Field :span="22" label="部门名称" prop="deptName" v-model="form.deptName" type="textarea" placeholder="请输入部门名称"/>
<Field :span="22" label="部门状态" prop="deptStatus" v-model="form.deptStatus" type="select" :enumData="dict.deptStatus" placeholder="请选择部门状态"/>
<Field :span="22" label="顺序" prop="orderNum" v-model="form.orderNum" placeholder="请输入顺序"/>
<Field :span="22" label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</template>
<script>
import form from "@/assets/mixins/formdialog";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
mixins: [form],
components: {
Treeselect,
},
data() {
return {
deptOptions: [],
// 遮罩层
loading: true,
// 弹出层标题
title: "部门信息",
// 是否显示弹出层
open: false,
toString:[
"deptStatus",
],
// 表单校验
rules: {
deptName: [
{required: true,message: "请输入部门名称", trigger: "blur" },
{max: 256,message: "最多只能录入256个字符",trigger: "blur",},
],
deptStatus: [
{required: true,message: "请输入部门状态", trigger: "blur" },
],
orderNum: [
{required: true,message: "请输入顺序", trigger: "blur" },
],
}
};
},
methods: {
/** 编辑 */
edit(row, deptOptions) {
this.reset()
this.query = { id: row.id };
this.urls.currUrl =this.pageInfo.editUrl;;
this.getData();
this.deptOptions = deptOptions;
this.title = "修改部门信息";
},
/** 新增 */
add(row, deptOptions) {
this.reset()
this.query = { id: row.id };
this.urls.currUrl = this.pageInfo.addUrl;
this.getData();
if(row.id){
this.form.parentId=row.id
}
this.deptOptions = deptOptions;
this.title = "新增部门信息";
},
/** 查看*/
view(row, deptOptions) {
this.query = { id: row.id };
this.urls.currUrl =this.pageInfo.viewUrl;;
this.getData();
this.deptOptions = deptOptions;
this.title = "部门信息详细";
},
/**取消按钮 */
cancel() {
this.open = false;
},
/**获取数据后弹框 */
afterRender(data) {
this.open = true;
},
afterSubmit(data) {
this.open = false;
this.$emit("ok");
},
/** 转换部门信息数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return {
id: node.id,
label: node.deptName,
children: node.children,
};
},
// 表单重置
reset() {
this.form = {
parentId : null,
ancestors : "",
deptName : "",
deptStatus : 1,
orderNum : 0,
remark : "",
};
this.resetForm("form");
},
resetForm(refName) {
if (this.$refs[refName]) {
this.$refs[refName].resetFields();
}
},
},
};
</script>
<template>
<!-- 弹出框表单 -->
<el-drawer
:title="title"
:visible.sync="open"
:direction="direction"
size="50%">
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<Field label="部门名称" prop="deptName" v-model="form.deptName" type="textarea" placeholder="请输入部门名称" :maxLength="15"/>
<Field label="上级部门" prop="parentId" v-model="form.parentId" type="select" :enumData="dict.deptName" placeholder="请选择上级部门"/>
<Field label="负责人" prop="workId" v-model="form.workId" type="select" :enumData="dict.workName" placeholder="请选择员工"/>
</el-row>
<form-buttons @submit='submitForm' noCancelBtn />
</el-form>
</el-drawer>
</template>
<script>
import form from "@/assets/mixins/formdialog";
export default {
name: "DeptDetail",
mixins: [form],
components: {
},
created() {
this.changePath("dept")
},
data() {
return {
// 遮罩层
loading: true,
// 弹出层标题
title: "部门信息",
// 是否显示弹出层
open: false,
direction:"rtl",
toString:[
"deptStatus",
],
toDate:[
],
// 表单校验
rules: {
deptName: [
{required: true,message: "请输入部门名称", trigger: "blur" },
{max: 15,message: "最多只能录入15个字符",trigger: "blur",},
],
parentId: [
{required: true,message: "请输入部门", trigger: "change" },
]
}
};
},
methods: {
/** 编辑 */
edit(row) {
this.reset()
this.query = { id: row.id };
this.urls.currUrl ="dept/edit";
this.getData();
this.pageInfo.type="edit"
this.title = "修改部门信息";
},
/** 新增 */
add(row) {
this.reset()
this.urls.currUrl = "dept/add";
this.getData();
this.pageInfo.type="add"
this.title = "新增部门信息";
},
/** 查看*/
view(row) {
this.reset()
this.query = { id: row.id };
this.urls.currUrl ="dept/view";
this.getData();
this.pageInfo.type="view"
this.title = "部门信息详细";
},
/**取消按钮 */
cancel() {
this.open = false;
},
/**获取数据后弹框 */
afterRender(data) {
this.form.parentId = this.form.parentId.toString()
this.open = true;
},
afterSubmit(data) {
this.open = false;
this.$emit("ok");
},
// 表单重置
reset() {
this.form = {
parentId : null,
ancestors : "",
deptName : "",
deptStatus : 1,
orderNum : 0,
remark : "",
};
this.resetForm("form");
},
resetForm(refName) {
if (this.$refs[refName]) {
this.$refs[refName].resetFields();
}
},
},
};
</script>
<template>
<div className="page">
<el-card style="height:80vh;overflow:scroll-y">
<LayoutTable notPagination :data="tableData" ref="layoutTable" :config="tableConfig" notSearch></LayoutTable>
</el-card>
<drawer-show ref="drawerform" @ok="getData" />
</div>
</template>
<script>
/** 表单弹出框模式需引入 */
import {handleTree} from "@/assets/utils/table";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import drawerShow from "./drawershow";
import table from "@/assets/mixins/table";
export default {
name: "DeptList",
components: {
drawerShow,
Treeselect
},
mixins: [table],
created() {
this.query={"page":1,"size":-1}
},
methods: {
/** 重写新增方法 */
toAdd(row) {
this.$refs.drawerform.add(row,this.menuOptions);
},
/** 重写编辑方法 */
toEdit(row) {
this.$refs.drawerform.edit(row,this.menuOptions);
},
/** 重写查看方法 */
toView(row) {
this.$refs.drawerform.view(row, this.menuOptions);
},
afterRender(data) {
data.data = handleTree(data.data, "id", "parentId");
console.log("tree data:",data.data)
this.menuOptions = data.data;
this.$refs.layoutTable.showType = "treetable"
},
},
data() {
return {
config: {
showType:'treetable',
isshowTabPane:true,
/** 树表是否默认展开 */
expand: false,
columns: [
{type: "selection", width: 60},
{label: "部门名称", prop: "deptName"},
{label: "成员数量", prop: "personNum"},
{label: "负责人", prop: "workName"},
// {label: "部门状态", prop: "deptStatus",formatter: this.formatter},
// {label: "顺序", prop: "orderNum",formatter: this.formatter},
// {label: "创建用户", prop: "createUserId", formatter: this.formatter},
{
label: "操作",
width: 240,
formatter: row => {
return (
<table-buttons noAdd noView row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
)
}
}
]
}
};
}
};
</script>
\ No newline at end of file
<template>
<layout-view>
<el-descriptions :title="title" :column="column" :size="size" :colon="false" border>
<template slot="title">
<i class="el-icon-tickets"></i>
基本详细信息
</template>
<template slot="extra">
<el-button type="primary" @click="$router.go(-1)" size="small">返回</el-button>
</template>
<el-descriptions-item label="父id" label-class-name="labelClass" content-class-name="contentClass">
{{form.parentId}}
</el-descriptions-item>
<el-descriptions-item label="祖级列表" label-class-name="labelClass" content-class-name="contentClass">
{{form.ancestors}}
</el-descriptions-item>
<el-descriptions-item label="部门名称" label-class-name="labelClass" content-class-name="contentClass">
{{form.deptName}}
</el-descriptions-item>
<el-descriptions-item label="部门状态" label-class-name="labelClass" content-class-name="contentClass">
{{ util_formatters("deptStatus", form.deptStatus) }}
</el-descriptions-item>
<el-descriptions-item label="顺序" label-class-name="labelClass" content-class-name="contentClass">
{{form.orderNum}}
</el-descriptions-item>
<el-descriptions-item label="备注" label-class-name="labelClass" content-class-name="contentClass">
{{form.remark}}
</el-descriptions-item>
</el-descriptions>
</layout-view>
</template>
<script>
import view from "@/assets/mixins/view";
export default {
mixins: [view],
components: {
},
methods: {
},
data() {
return {
size:"small",
column:2,
toString:[
"deptStatus",
],
toArrays: [
],
toDate: [
]
}
}
}
</script>
<style lang="less">
.labelClass{
width: 200px;
}
.el-descriptions__body{
margin-left: 5px;
margin-right: 5px;
color: #606266;
background-color: #FFF;
}
.contentClass{
width: 600px;
}
</style>
\ No newline at end of file
......@@ -8,8 +8,8 @@
size="50%">
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<Field label="频道名称" prop="name" v-model="form.name" placeholder="请输入频道名称"/>
<Field label="备注" prop="remark" v-model="form.remark" placeholder="请输入备注"/>
<Field :span="20" label="频道名称" prop="name" v-model="form.name" placeholder="请输入频道名称"/>
<Field :span="20" label="备注" prop="remark" type="textarea" v-model="form.remark" placeholder="请输入备注"/>
</el-row>
......
......@@ -8,14 +8,18 @@
size="50%">
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<Field label="分类id" prop="categoryId" v-model="form.categoryId" placeholder="请输入分类id"/>
<Field label="分类名称" prop="categoryName" v-model="form.categoryName" placeholder="请输入分类名称"/>
<Field label="标题" prop="title" v-model="form.title" type="textarea" placeholder="请输入标题"/>
<Field label="标题logo"><imageUpload v-model="form.titleLogoPath" prePath="/file/preview"/></Field>
<Field label="内容"><editor v-model="form.content" :min-height="256"/></Field>
<Field label="置顶 " prop="top" v-model="form.top" type="select" :enumData="dict.top" placeholder="请选择置顶 "/>
<Field label="浏览次数" prop="viewNums" v-model="form.viewNums" type="select" :enumData="dict.viewNums" placeholder="请选择浏览次数"/>
<Field label="发布时间" prop="publishTime" v-model="form.publishTime" type="date" />
<Field label="类型" :span="20" prop="categoryId" v-model="form.categoryId" type="radio" :enum-data="dict.categoryId" placeholder="请输入分类id"/>
<Field :span="20" label="封面"><imageUpload v-model="form.titleLogoPath" prePath="/file/preview"/></Field>
<Field label="标题" :span="20" prop="title" v-model="form.title" placeholder="请输入标题"/>
<Field :span="20" label="内容"><editor v-model="form.content" :min-height="256"/></Field>
<Field :span="20" label="责任编辑" prop="editor" v-model="form.editor" placeholder="请输入责任编辑"/>
<Field :span="20" label="发布部门" prop="deptId" v-model="form.deptId" placeholder="请输入发布部门"/>
<Field :span="20" label="文章来源" prop="source" v-model="form.source" type="textarea" placeholder="请输入文章来源"/>
<Field :span="20" label="声明" prop="statement" v-model="form.statement" type="textarea" placeholder="请输入声明"/>
</el-row>
......
......@@ -34,6 +34,20 @@
this.$refs.drawerform.view(row);
},
handTop(row,top) {
this.$post("/news/save",{id:row.id,top:top}).then((res) => {
if (res.code == 1) {
this.$message.success("置顶成功!");
this.getData();
}
})
.catch((error) => {
this.$message.error(error.message);
});
},
},
data() {
return {
......@@ -44,17 +58,18 @@
{type: "selection", width: 60},
{type: "index",label: "序号",width: 50},
{label: "分类名称", prop: "categoryName"},
{label: "标题", prop: "title"},
{label: "标题logo", prop: "titleLogoPath"},
{label: "新闻类型", prop: "categoryId",formatter: this.formatter},
{label: "内容", prop: "content"},
{label: "创建时间", prop: "createDateTime", formatter: this.formatterDate},
{label: "置顶 ", prop: "top",formatter: this.formatter},
{label: "数据",formatter: row => {
let bool=false;
return (
<div><el-link underline={bool} type="primary">浏览({row.viewNums})</el-link></div>
);}},
{label: "浏览次数", prop: "viewNums",formatter: this.formatter},
{label: "创建用户", prop: "createUserId", formatter: this.formatter},
{
......@@ -62,7 +77,41 @@
width: 240,
formatter: row => {
return (
<table-buttons noAdd row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
<div>
{row.top === 0 ? (
<el-button
size="mini"
type="text"
icon="el-icon-open"
onClick={() => {
this.handTop(row,1);
}}
>
置顶
</el-button>
) : (
<el-button
size="mini"
type="text"
icon="el-icon-open"
onClick={() => {
this.handTop(row,0);
}}
>
取消置顶
</el-button>
)}
<span> </span>
<table-buttons
noAdd
row={row}
onEdit={this.toEdit}
onView={this.toView}
onDel={this.toDel}
/>
</div>
);
}
}
......
......@@ -4,12 +4,12 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* 启用状态 (0.停止,1.启用)枚举类
*
* @author zxfei
*/
* 启用状态 (0.停止,1.启用)枚举类
*
* @author zxfei
*/
public enum EnabledEnum {
(0, "停止"),
(0, "停用"),
启用(1, "启用");
private Integer value;
private String desc;
......
package com.mortals.xhx.module.dept.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.dept.model.DeptEntity;
import java.util.List;
/**
* 部门信息Dao
* 部门信息 DAO接口
*
* @author zxfei
* @date 2023-03-06
*/
public interface DeptDao extends ICRUDDao<DeptEntity,Long>{
/**
* 查询子节点
*
* @param
* @return
*/
List<DeptEntity> selectChildrenDeptById(String deptId);
/**
* 查询所有数据
* */
List<DeptEntity> queryAllList();
/**
* 查询部门信息
* */
DeptEntity queryDept(String deptCode);
/**
* 查询是否作为上级本门
* */
DeptEntity queryDeptParient(String parentCode);
/**
* 查询包含本部门所有下级部门
* */
List<DeptEntity> getAllChildrenDept(Long deptId);
}
package com.mortals.xhx.module.dept.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.xhx.module.dept.dao.DeptDao;
import com.mortals.xhx.module.dept.model.DeptEntity;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 部门信息DaoImpl DAO接口
*
* @author zxfei
* @date 2023-03-06
*/
@Repository("deptDao")
public class DeptDaoImpl extends BaseCRUDDaoMybatis<DeptEntity,Long> implements DeptDao {
@Override
public List<DeptEntity> selectChildrenDeptById(String deptId) {
return getSqlSession().selectList(getSqlId("selectChildrenDeptById"), deptId);
}
@Override
public List<DeptEntity> queryAllList() {
return this.getList(new DeptEntity());
}
@Override
public DeptEntity queryDept(String deptCode) {
return getSqlSession().selectOne(getSqlId("queryDept"),deptCode);
}
@Override
public DeptEntity queryDeptParient(String parentCode) {
return getSqlSession().selectOne(getSqlId("queryDeptParient"),parentCode);
}
@Override
public List<DeptEntity> getAllChildrenDept(Long deptId) {
return getSqlSession().selectList(getSqlId("getAllChildrenDept"), deptId);
}
}
package com.mortals.xhx.module.dept.model;
import com.mortals.xhx.module.dept.model.vo.DeptVo;
import lombok.Data;
import java.math.BigDecimal;
/**
* 部门信息实体对象
*
* @author zxfei
* @date 2023-05-16
*/
@Data
public class DeptEntity extends DeptVo {
private static final long serialVersionUID = 1L;
/**
* 父id
*/
private Long parentId;
/**
* 祖级列表
*/
private String ancestors;
/**
* 部门名称
*/
private String deptName;
/**
* 部门编码
*/
private String deptCode;
/**
* 部门状态(0.停用,1.启用)
*/
private Integer deptStatus;
/**
* 顺序
*/
private Integer orderNum;
/**
* 部门人数
*/
private Integer personNum;
/**
* 负责人id
*/
private Long workId;
/**
* 负责人名称
*/
private String workName;
/**
* 备注
*/
private String remark;
/**
* 绩效分数
*/
private BigDecimal score;
@Override
public int hashCode() {
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof DeptEntity) {
DeptEntity tmp = (DeptEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
}
}
return false;
}
public void initAttrValue(){
this.parentId = -1L;
this.ancestors = "";
this.deptName = "";
this.deptCode = "";
this.deptStatus = 1;
this.orderNum = 0;
this.personNum = 0;
this.workId = -1L;
this.workName = "";
this.remark = "";
this.score = new BigDecimal(0);
}
}
\ No newline at end of file
package com.mortals.xhx.module.dept.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.util.ObjectUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 部门信息前端映射树结构实体类
*
* @author zxfei
* @date 2023-03-06
*/
@Data
public class DeptTreeSelect implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 节点ID
*/
private Long id;
/**
* 节点名称
*/
private String label;
private Integer personNum;
/**
* 子节点
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<DeptTreeSelect> children;
/**
* 子节点
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<Map<String, Object>> personList;
public DeptTreeSelect(DeptEntity entity) {
this.id = entity.getId();
this.label = entity.getDeptName();
this.personNum = entity.getPersonNum();
if (!ObjectUtils.isEmpty(entity.getChildren())) {
this.children = entity.getChildren().stream().map(DeptTreeSelect::new).collect(Collectors.toList());
}
this.personList = entity.getPersonList();
}
}
package com.mortals.xhx.module.dept.model.vo;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.dept.model.DeptEntity;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 部门信息视图对象
*
* @author zxfei
* @date 2023-03-06
*/
@Data
public class DeptVo extends BaseEntityLong {
/** 子部门信息 */
private List<DeptEntity> children = new ArrayList<>();
/** 子节点人员信息 */
private List<Map<String,Object>> personList = new ArrayList<>();
//成员数量
}
package com.mortals.xhx.module.dept.service;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.dept.dao.DeptDao;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptTreeSelect;
import java.util.List;
/**
* DeptService
* <p>
* 部门信息 service接口
*
* @author zxfei
* @date 2023-03-06
*/
public interface DeptService extends ICRUDService<DeptEntity, Long> {
DeptDao getDao();
/**
* 是否存在部门信息节点
*
* @param deptId 部门信息ID
* @return 结果
*/
boolean hasChildByDeptId(Long deptId);
/**
* 查询部门信息数据
*
* @param dept 部门信息
* @return 部门信息集合
*/
List<DeptEntity> selectDeptList(DeptEntity dept);
/**
* 构建前端所需要下拉树结构
*
* @param deptList 部门信息列表
* @return 下拉树结构列表
*/
List<DeptTreeSelect> buildDeptTreeSelect(List<DeptEntity> deptList);
/**
* 根据父id查询子节点
*
* @param parentId
* @param context
* @return
*/
List<DeptTreeSelect> getListByParentId(Long parentId, Context context);
/**
* 更新部门人员数量
*
* @param context
*/
Rest<Void> updateDeptNum(Context context);
/**
* 查询包含本部门所有下级部门
* */
List<DeptEntity> getAllChildrenDept(Long deptId) throws AppException;
}
\ No newline at end of file
package com.mortals.xhx.module.dept.service.impl;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.common.code.EnabledEnum;
import com.mortals.xhx.module.dept.dao.DeptDao;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.model.DeptTreeSelect;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffQuery;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* DeptService
* 部门信息 service实现
*
* @author zxfei
* @date 2023-03-06
*/
@Service("deptService")
@Slf4j
public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity, Long> implements DeptService {
@Autowired
private StaffService staffService;
@Override
protected void saveBefore(DeptEntity entity, Context context) throws AppException {
if (ObjectUtils.isEmpty(entity.getParentId())) {
//如果父节点为空,默认挂载到根目录
entity.setParentId(0L);
}
DeptEntity parentDeptEntity = this.get(entity.getParentId());
if (!ObjectUtils.isEmpty(parentDeptEntity) && EnabledEnum.停用.getValue() == parentDeptEntity.getDeptStatus()) {
throw new AppException("部门信息停用,不允许新增");
}
if (!ObjectUtils.isEmpty(parentDeptEntity)) {
entity.setAncestors(parentDeptEntity.getAncestors() + "," + entity.getParentId());
}
super.saveBefore(entity, context);
}
@Override
protected void updateBefore(DeptEntity entity, Context context) throws AppException {
DeptEntity newParentEntity = this.get(entity.getParentId());
DeptEntity oldEntity = this.get(entity.getId());
if (!ObjectUtils.isEmpty(newParentEntity) && !ObjectUtils.isEmpty(oldEntity)) {
String newAncestors = newParentEntity.getAncestors() + "," + entity.getId();
String oldAncestors = oldEntity.getAncestors();
entity.setAncestors(newAncestors);
updateDeptChildren(entity.getId(), newAncestors, oldAncestors, context);
}
super.updateBefore(entity, context);
}
@Override
protected void updateAfter(DeptEntity entity, Context context) throws AppException {
if (EnabledEnum.启用.getValue() == entity.getDeptStatus()) {
updateParentDeptStatus(entity, context);
}
super.updateAfter(entity, context);
}
/**
* 修改该部门信息的父级部门信息状态
*
* @param dept 当前部门信息
*/
private void updateParentDeptStatus(DeptEntity dept, Context context) {
DeptEntity deptEntity = this.get(dept.getParentId());
if (!ObjectUtils.isEmpty(deptEntity)) {
deptEntity.setDeptStatus(EnabledEnum.启用.getValue());
deptEntity.setUpdateTime(new Date());
deptEntity.setUpdateUser(context == null ? "admin" : context.getUser().getLoginName());
DeptEntity condition = new DeptEntity();
condition.setId(deptEntity.getId());
this.updateBatch(deptEntity, condition, context);
}
}
/**
* 修改子元素关系
*
* @param deptId 被修改的部门信息ID
* @param newAncestors 新的父ID集合
* @param oldAncestors 旧的父ID集合
*/
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors, Context context) {
List<DeptEntity> children = getDao().selectChildrenDeptById(deptId.toString());
for (DeptEntity child : children) {
child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
}
if (children.size() > 0) {
this.updateAfter(children, context);
}
}
@Override
protected void removeBefore(Long[] ids, Context context) throws AppException {
//有子节点 禁止删除
if (hasChildByDeptId(ids[0])) {
throw new AppException("存在下级部门信息,不允许删除");
}
super.removeBefore(ids, context);
}
@Override
public boolean hasChildByDeptId(Long deptId) {
List<DeptEntity> list = this.find(new DeptQuery().parentId(deptId));
return list.size() > 0 ? true : false;
}
@Override
public List<DeptEntity> selectDeptList(DeptEntity dept) {
return this.find(new DeptQuery());
}
@Override
public List<DeptTreeSelect> buildDeptTreeSelect(List<DeptEntity> list) {
for (Iterator<DeptEntity> iterator = list.iterator(); iterator.hasNext(); ) {
DeptEntity deptEntity = iterator.next();
StaffQuery staffQuery = new StaffQuery();
List<StaffEntity> staffEntities = staffService.find(staffQuery);
List<Map<String, Object>> personList = new ArrayList<>();
staffEntities.forEach(item -> {
Map<String, Object> map = new HashMap<>();
map.put("staffId", item.getId());
map.put("staffName", item.getName());
// map.put("deptId", item.getDeptId());
personList.add(map);
});
deptEntity.setPersonList(personList);
}
//获取父节点
List<DeptEntity> returnList = list.stream().filter(t -> t.getParentId() == 0).map(
m -> {
m.setChildren(getChildren(m, list));
StaffEntity query = new StaffQuery();
// query.setDeptIdList(getChildrenId(m, list));
int count = staffService.count(query,null);
m.setPersonNum(count);
return m;
}
).collect(Collectors.toList());
return returnList.stream().map(DeptTreeSelect::new).collect(Collectors.toList());
}
/**
* 递归查询子节点
* @param root 根节点
* @param all 所有节点
* @return 根节点信息
*/
private List<DeptEntity> getChildren(DeptEntity root, List<DeptEntity> all) {
List<DeptEntity> children = all.stream().filter(t -> {
return Objects.equals(t.getParentId(), root.getId());
}).map(
m -> {
m.setChildren(getChildren(m, all));
StaffQuery query = new StaffQuery();
// query.setDeptIdList(getChildrenId(m, all));
// query.setStatusNotList(Arrays.asList(StaffSatusEnum.离职.getValue()));
int count = staffService.count(query,null);
m.setPersonNum(count);
return m;
}
).collect(Collectors.toList());
return children;
}
private List<Long> getChildrenId(DeptEntity root, List<DeptEntity> all){
List<Long> idList = new ArrayList<>();
idList.add(root.getId());
all.forEach(item ->{
if(Objects.equals(item.getParentId(), root.getId())){
idList.addAll(getChildrenId(item,all));
}
});
return idList;
}
@Override
public List<DeptTreeSelect> getListByParentId(Long parentId, Context context) {
if (ObjectUtils.isEmpty(parentId)) {
parentId = 0L;
}
//只做一层
List<DeptTreeSelect> collect = this.find(new DeptQuery().parentId(parentId), context).stream().map(item -> new DeptTreeSelect(item)
).collect(Collectors.toList());
if ("0".equals(parentId)) {
return collect;
}
return collect;
}
@Override
public Rest<Void> updateDeptNum(Context context) {
log.info("更新部门用户数量");
return Rest.ok();
}
@Override
public List<DeptEntity> getAllChildrenDept(Long deptId) throws AppException {
return dao.getAllChildrenDept(deptId);
}
}
package com.mortals.xhx.module.dept.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.model.DeptTreeSelect;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.staff.service.StaffService;
import com.mortals.xhx.module.workman.model.WorkmanQuery;
import com.mortals.xhx.module.workman.service.WorkmanService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.mortals.framework.ap.SysConstains.RESULT_KEY;
/**
* 部门信息
*
* @author zxfei
* @date 2023-03-06
*/
@RestController
@RequestMapping("dept")
public class DeptController extends BaseCRUDJsonBodyMappingController<DeptService, DeptEntity, Long> {
@Autowired
private ParamService paramService;
@Autowired
private DeptService deptService;
@Autowired
private WorkmanService workmanService;
@Autowired
private StaffService staffService;
public DeptController() {
super.setModuleDesc("部门信息");
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "deptStatus", paramService.getParamBySecondOrganize("Dept", "deptStatus"));
this.addDict(model, "deptName", deptService.find(new DeptQuery()).stream().collect(Collectors.toMap(x->x.getId().toString(), y->y.getDeptName(),(o, n)->n)));
this.addDict(model, "workName", workmanService.find(new WorkmanQuery()).stream().collect(Collectors.toMap(x->x.getId().toString(), y->y.getName(),(o, n)->n)));
super.init(model, context);
}
@PostMapping("list/exclude")
public String excludeList(@RequestParam(name = "id") Long id) {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "查询" + this.getModuleDesc();
// Long id = form.getId()[0];
int code = VALUE_RESULT_SUCCESS;
try {
List<DeptEntity> collect = this.service.find(new DeptQuery()).stream().map(item -> {
if (item.getId().intValue() == id || ArrayUtils.contains(StringUtils.split(item.getAncestors(), ","), id + "")) {
return null;
}
return item;
}).filter(f -> f != null).collect(Collectors.toList());
model.put("result", collect);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/**
* 获取站点下拉树列表
*/
@PostMapping("treeselect")
public String treeselect() {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "查询" + this.getModuleDesc();
int code = VALUE_RESULT_SUCCESS;
try {
DeptQuery deptQuery = new DeptQuery();
deptQuery.setOrderColList(Arrays.asList(new OrderCol("deptName")));
List<DeptEntity> list = this.service.find(deptQuery);
List<DeptTreeSelect> treeSelects = this.service.buildDeptTreeSelect(list);
model.put("result", treeSelects);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/**
* 根据parentId查询子信息
*/
@GetMapping(value = "getListByParentId")
public String getListByParentId(Long parentId) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc() + "子节点";
try {
List<DeptTreeSelect> treeList = this.service.getListByParentId(parentId, getContext());
model.put(RESULT_KEY, treeList);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_DATA, model);
recordSysLog(request, busiDesc + "【成功】");
} catch (Exception e) {
log.error("根据parentId查询子信息错误", e);
this.doException(request, busiDesc, model, e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
return ret.toJSONString();
}
@Override
protected int doListAfter(DeptEntity query, Map<String, Object> model, Context context) throws AppException {
int allPerson =staffService.queryAllPerson();
model.put("allPerson",allPerson);
return super.doListAfter(query, model, context);
}
}
\ No newline at end of file
......@@ -11,11 +11,11 @@ import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.news.model.vo.NewsVo;
import lombok.Data;
/**
* 新闻实体对象
*
* @author zxfei
* @date 2023-09-18
*/
* 新闻实体对象
*
* @author zxfei
* @date 2023-09-28
*/
@Data
public class NewsEntity extends NewsVo {
private static final long serialVersionUID = 1L;
......@@ -52,6 +52,34 @@ public class NewsEntity extends NewsVo {
* 发布时间
*/
private Date publishTime;
/**
* 责任编辑
*/
private String editor;
/**
* 分享次数
*/
private Integer shareNums;
/**
* 发布部门
*/
private Long deptId;
/**
* 所属部门名称
*/
private String deptName;
/**
* 声明
*/
private String statement;
/**
* 文章来源
*/
private String source;
/**
* 备注
*/
private String remark;
@Override
public int hashCode() {
return this.getId().hashCode();
......@@ -69,13 +97,20 @@ public class NewsEntity extends NewsVo {
}
public void initAttrValue(){
this.categoryId = 0L;
this.categoryId = null;
this.categoryName = "";
this.title = "";
this.titleLogoPath = "";
this.content = "";
this.top = 0;
this.viewNums = 0;
this.publishTime = new Date();
this.publishTime =null;
this.editor = "";
this.shareNums = 0;
this.deptId = null;
this.deptName = "";
this.statement = "";
this.source = "";
this.remark = "";
}
}
\ No newline at end of file
......@@ -19,5 +19,10 @@ public class NewsVo extends BaseEntityLong {
/** 主键ID,主键,自增长列表 */
private List <Long> idList;
/**
* 分享次数
*/
private Integer shareNums;
}
\ No newline at end of file
package com.mortals.xhx.module.news.web;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.news.model.NewsCategoryEntity;
import com.mortals.xhx.module.news.model.NewsCategoryQuery;
import com.mortals.xhx.module.news.service.NewsCategoryService;
import org.apache.commons.lang3.ObjectUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.news.model.NewsEntity;
import com.mortals.xhx.module.news.service.NewsService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
*
* 新闻
*
* @author zxfei
* @date 2023-09-18
*/
* 新闻
*
* @author zxfei
* @date 2023-09-18
*/
@RestController
@RequestMapping("news")
public class NewsController extends BaseCRUDJsonBodyMappingController<NewsService,NewsEntity,Long> {
public class NewsController extends BaseCRUDJsonBodyMappingController<NewsService, NewsEntity, Long> {
@Autowired
private ParamService paramService;
@Autowired
private NewsCategoryService newsCategoryService;
@Autowired
private DeptService deptService;
public NewsController(){
super.setModuleDesc( "新闻");
public NewsController() {
super.setModuleDesc("新闻");
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "top", paramService.getParamBySecondOrganize("News","top"));
this.addDict(model, "viewNums", paramService.getParamBySecondOrganize("News","viewNums"));
this.addDict(model, "top", paramService.getParamBySecondOrganize("News", "top"));
this.addDict(model, "viewNums", paramService.getParamBySecondOrganize("News", "viewNums"));
this.addDict(model, "categoryId", newsCategoryService.find(new NewsCategoryQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getName(), (o, n) -> n)));
this.addDict(model, "deptId", deptService.find(new DeptQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getDeptName(), (o, n) -> n)));
super.init(model, context);
}
@Override
protected void saveBefore(NewsEntity entity, Map<String, Object> model, Context context) throws AppException {
if (!ObjectUtils.isEmpty(entity.getCategoryId())) {
NewsCategoryEntity newsCategoryEntity = newsCategoryService.get(entity.getCategoryId(), context);
entity.setCategoryName(newsCategoryEntity.getName());
}
if (!ObjectUtils.isEmpty(entity.getDeptId())) {
DeptEntity deptEntity = deptService.get(entity.getDeptId(), context);
entity.setDeptName(deptEntity.getDeptName());
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.dept.dao.ibatis.DeptDaoImpl">
<select id="queryDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
select * from mortals_xhx_dept where deptCode = #{deptCode}
</select>
<select id="queryDeptParient" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
select * from mortals_xhx_dept where deptCode = #{parentCode}
</select>
<select id="queryDeptParentId" resultType="integer">
select parentId from mortals_xhx_dept where deptId = #{deptId}
</select>
<!--查询所有子部门-->
<select id="getAllChildrenDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
SELECT T3.id,T3.parentId, T3.deptName,T3.deptCode,T3.deptStatus
FROM(
SELECT
@codes as _ids,
( SELECT @codes := GROUP_CONCAT(id)
FROM mortals_xhx_dept
WHERE FIND_IN_SET(parentId, @codes)
) as T1,
@l := @l+1 as level_
FROM mortals_xhx_dept, (SELECT @codes := #{deptId}, @l := 0 ) T4
WHERE @codes IS NOT NULL
) T2, mortals_xhx_dept T3
WHERE FIND_IN_SET(T3.parentId, T2._ids)
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.dept.dao.ibatis.DeptPerformStatDaoImpl">
<!-- 按天top10 -->
<select id="getDaySummaryList" parameterType="com.mortals.xhx.module.dept.model.vo.DeptSummaryTopQuery" resultType="com.mortals.xhx.module.dept.model.DeptPerformStatEntity">
SELECT * FROM (
SELECT
`year`,
`month`,
`day`,
deptId,
deptName,
SUM(totalScore) AS totalScore
FROM
mortals_xhx_dept_perform_stat
WHERE 1=1
<if test="year != null">
AND `year` = #{year}
</if>
<if test="month != null">
AND `month` = #{month}
</if>
<if test="day != null">
AND `day` = #{day}
</if>
GROUP BY
deptId,
deptName,
`year`,
`month`,
`day`
) AS a ORDER BY totalScore DESC LIMIT 10
</select>
<!-- 按月top10 -->
<select id="getMonthSummaryList" parameterType="com.mortals.xhx.module.dept.model.vo.DeptSummaryTopQuery" resultType="com.mortals.xhx.module.dept.model.DeptPerformStatEntity">
SELECT * FROM (
SELECT
`year`,
`month`,
deptId,
deptName,
SUM(totalScore) AS totalScore
FROM
mortals_xhx_dept_perform_stat
WHERE 1=1
<if test="year != null">
AND `year` = #{year}
</if>
<if test="month != null">
AND `month` = #{month}
</if>
GROUP BY
deptId,
deptName,
`year`,
`month`
) AS a ORDER BY totalScore DESC LIMIT 10
</select>
<!-- 按年top10 -->
<select id="getYearSummaryList" parameterType="com.mortals.xhx.module.dept.model.vo.DeptSummaryTopQuery" resultType="com.mortals.xhx.module.dept.model.DeptPerformStatEntity">
SELECT * FROM (
SELECT
`year`,
deptId,
deptName,
SUM(totalScore) AS totalScore
FROM
mortals_xhx_dept_perform_stat
WHERE 1=1
<if test="year != null">
AND `year` = #{year}
</if>
<if test="month != null">
AND `month` = #{month}
</if>
<if test="day != null">
AND `day` = #{day}
</if>
GROUP BY
deptId,
deptName,
`year`
) AS a ORDER BY totalScore DESC LIMIT 10
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment