管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-07 8d7a67ab1d635cb954337d8a767878ae526dd3dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
using ExportMap.cs;
using ExportMap.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using System.Diagnostics;
using System.Threading;
 
namespace ExportMap.Controllers
{
    public class TBController : ApiController
    {
        [HttpGet]
        public ResponseMsg<string> CreateMpt(string path, string token)
        {
            try
            {
                if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(token)) return ResponseMsg<string>.fail("path和token参数不能为空");
 
                if (!ExportUtil.VerifyToken(token)) return ResponseMsg<string>.fail("令牌无效");
 
                if (!Directory.Exists(path)) return ResponseMsg<string>.fail("文件路径不存在");
 
                string err = null;
                string rs = TBUtils.CreateMpt(path, ref err);
 
                if (string.IsNullOrEmpty(rs)) return ResponseMsg<string>.fail(null == err ? "失败" : err);
 
                return ResponseMsg<string>.success("成功", rs, 1);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return ResponseMsg<string>.fail(ex.Message);
            }
        }
 
        [HttpGet] // http://localhost/ExportMap/TB/Test
        public ResponseMsg<string> Test()
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                string err = null;
                bool rs = TBUtils.Test(ref err);
                sw.Stop();
 
                return ResponseMsg<string>.success((rs ? "成功" : "失败") + ",耗时:" + sw.ElapsedMilliseconds / 1000.0 + " s", rs.ToString());
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return ResponseMsg<string>.fail(ex.Message);
            }
        }
 
        [HttpGet] // http://localhost/ExportMap/TB/Wait?seconds=10
        public ResponseMsg<string> Wait(long seconds)
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
 
                Thread.Sleep(new TimeSpan(seconds * 10 * 1000 * 1000));
 
                sw.Stop();
 
                return ResponseMsg<string>.success("成功", "耗时:" + sw.ElapsedMilliseconds / 1000.0 + " s");
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return ResponseMsg<string>.fail(ex.Message);
            }
        }
    }
}