|
@@ -1,5 +1,6 @@
|
|
|
package com.uas.ps.inquiry.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.ps.core.util.ContextUtils;
|
|
|
import com.uas.ps.entity.Product;
|
|
@@ -24,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.amqp.rabbit.support.CorrelationData;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.CacheEvict;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Sort;
|
|
@@ -31,6 +33,7 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.RowMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.ui.ModelMap;
|
|
@@ -42,6 +45,8 @@ import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -722,7 +727,10 @@ public class PublicInquiryServiceImpl implements PublicInquiryService {
|
|
|
Integer month = now.get(Calendar.MONTH) + 1;
|
|
|
ModelMap result = new ModelMap();
|
|
|
try {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
Long current = inquiryItemInfoDao.countByMonth(year, month);
|
|
|
+ log.info("查询本月询价单耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
result.put("current", current);
|
|
|
if (month == 1) {
|
|
|
year = year - 1;
|
|
@@ -731,6 +739,7 @@ public class PublicInquiryServiceImpl implements PublicInquiryService {
|
|
|
month = month - 1;
|
|
|
}
|
|
|
Long last = inquiryItemInfoDao.countByMonth(year, month);
|
|
|
+ log.info("查询本月询价单耗时:{}", (System.currentTimeMillis() - start));
|
|
|
result.put("last", last);
|
|
|
result.put("success", "true");
|
|
|
} catch (Exception e) {
|
|
@@ -780,6 +789,7 @@ public class PublicInquiryServiceImpl implements PublicInquiryService {
|
|
|
* @param valid 1有效 0 无效
|
|
|
* @return
|
|
|
*/
|
|
|
+ @CacheEvict(value="inquiry_public", allEntries = true)
|
|
|
@Override
|
|
|
public ModelMap deleteItems(Long id, Integer valid) {
|
|
|
ModelMap map = new ModelMap();
|
|
@@ -1274,63 +1284,184 @@ public class PublicInquiryServiceImpl implements PublicInquiryService {
|
|
|
*
|
|
|
* @param info 分页参数
|
|
|
* @param filter 过滤条件
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public IPage<PurcInquiryItemInfo> findTodoByPageInfo(final PageInfo info, final SearchFilter filter) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ if (null != filter && !"{}".equals(JSON.toJSONString(filter))) {
|
|
|
+ Long enUU = filter.getEnUU();
|
|
|
+
|
|
|
+
|
|
|
+ setFilter(info, filter);
|
|
|
+
|
|
|
+ Page<PurcInquiryItemInfo> orders = inquiryItemInfoDao.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);
|
|
|
+ log.info("filter-查询询价单列表,耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+
|
|
|
+
|
|
|
+ return covert(orders, enUU);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ String sql = "SELECT * FROM ( SELECT * FROM purc$puinquiryitems WHERE id_valid = 1 ORDER BY id_date DESC LIMIT ?,? ) a " +
|
|
|
+ "LEFT JOIN `purc$puinquiry` b ON a.id_inid = b.in_id";
|
|
|
+ List<PurcInquiryItemInfo> orders = jdbcTemplate.query(sql, getRowMapper(),
|
|
|
+ info.getPageSize() * (info.getPageNumber() - 1), info.getPageSize() * info.getPageNumber());
|
|
|
+ log.info("查询询价单耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+ String countSql = "select count(1) from purc$puinquiryitems where id_valid = 1";
|
|
|
+ Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
|
|
+ log.info("查询条数耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+
|
|
|
+ IPage<PurcInquiryItemInfo> iPage = new IPage<>();
|
|
|
+ iPage.setTotalElements(count);
|
|
|
+ iPage.setSize(info.getPageSize());
|
|
|
+ iPage.setNumber(info.getPageNumber());
|
|
|
+ iPage.setContent(orders);
|
|
|
+ return iPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 过滤条件处理
|
|
|
+ * @param info 分页参数
|
|
|
+ * @param filter 过滤条件
|
|
|
+ */
|
|
|
+ private void setFilter(PageInfo info, SearchFilter filter) {
|
|
|
Sort sort = new Sort(Sort.Direction.DESC, "id", "date");
|
|
|
if (info.getOffset() == 0) {
|
|
|
info.setOffset(info.getPageSize() * (info.getPageNumber() - 1));
|
|
|
}
|
|
|
info.setSort(sort);
|
|
|
- Long enUU = null;
|
|
|
- if (null != filter) {
|
|
|
- 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 (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
- info.expression(PredicateUtils.in("inquiry.enUU", filter.getDistribute(), false));
|
|
|
- }
|
|
|
-
|
|
|
- enUU = filter.getEnUU();
|
|
|
- if (!StringUtils.isEmpty(filter.getIsAll()) && filter.getIsAll() == 0 && !StringUtils.isEmpty(filter.getEnUU())) {
|
|
|
- info.expression(PredicateUtils.ne("inquiry.enUU", filter.getEnUU(), false));
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(filter.getKeyword())) {
|
|
|
- SimpleExpression cmpCode = new SimpleExpression("cmpCode", filter.getKeyword(), CriterionExpression.Operator.LIKE, true);
|
|
|
- SimpleExpression brand = new SimpleExpression("inbrand", filter.getKeyword(), CriterionExpression.Operator.LIKE, true);
|
|
|
- SimpleExpression title = new SimpleExpression("prodTitle", filter.getKeyword(), CriterionExpression.Operator.LIKE, true);
|
|
|
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{cmpCode, brand, title};
|
|
|
- LogicalExpression logical = new LogicalExpression(simpleExpressions, CriterionExpression.Operator.OR);
|
|
|
- info.expression(logical);
|
|
|
- }
|
|
|
+ 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));
|
|
|
}
|
|
|
- Page<PurcInquiryItemInfo> orders = inquiryItemInfoDao.findAll(new Specification<PurcInquiryItemInfo>() {
|
|
|
+ if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
+ info.expression(PredicateUtils.in("enuu", filter.getDistribute(), false));
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(filter.getIsAll()) && filter.getIsAll() == 0 && !StringUtils.isEmpty(filter.getEnUU())) {
|
|
|
+ info.expression(PredicateUtils.ne("enuu", filter.getEnUU(), false));
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(filter.getKeyword())) {
|
|
|
+ SimpleExpression cmpCode = new SimpleExpression("cmpCode", filter.getKeyword(), CriterionExpression.Operator.LIKE, true);
|
|
|
+ SimpleExpression brand = new SimpleExpression("inbrand", filter.getKeyword(), CriterionExpression.Operator.LIKE, true);
|
|
|
+ SimpleExpression title = new SimpleExpression("prodTitle", filter.getKeyword(), CriterionExpression.Operator.LIKE, true);
|
|
|
+ SimpleExpression[] simpleExpressions = new SimpleExpression[]{cmpCode, brand, title};
|
|
|
+ LogicalExpression logical = new LogicalExpression(simpleExpressions, CriterionExpression.Operator.OR);
|
|
|
+ info.expression(logical);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 实体转换
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private RowMapper<PurcInquiryItemInfo> getRowMapper() {
|
|
|
+ return new RowMapper<PurcInquiryItemInfo>() {
|
|
|
+
|
|
|
@Override
|
|
|
- public Predicate toPredicate(Root<PurcInquiryItemInfo> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
- query.where(info.getPredicates(root, query, builder));
|
|
|
- return null;
|
|
|
+ public PurcInquiryItemInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
|
+ PurcInquiryItemInfo item = new PurcInquiryItemInfo();
|
|
|
+ item.setId(rs.getLong("id_id"));
|
|
|
+ item.setNumber(rs.getShort("id_number"));
|
|
|
+ item.setUserUU(rs.getLong("id_useruu"));
|
|
|
+ item.setUserName(rs.getString("id_username"));
|
|
|
+ item.setUserTel(rs.getString("id_usertel"));
|
|
|
+ item.setProductId(rs.getLong("id_prid"));
|
|
|
+ item.setProdCode(rs.getString("id_prodcode"));
|
|
|
+ item.setProdTitle(rs.getString("id_prodtitle"));
|
|
|
+ item.setSpec(rs.getString("id_prodspec"));
|
|
|
+ item.setInbrand(rs.getString("id_inbrand"));
|
|
|
+ item.setCurrency(rs.getString("id_currency"));
|
|
|
+ item.setTaxrate(rs.getFloat("id_taxrate"));
|
|
|
+ item.setFromDate(rs.getDate("id_date"));
|
|
|
+ item.setStatus(rs.getShort("id_status"));
|
|
|
+ item.setOverdue(rs.getShort("id_overdue"));
|
|
|
+ item.setSource(rs.getString("id_source"));
|
|
|
+ item.setNeedquantity(rs.getDouble("id_needquantity"));
|
|
|
+ item.setSourceid(rs.getLong("id_sourceid"));
|
|
|
+ item.setDate(rs.getDate("id_date"));
|
|
|
+ item.setEnuu(rs.getLong("id_enuu"));
|
|
|
+ item.setEndDate(rs.getDate("id_enddate"));
|
|
|
+ item.setOfferAmount(rs.getInt("id_offeramount"));
|
|
|
+ item.setAgreed(rs.getShort("id_agreed"));
|
|
|
+ item.setValid(rs.getInt("id_valid"));
|
|
|
+
|
|
|
+ PurcInquiryInfo purcInquiryInfo = new PurcInquiryInfo();
|
|
|
+ purcInquiryInfo.setId(rs.getLong("in_id"));
|
|
|
+ purcInquiryInfo.setEnUU(rs.getLong("in_enuu"));
|
|
|
+ purcInquiryInfo.setEnName(rs.getString("in_enname"));
|
|
|
+ purcInquiryInfo.setRecorderUU(rs.getLong("in_recorderuu"));
|
|
|
+ purcInquiryInfo.setCode(rs.getString("in_code"));
|
|
|
+ purcInquiryInfo.setDate(rs.getDate("in_date"));
|
|
|
+ purcInquiryInfo.setRecorder(rs.getString("in_recorder"));
|
|
|
+ purcInquiryInfo.setEndDate(rs.getDate("in_enddate"));
|
|
|
+ purcInquiryInfo.setRemark(rs.getString("in_remark"));
|
|
|
+ purcInquiryInfo.setEnvironment(rs.getString("in_environment"));
|
|
|
+ purcInquiryInfo.setEnteryStatus(rs.getInt("in_enterystatus"));
|
|
|
+ purcInquiryInfo.setShip(rs.getString("in_ship"));
|
|
|
+ purcInquiryInfo.setInvoice(rs.getShort("in_invoice"));
|
|
|
+ purcInquiryInfo.setIfTax(rs.getShort("in_iftax"));
|
|
|
+ purcInquiryInfo.setCurrency(rs.getString("in_currency"));
|
|
|
+ purcInquiryInfo.setInquirytype(rs.getString("in_inquirytype"));
|
|
|
+ purcInquiryInfo.setSourceapp(rs.getString("in_sourceapp"));
|
|
|
+ purcInquiryInfo.setErpid(rs.getLong("in_erpid"));
|
|
|
+ purcInquiryInfo.setErpdate(rs.getDate("in_erpdate"));
|
|
|
+ purcInquiryInfo.setAmount(rs.getInt("in_amount"));
|
|
|
+ purcInquiryInfo.setSpec(rs.getString("in_spec"));
|
|
|
+ purcInquiryInfo.setCount(rs.getInt("in_count"));
|
|
|
+
|
|
|
+ item.setInquiry(purcInquiryInfo);
|
|
|
+ return item;
|
|
|
}
|
|
|
- }, info);
|
|
|
-
|
|
|
- if (null != filter && !StringUtils.isEmpty(enUU)) {
|
|
|
- for (PurcInquiryItemInfo itemInfo : orders) {
|
|
|
- PublicInquiryItem item = publicInquiryItemDao.findByVendUUAndSourceId(filter.getEnUU(), itemInfo.getId());
|
|
|
- List<InquiryEnRemind> inquiryEnRemind = inquiryEnRemindDao.findByItemIdAndVendUU(itemInfo.getId(), filter.getEnUU());
|
|
|
- if (!CollectionUtils.isEmpty(inquiryEnRemind) && inquiryEnRemind.size() > 0) {
|
|
|
- itemInfo.setAllotStatus((short) 1);
|
|
|
- } else {
|
|
|
- itemInfo.setAllotStatus((short) 0);
|
|
|
- }
|
|
|
- itemInfo.setQuotation(item);
|
|
|
- }
|
|
|
- }
|
|
|
- return covert(orders, enUU);
|
|
|
+
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
* 将数据库查询的数据进行封装处理
|
|
|
*
|
|
@@ -1338,32 +1469,47 @@ public class PublicInquiryServiceImpl implements PublicInquiryService {
|
|
|
* @return
|
|
|
*/
|
|
|
private IPage<PurcInquiryItemInfo> covert(Page<PurcInquiryItemInfo> orders, Long enuu) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ StringBuilder sourceIds = new StringBuilder();
|
|
|
if (!CollectionUtils.isEmpty(orders.getContent()) && null != enuu) {
|
|
|
for (PurcInquiryItemInfo itemInfo : orders.getContent()) {
|
|
|
- PublicInquiryItem item = publicInquiryItemDao.findByVendUUAndSourceId(enuu, itemInfo.getId());
|
|
|
+ if (!StringUtils.isEmpty(sourceIds)) {
|
|
|
+ sourceIds.append(",");
|
|
|
+ }
|
|
|
+ sourceIds.append(itemInfo.getId());
|
|
|
+
|
|
|
+ Product product = new Product();
|
|
|
+ product.setTitle(itemInfo.getProdTitle());
|
|
|
+ product.setCmpCode(itemInfo.getCmpCode());
|
|
|
+ product.setBrand(itemInfo.getInbrand());
|
|
|
+ product.setSpec(itemInfo.getSpec());
|
|
|
+ product.setCode(itemInfo.getProdCode());
|
|
|
+ if (null == product.getCode()) {
|
|
|
+ product.setCode(itemInfo.getCmpCode());
|
|
|
+ }
|
|
|
+ itemInfo.setProduct(product);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<PublicInquiryItem> items = publicInquiryItemDao.findByVendUUAndSourceIds(enuu, sourceIds.toString());
|
|
|
+
|
|
|
+
|
|
|
+ HashMap<Long, PublicInquiryItem> map = new HashMap<>(50);
|
|
|
+ for (PublicInquiryItem item : items) {
|
|
|
+
|
|
|
+ map.put(item.getSourceId(), item);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (PurcInquiryItemInfo itemInfo : orders.getContent()) {
|
|
|
itemInfo.setQuoted(Constant.NO);
|
|
|
- if (null != item) {
|
|
|
- itemInfo.setAgreed(item.getAgreed());
|
|
|
- itemInfo.setQuteId(item.getId());
|
|
|
+ if (null != map.get(itemInfo.getId())) {
|
|
|
+ itemInfo.setAgreed(map.get(itemInfo.getId()).getAgreed());
|
|
|
+ itemInfo.setQuteId(map.get(itemInfo.getId()).getId());
|
|
|
itemInfo.setQuoted(Constant.YES);
|
|
|
}
|
|
|
- if (null == itemInfo.getProductId()) {
|
|
|
- Product product = new Product();
|
|
|
- product.setTitle(itemInfo.getProdTitle());
|
|
|
- product.setCmpCode(itemInfo.getCmpCode());
|
|
|
- product.setBrand(itemInfo.getInbrand());
|
|
|
- product.setSpec(itemInfo.getSpec());
|
|
|
- product.setCode(itemInfo.getProdCode());
|
|
|
- if (null == product.getCode()) {
|
|
|
- product.setCode(itemInfo.getCmpCode());
|
|
|
- }
|
|
|
- itemInfo.setProduct(product);
|
|
|
- } else {
|
|
|
- Product product = productDao.findOne(itemInfo.getProductId());
|
|
|
- itemInfo.setProduct(product);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
+ log.info("filter-转换数据耗时:{}", (System.currentTimeMillis() - start));
|
|
|
return IPageUtils.covert(orders);
|
|
|
}
|
|
|
|