zhaowc
2024-08-22 13dce68bfdf0aca4b05e800494d2cd82c36ac44c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using Model.ModelDto.SysDto;
using Model.ModelVm.SysVm;
using System;
using System.Collections.Generic;
using System.Text;
using WMS.DAL;
using WMS.IBLL.ISysServer;
using WMS.Entity.SysEntity;
using SqlSugar;
using WMS.Entity.Context;
using AutoMapper;
using System.Threading.Tasks;
 
 
namespace WMS.BLL.SysServer
{
    public class PrintTemplateServer : DbHelper<SysPrintTemplate>, IPrintTemplateServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public PrintTemplateServer() : base(Db)
        {
        }
 
        /// <summary>
        /// 添加模板
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task AddPrintTemplate(SysPrintTemplate model, int userid)
        {
            if (model.Status == "1")
            {
                await Db.Updateable<SysPrintTemplate>().SetColumns(s => s.Status == "0").Where(s => s.Type == model.Type && model.Status == "1").ExecuteCommandAsync();
            }
            model.CreateTime = DateTime.Now;
            model.CreateUser = userid;
            await Db.Insertable(model).ExecuteCommandAsync();
        }
        /// <summary>
        /// 删除模板
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task DelPrintTemplate(SysPrintTemplate model, int userid)
        {
            await Db.Updateable<SysPrintTemplate>().SetColumns(s => s.IsDel == "1").Where(s => s.Id == model.Id).ExecuteCommandAsync();
        }
        /// <summary>
        /// 修改模板
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task EditPrintTemplate(SysPrintTemplate model, int userid)
        {
            if (model.Status == "1")
            {
                await Db.Updateable<SysPrintTemplate>().SetColumns(s => s.Status == "0").Where(s => s.Type == model.Type && model.Status == "1").ExecuteCommandAsync();
            }
            model.UpdateTime = DateTime.Now;
            model.UpdateUser = userid;
            await Db.Updateable(model).UpdateColumns(it => new { it.Name, it.Type, it.Status, it.PositionJson, it.UpdateTime, it.UpdateUser }).ExecuteCommandAsync();
        }
        /// <summary>
        /// 获取模板分页
        /// </summary>
        /// <param name="model"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<PrintTemplateDto>> GetPrintTemplateList(PrintTemplateVm model, RefAsync<int> count)
        {
            var list = await Db.Queryable<SysPrintTemplate>()
                        .LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id)
                        .WhereIF(!string.IsNullOrWhiteSpace(model.Name), (a, b) => a.Name.Contains(model.Name))
                        .Where((a, b) => a.IsDel == "0")
                        .Select((a, b) => new PrintTemplateDto()
                        {
                            Id = a.Id,
                            Name = a.Name,
                            Type = a.Type,
                            Status = a.Status,
                            PositionJson = a.PositionJson,
                            CreateTime = a.CreateTime,
                            CreateUserName = b.RealName,
                            UpdateTime = b.CreateTime,
                        })
                        .ToPageListAsync(model.Page, model.Limit, count);
            return list;
        }
        /// <summary>
        /// 获取默认打印模板
        /// </summary>
        public async Task<SysPrintTemplate> GetDefaultPrintTemplate(string Type)
        {
            return await Db.Queryable<SysPrintTemplate>().FirstAsync(s => s.Type == Type && s.Status == "1");
        }
    }
}