|
@@ -0,0 +1,168 @@
|
|
|
|
|
+package com.uas.platform.b2c.prod.product.brand.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.uas.platform.b2c.common.account.model.User;
|
|
|
|
|
+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.BrandMapDao;
|
|
|
|
|
+import com.uas.platform.b2c.prod.product.brand.dao.BrandTempDao;
|
|
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.Brand;
|
|
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.BrandMap;
|
|
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.BrandTemp;
|
|
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.MapOperator;
|
|
|
|
|
+import com.uas.platform.b2c.prod.product.brand.service.BrandMapService;
|
|
|
|
|
+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.StoreType;
|
|
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
|
|
+import com.uas.platform.core.model.PageInfo;
|
|
|
|
|
+import com.uas.platform.core.model.PageParams;
|
|
|
|
|
+import com.uas.platform.core.persistence.criteria.CriterionExpression;
|
|
|
|
|
+import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
|
|
+import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
+
|
|
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 品牌映射服务的实现类
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+public class BrandMapServiceImpl implements BrandMapService{
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BrandTempDao brandTempDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BrandMapDao brandMapDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BrandDao brandDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private StoreInDao storeInDao;
|
|
|
|
|
+
|
|
|
|
|
+ //10041230L--10000666L--10030744L--10042176L--10005919L--10043358L--10044036L--10041191L--10042901L
|
|
|
|
|
+// private final static List<Long> uuList = Arrays.asList(10041230L, 10000666L,
|
|
|
|
|
+// 10030744L, 10042176L, 10005919L, 10043358L, 10044036L, 10041191L, 10042901L);
|
|
|
|
|
+
|
|
|
|
|
+ //暂时测试happy和豆腐公司
|
|
|
|
|
+ private final static List<Long> uuList = Arrays.asList(10043457L, 10043516L);
|
|
|
|
|
+
|
|
|
|
|
+ public PageInfo convertPageInfo(PageInfo info, String keyword, StoreType type, Long fromDate, Long toDate){
|
|
|
|
|
+ if (type != null){
|
|
|
|
|
+ info.expression(PredicateUtils.eq("type", type, false));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.hasText(keyword)){
|
|
|
|
|
+ SimpleExpression expression1 = new SimpleExpression("nameStandardEn", keyword, CriterionExpression.Operator.LIKE, true);
|
|
|
|
|
+ SimpleExpression expression2 = new SimpleExpression("nameStandardCn", keyword, CriterionExpression.Operator.LIKE, true);
|
|
|
|
|
+ SimpleExpression expression3 = new SimpleExpression("enName", keyword, CriterionExpression.Operator.LIKE);
|
|
|
|
|
+ SimpleExpression[] expressions = new SimpleExpression[]{expression1, expression2, expression3};
|
|
|
|
|
+ info.expression(PredicateUtils.or(expressions));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fromDate != null){
|
|
|
|
|
+ info.expression(PredicateUtils.gte("operateTime", new Date(fromDate), false));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toDate != null){
|
|
|
|
|
+ info.expression(PredicateUtils.lte("operateTime", new Date(toDate), false));
|
|
|
|
|
+ }
|
|
|
|
|
+ return info;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Page<BrandMap> findAllMap(PageParams params, String keyword, StoreType type, Long fromDate, Long toDate) {
|
|
|
|
|
+ final PageInfo pageInfo = new PageInfo(params);
|
|
|
|
|
+ convertPageInfo(pageInfo, keyword, type, fromDate, toDate);
|
|
|
|
|
+ return brandMapDao.findAll(new Specification<BrandMap>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Predicate toPredicate(Root<BrandMap> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
|
|
|
+ criteriaQuery.where(pageInfo.getPredicates(root, criteriaQuery, criteriaBuilder));
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }, pageInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<BrandMap> getMapDataList(String keyword, StoreType type, Long fromDate, Long toDate) {
|
|
|
|
|
+ final PageInfo pageInfo = new PageInfo();
|
|
|
|
|
+ convertPageInfo(pageInfo, keyword, type, fromDate, toDate);
|
|
|
|
|
+ List<BrandMap> mapList = brandMapDao.findAll(new Specification<BrandMap>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Predicate toPredicate(Root<BrandMap> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
|
|
+ query.where(pageInfo.getPredicates(root, query, builder));
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return mapList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BrandMap addOneMap(BrandMap map) {
|
|
|
|
|
+ User user = SystemSession.getUser();
|
|
|
|
|
+ map.setUserUU(user.getUserUU());
|
|
|
|
|
+ map.setOperateName(user.getUserName());
|
|
|
|
|
+ map.setOperateTime(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ return brandMapDao.save(map);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Object deleteOneMap(Long id) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initBrandMap() {
|
|
|
|
|
+ List<BrandTemp> originalList = brandTempDao.getAllBySdNameNotNull();
|
|
|
|
|
+ List<BrandTemp> convertList = new ArrayList<>();
|
|
|
|
|
+ for (BrandTemp temp : originalList){
|
|
|
|
|
+ if (!temp.getNameCd().equals(temp.getNameSd())) { //相同的不记录
|
|
|
|
|
+ convertList.add(temp);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ List<BrandMap> resultList = new ArrayList<>();
|
|
|
|
|
+ for (Long enuu : uuList){
|
|
|
|
|
+ List<StoreIn> storeList = storeInDao.findByEnUU(enuu);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(storeList)){
|
|
|
|
|
+ throw new IllegalOperatorException("对应的店铺信息丢失,请刷新重新");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ StoreIn store = storeList.get(0);
|
|
|
|
|
+ for (BrandTemp temp : convertList){
|
|
|
|
|
+
|
|
|
|
|
+ List<Brand> brandList = brandDao.findByNameEn(temp.getNameSd());
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(brandList)){
|
|
|
|
|
+ Brand brand = brandList.get(0);
|
|
|
|
|
+ BrandMap map = new BrandMap();
|
|
|
|
|
+ map.setNameStandardEn(temp.getNameSd());
|
|
|
|
|
+ map.setNameStandardCn(brand.getNameCn());
|
|
|
|
|
+ map.setNameChildEn(temp.getNameCd());
|
|
|
|
|
+ map.setNameChildCn(temp.getNameCd());
|
|
|
|
|
+
|
|
|
|
|
+ map.setEnuu(store.getEnUU());
|
|
|
|
|
+ map.setEnName(store.getStoreName());
|
|
|
|
|
+ map.setType(store.getType());
|
|
|
|
|
+
|
|
|
|
|
+ User user = SystemSession.getUser();
|
|
|
|
|
+ map.setUserUU(user.getUserUU());
|
|
|
|
|
+ map.setOperateName(user.getUserName());
|
|
|
|
|
+ map.setOperateTime(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ resultList.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ brandMapDao.save(resultList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|