|
|
@@ -2,10 +2,10 @@ package com.uas.platform.b2c.trade.seek.service.impl;
|
|
|
|
|
|
import com.uas.platform.b2c.common.account.model.User;
|
|
|
import com.uas.platform.b2c.common.search.service.SearcherService;
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.support.log.UsageBufferedLogger;
|
|
|
import com.uas.platform.b2c.core.utils.StringUtilB2C;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
-import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
import com.uas.platform.b2c.prod.product.brand.modal.Brand;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
|
|
|
@@ -13,7 +13,6 @@ import com.uas.platform.b2c.prod.product.component.modal.Component;
|
|
|
import com.uas.platform.b2c.trade.seek.dao.*;
|
|
|
import com.uas.platform.b2c.trade.seek.model.*;
|
|
|
import com.uas.platform.b2c.trade.seek.service.SeekPurchaseBomService;
|
|
|
-import com.uas.platform.b2c.trade.seek.utils.DateUtils;
|
|
|
import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
@@ -32,11 +31,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
@@ -102,7 +103,7 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
/**
|
|
|
* 模板列
|
|
|
*/
|
|
|
- private final int SEEK_TEMPLATE_COLNUM = 6;
|
|
|
+ private final int SEEK_TEMPLATE_COLNUM = 5;
|
|
|
/**
|
|
|
* 上限行数
|
|
|
*/
|
|
|
@@ -115,10 +116,10 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
public final int CODENUM = 2;
|
|
|
// 品牌
|
|
|
public final int BRANDNUM = 0;
|
|
|
- // 截止日期
|
|
|
- public final int DEADLINENUM = 4;
|
|
|
+// // 截止日期
|
|
|
+// public final int DEADLINENUM = 4;
|
|
|
// 采购数量
|
|
|
- public final int AMOUNTNUM = 5;
|
|
|
+ public final int AMOUNTNUM = 4;
|
|
|
// public static final int CURRENCYNUM = 6;
|
|
|
// public static final int UNITPRICENUM = 7;
|
|
|
// public static final int ENCAPSULATIONNUM = 8;
|
|
|
@@ -154,6 +155,10 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
seekPurchaseBom.setReleaseDate(new Date(System.currentTimeMillis()));
|
|
|
seekPurchaseBom.setName(bomName);
|
|
|
seekPurchaseBom.setStatus(0);
|
|
|
+ seekPurchaseBom.setUu(SystemSession.getUser().getUserUU());
|
|
|
+ if (null != SystemSession.getUser().getEnterprise()) {
|
|
|
+ seekPurchaseBom.setEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ }
|
|
|
seekPurchaseBom = seekPurchaseBomDao.save(seekPurchaseBom);
|
|
|
// 获取第一行的信息
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
@@ -167,6 +172,7 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
if (sheet.getRow(startRow) != null && vaidSample(sheet.getRow(startRow))) {
|
|
|
startRow = 3;
|
|
|
}
|
|
|
+ Date releaseDate = new Date(System.currentTimeMillis());
|
|
|
for (int r = startRow; r <= rowNum; r++) {
|
|
|
Row row = sheet.getRow(r);
|
|
|
if (row != null) {
|
|
|
@@ -176,7 +182,7 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
continue;
|
|
|
}
|
|
|
seekPurchaseByBatch.setBomId(seekPurchaseBom.getId());
|
|
|
- seekPurchaseByBatch.setReleaseDate(new Date(System.currentTimeMillis()));
|
|
|
+ seekPurchaseByBatch.setReleaseDate(releaseDate);
|
|
|
seekPurchaseByBatchList.add(seekPurchaseByBatch);
|
|
|
}
|
|
|
}
|
|
|
@@ -184,6 +190,8 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
seekPurchaseBomDao.delete(seekPurchaseBom.getId());
|
|
|
return new ResultMap(CodeType.PARAMETER_ERROR, "上传的excel内容为空,请填写完整后上传");
|
|
|
} else {
|
|
|
+ seekPurchaseBom.setAmount(seekPurchaseByBatchList.size());
|
|
|
+ seekPurchaseBomDao.save(seekPurchaseBom);
|
|
|
seekPurchaseByBatchDao.save(seekPurchaseByBatchList);
|
|
|
}
|
|
|
}
|
|
|
@@ -224,9 +232,9 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
if (!"品牌名称".equals(StringUtilB2C.getStr(brandCellObj))) {
|
|
|
return false;
|
|
|
}
|
|
|
- Object deadlineCellObj = readWorkBookCell(headerRow.getCell(DEADLINENUM), Cell.CELL_TYPE_STRING,
|
|
|
- 0, DEADLINENUM);
|
|
|
- if (!"截止时间".equals(StringUtilB2C.getStr(deadlineCellObj))) {
|
|
|
+ Object prodTitleCellObj = readWorkBookCell(headerRow.getCell(KINDNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, KINDNUM);
|
|
|
+ if (!"物料名称".equals(StringUtilB2C.getStr(prodTitleCellObj))) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
@@ -273,34 +281,34 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
seekPurchaseByBatch.setBrand(convert(brandValue, 50));
|
|
|
}
|
|
|
|
|
|
- // 截止日期
|
|
|
- Object deadlineValue = readWorkBookCell(row.getCell(DEADLINENUM), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, DEADLINENUM);
|
|
|
- if (StringUtils.isEmpty(deadlineValue)) {
|
|
|
- result += 1;
|
|
|
- } else {
|
|
|
- String deadline = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(deadlineValue));
|
|
|
- if (deadline.contains(".")) {
|
|
|
- deadline = deadline.replace(".", "-");
|
|
|
- }
|
|
|
- if (deadline.contains("/")) {
|
|
|
- deadline = deadline.replace("/", "-");
|
|
|
- }
|
|
|
- try {
|
|
|
- deadline = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(deadline, 10);
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- Date deadlineDate = sdf.parse(deadline);
|
|
|
- Date now = sdf.parse(sdf.format(new Date()));
|
|
|
- if (deadlineDate.getTime() < now.getTime()) {
|
|
|
- seekPurchaseByBatch.setDeadline(null);
|
|
|
- } else {
|
|
|
- seekPurchaseByBatch.setDeadline(DateUtils.addTime(deadlineDate, 0, 23, 59, 59));
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- seekPurchaseByBatch.setDeadline(null);
|
|
|
- }
|
|
|
- }
|
|
|
+// // 截止日期
|
|
|
+// Object deadlineValue = readWorkBookCell(row.getCell(DEADLINENUM), Cell.CELL_TYPE_STRING,
|
|
|
+// rowNum, DEADLINENUM);
|
|
|
+// if (StringUtils.isEmpty(deadlineValue)) {
|
|
|
+// result += 1;
|
|
|
+// } else {
|
|
|
+// String deadline = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(deadlineValue));
|
|
|
+// if (deadline.contains(".")) {
|
|
|
+// deadline = deadline.replace(".", "-");
|
|
|
+// }
|
|
|
+// if (deadline.contains("/")) {
|
|
|
+// deadline = deadline.replace("/", "-");
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// deadline = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(deadline, 10);
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+// Date deadlineDate = sdf.parse(deadline);
|
|
|
+// Date now = sdf.parse(sdf.format(new Date()));
|
|
|
+// if (deadlineDate.getTime() < now.getTime()) {
|
|
|
+// seekPurchaseByBatch.setDeadline(null);
|
|
|
+// } else {
|
|
|
+// seekPurchaseByBatch.setDeadline(DateUtils.addTime(deadlineDate, 0, 23, 59, 59));
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// seekPurchaseByBatch.setDeadline(null);
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
// 类目
|
|
|
Object kindValue = readWorkBookCell(row.getCell(KINDNUM), Cell.CELL_TYPE_STRING,
|
|
|
@@ -318,7 +326,7 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
try {
|
|
|
Double amount = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(amountValue)));
|
|
|
int amountInt = amount.intValue();
|
|
|
- if (amount <= 0 || amount >= 1000000000 || amountInt != amount) {
|
|
|
+ if (amount <= 0 || amount >= 10000 || amountInt != amount) {
|
|
|
amount = null;
|
|
|
}
|
|
|
seekPurchaseByBatch.setAmount(amount);
|
|
|
@@ -488,95 +496,15 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
return new PageImpl<SeekPurchaseByBatch>(seekPurchaseByBatchList, pageInfo, pageSeeks.getTotalElements());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public ResultMap confirmBom(Long bomId, User user, String url) {
|
|
|
- SeekPurchaseBom seekPurchaseBom = seekPurchaseBomDao.findOne(bomId);
|
|
|
- if (seekPurchaseBom == null) {
|
|
|
- return new ResultMap(CodeType.NOT_PERMIT, "请勿重复发布");
|
|
|
+ public ResultMap confirmBom(Long bomId, String url, Long endTime, Integer count) {
|
|
|
+ if (null == endTime || null == count) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "存在未传入必需参数");
|
|
|
}
|
|
|
- PurcInquiry inquiry = new PurcInquiry();
|
|
|
+ SeekPurchaseBom seekPurchaseBom = seekPurchaseBomDao.findOne(bomId);
|
|
|
List<SeekPurchaseByBatch> seekPurchaseByBatchList = seekPurchaseByBatchDao.findByBomId(bomId);
|
|
|
- // 商城现货的数量
|
|
|
- int haveGoodsCount = 0;
|
|
|
- Set<PurcInquiryItem> inquiryItems = new HashSet<>();
|
|
|
- List<SeekPurchaseByBatch> deleteBatchList = new ArrayList<>();
|
|
|
- Date endDate = null;
|
|
|
- for (SeekPurchaseByBatch batch : seekPurchaseByBatchList) {
|
|
|
- SeekPurchase seekPurchase = new SeekPurchase();
|
|
|
- Calendar now = Calendar.getInstance();
|
|
|
- now.add(Calendar.DAY_OF_MONTH, 91);
|
|
|
- if (!StringUtils.isEmpty(batch.getCode()) && !StringUtils.isEmpty(batch.getBrand()) && !StringUtils.isEmpty(batch.getDeadline()) && batch.getDeadline().compareTo(now.getTime()) != 1) {
|
|
|
- PurcInquiryItem inquiryItem = new PurcInquiryItem();
|
|
|
- inquiryItem.setProdTitle(batch.getCode());
|
|
|
- inquiryItem.setUserUU(user.getUserUU());
|
|
|
- inquiryItem.setSource("MALL");
|
|
|
- inquiryItem.setUserName(user.getUserName());
|
|
|
- inquiryItem.setUserTel(user.getUserTel());
|
|
|
- inquiryItem.setNeedquantity(batch.getAmount());
|
|
|
- inquiryItem.setInbrand(batch.getBrand());
|
|
|
- inquiryItem.setCurrency(batch.getCurrency());
|
|
|
- inquiryItem.setCmpCode(batch.getCode().toUpperCase());
|
|
|
- inquiryItem.setUnitPrice(batch.getUnitPrice());
|
|
|
- inquiryItem.setProduceDate(batch.getProduceDate());
|
|
|
- inquiryItem.setDate(new Date());
|
|
|
- inquiryItem.setEndDate(batch.getDeadline());
|
|
|
- if (StringUtils.isEmpty(batch.getKind())) {
|
|
|
- batch.setKind(matchKind(batch.getBrand(), batch.getCode()));
|
|
|
- }
|
|
|
- inquiryItem.setProdTitle(batch.getKind());
|
|
|
- inquiryItem.setSpec(batch.getSpec());
|
|
|
- if (StringUtils.isEmpty(endDate)) {
|
|
|
- endDate = batch.getDeadline();
|
|
|
- } else {
|
|
|
- if (endDate.compareTo(batch.getDeadline()) != 1) {
|
|
|
- endDate = batch.getDeadline();
|
|
|
- }
|
|
|
- }
|
|
|
- inquiryItem.setEncapsulation(batch.getEncapsulation());
|
|
|
- // 商城现货搜索
|
|
|
- List<Goods> goods = goodsDao.getGoodsByCodeAndName(seekPurchase.getCode(), seekPurchase.getBrand());
|
|
|
- if (goods != null && goods.size() > 0) {
|
|
|
- haveGoodsCount++;
|
|
|
- }
|
|
|
- deleteBatchList.add(batch);
|
|
|
- inquiryItems.add(inquiryItem);
|
|
|
- }
|
|
|
- }
|
|
|
- seekPurchaseByBatchDao.delete(deleteBatchList);
|
|
|
- // 询价单数据插入
|
|
|
- inquiry.setAmount(deleteBatchList.size());
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddsss");
|
|
|
- try {
|
|
|
- inquiry.setCode("MALL" + sdf.parse(sdf.format(new Date())).getTime());
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- inquiry.setDate(new Date(System.currentTimeMillis()));
|
|
|
- inquiry.setEndDate(endDate);
|
|
|
- inquiry.setInquiryItems(inquiryItems);
|
|
|
- if (!StringUtils.isEmpty(user.getEnterprise())) {
|
|
|
- inquiry.setEnUU(user.getEnterprise().getUu());
|
|
|
- }
|
|
|
- inquiry.setRecorderUU(user.getUserUU());
|
|
|
- inquiry.setSourceapp("MALL");
|
|
|
- inquiry.setRemark(seekPurchaseBom.getName());
|
|
|
- inquiry.setInquiryItems(inquiryItems);
|
|
|
- String res = "";
|
|
|
- try {
|
|
|
- res = HttpUtil.doPost(url + "/inquiry/buyer/save", FlexJsonUtils.toJsonDeep(inquiry));
|
|
|
- logger.log("bom求购确认发布成功",user.getUserUU() + ",参数:" + FlexJsonUtils.toJsonDeep(inquiry));
|
|
|
- } catch (Exception e) {
|
|
|
- logger.log("bom求购确认发布报错",user.getUserUU() + ",错误:" + e.getMessage() + "参数:" + FlexJsonUtils.toJsonDeep(inquiry));
|
|
|
- e.printStackTrace();
|
|
|
- throw new IllegalOperatorException("发布失败");
|
|
|
- }
|
|
|
- // 删除bom的临时数据
|
|
|
- seekPurchaseBomDao.delete(seekPurchaseBom.getId());
|
|
|
- seekPurchaseBomListDao.deleteByBomId(seekPurchaseBom.getId());
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("successAmount", inquiryItems.size());
|
|
|
- result.put("goodsAmount", haveGoodsCount);
|
|
|
- return ResultMap.success(result);
|
|
|
+ return publishBomInquiry(url, seekPurchaseByBatchList, seekPurchaseBom, endTime, count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -686,4 +614,260 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
return seekPurchaseBomListDao.findOne(bomId);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 通过分页信息和过滤条件查询bom列表
|
|
|
+ *
|
|
|
+ * @param pageInfo 分页参数
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @return bom列表分页
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<SeekPurchaseBom> findAllByPageInfo(final PageInfo pageInfo, String keyword) {
|
|
|
+ Sort sort = new Sort(Sort.Direction.DESC, "id");
|
|
|
+ pageInfo.setSort(sort);
|
|
|
+ pageInfo.setOffset((pageInfo.getPageNumber() -1 ) * pageInfo.getPageSize());
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ pageInfo.expression(PredicateUtils.like("name", keyword, false));
|
|
|
+ }
|
|
|
+ pageInfo.expression(PredicateUtils.eq("uu", SystemSession.getUser().getUserUU(), false));
|
|
|
+ if (null != SystemSession.getUser().getEnterprise()) {
|
|
|
+ pageInfo.expression(PredicateUtils.eq("enuu", SystemSession.getUser().getEnterprise().getUu(), false));
|
|
|
+ } else {
|
|
|
+ pageInfo.expression(PredicateUtils.isNull("enuu"));
|
|
|
+ }
|
|
|
+ return seekPurchaseBomDao.findAll(new Specification<SeekPurchaseBom>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<SeekPurchaseBom> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ query.where(pageInfo.getPredicates(root, query, cb));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取单个bom的信息
|
|
|
+ *
|
|
|
+ * @param bomId bom id
|
|
|
+ * @return bom的详情信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SeekPurchaseBom findOne(Long bomId) {
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatches = seekPurchaseByBatchDao.findByBomId(bomId);
|
|
|
+ SeekPurchaseBom bom = seekPurchaseBomDao.findOne(bomId);
|
|
|
+ bom.setSeekPurchaseByBatchs(seekPurchaseByBatches);
|
|
|
+ return bom;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑bom信息
|
|
|
+ *
|
|
|
+ * @param bom 编辑完的bom信息
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap editBom(SeekPurchaseBom bom) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ if (null == bom || StringUtils.isEmpty(bom.getName())) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "未传入有效Bom信息");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatches = bom.getSeekPurchaseByBatchs();
|
|
|
+ if (!CollectionUtils.isEmpty(seekPurchaseByBatches)) {
|
|
|
+ for (SeekPurchaseByBatch batch : seekPurchaseByBatches) {
|
|
|
+ if (null == batch.getAmount()) {
|
|
|
+ batch.setAmount(1d);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ seekPurchaseByBatchDao.save(seekPurchaseByBatches);
|
|
|
+ }
|
|
|
+ seekPurchaseBomDao.save(bom);
|
|
|
+ map.put("success", true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", e.getMessage());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除bom信息
|
|
|
+ *
|
|
|
+ * @param bomId bomId
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap deleteBom(Long bomId) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ try {
|
|
|
+ SeekPurchaseBom bom = seekPurchaseBomDao.findOne(bomId);
|
|
|
+ if (null != bom) {
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatches = seekPurchaseByBatchDao.findByBomId(bomId);
|
|
|
+ if (!CollectionUtils.isEmpty(seekPurchaseByBatches)) {
|
|
|
+ seekPurchaseByBatchDao.delete(seekPurchaseByBatches);
|
|
|
+ }
|
|
|
+ seekPurchaseBomDao.delete(bom);
|
|
|
+ map.put("success", true);
|
|
|
+ } else {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "未查找到对应bom记录");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", e.getMessage());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除bom中的物料明细信息
|
|
|
+ *
|
|
|
+ * @param detailIds detail id串 1,2,3,4...
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap deleteBomProducts(String detailIds) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ try {
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ String[] idArray = detailIds.split(",");
|
|
|
+ for (String idString : idArray) {
|
|
|
+ ids.add(Long.valueOf(idString));
|
|
|
+ }
|
|
|
+ List<SeekPurchaseByBatch> batches = seekPurchaseByBatchDao.findAll(ids);
|
|
|
+ if (!CollectionUtils.isEmpty(batches)) {
|
|
|
+ SeekPurchaseBom bom = seekPurchaseBomDao.findOne(batches.get(0).getBomId());
|
|
|
+ if (null != bom) {
|
|
|
+ bom.setAmount(bom.getAmount() - batches.size());
|
|
|
+ seekPurchaseByBatchDao.delete(batches);
|
|
|
+ seekPurchaseBomDao.save(bom);
|
|
|
+ }
|
|
|
+ map.put("success", true);
|
|
|
+ } else {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "未找到对应bom明细产品记录");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", e.getMessage());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 部分发布,bom明细非全选时
|
|
|
+ *
|
|
|
+ * @param detailIds detail id串 1,2,3,4...
|
|
|
+ * @param endTime 截止时间 时间戳
|
|
|
+ * @param count 采购套数
|
|
|
+ * @param url 询价服务地址
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap confirmBomSelectedItems(String detailIds, String url, Long endTime, Integer count) {
|
|
|
+ if (null == endTime || null == count) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "存在未传入必需参数");
|
|
|
+ }
|
|
|
+ List<Long> detailIdList = new ArrayList<>();
|
|
|
+ String[] detailIdsArray = detailIds.split(",");
|
|
|
+ for (String detailId : detailIdsArray) {
|
|
|
+ detailIdList.add(Long.valueOf(detailId));
|
|
|
+ }
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatchList = seekPurchaseByBatchDao.findAll(detailIdList);
|
|
|
+ if (!CollectionUtils.isEmpty(seekPurchaseByBatchList)) {
|
|
|
+ SeekPurchaseBom seekPurchaseBom = seekPurchaseBomDao.findOne(seekPurchaseByBatchList.get(0).getBomId());
|
|
|
+ return publishBomInquiry(url, seekPurchaseByBatchList, seekPurchaseBom, endTime, count);
|
|
|
+ }
|
|
|
+ return new ResultMap(CodeType.NOT_EXiST, "未找到对应bom明细记录");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询bom信息,(无明细)
|
|
|
+ *
|
|
|
+ * @param bomId bomId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SeekPurchaseBom findOneWithoutDetail(Long bomId) {
|
|
|
+ return seekPurchaseBomDao.findOne(bomId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布bom询价
|
|
|
+ * @param url 询价服务url
|
|
|
+ * @param seekPurchaseByBatchList bom明细List
|
|
|
+ * @param endTime 截止时间 时间戳
|
|
|
+ * @param count 采购套数
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ private ResultMap publishBomInquiry(String url, List<SeekPurchaseByBatch> seekPurchaseByBatchList, SeekPurchaseBom seekPurchaseBom, Long endTime, Integer count) {
|
|
|
+ Calendar now = Calendar.getInstance();
|
|
|
+ now.add(Calendar.DAY_OF_MONTH, 91);
|
|
|
+ if (endTime > now.getTimeInMillis()) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "截止日期最迟不能超过三个月");
|
|
|
+ }
|
|
|
+ PurcInquiry inquiry = new PurcInquiry();
|
|
|
+ User user = SystemSession.getUser();
|
|
|
+ Set<PurcInquiryItem> inquiryItems = new HashSet<>();
|
|
|
+ Date endDate = new Date(endTime);
|
|
|
+ for (SeekPurchaseByBatch batch : seekPurchaseByBatchList) {
|
|
|
+ if (!StringUtils.isEmpty(batch.getCode()) && !StringUtils.isEmpty(batch.getBrand())) {
|
|
|
+ PurcInquiryItem inquiryItem = new PurcInquiryItem();
|
|
|
+ inquiryItem.setProdTitle(batch.getCode());
|
|
|
+ inquiryItem.setUserUU(user.getUserUU());
|
|
|
+ inquiryItem.setSource("MALL");
|
|
|
+ inquiryItem.setUserName(user.getUserName());
|
|
|
+ inquiryItem.setUserTel(user.getUserTel());
|
|
|
+ inquiryItem.setNeedquantity(null != batch.getAmount() ? batch.getAmount() * count : count);
|
|
|
+ inquiryItem.setInbrand(batch.getBrand());
|
|
|
+ inquiryItem.setCurrency(batch.getCurrency());
|
|
|
+ inquiryItem.setCmpCode(batch.getCode().toUpperCase());
|
|
|
+ inquiryItem.setUnitPrice(batch.getUnitPrice());
|
|
|
+ inquiryItem.setProduceDate(batch.getProduceDate());
|
|
|
+ inquiryItem.setDate(new Date());
|
|
|
+ inquiryItem.setEndDate(endDate);
|
|
|
+ if (StringUtils.isEmpty(batch.getKind())) {
|
|
|
+ batch.setKind(matchKind(batch.getBrand(), batch.getCode()));
|
|
|
+ }
|
|
|
+ inquiryItem.setProdTitle(batch.getKind());
|
|
|
+ inquiryItem.setSpec(batch.getSpec());
|
|
|
+ inquiryItem.setEncapsulation(batch.getEncapsulation());
|
|
|
+ inquiryItems.add(inquiryItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 询价单数据插入
|
|
|
+ inquiry.setAmount(inquiryItems.size());
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddsss");
|
|
|
+ try {
|
|
|
+ inquiry.setCode("MALL" + sdf.parse(sdf.format(new Date())).getTime());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ inquiry.setDate(new Date(System.currentTimeMillis()));
|
|
|
+ inquiry.setEndDate(endDate);
|
|
|
+ inquiry.setCount(count);
|
|
|
+ inquiry.setSpec(seekPurchaseBom.getSpec());
|
|
|
+ inquiry.setInquiryItems(inquiryItems);
|
|
|
+ if (!StringUtils.isEmpty(user.getEnterprise())) {
|
|
|
+ inquiry.setEnUU(user.getEnterprise().getUu());
|
|
|
+ }
|
|
|
+ inquiry.setRecorderUU(user.getUserUU());
|
|
|
+ inquiry.setSourceapp("MALL");
|
|
|
+ inquiry.setRemark(seekPurchaseBom.getName());
|
|
|
+ inquiry.setInquiryItems(inquiryItems);
|
|
|
+ String res = "";
|
|
|
+ try {
|
|
|
+ res = HttpUtil.doPost(url + "/inquiry/buyer/save", FlexJsonUtils.toJsonDeep(inquiry));
|
|
|
+ logger.log("bom求购确认发布成功",user.getUserUU() + ",参数:" + FlexJsonUtils.toJsonDeep(inquiry));
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.log("bom求购确认发布报错",user.getUserUU() + ",错误:" + e.getMessage() + "参数:" + FlexJsonUtils.toJsonDeep(inquiry));
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new IllegalOperatorException("发布失败");
|
|
|
+ }
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("successAmount", inquiryItems.size());
|
|
|
+ return ResultMap.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
}
|