Administrator
2018-10-30 7bf6a0582c7c62c90ee2ed8a88654f11d0479092
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
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
package com.yeshi.fanli.controller.admin;
 
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.UUID;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
import com.yeshi.fanli.service.inter.order.OrderProcessService;
import com.yeshi.fanli.service.inter.order.OrderService;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.tencentcloud.COSManager;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("admin/new/api/v1/upload")
public class UploadController {
 
    @Resource
    private HongBaoService hongBaoService;
 
    @Resource
    private OrderService orderService;
 
    @Resource
    private OrderProcessService orderProcessService;
 
    // private static final String PAYSUCCESS = "支付成功";
    // private static final String ORDERCLOSE="订单关闭";
    // private static final String REFUNDSTETA = "Y";
 
    // private static final String ORDERSUCCESS = "订单成功";
    // private static final String ORDERSETTLEMENT = "订单结算";
    // private static final String ORDERPAYMENT = "订单付款";
    // private static final String ORDERFAILURE = "订单失效";
 
    @RequestMapping(value = "uploadImg", method = RequestMethod.POST)
    public void uploadImg(@RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
        try {
            InputStream inputStream = file.getInputStream();
            String contentType = file.getContentType();
            String type = contentType.substring(contentType.indexOf("/") + 1);
            String uploadFilePath = COSManager.getInstance().uploadFile(inputStream,
                    UUID.randomUUID().toString().replace("-", "") + "." + type).getUrl();
            out.print(JsonUtil.loadTrueResult(uploadFilePath));
        } catch (IOException e) {
            e.printStackTrace();
            out.print(JsonUtil.loadFalseResult(e.getMessage()));
        }
    }
 
    /**
     * 
     * 方法说明: 上传Apk安装包
     * 
     * @author mawurui createTime 2018年4月12日 上午11:54:29
     * @param file
     * @param out
     */
    @RequestMapping(value = "uploadInstallApk")
    public void uploadInstallApk(@RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
        try {
            InputStream inputStream = file.getInputStream();
            String contentType = file.getContentType();
            String type = contentType.substring(contentType.indexOf("/") + 1);
            String uploadFilePath = COSManager.getInstance().uploadFile(inputStream,
                    UUID.randomUUID().toString().replace("-", "") + "." + type + ".apk").getUrl();
            out.print(JsonUtil.loadTrueResult(uploadFilePath));
        } catch (Exception e) {
            e.printStackTrace();
            out.print(JsonUtil.loadFalseResult(e.getMessage()));
        }
    }
 
    @RequestMapping(value = "uploadfImg")
    public void uploadfImg(@RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
        try {
            InputStream inputStream = file.getInputStream();
            long timeMillis = System.currentTimeMillis();
            String date = TimeUtil.getyyyyMMdd(timeMillis);
            String contentType = file.getContentType();
            String type = contentType.substring(contentType.indexOf("/") + 1);
            String uploadFilePath = COSManager.getInstance().uploadFile(inputStream,
                    "section/" + date + "/" + timeMillis + "." + type).getUrl();
            JSONObject data = new JSONObject();
            data.put("original", file.getOriginalFilename());
            data.put("name", file.getOriginalFilename());
            data.put("url", uploadFilePath);
            data.put("size", file.getSize() + "");
            data.put("type", "." + type);
            data.put("state", "SUCCESS");
            out.print(data);
 
        } catch (Exception e) {
            e.printStackTrace();
            out.print(JsonUtil.loadFalseResult(e.getMessage()));
        }
    }
 
    @RequestMapping(value = "uploadOrder", method = RequestMethod.POST)
    public void uploadOrder(@RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
 
        if (file != null) {
            try {
                List<TaoBaoOrder> orderList = TaoBaoOrderUtil.parseOrder(file.getInputStream());
                orderProcessService.processOrder(TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(orderList));
            } catch (IOException e) {
                e.printStackTrace();
                out.print(JsonUtil.loadFalseResult(e.getMessage()));
                return;
            }
            out.print(JsonUtil.loadTrueResult(""));
            return;
        }
        out.print(JsonUtil.loadFalseResult("文件不能为空!"));
 
    }
 
}