|
|
@@ -1,5 +1,6 @@
|
|
|
package com.usoftchina.saas.document.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
|
|
|
@@ -11,25 +12,25 @@ import com.usoftchina.saas.commons.dto.DocBaseDTO;
|
|
|
import com.usoftchina.saas.commons.dto.ListReqDTO;
|
|
|
import com.usoftchina.saas.commons.exception.BizExceptionCode;
|
|
|
import com.usoftchina.saas.commons.po.BillCodeSeq;
|
|
|
+import com.usoftchina.saas.commons.po.DataImportDetail;
|
|
|
import com.usoftchina.saas.commons.po.Operation;
|
|
|
import com.usoftchina.saas.commons.po.Status;
|
|
|
import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
-import com.usoftchina.saas.document.dto.CustomerDTO;
|
|
|
-import com.usoftchina.saas.document.dto.CustomerFormDTO;
|
|
|
-import com.usoftchina.saas.document.dto.CustomeraddressDTO;
|
|
|
-import com.usoftchina.saas.document.dto.CustomercontactDTO;
|
|
|
+import com.usoftchina.saas.document.dto.*;
|
|
|
import com.usoftchina.saas.document.entities.*;
|
|
|
import com.usoftchina.saas.document.mapper.*;
|
|
|
import com.usoftchina.saas.document.service.CustomerService;
|
|
|
import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
import com.usoftchina.saas.utils.BeanMapper;
|
|
|
+import com.usoftchina.saas.utils.CollectionUtils;
|
|
|
import com.usoftchina.saas.utils.DateUtils;
|
|
|
import com.usoftchina.saas.utils.RegexpUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+import sun.reflect.generics.tree.LongSignature;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
@@ -59,6 +60,8 @@ public class CustomerServiceImpl extends CommonBaseServiceImpl<CustomerMapper, C
|
|
|
private SubledgerMapper subledgerMapper;
|
|
|
@Autowired
|
|
|
private CustomerMapper customerMapper;
|
|
|
+ @Autowired
|
|
|
+ private DataImportMapper dataImportMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -488,6 +491,68 @@ public class CustomerServiceImpl extends CommonBaseServiceImpl<CustomerMapper, C
|
|
|
return getMapper().getCombo(id,BaseContextHolder.getCompanyId());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void saveToFormal(Integer id, boolean update) {
|
|
|
+ if (null == id || "0".equals(id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ StringBuilder err = new StringBuilder();
|
|
|
+ List<CustomerFormDTO> list = new ArrayList<>();
|
|
|
+ CustomerFormDTO listDTO = 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;
|
|
|
+ for (String code : datas.keySet()) {
|
|
|
+ listDTO = new CustomerFormDTO();
|
|
|
+ List<CustomercontactDTO> details_ = new ArrayList<>();
|
|
|
+ int i = getMapper().validateCodeWhenInsert(code, companyId);
|
|
|
+ List<DataImportDetail> data = datas.get(code);
|
|
|
+ DataImportDetail main = dataImportMapper.selectMainBycode(code, id, companyId);
|
|
|
+ CustomerDTO customerDTO = JSONObject.parseObject(main.getDd_maindata(), CustomerDTO.class);
|
|
|
+ customerDTO.setCu_status(Status.OPEN.getDisplay());
|
|
|
+ customerDTO.setCu_statuscode(Status.OPEN.name());
|
|
|
+ //编号不存在
|
|
|
+ if (i == 0) {
|
|
|
+ customerDTO.setId(0l);
|
|
|
+ //编号存在、需要更新
|
|
|
+ } else if (update){
|
|
|
+ Long cu_id = getMapper().selectIdByCode(code, companyId);
|
|
|
+ customerDTO.setId(cu_id);
|
|
|
+ //编号存在、不需要处理
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //添加从表
|
|
|
+ if (data.size() > 0) {
|
|
|
+ detno = 1;
|
|
|
+ for (DataImportDetail vendorDetail : data) {
|
|
|
+ CustomercontactDTO detail = JSONObject.parseObject(vendorDetail.getDd_detaildata(), CustomercontactDTO.class);
|
|
|
+ if (null != detail) {
|
|
|
+ detail.setCc_cuid(customerDTO.getId());
|
|
|
+ detail.setCc_detno(detno);
|
|
|
+ detno++;
|
|
|
+ details_.add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ listDTO.setMain(customerDTO);
|
|
|
+ listDTO.setItems1(details_);
|
|
|
+ listDTO.setItems2(new ArrayList<CustomeraddressDTO>());
|
|
|
+ list.add(listDTO);
|
|
|
+ }
|
|
|
+ if (err.length() > 0) {
|
|
|
+ dataImportMapper.updateDataImportError(err.toString(), id);
|
|
|
+ throw new BizException(12345, err.toString());
|
|
|
+ }
|
|
|
+ for (CustomerFormDTO dto : list) {
|
|
|
+ saveFormData(dto);
|
|
|
+ }
|
|
|
+ dataImportMapper.updateDataImport(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private List<CustomerList> getListByMode(ListReqDTO req) {
|
|
|
List<CustomerList> list = null;
|