|
@@ -1,23 +1,35 @@
|
|
|
package org.jeecg.modules.saleCode.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
import io.micrometer.core.instrument.util.StringUtils;
|
|
|
+import io.swagger.annotations.ApiModelProperty;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
-import org.jeecg.modules.saleCode.entity.SaleInterfaceSync;
|
|
|
-import org.jeecg.modules.saleCode.entity.SaleInterfaceItem;
|
|
|
-import org.jeecg.modules.saleCode.mapper.SaleInterfaceItemMapper;
|
|
|
-import org.jeecg.modules.saleCode.mapper.SaleInterfaceSyncMapper;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.modules.baseCode.entity.BaseProductArchive;
|
|
|
+import org.jeecg.modules.baseCode.entity.BaseShipArchive;
|
|
|
+import org.jeecg.modules.baseCode.mapper.BaseProductArchiveMapper;
|
|
|
+import org.jeecg.modules.baseCode.service.IBaseProductArchiveService;
|
|
|
+import org.jeecg.modules.baseCode.service.IBaseShipArchiveService;
|
|
|
+import org.jeecg.modules.baseCode.service.ISerialPatternService;
|
|
|
+import org.jeecg.modules.cuspCode.entity.CuspCustomerProfile;
|
|
|
+import org.jeecg.modules.cuspCode.service.ICuspCustomerProfileService;
|
|
|
+import org.jeecg.modules.saleCode.entity.*;
|
|
|
+import org.jeecg.modules.saleCode.mapper.*;
|
|
|
import org.jeecg.modules.saleCode.service.ISaleInterfaceSyncService;
|
|
|
import org.jeecg.modules.saleCode.util.HttpUtils;
|
|
|
+import org.jeecgframework.poi.excel.annotation.Excel;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.Instant;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -34,6 +46,23 @@ public class SaleInterfaceSyncServiceImpl extends ServiceImpl<SaleInterfaceSyncM
|
|
|
private SaleInterfaceSyncMapper saleInterfaceSyncMapper;
|
|
|
@Autowired
|
|
|
private SaleInterfaceItemMapper saleInterfaceItemMapper;
|
|
|
+ @Autowired
|
|
|
+ private ICuspCustomerProfileService cuspCustomerProfileService;
|
|
|
+ @Autowired
|
|
|
+ private ISerialPatternService serialPatternService;
|
|
|
+ @Autowired
|
|
|
+ private IBaseShipArchiveService baseShipArchiveService;
|
|
|
+ @Autowired
|
|
|
+ private SaleInquiryFormShipMapper saleInquiryFormShipMapper;
|
|
|
+ @Autowired
|
|
|
+ private SaleInquiryFormProductMapper saleInquiryFormProductMapper;
|
|
|
+ @Autowired
|
|
|
+ private SaleInquiryFormMapper saleInquiryFormMapper;
|
|
|
+ @Autowired
|
|
|
+ private IBaseProductArchiveService baseProductArchiveService;
|
|
|
+ @Autowired
|
|
|
+ private BaseProductArchiveMapper baseProductArchiveMapper;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -44,17 +73,17 @@ public class SaleInterfaceSyncServiceImpl extends ServiceImpl<SaleInterfaceSyncM
|
|
|
JsonNode jsonNode = HttpUtils.getDateListByUrl(null);
|
|
|
String content = jsonNode.get("content").toPrettyString();
|
|
|
|
|
|
- String numberOfElements = jsonNode.get("numberOfElements").toPrettyString();
|
|
|
- String totalElements = jsonNode.get("totalElements").toPrettyString();
|
|
|
- String totalPages = jsonNode.get("totalPages").toPrettyString();
|
|
|
+ String numberOfElements = jsonNode.get("numberOfElements").toPrettyString();
|
|
|
+ String totalElements = jsonNode.get("totalElements").toPrettyString();
|
|
|
+ String totalPages = jsonNode.get("totalPages").toPrettyString();
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
Map<String, String> aa = new HashMap<>();
|
|
|
- aa.put("id","7781d549-2c06-4c95-8bf8-05b31a4b2f8a");
|
|
|
+ aa.put("id", "7781d549-2c06-4c95-8bf8-05b31a4b2f8a");
|
|
|
// List<Map<String, String>> list =new ArrayList<>();
|
|
|
// list.add(aa);
|
|
|
List<Map<String, String>> list = mapper.readValue(content, new TypeReference<List<Map<String, String>>>() {
|
|
|
});
|
|
|
- if(list.size() == 0){
|
|
|
+ if (list.size() == 0) {
|
|
|
list.add(aa);
|
|
|
}
|
|
|
for (Map<String, String> m : list) {
|
|
@@ -117,7 +146,7 @@ public class SaleInterfaceSyncServiceImpl extends ServiceImpl<SaleInterfaceSyncM
|
|
|
});
|
|
|
|
|
|
List<SaleInterfaceItem> saleInterfaceItemList = new ArrayList<>();
|
|
|
- for(Map<String, Object> line:lineItemsMap){
|
|
|
+ for (Map<String, Object> line : lineItemsMap) {
|
|
|
|
|
|
SaleInterfaceItem item = new SaleInterfaceItem();
|
|
|
|
|
@@ -148,19 +177,19 @@ public class SaleInterfaceSyncServiceImpl extends ServiceImpl<SaleInterfaceSyncM
|
|
|
headEntry.setCurrencyCode(currencyCode);
|
|
|
headEntry.setReferenceNumber(referenceNumber);
|
|
|
|
|
|
- if(StringUtils.isNotBlank(requestedDeliveryDate)){
|
|
|
+ if (StringUtils.isNotBlank(requestedDeliveryDate)) {
|
|
|
Instant instant = Instant.parse(requestedDeliveryDate);
|
|
|
headEntry.setRequestedDeliveryDate(Date.from(instant));
|
|
|
}
|
|
|
- if(StringUtils.isNotBlank(adviseBeforeDate)){
|
|
|
+ if (StringUtils.isNotBlank(adviseBeforeDate)) {
|
|
|
Instant instant = Instant.parse(adviseBeforeDate);
|
|
|
headEntry.setAdviseBeforeDate(Date.from(instant));
|
|
|
}
|
|
|
- if(StringUtils.isNotBlank(submittedDate)){
|
|
|
+ if (StringUtils.isNotBlank(submittedDate)) {
|
|
|
Instant instant = Instant.parse(submittedDate);
|
|
|
headEntry.setSubmittedDate(Date.from(instant));
|
|
|
}
|
|
|
- if(StringUtils.isNotBlank(createdDate)){
|
|
|
+ if (StringUtils.isNotBlank(createdDate)) {
|
|
|
Instant instant = Instant.parse(createdDate);
|
|
|
headEntry.setCreatedDate(Date.from(instant));
|
|
|
}
|
|
@@ -182,8 +211,8 @@ public class SaleInterfaceSyncServiceImpl extends ServiceImpl<SaleInterfaceSyncM
|
|
|
headEntry.setExported(exported);
|
|
|
|
|
|
try {
|
|
|
- saveMain(headEntry,saleInterfaceItemList);
|
|
|
- }catch (Exception e){
|
|
|
+ saveMain(headEntry, saleInterfaceItemList);
|
|
|
+ } catch (Exception e) {
|
|
|
System.out.println("===========重复数据=========");
|
|
|
}
|
|
|
|
|
@@ -195,6 +224,7 @@ public class SaleInterfaceSyncServiceImpl extends ServiceImpl<SaleInterfaceSyncM
|
|
|
}
|
|
|
return Result.OK("执行成功");
|
|
|
}
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
String dateStr = "2025-04-11T08:33:50.963Z";
|
|
|
|
|
@@ -204,16 +234,191 @@ public class SaleInterfaceSyncServiceImpl extends ServiceImpl<SaleInterfaceSyncM
|
|
|
System.out.println(date);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void actionSyncOrder(Collection<? extends Serializable> idList) {
|
|
|
+ public Result<String> actionSyncOrder(Collection<? extends Serializable> idList) {
|
|
|
|
|
|
- for (Serializable id : idList) {
|
|
|
+ QueryWrapper<SaleInterfaceSync> entityQuery = new QueryWrapper<>();
|
|
|
+ entityQuery.in("id", idList);
|
|
|
+ List<SaleInterfaceSync> listSaleInterfaceSync = this.list(entityQuery);
|
|
|
+ if (listSaleInterfaceSync.size() == 0) {
|
|
|
+ return Result.error("数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ for (SaleInterfaceSync ent : listSaleInterfaceSync) {
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ String referenceNumber = ent.getReferenceNumber();//询价编号
|
|
|
+
|
|
|
+ Integer sync = ent.getSync();//同步状态(0-未同步,1-同步成功,2-同步失败)
|
|
|
+ Integer submit = ent.getSubmit();//提交(0否,1是)
|
|
|
+ Integer close = ent.getClose();//关闭(0否,1是)
|
|
|
+
|
|
|
+ if (sync.equals(1)) {
|
|
|
+ builder.append("编号:" + referenceNumber + "已同步,请勿再次同步;");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (submit.equals(0)) {
|
|
|
+ builder.append("编号:" + referenceNumber + "还未提交,请勿执行;");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (close.equals(1)) {
|
|
|
+ builder.append("编号:" + referenceNumber + "已关闭,请勿执行;");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String buyerName = ent.getBuyerName();//客户名称
|
|
|
+ String currencyCode = ent.getCurrencyCode();//币种
|
|
|
+
|
|
|
+ QueryWrapper<CuspCustomerProfile> customerQuery = new QueryWrapper<>();
|
|
|
+// if(StringUtils.isNotBlank(currencyCode)){
|
|
|
+// customerQuery.eq("currency",currencyCode);
|
|
|
+// }
|
|
|
+
|
|
|
+ customerQuery.eq("status", 1);
|
|
|
+ customerQuery.eq("del_flag", 0);
|
|
|
+ List<CuspCustomerProfile> listCustomer = cuspCustomerProfileService.list(customerQuery);
|
|
|
+ if (listCustomer.size() == 0) {
|
|
|
+ builder.append("客户'" + buyerName + "'未找到有效数据,请先维护客户档案;");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Date adviseBeforeDate = ent.getAdviseBeforeDate();//询价有效期尾
|
|
|
+ Date submittedDate = ent.getSubmittedDate();//客户询价日期
|
|
|
+ String comment = ent.getComment();//询价表头备注
|
|
|
+ String vesselImo = ent.getVesselImo();//船imo
|
|
|
+ String vesselCode = ent.getVesselCode();//船名
|
|
|
+ String priority = ent.getPriority();//优先级
|
|
|
+
|
|
|
+ SaleInquiryForm saleInquiryForm = new SaleInquiryForm();
|
|
|
+
|
|
|
+ saleInquiryForm.setBillDate(new Date());//单据日期
|
|
|
+ saleInquiryForm.setInquiryTime(submittedDate);//客户询价日期
|
|
|
+ saleInquiryForm.setInquiryCustomer(listCustomer.get(0).getId());//询价客户
|
|
|
+ saleInquiryForm.setCustomerName(listCustomer.get(0).getName());//询价客户
|
|
|
+ saleInquiryForm.setCustomerInquiryNumber(referenceNumber);//询价编号
|
|
|
+ saleInquiryForm.setInquiryPeriodBegin(submittedDate);//询价有效期
|
|
|
+ saleInquiryForm.setInquiryPeriodEnd(adviseBeforeDate);//询价有效期尾
|
|
|
+ saleInquiryForm.setPriority(priority);//询价有效期尾
|
|
|
+ saleInquiryForm.setInquiryNotes(comment);//询价表头备注
|
|
|
+
|
|
|
+ saleInquiryForm.setSaleDepartment(sysUser.getOrgCode());
|
|
|
+// saleInquiryForm.setSaleDepartmentName();
|
|
|
+ saleInquiryForm.setSalesman(sysUser.getUsername());
|
|
|
+ saleInquiryForm.setSalesmanName(sysUser.getRealname());
|
|
|
+
|
|
|
+ QueryWrapper<BaseShipArchive> queryWrapperShip = new QueryWrapper();
|
|
|
+ queryWrapperShip.eq("imo", vesselImo);
|
|
|
+ queryWrapperShip.eq("ship_name", vesselCode);
|
|
|
+ queryWrapperShip.eq("del_flag", "0");
|
|
|
+
|
|
|
+ List<BaseShipArchive> listShip = baseShipArchiveService.list(queryWrapperShip);
|
|
|
+ BaseShipArchive baseShipArchive = new BaseShipArchive();
|
|
|
+ if (listShip.size() == 0) {
|
|
|
+ baseShipArchive.setImo(vesselImo);
|
|
|
+ baseShipArchive.setShipName(vesselCode);
|
|
|
+ baseShipArchive.setStatus(1);
|
|
|
+ baseShipArchiveService.save(baseShipArchive);
|
|
|
+ } else {
|
|
|
+ baseShipArchive = listShip.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ SaleInquiryFormShip saleInquiryFormShip = new SaleInquiryFormShip();
|
|
|
+ saleInquiryFormShip.setShipName(vesselCode);
|
|
|
+ saleInquiryFormShip.setShipId(baseShipArchive.getId());
|
|
|
+ saleInquiryFormShip.setShipFactory(baseShipArchive.getShipFactory());
|
|
|
+
|
|
|
+
|
|
|
+ Result<String> result = serialPatternService.getNextSerial("sale_inquiry_form", "bill_code");
|
|
|
+ if (!result.isSuccess()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ saleInquiryForm.setBillCode(result.getMessage());
|
|
|
+
|
|
|
+ saleInquiryFormMapper.insert(saleInquiryForm);
|
|
|
+ List<SaleInterfaceItem> interfaceItemList = saleInterfaceItemMapper.selectByMainId(ent.getId());
|
|
|
+ for (SaleInterfaceItem interfaceItem : interfaceItemList) {
|
|
|
+ String description = interfaceItem.getDescription();
|
|
|
+ String supplierPartNumber = interfaceItem.getSupplierPartNumber();
|
|
|
+ String quantity = interfaceItem.getQuantity();
|
|
|
+ String unitOfMeasure = interfaceItem.getUnitOfMeasure();
|
|
|
+ String commentChild = interfaceItem.getComment();
|
|
|
+
|
|
|
+ QueryWrapper<BaseProductArchive> queryWrapperProduct = new QueryWrapper();
|
|
|
+ queryWrapperProduct.eq("del_flag", "0");
|
|
|
+ queryWrapperProduct.eq("english_name", description);
|
|
|
+ queryWrapperProduct.eq("partno", supplierPartNumber);
|
|
|
+ queryWrapperProduct.eq("measurement_unit", unitOfMeasure);
|
|
|
+
|
|
|
+ List<BaseProductArchive> listProduct = baseProductArchiveService.list(queryWrapperProduct);
|
|
|
+ BaseProductArchive baseProductArchive = new BaseProductArchive();
|
|
|
+
|
|
|
+ if (listProduct.size() == 0) {
|
|
|
+
|
|
|
+ Result<String> resultProduct = serialPatternService.getNextSerial("base_product_archive", "code");
|
|
|
+ if (!resultProduct.isSuccess()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ baseProductArchive.setCode(resultProduct.getMessage());
|
|
|
+ baseProductArchive.setEnglishName(description);
|
|
|
+ baseProductArchive.setPartno(supplierPartNumber);
|
|
|
+ baseProductArchive.setMeasurementUnit(unitOfMeasure);
|
|
|
+ baseProductArchive.setHarmfulSubstances(0);
|
|
|
+ baseProductArchive.setVirtualProduct(0);
|
|
|
+// baseProductArchive.setCommissionRebate(1);
|
|
|
+ baseProductArchiveMapper.insert(baseProductArchive);
|
|
|
+ } else {
|
|
|
+ baseProductArchive = listProduct.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ SaleInquiryFormProduct saleInquiryFormProduct = new SaleInquiryFormProduct();
|
|
|
+ saleInquiryFormProduct.setEnglishName(description);
|
|
|
+ saleInquiryFormProduct.setPartno(supplierPartNumber);
|
|
|
+ saleInquiryFormProduct.setQuantity(new BigDecimal(quantity));
|
|
|
+ saleInquiryFormProduct.setUnit(unitOfMeasure);
|
|
|
+ saleInquiryFormProduct.setNotes(commentChild);
|
|
|
+ saleInquiryFormProduct.setProductId(baseProductArchive.getId());
|
|
|
+ saleInquiryFormProduct.setProductCode(baseProductArchive.getCode());
|
|
|
+ saleInquiryFormProduct.setProductClass(baseProductArchive.getClassId());
|
|
|
+ saleInquiryFormProduct.setModel(baseProductArchive.getModel());
|
|
|
+ saleInquiryFormProduct.setChineseName(baseProductArchive.getChineseName());
|
|
|
+
|
|
|
+ saleInquiryFormProduct.setHeadId(saleInquiryForm.getId());
|
|
|
+
|
|
|
+ saleInquiryFormProductMapper.insert(saleInquiryFormProduct);
|
|
|
+ }
|
|
|
+ saleInquiryFormShip.setHeadId(saleInquiryForm.getId());
|
|
|
+ saleInquiryFormShipMapper.insert(saleInquiryFormShip);
|
|
|
+
|
|
|
+ ent.setSync(1);
|
|
|
+ ent.setSyncBy(sysUser.getUsername());
|
|
|
+ ent.setSyncTime(new Date());
|
|
|
+ ent.setSyncCode(saleInquiryForm.getBillCode());
|
|
|
+ saleInterfaceSyncMapper.updateById(ent);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ ent.setSync(2);
|
|
|
+ ent.setSyncBy(sysUser.getUsername());
|
|
|
+ ent.setSyncTime(new Date());
|
|
|
+ ent.setSyncInfo(e.getMessage());
|
|
|
+ saleInterfaceSyncMapper.updateById(ent);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(builder.toString())) {
|
|
|
+ return Result.OK(builder.toString());
|
|
|
+ }
|
|
|
|
|
|
+ return Result.OK("同步订单成功!");
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@Override
|