一套完整的业务逻辑(班次管理)
DB
use yxt_mes_db;
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
VALUES ('班次维护', 1145, 999, 'BFlightInfo', 'factorys/BFlightInfo', 0, 0, 'C', '0', '0', 'factorys:bflightinfo:list', 'icon1', 'system', GETDATE());
declare @menuId int = @@identity
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:query', '', 'system', GETDATE());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:add', '', 'system', GETDATE());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:delete', '', 'system', GETDATE());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:edit', '', 'system', GETDATE());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:export', '', 'system', GETDATE());
SELECT * FROM sys_menu WHERE parentId = @menuId;
SELECT * FROM sys_menu WHERE menuId = @menuId;
Controllers/Factorys/BFlightInfoController
using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using YXT.Model.Dto;
using YXT.Model.Models;
using YXT.Service.Factorys.IFactorysService;
using YXT.Admin.WebApi.Extensions;
using YXT.Admin.WebApi.Filters;
using YXT.Common;
namespace YXT.Admin.WebApi.Controllers
{
[Verify]
[Route("factorys/BFlightInfo")]
public class BFlightInfoController : BaseController
{
private readonly IBFlightInfoService _BFlightInfoService;
public BFlightInfoController(IBFlightInfoService BFlightInfoService)
{
_BFlightInfoService = BFlightInfoService;
}
[HttpGet("list")]
[ActionPermissionFilter(Permission = "factorys:bflightinfo:list")]
public IActionResult QueryBFlightInfo([FromQuery] BFlightInfoQueryDto parm)
{
var response = _BFlightInfoService.GetList(parm);
return SUCCESS(response);
}
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "factorys:bflightinfo:query")]
public IActionResult GetBFlightInfo(int Id)
{
var response = _BFlightInfoService.GetFirst(x => x.Id == Id);
return SUCCESS(response);
}
[HttpPost]
[ActionPermissionFilter(Permission = "factorys:bflightinfo:add")]
[Log(Title = "班次维护", BusinessType = BusinessType.INSERT)]
public IActionResult AddBFlightInfo([FromBody] BFlightInfoDto parm)
{
if (parm == null)
{
throw new CustomException("请求参数错误");
}
var modal = parm.Adapt<BFlightInfo>().ToCreate(HttpContext);
var response = _BFlightInfoService.AddBFlightInfo(modal);
return ToResponse(response);
}
[HttpPut]
[ActionPermissionFilter(Permission = "factorys:bflightinfo:edit")]
[Log(Title = "班次维护", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateBFlightInfo([FromBody] BFlightInfoDto parm)
{
if (parm == null)
{
throw new CustomException("请求实体不能为空");
}
var modal = parm.Adapt<BFlightInfo>().ToUpdate(HttpContext);
var response = _BFlightInfoService.UpdateBFlightInfo(modal);
return ToResponse(response);
}
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "factorys:bflightinfo:delete")]
[Log(Title = "班次维护", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteBFlightInfo(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _BFlightInfoService.Delete(idsArr);
return ToResponse(response);
}
[Log(Title = "班次维护", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
[HttpGet("export")]
[ActionPermissionFilter(Permission = "factorys:bflightinfo:export")]
public IActionResult Export([FromQuery] BFlightInfoQueryDto parm)
{
parm.PageSize = 10000;
var list = _BFlightInfoService.GetList(parm).Result;
string sFileName = ExportExcel(list, "BFlightInfo", "班次维护");
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
}
}
}
Model/Dto/Factorys/BFlightInfoDto
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using YXT.Model.Dto;
using YXT.Model.Models;
namespace YXT.Model.Dto
{
public class BFlightInfoDto
{
public int? Id { get; set; }
[Required(ErrorMessage = "班次名称不能为空")]
public string FlightName { get; set; }
[Required(ErrorMessage = "班次编码不能为空")]
public string FlightCode { get; set; }
[Required(ErrorMessage = "班次描述不能为空")]
public string FlightDescribe { get; set; }
public string Status { get; set; }
public int? CreateUserid { get; set; }
public DateTime? CreateDate { get; set; }
public int? UpdateUserid { get; set; }
public DateTime? UpdateDate { get; set; }
public string WorkTime { get; set; }
public string NoworkTime { get; set; }
}
public class BFlightInfoQueryDto : PagerInfo
{
public string FlightName { get; set; }
public string FlightCode { get; set; }
public string FlightDescribe { get; set; }
}
}
Model/Models/Factorys/BFlightInfo.cs
using System;
using System.Collections.Generic;
using SqlSugar;
using OfficeOpenXml.Attributes;
namespace YXT.Model.Models
{
[SugarTable("B_Flight_Info")]
public class BFlightInfo
{
[EpplusTableColumn(Header = "id")]
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int? Id { get; set; }
[EpplusTableColumn(Header = "班次名称")]
[SugarColumn(ColumnName = "fLIGHT_NAME")]
public string FlightName { get; set; }
[EpplusTableColumn(Header = "班次编码")]
[SugarColumn(ColumnName = "fLIGHT_CODE")]
public string FlightCode { get; set; }
[EpplusTableColumn(Header = "班次描述")]
[SugarColumn(ColumnName = "fLIGHT_DESCRIBE")]
public string FlightDescribe { get; set; }
[EpplusTableColumn(Header = "状态")]
public string Status { get; set; }
[EpplusTableColumn(Header = "创建人id")]
[SugarColumn(ColumnName = "cREATE_USERID")]
public int? CreateUserid { get; set; }
[EpplusTableColumn(Header = "创建日期", NumberFormat = "yyyy-MM-dd HH:mm:ss")]
[SugarColumn(ColumnName = "cREATE_DATE")]
public DateTime? CreateDate { get; set; }
[EpplusTableColumn(Header = "更新人id")]
[SugarColumn(ColumnName = "uPDATE_USERID")]
public int? UpdateUserid { get; set; }
[EpplusTableColumn(Header = "更新日期", NumberFormat = "yyyy-MM-dd HH:mm:ss")]
[SugarColumn(ColumnName = "uPDATE_DATE")]
public DateTime? UpdateDate { get; set; }
[EpplusTableColumn(Header = "上班时间")]
[SugarColumn(ColumnName = "wORK_TIME")]
public string WorkTime { get; set; }
[EpplusTableColumn(Header = "下班时间")]
[SugarColumn(ColumnName = "nOWORK_TIME")]
public string NoworkTime { get; set; }
}
}
Repository/Factorys/BFlightInfoRepository.cs
using System;
using Infrastructure.Attribute;
using YXT.Repository.System;
using YXT.Model.Models;
using Repository;
namespace YXT.Repository
{
[AppService(ServiceLifetime = LifeTime.Transient)]
public class BFlightInfoRepository : BaseRepository<BFlightInfo>
{
#region 业务逻辑代码
#endregion
}
}
Service/Factorys/BFlightInfoService.cs
using System;
using SqlSugar;
using System.Collections.Generic;
using Infrastructure;
using Infrastructure.Attribute;
using Model;
using YXT.Model.Dto;
using YXT.Model.Models;
using YXT.Repository;
using YXT.Service.Factorys.IFactorysService;
using Repository;
namespace YXT.Service.Factorys
{
[AppService(ServiceType = typeof(IBFlightInfoService), ServiceLifetime = LifeTime.Transient)]
public class BFlightInfoService : BaseService<BFlightInfo>, IBFlightInfoService
{
private readonly BFlightInfoRepository _BFlightInfoRepository;
public BFlightInfoService(BFlightInfoRepository repository)
{
_BFlightInfoRepository = repository;
}
#region 业务逻辑代码
public PagedInfo<BFlightInfo> GetList(BFlightInfoQueryDto parm)
{
var predicate = Expressionable.Create<BFlightInfo>();
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.FlightName), it => it.FlightName.Contains(parm.FlightName));
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.FlightCode), it => it.FlightCode.Contains(parm.FlightCode));
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.FlightDescribe), it => it.FlightDescribe.Contains(parm.FlightDescribe));
var response = _BFlightInfoRepository
.Queryable()
.Where(predicate.ToExpression())
.ToPage(parm);
return response;
}
public int AddBFlightInfo(BFlightInfo parm)
{
var response = _BFlightInfoRepository.Insert(parm, it => new
{
it.FlightName,
it.FlightCode,
it.FlightDescribe,
it.Status,
it.CreateUserid,
it.CreateDate,
it.WorkTime,
it.NoworkTime,
});
return response;
}
public int UpdateBFlightInfo(BFlightInfo parm)
{
var response = _BFlightInfoRepository.Update(w => w.Id == parm.Id, it => new BFlightInfo()
{
FlightName = parm.FlightName,
FlightCode = parm.FlightCode,
FlightDescribe = parm.FlightDescribe,
Status = parm.Status,
UpdateUserid = parm.UpdateUserid,
UpdateDate = parm.UpdateDate,
WorkTime = parm.WorkTime,
NoworkTime = parm.NoworkTime,
});
return response;
}
#endregion
}
}
Service\Factorys\IFactorysService\IFactorysService.cs
using System;
using Model;
using YXT.Model.Dto;
using YXT.Model.Models;
using System.Collections.Generic;
namespace YXT.Service.Factorys.IFactorysService
{
public interface IBFlightInfoService : IBaseService<BFlightInfo>
{
PagedInfo<BFlightInfo> GetList(BFlightInfoQueryDto parm);
int AddBFlightInfo(BFlightInfo parm);
int UpdateBFlightInfo(BFlightInfo parm);
}
}
Vue\src\api\factorys\bFlightInfo.js
import request from '@/utils/request'
export function listBFlightInfo(query) {
return request({
url: 'factorys/BFlightInfo/list',
method: 'get',
params: query,
})
}
export function addBFlightInfo(data) {
return request({
url: 'factorys/BFlightInfo',
method: 'post',
data: data,
})
}
export function updateBFlightInfo(data) {
return request({
url: 'factorys/BFlightInfo',
method: 'PUT',
data: data,
})
}
export function getBFlightInfo(id) {
return request({
url: 'factorys/BFlightInfo/' + id,
method: 'get'
})
}
export function delBFlightInfo(pid) {
return request({
url: 'factorys/BFlightInfo/' + pid,
method: 'delete'
})
}
export function exportBFlightInfo(query) {
return request({
url: 'factorys/BFlightInfo/export',
method: 'get',
params: query
})
}
Vue\src\views\factorys\BFlightInfo.vue
<template>
<div class="app-container">
<el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch"
@submit.native.prevent>
<el-form-item label="班次名称" prop="flightName">
<el-input v-model="queryParams.flightName" placeholder="请输入班次名称" />
</el-form-item>
<el-form-item label="班次编码" prop="flightCode">
<el-input v-model="queryParams.flightCode" placeholder="请输入班次编码" />
</el-form-item>
<el-form-item label="班次描述" prop="flightDescribe">
<el-input v-model="queryParams.flightDescribe" placeholder="请输入班次描述" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" v-hasPermi="['factorys:bflightinfo:add']" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" :disabled="single" v-hasPermi="['factorys:bflightinfo:edit']" plain icon="el-icon-edit" size="mini" @click="handleUpdate">修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" :disabled="multiple" v-hasPermi="['factorys:bflightinfo:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['factorys:bflightinfo:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table :data="dataList" v-loading="loading" ref="table" border highlight-current-row @sort-change="sortChange" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="50" align="center"/>
<el-table-column prop="flightName" label="班次名称" align="center" :show-overflow-tooltip="true" />
<el-table-column prop="flightCode" label="班次编码" align="center" :show-overflow-tooltip="true" />
<el-table-column prop="flightDescribe" label="班次描述" align="center" :show-overflow-tooltip="true" />
<el-table-column prop="status" label="状态" align="center">
<template slot-scope="scope">
<dict-tag :options="statusOptions" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column prop="createDate" label="创建日期" align="center" :show-overflow-tooltip="true" />
<el-table-column prop="updateDate" label="更新日期" align="center" :show-overflow-tooltip="true" />
<el-table-column prop="workTime" label="上班时间" align="center" :show-overflow-tooltip="true" />
<el-table-column prop="noworkTime" label="下班时间" align="center" :show-overflow-tooltip="true" />
<el-table-column label="操作" align="center" width="140">
<template slot-scope="scope">
<el-button size="mini" v-hasPermi="['factorys:bflightinfo:edit']" type="success" icon="el-icon-edit" title="编辑"
@click="handleUpdate(scope.row)"></el-button>
<el-button size="mini" v-hasPermi="['factorys:bflightinfo:delete']" type="danger" icon="el-icon-delete" title="删除"
@click="handleDelete(scope.row)"></el-button>
</template>
</el-table-column>
</el-table>
<pagination class="mt10" background :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
<el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
<el-row :gutter="20">
<el-col :lg="12" v-if="opertype == 2">
<el-form-item label="id">{{form.id}}</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="班次名称" prop="flightName">
<el-input v-model="form.flightName" placeholder="请输入班次名称" />
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="班次编码" prop="flightCode">
<el-input v-model="form.flightCode" placeholder="请输入班次编码" />
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="班次描述" prop="flightDescribe">
<el-input v-model="form.flightDescribe" placeholder="请输入班次描述" />
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio v-for="item in statusOptions" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="创建人id" prop="createUserid">
<el-input v-model="form.createUserid" placeholder="请输入创建人id" />
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="创建日期" prop="createDate">
<el-date-picker v-model="form.createDate" type="datetime" placeholder="选择日期时间"></el-date-picker>
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="更新人id" prop="updateUserid">
<el-input v-model="form.updateUserid" placeholder="请输入更新人id" />
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="更新日期" prop="updateDate">
<el-date-picker v-model="form.updateDate" type="datetime" placeholder="选择日期时间"></el-date-picker>
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="上班时间" prop="workTime">
<el-input v-model="form.workTime" placeholder="请输入上班时间" />
</el-form-item>
</el-col>
<el-col :lg="12">
<el-form-item label="下班时间" prop="noworkTime">
<el-input v-model="form.noworkTime" placeholder="请输入下班时间" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="cancel">取 消</el-button>
<el-button type="primary" @click="submitForm">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
listBFlightInfo,
addBFlightInfo,
delBFlightInfo,
updateBFlightInfo,
getBFlightInfo,
exportBFlightInfo,
} from '@/api/factorys/bFlightInfo.js';
export default {
name: "bflightinfo",
data() {
return {
labelWidth: "100px",
formLabelWidth:"100px",
ids: [],
single: true,
multiple: true,
loading: false,
showSearch: true,
queryParams: {
pageNum: 1,
pageSize: 10,
sort: undefined,
sortType: undefined,
flightName: undefined,
flightCode: undefined,
flightDescribe: undefined,
},
title: "",
opertype: 0,
open: false,
form: {},
columns: [
{ index: 0, key: 'id', label: `id`, checked: true },
{ index: 1, key: 'flightName', label: `班次名称`, checked: true },
{ index: 2, key: 'flightCode', label: `班次编码`, checked: true },
{ index: 3, key: 'flightDescribe', label: `班次描述`, checked: true },
{ index: 4, key: 'status', label: `状态`, checked: true },
{ index: 5, key: 'createUserid', label: `创建人id`, checked: true },
{ index: 6, key: 'createDate', label: `创建日期`, checked: true },
{ index: 7, key: 'updateUserid', label: `更新人id`, checked: true },
{ index: 8, key: 'updateDate', label: `更新日期`, checked: true },
{ index: 9, key: 'workTime', label: `上班时间`, checked: false },
{ index: 10, key: 'noworkTime', label: `下班时间`, checked: false },
],
statusOptions: [],
dataList: [],
total: 0,
btnSubmitVisible: true,
rules: {
flightName: [
{ required: true, message: "班次名称不能为空", trigger: "blur" }
],
flightCode: [
{ required: true, message: "班次编码不能为空", trigger: "blur" }
],
flightDescribe: [
{ required: true, message: "班次描述不能为空", trigger: "blur" }
],
},
};
},
created() {
this.getList();
var dictParams = [
{ dictType: "sys_notice_status", columnName: "statusOptions" },
];
this.getDicts(dictParams).then((response) => {
response.data.forEach((element) => {
this[element.columnName] = element.list;
});
});
},
methods: {
getList() {
this.loading = true;
listBFlightInfo(this.queryParams).then(res => {
if (res.code == 200) {
this.dataList = res.data.result;
this.total = res.data.totalNum;
this.loading = false;
}
})
},
cancel() {
this.open = false;
this.reset();
},
reset() {
this.form = {
flightName: undefined,
flightCode: undefined,
flightDescribe: undefined,
status: undefined,
createUserid: undefined,
createDate: undefined,
updateUserid: undefined,
updateDate: undefined,
workTime: undefined,
noworkTime: undefined,
};
this.resetForm("form");
},
resetQuery() {
this.timeRange = [];
this.resetForm("queryForm");
this.handleQuery();
},
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.id);
this.single = selection.length != 1
this.multiple = !selection.length;
},
sortChange(column) {
if (column.prop == null || column.order == null) {
this.queryParams.sort = undefined;
this.queryParams.sortType = undefined;
} else {
this.queryParams.sort = column.prop;
this.queryParams.sortType = column.order;
}
this.handleQuery();
},
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
handleAdd() {
this.reset();
this.open = true;
this.title = "添加";
this.opertype = 1;
},
handleDelete(row) {
const Ids = row.id || this.ids;
this.$confirm('是否确认删除参数编号为"' + Ids + '"的数据项?')
.then(function () {
return delBFlightInfo(Ids);
})
.then(() => {
this.handleQuery();
this.msgSuccess("删除成功");
})
.catch(() => {});
},
handleUpdate(row) {
this.reset();
const id = row.id || this.ids;
getBFlightInfo(id).then((res) => {
const { code, data } = res;
if (code == 200) {
this.open = true;
this.title = "修改数据";
this.opertype = 2;
this.form = {
...data,
};
}
});
},
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
},
submitForm: function () {
this.$refs["form"].validate((valid) => {
if (valid) {
console.log(JSON.stringify(this.form));
if (this.form.id != undefined && this.opertype === 2) {
updateBFlightInfo(this.form)
.then((res) => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
})
.catch((err) => {
});
} else {
addBFlightInfo(this.form)
.then((res) => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
})
.catch((err) => {
});
}
}
});
},
handleExport() {
const queryParams = this.queryParams;
this.$confirm("是否确认导出所有班次维护数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(function () {
return exportBFlightInfo(queryParams);
})
.then((response) => {
this.download(response.data.path);
});
},
},
};
</script>