|
|
@@ -1,370 +0,0 @@
|
|
|
-package com.uas.platform.b2b.erp.service.impl;
|
|
|
-
|
|
|
-import com.uas.message.mail.service.MailService;
|
|
|
-import com.uas.platform.b2b.core.util.ContextUtils;
|
|
|
-import com.uas.platform.b2b.core.util.DateFormatUtils;
|
|
|
-import com.uas.platform.b2b.core.util.ThreadTask;
|
|
|
-import com.uas.platform.b2b.dao.*;
|
|
|
-import com.uas.platform.b2b.erp.model.*;
|
|
|
-import com.uas.platform.b2b.erp.model.Inquiry;
|
|
|
-import com.uas.platform.b2b.erp.service.PublicInquiryService;
|
|
|
-import com.uas.platform.b2b.erp.support.ErpBufferedLogger;
|
|
|
-import com.uas.platform.b2b.event.PurcInquirySaveReleaseEvent;
|
|
|
-import com.uas.platform.b2b.model.*;
|
|
|
-import com.uas.platform.b2b.support.MessageConf;
|
|
|
-import com.uas.platform.b2b.support.SystemSession;
|
|
|
-import com.uas.platform.b2b.support.UsageBufferedLogger;
|
|
|
-import com.uas.platform.b2b.temporary.model.SmsMessage;
|
|
|
-import com.uas.platform.b2b.temporary.model.UserInfo;
|
|
|
-import com.uas.platform.core.exception.NotFoundException;
|
|
|
-import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
-import com.uas.platform.core.model.Constant;
|
|
|
-import com.uas.platform.core.model.Status;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
-import java.util.regex.Pattern;
|
|
|
-
|
|
|
-/**
|
|
|
- * 公共询价单实现方法
|
|
|
- *
|
|
|
- * Created by hejq on 2017-09-18.
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class PublicInquiryServiceImpl implements PublicInquiryService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PurcInquiryDao inquiryDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ProductDao productDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private EnterpriseDao enterpriseDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PurcInquiryItemDao purcInquiryItemDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommonDao commonDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MailService mailService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MessageConf messageConf;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private NoticeDao noticeDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PublicInquiryItemDao publicInquiryItemDao;
|
|
|
-
|
|
|
- private final static ErpBufferedLogger logger = BufferedLoggerManager.getLogger(ErpBufferedLogger.class);
|
|
|
-
|
|
|
- private final static UsageBufferedLogger usageLogger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
-
|
|
|
- private static final String TEL_REGEXP = "^((\\(\\d{3}\\))|(\\d{3}\\-))?(13|15|18|17)\\d{9}$";
|
|
|
-
|
|
|
- /**
|
|
|
- * 公共询价传输增加物料异常抛出
|
|
|
- *
|
|
|
- * @author hejq
|
|
|
- * @date 2018-01-12 9:27
|
|
|
- * @param inquiries 询价明细
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<PurcInquiry> convertInquiry(List<BatchInquiry> inquiries) {
|
|
|
- Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- List<PurcInquiry> purcInquiries = new ArrayList<PurcInquiry>();
|
|
|
- if(!CollectionUtils.isEmpty(inquiries)) {
|
|
|
- for(BatchInquiry inquiry : inquiries) {
|
|
|
- PurcInquiry old = inquiryDao.findByCodeAndEnUU(inquiry.getBi_code(), enuu);
|
|
|
- //先判断是否已经存在,不存在才进行存储
|
|
|
- if(null == old) {
|
|
|
- PurcInquiry purcInquiry = inquiry.covert();
|
|
|
- purcInquiry.setEnUU(enuu);
|
|
|
- purcInquiry.setEnterprise(enterpriseDao.findEnterpriseInfoByUu(enuu));
|
|
|
- purcInquiry.setShip(SystemSession.getUser().getEnterprise().getEnAddress());
|
|
|
- Set<PurcInquiryItem> purcInquiryItems = new HashSet<PurcInquiryItem>();
|
|
|
- if(!CollectionUtils.isEmpty(inquiry.getInProducts())) {
|
|
|
- for(BatchInProduct batch : inquiry.getInProducts()) {
|
|
|
- PurcInquiryItem item = new PurcInquiryItem();
|
|
|
- item.setIsOpen(Constant.YES);
|
|
|
- List<Product> products = productDao.findByEnUUAndCode(enuu, batch.getBip_prodcode());
|
|
|
- if (CollectionUtils.isEmpty(products)) {
|
|
|
- throw new NotFoundException("编号为[" + batch.getBip_prodcode() + "]的物料未找到");
|
|
|
- }
|
|
|
- item.setProduct(products.get(0));
|
|
|
- item.setProductId(products.get(0).getId());
|
|
|
- item.setRemark(batch.getBip_remark());
|
|
|
- item.setNumber(batch.getBip_detno());
|
|
|
- item.setFromDate(new Date());
|
|
|
- item.setToDate(purcInquiry.getEndDate());
|
|
|
- item.setStatus((short) Status.NOT_REPLY.value());
|
|
|
- item.setIsOpen(Constant.YES);
|
|
|
- item.setSource("ERP");
|
|
|
- item.setSourceid(batch.getBip_id());
|
|
|
- item.setCurrency(batch.getBip_currency());
|
|
|
- if(null != inquiry.getBi_date()) {
|
|
|
- item.setDate(inquiry.getBi_date());
|
|
|
- } else {
|
|
|
- item.setDate(new Date());
|
|
|
- }
|
|
|
- if(item.getCurrency() == null) {
|
|
|
- item.setCurrency("RMB");
|
|
|
- }
|
|
|
- purcInquiryItems.add(item);
|
|
|
- }
|
|
|
- }
|
|
|
- purcInquiry.setInquiryItems(purcInquiryItems);
|
|
|
- purcInquiries.add(purcInquiry);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return purcInquiries;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void save(List<PurcInquiry> inquiries) {
|
|
|
- List<PurcInquiryItem> inquiryItems = new ArrayList<>();
|
|
|
- if(!CollectionUtils.isEmpty(inquiries)) {
|
|
|
- for(PurcInquiry inquiry : inquiries) {
|
|
|
- // 判断单号是否已存在
|
|
|
- PurcInquiry old = inquiryDao.findByCodeAndEnUU(inquiry.getCode(), SystemSession.getUser().getEnterprise().getUu());
|
|
|
- List<PurcInquiryItem> items = new ArrayList<PurcInquiryItem>();
|
|
|
- if(old == null && !CollectionUtils.isEmpty(inquiry.getInquiryItems())) {
|
|
|
- for(PurcInquiryItem item : inquiry.getInquiryItems()) {
|
|
|
- item.setInquiry(inquiry);
|
|
|
- items.add(item);
|
|
|
- }
|
|
|
- }
|
|
|
- try {
|
|
|
- items = purcInquiryItemDao.save(items);
|
|
|
- inquiryItems.addAll(items);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.log("公共询价保存出错", inquiry.getEnUU() + "," +inquiry.getCode() +" 保存失败", 1);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- // 产生消息 使用线程会丢数据
|
|
|
-// sendMessage(inquiryItems);
|
|
|
- List<PurcInquiry> distinctInquiries = PurcInquiryItem.distinct(inquiryItems);
|
|
|
- List<PurcInquiryItem> items = new ArrayList<>();
|
|
|
- for (PurcInquiry inquiry : distinctInquiries) {
|
|
|
- Set<Long> enUUs = new HashSet<>();
|
|
|
- for (PurcInquiryItem inquiryItem : inquiry.getInquiryItems()) {
|
|
|
- if (!enUUs.contains(inquiryItem.getVendUU())) {
|
|
|
- items.add(inquiryItem);
|
|
|
- enUUs.add(inquiryItem.getVendUU());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ContextUtils.publishEvent(new PurcInquirySaveReleaseEvent(items));
|
|
|
- // 发送通知
|
|
|
- Long userUU = SystemSession.getUser().getUserUU();
|
|
|
- Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- String userIp = SystemSession.getUser().getIp();
|
|
|
- String userName = SystemSession.getUser().getUserName();
|
|
|
-// sendRemind(inquiries, userUU, userName, userIp, enUU);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 产生消息
|
|
|
- * @param inquiryItems
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void sendMessage(final List<PurcInquiryItem> inquiryItems) {
|
|
|
- ThreadTask.getInstance().execute(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- List<PurcInquiry> inquiries = PurcInquiryItem.distinct(inquiryItems);
|
|
|
- List<PurcInquiryItem> items = new ArrayList<>();
|
|
|
- for (PurcInquiry inquiry : inquiries) {
|
|
|
- Set<Long> enUUs = new HashSet<>();
|
|
|
- for (PurcInquiryItem inquiryItem : inquiry.getInquiryItems()) {
|
|
|
- if (!enUUs.contains(inquiryItem.getVendUU())) {
|
|
|
- items.add(inquiryItem);
|
|
|
- enUUs.add(inquiryItem.getVendUU());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ContextUtils.publishEvent(new PurcInquirySaveReleaseEvent(items));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将平台的公共询价转成ERP的对应的字段
|
|
|
- *
|
|
|
- * @param notUploadReply 未下载的供应商报价信息
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<InquiryDetail> convertPublicInquiryReply(List<PublicInquiryItemInfo> notUploadReply) {
|
|
|
- List<InquiryDetail> details = new ArrayList<InquiryDetail>();
|
|
|
- if (!CollectionUtils.isEmpty(notUploadReply)) {
|
|
|
- for (PublicInquiryItemInfo item : notUploadReply) {
|
|
|
- details.add(new InquiryDetail(item));
|
|
|
- }
|
|
|
- }
|
|
|
- return details;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将ERP采纳状态传回平台更新平台的采纳状态
|
|
|
- *
|
|
|
- * @param decides ERP采纳结果
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<PublicInquiryItem> convertInquiryDecide(List<InquiryDecide> decides) {
|
|
|
- List<PublicInquiryItem> inquiryItems = new ArrayList<PublicInquiryItem>();
|
|
|
- if (!CollectionUtils.isEmpty(decides)) {
|
|
|
- long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- for (InquiryDecide decide : decides) {
|
|
|
- PublicInquiryItem item = publicInquiryItemDao.findOne(decide.getB2b_id());
|
|
|
- if (null != item) {
|
|
|
- item.setAgreed(decide.getId_agreed());
|
|
|
- item.setDecideStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- inquiryItems.add(item);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return inquiryItems;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送通知
|
|
|
- *
|
|
|
- * @param inquiries 采购询价单主表
|
|
|
- * @param userUU
|
|
|
- *@param userName
|
|
|
- * @param userIp
|
|
|
- * @param enUU @return
|
|
|
- */
|
|
|
- private void sendRemind(final List<PurcInquiry> inquiries, final Long userUU, final String userName, final String userIp, final Long enUU) {
|
|
|
- ThreadTask.getInstance().execute(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- for (PurcInquiry inquiry : inquiries) {
|
|
|
- // 一个询价单,给一个企业只发一封邮件
|
|
|
- Set<Long> enUUs = new HashSet<>();
|
|
|
- // 短信设置
|
|
|
- SmsMessage sms = new SmsMessage();
|
|
|
- List<Object> obj = new ArrayList<Object>();
|
|
|
- obj.add(inquiry.getEnterprise().getEnName());
|
|
|
- sms.setParams(obj);
|
|
|
- for (PurcInquiryItem inquiryItem : inquiry.getInquiryItems()) {
|
|
|
- if (null != inquiryItem.getVendUU() && !enUUs.contains(inquiryItem.getVendUU())) {
|
|
|
- // 查找业务员邮箱
|
|
|
- String userEmailSql = "select distinct us.user_email ememail from sec$users us " +
|
|
|
- " left join sec$userrole ur on us.user_uu = ur.user_uu left join sec$roles sr " +
|
|
|
- " on ur.role_id = sr.role_id where sr.role_desc = '业务员' and us.user_email is not null " +
|
|
|
- " and sr.role_enuu = " + inquiryItem.getVendUU() + " and us.user_uu in (" +
|
|
|
- "select pd_useruu from purc$distribute where pd_vdid = (" +
|
|
|
- "select ve_id from purc$vendors where ve_myenuu = " + inquiry.getEnUU() + " and ve_vendenuu = " + inquiryItem.getVendUU() + "))";
|
|
|
- List<UserInfo> userEmails = commonDao.query(userEmailSql, UserInfo.class);
|
|
|
- String userTelSql = "select distinct us.user_tel emphone from sec$users us " +
|
|
|
- " left join sec$userrole ur on us.user_uu = ur.user_uu left join sec$roles sr " +
|
|
|
- " on ur.role_id = sr.role_id where sr.role_desc = '业务员' and us.user_tel is not null " +
|
|
|
- " and sr.role_enuu = " + inquiryItem.getVendUU() + " and us.user_uu in (" +
|
|
|
- "select pd_useruu from purc$distribute where pd_vdid = (" +
|
|
|
- "select ve_id from purc$vendors where ve_myenuu = " + inquiry.getEnUU() + " and ve_vendenuu = " + inquiryItem.getVendUU() + "))";
|
|
|
- List<UserInfo> userTels = commonDao.query(userTelSql, UserInfo.class);
|
|
|
- // 发邮件
|
|
|
- Map<String, Object> model = new HashMap<String, Object>();
|
|
|
- Enterprise vendor = enterpriseDao.findOne(inquiryItem.getVendUU());
|
|
|
- if (null != vendor) {
|
|
|
- model.put("vendorname", vendor.getEnName());
|
|
|
- } else {
|
|
|
- model.put("vendorname", "供应商");
|
|
|
- }
|
|
|
- model.put("custname", inquiry.getEnterprise().getEnName());
|
|
|
- model.put("date", DateFormatUtils.DATE_FORMAT.format(new Date()));
|
|
|
- // 不存在被分配客户的业务员则添加系统管理员
|
|
|
- if (CollectionUtils.isEmpty(userEmails) && CollectionUtils.isEmpty(userTels)) {
|
|
|
- Enterprise enterprise = enterpriseDao.findOne(inquiryItem.getVendUU());
|
|
|
- if (null != enterprise && null != enterprise.getAdmin()) {
|
|
|
- UserInfo adminInfo = new UserInfo(enterprise.getAdmin());
|
|
|
- userEmails.add(adminInfo);
|
|
|
- userTels.add(adminInfo);
|
|
|
- }
|
|
|
- }
|
|
|
- for (UserInfo userEmail : userEmails) {
|
|
|
- String emailRegex = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
|
|
|
- if (Pattern.matches(emailRegex, userEmail.getEmemail())) {
|
|
|
- try {
|
|
|
- mailService.send(messageConf.getTplInquiryForB2B(), userEmail.getEmemail(), model);
|
|
|
- // 线程内无法访问Systemsession,会报nullPoint,采用存储过程
|
|
|
-// usageLogger.log("询价发送邮件", "企业UU:" + inquiry.getEnUU() + ",单号:" +inquiry.getCode() +" 发送邮件成功", "询价发送邮件成功");
|
|
|
- noticeDao.saveErpLog(userName, userIp, enUU, userUU, "公共询价单通知邮件", "发送成功,询价单号" + inquiry.getCode());
|
|
|
- } catch (Exception e) {
|
|
|
-// usageLogger.log("询价发送邮件", "企业UU:" + inquiry.getEnUU() + ",单号:" +inquiry.getCode() +" 发送邮件失败", "询价发送邮件出错");
|
|
|
- noticeDao.saveErpLog(userName, userIp, enUU, userUU, "公共询价单通知邮件", "发送失败,询价单号" + inquiry.getCode());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 发短信
|
|
|
-// for (UserInfo userTel : userTels) {
|
|
|
-// if(null != userTel.getEmphone() && userTel.getEmphone().matches(TEL_REGEXP)) {//手机号判断
|
|
|
-// try {
|
|
|
-// sms.setReceiver(userTel.getEmphone());
|
|
|
-// sms.setTemplateId(messageConf.getMsgInquiryForB2B());
|
|
|
-// PSHttpUtils.sendPost(messageConf.getMessageUrl(), FlexJsonUtils.toJsonDeep(sms));
|
|
|
-// noticeDao.saveErpLog(userName, userIp, enUU, userUU, "发送询价单通知短信", "发送成功,询价单号" + inquiry.getCode());
|
|
|
-// } catch (Exception e) {
|
|
|
-// noticeDao.saveErpLog(userName, userIp, enUU, userUU, "发送询价单通知短信", "发送失败,询价单号" + inquiry.getCode());
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- enUUs.add(inquiryItem.getVendUU());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void updateStatus(List<BatchInquiry> inquiries) {
|
|
|
- if(!CollectionUtils.isEmpty(inquiries)) {
|
|
|
- for(BatchInquiry inquiry : inquiries) {
|
|
|
- // 更新为过期状态,不能进行报价处理
|
|
|
- String sql = "update purc$puinquiryitems set id_overdue = 1 where id_inid in ( select in_id from purc$puinquiry where in_enuu = "
|
|
|
- + SystemSession.getUser().getEnterprise().getUu() + " and in_code = '" + inquiry.getBi_code() + "')";
|
|
|
- commonDao.getJdbcTemplate().update(sql);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * ERP提交公共询价单之后,更新平台状态,让平台询价单不能进行报价操作
|
|
|
- *
|
|
|
- * @param inquiries
|
|
|
- * @author hejq
|
|
|
- * @date 2018-01-11 9:13
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void updateInquiryStatus(List<Inquiry> inquiries) {
|
|
|
- if(!CollectionUtils.isEmpty(inquiries)) {
|
|
|
- Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- for(Inquiry inquiry : inquiries) {
|
|
|
- // 更新为过期状态,不能进行报价处理
|
|
|
- String sql = "update purc$puinquiryitems set id_overdue = 1 where id_inid in ( select in_id from purc$puinquiry where in_enuu = "
|
|
|
- + enuu + " and in_code = '" + inquiry.getIn_code() + "')";
|
|
|
- commonDao.getJdbcTemplate().update(sql);
|
|
|
- // 更新已转报价的询价单明细状态
|
|
|
- commonDao.getJdbcTemplate().update("update public$inquiryItems set id_overdue = 1 where id_inid in " +
|
|
|
- "(select in_id from public$inquiry where in_enuu = " + enuu + " and in_code = '" + inquiry.getIn_code() + "')");
|
|
|
- // 更新已转报价的询价单主表check状态为已提交
|
|
|
- commonDao.getJdbcTemplate().update("update public$inquiry set in_checked = 1 where in_enuu = " + enuu + " and in_code = '" + inquiry.getIn_code() + "'");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|