|
|
@@ -0,0 +1,511 @@
|
|
|
+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.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.component.dao.ComponentDao;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseBomDao;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseBomListDao;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseByBatchDao;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseDao;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseGoodsDao;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseOfferDao;
|
|
|
+import com.uas.platform.b2c.trade.seek.model.SeekPurchase;
|
|
|
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBom;
|
|
|
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBomList;
|
|
|
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseByBatch;
|
|
|
+import com.uas.platform.b2c.trade.seek.service.SeekPurchaseBomService;
|
|
|
+import com.uas.platform.b2c.trade.seek.status.Status;
|
|
|
+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;
|
|
|
+import com.uas.platform.core.model.PageInfo;
|
|
|
+import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+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.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.util.StringUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author liusw
|
|
|
+ * @version 2018/1/19 15:06
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SeekPurchaseDao seekPurchasedao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BrandDao brandDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ComponentDao componentDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsDao goodsDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SeekPurchaseOfferDao seekPurchaseOfferDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SeekPurchaseGoodsDao seekPurchaseGoodsDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SeekPurchaseBomDao seekPurchaseBomDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SeekPurchaseByBatchDao seekPurchaseByBatchDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SeekPurchaseBomListDao seekPurchaseBomListDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SearcherService searcherService;
|
|
|
+
|
|
|
+ private static Long deadlineTime = Long.valueOf(90 * 24 * 60 * 60 * 1000);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入bom
|
|
|
+ * @param workbook
|
|
|
+ * @param bomName
|
|
|
+ * @param user
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap importBom(Workbook workbook, String bomName, User user) {
|
|
|
+ // 获取第一个工作表
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
+ if (colNum != 8) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "表格模板不正确!请重新下载最新模板");
|
|
|
+ }
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ if (rowNum > 500) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息超过500条,请拆分成2000以再在上传");
|
|
|
+ }
|
|
|
+ // 插入Bom求购中
|
|
|
+ SeekPurchaseBom seekPurchaseBom = new SeekPurchaseBom();
|
|
|
+ seekPurchaseBom.setReleaseDate(new Date(System.currentTimeMillis()));
|
|
|
+ seekPurchaseBom.setEnuu(user.getEnterprise().getUu());
|
|
|
+ seekPurchaseBom.setUu(user.getUserUU());
|
|
|
+ seekPurchaseBom.setName(bomName);
|
|
|
+ seekPurchaseBom.setStatus(0);
|
|
|
+ seekPurchaseBom = seekPurchaseBomDao.save(seekPurchaseBom);
|
|
|
+ // 获取第一行的信息
|
|
|
+ Row headerRow = sheet.getRow(0);
|
|
|
+ int total = 0;
|
|
|
+ int blankNum = 0;
|
|
|
+ if (headerRow != null) {
|
|
|
+ // 验证是否为商城模板
|
|
|
+ if (!vaildTemplete(headerRow)) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatchList = new ArrayList<>();
|
|
|
+ for (int r = 3; r <= rowNum; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+ if (row != null) {
|
|
|
+ SeekPurchaseByBatch seekPurchaseByBatch = new SeekPurchaseByBatch();
|
|
|
+ blankNum = convertValueToSeekPurchaseByBatch(row, seekPurchaseByBatch, r);
|
|
|
+ seekPurchaseByBatch.setBomId(seekPurchaseBom.getId());
|
|
|
+ seekPurchaseByBatch.setReleaseDate(new Date(System.currentTimeMillis()));
|
|
|
+ seekPurchaseByBatchList.add(seekPurchaseByBatch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ seekPurchaseByBatchDao.save(seekPurchaseByBatchList);
|
|
|
+ }
|
|
|
+ return ResultMap.success(seekPurchaseBom.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证是否为商城模板
|
|
|
+ * @param headerRow
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean vaildTemplete(Row headerRow){
|
|
|
+ Object codeCellObj = readWorkBookCell(headerRow.getCell(0), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, 0);
|
|
|
+ if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Object brandCellObj = readWorkBookCell(headerRow.getCell(1), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, 1);
|
|
|
+ if (!"品牌名称".equals(StringUtilB2C.getStr(brandCellObj))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Object deadlineCellObj = readWorkBookCell(headerRow.getCell(2), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, 2);
|
|
|
+ if (!"截止时间".equals(StringUtilB2C.getStr(deadlineCellObj))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Object produceDateCellObj = readWorkBookCell(headerRow.getCell(7), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, 7);
|
|
|
+ if (!"生产日期".equals(StringUtilB2C.getStr(produceDateCellObj))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将列信息注入到求购临时实体中
|
|
|
+ * @param row
|
|
|
+ * @param seekPurchaseByBatch
|
|
|
+ * @param rowNum
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private int convertValueToSeekPurchaseByBatch(Row row, SeekPurchaseByBatch seekPurchaseByBatch, int rowNum) {
|
|
|
+ // 统计为空的个数
|
|
|
+ int result = 0;
|
|
|
+ // 型号
|
|
|
+ Object codeValue = readWorkBookCell(row.getCell(0), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 0);
|
|
|
+ if (StringUtils.isEmpty(codeValue)) {
|
|
|
+ result += 1;
|
|
|
+ } else {
|
|
|
+ seekPurchaseByBatch.setCode(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(codeValue)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 品牌
|
|
|
+ Object brandValue = readWorkBookCell(row.getCell(1), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 1);
|
|
|
+ if (StringUtils.isEmpty(brandValue)) {
|
|
|
+ result += 1;
|
|
|
+ } else {
|
|
|
+ seekPurchaseByBatch.setBrand(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(brandValue)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 截止日期
|
|
|
+ Object deadlineValue = readWorkBookCell(row.getCell(2), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 2);
|
|
|
+ if (StringUtils.isEmpty(deadlineValue)) {
|
|
|
+ result += 1;
|
|
|
+ } else {
|
|
|
+ String deadline = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(deadlineValue));
|
|
|
+ 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);
|
|
|
+ if (deadlineDate.getTime() < System.currentTimeMillis()) {
|
|
|
+ seekPurchaseByBatch.setDeadline(DateUtils.addTime(new Date(), 1, 23, 59,59));
|
|
|
+ } else {
|
|
|
+ seekPurchaseByBatch.setDeadline(DateUtils.addTime(deadlineDate));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ seekPurchaseByBatch.setDeadline(DateUtils.addTime(new Date(System.currentTimeMillis())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 求购数量
|
|
|
+ Object amountValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 3);
|
|
|
+ if (!StringUtils.isEmpty(amountValue)) {
|
|
|
+ try {
|
|
|
+ Integer amount = Integer.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(amountValue)));
|
|
|
+ seekPurchaseByBatch.setAmount(amount);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ seekPurchaseByBatch.setAmount(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 币别
|
|
|
+ Object currencyValue = readWorkBookCell(row.getCell(4), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 4);
|
|
|
+ if (!StringUtils.isEmpty(currencyValue)) {
|
|
|
+ try {
|
|
|
+ String currency = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(currencyValue));
|
|
|
+ seekPurchaseByBatch.setCurrency(currency);
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setCurrency("RMB");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 单价
|
|
|
+ Object unitPriceValue = readWorkBookCell(row.getCell(5), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 5);
|
|
|
+ if (!StringUtils.isEmpty(unitPriceValue)) {
|
|
|
+ try {
|
|
|
+ Double unitPrice = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(unitPriceValue)));
|
|
|
+ seekPurchaseByBatch.setUnitPrice(unitPrice);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ seekPurchaseByBatch.setUnitPrice(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果填了单价又不选币种,导入的时候系统就默认人民币吧
|
|
|
+ if (!StringUtils.isEmpty(unitPriceValue) && StringUtils.isEmpty(currencyValue)) {
|
|
|
+ seekPurchaseByBatch.setCurrency("RMB");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装
|
|
|
+ Object encapsulationValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 6);
|
|
|
+ if (!StringUtils.isEmpty(encapsulationValue)) {
|
|
|
+ try {
|
|
|
+ String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
|
|
|
+ seekPurchaseByBatch.setEncapsulation(encapsulation);
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setEncapsulation(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 生产日期
|
|
|
+ Object produceDateValue = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 7);
|
|
|
+ if (!StringUtils.isEmpty(produceDateValue)) {
|
|
|
+ try {
|
|
|
+ String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
|
|
|
+ seekPurchaseByBatch.setProduceDate(produceDate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setProduceDate(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取excel
|
|
|
+ * @param cell
|
|
|
+ * @param cellType
|
|
|
+ * @param r
|
|
|
+ * @param n
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Object readWorkBookCell(Cell cell, int cellType, int r, int n) {
|
|
|
+ Object obj = null;
|
|
|
+ try {
|
|
|
+ if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ switch (cellType) {
|
|
|
+ case Cell.CELL_TYPE_STRING :
|
|
|
+ cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
+ String str = cell.getStringCellValue().trim();
|
|
|
+ if (str.indexOf("\u00A0") > 0) {
|
|
|
+ str= str.replaceAll("\u00A0", "");
|
|
|
+ }
|
|
|
+ str = StringUtilB2C.replaceTabAndLineBreak(str);
|
|
|
+ obj = str.trim();
|
|
|
+ break;
|
|
|
+ case Cell.CELL_TYPE_NUMERIC :
|
|
|
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
+ obj = cell.getNumericCellValue();
|
|
|
+ if (obj != null) {
|
|
|
+ if (obj.toString().indexOf("E") > 0) {
|
|
|
+ BigDecimal b = new BigDecimal(obj.toString());
|
|
|
+ obj = b.toPlainString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default :
|
|
|
+ if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
|
|
+ String productTime = cell.getStringCellValue();
|
|
|
+ Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
|
|
+ Matcher m = p.matcher(productTime);
|
|
|
+ String time = m.replaceAll("");
|
|
|
+ if (time.indexOf("\u00A0") > 0){
|
|
|
+ time= time.replaceAll("\u00A0", "");
|
|
|
+ }
|
|
|
+ DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+ obj = format1.parse(time);
|
|
|
+ } else if (HSSFDateUtil.isCellDateFormatted(cell)) {
|
|
|
+ obj = cell.getDateCellValue();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IllegalOperatorException("读取表格中" + r + "行" + (n + 1) + "列的内容错误,有可能是该单元格的格式不正确");
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<SeekPurchaseByBatch> getSeekPurchaseByBatchPageInfo(final PageInfo pageInfo, Long bomId) {
|
|
|
+ if (bomId != null) {
|
|
|
+ pageInfo.filter("bomId", bomId);
|
|
|
+ }
|
|
|
+ Page<SeekPurchaseByBatch> pageSeeks = seekPurchaseByBatchDao.findAll(new Specification<SeekPurchaseByBatch>() {
|
|
|
+ public Predicate toPredicate(Root<SeekPurchaseByBatch> root, CriteriaQuery<?> query,
|
|
|
+ CriteriaBuilder builder) {
|
|
|
+ query.where(pageInfo.getPredicates(root, query, builder));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatchList = pageSeeks.getContent();
|
|
|
+ for (int i = 0;i < seekPurchaseByBatchList.size(); i++) {
|
|
|
+ if (!StringUtils.isEmpty(seekPurchaseByBatchList.get(i).getCode()) && !StringUtils.isEmpty(seekPurchaseByBatchList.get(i).getBrand())) {
|
|
|
+ List<Map<String, Object>> codeWord = searcherService.getSimilarComponents(seekPurchaseByBatchList.get(i).getCode());
|
|
|
+ if (codeWord != null && codeWord.size() > 0) {
|
|
|
+ seekPurchaseByBatchList.get(i).setCodeWord(codeWord);
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> brandWord = searcherService.getSimilarComponents(seekPurchaseByBatchList.get(i).getBrand());
|
|
|
+ if (codeWord != null && codeWord.size() > 0) {
|
|
|
+ seekPurchaseByBatchList.get(i).setBrandWord(brandWord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new PageImpl<SeekPurchaseByBatch>(seekPurchaseByBatchList, pageInfo, pageSeeks.getTotalElements());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap confirmBom(Long bomId, String spIds) {
|
|
|
+ SeekPurchaseBom seekPurchaseBom = seekPurchaseBomDao.findOne(bomId);
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatchList = null;
|
|
|
+ if (!StringUtils.isEmpty(spIds)) {
|
|
|
+ // 保存选中
|
|
|
+ seekPurchaseByBatchList = seekPurchaseByBatchDao.findBySpids(Arrays.asList(spIds.split(",")));
|
|
|
+ } else {
|
|
|
+ // 保存所有
|
|
|
+ seekPurchaseByBatchList = seekPurchaseByBatchDao.findByBomId(bomId);
|
|
|
+ }
|
|
|
+ // 商城现货的数量
|
|
|
+ int haveGoodsCount = 0;
|
|
|
+ // 将临时表转换成正式表数据
|
|
|
+ List<SeekPurchase> seekPurchaseList = new ArrayList<>();
|
|
|
+ // 发布到正式表的临时数据
|
|
|
+ List<SeekPurchaseByBatch> deleteBatchList = new ArrayList<>();
|
|
|
+ for (SeekPurchaseByBatch batch : seekPurchaseByBatchList) {
|
|
|
+ SeekPurchase seekPurchase = new SeekPurchase();
|
|
|
+ if (!StringUtils.isEmpty(batch.getCode()) && !StringUtils.isEmpty(batch.getBrand()) && !StringUtils.isEmpty(batch.getDeadline()) && batch.getDeadline().compareTo(DateUtils.addTime(new Date(), 90, 23, 59 ,59))!= 1) {
|
|
|
+ //seekPurchase = (SeekPurchase) batch;
|
|
|
+ seekPurchase.setDeadline(batch.getDeadline());
|
|
|
+ seekPurchase.setCurrency(batch.getCurrency());
|
|
|
+ seekPurchase.setReleaseDate(batch.getReleaseDate());
|
|
|
+ seekPurchase.setCode(batch.getCode());
|
|
|
+ seekPurchase.setBrand(batch.getBrand());
|
|
|
+ seekPurchase.setAmount(batch.getAmount());
|
|
|
+ seekPurchase.setEncapsulation(batch.getEncapsulation());
|
|
|
+ seekPurchase.setUnitPrice(batch.getUnitPrice());
|
|
|
+ seekPurchase.setProduceDate(batch.getProduceDate());
|
|
|
+ seekPurchase.setBomId(batch.getBomId());
|
|
|
+ seekPurchase.setEnUu(seekPurchaseBom.getEnuu());
|
|
|
+ seekPurchase.setUu(seekPurchaseBom.getUu());
|
|
|
+ seekPurchase.setStatus(Status.NO_OFFER.getValue());
|
|
|
+ // 商城现货搜索
|
|
|
+ List<Goods> goods = goodsDao.getGoodsByCodeAndName(seekPurchase.getCode(), seekPurchase.getBrand());
|
|
|
+ if (goods != null && goods.size() > 0) {
|
|
|
+ haveGoodsCount++;
|
|
|
+ }
|
|
|
+ deleteBatchList.add(batch);
|
|
|
+ seekPurchaseList.add(seekPurchase);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ seekPurchaseList = seekPurchasedao.save(seekPurchaseList);
|
|
|
+ seekPurchaseBom.setAmount((seekPurchaseBom.getAmount() == null ? 0 : seekPurchaseBom.getAmount()) + seekPurchaseList.size());
|
|
|
+ seekPurchaseBom.setStatus(1);
|
|
|
+ seekPurchaseBomDao.save(seekPurchaseBom);
|
|
|
+ seekPurchaseByBatchDao.delete(deleteBatchList);
|
|
|
+ return ResultMap.success(haveGoodsCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<SeekPurchaseBomList> getSeekPurchaseBomListPage(final PageInfo pageInfo, User user, String minReleaseDate, String maxReleaseDate, String name) {
|
|
|
+ if (user.getEnterprise() != null) {
|
|
|
+ pageInfo.filter("enUu", user.getEnterprise().getUu());
|
|
|
+ } else {
|
|
|
+ pageInfo.filter("uu", user.getUserUU());
|
|
|
+ }
|
|
|
+ // 发布时间
|
|
|
+ if (!StringUtils.isEmpty(minReleaseDate)) {
|
|
|
+ pageInfo.expression(
|
|
|
+ PredicateUtils.gte("releaseDate", new Date(Long.valueOf(minReleaseDate)), false));
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(maxReleaseDate)) {
|
|
|
+ pageInfo.expression(PredicateUtils.lte("releaseDate", new Date(Long.valueOf(maxReleaseDate)), false));
|
|
|
+ }
|
|
|
+ // Bom名称
|
|
|
+ if (!StringUtils.isEmpty(name)) {
|
|
|
+ pageInfo.filter("name", name);
|
|
|
+ }
|
|
|
+ pageInfo.sorting("releaseDate", Direction.DESC);
|
|
|
+ Page<SeekPurchaseBomList> pageSeeks = seekPurchaseBomListDao.findAll(new Specification<SeekPurchaseBomList>() {
|
|
|
+ public Predicate toPredicate(Root<SeekPurchaseBomList> root, CriteriaQuery<?> query,
|
|
|
+ CriteriaBuilder builder) {
|
|
|
+ query.where(pageInfo.getPredicates(root, query, builder));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ return pageSeeks;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getImportBomInfo(Long bomId) {
|
|
|
+ String sql = "select bom_id,count(bom_id) as successImport,(sum((IF(sp_brand is null,1,0)))+sum((IF(sp_code is null,1,0)))+sum((IF(sp_deadline is null,1,0)))) as nullField "
|
|
|
+ + "from trade$seek_purchase_by_batch where bom_id = ? group by bom_id";
|
|
|
+ try {
|
|
|
+ Map<String, Object> map = jdbcTemplate.queryForMap(sql, new Object[]{bomId});
|
|
|
+ return map;
|
|
|
+ } catch (DataAccessException e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap updateSeekPurchaseByBatch(SeekPurchaseByBatch seekPurchaseByBatch) {
|
|
|
+ seekPurchaseByBatchDao.save(seekPurchaseByBatch);
|
|
|
+ return ResultMap.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap deleteSeekPurchaseByBatch(String spIds) {
|
|
|
+ String sql = "delete from trade$seek_purchase_by_batch where sp_id in (:spIds)";
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("spIds", spIds.contains(",") ? Arrays.asList(spIds.split(",")) : spIds);
|
|
|
+ namedParameterJdbcTemplate.update(sql, param);
|
|
|
+ return ResultMap.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap updateSeekPurchaseBom(SeekPurchaseBom seekPurchaseBom) {
|
|
|
+ SeekPurchaseBom oldBom = seekPurchaseBomDao.findOne(seekPurchaseBom.getId());
|
|
|
+ String name = seekPurchaseBom.getName();
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
+ throw new IllegalOperatorException("bom名称不符合要求");
|
|
|
+ }
|
|
|
+ oldBom.setName(seekPurchaseBom.getName());
|
|
|
+ seekPurchaseBomDao.save(oldBom);
|
|
|
+ return ResultMap.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SeekPurchaseBomList findOneBom(Long bomId) {
|
|
|
+ return seekPurchaseBomListDao.findOne(bomId);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|