|
|
package com.yoho.ufo.service.impl;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.slf4j.helpers.MessageFormatter;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.common.collect.Sets;
|
|
|
import com.yoho.product.dal.SelfSizeMapper;
|
|
|
import com.yoho.product.dal.SelfSizeUidMapper;
|
|
|
import com.yoho.product.model.SelfSize;
|
|
|
import com.yoho.product.model.SelfSizeReq;
|
|
|
import com.yoho.product.model.SelfSizeRsp;
|
|
|
import com.yoho.product.model.SelfSizeUid;
|
|
|
import com.yoho.ufo.dal.BrandMapper;
|
|
|
import com.yoho.ufo.dal.ProductMapper;
|
|
|
import com.yoho.ufo.dal.StorageMapper;
|
|
|
import com.yoho.ufo.dal.UfoSizeMapper;
|
|
|
import com.yoho.ufo.dal.model.Product;
|
|
|
import com.yoho.ufo.dal.model.Storage;
|
|
|
import com.yoho.ufo.exception.PlatformException;
|
|
|
import com.yoho.ufo.model.brand.Brand;
|
|
|
import com.yoho.ufo.model.commoditybasicrole.size.Size;
|
|
|
import com.yoho.ufo.service.ISelfSizeService;
|
|
|
import com.yoho.ufo.service.UserProxyService;
|
|
|
import com.yoho.ufo.service.model.PageResponseBO;
|
|
|
|
|
|
/**
|
|
|
* @author caoyan
|
|
|
* @date 2019/3/19
|
|
|
*/
|
|
|
@Service
|
|
|
public class SelfSizeServiceImpl implements ISelfSizeService {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(SelfSizeServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SelfSizeMapper selfSizeMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SelfSizeUidMapper selfSizeUidMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private BrandMapper brandMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private UfoSizeMapper ufoSizeMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private StorageMapper storageMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private InboxServiceImpl inboxService;
|
|
|
|
|
|
@Autowired
|
|
|
private UserProxyService userProxyService;
|
|
|
|
|
|
@Override
|
|
|
public PageResponseBO<SelfSizeRsp> queryList(SelfSizeReq req){
|
|
|
int total = selfSizeMapper.selectTotalByCondition(req);
|
|
|
if(total == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
List<SelfSize> list = selfSizeMapper.selectByCondition(req);
|
|
|
if(CollectionUtils.isEmpty(list)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
List<Integer> productIdList = list.stream().map(SelfSize::getProductId).collect(Collectors.toList());
|
|
|
List<Product> productList = productMapper.selectProductListByIds(productIdList);
|
|
|
Map<Integer, Product> productMap = productList.stream().collect(Collectors.toMap(Product::getId, p->p));
|
|
|
List<Integer> brandIdList = productList.stream().map(Product::getBrandId).collect(Collectors.toList());
|
|
|
List<Brand> brandList = brandMapper.selectBrandByIdList(brandIdList);
|
|
|
Map<Integer, String> brandIdNameMap = brandList.stream().collect(Collectors.toMap(Brand::getId, Brand::getBrandName));
|
|
|
List<Integer> sizeIdList = list.stream().map(SelfSize::getSizeId).collect(Collectors.toList());
|
|
|
List<Size> sizeList = ufoSizeMapper.selectByIdList(sizeIdList);
|
|
|
Map<Integer, String> sizeIdNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
|
|
|
List<Integer> goodsIdList = list.stream().map(SelfSize::getGoodsId).collect(Collectors.toList());
|
|
|
Map<Integer, String> goodsIdSizeNameMap = getSellingSizeNameMap(goodsIdList);
|
|
|
List<SelfSizeUid> uidInfoList = selfSizeUidMapper.selectByPrdIdList(productIdList);
|
|
|
Map<Integer, List<SelfSizeUid>> selfSizeUidMap = uidInfoList.stream().collect(Collectors.groupingBy(SelfSizeUid::getSizeId));
|
|
|
|
|
|
|
|
|
List<SelfSizeRsp> rspList = Lists.newArrayList();
|
|
|
for(SelfSize item : list) {
|
|
|
SelfSizeRsp rsp = new SelfSizeRsp();
|
|
|
rsp.setId(item.getId());
|
|
|
rsp.setBrandName(brandIdNameMap.get(productMap.get(item.getProductId()).getBrandId()));
|
|
|
rsp.setProductName(productMap.get(item.getProductId()).getProductName());
|
|
|
rsp.setProductCode(productMap.get(item.getProductId()).getProductCode());
|
|
|
rsp.setProductId(item.getProductId());
|
|
|
rsp.setApplySizeName(sizeIdNameMap.get(item.getSizeId()));
|
|
|
rsp.setStatus(item.getStatus());
|
|
|
rsp.setStatusStr(getStatusStr(item.getStatus()));
|
|
|
rsp.setSellingSizeName(goodsIdSizeNameMap.get(item.getGoodsId()));
|
|
|
List<SelfSizeUid> selfSizeUids = selfSizeUidMap.get(item.getSizeId());
|
|
|
List<Integer> applyUidList = selfSizeUids.stream().map(SelfSizeUid::getUid).collect(Collectors.toList());
|
|
|
rsp.setApplyUid(getApplyUidStr(applyUidList));
|
|
|
|
|
|
rspList.add(rsp);
|
|
|
}
|
|
|
|
|
|
PageResponseBO<SelfSizeRsp> result=new PageResponseBO<>();
|
|
|
result.setList(rspList);
|
|
|
result.setPage(req.getPage());
|
|
|
result.setSize(req.getSize());
|
|
|
result.setTotal(total);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private String getApplyUidStr(List<Integer> uidList) {
|
|
|
Set<String> uidStrSet = Sets.newHashSet();
|
|
|
for(Integer uid : uidList) {
|
|
|
uidStrSet.add(String.valueOf(uid));
|
|
|
}
|
|
|
|
|
|
return String.join("、", uidStrSet);
|
|
|
}
|
|
|
|
|
|
private Map<Integer, String> getSellingSizeNameMap(List<Integer> goodsIdList){
|
|
|
List<Storage> storageList = storageMapper.selectByGoodsIdList(goodsIdList);
|
|
|
Map<Integer, List<Storage>> goodsIdMap = storageList.stream().collect(Collectors.groupingBy(Storage::getGoodsId));
|
|
|
List<Integer> sizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList());
|
|
|
List<Size> sizeList = ufoSizeMapper.selectByIdList(sizeIdList);
|
|
|
Map<Integer, String> sizeIdNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
|
|
|
Map<Integer, String> result = Maps.newHashMap();
|
|
|
for(Entry<Integer, List<Storage>> entry : goodsIdMap.entrySet()) {
|
|
|
List<Integer> sizeIds = entry.getValue().stream().map(Storage::getSizeId).collect(Collectors.toList());
|
|
|
List<String> sizeNameList = Lists.newArrayList();
|
|
|
for(Integer sizeId : sizeIds) {
|
|
|
sizeNameList.add(sizeIdNameMap.get(sizeId));
|
|
|
}
|
|
|
result.put(entry.getKey(), String.join("、", sizeNameList));
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private String getStatusStr(Integer status) {
|
|
|
if(status.intValue() == 0) {
|
|
|
return "待审核";
|
|
|
}else if(status.intValue() == 1) {
|
|
|
return "已通过";
|
|
|
}else if(status.intValue() == 2) {
|
|
|
return "不通过";
|
|
|
}else {
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SelfSizeRsp getDetail(SelfSizeReq req) {
|
|
|
SelfSize selfSize = selfSizeMapper.selectByPrimaryKey(req.getId());
|
|
|
if(null == selfSize) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
Product product = productMapper.selectByPrimaryKey(selfSize.getProductId());
|
|
|
Brand brand = brandMapper.selectOneById(product.getBrandId());
|
|
|
Size size = ufoSizeMapper.selectOneById(selfSize.getSizeId());
|
|
|
List<Storage> storageList = storageMapper.selectByGoodsId(selfSize.getGoodsId());
|
|
|
List<Integer> sizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList());
|
|
|
List<Size> sizeList = ufoSizeMapper.selectByIdList(sizeIdList);
|
|
|
List<String> sizeNameList = sizeList.stream().map(Size::getSizeName).collect(Collectors.toList());
|
|
|
List<Integer> uidList = selfSizeUidMapper.selectUidByProductIdAndSizeId(selfSize.getProductId(), selfSize.getSizeId());
|
|
|
|
|
|
SelfSizeRsp rsp = new SelfSizeRsp();
|
|
|
rsp.setBrandName(brand.getBrandName());
|
|
|
rsp.setProductName(product.getProductName());
|
|
|
rsp.setProductId(product.getId());
|
|
|
rsp.setProductCode(product.getProductCode());
|
|
|
rsp.setApplySizeName(size.getSizeName());
|
|
|
rsp.setSellingSizeName(String.join("、", sizeNameList));
|
|
|
List<String> uidStrList = Lists.newArrayList();
|
|
|
for(Integer uid : uidList) {
|
|
|
uidStrList.add(String.valueOf(uid));
|
|
|
}
|
|
|
rsp.setApplyUid(String.join("、", uidStrList));
|
|
|
return rsp;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int updateAuditResult(SelfSizeReq req) throws PlatformException {
|
|
|
SelfSize selfSize = selfSizeMapper.selectByPrimaryKey(req.getId());
|
|
|
if(null == selfSize) {
|
|
|
throw new PlatformException("记录不存在", 400);
|
|
|
}
|
|
|
|
|
|
UserHelper userInfo = new UserHelper();
|
|
|
int num = selfSizeMapper.upadteAuditResult(req.getId(), req.getStatus(), userInfo.getUserId());
|
|
|
if(num > 0 && req.getStatus().intValue() == 1) {//审核通过
|
|
|
//发送站内信
|
|
|
// inboxService.addInboxForPlatform(pss.getUid(), InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_SELF_SHELVES_AUDIT_PASS.getType(),
|
|
|
// InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_SELF_SHELVES_AUDIT_PASS.getBusinessType(), buildParams(pss.getBrand(), pss.getProductName(), pss.getProductCode()));
|
|
|
// //发送短信
|
|
|
// SmsMessageReq smsReq = new SmsMessageReq();
|
|
|
// //获取手机号
|
|
|
// String mobile = userProxyService.getMobile(pss.getUid());
|
|
|
// smsReq.setMobileList(Lists.newArrayList(mobile));
|
|
|
// smsReq.setContent(getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_SELLER_WHEN_SELF_SHELVES_AUDIT_PASS.getContent(), pss.getBrand(), pss.getProductName(), pss.getProductCode()));
|
|
|
// inboxService.sendSmsMessage(smsReq);
|
|
|
}
|
|
|
return num;
|
|
|
}
|
|
|
|
|
|
private String getReplacedContent(String content ,Object... params) {
|
|
|
return MessageFormatter.arrayFormat(content, params).getMessage();
|
|
|
}
|
|
|
|
|
|
public static String buildParams(Object... objects) {
|
|
|
if (objects == null) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (objects.length == 1) {
|
|
|
return objects[0].toString();
|
|
|
}
|
|
|
|
|
|
String params = StringUtils.join(objects, ",");
|
|
|
return params;
|
|
|
}
|
|
|
|
|
|
private String getAuditStatusStr(int status) {
|
|
|
if(status == 0) {
|
|
|
return "待审核";
|
|
|
}else if(status == 1) {
|
|
|
return "已上架";
|
|
|
}else if(status == 2) {
|
|
|
return "不通过";
|
|
|
}else if(status == 3) {
|
|
|
return "待上架";
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
} |
...
|
...
|
|