BiDecisionOhterService.cs 4.12 KB
using Hh.Mes.Common.log;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hh.Mes.Service
{
    public partial class BiDecisionService : RepositorySqlSugar<sys_user>
    {
        /// <summary>
        /// 供应商列表
        /// </summary>
        public dynamic GetSuppliersInfo()
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var options = new List<dynamic>
                {
                    new { value = "00000000-0000-0000-0000-000000000000", label = "全部" }
                };
                var list = base.Context.Queryable<base_project_client_info>().Select(x => new
                {
                    value = x.keys,
                    label = x.clientName
                }).ToList();
                var finalList = options.Concat(list).ToList();
                response.Result = finalList;
                response.Count = finalList.Count;
                return response;
            }, catchRetrunValue: "GetSuppliersInfo");
        }

        /// <summary>
        /// 供应商对应的项目 
        /// </summary>
        public dynamic GeteProjectInfoByClientInfoKeys(Guid clientInfoKeys)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var expression = Expressionable.Create<base_project>()
                                .AndIF(clientInfoKeys != Guid.Empty, (x) => x.projectClientInfoKeys == clientInfoKeys)
                                .ToExpression();
                var list = base.Context.Queryable<base_project>()
                               .Where(expression)
                               .Select(x => new
                               {
                                   value = x.projectCode,
                                   label = x.projectName
                               }).ToList();
                response.Result = list;
                response.Count = list.Count;
                return response;
            }, catchRetrunValue: "list");
        }

        /// <summary>
        /// 时间公告方法 
        /// </summary>
        /// <param name="inputDate">输入时间 格式:年月日 2025-06-01</param>
        /// <param name="monthStart">月开始</param>
        /// <param name="monthEnd">月结束</param>
        /// <param name="monthStart90">月开始减去90</param>
        /// <param name="monthEnd90">月结束减去90</param>
        /// <param name="monthStart7">月开始减去7</param>
        /// <param name="monthEnd7">月结束减去7</param>
        public void CalculateDateRanges(DateTime inputDate, out DateTime monthStart7, out DateTime monthEnd7, out DateTime monthStart, out DateTime monthEnd,
                                        out DateTime monthStart90, out DateTime monthEnd90)
        {
            DateTime now = DateTime.Now;
            // 计算本月起始时间(当月第一天00:00:00)
            monthStart = new DateTime(inputDate.Year, inputDate.Month, 1, 0, 0, 0);
            // 本月
            if (inputDate.Year == now.Year && inputDate.Month == now.Month)
            {
                // 当前月结束
                monthEnd = new DateTime(inputDate.Year, inputDate.Month, inputDate.Day, 23, 59, 59);
            }
            else
            {
                //月结束
                DateTime nextMonth = monthStart.AddMonths(1);
                monthEnd = nextMonth.AddDays(-1).AddHours(23).AddMinutes(59).AddSeconds(59);
            }
            // 计算90天前的日期
            monthStart90 = inputDate.AddMonths(-3).AddHours(0).AddMinutes(0).AddSeconds(0);
            monthEnd90 = inputDate.AddHours(23).AddMinutes(59).AddSeconds(59);

            // 计算7天前的日期
            monthStart7 = inputDate.AddDays(-6).AddHours(0).AddMinutes(0).AddSeconds(0);
            monthEnd7 = inputDate.AddHours(23).AddMinutes(59).AddSeconds(59);
        }
    }
}