Browse Source

节假日自动同步功能

seimin 3 years ago
parent
commit
913326ae6a

+ 1 - 1
proxy.conf.json

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "/service": {
3
-    "target": "http://192.168.3.96",
3
+    "target": "http://192.168.3.108",
4 4
     "logLevel": "debug",
5 5
     "changeOrigin": true,
6 6
     "pathRewrite": {

+ 4 - 0
src/app/services/main.service.ts

@@ -317,4 +317,8 @@ export class MainService {
317 317
   listDeptOrderRecord(data) {
318 318
     return this.http.post(host.host + '/nurse/listDeptOrderRecord', data, { headers: this.headers });
319 319
   }
320
+  //自动同步国家法定节假日
321
+  syncWorkDay(data) {
322
+    return this.http.post(host.host + '/configuration/syncWorkDay', data, { headers: this.headers });
323
+  }
320 324
 }

+ 4 - 1
src/app/views/holidays-management/holidays-management.component.html

@@ -1,7 +1,10 @@
1 1
 <div class="holidays">
2 2
   <div class="set display_flex justify-content_space-between align-items_center">
3 3
     <span>工作日:周一、周二、周三、周四、周五;节假日:周六、周日;</span>
4
-    <button class="btn default fr" [disabled]="!coopBtns.edit" (click)='showModal()'>设置</button>
4
+    <div>
5
+      <label nz-checkbox [(ngModel)]="syncWorkDay" (ngModelChange)="setSyncWorkDay($event)">自动同步国家法定节假日</label>
6
+      <button class="btn default" [disabled]="!coopBtns.edit" (click)='showModal()'>设置</button>
7
+    </div>
5 8
   </div>
6 9
   <div class="day" *ngIf="!loading1">
7 10
     <nz-calendar (nzSelectChange)="onValueChange($event)" [(ngModel)]="selected">

+ 196 - 144
src/app/views/holidays-management/holidays-management.component.ts

@@ -1,87 +1,122 @@
1
-import { Component, OnInit } from '@angular/core';
2
-import { MainService } from '../../services/main.service';
3
-import { ActivatedRoute, Router } from '@angular/router';
1
+import { Component, OnInit } from "@angular/core";
2
+import { MainService } from "../../services/main.service";
3
+import { ActivatedRoute, Router } from "@angular/router";
4 4
 
5
-import { NzMessageService } from 'ng-zorro-antd/message';
5
+import { NzMessageService } from "ng-zorro-antd/message";
6 6
 
7 7
 @Component({
8
-  selector: 'app-holidays-management',
9
-  templateUrl: './holidays-management.component.html',
10
-  styleUrls: ['./holidays-management.component.less']
8
+  selector: "app-holidays-management",
9
+  templateUrl: "./holidays-management.component.html",
10
+  styleUrls: ["./holidays-management.component.less"],
11 11
 })
12 12
 export class HolidaysManagementComponent implements OnInit {
13
-
14
-  constructor(private mainService: MainService, private msg: NzMessageService,
15
-    private route: ActivatedRoute,) { }
13
+  constructor(
14
+    private mainService: MainService,
15
+    private msg: NzMessageService,
16
+    private route: ActivatedRoute
17
+  ) {}
16 18
 
17 19
   ngOnInit() {
18 20
     this.initCoopBtns();
19
-    this.initDates();//初始化日历选中情况
20
-    // this.getDaySet();//工作日设置(小弹窗)
21
+    this.initDates(); //初始化日历选中情况
22
+    this.getSyncWorkDay();
21 23
   }
22 24
 
23
-  menu: any = JSON.parse(localStorage.getItem('menu')) || [];//菜单
24
-  promptContent: string;//操作提示框提示信息
25
-  ifSuccess: boolean;//操作成功/失败
26
-  promptInfo: string;//操作结果提示信息
27
-  promptModalShow: boolean;//操作提示框是否展示
28
-  setDay: boolean = false;//设置工作日模态框
25
+  menu: any = JSON.parse(localStorage.getItem("menu")) || []; //菜单
26
+  promptContent: string; //操作提示框提示信息
27
+  ifSuccess: boolean; //操作成功/失败
28
+  promptInfo: string; //操作结果提示信息
29
+  promptModalShow: boolean; //操作提示框是否展示
30
+  setDay: boolean = false; //设置工作日模态框
29 31
   dates = [];
30
-  dateChecked: any = {};//日历选择
32
+  dateChecked: any = {}; //日历选择
33
+  syncWorkDay = "0"; //自动同步国家法定节假日
34
+  syncWorkDayObj; //自动同步国家法定节假日
31 35
   weeks = [
32
-    { label: '周一', value: '1' },
33
-    { label: '周二', value: '2' },
34
-    { label: '周三', value: '3' },
35
-    { label: '周四', value: '4' },
36
-    { label: '周五', value: '5' },
37
-    { label: '周六', value: '6' },
38
-    { label: '周日', value: '7' },
39
-  ];//工作日设置:周
40
-  btnLoading: boolean = false;//提交按钮loading状态
36
+    { label: "周一", value: "1" },
37
+    { label: "周二", value: "2" },
38
+    { label: "周三", value: "3" },
39
+    { label: "周四", value: "4" },
40
+    { label: "周五", value: "5" },
41
+    { label: "周六", value: "6" },
42
+    { label: "周日", value: "7" },
43
+  ]; //工作日设置:周
44
+  btnLoading: boolean = false; //提交按钮loading状态
41 45
 
42 46
   // 初始化增删改按钮
43 47
   coopBtns: any = {
44 48
     look: false,
45 49
     add: false,
46 50
     edit: false,
47
-    del: false
51
+    del: false,
48 52
   };
49 53
 
50 54
   initCoopBtns() {
51 55
     // 二级菜单
52
-    let secondMenus = []
53
-    this.menu.forEach(e => {
54
-      e.childrens.forEach(el => {
55
-        secondMenus.push(el)
56
+    let secondMenus = [];
57
+    this.menu.forEach((e) => {
58
+      e.childrens.forEach((el) => {
59
+        secondMenus.push(el);
56 60
       });
57 61
     });
58
-    console.log(secondMenus)
62
+    console.log(secondMenus);
59 63
     let link = this.route.parent.snapshot.routeConfig.path;
60
-    let btns = []
61
-    secondMenus.forEach(e => {
64
+    let btns = [];
65
+    secondMenus.forEach((e) => {
62 66
       if (e.link == link) {
63 67
         btns = e.childrens || [];
64 68
       }
65 69
     });
66
-    btns.forEach(e => {
70
+    btns.forEach((e) => {
67 71
       switch (e.link) {
68
-        case 'look':
72
+        case "look":
69 73
           this.coopBtns.look = true;
70 74
           break;
71
-        case 'add':
75
+        case "add":
72 76
           this.coopBtns.add = true;
73 77
           break;
74
-        case 'edit':
78
+        case "edit":
75 79
           this.coopBtns.edit = true;
76 80
           break;
77
-        case 'del':
81
+        case "del":
78 82
           this.coopBtns.del = true;
79 83
           break;
80 84
       }
81
-    })
85
+    });
82 86
     console.log(this.coopBtns);
83 87
   }
84
-
88
+  //设置自动同步国家法定节假日
89
+  setSyncWorkDay() {
90
+    this.syncWorkDayObj.syncWorkDay = this.syncWorkDay;
91
+    let postData = { syncWorkDay: this.syncWorkDayObj };
92
+    this.mainService.syncWorkDay(postData).subscribe((result) => {
93
+      if (result["status"] == 200) {
94
+        this.msg.success("设置成功", {
95
+          nzDuration: 1000,
96
+        });
97
+      } else {
98
+        this.msg.error("设置失败", {
99
+          nzDuration: 1000,
100
+        });
101
+      }
102
+    });
103
+  }
104
+  //获取自动同步国家法定节假日
105
+  getSyncWorkDay() {
106
+    let postData = {
107
+      idx: 0,
108
+      sum: 99,
109
+      systemConfiguration: { keyconfig: "syncWorkDay" },
110
+    };
111
+    this.mainService
112
+      .getFetchDataList("simple/data", "systemConfiguration", postData)
113
+      .subscribe((result) => {
114
+        if (result.status == 200) {
115
+          this.syncWorkDay = result.list[0].valueconfig;
116
+          this.syncWorkDayObj = result.list[0];
117
+        }
118
+      });
119
+  }
85 120
   getMonthData(date: Date): number | null {
86 121
     if (date.getMonth() === 8) {
87 122
       return 1394;
@@ -90,76 +125,83 @@ export class HolidaysManagementComponent implements OnInit {
90 125
   }
91 126
   // 切换日历上本日工作日/节假日选中情况(checkBox)
92 127
   onDateClick(d) {
93
-    console.log(d)
128
+    console.log(d);
94 129
     d = d - 0;
95 130
     let that = this;
96 131
     if (!that.coopBtns.edit) {
97
-      that.msg.warning('暂无修改权限!', {
98
-        nzDuration: 1000
132
+      that.msg.warning("暂无修改权限!", {
133
+        nzDuration: 1000,
99 134
       });
100 135
       return;
101 136
     }
102
-    if ((new Date(d).getFullYear()) < (new Date().getFullYear())) {
103
-      that.msg.warning('禁止修改!', {
104
-        nzDuration: 1000
137
+    if (new Date(d).getFullYear() < new Date().getFullYear()) {
138
+      that.msg.warning("禁止修改!", {
139
+        nzDuration: 1000,
105 140
       });
106 141
       return;
107 142
     }
108 143
     let postData = {
109
-      "workDayException": {
110
-        "date": (new Date(d)).getFullYear() + '-' + ((new Date(d)).getMonth() + 1) + '-' + (new Date(d)).getDate() + " 00:00:00",
111
-        "isWork": !that.dateChecked['' + d]
112
-      }
113
-    }
144
+      workDayException: {
145
+        date:
146
+          new Date(d).getFullYear() +
147
+          "-" +
148
+          (new Date(d).getMonth() + 1) +
149
+          "-" +
150
+          new Date(d).getDate() +
151
+          " 00:00:00",
152
+        isWork: !that.dateChecked["" + d],
153
+      },
154
+    };
114 155
     // console.log(postData)
115 156
     // return
116
-    that.mainService.coopTypeConfig('addData', 'workDayException', postData).subscribe(data => {
117
-      // console.log(data);
118
-      if (data.status == 200) {
119
-        that.msg.success('设置成功!', {
120
-          nzDuration: 1000
121
-        });
122
-      } else {
123
-        that.msg.error(data.msg, {
124
-          nzDuration: 1000
125
-        });
126
-      }
127
-    })
157
+    that.mainService
158
+      .coopTypeConfig("addData", "workDayException", postData)
159
+      .subscribe((data) => {
160
+        // console.log(data);
161
+        if (data.status == 200) {
162
+          that.msg.success("设置成功!", {
163
+            nzDuration: 1000,
164
+          });
165
+        } else {
166
+          that.msg.error(data.msg, {
167
+            nzDuration: 1000,
168
+          });
169
+        }
170
+      });
128 171
   }
129 172
 
130 173
   // change当前选中日期
131
-  lastSelectMonth = new Date();//上次点击月份的日期;
132
-  selected;//当前选中日期
174
+  lastSelectMonth = new Date(); //上次点击月份的日期;
175
+  selected; //当前选中日期
133 176
   onValueChange(value: Date): void {
134
-    let lastYear = this.lastSelectMonth.getFullYear();//上次选中年
135
-    let lastMonth = this.lastSelectMonth.getMonth() + 1;//上次选中月
136
-    let newYear = value.getFullYear();//本次选中年
137
-    let newMonth = value.getMonth() + 1;//本次选中月
177
+    let lastYear = this.lastSelectMonth.getFullYear(); //上次选中年
178
+    let lastMonth = this.lastSelectMonth.getMonth() + 1; //上次选中月
179
+    let newYear = value.getFullYear(); //本次选中年
180
+    let newMonth = value.getMonth() + 1; //本次选中月
138 181
     // console.log(lastYear, lastMonth, newYear, newMonth)
139 182
     if (lastYear != newYear || lastMonth != newMonth) {
140 183
       // console.log('已切换了年/月,需重新获取当前年/月数据')
141
-      this.initDates(value.getFullYear(), value.getMonth())
184
+      this.initDates(value.getFullYear(), value.getMonth());
142 185
     }
143 186
     this.lastSelectMonth = value;
144
-
145 187
   }
146 188
 
147 189
   // 初始化日历选中情况
148 190
   loading1 = false;
149 191
   initDates(year?, month?) {
150
-    console.log(year, month)
192
+    console.log(year, month);
151 193
     let that = this;
152 194
     // dates 一个月内的 “日”
153
-    that.dates = []
195
+    that.dates = [];
154 196
     if (year !== undefined && month !== undefined) {
155 197
       let n = 0;
156 198
       if (month == 0) {
157 199
         n = 31;
158 200
       } else {
159
-        n = (new Date(year, month + 1, 0).getDate());
201
+        n = new Date(year, month + 1, 0).getDate();
160 202
       }
161 203
       for (var i = 1; i <= n; i++) {
162
-        let d = (new Date(new Date(year, month, i))).getTime() + '';
204
+        let d = new Date(new Date(year, month, i)).getTime() + "";
163 205
         that.dates.push(d);
164 206
       }
165 207
     } else {
@@ -167,51 +209,59 @@ export class HolidaysManagementComponent implements OnInit {
167 209
       if (new Date().getMonth() == 0) {
168 210
         n = 31;
169 211
       } else {
170
-        n = (new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate());
212
+        n = new Date(
213
+          new Date().getFullYear(),
214
+          new Date().getMonth() + 1,
215
+          0
216
+        ).getDate();
171 217
       }
172 218
       for (var i = 1; i <= n; i++) {
173
-        let d = (new Date(new Date(new Date().getFullYear(), new Date().getMonth(), i))).getTime() + '';
219
+        let d =
220
+          new Date(
221
+            new Date(new Date().getFullYear(), new Date().getMonth(), i)
222
+          ).getTime() + "";
174 223
         that.dates.push(d);
175 224
       }
176 225
     }
177
-    console.log(that.dates)
226
+    console.log(that.dates);
178 227
 
179 228
     let postData = {
180
-      "idx": 0,
181
-      "sum": 31,
182
-      "workDay": {
183
-        "year": year ? year : (new Date().getFullYear()),
184
-        "month": month + 1 ? month + 1 : (new Date().getMonth() + 1)
185
-      }
186
-    }
229
+      idx: 0,
230
+      sum: 31,
231
+      workDay: {
232
+        year: year ? year : new Date().getFullYear(),
233
+        month: month + 1 ? month + 1 : new Date().getMonth() + 1,
234
+      },
235
+    };
187 236
     // return
188 237
     this.loading1 = true;
189
-    that.mainService.getFetchDataList('configuration','workDay', postData).subscribe(data => {
190
-      this.loading1 = false;
191
-      console.log(data)
192
-      let k = '';
193
-      let dateChecked = {}
194
-      data.list.forEach(e => {
195
-        let k = (new Date(e.year, e.month - 1, e.date.substring(8, 10))).getTime() + '';
196
-        dateChecked[k] = e.isWork
238
+    that.mainService
239
+      .getFetchDataList("configuration", "workDay", postData)
240
+      .subscribe((data) => {
241
+        this.loading1 = false;
242
+        console.log(data);
243
+        let k = "";
244
+        let dateChecked = {};
245
+        data.list.forEach((e) => {
246
+          let k =
247
+            new Date(e.year, e.month - 1, e.date.substring(8, 10)).getTime() +
248
+            "";
249
+          dateChecked[k] = e.isWork;
250
+        });
251
+        console.log(dateChecked);
252
+        this.dateChecked = dateChecked;
197 253
       });
198
-      console.log(dateChecked)
199
-      this.dateChecked = dateChecked;
200
-    })
201
-
202
-
203
-
204 254
   }
205 255
 
206 256
   // 获取当前年
207 257
   getYear(): any {
208
-    return new Date().getFullYear()
258
+    return new Date().getFullYear();
209 259
   }
210 260
 
211 261
   // 设置工作日模态框
212 262
   showModal() {
213 263
     this.setDay = true;
214
-    this.getDaySet();//工作日设置(小弹窗)
264
+    this.getDaySet(); //工作日设置(小弹窗)
215 265
   }
216 266
   hideModal() {
217 267
     this.setDay = false;
@@ -226,18 +276,18 @@ export class HolidaysManagementComponent implements OnInit {
226 276
     6: false,
227 277
     7: false,
228 278
   };
229
-  saveStr: string = '';//工作日设置保存参数
230
-  hasChange: boolean = false;//是否修改工作日设置选项
279
+  saveStr: string = ""; //工作日设置保存参数
280
+  hasChange: boolean = false; //是否修改工作日设置选项
231 281
   // 工作日设置操作checkBox
232 282
   changeWeeks() {
233 283
     this.hasChange = true;
234
-    let str = '';
284
+    let str = "";
235 285
     for (let i in this.weeksChecked) {
236
-      str += ('' + (this.weeksChecked[i] ? 1 : 2));
286
+      str += "" + (this.weeksChecked[i] ? 1 : 2);
237 287
     }
238 288
     str = str.slice(0, 6);
239
-    str = '' + (this.weeksChecked[7] ? 1 : 2) + str;
240
-    str = (new Date().getFullYear()) + '-' + str;
289
+    str = "" + (this.weeksChecked[7] ? 1 : 2) + str;
290
+    str = new Date().getFullYear() + "-" + str;
241 291
     this.saveStr = str;
242 292
   }
243 293
   // 保存工作日设置
@@ -245,48 +295,51 @@ export class HolidaysManagementComponent implements OnInit {
245 295
     let that = this;
246 296
     that.btnLoading = true;
247 297
     if (!that.hasChange) {
248
-      that.changeWeeks()
298
+      that.changeWeeks();
249 299
     }
250
-    let postData = { workDayConfigure: { rule: that.saveStr } }
251
-    that.mainService.coopTypeConfig('addData', 'workDayConfigure', postData).subscribe(data => {
252
-      that.btnLoading = false;
253
-      that.setDay = false;
254
-      if (data.status == 200) {
255
-        that.showPromptModal('保存', true, '');
256
-        that.initDates();
257
-      } else {
258
-        that.showPromptModal('保存', false, data.msg)
259
-      }
260
-    })
300
+    let postData = { workDayConfigure: { rule: that.saveStr } };
301
+    that.mainService
302
+      .coopTypeConfig("addData", "workDayConfigure", postData)
303
+      .subscribe((data) => {
304
+        that.btnLoading = false;
305
+        that.setDay = false;
306
+        if (data.status == 200) {
307
+          that.showPromptModal("保存", true, "");
308
+          that.initDates();
309
+        } else {
310
+          that.showPromptModal("保存", false, data.msg);
311
+        }
312
+      });
261 313
   }
262 314
 
263 315
   // 获取工作日设置
264 316
   loading2 = false;
265 317
   getDaySet() {
266 318
     let postData = {
267
-      "workDayConfigure": {
268
-        "year": (new Date().getFullYear()),
269
-        "state": 1
319
+      workDayConfigure: {
320
+        year: new Date().getFullYear(),
321
+        state: 1,
270 322
       },
271
-      "idx": 0,
272
-      "sum": 1000
273
-    }
323
+      idx: 0,
324
+      sum: 1000,
325
+    };
274 326
     this.loading2 = true;
275
-    this.mainService.getFetchDataList('configuration','workDayConfigure', postData).subscribe(data => {
276
-      this.loading2 = false;
277
-      if (data.list && data.list[0]) {
278
-        this.weeksChecked[1] = (data.list[0]['monday'] == 1 ? true : false)
279
-        this.weeksChecked[2] = (data.list[0]['tuesday'] == 1 ? true : false)
280
-        this.weeksChecked[3] = (data.list[0]['wednesday'] == 1 ? true : false)
281
-        this.weeksChecked[4] = (data.list[0]['thursday'] == 1 ? true : false)
282
-        this.weeksChecked[5] = (data.list[0]['friday'] == 1 ? true : false)
283
-        this.weeksChecked[6] = (data.list[0]['saturday'] == 1 ? true : false)
284
-        this.weeksChecked[7] = (data.list[0]['sunday'] == 1 ? true : false)
285
-        console.log(data.list[0])
286
-        console.log(this.weeksChecked)
287
-      }
288
-    })
289
-
327
+    this.mainService
328
+      .getFetchDataList("configuration", "workDayConfigure", postData)
329
+      .subscribe((data) => {
330
+        this.loading2 = false;
331
+        if (data.list && data.list[0]) {
332
+          this.weeksChecked[1] = data.list[0]["monday"] == 1 ? true : false;
333
+          this.weeksChecked[2] = data.list[0]["tuesday"] == 1 ? true : false;
334
+          this.weeksChecked[3] = data.list[0]["wednesday"] == 1 ? true : false;
335
+          this.weeksChecked[4] = data.list[0]["thursday"] == 1 ? true : false;
336
+          this.weeksChecked[5] = data.list[0]["friday"] == 1 ? true : false;
337
+          this.weeksChecked[6] = data.list[0]["saturday"] == 1 ? true : false;
338
+          this.weeksChecked[7] = data.list[0]["sunday"] == 1 ? true : false;
339
+          console.log(data.list[0]);
340
+          console.log(this.weeksChecked);
341
+        }
342
+      });
290 343
   }
291 344
 
292 345
   // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
@@ -299,5 +352,4 @@ export class HolidaysManagementComponent implements OnInit {
299 352
       this.promptModalShow = true;
300 353
     }, 100);
301 354
   }
302
-
303 355
 }