|  | @@ -19,6 +19,8 @@ import com.hwrj.cloud.common.api.CommonResult;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.core.io.ClassPathResource;
 | 
	
		
			
				|  |  | +import org.springframework.core.io.Resource;
 | 
	
		
			
				|  |  |  import org.springframework.util.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.validation.BindingResult;
 | 
	
		
			
				|  |  |  import org.springframework.validation.annotation.Validated;
 | 
	
	
		
			
				|  | @@ -26,8 +28,10 @@ import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  |  import org.springframework.web.multipart.MultipartFile;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletResponse;
 | 
	
		
			
				|  |  | -import java.io.IOException;
 | 
	
		
			
				|  |  | +import java.io.*;
 | 
	
		
			
				|  |  | +import java.net.URLEncoder;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Objects;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 商品管理Controller
 | 
	
	
		
			
				|  | @@ -76,7 +80,7 @@ public class PmsProductController {
 | 
	
		
			
				|  |  |      @ApiOperation("根据供应商选择生产地")
 | 
	
		
			
				|  |  |      @GetMapping(value = "/plOfPro/select")
 | 
	
		
			
				|  |  |      @ResponseBody
 | 
	
		
			
				|  |  | -    public CommonResult plOfProSelect(@RequestParam(value = "compId",required = false) Long compId) {
 | 
	
		
			
				|  |  | +    public CommonResult plOfProSelect(@RequestParam(value = "compId", required = false) Long compId) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<SelectVo> plOfProSelect = productService.plOfProSelect(compId);
 | 
	
		
			
				|  |  |          return CommonResult.success(plOfProSelect);
 | 
	
	
		
			
				|  | @@ -182,7 +186,7 @@ public class PmsProductController {
 | 
	
		
			
				|  |  |      @ApiOperation("通过id查询商品信息")
 | 
	
		
			
				|  |  |      @RequestMapping(value = "/getProductByProductId", method = RequestMethod.GET)
 | 
	
		
			
				|  |  |      @ResponseBody
 | 
	
		
			
				|  |  | -    public CommonResult<PmsProductOutput> getProductByProductId(@RequestParam("productId") Long productId ) {
 | 
	
		
			
				|  |  | +    public CommonResult<PmsProductOutput> getProductByProductId(@RequestParam("productId") Long productId) {
 | 
	
		
			
				|  |  |          PmsProductOutput pmsProduct = productService.getProductByProductId(productId);
 | 
	
		
			
				|  |  |          return CommonResult.success(pmsProduct);
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -194,4 +198,51 @@ public class PmsProductController {
 | 
	
		
			
				|  |  |          productService.importBasic(file);
 | 
	
		
			
				|  |  |          return CommonResult.success();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @PostMapping(value = "/out")
 | 
	
		
			
				|  |  | +    public void out(HttpServletResponse response) throws IOException {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //定义文件名和文件地址
 | 
	
		
			
				|  |  | +        String downloadUrl = "excel/model/productModel.xlsx";
 | 
	
		
			
				|  |  | +        Resource resource = null;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            //获取资源文件
 | 
	
		
			
				|  |  | +            resource = new ClassPathResource(downloadUrl);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            //自定义业务异常
 | 
	
		
			
				|  |  | +            throw new RuntimeException("导出模板失败!");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        byte[] buff = new byte[1024];
 | 
	
		
			
				|  |  | +        BufferedInputStream bis = null;
 | 
	
		
			
				|  |  | +        OutputStream os = null;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            // 配置文件下载
 | 
	
		
			
				|  |  | +            response.setHeader("content-type", "application/octet-stream");
 | 
	
		
			
				|  |  | +            response.setContentType("application/octet-stream");
 | 
	
		
			
				|  |  | +            // 下载文件能正常显示中文
 | 
	
		
			
				|  |  | +            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("商品导入模板.xlsx", "UTF-8"));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            os = response.getOutputStream();
 | 
	
		
			
				|  |  | +            bis = new BufferedInputStream(resource.getInputStream());
 | 
	
		
			
				|  |  | +            int i = bis.read(buff);
 | 
	
		
			
				|  |  | +            while (i != -1) {
 | 
	
		
			
				|  |  | +                os.write(buff, 0, buff.length);
 | 
	
		
			
				|  |  | +                os.flush();
 | 
	
		
			
				|  |  | +                i = bis.read(buff);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } catch (IOException e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  | +            throw new RuntimeException("文件下载出错!");
 | 
	
		
			
				|  |  | +        } finally {
 | 
	
		
			
				|  |  | +            if (bis != null) {
 | 
	
		
			
				|  |  | +                try {
 | 
	
		
			
				|  |  | +                    bis.close();
 | 
	
		
			
				|  |  | +                } catch (IOException e) {
 | 
	
		
			
				|  |  | +                    e.printStackTrace();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |