wzy
2021-11-30 0e5aaeba97021c289485a652ec6af0bb37f92af7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.xzx.gc.order.service;
 
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.entity.OrderItemInfo;
import com.xzx.gc.entity.SysEnvironmentalInfo;
import com.xzx.gc.model.order.ItemDto;
import com.xzx.gc.model.order.OrderItemReq;
import com.xzx.gc.model.order.OrderItemVo;
import com.xzx.gc.order.mapper.OrderItemInfoMapper;
import com.xzx.gc.order.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
@Service
@Transactional
@Slf4j
public class OrderItemService {
 
    @Autowired
    private OrderItemInfoMapper orderItemInfoMapper;
 
    @Autowired
    private SysEnvironmentalInfoService sysEnvironmentalInfoService;
 
    @Autowired
    private AddressService addressService;
 
    @Autowired
    private OrderMapper orderMapper;
 
    /**
     * 查询订单下的所有纸类分类下的信息
     * @param orderId
     * @return
     */
    public List<OrderItemInfo> findByOrderIdAndPaper(String orderId,String addressId){
        //根据订单找用户下单区域
        Integer areaId=Convert.toInt(addressService.findById(addressId).getTownshipId());
        OrderItemInfo orderItemInfo=new OrderItemInfo();
        orderItemInfo.setOrderId(orderId);
        List<OrderItemInfo> select = orderItemInfoMapper.select(orderItemInfo);
        List<OrderItemInfo> list=new ArrayList<>();
        if(CollUtil.isNotEmpty(select)){
            for (OrderItemInfo itemInfo : select) {
                String money = itemInfo.getMoney();
                if(NumberUtil.isGreater(Convert.toBigDecimal(money, Constants.MONEY_INIT), BigDecimal.ZERO)){
                    String itemType = itemInfo.getItemType();
 
                    //是否是纸类的小类
                    SysEnvironmentalInfo byItemTypeAndArea = sysEnvironmentalInfoService.findByItemTypeAndArea(itemType, areaId);
                    if(byItemTypeAndArea!=null){
                        Long parentId = byItemTypeAndArea.getParentId();
                        SysEnvironmentalInfo paperByArea = sysEnvironmentalInfoService.findByItemTypeAndArea(Constants.PAPER_ITEM_TYPE,areaId);
                        if(paperByArea!=null){
                            if(paperByArea.getId().equals(parentId)){
                                list.add(itemInfo);
                            }
                        }
                    }
                }
            }
        }
        return list;
    }
 
 
    /**
     * 是否存在
     * @param orderId
     * @param itemType
     * @return
     */
    public boolean isExist(String orderId,String itemType){
        OrderItemInfo orderItemInfo=new OrderItemInfo();
        orderItemInfo.setOrderId(orderId);
        orderItemInfo.setItemType(itemType);
        return orderItemInfoMapper.selectCount(orderItemInfo)>0?true:false;
    }
 
 
    /**
     * 根据订单id查找订单分类
     * @param orderId
     * @return
     */
    public  List<OrderItemVo> findByOrderId(String orderId,String townId){
        OrderItemReq orderItemReq = new OrderItemReq();
        orderItemReq.setOrderId(orderId);
        List<OrderItemVo> orderItemList = orderMapper.orderItemQuery(orderItemReq);
        for (OrderItemVo orderItemVo : orderItemList) {
            String itemType = orderItemVo.getItemType();
            SysEnvironmentalInfo byItemType = sysEnvironmentalInfoService.findByItemTypeAndArea(itemType,Convert.toInt(townId));
            if(byItemType!=null){
                orderItemVo.setItemTypeName(byItemType.getTitle());
                orderItemVo.setSecondPrice(byItemType.getSecondPrice());
                orderItemVo.setPicture(byItemType.getPicture());
                if(StrUtil.isBlank(orderItemVo.getPrice())){
                    orderItemVo.setPrice(byItemType.getPrice());
                }
            }
        }
        return orderItemList;
    }
 
 
    /**
     * 根据订单id和类型筛选订单分类
     * @param orderId
     * @param childItemTypeByType
     * @return
     */
    public List<OrderItemInfo> findByOrderIdAndTypes(String orderId,List<String> childItemTypeByType){
        return orderItemInfoMapper.findByOrderIdAndTypes(orderId,childItemTypeByType);
    }
 
    /**
     * 根据订单创建用户id和类型筛选已完成的订单分类
     * @param userId
     * @param childItemTypeByType
     * @return
     */
    public List<OrderItemInfo> findByUserIdAndTypesWithComplete(String userId,List<String> childItemTypeByType){
        return orderItemInfoMapper.findByUserIdAndTypesWithComplete(userId,childItemTypeByType);
    }
 
}