|
|
@@ -8,7 +8,6 @@ import com.uas.ps.entity.ProductMatchResult;
|
|
|
import com.uas.ps.entity.ProductUsers;
|
|
|
import com.uas.ps.entity.Status;
|
|
|
import com.uas.ps.product.ProductConstant;
|
|
|
-import com.uas.ps.product.entity.Constant;
|
|
|
import com.uas.ps.product.entity.Prod;
|
|
|
import com.uas.ps.product.entity.ProductSaler;
|
|
|
import com.uas.ps.product.repository.ProductDao;
|
|
|
@@ -18,18 +17,17 @@ import com.uas.ps.product.repository.ProductUsersDao;
|
|
|
import com.uas.ps.product.service.ProductService;
|
|
|
import com.uas.ps.properties.UrlProperties;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
-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.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @author sunyj
|
|
|
@@ -111,12 +109,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ModelMap match(Long enUU, Long userUU, String matchtype) {
|
|
|
- ModelMap map = new ModelMap();
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public ModelMap matchB2cAll(Long enUU) {
|
|
|
@@ -149,6 +141,69 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据id删除匹配结果
|
|
|
+ *
|
|
|
+ * @param id 匹配结果id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteMatchResultAndProductUser(Long id) {
|
|
|
+ if (productDao.exists(id)) {
|
|
|
+ // 先删除匹配结果的id
|
|
|
+ List<ProductMatchResult> results = productMatchResultDao.findByProductId(id);
|
|
|
+ if (!CollectionUtils.isEmpty(results)) {
|
|
|
+ productMatchResultDao.delete(results);
|
|
|
+ }
|
|
|
+ // 需要删除个人物料库的数据
|
|
|
+ List<ProductUsers> productUsers = productUsersDao.findByPrid(id);
|
|
|
+ if (!CollectionUtils.isEmpty(productUsers)) {
|
|
|
+ productUsersDao.delete(productUsers);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据企业UU 开关状态,开关类型一键操作
|
|
|
+ *
|
|
|
+ * @param enUU 企业UU
|
|
|
+ * @param switchType 开关类型 purc or sale
|
|
|
+ * @param switchStatus 开关状态 1 or 0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void switchProductByEnuuAndTypeAndStatus(Long enUU, String switchType, Integer switchStatus) {
|
|
|
+ if ("sale".equals(switchType)) {
|
|
|
+ productDao.updateSaleStatusByEnUU(enUU, switchStatus);
|
|
|
+ } else if ("purc".equals(switchType)) {
|
|
|
+ productDao.updatePurchaseStatusByEnUU(enUU, switchStatus);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据物料id 开关状态,开关类型一键操作
|
|
|
+ *
|
|
|
+ * @param id 物料id
|
|
|
+ * @param switchType 开关类型 purc or sale
|
|
|
+ * @param switchStatus 开关状态 1 or 0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void switchProductByIdAndTypeAndStatus(Long id, String switchType, Integer switchStatus) {
|
|
|
+ if ("sale".equals(switchType)) {
|
|
|
+ productDao.updateSaleStatusById(id, switchStatus);
|
|
|
+ } else if ("purc".equals(switchType)) {
|
|
|
+ productDao.updatePurchaseStatusById(id, switchStatus);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存匹配结果
|
|
|
+ *
|
|
|
+ * @param results 匹配结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void saveMatchResults(List<ProductMatchResult> results) {
|
|
|
+ productMatchResultDao.save(results);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 单个物料匹配
|
|
|
* @param product
|
|
|
@@ -353,147 +408,4 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量导入物料信息
|
|
|
- *
|
|
|
- * @param workbook excel解析的物料信息
|
|
|
- * @param enUU 企业UU
|
|
|
- * @param userUU 用户UU
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ModelMap releaseByWorkbook(Workbook workbook, Long enUU, Long userUU) {
|
|
|
- ModelMap modelMap = new ModelMap();
|
|
|
- List<String> alters = new ArrayList<>();
|
|
|
- List<String> infos = new ArrayList<>();
|
|
|
- List<Product> products = new ArrayList<>();
|
|
|
- List<Product> productsInfo = new ArrayList<>();
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- int rowNum = sheet.getLastRowNum();
|
|
|
- Row headerRow = sheet.getRow(0);
|
|
|
- int total = 0;
|
|
|
- if (headerRow != null) {
|
|
|
- for (int r = 3; r <= rowNum; r++) {
|
|
|
- Row row = sheet.getRow(r);
|
|
|
- if (row != null && row.getCell(0) != null && row.getCell(0).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- total++;
|
|
|
- Product product = new Product();
|
|
|
-
|
|
|
- // 物料编号
|
|
|
- if (row.getCell(0) != null) {
|
|
|
- row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setCode(row.getCell(0).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 物料名称
|
|
|
- if (row.getCell(1) != null) {
|
|
|
- row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setTitle(row.getCell(1).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 原厂型号
|
|
|
- if (row.getCell(2) != null) {
|
|
|
- row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setCmpCode(row.getCell(2).getStringCellValue().trim());
|
|
|
- if (product.getCode() == null) {
|
|
|
- // 生成随机物料编码
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("mmsssss");
|
|
|
- String code = enUU + sdf.format(new Date());
|
|
|
- product.setCode(code);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 品牌
|
|
|
- if (row.getCell(3) != null) {
|
|
|
- row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setBrand(row.getCell(3).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 单位
|
|
|
- if (row.getCell(4) != null) {
|
|
|
- row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setUnit(row.getCell(4).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 最小包装量
|
|
|
- if (row.getCell(5) != null) {
|
|
|
- row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(5).getStringCellValue()
|
|
|
- && !row.getCell(5).getStringCellValue().trim().equals("")) {
|
|
|
- product.setMinPack(Double.valueOf(row.getCell(5).getStringCellValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- // 最小订购量
|
|
|
- if (row.getCell(6) != null) {
|
|
|
- row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(6).getStringCellValue().trim()
|
|
|
- && !row.getCell(6).getStringCellValue().trim().equals("")) {
|
|
|
- product.setMinOrder(Double.valueOf(row.getCell(6).getStringCellValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- // 交货周期
|
|
|
- if (row.getCell(7) != null) {
|
|
|
- row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(7).getStringCellValue().trim()
|
|
|
- && !row.getCell(7).getStringCellValue().trim().equals("")) {
|
|
|
- product.setLeadTime(Double.valueOf(row.getCell(7).getStringCellValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- // 交货提前期
|
|
|
- if (row.getCell(8) != null) {
|
|
|
- row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(8).getStringCellValue().trim()
|
|
|
- && !row.getCell(8).getStringCellValue().trim().equals("")) {
|
|
|
- product.setLtinstock(Double.valueOf(row.getCell(8).getStringCellValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- // 判断是否存在
|
|
|
- List<Product> prods = productDao.findByEnUUAndCode(enUU, product.getCode());
|
|
|
- if (org.apache.commons.collections.CollectionUtils.isEmpty(prods)) {
|
|
|
- } else {
|
|
|
- Product oldProd = prods.get(0);
|
|
|
- if (oldProd.getIsSale() == null) {
|
|
|
- oldProd.setIsSale(Constant.YES);
|
|
|
- productDao.save(oldProd);
|
|
|
- }
|
|
|
- alters.add(product.getCode());
|
|
|
- product.setCode(null);
|
|
|
- }
|
|
|
- product.setEnUU(enUU);
|
|
|
- product.setUserUU(userUU);
|
|
|
- product.setSourceApp("B2B");
|
|
|
- product.setIsPubsale(Constant.NO);
|
|
|
- product.setIsShow(Constant.NO);
|
|
|
- product.setIsSale(Constant.YES);
|
|
|
- if (alters.size() > 0) {
|
|
|
- modelMap.put("alters", alters);
|
|
|
- }
|
|
|
- if (infos.size() > 0) {
|
|
|
- modelMap.put("infos", infos);
|
|
|
- }
|
|
|
- if (product.getCode() != null) {
|
|
|
- products.add(product);
|
|
|
- }
|
|
|
- if (product.getStandard() == null) {
|
|
|
- product.setStandard(Constant.NO);
|
|
|
- }
|
|
|
- product.setErpDate(new Date());
|
|
|
- productsInfo.add(product);
|
|
|
- modelMap.put("total", total);
|
|
|
- modelMap.put("products", productsInfo);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!org.apache.commons.collections.CollectionUtils.isEmpty(products)) {
|
|
|
- try {
|
|
|
- products = productDao.save(products);
|
|
|
-// saveUserOrders(products);
|
|
|
- modelMap.put("success", products.size());
|
|
|
- } catch (Exception e) {
|
|
|
- modelMap.put("error", "存在编号相同的产品");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return modelMap;
|
|
|
- }
|
|
|
}
|