|
|
@@ -1,7 +1,11 @@
|
|
|
package com.usoftchina.saas.sale.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import com.usoftchina.saas.commons.po.*;
|
|
|
+import com.usoftchina.saas.document.dto.CustomerDTO;
|
|
|
+import com.usoftchina.saas.document.dto.ProductDTO;
|
|
|
import com.usoftchina.saas.inquiry.api.InquiryApi;
|
|
|
import com.usoftchina.saas.inquiry.po.inquiry.*;
|
|
|
import com.usoftchina.saas.account.api.AccountApi;
|
|
|
@@ -14,9 +18,6 @@ import com.usoftchina.saas.commons.dto.BatchDealBaseDTO;
|
|
|
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.Operation;
|
|
|
-import com.usoftchina.saas.commons.po.Status;
|
|
|
import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.page.PageDefault;
|
|
|
@@ -80,6 +81,8 @@ public class SaleServiceImpl implements SaleService{
|
|
|
private AccountApi accountApi;
|
|
|
@Autowired
|
|
|
private CompanyApi companyApi;
|
|
|
+ @Autowired
|
|
|
+ private DataImportMapper dataImportMapper;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(SaleServiceImpl.class);
|
|
|
|
|
|
@@ -675,6 +678,74 @@ public class SaleServiceImpl implements SaleService{
|
|
|
return baseDTO;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void saveToFormal(Long id, boolean update){
|
|
|
+ if (null == id || "0".equals(id)) {
|
|
|
+ throw new BizException(BizExceptionCode.NO_DATA);
|
|
|
+ }
|
|
|
+ String userName = BaseContextHolder.getUserName();
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ SaleFormDTO saleFormDTO = null;
|
|
|
+ List<DataImportDetail> details = dataImportMapper.selectDataById(id);
|
|
|
+ if (!CollectionUtils.isEmpty(details)) {
|
|
|
+ Map<String, List<DataImportDetail>> datas = CollectionUtils.groupBy(details, DataImportDetail::getDd_codevalue);
|
|
|
+ int detno = 0;
|
|
|
+ for (String code : datas.keySet()) {
|
|
|
+ saleFormDTO = new SaleFormDTO();
|
|
|
+ List<SaleDetailDTO> saleDetailDTOList = new ArrayList<>();
|
|
|
+ List<DataImportDetail> data = datas.get(code);
|
|
|
+ //准备主表数据
|
|
|
+ DataImportDetail main = dataImportMapper.selectMainBycode(code, id.intValue(), companyId);
|
|
|
+ if (StringUtils.isEmpty(main)){
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_REPORT_NOTCORRECT);
|
|
|
+ }
|
|
|
+ SaleDTO saleDTO = JSONObject.parseObject(main.getDd_maindata(), SaleDTO.class);
|
|
|
+ CustomerDTO customerDTO = saleMapper.selectCustByCustCode(saleDTO.getSa_custcode(), companyId);
|
|
|
+ if (ObjectUtils.isEmpty(customerDTO)) {
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_CUSTOMER_CODE_NOT_EXISTS.getCode(),
|
|
|
+ String.format(BizExceptionCode.BIZ_CUSTOMER_CODE_NOT_EXISTS.getMessage(), saleDTO.getSa_custname() + "(" + saleDTO.getSa_custcode() + ")"));
|
|
|
+ }
|
|
|
+ if (!customerDTO.getCu_name().equals(saleDTO.getSa_custname())) {
|
|
|
+ throw new BizException(79360, "客户编号" + saleDTO.getSa_custcode() + "客户名称" + saleDTO.getSa_custname() + "匹配错误");
|
|
|
+ }
|
|
|
+ saleDTO.setSa_custid(customerDTO.getId().intValue());
|
|
|
+ saleDTO.setId(0L);
|
|
|
+ saleDTO.setCreateTime(new Date());
|
|
|
+ saleDTO.setCreatorName(userName);
|
|
|
+ saleDTO.setSa_date(new Date());
|
|
|
+ saleDTO.setSa_status(Status.UNAUDITED.getDisplay());
|
|
|
+ saleDTO.setSa_statuscode(Status.UNAUDITED.name());
|
|
|
+
|
|
|
+ saleFormDTO.setMain(saleDTO);
|
|
|
+ //准备从表数据
|
|
|
+ if (data.size() > 0) {
|
|
|
+ detno = 1;
|
|
|
+ for (DataImportDetail detail : data) {
|
|
|
+ SaleDetailDTO saleDetailDTO = JSONObject.parseObject(detail.getDd_detaildata(), SaleDetailDTO.class);
|
|
|
+ //校验明细物料
|
|
|
+ ProductDTO productDTO = saleMapper.selectProductByCode(saleDetailDTO.getSd_prodcode(), companyId);
|
|
|
+ if (ObjectUtils.isEmpty(productDTO)) {
|
|
|
+ throw new BizException(79360, "物料" + saleDetailDTO.getSd_prodcode() + "不存在");
|
|
|
+ }
|
|
|
+ saleDetailDTO.setSd_prodid(productDTO.getId());
|
|
|
+ saleDetailDTO.setSd_detno(detno++);
|
|
|
+ saleDetailDTO.setId(0L);
|
|
|
+ saleDetailDTO.setSd_price(saleDetailDTO.getSd_netprice() * (100 + saleDetailDTO.getSd_taxrate()) / 100);
|
|
|
+ saleDetailDTO.setSd_nettotal(saleDetailDTO.getSd_netprice() * saleDetailDTO.getSd_qty());
|
|
|
+ saleDetailDTO.setSd_total(saleDetailDTO.getSd_price() * saleDetailDTO.getSd_qty());
|
|
|
+
|
|
|
+ saleDetailDTOList.add(saleDetailDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saleFormDTO.setItems(saleDetailDTOList);
|
|
|
+ //保存
|
|
|
+ saleFormDTO.setCodeModified(true);
|
|
|
+ saveFormData(saleFormDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取企业商机
|
|
|
* @param remindReqDTO
|
|
|
@@ -688,19 +759,24 @@ public class SaleServiceImpl implements SaleService{
|
|
|
}
|
|
|
Long enUU = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData().getUu();
|
|
|
//Long userUU = 1000002503L, enUU = 10041559L;
|
|
|
- IPage<InquiryEnRemind> inquiryEnRemindIPage = inquiryApi.findEnRemind(userUU, enUU, remindReqDTO.getPageNumber(),
|
|
|
- remindReqDTO.getPageSize(), remindReqDTO.getEnableOffer(), remindReqDTO.getKeyword(), remindReqDTO.getQuoted(),
|
|
|
- remindReqDTO.getFromDate(), remindReqDTO.getEndDate());
|
|
|
- List<InquiryEnRemind> inquiryEnRemindList = inquiryEnRemindIPage.getContent();
|
|
|
- if (CollectionUtils.isEmpty(inquiryEnRemindList)){
|
|
|
- return null;
|
|
|
+ IPage<InquiryEnRemind> inquiryEnRemindIPage = null;
|
|
|
+ if (remindReqDTO.getQuoted() != 1) {
|
|
|
+ inquiryEnRemindIPage = inquiryApi.findEnRemind(userUU, enUU, remindReqDTO.getPageNumber(),
|
|
|
+ remindReqDTO.getPageSize(), remindReqDTO.getEnableOffer(), remindReqDTO.getKeyword(), remindReqDTO.getQuoted(),
|
|
|
+ remindReqDTO.getFromDate(), remindReqDTO.getEndDate());
|
|
|
+ List<InquiryEnRemind> inquiryEnRemindList = inquiryEnRemindIPage.getContent();
|
|
|
+ if (CollectionUtils.isEmpty(inquiryEnRemindList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<RemindRspDTO> remindRspDTOList = convertToRemindRspDTO(JsonUtils.toJsonString(inquiryEnRemindList), "enterprise");
|
|
|
+ //转换成分页对象
|
|
|
+ IPage<RemindRspDTO> remindRspDTOIPage = new IPage<RemindRspDTO>(inquiryEnRemindIPage.getNumber(), inquiryEnRemindIPage.getSize(),
|
|
|
+ inquiryEnRemindIPage.getNumberOfElements(), remindRspDTOList, inquiryEnRemindIPage.isFirst(), inquiryEnRemindIPage.isLast(),
|
|
|
+ inquiryEnRemindIPage.getTotalElements());
|
|
|
+ return remindRspDTOIPage;
|
|
|
+ }else {
|
|
|
+ return getRemindRspDTO(enUU, userUU, remindReqDTO);
|
|
|
}
|
|
|
- List<RemindRspDTO> remindRspDTOList = convertToRemindRspDTO(JsonUtils.toJsonString(inquiryEnRemindList), "enterprise");
|
|
|
- //转换成分页对象
|
|
|
- IPage<RemindRspDTO> remindRspDTOIPage = new IPage<RemindRspDTO>(inquiryEnRemindIPage.getNumber(), inquiryEnRemindIPage.getSize(),
|
|
|
- inquiryEnRemindIPage.getNumberOfElements(),remindRspDTOList, inquiryEnRemindIPage.isFirst(), inquiryEnRemindIPage.isLast(),
|
|
|
- inquiryEnRemindIPage.getTotalElements());
|
|
|
- return remindRspDTOIPage;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -712,19 +788,100 @@ public class SaleServiceImpl implements SaleService{
|
|
|
public IPage<RemindRspDTO> findRemindByUserInfo(RemindReqDTO remindReqDTO) {
|
|
|
Long userUU = accountApi.getAccountById(BaseContextHolder.getUserId()).getData().getUu();
|
|
|
Long enUU = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData().getUu();
|
|
|
- IPage<InquiryRemind> inquiryRemindIpage = inquiryApi.findRemindByUserInfo(userUU, enUU, remindReqDTO.getPageNumber(), remindReqDTO.getPageSize(),
|
|
|
- remindReqDTO.getEnableOffer(),remindReqDTO.getKeyword(), remindReqDTO.getQuoted(),
|
|
|
- remindReqDTO.getFromDate(), remindReqDTO.getEndDate());
|
|
|
- List<InquiryRemind> inquiryRemindList = inquiryRemindIpage.getContent();
|
|
|
- if (CollectionUtils.isEmpty(inquiryRemindList)){
|
|
|
- return null;
|
|
|
+ if (remindReqDTO.getQuoted() != 1) {
|
|
|
+ IPage<InquiryRemind> inquiryRemindIpage = inquiryApi.findRemindByUserInfo(userUU, enUU, remindReqDTO.getPageNumber(), remindReqDTO.getPageSize(),
|
|
|
+ remindReqDTO.getEnableOffer(), remindReqDTO.getKeyword(), remindReqDTO.getQuoted(),
|
|
|
+ remindReqDTO.getFromDate(), remindReqDTO.getEndDate());
|
|
|
+ List<InquiryRemind> inquiryRemindList = inquiryRemindIpage.getContent();
|
|
|
+ if (CollectionUtils.isEmpty(inquiryRemindList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<RemindRspDTO> remindRspDTOList = convertToRemindRspDTO(JsonUtils.toJsonString(inquiryRemindList), "personal");
|
|
|
+ //转换成分页对象
|
|
|
+ IPage<RemindRspDTO> remindRspDTOIPage = new IPage<RemindRspDTO>(inquiryRemindIpage.getNumber(), inquiryRemindIpage.getSize(),
|
|
|
+ inquiryRemindIpage.getNumberOfElements(), remindRspDTOList, inquiryRemindIpage.isFirst(), inquiryRemindIpage.isLast(),
|
|
|
+ inquiryRemindIpage.getTotalElements());
|
|
|
+ return remindRspDTOIPage;
|
|
|
+ }else {
|
|
|
+ return getRemindRspDTO(enUU, userUU, remindReqDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询已报过价的商机
|
|
|
+ * @param enUU 企业UU
|
|
|
+ * @param userUU 个人UU,企业商机传入userUU=null
|
|
|
+ * @param remindReqDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private IPage<RemindRspDTO> getRemindRspDTO(Long enUU, Long userUU, RemindReqDTO remindReqDTO){
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("userUU", userUU);
|
|
|
+ jsonObject.put("vendUU", enUU);
|
|
|
+ jsonObject.put("fromDate", remindReqDTO.getFromDate());
|
|
|
+ jsonObject.put("endDate", remindReqDTO.getEndDate());
|
|
|
+ jsonObject.put("fromDelivery", null);
|
|
|
+ jsonObject.put("endDelivery", null);
|
|
|
+ String filter = jsonObject.toJSONString();
|
|
|
+ IPage<PublicInquiryItemInfo> publicInquiryItemInfoIPage = inquiryApi.findQuotationList(remindReqDTO.getPageNumber(), remindReqDTO.getPageSize(), remindReqDTO.getKeyword(), "done", 1, filter);
|
|
|
+ List<PublicInquiryItemInfo> publicInquiryItemInfoList = publicInquiryItemInfoIPage.getContent();
|
|
|
+ List<RemindRspDTO> remindRspDTOList = new ArrayList<>();
|
|
|
+ RemindRspDTO remindRspDTO = null;
|
|
|
+
|
|
|
+ for (PublicInquiryItemInfo publicInquiryItemInfo : publicInquiryItemInfoList) {
|
|
|
+ remindRspDTO = new RemindRspDTO();
|
|
|
+ //询价单信息
|
|
|
+ PublicInquiryInfo publicInquiryInfo = publicInquiryItemInfo.getInquiry();
|
|
|
+ if (!ObjectUtils.isEmpty(publicInquiryInfo)) {
|
|
|
+ remindRspDTO.setCustName(publicInquiryInfo.getEnName());
|
|
|
+ }
|
|
|
+ Product product = publicInquiryItemInfo.getProduct();
|
|
|
+ if (!ObjectUtils.isEmpty(product)) {
|
|
|
+ remindRspDTO.setProdBrand(product.getBrand());
|
|
|
+ remindRspDTO.setProdName(product.getTitle());
|
|
|
+ remindRspDTO.setProdOrispeccode(product.getCmpCode());
|
|
|
+ remindRspDTO.setProdSpec(product.getSpec());
|
|
|
+ remindRspDTO.setProdUnit(StringUtils.isEmpty(product.getUnit()) ? "PCS" : product.getUnit());
|
|
|
+ }
|
|
|
+
|
|
|
+ remindRspDTO.setNeedQty(publicInquiryItemInfo.getNeedquantity());
|
|
|
+ remindRspDTO.setStartDate(publicInquiryItemInfo.getDate());
|
|
|
+ remindRspDTO.setEndDate(publicInquiryItemInfo.getEndDate());
|
|
|
+ remindRspDTO.setQuoted(1);
|
|
|
+ remindRspDTO.setUserName(publicInquiryItemInfo.getUserName());
|
|
|
+ remindRspDTO.setUserTel(publicInquiryItemInfo.getUserTel());
|
|
|
+ remindRspDTO.setUserUU(publicInquiryItemInfo.getUserUU());
|
|
|
+ remindRspDTO.setSourceId(publicInquiryItemInfo.getSourceId());
|
|
|
+ remindRspDTO.setEnUU(publicInquiryInfo.getEnUU());
|
|
|
+ remindRspDTO.setRecorderUU(publicInquiryItemInfo.getUserUU());
|
|
|
+ remindRspDTO.setInquiryCode(publicInquiryInfo.getCode());
|
|
|
+ remindRspDTO.setInquiryId(publicInquiryInfo.getId());
|
|
|
+
|
|
|
+ QuotationRspDTO quotationRspDTO = new QuotationRspDTO();
|
|
|
+ quotationRspDTO.setAgreed(publicInquiryItemInfo.getAgreed());
|
|
|
+ quotationRspDTO.setRefusereason(publicInquiryItemInfo.getRefusereason());
|
|
|
+ quotationRspDTO.setLeadTime(publicInquiryItemInfo.getLeadtime());
|
|
|
+ quotationRspDTO.setTaxRate(new BigDecimal(publicInquiryItemInfo.getTaxrate()).doubleValue());
|
|
|
+ //分段报价明细
|
|
|
+ List<InquiryReplayDTO> inquiryReplayDTOList = new ArrayList<InquiryReplayDTO>();
|
|
|
+ List<PublicInquiryReplyInfo> publicInquiryReplyList = publicInquiryItemInfo.getReplies();
|
|
|
+ if (!CollectionUtils.isEmpty(publicInquiryReplyList)) {
|
|
|
+ for (PublicInquiryReplyInfo publicInquiryReplyInfo : publicInquiryReplyList) {
|
|
|
+ InquiryReplayDTO inquiryReplayDTO = new InquiryReplayDTO(publicInquiryReplyInfo.getId(), publicInquiryReplyInfo.getLapQty(), publicInquiryReplyInfo.getPrice());
|
|
|
+ inquiryReplayDTOList.add(inquiryReplayDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ quotationRspDTO.setReplies(inquiryReplayDTOList);
|
|
|
+ remindRspDTO.setQutations(quotationRspDTO);
|
|
|
+
|
|
|
+ remindRspDTOList.add(remindRspDTO);
|
|
|
}
|
|
|
- List<RemindRspDTO> remindRspDTOList = convertToRemindRspDTO(JsonUtils.toJsonString(inquiryRemindList), "personal");
|
|
|
- //转换成分页对象
|
|
|
- IPage<RemindRspDTO> remindRspDTOIPage = new IPage<RemindRspDTO>(inquiryRemindIpage.getNumber(), inquiryRemindIpage.getSize(),
|
|
|
- inquiryRemindIpage.getNumberOfElements(),remindRspDTOList, inquiryRemindIpage.isFirst(), inquiryRemindIpage.isLast(),
|
|
|
- inquiryRemindIpage.getTotalElements());
|
|
|
- return remindRspDTOIPage;
|
|
|
+ //构造回写数据
|
|
|
+ IPage<RemindRspDTO> Ipage = new IPage<RemindRspDTO>(publicInquiryItemInfoIPage.getNumber(), publicInquiryItemInfoIPage.getSize(),
|
|
|
+ publicInquiryItemInfoIPage.getNumberOfElements(), remindRspDTOList,
|
|
|
+ publicInquiryItemInfoIPage.isFirst(), publicInquiryItemInfoIPage.isLast(),
|
|
|
+ publicInquiryItemInfoIPage.getTotalElements());
|
|
|
+ return Ipage;
|
|
|
}
|
|
|
|
|
|
/**
|