Pu Zhibing
19 小时以前 d0d6f8f40e5d9762d940b47c566da1876361020e
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/system/UserMgrController.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.heredata.hos.model.bucket.Bucket;
import com.stylefeng.guns.config.properties.GunsProperties;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.Tip;
@@ -33,6 +34,8 @@
import com.stylefeng.guns.modular.system.transfer.UserDto;
import com.stylefeng.guns.modular.system.util.OssUploadUtil;
import com.stylefeng.guns.modular.system.util.huawei.OBSUtil;
import com.stylefeng.guns.modular.system.util.qianyuntong.NCOSSUtil;
import com.stylefeng.guns.modular.system.util.qianyuntong.QianYunTongConfig;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -74,6 +77,9 @@
    private ITAgentService agentService;
    @Autowired
    private ITBranchOfficeService branchOfficeService;
    @Autowired
    private QianYunTongConfig qianYunTongConfig;
    /**
@@ -423,21 +429,31 @@
    @RequestMapping("/saveApk")
    public String saveApk(@RequestPart("myfile") MultipartFile file, HttpServletRequest request){
        Map<String, Object> m = new HashMap<>();
        QianYunTongConfig qianYunTongConfig1 = qianYunTongConfig.getQianYunTongConfig();
        try {
            String pictureName = UUID.randomUUID().toString() + "." + ToolUtil.getFileSuffix(file.getOriginalFilename());
            try {
                String fileSavePath = gunsProperties.getFileUploadPath()+"apk\\";
                InputStream inputStream = file.getInputStream();
                String name1 = file.getOriginalFilename();
                name1 = UUIDUtil.getRandomCode() + name1.substring(name1.lastIndexOf("."));
                String s = OBSUtil.putObjectToBucket(inputStream, name1);
//                String s = OssUploadUtil.ossUpload(request, file);
                // file.transferTo(new File(fileSavePath + pictureName));
                return s;
            } catch (Exception e) {
                e.printStackTrace();
            String bucketName = qianYunTongConfig1.getBucketName();
            Bucket grjyTest = NCOSSUtil.getBucketInfo(bucketName);
            if (null == grjyTest) {
                //创建桶
                Boolean bucket = NCOSSUtil.createBucket(bucketName);
                if (!bucket) {
                    throw new RuntimeException("创建存储桶失败");
                }
                //设置桶策略
                String policyText = "{\"Version\":\"2025-06-23\",\"Statement\":[{\"Sid\":\"Stmt20250623\",\"Action\":[\"GetObject\"],\"Effect\":\"Allow\",\"Resource\":\"" + bucketName + "/*\",\"Principal\":\"*\"}]}";
                Boolean bucketPolicy = NCOSSUtil.setBucketPolicy(bucketName, policyText);
                if (!bucketPolicy) {
                    throw new RuntimeException("设置桶策略失败");
                }
            }
            m.put("imgUrl", gunsProperties.getFileUploadPath()+"apk/"+pictureName);
            //上传对象
            String key = "apk/" + pictureName;
            String object = NCOSSUtil.putObject(bucketName, key, file.getInputStream());
            if (null == object) {
                throw new RuntimeException("上传图片失败");
            }
            m.put("imgUrl", "https://traffic.qytzt.cn/v1/AUTH_" + qianYunTongConfig1.getAccount() + "/" + bucketName + "/" + key);
        } catch (Exception e) {
            e.printStackTrace();
        }