提交 72ab2bb8 编写于 作者: X xiongchun

代码优化

上级 0e029c6c
package com.pulanit.pangu.admin.system.api.param;
import com.gitee.pulanos.pangu.framework.common.model.MyPage;
import com.gitee.pulanos.pangu.framework.common.model.Page;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 角色查询入参
* @author xiongchun
*/
@Data
@Accessors(chain = true)
public class RoleIn extends MyPage implements Serializable {
private static final long serialVersionUID = 1L;
public class RoleIn extends Page {
/**
* 角色名称
......
package com.pulanit.pangu.admin.system.api.service;
import com.gitee.pulanos.pangu.framework.common.model.MyPage;
import com.gitee.pulanos.pangu.framework.common.model.PageResult;
import com.pulanit.pangu.admin.system.api.entity.RoleEntity;
import com.pulanit.pangu.admin.system.api.param.RoleIn;
......@@ -19,7 +18,7 @@ public interface RoleService {
* @param roleIn
* @return
*/
MyPage<RoleEntity> list(RoleIn roleIn);
PageResult<RoleEntity> list(RoleIn roleIn);
/**
* 新增
......
package com.pulanit.pangu.admin.system.api.service;
import com.gitee.pulanos.pangu.framework.common.model.MyPage;
import com.gitee.pulanos.pangu.framework.common.model.PageResult;
import com.pulanit.pangu.admin.system.api.entity.UserEntity;
import com.pulanit.pangu.admin.system.api.param.LoginIn;
import com.pulanit.pangu.admin.system.api.param.LoginOut;
......@@ -21,7 +21,7 @@ public interface UserService {
* @param userIn
* @return
*/
MyPage<UserEntity> list(UserIn userIn);
PageResult<UserEntity> list(UserIn userIn);
/**
* 新增
......
package com.pulanit.pangu.admin.system.service;
import com.gitee.pulanos.pangu.framework.common.model.MyPage;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gitee.pulanos.pangu.framework.common.model.PageResult;
import com.gitee.pulanos.pangu.framework.common.utils.PagingUtil;
import com.pulanit.pangu.admin.system.api.entity.RoleEntity;
import com.pulanit.pangu.admin.system.api.param.RoleIn;
import com.pulanit.pangu.admin.system.api.service.RoleService;
......@@ -19,28 +25,32 @@ public class RoleServiceImpl implements RoleService {
private RoleMapper roleMapper;
@Override
public MyPage<RoleEntity> list(RoleIn roleIn) {
return null;
public PageResult<RoleEntity> list(RoleIn roleIn) {
Page<RoleEntity> page = PagingUtil.createPage(roleIn);
LambdaQueryWrapper<RoleEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.like(ObjectUtil.isNotEmpty(roleIn.getName()), RoleEntity::getName, roleIn.getName());
roleMapper.selectPage(page, lambdaQueryWrapper);
return PagingUtil.getPageResult(page);
}
@Override
public void add(RoleEntity roleEntity) {
roleEntity.setGmtCreated(DateUtil.date());
roleMapper.insert(roleEntity);
}
@Override
public void update(RoleEntity roleEntity) {
roleEntity.setGmtModified(DateUtil.date());
}
@Override
public void delete(Long id) {
roleMapper.deleteById(id);
}
@Override
public void batchDelete(List<Long> ids) {
roleMapper.deleteBatchIds(ids);
}
}
......@@ -18,7 +18,7 @@
package com.pulanit.pangu.admin.system.service;
import cn.hutool.core.lang.UUID;
import com.gitee.pulanos.pangu.framework.common.model.MyPage;
import com.gitee.pulanos.pangu.framework.common.model.PageResult;
import com.pulanit.pangu.admin.system.api.dto.UserDto;
import com.pulanit.pangu.admin.system.api.entity.UserEntity;
import com.pulanit.pangu.admin.system.api.param.LoginIn;
......@@ -46,7 +46,7 @@ public class UserServiceImpl implements UserService {
}
@Override
public MyPage<UserEntity> list(UserIn userIn) {
public PageResult<UserEntity> list(UserIn userIn) {
return null;
}
......
package com.pulanit.pangu.admin.web.system;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.CharsetUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cn.hutool.core.lang.Assert;
import com.gitee.pulanos.pangu.framework.common.model.PageResult;
import com.gitee.pulanos.pangu.framework.common.model.Result;
import com.pulanit.pangu.admin.system.api.entity.RoleEntity;
import com.pulanit.pangu.admin.system.api.param.RoleIn;
import com.pulanit.pangu.admin.system.api.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 角色
......@@ -22,15 +22,70 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/api/system/role")
public class RoleController {
@Reference(version = "1.0.0", group = "pangu-admin-system-app")
private RoleService roleService;
/**
* 获取角色
* @return
*/
@GetMapping("/list")
public Result<JSONObject> list() {
String roles = ResourceUtil.readStr("json/role.json", CharsetUtil.CHARSET_UTF_8);
JSONObject jsonObject = JSON.parseObject(roles);
return Result.success(jsonObject);
public Result<PageResult<RoleEntity>> list(RoleIn roleIn) {
PageResult<RoleEntity> pageResult = roleService.list(roleIn);
return Result.success(pageResult);
}
/**
* 新增
*
* @param roleEntity
* @return
*/
@PostMapping("/add")
public Result<Void> add(@RequestBody RoleEntity roleEntity) {
roleService.add(roleEntity);
return Result.success();
}
/**
* 修改
*
* @param roleEntity
* @return
*/
@PostMapping("/update")
public Result<Void> update(@RequestBody RoleEntity roleEntity) {
Assert.notNull(roleEntity.getId(), "部门 ID 不能为空");
roleService.update(roleEntity);
return Result.success();
}
/**
* 删除
*
* @param id
* @return
*/
@PostMapping("/delete")
public Result<Void> delete(@RequestParam Long id) {
Assert.notNull(id, "角色 ID 不能为空");
roleService.delete(id);
return Result.success();
}
/**
* 批量删除
*
* @param ids
* @return
*/
@PostMapping("/batchDelete")
public Result<Void> batchDelete(@RequestParam List<Long> ids) {
Assert.notEmpty(ids, "角色 ID 不能为空");
roleService.batchDelete(ids);
return Result.success();
}
}
......@@ -8,7 +8,7 @@
</div>
<div class="right-panel">
<div class="right-panel-search">
<el-input v-model="search.keyword" placeholder="角色名称" clearable></el-input>
<el-input v-model="search.name" placeholder="角色名称" clearable></el-input>
<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
</div>
</div>
......@@ -17,20 +17,26 @@
<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe>
<el-table-column type="selection" width="50"></el-table-column>
<el-table-column label="#" type="index" width="50"></el-table-column>
<el-table-column label="角色名称" prop="label" width="150"></el-table-column>
<el-table-column label="别名" prop="alias" width="200"></el-table-column>
<el-table-column label="排序" prop="sort" width="80"></el-table-column>
<el-table-column label="状态" prop="status" width="80">
<el-table-column label="角色名称" prop="name" width="150"></el-table-column>
<el-table-column label="角色标识" prop="key" width="200"></el-table-column>
<el-table-column label="角色状态" prop="status" width="150">
<template #default="scope">
<el-switch v-model="scope.row.status" @change="changeSwitch($event, scope.row)" :loading="scope.row.$switch_status" active-value="1" inactive-value="0"></el-switch>
<el-tag v-if="scope.row.status==1" type="success">启用</el-tag>
<el-tag v-if="scope.row.status==9" type="danger">停用</el-tag>
</template>
</el-table-column>
<el-table-column label="创建时间" prop="date" width="180"></el-table-column>
<el-table-column label="备注" prop="remark" min-width="150"></el-table-column>
<el-table-column label="角色类型" prop="type" width="150">
<template #default="scope">
<el-tag v-if="scope.row.type==1" type="info">缺省</el-tag>
</template>
</el-table-column>
<el-table-column label="扩展码" prop="bizCode" width="150"></el-table-column>
<el-table-column label="创建时间" prop="gmtCreated" width="180"></el-table-column>
<el-table-column label="备注" prop="remark" width="200"></el-table-column>
<el-table-column label="操作" fixed="right" align="right" width="170">
<template #default="scope">
<el-button-group>
<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
<!-- <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button> -->
<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
<el-popconfirm title="确定删除吗?" @confirm="table_del(scope.row, scope.$index)">
<template #reference>
......@@ -70,7 +76,7 @@
apiObj: this.$API.system.role.list,
selection: [],
search: {
keyword: null
name: null
}
}
},
......
<template>
<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
<el-form-item label="角色名称" prop="label">
<el-input v-model="form.label" clearable></el-input>
<el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="100px"
label-position="left">
<el-form-item label="角色名称" prop="name">
<el-input v-model="form.name" clearable></el-input>
</el-form-item>
<el-form-item label="角色别名" prop="alias">
<el-input v-model="form.alias" clearable></el-input>
<el-form-item label="角色标识" prop="key">
<el-input v-model="form.key" clearable></el-input>
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input-number v-model="form.sort" controls-position="right" :min="1" style="width: 100%;"></el-input-number>
<el-form-item label="角色类型" prop="type">
<el-select v-model="form.type" class="m-2" placeholder="Select" style="width: 100%;">
<el-option v-for="item in typeItems" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="是否有效" prop="status">
<el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
<el-form-item label="角色状态" prop="status">
<el-select v-model="form.status" class="m-2" placeholder="Select" style="width: 100%;">
<el-option v-for="item in statusItems" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="扩展码" prop="bizCode">
<el-input v-model="form.bizCode" placeholder="请输入业务扩展码" clearable></el-input>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" clearable type="textarea"></el-input>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="visible=false" >取 消</el-button>
<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
<el-button @click="visible = false">取 消</el-button>
<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
</template>
</el-dialog>
</template>
<script>
export default {
emits: ['success', 'closed'],
data() {
return {
mode: "add",
titleMap: {
add: '新增',
edit: '编辑',
show: '查看'
},
visible: false,
isSaveing: false,
//表单数据
form: {
id:"",
label: "",
alias: "",
sort: 1,
status: 1,
remark: ""
},
//验证规则
rules: {
sort: [
{required: true, message: '请输入排序', trigger: 'change'}
],
label: [
{required: true, message: '请输入角色名称'}
],
alias: [
{required: true, message: '请输入角色别名'}
]
}
}
},
mounted() {
export default {
emits: ['success', 'closed'],
data() {
return {
mode: "add",
titleMap: {
add: '新增角色',
edit: '编辑角色',
show: '查看角色'
},
visible: false,
isSaveing: false,
//表单数据
form: {
id: "",
name: "",
key: "",
status: '1',
type: '1',
bizCode: "",
remark: ""
},
//验证规则
rules: {
status: [
{ required: true, message: '角色状态不能为空' }
],
type: [
{ required: true, message: '角色类型不能为空' }
],
name: [
{ required: true, message: '角色名称不能为空' }
],
key: [
{ required: true, message: '角色标识不能为空' }
]
},
typeItems: [{
value: '1',
label: '缺省',
}],
statusItems: [{
value: '1',
label: '启用',
},{
value: '9',
label: '停用',
}],
}
},
mounted() {
},
methods: {
//显示
open(mode = 'add') {
this.mode = mode;
this.visible = true;
return this
},
methods: {
//显示
open(mode='add'){
this.mode = mode;
this.visible = true;
return this
},
//表单提交方法
submit(){
this.$refs.dialogForm.validate(async (valid) => {
if (valid) {
this.isSaveing = true;
var res = await this.$API.demo.post.post(this.form);
this.isSaveing = false;
if(res.code == 200){
this.$emit('success', this.form, this.mode)
this.visible = false;
this.$message.success("操作成功")
}else{
this.$alert(res.message, "提示", {type: 'error'})
}
//表单提交方法
submit() {
this.$refs.dialogForm.validate(async (valid) => {
if (valid) {
this.isSaveing = true;
var res = await this.$API.demo.post.post(this.form);
this.isSaveing = false;
if (res.code == 200) {
this.$emit('success', this.form, this.mode)
this.visible = false;
this.$message.success("操作成功")
} else {
this.$alert(res.message, "提示", { type: 'error' })
}
})
},
//表单注入数据
setData(data){
this.form.id = data.id
this.form.label = data.label
this.form.alias = data.alias
this.form.sort = data.sort
this.form.status = data.status
this.form.remark = data.remark
}
})
},
//表单注入数据
setData(data) {
this.form.id = data.id
this.form.label = data.label
this.form.alias = data.alias
this.form.sort = data.sort
this.form.status = data.status
this.form.remark = data.remark
//可以和上面一样单个注入,也可以像下面一样直接合并进去
//Object.assign(this.form, data)
}
//可以和上面一样单个注入,也可以像下面一样直接合并进去
//Object.assign(this.form, data)
}
}
}
</script>
<style>
......
......@@ -22,5 +22,4 @@ public class Page implements Serializable {
private long pageSize;
}
......@@ -33,8 +33,4 @@ public class PageResult<T> implements Serializable {
private Map<String, String> summary = Collections.EMPTY_MAP;
public static <T> PageResult<T> of(Page<T> page) {
return new PageResult<T>().setPage(page.getCurrent()).setPageSize(page.getSize()).setTotal(page.getTotal()).setRows(page.getRecords());
}
}
package com.gitee.pulanos.pangu.framework.common.utils;
import cn.hutool.core.util.ReflectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gitee.pulanos.pangu.framework.common.model.PageResult;
/**
* Paging Utils
*
* @author xiongchun
* @since 4.1.0
*/
public class PagingUtil {
public static Page createPage(long page, long pageSize){
return new Page(page, pageSize);
}
public static Page createPage(Object obj){
long page = Long.valueOf(ReflectUtil.getFieldValue(obj, "page").toString());
long pageSize = Long.valueOf(ReflectUtil.getFieldValue(obj, "pageSize").toString());
return createPage(page, pageSize);
}
public static PageResult getPageResult(Page page) {
return new PageResult().setPage(page.getCurrent()).setPageSize(page.getSize()).setTotal(page.getTotal()).setRows(page.getRecords());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册