Blame view

sys/Hh.Mes.Service/WebService/Planned/FactoryCalendarService.cs 6.5 KB
赖素文 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using Hh.Mes.Common.Date;
using Hh.Mes.Common.log;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using System;
using System.Globalization;
using System.Text;

namespace Hh.Mes.Service.Planned
{
    public class FactoryCalendarService : RepositorySqlSugar<base_factory_calendar>
    {
        /// <summary>
        /// 新增  code = 字典前缀+对应表标识最大值
        /// </summary>
        /// <returns></returns>
        public dynamic Ins(base_factory_calendar model)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
23
                model.createBy = sysWebUser.Account;
赖素文 authored
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
                model.createTime = DateTime.Now;
                var result = Add(model);
                response.Status = result;
                return response;
            });
        }

        /// <summary>
        /// 编辑  code = 字典前缀+对应表标识最大值
        /// </summary>
        /// <returns></returns>
        public dynamic Edit(base_factory_calendar model)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
40
                model.updateBy = sysWebUser.Account;
赖素文 authored
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
                model.updateTime = DateTime.Now;
                var result = Update(model);
                response.Status = result;
                return response;
            });
        }

        /// <summary>
        /// 加载日历
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public dynamic GetFactoryCalendarList(string model)
        {
            #region 加载生产班别日历
            //if (string.IsNullOrEmpty(model))
            //{
            //    model = DateTime.Now.ToString();
            //}
            ////加载日历显示的时候 是显示班别里面的时间(范围) 还是日历里面的时间(范围)???????
            //var result = new TableData();
            //var factoryCalendar = GetList();
            //var data = Convert.ToDateTime(model);
            //var s = data.Month <= 9 ? "0" + data.Month : data.Month.ToString();
            //string modeldata = data.Year.ToString() + "-" + s;
            //string sql = string.Format($" CONVERT(varchar,statrCalendarDay,120) like '%{modeldata}%' ");
            //var list = Context.Queryable<factory_calendar, product_shift>((fc, ps) => new JoinQueryInfos(JoinType.Left, fc.tableCode == ps.code)).Where(sql).Select((fc, ps) => new { fc.id, title = ps.shiftName, start = fc.statrCalendarDay, end = fc.endCalendarDay }).ToList();
            //return ExceptionsHelp.Instance.ExecuteT(() =>
            //{
            //    result.data = list;
            //    result.count = result.data.Count;
            //    return result;
            //}, catchRetrunValue: "list");
            #endregion
            return null;

        }

        /// <summary>
        /// 线体日历详情获取
        /// </summary>
        /// <param name="calendarTime"></param>
        /// <param name="falg">查询月还是天</param>
        /// <returns></returns>
        public dynamic GetCalendarLineList(string calendarTime, string falg)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var stringBuilder = new StringBuilder();
                string sql = "";
                var date = Convert.ToDateTime(calendarTime);
                var FirstDayOfMonth = DateHelper.FirstDayOfMonth(date);
                var LastDayOfMonth = DateHelper.LastDayOfMonth(date);
                if (string.IsNullOrEmpty(calendarTime)) calendarTime = DateTime.Now.ToString(CultureInfo.InvariantCulture);
                if (falg == "month")
                {
                    sql = string.Format($" t2.CalendarDay >='{FirstDayOfMonth}' and  t2.CalendarDay <='{LastDayOfMonth}' ");
                    stringBuilder.AppendLine($@" select t2.CalendarDay as start, t2.[Weekday], t2.LineCode, t1.lineCode  
                                                 from line t1 left join [factory_calendar] t2 on t1.lineCode = t2.LineCode 
                                                 where  {sql} ");
                }
                else if (falg == "day")
                {
                    sql = string.Format($" t2.CalendarDay ='{date}' ");
                    stringBuilder.AppendLine($@" select t2.*,t1.lineName, t1.lineCode  from line t1 
                                                 left join(
                                                             select t2.CalendarDay as start, t2.[Weekday], code= t2.LineCode 
                                                             from line t1 left join [factory_calendar] t2 on t1.lineCode = t2.LineCode
                                                             where  {sql}
                                                          ) t2 on t1.lineCode = t2.code ");
                }
                var dt = base.Context.Ado.GetDataTable(stringBuilder.ToString());
                var result = new Response
                {
                    Result = dt,
                    Count = dt.Rows.Count
                };
                return result;
            }, catchRetrunValue: "list");
        }

        /// <summary>
        /// 线体日历线体操作   ****要么一个一个执行  要么全部执行***
        /// </summary>
        public Response CalendarLineList(string calendartime, string lines, bool flag)
        {
            var dateTime = Convert.ToDateTime(calendartime);
            var result= new Response();
            var calendar = new base_factory_calendar();
            foreach (var line in lines.Split(','))
            {
                var factorycalendar = Context.Queryable<base_factory_calendar>().Where(u => u.LineCode == line && u.CalendarDay == dateTime).First();
                if (factorycalendar==null&&flag)
                {
                    calendar.LineCode = line;
                    calendar.CalendarDay = dateTime;
                    calendar.Weekday = flag;
138
                    calendar.createBy = sysWebUser.Account;
赖素文 authored
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
                    calendar.createTime = DateTime.Now;
                    Add(calendar);
                }
                else if (!flag)
                {
                    Context.Deleteable<base_factory_calendar>().Where(u => u.id == factorycalendar.id).ExecuteCommand();
                }

            }
            result.Result = GetCalendarLineList(calendartime, "month");
            return result;

        }
    }
}