|
|
@@ -0,0 +1,490 @@
|
|
|
+package com.uas.platform.b2c.prod.product.brand.service.impl;
|
|
|
+
|
|
|
+import com.uas.platform.b2c.common.account.dao.EnterpriseDao;
|
|
|
+import com.uas.platform.b2c.common.account.dao.UserBaseInfoDao;
|
|
|
+import com.uas.platform.b2c.common.account.model.UserBaseInfo;
|
|
|
+import com.uas.platform.b2c.core.constant.Status;
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.dao.VendorListDao;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.dao.VendorListSubmitDao;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.Brand;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.BrandInfo;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.VendorList;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.VendorListSubmit;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.service.VendorListSubmitService;
|
|
|
+import com.uas.platform.b2c.prod.store.dao.StoreInDao;
|
|
|
+import com.uas.platform.b2c.prod.store.model.StoreIn;
|
|
|
+import com.uas.platform.b2c.prod.store.model.StoreStatus;
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import com.uas.platform.core.model.Constant;
|
|
|
+import com.uas.platform.core.model.PageInfo;
|
|
|
+import com.uas.platform.core.persistence.criteria.CriterionExpression;
|
|
|
+import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+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.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by wangyc on 2017/11/27.
|
|
|
+ *
|
|
|
+ * @version 2017/11/27 10:39 wangyc
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class VendorListSubmitServiceImpl implements VendorListSubmitService {
|
|
|
+
|
|
|
+ private final VendorListDao vendorListDao;
|
|
|
+
|
|
|
+ private final VendorListSubmitDao vendorListSubmitDao;
|
|
|
+
|
|
|
+ private final BrandDao brandDao;
|
|
|
+
|
|
|
+ private final StoreInDao storeInDao;
|
|
|
+
|
|
|
+ private final UserBaseInfoDao userBaseInfoDao;
|
|
|
+
|
|
|
+ private final EnterpriseDao enterpriseDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public VendorListSubmitServiceImpl(VendorListDao vendorListDao, VendorListSubmitDao vendorListSubmitDao, BrandDao brandDao, StoreInDao storeInDao, UserBaseInfoDao userBaseInfoDao, EnterpriseDao enterpriseDao){
|
|
|
+ this.vendorListDao = vendorListDao;
|
|
|
+ this.vendorListSubmitDao = vendorListSubmitDao;
|
|
|
+ this.brandDao = brandDao;
|
|
|
+ this.storeInDao = storeInDao;
|
|
|
+ this.userBaseInfoDao = userBaseInfoDao;
|
|
|
+ this.enterpriseDao = enterpriseDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VendorListSubmit findOne(Long id) {
|
|
|
+ VendorListSubmit vendorListSubmit = vendorListSubmitDao.findOne(id);
|
|
|
+ if (vendorListSubmit == null) {
|
|
|
+ throw new IllegalOperatorException("此供应商申请不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (vendorListSubmit.getStoreuuid() != null) {
|
|
|
+ vendorListSubmit.setStoreIn(storeInDao.findByUuid(vendorListSubmit.getStoreuuid()));
|
|
|
+ }
|
|
|
+ return vendorListSubmit;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VendorListSubmit save(VendorListSubmit vendorListSubmit) {
|
|
|
+ validition(vendorListSubmit);// 验证申请
|
|
|
+
|
|
|
+ List<VendorList> existsVendors = new ArrayList<VendorList>();
|
|
|
+ if (vendorListSubmit.getLicense() != null) {// 判断供应商信息是否已存在
|
|
|
+ existsVendors = vendorListDao.findByBranduuidAndLicense(vendorListSubmit.getBranduuid(), vendorListSubmit.getLicense());
|
|
|
+ } else {
|
|
|
+ existsVendors = vendorListDao.findByBranduuidAndVendorName(vendorListSubmit.getBranduuid(), vendorListSubmit.getVendorName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(existsVendors)) {
|
|
|
+ throw new IllegalOperatorException("此供应商已存在,请重新确认供应商信息或更新对应供应商信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ vendorListSubmit.setUpdateruu(SystemSession.getUser().getUserUU());
|
|
|
+ vendorListSubmit.setUpdatetime(new Date());
|
|
|
+ vendorListSubmit.setStatus(Status.SUBMITTED.value());
|
|
|
+ // 设置操作类型为新增
|
|
|
+ vendorListSubmit.setType(Status.PRELIMINARY.value());
|
|
|
+ return vendorListSubmitDao.save(vendorListSubmit);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VendorListSubmit delete(Long id) {
|
|
|
+ VendorList oldVendor = vendorListDao.findOne(id);
|
|
|
+ if (oldVendor == null) {
|
|
|
+ throw new IllegalOperatorException("此供应商信息不存在,请确认后再进行操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Constant.YES == oldVendor.getIsSubmited()) {
|
|
|
+ throw new IllegalOperatorException("此供应商信息正在申请中,请联系管理员处理完现有申请后,再进行操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ VendorListSubmit vendorListSubmit = new VendorListSubmit(oldVendor);
|
|
|
+ vendorListSubmit.setUpdateruu(SystemSession.getUser().getUserUU());
|
|
|
+ vendorListSubmit.setUpdatetime(now);
|
|
|
+ vendorListSubmit.setVendorid(oldVendor.getId());
|
|
|
+ vendorListSubmit.setStatus(Status.SUBMITTED.value());
|
|
|
+ // 设置操作类型为删除
|
|
|
+ vendorListSubmit.setType(Status.DELETED.value());
|
|
|
+
|
|
|
+ // 更新供应商信息为正在申请
|
|
|
+ oldVendor.setSubmitTime(now);
|
|
|
+ oldVendor.setIsSubmited(Constant.YES);
|
|
|
+ vendorListDao.save(oldVendor);
|
|
|
+
|
|
|
+ return vendorListSubmitDao.save(vendorListSubmit);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VendorListSubmit update(VendorListSubmit vendorListSubmit) {
|
|
|
+ validition(vendorListSubmit);// 验证申请
|
|
|
+
|
|
|
+ VendorList oldVendor = vendorListDao.findOne(vendorListSubmit.getVendorid());
|
|
|
+ if (oldVendor == null)
|
|
|
+ throw new IllegalOperatorException("此供应商不存在");
|
|
|
+
|
|
|
+ if (Constant.YES == oldVendor.getIsSubmited()) {
|
|
|
+ throw new IllegalOperatorException("此供应商信息正在申请中,请联系管理员处理完现有申请后,再进行操作");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ vendorListSubmit.setUpdateruu(SystemSession.getUser().getUserUU());
|
|
|
+ vendorListSubmit.setUpdatetime(now);
|
|
|
+ vendorListSubmit.setStatus(Status.SUBMITTED.value());
|
|
|
+ // 设置操作类型为更新
|
|
|
+ vendorListSubmit.setType(Status.ACTIVE.value());
|
|
|
+ vendorListSubmit.setId(null);
|
|
|
+
|
|
|
+ // 更新供应商信息为正在申请
|
|
|
+ oldVendor.setSubmitTime(now);
|
|
|
+ oldVendor.setIsSubmited(Constant.YES);
|
|
|
+ vendorListDao.save(oldVendor);
|
|
|
+
|
|
|
+ return vendorListSubmitDao.save(vendorListSubmit);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VendorListSubmit audit(VendorListSubmit vendorListSubmit) {
|
|
|
+ validition(vendorListSubmit);// 验证申请
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ vendorListSubmit.setStatus(Status.AUDITED.value());// 修改状态为已审核
|
|
|
+ vendorListSubmit.setAuditeruu(SystemSession.getUser().getUserUU());
|
|
|
+ vendorListSubmit.setAudittime(now);
|
|
|
+ vendorListSubmitDao.save(vendorListSubmit);
|
|
|
+
|
|
|
+ // 删除申请,删除原供应商信息
|
|
|
+ if (Status.DELETED.value() == vendorListSubmit.getType()) {
|
|
|
+ // 检测关联供应商信息有效性
|
|
|
+ checkVendorid(vendorListSubmit);
|
|
|
+ vendorListDao.delete(vendorListSubmit.getVendorid());
|
|
|
+ } else {
|
|
|
+ VendorList vendorList = new VendorList(vendorListSubmit);
|
|
|
+ // 若为更新则更新之前的供应商信息
|
|
|
+ if (Status.ACTIVE.value() == vendorListSubmit.getType()) {
|
|
|
+ // 检测关联供应商信息有效性
|
|
|
+ checkVendorid(vendorListSubmit);
|
|
|
+ vendorList.setId(vendorListSubmit.getVendorid());
|
|
|
+ }
|
|
|
+ // 将供应商信息申请状态更新为不在申请中
|
|
|
+ vendorList.setIsSubmited(Constant.NO);
|
|
|
+ vendorList.setSubmitTime(now);
|
|
|
+ vendorListDao.save(vendorList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return vendorListSubmit;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检测关联供应商信息有效性
|
|
|
+ * @param vendorListSubmit 供应商申请
|
|
|
+ */
|
|
|
+ private void checkVendorid(VendorListSubmit vendorListSubmit) {
|
|
|
+ if (vendorListSubmit.getVendorid() == null || vendorListDao.findOne(vendorListSubmit.getVendorid()) == null) {
|
|
|
+ throw new IllegalOperatorException("原供应商信息不存在,请重新确认后再进行操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VendorListSubmit unaudit(Long id) {
|
|
|
+ VendorListSubmit vendorListSubmit = vendorListSubmitDao.findOne(id);
|
|
|
+ if (vendorListSubmit == null)
|
|
|
+ throw new IllegalOperatorException("此申请不存在,请重新确认申请信息");
|
|
|
+ if (Status.SUBMITTED.value() != vendorListSubmit.getStatus())
|
|
|
+ throw new IllegalOperatorException("此申请不为待审核状态,请重新确认申请信息");
|
|
|
+
|
|
|
+ vendorListSubmit.setStatus(Status.NOTALLOW.value());
|
|
|
+ vendorListSubmit.setAuditeruu(SystemSession.getUser().getUserUU());
|
|
|
+ vendorListSubmit.setAudittime(new Date());
|
|
|
+
|
|
|
+ // 若申请关联已生效供应商信息,将已生效信息改为不在申请状态中
|
|
|
+ if (vendorListSubmit.getVendorid() != null) {
|
|
|
+ VendorList oldVendor = vendorListDao.findOne(vendorListSubmit.getVendorid());
|
|
|
+ if (oldVendor != null) {
|
|
|
+ oldVendor.setIsSubmited(Constant.NO);
|
|
|
+ oldVendor.setSubmitTime(new Date());
|
|
|
+ vendorListDao.save(oldVendor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return vendorListSubmitDao.save(vendorListSubmit);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<VendorListSubmit> upload(Workbook workbook) {
|
|
|
+ List<VendorListSubmit> vendorListSubmits = new ArrayList<VendorListSubmit>();
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ Row firstRow = sheet.getRow(0);// 验证表头
|
|
|
+ if (firstRow != null) {
|
|
|
+ List<String> titles = new ArrayList<String>();
|
|
|
+ titles.add("品牌英文名");
|
|
|
+ titles.add("代理商名称");
|
|
|
+ titles.add("营业执照号");
|
|
|
+ titles.add("地区(省,市,区/县。以,分隔)");
|
|
|
+ titles.add("详细地址(街道)");
|
|
|
+ titles.add("电话");
|
|
|
+ titles.add("传真");
|
|
|
+ titles.add("网址");
|
|
|
+ titles.add("关联企业名称");
|
|
|
+ titles.add("邮箱");
|
|
|
+
|
|
|
+ List<String> heads = new ArrayList<String>();
|
|
|
+ for (int j = 0; j < 10; j++) {
|
|
|
+ if (firstRow.getCell(j) != null) {
|
|
|
+ firstRow.getCell(j).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ Object cell = firstRow.getCell(j);
|
|
|
+ if (cell != null && StringUtils.hasText(firstRow.getCell(j).getStringCellValue().trim())) {
|
|
|
+ heads.add(firstRow.getCell(j).getStringCellValue().trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!titles.equals(heads))
|
|
|
+ throw new IllegalOperatorException("表头不正确,请重新下载模板");
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("表头不正确,请重新下载模板");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<VendorListSubmit> vendorListSubmitList = new ArrayList<VendorListSubmit>();
|
|
|
+
|
|
|
+ for (int r = 1; r <= rowNum; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+
|
|
|
+ if (row != null && row.getCell(0) != null) {
|
|
|
+ VendorListSubmit vendorListSubmit = new VendorListSubmit();
|
|
|
+
|
|
|
+ // 品牌英文名
|
|
|
+ if (row.getCell(0) != null) {
|
|
|
+ row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String brandNameEn = row.getCell(0).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(brandNameEn)) {
|
|
|
+ List<Brand> brands = brandDao.findByUpperNameEn(brandNameEn);
|
|
|
+ if (CollectionUtils.isEmpty(brands))
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行品牌:" + brandNameEn + " 不存在,请重新确认品牌信息");
|
|
|
+
|
|
|
+ vendorListSubmit.setBranduuid(brands.get(0).getUuid());
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行品牌英文名不可为空");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行品牌英文名不可为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 供应商名称
|
|
|
+ if (row.getCell(1) != null) {
|
|
|
+ row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String vendorName = row.getCell(1).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(vendorName)) {
|
|
|
+ vendorListSubmit.setVendorName(vendorName);
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行供应商名称不可为空");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行供应商名称不可为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 营业执照号
|
|
|
+ if (row.getCell(2) != null) {
|
|
|
+ row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String license = row.getCell(2).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(license))
|
|
|
+ vendorListSubmit.setLicense(license);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 地区
|
|
|
+ if (row.getCell(3) != null) {
|
|
|
+ row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String area = row.getCell(3).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(area)) {
|
|
|
+ area.replace(",", ",");
|
|
|
+ vendorListSubmit.setArea(area);
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行地区不可为空");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行地区不可为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 详细地址
|
|
|
+ if (row.getCell(4) != null) {
|
|
|
+ row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String detailAddress = row.getCell(4).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(detailAddress)) {
|
|
|
+ vendorListSubmit.setDetailAddress(detailAddress);
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行详细地址不可为空");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行详细地址不可为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 电话
|
|
|
+ if (row.getCell(5) != null) {
|
|
|
+ row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String tel = row.getCell(5).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(tel)) {
|
|
|
+ vendorListSubmit.setTel(tel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 传真
|
|
|
+ if (row.getCell(6) != null) {
|
|
|
+ row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String fax = row.getCell(6).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(fax)) {
|
|
|
+ vendorListSubmit.setFax(fax);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 网址
|
|
|
+ if (row.getCell(7) != null) {
|
|
|
+ row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String website = row.getCell(7).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(website)) {
|
|
|
+ vendorListSubmit.setWebsite(website);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关联企业名称
|
|
|
+ if (row.getCell(8) != null) {
|
|
|
+ row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String enName = row.getCell(8).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(enName)) {
|
|
|
+ List<Long> enuu = enterpriseDao.findEnuuByName(enName);
|
|
|
+ if (CollectionUtils.isNotEmpty(enuu)) {
|
|
|
+ List<StoreIn> storeInExist = storeInDao.findByEnUU(enuu.get(0));
|
|
|
+ if (CollectionUtils.isNotEmpty(storeInExist)) {
|
|
|
+ StoreIn storeIn = storeInExist.get(0);
|
|
|
+ if (StoreStatus.OPENED == storeIn.getStatus()) {
|
|
|
+ VendorList vendorLists = vendorListDao.findByBranduuidAndStoreuuid(vendorListSubmit.getBranduuid(), storeIn.getUuid());
|
|
|
+ if (vendorLists != null) {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行企业:" + enName + " 店铺,在当前品牌下已关联供应商");
|
|
|
+ }
|
|
|
+ vendorListSubmit.setStoreuuid(storeIn.getUuid());
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行企业:" + enName + " 店铺不为已开通状态");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行企业:" + enName + "未开通店铺");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第" + (r+1) + "行企业:" + enName + "不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 邮箱
|
|
|
+ if (row.getCell(9) != null) {
|
|
|
+ row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String email = row.getCell(9).getStringCellValue().trim();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(email)) {
|
|
|
+ vendorListSubmit.setEmail(email);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ vendorListSubmit.setUpdateruu(SystemSession.getUser().getUserUU());
|
|
|
+ vendorListSubmit.setUpdatetime(new Date());
|
|
|
+ vendorListSubmit.setStatus(Status.SUBMITTED.value());
|
|
|
+ // 设置操作类型为新增
|
|
|
+ vendorListSubmit.setType(Status.PRELIMINARY.value());
|
|
|
+ vendorListSubmitList.add(vendorListSubmit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return vendorListSubmitDao.save(vendorListSubmitList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<VendorListSubmit> findByPage(final PageInfo pageInfo, String keywords, Integer status) {
|
|
|
+ if (Status.AVAILABLE.value() != status) {// 非全部时过滤状态
|
|
|
+ pageInfo.filter("status", status);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.hasText(keywords)) {
|
|
|
+ SimpleExpression vendorName = new SimpleExpression("vendorName", keywords, CriterionExpression.Operator.LIKE, true);
|
|
|
+ pageInfo.expression(vendorName);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<VendorListSubmit> vendorListSubmitPage = vendorListSubmitDao.findAll(new Specification<VendorListSubmit>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<VendorListSubmit> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ query.where(pageInfo.getPredicates(root, query, cb));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+
|
|
|
+ List<VendorListSubmit> vendorListSubmits = vendorListSubmitPage.getContent();
|
|
|
+ for (VendorListSubmit vendorListSubmit : vendorListSubmits) {// 设置品牌信息、提交人、审核人
|
|
|
+ Brand brand = brandDao.findByUuid(vendorListSubmit.getBranduuid());
|
|
|
+ if (brand == null)
|
|
|
+ throw new IllegalOperatorException("供应商申请:" + vendorListSubmit.getVendorName() + " 所属品牌不存在");
|
|
|
+ vendorListSubmit.setBrand(new BrandInfo(brand));
|
|
|
+
|
|
|
+ UserBaseInfo updater = userBaseInfoDao.findUserByUserUU(vendorListSubmit.getUpdateruu());
|
|
|
+ if (updater == null)
|
|
|
+ throw new IllegalOperatorException("供应商申请:" + vendorListSubmit.getVendorName() + " 提交人不存在");
|
|
|
+ vendorListSubmit.setUpdater(updater);
|
|
|
+
|
|
|
+ if (vendorListSubmit.getAuditeruu() != null) {
|
|
|
+ UserBaseInfo auditer = userBaseInfoDao.findUserByUserUU(vendorListSubmit.getUpdateruu());
|
|
|
+ if (auditer == null)
|
|
|
+ throw new IllegalOperatorException("供应商申请:" + vendorListSubmit.getVendorName() + " 审核人不存在");
|
|
|
+ vendorListSubmit.setAuditer(auditer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new PageImpl<VendorListSubmit>(vendorListSubmits, pageInfo, vendorListSubmitPage.getTotalElements());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证申请数据正确性
|
|
|
+ * @param vendorListSubmit
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void validition(VendorListSubmit vendorListSubmit) {
|
|
|
+ if (vendorListSubmit.getBranduuid() == null) {
|
|
|
+ throw new IllegalOperatorException("品牌信息为空,请确认信息后重新申请");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 店铺id不为空时,验证同品牌下是否存在已关联该店铺的供应商(更新自身除外)
|
|
|
+ if (vendorListSubmit.getStoreuuid() != null) {
|
|
|
+ VendorList existsVendor = vendorListDao.findByBranduuidAndStoreuuid(vendorListSubmit.getBranduuid(), vendorListSubmit.getStoreuuid());
|
|
|
+ if (existsVendor != null && !existsVendor.getId().equals(vendorListSubmit.getVendorid())) {
|
|
|
+ throw new IllegalOperatorException("此店铺关联供应商已入驻,请确认信息后重新申请");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|