倚楼听风雨 3 år sedan
förälder
incheckning
7724bdcda1

+ 1 - 1
cool-admin-midway-master/src/app/modules/shuyou/entity/rent_computer.ts

@@ -1,7 +1,7 @@
 /*
  * @Author: YKH
  * @Date: 2022-09-01 20:41:58
- * @LastEditTime: 2022-09-20 17:58:34
+ * @LastEditTime: 2022-09-22 15:51:45
  * @Description: file content
  * @FilePath: \cool-admin-3.x\cool-admin-midway-master\src\app\modules\shuyou\entity\rent_computer.ts
  */

+ 3 - 2
cool-admin-midway-master/src/app/modules/shuyou/service/rent_computer.ts

@@ -1,7 +1,7 @@
 /*
  * @Author: YKH
  * @Date: 2021-12-08 10:26:27
- * @LastEditTime: 2022-09-20 21:31:41
+ * @LastEditTime: 2022-09-22 14:57:04
  * @Description:
  * @FilePath: \cool-admin-3.x\cool-admin-midway-master\src\app\modules\shuyou\service\rent_computer.ts
  */
@@ -118,7 +118,7 @@ export class ShuyouRentComputerService extends BaseService {
    * @param query
    */
   async page(query) {
-    const { pc_num } = query;
+    const { pc_num, is_expire } = query;
     const sql = `
           SELECT
             a.*,
@@ -134,6 +134,7 @@ export class ShuyouRentComputerService extends BaseService {
             LEFT JOIN shuyou_game_director f ON f.id = e.directorId
           WHERE 1 = 1
             ${this.setSql(pc_num, 'and a.pc_num = ?', [pc_num])}
+            ${this.setSql(is_expire, 'and a.is_expire = ?', [is_expire])}
           GROUP BY a.id
         `;
     return this.sqlRenderPage(sql, query);

+ 90 - 0
cool-admin-midway-master/src/app/modules/task/service/rent_computer.ts

@@ -0,0 +1,90 @@
+/*
+ * @Author: 倚楼听风雨 18408246387@163.com
+ * @Date: 2022-09-22 14:50:54
+ * @LastEditors: 倚楼听风雨 18408246387@163.com
+ * @LastEditTime: 2022-09-22 18:01:13
+ * @FilePath: \cool-admin-3.x\cool-admin-midway-master\src\app\modules\task\service\rent_computer.ts
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ */
+import { Inject, Logger, Provide } from '@midwayjs/decorator';
+import { BaseService } from 'midwayjs-cool-core';
+import { ILogger } from '@midwayjs/logger';
+import { Utils } from '../../../comm/utils';
+import * as _ from 'lodash';
+import { InjectEntityModel } from '@midwayjs/orm';
+import { Repository } from 'typeorm';
+// import { ShuyouUtilsService } from '../../shuyou/service/utils';
+import { ShuyouRentComputerEntity } from '../../shuyou/entity/rent_computer';
+import { ShuyouRentComputerService } from '../../shuyou/service/rent_computer';
+
+/**
+ * 租机定时任务
+ */
+@Provide()
+export class RentComputerTaskService extends BaseService {
+  @Logger()
+  logger: ILogger;
+
+  @Inject()
+  utils: Utils;
+
+  @InjectEntityModel(ShuyouRentComputerEntity)
+  ShuyouRentComputerEntity: Repository<ShuyouRentComputerEntity>;
+
+  @Inject()
+  ShuyouRentComputerService: ShuyouRentComputerService;
+
+  /**
+   * 检查是否有电脑到期,修改租机状态
+   * @memberof RentComputerTaskService
+   */
+  async checkIsExpire() {
+    let updateTime = new Date();
+    this.logger.info('checkOccupyOverTime>>>' + updateTime);
+    const sql = `
+      SELECT pc_num,rent_start,rent_end,is_expire FROM shuyou_rent_computer
+    `;
+    // console.log(sql)
+    const accList = await this.nativeQuery(sql);
+    const overtime = 24 * 60 * 60 * 1000;
+    let is_expire = 0;
+    await ykhForeach(accList, async (item, index) => {
+      if (Date.parse(item.rent_end) < updateTime.getTime()) {
+        // console.log('已经到期');
+        //已经到期
+        is_expire = 1;
+      } else if (Date.parse(item.rent_end) - updateTime.getTime() <= overtime) {
+        //明日到期
+        is_expire = 2;
+      } else {
+        //在租期中
+        is_expire = 0;
+      }
+      const ShuyouRentComputerEntity =
+        await this.ShuyouRentComputerEntity.findOne({ pc_num: item.pc_num });
+      if (ShuyouRentComputerEntity) {
+        ShuyouRentComputerEntity.is_expire = is_expire;
+        await this.ShuyouRentComputerEntity.save(ShuyouRentComputerEntity);
+      }
+    });
+
+    return 'checkIsExpire  SUCCESS>>>' + updateTime;
+  }
+}
+
+//==========================================================================================
+
+// foreach加上async/await
+const ykhForeach = async (arr, callback) => {
+  const length = arr.length;
+  const O = Object(arr);
+  let k = 0;
+  while (k < length) {
+    if (k in O) {
+      // console.log('doing foreach...');
+      const kValue = O[k];
+      await callback(kValue, k, O);
+    }
+    k++;
+  }
+};

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 493 - 406
cool-admin-midway-master/src/app/modules/task/service/shuyou.ts


+ 43 - 0
cool-admin-vue-vue3-ts-vite/src/cool/modules/shuyou/components/query-is_expire.vue

@@ -0,0 +1,43 @@
+<!--
+ * @Author: 倚楼听风雨 18408246387@163.com
+ * @Date: 2022-09-22 13:44:58
+ * @LastEditors: 倚楼听风雨 18408246387@163.com
+ * @LastEditTime: 2022-09-22 13:49:38
+ * @FilePath: \cool-admin-3.x\cool-admin-vue-vue3-ts-vite\src\cool\modules\shuyou\components\query-is_expire.vue
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+-->
+<template>
+	<cl-query field="is_expire" :list="list" />
+	<!--未完成红点提示-->
+	<!-- <el-badge class="item" is-dot type="danger">
+		<span style="font-size: 10px">未完成</span>
+	</el-badge> -->
+</template>
+
+<script lang="ts">
+import { QueryList } from "cl-admin-crud-vue3/types";
+import { defineComponent, ref } from "vue";
+
+export default defineComponent({
+	setup() {
+		const list = ref<QueryList[]>([
+			{
+				label: "在租期中",
+				value: 0
+			},
+			{
+				label: "到期未续",
+				value: 1
+			},
+			{
+				label: "即将到期",
+				value: 2
+			}
+		]);
+
+		return {
+			list
+		};
+	}
+});
+</script>

+ 4 - 3
cool-admin-vue-vue3-ts-vite/src/cool/modules/shuyou/views/rent_computer.vue

@@ -4,8 +4,9 @@
 			<cl-refresh-btn />
 			<cl-add-btn />
 			<cl-multi-delete-btn />
-			<!-- <demo-query-isabnormal /> -->
+			<demo-query-is_expire />
 			<cl-flex1 />
+			<cl-export-btn :columns="table.columns"></cl-export-btn>
 			<cl-search-key
 				field="pc_num"
 				:field-list="[
@@ -109,7 +110,7 @@
 <script lang="ts">
 import { CrudLoad, Table, Upsert } from "cl-admin-crud-vue3/types";
 import { defineComponent, inject, reactive, ref } from "vue";
-import QueryIsAbnormal from "../components/query-is_abnormal.vue";
+import QueryIsExpire from "../components/query-is_expire.vue";
 import dayjs from "dayjs";
 import { ElMessage } from "element-plus";
 import { useRefs } from "/@/core";
@@ -118,7 +119,7 @@ export default defineComponent({
 	name: "rent-computer",
 
 	components: {
-		"demo-query-isabnormal": QueryIsAbnormal
+		"demo-query-is_expire": QueryIsExpire
 	},
 
 	setup() {