| 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);  | 
|     }  | 
|   | 
| }  |