Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(OmsOrderServiceImpl,EsProductServiceImpl): Code refactor. #600

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.macro.mall.model.OmsOrderExample;
import com.macro.mall.model.OmsOrderOperateHistory;
import com.macro.mall.service.OmsOrderService;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -44,15 +45,7 @@ public int delivery(List<OmsOrderDeliveryParam> deliveryParamList) {
int count = orderDao.delivery(deliveryParamList);
//添加操作记录
List<OmsOrderOperateHistory> operateHistoryList = deliveryParamList.stream()
.map(omsOrderDeliveryParam -> {
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(omsOrderDeliveryParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(2);
history.setNote("完成发货");
return history;
}).collect(Collectors.toList());
.map(omsOrderDeliveryParam -> getOmsOrderOperateHistory(omsOrderDeliveryParam.getOrderId(), 2, "完成发货")).collect(Collectors.toList());
orderOperateHistoryDao.insertList(operateHistoryList);
return count;
}
Expand All @@ -64,15 +57,7 @@ public int close(List<Long> ids, String note) {
OmsOrderExample example = new OmsOrderExample();
example.createCriteria().andDeleteStatusEqualTo(0).andIdIn(ids);
int count = orderMapper.updateByExampleSelective(record, example);
List<OmsOrderOperateHistory> historyList = ids.stream().map(orderId -> {
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(orderId);
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(4);
history.setNote("订单关闭:"+note);
return history;
}).collect(Collectors.toList());
List<OmsOrderOperateHistory> historyList = ids.stream().map(orderId -> getOmsOrderOperateHistory(orderId, 4, "订单关闭:" + note)).collect(Collectors.toList());
orderOperateHistoryDao.insertList(historyList);
return count;
}
Expand Down Expand Up @@ -105,12 +90,7 @@ public int updateReceiverInfo(OmsReceiverInfoParam receiverInfoParam) {
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
//插入操作记录
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(receiverInfoParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(receiverInfoParam.getStatus());
history.setNote("修改收货人信息");
OmsOrderOperateHistory history = getOmsOrderOperateHistory(receiverInfoParam.getOrderId(), receiverInfoParam.getStatus(), "修改收货人信息");
orderOperateHistoryMapper.insert(history);
return count;
}
Expand All @@ -124,12 +104,7 @@ public int updateMoneyInfo(OmsMoneyInfoParam moneyInfoParam) {
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
//插入操作记录
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(moneyInfoParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(moneyInfoParam.getStatus());
history.setNote("修改费用信息");
OmsOrderOperateHistory history = getOmsOrderOperateHistory(moneyInfoParam.getOrderId(), moneyInfoParam.getStatus(), "修改费用信息");
orderOperateHistoryMapper.insert(history);
return count;
}
Expand All @@ -141,13 +116,19 @@ public int updateNote(Long id, String note, Integer status) {
order.setNote(note);
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
OmsOrderOperateHistory history = getOmsOrderOperateHistory(id, status, "修改备注信息:" + note);
orderOperateHistoryMapper.insert(history);
return count;
}

@NotNull
private static OmsOrderOperateHistory getOmsOrderOperateHistory(Long id, Integer status, String note) {
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(id);
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(status);
history.setNote("修改备注信息:"+note);
orderOperateHistoryMapper.insert(history);
return count;
history.setNote(note);
return history;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;


Expand Down Expand Up @@ -78,25 +79,14 @@ public void delete(Long id) {

@Override
public EsProduct create(Long id) {
EsProduct result = null;
List<EsProduct> esProductList = productDao.getAllEsProductList(id);
if (esProductList.size() > 0) {
EsProduct esProduct = esProductList.get(0);
result = productRepository.save(esProduct);
}
return result;
Optional<EsProduct> firstEProduct = productDao.getAllEsProductList(id).stream().findFirst();
return firstEProduct.map(esProduct -> productRepository.save(esProduct)).orElse(null);
}

@Override
public void delete(List<Long> ids) {
if (!CollectionUtils.isEmpty(ids)) {
List<EsProduct> esProductList = new ArrayList<>();
for (Long id : ids) {
EsProduct esProduct = new EsProduct();
esProduct.setId(id);
esProductList.add(esProduct);
}
productRepository.deleteAll(esProductList);
ids.forEach(id->productRepository.deleteById(id));
}
}

Expand Down