| package com.xzx.gc.user.controller; | 
|   | 
| import cn.hutool.core.collection.CollUtil; | 
| import cn.hutool.core.date.DateUtil; | 
| import cn.hutool.core.io.FileUtil; | 
| import cn.hutool.core.thread.ThreadUtil; | 
| import cn.hutool.core.util.ArrayUtil; | 
| import cn.hutool.core.util.StrUtil; | 
| import cn.hutool.core.util.ZipUtil; | 
| import cn.hutool.poi.excel.ExcelReader; | 
| import cn.hutool.poi.excel.ExcelUtil; | 
| import com.xzx.gc.common.Result; | 
| import com.xzx.gc.common.exception.RestException; | 
| import com.xzx.gc.common.utils.DateUtils; | 
| import com.xzx.gc.entity.ResourceInfo; | 
| import com.xzx.gc.entity.UserInfo; | 
| import com.xzx.gc.user.service.UserService; | 
| import com.xzx.gc.user.service.PosterService; | 
| import io.swagger.annotations.Api; | 
| import io.swagger.annotations.ApiOperation; | 
| import io.swagger.annotations.ApiParam; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.validation.annotation.Validated; | 
| import org.springframework.web.bind.annotation.*; | 
| import org.springframework.web.multipart.MultipartFile; | 
|   | 
| import javax.servlet.http.HttpServletRequest; | 
| import java.io.File; | 
| import java.io.IOException; | 
| import java.util.*; | 
| import java.util.concurrent.CountDownLatch; | 
| import java.util.concurrent.ExecutionException; | 
|   | 
|   | 
| @RestController | 
| @RequestMapping("/poster") | 
| @Validated | 
| @Slf4j | 
| @Api(tags = "海报管理") | 
| public class ImageController { | 
|   | 
|   | 
|     @Autowired | 
|     private PosterService posterService; | 
|   | 
|     @Autowired | 
|     private UserService userService; | 
|   | 
| //    @ApiOperation("生成海报图") | 
| //    @PostMapping(value = "/create") | 
| //    @ResponseBody | 
| //    public Result<List<ResourceInfo>> upload(HttpServletRequest request,@ApiParam("上传文件") @RequestParam(name = "file") MultipartFile file,@ApiParam(value = "生成路径目录",defaultValue = "c:") @RequestParam(name = "path") String path,@ApiParam(value = "生成压缩包名称,X代表用文件名") @RequestParam(name = "zipRealName",required = false) String zipRealName) throws IOException, ExecutionException, InterruptedException { | 
| //        Result result=new Result(); | 
| //        if(!FileUtil.exist(path)||!FileUtil.isDirectory(path)){ | 
| //            return Result.error(-1,"目录不存在或者不是一个目录"); | 
| //        } | 
| //        ExcelReader reader = ExcelUtil.getReader(file.getInputStream()); | 
| //        List<Map<String, Object>> maps = reader.readAll(); | 
| // | 
| //        if(CollUtil.isNotEmpty(maps)){ | 
| //            List<File> list=new ArrayList<>(); | 
| //            CountDownLatch countDownLatch = ThreadUtil.newCountDownLatch(maps.size()); | 
| // | 
| //            for (Map<String, Object> map : maps) { | 
| //                String next = map.keySet().iterator().next(); | 
| //                Long mobile = (Long) map.get(next); | 
| //                if(mobile!=null){ | 
| //                    UserInfo byMobile = userService.findByMobileTest(mobile.toString()); | 
| //                    if(byMobile!=null){ | 
| //                        Runnable callable=()->{ | 
| //                            Map<String, String> generate = posterService.generateByUi(byMobile); | 
| //                            list.add(new File(generate.get("uploadUrl"))); | 
| //                            countDownLatch.countDown(); | 
| //                        }; | 
| //                        ThreadUtil.execAsync(callable,true); | 
| //                    }else { | 
| //                        throw new RestException(-1,"用户:"+mobile+"未注册"); | 
| //                    } | 
| //                } | 
| //            } | 
| // | 
| //            countDownLatch.await(); | 
| // | 
| //            if(CollUtil.isNotEmpty(list)){ | 
| //                String zipName=DateUtil.format(new Date(),DateUtils.DATE_FORMAT_YMDHMS_LINE); | 
| //                if(StrUtil.isNotBlank(zipRealName)){ | 
| //                    if("X".equals(zipRealName)){ | 
| //                        zipName=  StrUtil.subBefore(file.getOriginalFilename(),".",false); | 
| //                    }else { | 
| //                        zipName = StrUtil.removeSuffix(zipRealName, ".zip"); | 
| //                    } | 
| //                } | 
| //                String s = path + "/" + zipName + ".zip"; | 
| // | 
| // | 
| //                ZipUtil.zip(FileUtil.file(s), false,ArrayUtil.toArray(list,File.class)); | 
| //                result.setMsg("生成海报成功,压缩包路径:"+s); | 
| //                result.setCode(0); | 
| //                return result; | 
| //            } | 
| // | 
| //        } | 
| //        return Result.error(-1,"上传文件是空的"); | 
| //    } | 
|   | 
| } |