倚楼听风雨 3 years ago
parent
commit
dfb7fc295a

+ 10 - 4
README.md

@@ -1,16 +1,16 @@
 <!--
  * @Author: 倚楼听风雨 18408246387@163.com
  * @Date: 2022-09-16 17:54:29
- * @LastEditors: Please set LastEditors
- * @LastEditTime: 2022-09-16 23:19:27
+ * @LastEditors: 倚楼听风雨 18408246387@163.com
+ * @LastEditTime: 2022-10-08 17:28:05
  * @FilePath: \cool-admin-3.x\README.md
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 -->
+
 # cool-admin-3.x
 
 #### 介绍
 
-
 ## 前后端安装项目依赖
 
 推荐使用 `yarn`:
@@ -25,6 +25,12 @@ yarn
 yarn config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
 ```
 
+## 后端需要单独安装依赖 axios、node-xlsx
+
+- cd /home/cool/server
+- npm i axios
+- npm install node-xlsx --save
+
 ## 运行应用程序
 
 ```shell
@@ -34,4 +40,4 @@ yarn dev
 //表编码格式不一致导致报错解决办法
 //SHOW CREATE TABLE shuyou_rent_computer_usage;
 //ALTER TABLE shuyou_rent_computer_usage DEFAULT CHARACTER SET utf8mb4 COLLATE=utf8mb4_german2_ci;
-//ALTER TABLE shuyou_rent_computer_usage CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci;
+//ALTER TABLE shuyou_rent_computer_usage CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci;

+ 2 - 1
cool-admin-midway-master/README.md

@@ -1,7 +1,7 @@
 <!--
  * @Author: YKH
  * @Date: 2021-12-08 10:23:31
- * @LastEditTime: 2022-09-29 15:01:04
+ * @LastEditTime: 2022-10-08 17:27:22
  * @Description:
  * @FilePath: \cool-admin\cool-admin-midway-master\README.md
 -->
@@ -83,6 +83,7 @@ $ npm stop
 - cd /home/cool/server
 - npm i axios
 - // npm install qiniu
+  npm install node-xlsx --save
 
 - 前端
 - // yarn add spark-md5

+ 16 - 0
cool-admin-midway-master/src/app/comm/utils.ts

@@ -201,4 +201,20 @@ export class Utils {
     var d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate();
     return y + '-' + m + '-' + d;
   }
+  // 转换excle中导入的日期格式
+  excelFormatDate(numb, format) {
+    const time = new Date((numb - 1) * 24 * 3600000 + 1);
+    time.setFullYear(time.getFullYear() - 70);
+    const year = time.getFullYear() + '';
+    const month = time.getMonth() + 1 + '';
+    const date = time.getDate() + '';
+    if (format && format.length === 1) {
+      return year + format + month + format + date;
+    }
+    return (
+      year +
+      (parseInt(month) < 10 ? '0' + month : month) +
+      (parseInt(date) < 10 ? '0' + date : date)
+    );
+  }
 }

+ 129 - 31
cool-admin-midway-master/src/app/modules/shuyou/controller/admin/rent_computer.ts

@@ -1,15 +1,20 @@
 /*
  * @Author: YKH
  * @Date: 2021-12-08 10:26:27
- * @LastEditTime: 2022-10-03 20:47:49
+ * @LastEditTime: 2022-10-08 14:44:52
  * @Description:
  * @FilePath: \cool-admin-3.x\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\rent_computer.ts
  */
 import { ALL, Body, Inject, Post, Provide } from '@midwayjs/decorator';
-import { CoolController, BaseController } from 'midwayjs-cool-core';
+import {
+  CoolController,
+  BaseController,
+  CoolCommException,
+} from 'midwayjs-cool-core';
 import { ShuyouRentComputerEntity } from '../../entity/rent_computer';
 import { ShuyouRentComputerService } from '../../service/rent_computer';
 import { ILogger } from '@midwayjs/logger';
+import { Utils } from '../../../../comm/utils';
 // import xlsx from 'node-xlsx';
 // import fs from 'fs';
 
@@ -64,6 +69,9 @@ export class ShuyouRentComputerController extends BaseController {
   @Inject()
   ShuyouRentComputerService: ShuyouRentComputerService;
 
+  @Inject()
+  utils: Utils;
+
   // 换编
   @Post('/replaceNum')
   async replaceNum(@Body(ALL) queryObject) {
@@ -145,39 +153,129 @@ export class ShuyouRentComputerController extends BaseController {
         if (order == 0) {
           return;
         }
-        console.log(item[0]);
+        // console.log(item[0]);
+        const price_type_text = item[4];
+        let price_type;
+        let rent_price;
+        let rent_price_day = 0;
+        const array_price_type_text = price_type_text.split('元/');
+        if (
+          array_price_type_text.length < 2 &&
+          !isNaN(parseFloat(array_price_type_text[0])) &&
+          isFinite(array_price_type_text[0])
+        ) {
+          throw new CoolCommException('[收费标准]有错误项~');
+        }
+        if (array_price_type_text[1] == '月') {
+          price_type = 2;
+          rent_price = array_price_type_text[0];
+          rent_price_day = parseInt(rent_price) / 30;
+        } else if (array_price_type_text[1] == '周') {
+          price_type = 1;
+          rent_price = array_price_type_text[0];
+          rent_price_day = parseInt(rent_price) / 7;
+        } else {
+          price_type = 0;
+          rent_price = array_price_type_text[0];
+          rent_price_day = parseInt(rent_price);
+        }
         const set_meal = name + item[1];
+        let pay_method = 0;
+        if (name == '逍遥') {
+          pay_method = 1;
+        }
+        // this.logger.info(item[2]);
+        // this.logger.info(this.utils.excelFormatDate(item[2], '/'));
+        // throw new CoolCommException(this.utils.excelFormatDate(item[2], '/'));
         // pc_num,pc_name,rent_person_id,shop_id,set_meal,rent_start,rent_duration,rent_end,price_type,rent_price,rent_price_day,pay_method,is_expire
-        info_text =
-          `('` +
-          item[0] +
-          `',` +
-          `'` +
-          item[0] +
-          `',` +
-          `'` +
-          rent_person_id +
-          `',` +
-          `'` +
-          shop_id +
-          `',` +
-          `'` +
-          set_meal +
-          `',` +
-          `'` +
-          item[2] +
-          `',` +
-          `'` +
-          item[5] +
-          `',` +
-          `'` +
-          item[3] +
-          `',` +
-          `'` +
-          item[0] +
-          `')`;
+        if (index == 0 && order == 1) {
+          info_text =
+            `('` +
+            item[0] +
+            `',` +
+            `'` +
+            item[0] +
+            `',` +
+            `'` +
+            rent_person_id +
+            `',` +
+            `'` +
+            shop_id +
+            `',` +
+            `'` +
+            set_meal +
+            `',` +
+            `'` +
+            this.utils.excelFormatDate(item[2], '/') +
+            `',` +
+            `'` +
+            item[5] +
+            `',` +
+            `'` +
+            this.utils.excelFormatDate(item[3], '/') +
+            `',` +
+            `'` +
+            price_type +
+            `',` +
+            `'` +
+            rent_price +
+            `',` +
+            `'` +
+            rent_price_day +
+            `',` +
+            `'` +
+            pay_method +
+            `',` +
+            `'0')`;
+        } else {
+          info_text +=
+            `,('` +
+            item[0] +
+            `',` +
+            `'` +
+            item[0] +
+            `',` +
+            `'` +
+            rent_person_id +
+            `',` +
+            `'` +
+            shop_id +
+            `',` +
+            `'` +
+            set_meal +
+            `',` +
+            `'` +
+            this.utils.excelFormatDate(item[2], '/') +
+            `',` +
+            `'` +
+            item[5] +
+            `',` +
+            `'` +
+            this.utils.excelFormatDate(item[3], '/') +
+            `',` +
+            `'` +
+            price_type +
+            `',` +
+            `'` +
+            rent_price +
+            `',` +
+            `'` +
+            rent_price_day +
+            `',` +
+            `'` +
+            pay_method +
+            `',` +
+            `'0')`;
+        }
       });
     });
+    // this.logger.warn(info_text);
+    let reqmsg = await this.ShuyouRentComputerService.batchAdd(info_text);
+    // this.logger.info('本次导入成功' + reqmsg.affectedRows + '条');
+    return this.ok({
+      code: 1,
+      message: '本次导入成功' + reqmsg.affectedRows + '条',
+    });
   }
 }
 // foreach加上async/await

+ 7 - 8
cool-admin-midway-master/src/app/modules/shuyou/controller/admin/rent_computer_shop.ts

@@ -1,7 +1,7 @@
 /*
  * @Author: YKH
  * @Date: 2022-09-01 14:20:37
- * @LastEditTime: 2022-09-02 22:38:57
+ * @LastEditTime: 2022-10-08 13:35:01
  * @Description: file content
  * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\rent_computer_shop.ts
  */
@@ -21,13 +21,13 @@ import { ShuyouRentComputerShopService } from '../../service/rent_computer_shop'
   // 设置表实体
   entity: ShuyouRentComputerShopEntity,
   service: ShuyouRentComputerShopService,
-  
+
   before: ctx => {
     //前段数据转JSON格式
-    
+
     const data = ctx.request.body;
-    if(data.name == ""){
-      data.name = null
+    if (data.name == '') {
+      data.name = null;
     }
     ctx.request.body.data = JSON.stringify(data);
   },
@@ -36,8 +36,7 @@ import { ShuyouRentComputerShopService } from '../../service/rent_computer_shop'
     // 让字段支持模糊查询
     keyWordLikeFields: ['name'],
     // 让字段支持筛选
-    fieldEq: ['name']
+    fieldEq: ['name'],
   },
 })
-export class ShuyouRentComputerShopController extends BaseController {
-}
+export class ShuyouRentComputerShopController extends BaseController {}

+ 11 - 17
cool-admin-midway-master/src/app/modules/shuyou/controller/admin/utils.ts

@@ -1,8 +1,8 @@
 /*
  * @Author: YKH
  * @Date: 2021-12-11 21:34:38
- * @LastEditTime: 2022-06-27 16:36:43
- * @Description: 
+ * @LastEditTime: 2022-10-08 13:31:10
+ * @Description:
  * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\utils.ts
  */
 import { ALL, Body, Get, Inject, Post, Provide } from '@midwayjs/decorator';
@@ -11,7 +11,6 @@ import { BaseController, CoolController } from 'midwayjs-cool-core';
 import { ShuyouUtilsService } from '../../service/utils';
 import { ShuyouXJFUtilsService } from '../../service/utils_xjf';
 
-
 @Provide()
 @CoolController()
 export class ShuyouAdminUtilsController extends BaseController {
@@ -27,7 +26,7 @@ export class ShuyouAdminUtilsController extends BaseController {
   /**
    *
    *http://127.0.0.1:8001/app/shuyou/utils/getWeatherCD
-   * @return {*} 
+   * @return {*}
    * @memberof ShuyouAdminUtilsController
    */
   @Get('/getWeatherCD')
@@ -40,18 +39,17 @@ export class ShuyouAdminUtilsController extends BaseController {
     }
   }
 
-
   //TODO
   /**
    *查询当前付费失败的账号
    *
-   * @return {*} 
+   * @return {*}
    * @memberof ShuyouAdminUtilsController
    */
   @Post('/payFailed')
   async payFailed(@Body(ALL) queryObject) {
     const { task_id } = queryObject;
-    let list
+    let list;
     list = await this.ShuyouXJFUtilsService.payFailed(task_id);
     if (list.code == 1) {
       if (list.data == 'null') {
@@ -64,15 +62,15 @@ export class ShuyouAdminUtilsController extends BaseController {
     }
   }
   /**
-     *查询今日可付费账号
-     *
-     * @return {*} 
-     * @memberof ShuyouAdminUtilsController
-     */
+   *查询今日可付费账号
+   *
+   * @return {*}
+   * @memberof ShuyouAdminUtilsController
+   */
   @Post('/unpaid')
   async unpaid(@Body(ALL) queryObject) {
     const { task_id } = queryObject;
-    let list
+    let list;
     list = await this.ShuyouXJFUtilsService.unpaid(task_id);
     if (list.code == 1) {
       if (list.data == 'null') {
@@ -84,8 +82,4 @@ export class ShuyouAdminUtilsController extends BaseController {
       return this.fail('无法获取信息', -1);
     }
   }
-
-
-
-
 }

+ 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-27 16:57:15
+ * @LastEditTime: 2022-10-08 13:37:43
  * @Description: file content
  * @FilePath: \cool-admin-3.x\cool-admin-midway-master\src\app\modules\shuyou\entity\rent_computer.ts
  */

+ 16 - 1
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-29 18:17:45
+ * @LastEditTime: 2022-10-08 14:01:08
  * @Description:
  * @FilePath: \cool-admin-3.x\cool-admin-midway-master\src\app\modules\shuyou\service\rent_computer.ts
  */
@@ -469,6 +469,21 @@ export class ShuyouRentComputerService extends BaseService {
       return { code: 1000, data: '该租机无变化' };
     }
   }
+  /***
+   * 批量插入数据库
+   */
+  async batchAdd(info: any) {
+    let info_text = info;
+    const sqlBatchAdd =
+      `
+        insert 
+          IGNORE into 
+          shuyou_rent_computer (pc_num,pc_name,rent_person_id,shop_id,set_meal,rent_start,rent_duration,rent_end,price_type,rent_price,rent_price_day,pay_method,is_expire) 
+          values 
+      ` + info_text;
+    // console.log(sqlBatchAdd)
+    return await this.nativeQuery(sqlBatchAdd);
+  }
 }
 
 // foreach加上async/await

+ 1 - 1
cool-admin-midway-master/src/app/modules/shuyou/service/utils.ts

@@ -1,7 +1,7 @@
 /*
  * @Author: YKH
  * @Date: 2021-12-11 21:36:52
- * @LastEditTime: 2022-10-04 19:57:52
+ * @LastEditTime: 2022-10-08 14:10:16
  * @Description:
  * @FilePath: \cool-admin-3.x\cool-admin-midway-master\src\app\modules\shuyou\service\utils.ts
  */

+ 5 - 9
cool-admin-vue-vue3-ts-vite/src/cool/modules/shuyou/views/rent_computer.vue

@@ -8,7 +8,7 @@
 			>
 
 			<el-button type="primary" size="mini"
-				><a class="aa" href="http://127.0.0.1:8001//uploads/模板文件/租机模板.xlsx"
+				><a class="aa" href="http://139.155.68.174:8888/down/e5VpdUAz7GLV"
 					><slot>下载模板</slot></a
 				></el-button
 			>
@@ -1063,14 +1063,10 @@ export default defineComponent({
 					console.log(data);
 					visible_import.value = false;
 					loading.close();
-					// if (data.code == -1) {
-					// 	ElMessage.success(data.message);
-					// } else {
-					// 	ElMessage.success(data.message);
-					// }
-					// ElMessageBox.alert(data.message, "提示", {
-					// 	confirmButtonText: "关闭"
-					// });
+					ElMessageBox.alert(data.message, "提示", {
+						confirmButtonText: "关闭"
+					});
+					refs.value.crud.refresh();
 				})
 				.catch((err: string) => {
 					loading.close();