|
|
@@ -3,18 +3,15 @@ package com.usoftchina.saas.purchase.service.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import com.netflix.discovery.converters.Auto;
|
|
|
-import com.rabbitmq.tools.json.JSONUtil;
|
|
|
import com.usoftchina.saas.account.dto.CompanyDTO;
|
|
|
import com.usoftchina.saas.commons.cache.ConfigsCache;
|
|
|
+import com.usoftchina.saas.commons.po.DataImportDetail;
|
|
|
import com.usoftchina.saas.document.api.AddressApi;
|
|
|
import com.usoftchina.saas.document.api.CurrencyApi;
|
|
|
import com.usoftchina.saas.document.api.ProductApi;
|
|
|
import com.usoftchina.saas.document.api.VendorApi;
|
|
|
-import com.usoftchina.saas.document.dto.CurrencyDTO;
|
|
|
-import com.usoftchina.saas.document.dto.ProductDTO;
|
|
|
-import com.usoftchina.saas.document.dto.VendorDTO;
|
|
|
-import com.usoftchina.saas.document.dto.VendorListDTO;
|
|
|
+import com.usoftchina.saas.document.dto.*;
|
|
|
+import com.usoftchina.saas.document.entities.Address;
|
|
|
import com.usoftchina.saas.document.entities.Vendor;
|
|
|
import com.usoftchina.saas.document.entities.Vendorcontact;
|
|
|
import com.usoftchina.saas.inquiry.api.InquiryApi;
|
|
|
@@ -115,6 +112,8 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
private AddressApi addressApi;
|
|
|
@Autowired
|
|
|
private ProductApi productApi;
|
|
|
+ @Autowired
|
|
|
+ private DataImportMapper dataImportMapper;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseServiceImpl.class);
|
|
|
|
|
|
@@ -334,6 +333,108 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
return saveFormData(purchaseFormDTO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void saveToFormal(Integer id, boolean update) {
|
|
|
+ if (null == id || "0".equals(id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ StringBuilder err = new StringBuilder();
|
|
|
+ List<PurchaseFormDTO> list = new ArrayList<>();
|
|
|
+ PurchaseFormDTO purchaseFormDTO = null;
|
|
|
+ List<DataImportDetail> details = dataImportMapper.selectDataById(id);
|
|
|
+ if (!CollectionUtils.isEmpty(details)) {
|
|
|
+ Map<String, List<DataImportDetail>> datas = CollectionUtils.groupBy(details, DataImportDetail::getDd_codevalue);
|
|
|
+ Integer detno = null;
|
|
|
+ //取统一的交货地址
|
|
|
+ Address address = purchaseMapper.selectDefaultAddress(companyId);
|
|
|
+ String defaultAddress = null;
|
|
|
+ if (null != address) {
|
|
|
+ defaultAddress = address.getAd_address();
|
|
|
+ }
|
|
|
+ for (String code : datas.keySet()) {
|
|
|
+ purchaseFormDTO = new PurchaseFormDTO();
|
|
|
+ List<PurchaseDetailDTO> detailDTOList = new ArrayList<>();
|
|
|
+ List<DataImportDetail> data = datas.get(code);
|
|
|
+ DataImportDetail main = dataImportMapper.selectMainBycode(code, id, companyId);
|
|
|
+ if (StringUtils.isEmpty(main)) {
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_REPORT_NOTCORRECT);
|
|
|
+ }
|
|
|
+ PurchaseDTO purchaseDTO = JSONObject.parseObject(main.getDd_maindata(), PurchaseDTO.class);
|
|
|
+ //验证供应商编号
|
|
|
+ String vend = purchaseDTO.getPu_vendcode();
|
|
|
+ if (!StringUtils.isEmpty(vend)) {
|
|
|
+ Vendor vendor = purchaseMapper.selectVendorByCode(vend, companyId);
|
|
|
+ if (null == vendor) {
|
|
|
+ err.append("采购订单号: " + purchaseDTO.getPu_code() + " 的供应商编号: "+ vend +" 在系统中不存在,请确认数据是否正确");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ purchaseDTO.setPu_vendid(vendor.getId().intValue());
|
|
|
+ purchaseDTO.setPu_vendname(vendor.getVe_name());
|
|
|
+ }
|
|
|
+ //币别验证
|
|
|
+ String currency = purchaseDTO.getPu_currency();
|
|
|
+ if (!StringUtils.isEmpty(currency)) {
|
|
|
+ Integer count = purchaseMapper.checkCurrency(currency, BaseContextHolder.getCompanyId());
|
|
|
+ if (count == 0) {
|
|
|
+ err.append("采购订单号: " + purchaseDTO.getPu_code() + " 的币别: "+ currency +" 在系统中不存在,请确认数据是否正确");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //新增
|
|
|
+ purchaseDTO.setId(0l);
|
|
|
+ purchaseDTO.setPu_status(Status.UNAUDITED.getDisplay());
|
|
|
+ purchaseDTO.setPu_statuscode(Status.UNAUDITED.name());
|
|
|
+ purchaseDTO.setPu_date(new Date());
|
|
|
+ purchaseDTO.setCreateTime(new Date());
|
|
|
+ purchaseDTO.setPu_shipaddresscode(defaultAddress);
|
|
|
+ if (null == purchaseDTO.getPu_delivery()) {
|
|
|
+ purchaseDTO.setPu_delivery(new Date());
|
|
|
+ }
|
|
|
+ //添加从表
|
|
|
+ if (data.size() > 0) {
|
|
|
+ detno = 1;
|
|
|
+ for (DataImportDetail detail : data) {
|
|
|
+ PurchaseDetailDTO purchaseDetailDTO = null;
|
|
|
+ try {
|
|
|
+ purchaseDetailDTO = JSONObject.parseObject(detail.getDd_detaildata(), PurchaseDetailDTO.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (null != purchaseDetailDTO) {
|
|
|
+ //验证物料编号
|
|
|
+ String prodcode = purchaseDetailDTO.getPd_prodcode();
|
|
|
+ if (!StringUtils.isEmpty(prodcode)) {
|
|
|
+ ProductDTO product = purchaseMapper.selectProductByCode(prodcode, companyId);
|
|
|
+ if (null == product) {
|
|
|
+ err.append("采购订单号: " + purchaseDTO.getPu_code() + " 的明细料号: "+ prodcode +" 在系统中不存在,请确认数据是否正确");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ purchaseDetailDTO.setPd_prodid(product.getId());
|
|
|
+ purchaseDetailDTO.setPd_detno(detno);
|
|
|
+ detno++;
|
|
|
+ detailDTOList.add(purchaseDetailDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //添加至List中
|
|
|
+ purchaseFormDTO.setMain(purchaseDTO);
|
|
|
+ purchaseFormDTO.setItems(detailDTOList);
|
|
|
+ purchaseFormDTO.setCodeModified(true);
|
|
|
+ list.add(purchaseFormDTO);
|
|
|
+ }
|
|
|
+ if (err.length() > 0) {
|
|
|
+ dataImportMapper.updateDataImportError(err.toString(), id);
|
|
|
+ throw new BizException(12345, err.toString());
|
|
|
+ }
|
|
|
+ for (PurchaseFormDTO dto : list) {
|
|
|
+ saveFormData(dto);
|
|
|
+ }
|
|
|
+ dataImportMapper.updateDataImport(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建供应商
|
|
|
* @param turnPurchaseReqDTO
|