|
@@ -1,32 +1,40 @@
|
|
|
package com.fdkankan.sale.controller;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.dtflys.forest.annotation.Post;
|
|
|
+import com.fdkankan.sale.common.ResultCode;
|
|
|
import com.fdkankan.sale.common.ResultData;
|
|
|
+import com.fdkankan.sale.entity.Camera;
|
|
|
+import com.fdkankan.sale.entity.CameraDetail;
|
|
|
+import com.fdkankan.sale.exception.BusinessException;
|
|
|
+import com.fdkankan.sale.service.ICameraDetailService;
|
|
|
+import com.fdkankan.sale.service.ICameraService;
|
|
|
import com.fdkankan.sale.service.IPriceListService;
|
|
|
import com.fdkankan.sale.service.ISysUserService;
|
|
|
import com.fdkankan.sale.service.impl.RepairInfoService;
|
|
|
+import com.fdkankan.sale.util.ExcelUtil;
|
|
|
import com.fdkankan.sale.util.OrderListVo;
|
|
|
import com.fdkankan.sale.util.pdf.PdfUtil;
|
|
|
import com.fdkankan.sale.util.pdf.PdfUtils;
|
|
|
import com.fdkankan.sale.vo.response.PriceListExcelVo;
|
|
|
import com.itextpdf.text.DocumentException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/test")
|
|
|
+@Slf4j
|
|
|
public class TestController {
|
|
|
|
|
|
@Autowired
|
|
@@ -37,6 +45,11 @@ public class TestController {
|
|
|
IPriceListService priceListService;
|
|
|
@Autowired
|
|
|
RepairInfoService repairInfoService;
|
|
|
+ @Autowired
|
|
|
+ ICameraService cameraService;
|
|
|
+ @Autowired
|
|
|
+ ICameraDetailService cameraDetailService;
|
|
|
+
|
|
|
|
|
|
@GetMapping("/test1")
|
|
|
public ResultData test1(HttpServletResponse response) throws IOException, DocumentException {
|
|
@@ -114,4 +127,57 @@ public class TestController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/reCameraBuyDate")
|
|
|
+ public ResultData reCameraBuyDate(@RequestParam(required = false) MultipartFile file) throws IOException {
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ assert originalFilename != null;
|
|
|
+ String fileType=originalFilename.substring(originalFilename.lastIndexOf(".")+1);
|
|
|
+ if (!fileType.equalsIgnoreCase("xlsx")) {
|
|
|
+ throw new BusinessException(-1,"文件错误");
|
|
|
+ }
|
|
|
+ for(int i = 0; i<=5; i++){
|
|
|
+ List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file,i);
|
|
|
+ this.updateBuyDate(excelRowList);
|
|
|
+ }
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateBuyDate(List<HashMap<Integer, String>> excelRowList){
|
|
|
+ Date parse = null;
|
|
|
+ String date = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+ for (HashMap<Integer, String> map : excelRowList) {
|
|
|
+ if(map.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ date = map.get(0);
|
|
|
+ String snCode = map.get(1);
|
|
|
+ Camera camera = cameraService.getBySnCode(snCode);
|
|
|
+ if(camera == null){
|
|
|
+ log.info("db-not-in:snCode:{}",snCode);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(date)){
|
|
|
+ log.info("excel-not-in:date:{}",date);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ parse = new SimpleDateFormat("yyyy/MM/dd").parse(date);
|
|
|
+ }catch ( Exception e){
|
|
|
+ parse = new SimpleDateFormat("yyyy.MM.dd").parse(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(parse != null){
|
|
|
+ CameraDetail cameraDetail = cameraService.getCameraTypeByCameraId(camera.getId());
|
|
|
+ cameraDetail.setBuyDate(parse);
|
|
|
+ cameraService.updateDetail(cameraDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("excel-error-in:date:{}",date);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|