123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- using DapperORMCore.Context.DataContext;
- using DapperORMCore.Model.BaseModel;
- using DapperORMCore.Model.CoreModel;
- using DapperORMCore.Repository.IRepositorys;
- using DapperORMCore.String.Consts;
- using DapperORMCore.String.Enums;
- using Microsoft.Extensions.Configuration;
- using NXWMS.Code;
- using NXWMS.Code.Verifications;
- using NXWMS.DataAccess.Entity;
- using NXWMS.IService.NXWMS.Rule;
- using NXWMS.Model.AppModels.Condition.Rule;
- using NXWMS.Model.AppModels.Result.Rule;
- using NXWMS.Model.Common;
- using NXWMS.String.Enums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WestDistance.DapperORM.Repository.Repositorys;
- namespace NXWMS.Service.NXWMS.Rule
- {
- /// <summary>
- /// 打印模版
- /// </summary>
- [AutoInject(typeof(IPrintTemplateService), InjectType.Scope)]
- public class PrintTemplateService : ServiceBase, IPrintTemplateService
- {
- /// <summary>
- /// 系统操作仓储中转
- /// </summary>
- private IDataRepositoryContext _dataContext;
- /// <summary>
- /// SQL节点仓储
- /// </summary>
- private ISQLNodeRepository _iSQLNodeRepository;
- /// <summary>
- /// 配置
- /// </summary>
- private IConfiguration _configuration;
- public PrintTemplateService(IDataRepositoryContext dataRepositoryContext, IConfiguration configuration, ISQLNodeRepository iSQLNodeRepository)
- {
- this._dataContext = dataRepositoryContext;
- this._configuration = configuration;
- this._iSQLNodeRepository = iSQLNodeRepository;
- }
-
- public OperateResultInfo<PageQueryResultInfo<PrintTemplateResult>> GetList(PrintTemplateSearchCondition info)
- {
- var sqlAndBuilder = new StringBuilder();
- var sqlOrBuilder = new StringBuilder();
- var sql = $@"SELECT
- CreateName = (SELECT USER_NAME FROM SYS_USER A WHERE A.USER_ID=CREATE_BY),
- UpdateName = (SELECT USER_NAME FROM SYS_USER B WHERE B.USER_ID=UPDATE_BY),
- UsedFlagName = {_iSQLNodeRepository.GetEnumIntCaseString<UsedFlag>("USED_FLAG")},
- PrintModeName = {_iSQLNodeRepository.GetEnumIntCaseString<PrintTemplateMode>("PRINT_MODE")},
- IsPrintHeaderName = {_iSQLNodeRepository.GetEnumIntCaseString<YesNoType>("PRINT_HEADER_FLAG")},
- IsShowWatermarkName = {_iSQLNodeRepository.GetEnumIntCaseString<YesNoType>("SHOW_WATERMARK_FLAG")},
- IsShowLogoName = {_iSQLNodeRepository.GetEnumIntCaseString<YesNoType>("SHOW_LOGO_FLAG")},
- SourceTypeName = {_iSQLNodeRepository.GetEnumIntCaseString<SourceType>("SOURCE_TYPE")},
- {info.ItemSQL} FROM BAS_PRINT_TEMPLATE WHERE 1=1 AND DEL_FLAG = 0 ";
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.TemplateCode) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("TEMPLATE_CODE", info.TemplateCode, DBOperationString._ContainIn));
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.TemplateCode) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("TEMPLATE_NAME", info.TemplateName, DBOperationString._ContainIn));
- sqlAndBuilder = info.PrintMode ==null ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("PRINT_MODE", info.PrintMode, DBOperationString._Equal));
- sqlAndBuilder = info.IsUsed == null ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("USED_FLAG", info.IsUsed, DBOperationString._Equal));
- sqlAndBuilder =string.IsNullOrWhiteSpace(info.SourceName) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("SOURCE_NAME", info.SourceName, DBOperationString._ContainIn));
- sqlAndBuilder = info.IsPrintHeader == null ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("PRINT_HEADER_FLAG", info.IsPrintHeader, DBOperationString._Equal));
-
- sql = sql + (sqlAndBuilder.Length > 0 ? _iSQLNodeRepository.GetAndString(sqlAndBuilder, false) : "");
- IEnumerable<PrintTemplateResult> result;
- IEnumerable<PrintTemplateResult> totalResult;
- totalResult = new DataRepository<PrintTemplateResult>(_dataContext).Query(sql);
- if (info.PageIndex == 0 || info.PageSize == 0)
- {
- result = totalResult.ToList();
- }
- else
- {
- result = new DataRepository<PrintTemplateResult>(_dataContext).QueryPage(sql, "CREATE_TIME", info.PageSize, info.PageIndex, true);
- }
- return SuccessStatus(new PageQueryResultInfo<PrintTemplateResult>
- {
- RowData = result,
- PageConditionInfo = info,
- TotalCount = totalResult.Count(),
- TotalPageCount = (int)Math.Ceiling((double)totalResult.Count() / info.PageSize)
- });
- }
- public OperateResultInfo Add(PrintTemplateCondition info)
- {
- if (new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Query().Where(m => m.PRINT_TEMPLATE_CODE == info.TemplateCode
- && m.DEL_FLAG == 0 && m.USED_FLAG == 1).Any())
- {
- return FailMessageStatus("打印模版编码已经存在,请输入其它编码!");
- }
-
- var now = DateTime.Now;
- var id =
- new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Query().Count() == 0 ? 1 :
- new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Query().Select(s => s.PRINT_TEMPLATE_ID).Max() + 1;
- var entity = new BAS_PRINT_TEMPLATE
- {
- CREATE_BY = info.OperationUserId,
- CREATE_TIME = now,
- UPDATE_BY = info.OperationUserId,
- UPDATE_TIME = now,
- USED_FLAG = Convert.ToInt32(info.IsUsed),
- DESCRIBE = info.Describe,
- DEL_FLAG = 0,
- PRINT_HEADER_FLAG = info.IsPrintHeader ? 1 : 0,
- PRINT_MODE=info.PrintMode,
- PRINT_TEMPLATE_CODE = info.TemplateCode,
- PRINT_NUMBER=info.PrintNumber,
- PRINT_TEMPLATE_NAME = info.TemplateName,
- SOURCE_CODE=info.SourceCode,
- SHOW_LOGO_FLAG = info.IsShowLogo ? 1 : 0,
- SHOW_WATERMARK_FLAG = info.IsShowWatermark ? 1 : 0,
- SOURCE_CONTENT = info.SourceContent,
- SOURCE_NAME = info.SourceCode,
- SOURCE_TYPE = info.SourceType,
- PRINT_TEMPLATE_ID= id,
- };
- var affectedRows = new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Add(entity);
- return GetStatus(affectedRows);
- }
- public OperateResultInfo Deleted(PrintTemplateCondition info)
- {
- var sqlAndBuilder = new StringBuilder();
- sqlAndBuilder = info.TemplateId != null ?
- info.TemplateId > 0 ?
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("PRINT_TEMPLATE_ID", info.TemplateId, DBOperationString._Equal)) :
- sqlAndBuilder : sqlAndBuilder;
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.TemplateCode) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("PRINT_TEMPLATE_CODE", info.TemplateCode, DBOperationString._Equal));
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.TemplateIds) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("PRINT_TEMPLATE_ID", info.TemplateIds, DBOperationString._In));
- if (sqlAndBuilder.Length == 0)
- {
- return FailMessageStatus("参数错误!");
- }
- var now = DateTime.Now;
- var sql = $@"UPDATE BAS_PRINT_TEMPLATE SET DEL_FLAG=1,UPDATE_BY={info.OperationUserId},UPDATE_TIME='{now}'
- WHERE 1=1 {sqlAndBuilder}";
- var affectedRows = new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Execute(sql);
- return GetStatus(affectedRows, info.TemplateIds.Split(',').Length);
- }
- public OperateResultInfo Edit(PrintTemplateCondition info)
- {
- if (info == null)
- {
- return FailStatus();
- }
- if (!UtilCheckString.GetDynamicParmaValidateResult(info.SourceCode, info.SourceType, info.PrintMode, info.SourceName, info.TemplateCode, info.TemplateName))
- {
- return FailMessageStatus("参数错误!");
- }
-
- var whereList = new List<FieldKeyInfo>()
- .AddFieldKeyInfo(nameof(BAS_PRINT_TEMPLATE.PRINT_TEMPLATE_CODE), info.TemplateCode, EnumCSharpPropertyType.STRING, DBOperationString._Equal,
- !string.IsNullOrWhiteSpace(info.TemplateCode))
- .AddFieldKeyInfo(nameof(BAS_PRINT_TEMPLATE.PRINT_TEMPLATE_ID), info.TemplateId, EnumCSharpPropertyType.INT, DBOperationString._Equal,
- info.TemplateId != null);
- var result = new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Query(whereList).FirstOrDefault();
- if (result != null)
- {
- var now = DateTime.Now;
- result.DESCRIBE = info.Describe;
- result.PRINT_TEMPLATE_NAME = info.TemplateName;
- result.PRINT_TEMPLATE_CODE = info.TemplateCode;
- result.PRINT_TEMPLATE_ID = result.PRINT_TEMPLATE_ID;
- result.PRINT_NUMBER = info.PrintNumber;
- result.PRINT_MODE = info.PrintMode;
- result.SOURCE_CODE = info.SourceCode;
- result.SOURCE_NAME = info.SourceName;
- result.SOURCE_TYPE = info.SourceType;
- result.SOURCE_CONTENT = info.SourceContent;
- result.PRINT_HEADER_FLAG = info.IsPrintHeader ? 1 : 0;
- result.SHOW_LOGO_FLAG = info.IsShowLogo ? 1 : 0;
- result.SHOW_WATERMARK_FLAG = info.IsShowWatermark ? 1 : 0;
- result.UPDATE_BY = info.OperationUserId;
- result.UPDATE_TIME = now;
- result.USED_FLAG = info.IsUsed ? 1 : 0;
- var affectedRows = new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Update(result, "PRINT_TEMPLATE_ID", "NEWID");
- return GetStatus(affectedRows);
- }
- return FailMessageStatus("未查找到数据!");
- }
- public OperateResultInfo Remove(PrintTemplateCondition info)
- {
- if (string.IsNullOrWhiteSpace(info.TemplateCode) && info.TemplateId == null && string.IsNullOrWhiteSpace(info.TemplateIds))
- {
- return FailMessageStatus("参数错误!");
- }
- var sqlAndBuilder = new StringBuilder();
- var sqlOrBuilder = new StringBuilder();
- var sql = $@"SELECT {info.ItemSQL} FROM BAS_RULE WHERE 1=1 AND DEL_FLAG = 0 ";
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.TemplateCode) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("PRINT_TEMPLATE_CODE", info.TemplateCode, DBOperationString._Equal));
- sqlAndBuilder = info.TemplateId != null ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("PRINT_TEMPLATE_ID", info.TemplateId, DBOperationString._Equal));
- sql = sql + (sqlAndBuilder.Length > 0 ? _iSQLNodeRepository.GetAndString(sqlAndBuilder, false) : "");
- var result = new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Query(sql);
- if (result.Count() != 1)
- {
- return FailMessageStatus("参数错误!");
- }
- var affectedRows = new DataRepository<BAS_PRINT_TEMPLATE>(_dataContext).Remove("PRINT_TEMPLATE_ID", result.FirstOrDefault().PRINT_TEMPLATE_ID.ToString());
- return GetStatus(affectedRows);
- }
- }
- }
|