|
@@ -1,20 +1,33 @@
|
|
|
package com.fdkankan.agent.controller;
|
|
|
|
|
|
|
|
|
+import com.alibaba.nacos.common.codec.Base64;
|
|
|
import com.fdkankan.agent.common.BaseController;
|
|
|
+import com.fdkankan.agent.common.ResultCode;
|
|
|
import com.fdkankan.agent.common.ResultData;
|
|
|
import com.fdkankan.agent.common.util.JwtUtil;
|
|
|
import com.fdkankan.agent.entity.AgentNew;
|
|
|
+import com.fdkankan.agent.exception.BusinessException;
|
|
|
import com.fdkankan.agent.request.CameraParam;
|
|
|
import com.fdkankan.agent.service.IAgentNewCameraService;
|
|
|
import com.fdkankan.agent.service.IAgentNewService;
|
|
|
import com.fdkankan.agent.service.ICameraService;
|
|
|
+import com.fdkankan.agent.service.IExcelService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -36,7 +49,8 @@ public class CameraController extends BaseController {
|
|
|
IAgentNewService agentNewService;
|
|
|
@Autowired
|
|
|
IAgentNewCameraService agentNewCameraService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ IExcelService excelService;
|
|
|
|
|
|
@PostMapping("/list")
|
|
|
public ResultData list(@RequestBody CameraParam param){
|
|
@@ -49,7 +63,11 @@ public class CameraController extends BaseController {
|
|
|
|
|
|
@PostMapping("/giveCamera")
|
|
|
public ResultData giveCamera(@RequestBody CameraParam param){
|
|
|
- agentNewCameraService.giveCamera(param,getAgent().getId());
|
|
|
+ if(param.getId() == null || param.getSubAgentId() == null){
|
|
|
+ throw new BusinessException(ResultCode.PARAM_MISS);
|
|
|
+ }
|
|
|
+ param.setAgentId(getAgent().getId());
|
|
|
+ agentNewCameraService.giveCamera(param);
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
@@ -57,12 +75,37 @@ public class CameraController extends BaseController {
|
|
|
public ResultData giveCameraBatch(
|
|
|
@RequestParam(required = false) Integer subAgentId,
|
|
|
@RequestParam(required = false) MultipartFile file){
|
|
|
- return ResultData.ok();
|
|
|
+ Integer count = excelService.uploadExcel(file,getAgent().getId(),subAgentId);
|
|
|
+ return ResultData.ok("成功导入"+count+"条数据。");
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/downTemplate")
|
|
|
- public ResultData downTemplate(@RequestBody CameraParam param){
|
|
|
- return ResultData.ok();
|
|
|
+ @GetMapping("/downTemplate")
|
|
|
+ public void downInTemplate(@RequestParam(required = false,defaultValue = "0") Integer type,
|
|
|
+ HttpServletResponse res, HttpServletRequest req) throws IOException {
|
|
|
+ String fileName = "";
|
|
|
+ switch (type){
|
|
|
+ case 0 : fileName = "giveCamera.xlsx"; break;
|
|
|
+ default: throw new BusinessException(ResultCode.PARAM_MISS);
|
|
|
+ }
|
|
|
+ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/"+fileName);
|
|
|
+ OutputStream os = res.getOutputStream();
|
|
|
+ try {
|
|
|
+ String agent = req.getHeader("USER-AGENT");
|
|
|
+ if (agent != null && !agent.contains("MSIE") && !agent.contains("like Gecko")) {// FF
|
|
|
+ String enableFileName = "=?UTF-8?B?" + (new String(Base64.encodeBase64(fileName.getBytes(StandardCharsets.UTF_8))))
|
|
|
+ + "?=";
|
|
|
+ res.setHeader("Content-Disposition", "attachment; filename=" + enableFileName);
|
|
|
+ } else { // IE
|
|
|
+ String enableFileName = URLEncoder.encode(fileName, "UTF-8");
|
|
|
+ res.setHeader("Content-Disposition", "attachment; filename=" + enableFileName);
|
|
|
+ }
|
|
|
+ File file = new File(fileName);
|
|
|
+ FileUtils.copyInputStreamToFile(inputStream,file);
|
|
|
+ os.write(FileUtils.readFileToByteArray(file));
|
|
|
+ os.flush();
|
|
|
+ } finally {
|
|
|
+ os.close();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|