|
|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.xpyy.xpyy.entity.Mplan;
|
|
|
import com.xpyy.xpyy.entity.User;
|
|
|
import com.xpyy.xpyy.entity.Vendor;
|
|
|
+import com.xpyy.xpyy.entity.VendorFiles;
|
|
|
import com.xpyy.xpyy.excel.ExcelUtils;
|
|
|
import com.xpyy.xpyy.service.VendorService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -16,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
@@ -152,49 +154,58 @@ public class VendorController {
|
|
|
vendorService.VendorListExport(vendor, response);
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 我的供应商列表导入
|
|
|
-// * @param file 文件
|
|
|
-// * @param request 参数
|
|
|
-// * @throws Exception
|
|
|
-// */
|
|
|
-// @PostMapping("/import")
|
|
|
-// @Transactional(rollbackFor = Exception.class)
|
|
|
-// public Map<String, Object> importExcel(@RequestPart("file") MultipartFile file, HttpServletRequest request) throws Exception{
|
|
|
-// Map<String, Object> map = new HashMap<>();
|
|
|
-// JSONArray array = ExcelUtils.readMultipartFile(file);
|
|
|
-// for(int i = 0; i < array.size(); i++){
|
|
|
-// JSONObject jsonObject = array.getJSONObject(i);
|
|
|
-// //查询供应商
|
|
|
-// String cVenCode = vendorService.getVenCode(jsonObject.get("供应商ID").toString());
|
|
|
-// //查询物料 ERP CODE
|
|
|
-// String ErpCode = vendorService.getErpCode(jsonObject.get("ERP CODE").toString());
|
|
|
-// //查询 供应商是否绑定次物料
|
|
|
-// String ErpCode = vendorService.getErpCode(jsonObject.get("ERP CODE").toString());
|
|
|
-//// Mplan mplan = new Mplan();
|
|
|
-//// mplan.setCusCode(CusCode);
|
|
|
-//// mplan.setModeCode(ModeCode);
|
|
|
-//// mplan.setPlanNum(jsonObject.get("数量").toString());
|
|
|
-//// mplan.setPlandate(jsonObject.get("日期").toString());
|
|
|
-//
|
|
|
-// if (CusCode == null || CusCode.equals("")){
|
|
|
-// System.out.println("客户不存在,请录入客户信息");
|
|
|
-// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
|
|
-// map.put("msg", "500");
|
|
|
-// map.put("errMsg", "客户不存在,请录入客户信息");
|
|
|
-// return map;
|
|
|
-// }
|
|
|
-// if (ModeCode == null || ModeCode.equals("")){
|
|
|
-// System.out.println("客户没有录入改型号信息,请录入客户型号信息");
|
|
|
-// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();////事务回滚
|
|
|
-// map.put("msg", "500");
|
|
|
-// map.put("errMsg", "客户没有录入改型号信息,请录入客户型号信息");
|
|
|
-// return map;
|
|
|
-// }
|
|
|
-// mplanService.importExcel(mplan,request);
|
|
|
-// }
|
|
|
-// map.put("msg", "200");
|
|
|
-// map.put("data", array.size());
|
|
|
-// return map;
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * 我的供应商列表导入
|
|
|
+ * @param file 文件
|
|
|
+ * @param request 参数
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/import")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map<String, Object> importExcel(@RequestPart("file") MultipartFile file, HttpServletRequest request) throws Exception{
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ JSONArray array = ExcelUtils.readMultipartFile(file);
|
|
|
+ for(int i = 0; i < array.size(); i++){
|
|
|
+ JSONObject jsonObject = array.getJSONObject(i);
|
|
|
+ //查询供应商
|
|
|
+ String cVenCode = vendorService.getVenCode(jsonObject.get("供应商ID").toString());
|
|
|
+ //查询物料 ERP CODE
|
|
|
+ String ErpCode = vendorService.getErpCode(jsonObject.get("ERP CODE").toString());
|
|
|
+ //查询 供应商是否绑定次物料
|
|
|
+ List<Vendor> list = vendorService.getErpCodeList(jsonObject.get("供应商ID").toString(),jsonObject.get("ERP CODE").toString());
|
|
|
+ if (cVenCode == null || cVenCode.equals("")){
|
|
|
+ System.out.println("供应商不存在,请录入供应商信息");
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
|
|
+ map.put("msg", "510");
|
|
|
+ map.put("errMsg", "供应商不存在,请录入供应商信息");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (ErpCode == null || ErpCode.equals("")){
|
|
|
+ System.out.println("物料没有录入,请录入物料信息");
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();////事务回滚
|
|
|
+ map.put("msg", "510");
|
|
|
+ map.put("errMsg", "物料没有录入,请录入物料信息");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (list.size() > 0){
|
|
|
+ System.out.println("供应商已绑定该物料信息");
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
|
|
+ map.put("msg", "510");
|
|
|
+ map.put("errMsg", "供应商已绑定该物料信息");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ Vendor vendor = new Vendor();
|
|
|
+ vendor.setcVenCode(jsonObject.get("供应商ID").toString());
|
|
|
+ vendor.setcVenName(jsonObject.get("供应商名称").toString());
|
|
|
+ vendor.setErpCode(jsonObject.get("ERP CODE").toString());
|
|
|
+ vendor.setPcode(jsonObject.get("图纸号").toString());
|
|
|
+ vendor.setPrice(jsonObject.get("单价").toString());
|
|
|
+ vendor.setdVenCreateDate(jsonObject.get("准入日期").toString());
|
|
|
+ vendor.setSupDays(jsonObject.get("供货周期").toString());
|
|
|
+ vendorService.importExcel(vendor,request);
|
|
|
+ }
|
|
|
+ map.put("msg", "200");
|
|
|
+ map.put("data", array.size());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|