| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983 |
- package com.uas.ps.inquiry.service.impl;
- import com.alibaba.fastjson.JSONObject;
- import com.uas.ps.core.util.CollectionUtils;
- import com.uas.ps.core.util.ContextUtils;
- import com.uas.ps.entity.Product;
- import com.uas.ps.entity.Status;
- import com.uas.ps.inquiry.AccessConfiguration;
- import com.uas.ps.inquiry.dao.*;
- import com.uas.ps.inquiry.entity.*;
- import com.uas.ps.inquiry.model.*;
- import com.uas.ps.inquiry.page.PageInfo;
- import com.uas.ps.inquiry.page.SearchFilter;
- import com.uas.ps.inquiry.page.criteria.CriterionExpression;
- import com.uas.ps.inquiry.page.criteria.LogicalExpression;
- import com.uas.ps.inquiry.page.criteria.PredicateUtils;
- import com.uas.ps.inquiry.page.criteria.SimpleExpression;
- import com.uas.ps.inquiry.page.exception.IllegalOperatorException;
- import com.uas.ps.inquiry.service.InquiryService;
- import com.uas.ps.inquiry.service.PublicInquiryService;
- import com.uas.ps.inquiry.util.FlexJsonUtils;
- import com.uas.ps.inquiry.util.HttpUtil;
- import com.uas.ps.inquiry.util.StringUtil;
- import com.uas.ps.inquiry.util.ThreadUtils;
- import javassist.NotFoundException;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.Sort;
- import org.springframework.data.jpa.domain.Specification;
- import org.springframework.jdbc.core.BeanPropertyRowMapper;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import javax.persistence.criteria.CriteriaBuilder;
- import javax.persistence.criteria.CriteriaQuery;
- import javax.persistence.criteria.Predicate;
- import javax.persistence.criteria.Root;
- import java.net.URLEncoder;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * 针对转询价报价单的数据查询操作
- *
- * Created by hejq on 2018-01-17.
- */
- @Service
- @Transactional
- public class InquiryServiceImpl implements InquiryService {
- /**
- * 消息类型 (在B2B消息中拼接跳转单据详情url请求时需要)
- */
- private final String INQUIRY_TYPE = "公共询价";
- /**
- * 消息推送短信模板id
- */
- private final String SMS_TEMP_ID = "e6320a3c-89ac-4c77-a75f-62a727bce654";
- /**
- * 消息推送方式:邮件、短信、im
- */
- private final String SMS_TYPE = "MAIL_AND_SM_AND_IM";
- /**
- * 消费类型: 多个,MULTI
- */
- private final String CUST_TYPE = "MULTI";
- /**
- * 应用来源,主要是为了平台公共询价做处理
- */
- private String SOURCEAPP_MALL = "MALL";
- /**
- * 接收应用
- */
- private final String CONSUMERAPP_HIDE = "HIDE";
- /**
- * 消息类型 (在MALL消息中拼接求购询价待报价)
- */
- private final String INQUIRY_TYPE_SELLER_MALL = "MALL跳转卖家待报价页面";
- /**
- * 公共消息访问地址
- */
- private final String PS_MESSAGE_URL = ContextUtils.getBean(AccessConfiguration.class).getPsMessageUrl();
- /**
- * 询价统计通知发送人UU
- */
- private final Long MESSAGE_SENDERUU = ContextUtils.getBean(AccessConfiguration.class).getSenderuu();
- /**
- * 询价统计通知发送企业UU
- */
- private final Long MESSAGE_SENDERENUU = ContextUtils.getBean(AccessConfiguration.class).getSenderEnuu();
- @Autowired
- private PublicInquiryItemDao itemDao;
- @Autowired
- private PurcInquiryItemInfoDao inquiryItemDao;
- @Autowired
- private PurcInquiryDao purcInquiryDao;
- @Autowired
- private PublicInquiryDao inquiryDao;
- @Autowired
- private ProductDao productDao;
- @Autowired
- private PurcInquiryItemDao purcInquiryItemDao;
- @Autowired
- private PublicInquiryService inquiryService;
- @Autowired
- private InquiryRemindDao inquiryRemindDao;
- @Autowired
- private JdbcTemplate jdbcTemplate;
- @Autowired
- private EnterpriseDao enterpriseDao;
- @Autowired
- private PublicInquiryServiceImpl service;
- @Autowired
- private InquiryEnRemindDao inquiryEnRemindDao;
- /**
- * 公共物料访问地址
- */
- private final String PS_PRODUCT_URL = ContextUtils.getBean(AccessConfiguration.class).getPsProductUrl();
- /**
- * 日志
- */
- private static final Logger log = LoggerFactory.getLogger(InquiryServiceImpl.class);
- /**
- * 查询公共询价列表信息
- *
- * @param info 分页新
- * @param filter 过滤条件
- * @param state 过滤状态
- * @param overdue 是否过期 1、已过期;0、未过期
- * @return
- */
- @Override
- public Page<PurcInquiryItemInfo> findTodoByPageInfo(final PageInfo info, SearchFilter filter, String state, Integer overdue) {
- Sort sort = new Sort(Sort.Direction.DESC, "date");
- if (info.getOffset() == 0) {
- info.setOffset(info.getPageSize() * (info.getPageNumber() - 1));
- }
- info.setSort(sort);
- if (null != filter) {
- if (null != filter.getUserUU()) {
- info.filter("userUU", filter.getUserUU());
- info.expression(PredicateUtils.isNull("inquiry.enUU"));
- } else if (null != filter.getEnUU()) {
- info.filter("inquiry.enUU", filter.getEnUU());
- } else {
- throw new IllegalAccessError("非法访问");
- }
- if (StringUtils.hasText(filter.getKeyword())) {
- SimpleExpression cmpCode = new SimpleExpression("cmpCode", filter.getKeyword(), CriterionExpression.Operator.LIKE);
- SimpleExpression brand = new SimpleExpression("inbrand", filter.getKeyword(), CriterionExpression.Operator.LIKE);
- SimpleExpression prodTitle = new SimpleExpression("prodTitle", filter.getKeyword(), CriterionExpression.Operator.LIKE);
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{cmpCode, brand, prodTitle};
- LogicalExpression logicalExpression = PredicateUtils.or(simpleExpressions);
- info.expression(logicalExpression);
- }
- if (filter.getFromDate() != null) {
- info.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
- }
- if (filter.getEndDate() != null) {
- info.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
- }
- }
- if (null != state) {
- // 待报价
- if (state.equals(OrderStatus.todo.name())) {
- SimpleExpression amount = new SimpleExpression("offerAmount", Constant.NO, CriterionExpression.Operator.EQ);
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{amount};
- LogicalExpression logicalExpression = PredicateUtils.and(simpleExpressions);
- info.expression(logicalExpression);
- }
- // 已报价
- if (state.equals(OrderStatus.done.name())) {
- SimpleExpression amount = new SimpleExpression("offerAmount", Constant.YES, CriterionExpression.Operator.GTE);
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{amount};
- LogicalExpression logicalExpression = PredicateUtils.and(simpleExpressions);
- info.expression(logicalExpression);
- }
- // 已超过截止日期
- if (state.equals(OrderStatus.end.name())) {
- SimpleExpression date = new SimpleExpression("endDate", new Date(System.currentTimeMillis()), CriterionExpression.Operator.LT);
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{date};
- LogicalExpression logicalExpression = PredicateUtils.and(simpleExpressions);
- info.expression(logicalExpression);
- }
- }
- if (null != overdue) {
- // 已超过截止日期
- if (overdue.equals((int)Constant.YES)) {
- SimpleExpression date = new SimpleExpression("endDate", new Date(System.currentTimeMillis()), CriterionExpression.Operator.LT);
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{date};
- LogicalExpression logicalExpression = PredicateUtils.and(simpleExpressions);
- info.expression(logicalExpression);
- } else if (overdue.equals((int)Constant.NO)) {
- info.expression(PredicateUtils.gte("endDate", new Date(System.currentTimeMillis()), false));
- }
- }
- return inquiryItemDao.findAll(new Specification<PurcInquiryItemInfo>() {
- @Override
- public Predicate toPredicate(Root<PurcInquiryItemInfo> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
- query.where(info.getPredicates(root, query, builder));
- return null;
- }
- }, info);
- }
- /**
- * 保存公共询价
- *
- * @param currentInquiry 询价信息
- */
- @Override
- public PurcInquiry saveInquiry(PurcInquiry currentInquiry) throws NotFoundException {
- // amount,code,date设置
- if (StringUtils.isEmpty(currentInquiry.getAmount())) {
- currentInquiry.setAmount(currentInquiry.getInquiryItems().size());
- }
- if (StringUtils.isEmpty(currentInquiry.getCode())) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddsss");
- try {
- currentInquiry.setCode("MALL" + sdf.parse(sdf.format(new Date())).getTime() + StringUtil.getRandomNumber(3) + StringUtil.getRandomNumber(3));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- //通过流水号和企业号找到公共询价单
- List<PurcInquiry> existInquiryList = purcInquiryDao.findByCodeAndEnUU(currentInquiry.getCode(), currentInquiry.getEnUU());
- if (!CollectionUtils.isEmpty(existInquiryList)) {
- throw new IllegalOperatorException("单号重复");
- } else {
- if (null != currentInquiry.getEnUU()) {
- Enterprise e = enterpriseDao.findOne(currentInquiry.getEnUU());
- if (null != e) {
- currentInquiry.setEnName(e.getEnName());
- } else {
- throw new NotFoundException("询价企业不存在");
- }
- }
- //保存询价单
- PurcInquiry inquiry = purcInquiryDao.save(currentInquiry);
- //判断询价明细单是否为空
- if (!CollectionUtils.isEmpty(currentInquiry.getInquiryItems())) {
- List<PurcInquiryItem> items = new ArrayList<PurcInquiryItem>();
- //给询价明细单属性设置初始值
- for (PurcInquiryItem item : currentInquiry.getInquiryItems()) {
- item.setInquiry(inquiry);
- item.setValid(1);
- item.setOfferAmount(0);
- item.setStatus((short) Status.NOT_REPLY.value());
- item.setIsOpen(Constant.YES);
- item.setEnuu(inquiry.getEnUU());
- if (null == item.getDate()) {
- //设置提交时间
- item.setDate(new Date(System.currentTimeMillis()));
- }
- // 这里设置物料信息的冗余字段
- if (null != item.getProduct()) {
- item.setProdTitle(item.getProduct().getTitle());
- item.setProdCode(item.getProduct().getCode());
- item.setSpec(item.getProduct().getSpec());
- item.setInbrand(item.getProduct().getBrand());
- item.setCmpCode(item.getProduct().getCmpCode());
- }
- if (null == item.getCmpCode() || item.getCmpCode().equals("无")) {
- item.setCmpCode(item.getSpec());
- }
- if (null == item.getEndDate()) {
- item.setEndDate(inquiry.getEndDate());
- }
- items.add(item);
- }
- //保存询价单明细表
- items = purcInquiryItemDao.save(items);
- final List<PurcInquiryItem> purcInquiryItems = items;
- final String sourceapp = inquiry.getSourceapp();
- final Long enuu = inquiry.getEnUU();
- if (null != inquiry.getSourceapp()) {
- ThreadUtils.task(new Runnable() {
- @Override
- public void run() {
- try {
- //生成推荐询价表
- inquiryService.notifyMessage(purcInquiryItems, sourceapp);
- if (!StringUtils.isEmpty(enuu)) {
- saveProduct(purcInquiryItems, sourceapp);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- }
- return inquiry;
- }
- }
- /**
- * 可配置的定时任务
- */
- @Override
- public List<InquiryRemind> testMessage(Date startTime, Date endTime, Long useruu, Long enuu){
- log.info("公共询价,9点定时统计询价单总数服务开启");
- List<InquiryRemind> list = inquiryRemindDao.findTestInfo(startTime,endTime,useruu,enuu);
- log.info("公共询价,9点定时统计询价单总数服务结束");
- return list;
- }
- /**
- * 发布询价成功后加入当前用户的个人物料库
- * @param inquiryItems
- * @param sourceApp
- */
- public void saveProduct(List<PurcInquiryItem> inquiryItems, String sourceApp) {
- List<Product> products = new ArrayList<>();
- for (PurcInquiryItem item : inquiryItems) {
- Product product = new Product();
- // 需要哪些字段
- product.setEnUU(item.getInquiry().getEnUU());
- product.setUserUU(item.getInquiry().getRecorderUU());
- product.setCmpCode(item.getCmpCode());
- product.setBrand(item.getInbrand());
- product.setpCmpCode(item.getCmpCode());
- product.setpBrandEn(item.getInbrand());
- product.setStandard((short) 0);
- product.setCreateTime(new Date());
- product.setSourceApp(sourceApp);
- product.setSpec(StringUtils.isEmpty(item.getSpec()) ? item.getCmpCode() : item.getSpec());
- product.setKind(item.getProdTitle());
- products.add(product);
- }
- // 调用公共物料服务的接口
- try {
- String url = PS_PRODUCT_URL + "/product/save/inquiry/batch";
- long start = System.currentTimeMillis();
- String res = HttpUtil.doPost(url, FlexJsonUtils.toJsonDeep(products));
- log.info("/product/save/inquiry/batch 耗时:{},物料数:{}", (System.currentTimeMillis() - start), products.size());
- JSONObject result = JSONObject.parseObject(res);
- Boolean success = (Boolean) result.get("success");
- if (success) {
- log.info("保存询价单后,批量保存物料成功:{}", products.size());
- } else {
- log.info("保存询价单后,批量保存物料失败,返回:{}", result.get("message"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 通过报价明细id对供应商报价进行相关审核操作
- *
- * @param id 报价明细id
- * @param status 状态
- */
- @Override
- public void decideQuote(Long id, Short status) {
- PublicInquiryItem item = itemDao.findOne(id);
- // 验证是否重复操作
- validateInquiry(item);
- item.setAgreed(status);
- item.setDecideDownStatus((short) Status.NOT_UPLOAD.value());
- itemDao.save(item);
- // 更新询价推荐表相关信息
- if (status.equals(Constant.YES)) {
- inquiryRemindDao.updateStatus(item.getSourceId(), Status.ALLOW.value(), item.getVendUU());
- inquiryEnRemindDao.updateStatus(item.getSourceId(), Status.ALLOW.value(), item.getVendUU());
- updatePurcInquiryItemAgreed(item.getSourceId(), status);
- } else if (status.equals(Constant.NO)) {
- inquiryRemindDao.updateStatus(item.getSourceId(), Status.NOTALLOW.value(), item.getVendUU());
- inquiryEnRemindDao.updateStatus(item.getSourceId(), Status.NOTALLOW.value(), item.getVendUU());
- }
- // 更新原公共询价单该条明细,设置为不可报价
- String sql = "update purc$puinquiryitems set id_overdue = 1 where id_id = " + item.getSourceId();
- jdbcTemplate.update(sql);
- inquiryService.notifyDecide(item, InquirySource.B2B.name());
- }
- /**
- * 商城通过报价明细id采纳对供应商报价
- *
- * @param id 报价明细id
- * @param status 状态
- */
- @Override
- public void adpotQuote(Long id, Short status) {
- PublicInquiryItem item = itemDao.findOne(id);
- // 验证是否重复操作
- validateInquiry(item);
- item.setAgreed(status);
- item.setDecideDownStatus((short) Status.NOT_UPLOAD.value());
- itemDao.save(item);
- // 更新询价推荐表相关信息
- if (status.equals(Constant.YES)) {
- inquiryRemindDao.updateStatus(item.getSourceId(), Status.ALLOW.value(), item.getVendUU());
- inquiryEnRemindDao.updateStatus(item.getSourceId(), Status.ALLOW.value(), item.getVendUU());
- // 修改询价明细agreed字段为1,表示存在已采纳报价明细
- updatePurcInquiryItemAgreed(item.getSourceId(), status);
- } else if (status.equals(Constant.NO)) {
- inquiryRemindDao.updateStatus(item.getSourceId(), Status.NOTALLOW.value(), item.getVendUU());
- inquiryEnRemindDao.updateStatus(item.getSourceId(), Status.NOTALLOW.value(), item.getVendUU());
- }
- // 更新原公共询价单该条明细,设置为不可报价
- String sql = "update purc$puinquiryitems set id_overdue = 1 where id_id = " + item.getSourceId();
- jdbcTemplate.update(sql);
- // 如果是替代料报价的采纳,添加替代料到询价方对应物料
- if (status.equals(Constant.YES)) {
- addProductReplace(item);
- }
- inquiryService.adoptMessage(item, InquirySource.MALL.name());
- }
- /**
- * 更新询价单明细采纳状态
- * @param id 询价单明细id
- * @param agreed 采纳参数 1 或 0
- */
- private void updatePurcInquiryItemAgreed(Long id, short agreed) {
- PurcInquiryItem inquiryItem = purcInquiryItemDao.findOne(id);
- inquiryItem.setAgreed(agreed);
- purcInquiryItemDao.save(inquiryItem);
- }
- /**
- * 替代料报价采纳之后,添加替代料到询价企业对应物料
- * @param item 报价明细
- */
- private void addProductReplace(PublicInquiryItem item) {
- if (null != item.getIsReplace() && Constant.YES == item.getIsReplace() && !StringUtils.isEmpty(item.getReplaceCmpCode())
- && !StringUtils.isEmpty(item.getReplaceBrand())) {
- try {
- String url = PS_PRODUCT_URL + "/product/save/inquiry?replaceCmpCode=" + URLEncoder.encode(item.getReplaceCmpCode(), "UTF-8")
- + "&replaceBrand=" + URLEncoder.encode(item.getReplaceBrand(), "UTF-8");
- Product product;
- if (null != item.getProductId()) {
- product = productDao.findOne(item.getProductId());
- product.setUserUU(item.getInquiry().getRecorderUU());
- } else {
- product = new Product();
- // 需要哪些字段
- product.setEnUU(item.getInquiry().getEnUU());
- product.setUserUU(item.getInquiry().getRecorderUU());
- product.setCmpCode(item.getCmpCode());
- product.setBrand(item.getInbrand());
- product.setpCmpCode(item.getCmpCode());
- product.setpBrandEn(item.getInbrand());
- product.setStandard((short) 0);
- product.setCreateTime(new Date());
- product.setSourceApp(item.getInquiry().getSourceApp());
- product.setSpec(StringUtils.isEmpty(item.getSpec()) ? item.getCmpCode() : item.getSpec());
- product.setKind(item.getProdTitle());
- }
- long start = System.currentTimeMillis();
- String res = HttpUtil.doPost(url, FlexJsonUtils.toJsonDeep(product));
- log.info("/product/save/inquiry 耗时:{}", (System.currentTimeMillis() - start));
- log.info("采纳替代物料报价,添加替代物料返回{}", res);
- } catch (Exception e) {
- log.info("/product/save/inquiry 替代料报价采纳之后保存到个人物料库中 出错:{}", e.getMessage());
- e.printStackTrace();
- }
- }
- }
- /**
- * 验证是否已采纳或拒绝
- * @param item 报价单
- */
- private void validateInquiry(PublicInquiryItem item) {
- if (null != item.getAgreed()) {
- if (item.getAgreed().equals(Constant.YES)) {
- throw new IllegalOperatorException("该报价已被采纳,请勿重复处理");
- } else if (item.getAgreed().equals(Constant.NO)) {
- throw new IllegalOperatorException("该报价已被拒绝,请勿重复处理");
- }
- }
- }
- /**
- * 商城通过报价明细id拒绝对供应商报价
- *
- * @param id 报价明细id
- * @param status 状态
- */
- @Override
- public void refuseQuote(Long id, Short status,String refusereason) {
- PublicInquiryItem item = itemDao.findOne(id);
- // 验证是否重复操作
- validateInquiry(item);
- item.setAgreed(status);
- item.setRefusereason(refusereason);
- item.setDecideDownStatus((short) Status.NOT_UPLOAD.value());
- itemDao.save(item);
- if (status.equals(Constant.YES)) {
- inquiryRemindDao.updateStatus(item.getSourceId(), Status.ALLOW.value(), item.getVendUU());
- inquiryEnRemindDao.updateStatus(item.getSourceId(), Status.ALLOW.value(), item.getVendUU());
- updatePurcInquiryItemAgreed(item.getSourceId(), status);
- } else if (status.equals(Constant.NO)) {
- inquiryRemindDao.updateStatus(item.getSourceId(), Status.NOTALLOW.value(), item.getVendUU());
- inquiryEnRemindDao.updateStatus(item.getSourceId(), Status.NOTALLOW.value(), item.getVendUU());
- }
- inquiryService.refuseMessage(item,InquirySource.MALL.name());
- }
- /**
- * 针对客户,查询供应商报价详情
- *
- * @param id 主表id
- * @param enuu 企业UU
- * @return
- */
- @Override
- public InquiryDetailInfo findById(Long id, Long enuu) {
- PublicInquiry inquiry = inquiryDao.findOne(id);
- InquiryDetailInfo inquiryInfo = new InquiryDetailInfo();
- if (inquiry != null) {
- inquiryInfo.setAttachs(inquiry.getAttachs());
- inquiryInfo.setAuditor(inquiry.getAuditor());
- inquiryInfo.setCheck(inquiry.getCheck());
- inquiryInfo.setCode(inquiry.getCode());
- inquiryInfo.setDate(inquiry.getDate());
- inquiryInfo.setEndDate(inquiry.getEndDate());
- inquiryInfo.setEnterprise(inquiry.getEnterprise());
- inquiryInfo.setEnUU(inquiry.getEnUU());
- inquiryInfo.setEnvironment(inquiry.getEnvironment());
- inquiryInfo.setId(inquiry.getId());
- inquiryInfo.setIsOpen(inquiry.getIsOpen());
- inquiryInfo.setOverdue(inquiry.getOverdue());
- inquiryInfo.setPriceType(inquiry.getPriceType());
- inquiryInfo.setRecorder(inquiry.getRecorder());
- inquiryInfo.setRecorderUU(inquiry.getRecorderUU());
- inquiryInfo.setRemark(inquiry.getRemark());
- inquiryInfo.setSourceApp(inquiry.getSourceApp());
- inquiryInfo.setSourceId(inquiry.getSourceId());
- inquiryInfo.setShip(inquiry.getShip());
- inquiryInfo.setInvoice(inquiry.getInvoice());
- inquiryInfo.setInquirytype(inquiry.getInquirytype());
- Set<Long> ids = new HashSet<Long>();
- List<Long> idList = new ArrayList<>();
- Set<InquiryProductInfo> products = new HashSet<InquiryProductInfo>();
- if (!CollectionUtils.isEmpty(inquiry.getInquiryItems())) {
- for (PublicInquiryItem item : inquiry.getInquiryItems()) {
- if (item.getProductId() != null) {
- idList.add(item.getProductId());
- ids.addAll(idList);
- } else {
- InquiryProductInfo productInfo = new InquiryProductInfo();
- Set<PublicInquiryItem> items = new HashSet<PublicInquiryItem>();
- productInfo.setBrand(item.getInbrand());
- productInfo.setSpec(item.getSpec());
- productInfo.setCode(item.getProdCode());
- productInfo.setTitle(item.getProdTitle());
- productInfo.setUnit(item.getUnit());
- productInfo.setCmpCode(item.getCmpCode());
- products.add(productInfo);
- for (PublicInquiryItem item1 : inquiry.getInquiryItems()) {
- if (item1.getCmpCode() != null && item1.getCmpCode().equals(productInfo.getCmpCode())) {
- String sql = "select at_path,at_name from attachs a left join public$inquiryitems$attach p on a.at_id = p.at_id " +
- "left join public$inquiryitems i on p.id_id = i.id_id where i.id_id = " + item1.getId();
- List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
- if (!org.springframework.util.CollectionUtils.isEmpty(maps)) {
- Map<String, Object> map = maps.get(0);
- item1.setAttachUrl(map.get("at_path").toString());
- item1.setAttachName(map.get("at_name").toString());
- }
- items.add(item1);
- }
- }
- productInfo.setInquiryItems(items);
- inquiryInfo.setProducts(products);
- }
- }
- }
- if (!CollectionUtils.isEmpty(ids)) {
- for (Long idInfo : ids) {
- InquiryProductInfo productInfo = new InquiryProductInfo();
- Set<PublicInquiryItem> items = new HashSet<PublicInquiryItem>();
- Product product = productDao.findOne(idInfo);
- productInfo.setBrand(product.getBrand());
- productInfo.setId(product.getId());
- productInfo.setSpec(product.getSpec());
- productInfo.setCode(product.getCode());
- productInfo.setTitle(product.getTitle());
- productInfo.setUnit(product.getUnit());
- productInfo.setCmpCode(product.getCmpCode());
- for (PublicInquiryItem item : inquiry.getInquiryItems()) {
- if (item.getProductId().equals(idInfo)) {
- String sql = "select at_path,at_name from attachs a left join public$inquiryitems$attach p on a.at_id = p.at_id " +
- "left join public$inquiryitems i on p.id_id = i.id_id where i.id_id = " + item.getId();
- List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
- if (!org.springframework.util.CollectionUtils.isEmpty(maps)) {
- Map<String, Object> map = maps.get(0);
- item.setAttachUrl(map.get("at_path").toString());
- item.setAttachName(map.get("at_name").toString());
- }
- items.add(item);
- }
- }
- productInfo.setInquiryItems(items);
- products.add(productInfo);
- inquiryInfo.setProducts(products);
- }
- }
- }
- return inquiryInfo;
- }
- /**
- * 通过企业UU和分页信息等查询已发布信息
- *
- * @param info 分页信息
- * @param filter 过滤条件
- * @return
- */
- @Override
- public Page<PurcInquiry> findByPageInfo(final PageInfo info, SearchFilter filter) {
- if (info.getOffset() == 0) {
- info.setOffset(info.getPageSize() * (info.getPageNumber() - 1));
- }
- Sort sort = new Sort(Sort.Direction.DESC, "date");
- if (info.getPageNumber() == 0) {
- info.setPageNumber(1);
- }
- if (info.getPageSize() == 0) {
- info.setPageSize(5);
- }
- info.setSort(sort);
- if (null == filter) {
- throw new IllegalOperatorException("未传入过滤条件");
- }
- if (null == filter.getUserUU() && null == filter.getEnUU()) {
- throw new IllegalAccessError("非法访问");
- }
- if (null != filter.getUserUU()) {
- info.expression(PredicateUtils.eq("recorderUU", filter.getUserUU(), false));
- }
- if (null != filter.getEnUU()) {
- info.expression(PredicateUtils.eq("enUU", filter.getEnUU(), false));
- } else {
- info.expression(PredicateUtils.isNull("enUU"));
- }
- if (!StringUtils.isEmpty(filter.getKeyword())) {
- SimpleExpression code = new SimpleExpression("remark", filter.getKeyword(), CriterionExpression.Operator.LIKE);
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{code};
- LogicalExpression logicalExpression = PredicateUtils.or(simpleExpressions);
- info.expression(logicalExpression);
- }
- if (filter.getFromDate() != null) {
- info.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
- }
- if (filter.getEndDate() != null) {
- info.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
- }
- SimpleExpression amount = new SimpleExpression("amount", Constant.YES, CriterionExpression.Operator.GT);
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{amount};
- LogicalExpression logicalExpression = PredicateUtils.and(simpleExpressions);
- info.expression(logicalExpression);
- return purcInquiryDao.findAll(new Specification<PurcInquiry>() {
- @Override
- public Predicate toPredicate(Root<PurcInquiry> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
- query.where(info.getPredicates(root, query, builder));
- return null;
- }
- }, info);
- }
- /**
- * 针对客户,查询单个物料的报价情况
- *
- * @param id 明细id
- * @param enuu 当前企业UU
- * @return
- */
- @Override
- public InquiryProductInfo findInquiryDetailById(Long id, Long enuu) {
- List<PublicInquiryItem> items = itemDao.findBySourceId(id);
- InquiryProductInfo productInfo = new InquiryProductInfo();
- if (!CollectionUtils.isEmpty(items)) {
- Long prId = items.get(0).getProductId();
- if (null != prId) {
- Product product = productDao.findOne(prId);
- productInfo.setBrand(product.getBrand());
- productInfo.setCode(product.getCode());
- productInfo.setTitle(product.getTitle());
- productInfo.setSpec(product.getSpec());
- productInfo.setUnit(product.getUnit());
- productInfo.setCmpCode(product.getCmpCode());
- } else {
- productInfo.setCmpCode(items.get(0).getCmpCode());
- productInfo.setBrand(items.get(0).getInbrand());
- }
- productInfo.setInquiryItems(new HashSet<PublicInquiryItem>(items));
- }
- return productInfo;
- }
- /**
- * 针对客户查询供应商报价信息
- *
- * @param pageInfo 分页信息
- * @param filter 过滤条件
- * @return
- */
- @Override
- public Page<PurcInquiryItemInfo> findQuotationsByPage(final PageInfo pageInfo, final SearchFilter filter, Long enUU, Long userUU, Short overdue) {
- if (enUU == null && userUU == null) {
- throw new IllegalAccessError("非法访问");
- }
- Sort sort = new Sort(Sort.Direction.DESC, "date");
- if (pageInfo.getOffset() == 0) {
- pageInfo.setOffset(pageInfo.getPageSize() * (pageInfo.getPageNumber() - 1));
- }
- pageInfo.setSort(sort);
- if (enUU != null) {
- pageInfo.filter("inquiry.enUU", enUU);
- } else {
- if (userUU != null) {
- pageInfo.filter("inquiry.recorderUU", userUU);
- pageInfo.expression(PredicateUtils.isNull("inquiry.enUU"));
- }
- }
- if (StringUtils.hasText(filter.getKeyword())) {
- SimpleExpression cmpCode = new SimpleExpression("cmpCode", filter.getKeyword(), CriterionExpression.Operator.LIKE);
- SimpleExpression inbrand = new SimpleExpression("inbrand", filter.getKeyword(), CriterionExpression.Operator.LIKE);
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{inbrand, cmpCode};
- LogicalExpression logicalExpression = PredicateUtils.or(simpleExpressions);
- pageInfo.expression(logicalExpression);
- }
- if (filter.getFromDate() != null) {
- pageInfo.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
- }
- if (filter.getEndDate() != null) {
- pageInfo.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
- }
- if (null != overdue) {
- // 已超过截止日期
- if (overdue.equals(Constant.YES)) {
- pageInfo.expression(PredicateUtils.lt("endDate", new Date(System.currentTimeMillis()), false));
- } else if (overdue.equals(Constant.NO)) {
- pageInfo.expression(PredicateUtils.gte("endDate", new Date(System.currentTimeMillis()), false));
- }
- }
- pageInfo.expression(PredicateUtils.gt("offerAmount", Constant.NO, false));
- Page<PurcInquiryItemInfo> items = inquiryItemDao.findAll(new Specification<PurcInquiryItemInfo>() {
- @Override
- public Predicate toPredicate(Root<PurcInquiryItemInfo> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
- query.where(pageInfo.getPredicates(root, query, builder));
- return null;
- }
- }, pageInfo);
- if (!CollectionUtils.isEmpty(items.getContent())) {
- for (PurcInquiryItemInfo itemInfo : items.getContent()) {
- List<PublicInquiryItem> itemList = itemDao.findBySourceIdOrderByOfferTimeDesc(itemInfo.getId());
- itemInfo.setQutations(itemList);
- itemInfo.setQuotation(itemList.get(0));
- itemInfo.setAgreed(Constant.NO);
- if (!CollectionUtils.isEmpty(itemList)) {
- for (PublicInquiryItem i : itemList) {
- if (i.getAgreed() != null && i.getAgreed().equals(Constant.YES)) {
- itemInfo.setAgreed(Constant.YES);
- break;
- }
- }
- }
- if (null != itemInfo.getInquiry().getEndDate()) {
- itemInfo.setRemainingTime(itemInfo.getInquiry().getEndDate().getTime() - System.currentTimeMillis());
- }
- if (null == itemInfo.getProductId()) {
- Product product = new Product();
- product.setTitle(itemInfo.getProdTitle());
- product.setCmpCode(itemInfo.getCmpCode());
- product.setBrand(itemInfo.getInbrand());
- product.setSpec(itemInfo.getSpec());
- itemInfo.setProduct(product);
- }
- }
- }
- return items;
- }
- /**
- * 针对客户单个公共询价,查询供应商报价信息
- *
- * @param id
- * @return
- */
- @Override
- public PurcInquiryItemInfo findQuotationById(Long id) {
- PurcInquiryItemInfo itemInfo = inquiryItemDao.findOne(id);
- List<PublicInquiryItem> itemList = itemDao.findBySourceId(itemInfo.getId());
- itemInfo.setQutations(itemList);
- itemInfo.setAgreed(Constant.NO);
- if (!CollectionUtils.isEmpty(itemList)) {
- for (PublicInquiryItem i : itemList) {
- if (i.getAgreed() != null && i.getAgreed().equals(Constant.YES)) {
- itemInfo.setAgreed(Constant.YES);
- break;
- }
- }
- }
- if (null != itemInfo.getInquiry().getEndDate()) {
- itemInfo.setRemainingTime(itemInfo.getInquiry().getEndDate().getTime() - System.currentTimeMillis());
- }
- if (null == itemInfo.getProductId()) {
- Product product = new Product();
- product.setTitle(itemInfo.getProdTitle());
- product.setCmpCode(itemInfo.getCmpCode());
- product.setBrand(itemInfo.getInbrand());
- product.setSpec(itemInfo.getSpec());
- itemInfo.setProduct(product);
- }
- return itemInfo;
- }
- /**
- * 发送消息推送
- *
- */
- public void sendMessage(final Integer count, final List<InquiryRemind> reminds) {
- ThreadUtils.task(new Runnable() {
- @Override
- public void run() {
- try {
- List<MessageModel> models = new ArrayList<>();
- MessageModel model = new MessageModel();
- model.setType(INQUIRY_TYPE);
- model.setType(INQUIRY_TYPE_SELLER_MALL);
- model.setProducerApp("MALl");
- model.setConsumerType(CUST_TYPE);
- model.setConsumerApp(CONSUMERAPP_HIDE);
- model.setRemark(String.valueOf(count));
- for(InquiryRemind remind : reminds){
- model.setReceiverEnuu(remind.getVendUU());
- model.setReceiverUu(remind.getVendUserUU());
- model.setSenderEnuu(MESSAGE_SENDERENUU);
- model.setSenderUu(MESSAGE_SENDERUU);
- }
- String company = "";
- Enterprise enterprise = enterpriseDao.findOne(reminds.get(0).getVendUU());
- if(null != enterprise){
- company = enterprise.getEnName();
- }
- String content = company + "新增了"+ count +"张公共询价单,快登录优软商城查看详情吧!https://www.usoftmall.com/vendor#/seekPurchase";
- model.setContent(content);
- model.setSmsType(SMS_TYPE);
- model.setSmTemplate(SMS_TEMP_ID);
- models.add(model);
- long start = System.currentTimeMillis();
- HttpUtil.doPost(PS_MESSAGE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
- log.info("/message 耗时:{},消息数:{}", (System.currentTimeMillis() - start), models.size());
- log.info("公共询价", "此次{}公司新增{}张公共询价", company, count);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * 发送消息推送 (定时任务使用)
- *
- */
- @Override
- public void sendMessage(final List<InquiryRemind> reminds) {
- ThreadUtils.task(new Runnable() {
- @Override
- public void run() {
- try {
- log.info("发送消息开始");
- List<MessageModel> models = new ArrayList<>();
- for (InquiryRemind remind : reminds) {
- if (null != remind.getVendUU() && null != remind.getVendUserUU()) {
- Integer count = remind.getCounts();
- MessageModel model = new MessageModel();
- model.setType(INQUIRY_TYPE);
- model.setType(INQUIRY_TYPE_SELLER_MALL);
- model.setProducerApp(SOURCEAPP_MALL);
- model.setConsumerType(CUST_TYPE);
- model.setConsumerApp(CONSUMERAPP_HIDE);
- model.setRemark(String.valueOf(count));
- model.setReceiverEnuu(remind.getVendUU());
- model.setReceiverUu(remind.getVendUserUU());
- model.setSenderEnuu(MESSAGE_SENDERENUU);
- model.setSenderUu(MESSAGE_SENDERUU);
- String company = "";
- Enterprise enterprise = enterpriseDao.findOne(remind.getVendUU());
- if(null != enterprise){
- company = enterprise.getEnName();
- }
- String content = company + "新增了"+ count +"张公共询价单,快登录优软商城查看详情吧!https://www.usoftmall.com/vendor#/seekPurchase";
- model.setContent(content);
- model.setSmsType(SMS_TYPE);
- model.setSmTemplate(SMS_TEMP_ID);
- models.add(model);
- log.info("此次{}公司新增{}张公共询价(发送信息前),接收人UU:{}", company, remind.getCounts(), model.getReceiverUu());
- }
- if (models.size() >= 500) {
- long start = System.currentTimeMillis();
- String res = HttpUtil.doPost(PS_MESSAGE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
- log.info("消息中心生成消息");
- log.info("发送消息{},耗时:{}", models.size(), (System.currentTimeMillis() - start));
- models = new ArrayList<>();
- }
- }
- if (!CollectionUtils.isEmpty(models)) {
- long start = System.currentTimeMillis();
- String res = HttpUtil.doPost(PS_MESSAGE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
- log.info("消息中心生成消息");
- log.info("发送消息{},耗时:{}", models.size(), (System.currentTimeMillis() - start));
- }
- log.info("发送消息全部完成");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * 以供应商企业UU和用户UU分组查询商机
- * @param hours 查之前多少小时内的单据
- * @return 商机List
- */
- @Override
- public List<InquiryRemind> findInquiryRemindGroupByVendUUAndVendUserUU(int hours) {
- String sql = "select ir_venduu vendUU,ir_venduseruu vendUserUU, count(1) counts from purc$inquiry$remind where ir_date between date_sub(now(), interval "
- + hours + " hour) and now() group by ir_venduu,ir_venduseruu";
- return jdbcTemplate.query(sql, new BeanPropertyRowMapper<InquiryRemind>(InquiryRemind.class));
- }
- /**
- * 讲报价产品数设置进page
- *
- * @param page 询价单page
- * @return 询价单pege
- */
- @Override
- public Page<PurcInquiry> setQuotedAmount(Page<PurcInquiry> page) {
- for (PurcInquiry inquiry : page.getContent()) {
- List<Long> itemIds = new ArrayList<>();
- Long[] itemIdArray = new Long[inquiry.getInquiryItems().size()];
- for (PurcInquiryItem item : inquiry.getInquiryItems()) {
- itemIds.add(item.getId());
- }
- Integer size = itemDao.getQuotedAmountBySourceId(itemIds.toArray(itemIdArray));
- inquiry.setQuotedAmount(size);
- }
- return page;
- }
- }
|