| | |
| | | import com.xzx.gc.common.utils.StringUtils; |
| | | import com.xzx.gc.entity.JhyOrder; |
| | | import com.xzx.gc.entity.JhyOrderItems; |
| | | import com.xzx.gc.entity.ScoreOrder; |
| | | import com.xzx.gc.entity.ScoreOrderDetails; |
| | | import com.xzx.gc.shop.dto.CancelJhyOrderDto; |
| | | import com.xzx.gc.shop.dto.QueryJhyOrderListDto; |
| | | import com.xzx.gc.shop.mapper.JhyOrderItemsMapper; |
| | | import com.xzx.gc.shop.mapper.JhyOrderMapper; |
| | | import com.xzx.gc.shop.mapper.OrderInfoMapper; |
| | | import com.xzx.gc.shop.mapper.ScoreOrderMapper; |
| | | import com.xzx.gc.shop.vo.*; |
| | | 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; |
| | |
| | | JhyOrderMapper jhyOrderMapper; |
| | | @Resource |
| | | JhyOrderItemsMapper jhyOrderItemsMapper; |
| | | |
| | | @Autowired |
| | | private OrderInfoMapper orderInfoMapper; |
| | | |
| | | @Autowired |
| | | private ScoreOrderMapper scoreOrderMapper; |
| | | |
| | | public Map<String, Object> queryOrderList(QueryJhyOrderListDto model) { |
| | | PageHelper.startPage(model.getPage(), model.getLimit()); |
| | |
| | | jhyOrder.setStatus(JhyOrder.ORDER_STATUS_CANCEL); |
| | | jhyOrderMapper.updateByPrimaryKey(jhyOrder); |
| | | } |
| | | |
| | | public StatisticsVo orderStatistics(String userId) { |
| | | // 骑手订单 |
| | | List<Map<String, Object>> qsAllData = orderInfoMapper.selectOrderTitleStatistics(null); |
| | | List<Map<String, Object>> qsUserData = orderInfoMapper.selectOrderTitleStatistics(userId); |
| | | |
| | | // 集物员订单 |
| | | List<Map<String, Object>> jhyAllData = jhyOrderMapper.selectJhyOrderTitleStatistics(null); |
| | | List<Map<String, Object>> jhyUserData = jhyOrderMapper.selectJhyOrderTitleStatistics(userId); |
| | | |
| | | BigDecimal allCarbon = totalData(qsAllData).add(totalData(jhyAllData)); |
| | | BigDecimal userCarbon = totalData(qsUserData).add(totalData(jhyUserData)); |
| | | |
| | | Integer qsAllCnt = orderInfoMapper.selectOrderCnt(null); |
| | | Integer qsUserCnt = orderInfoMapper.selectOrderCnt(userId); |
| | | |
| | | Integer jhyAllCnt = jhyOrderMapper.selectJhyOrderCnt(null); |
| | | Integer jhyUserCnt = jhyOrderMapper.selectJhyOrderCnt(userId); |
| | | |
| | | Integer allCnt = scoreOrderMapper.selectScoreOrderCnt(null); |
| | | BigDecimal score = jhyOrderMapper.selectTotalScoreHasGet(userId); |
| | | |
| | | StatisticsVo result = new StatisticsVo(); |
| | | result.setTotalReduceCarbon(allCarbon.divide(BigDecimal.valueOf(1000), 2, BigDecimal.ROUND_DOWN)); |
| | | result.setReduceCarbon(userCarbon.setScale(2, BigDecimal.ROUND_DOWN)); |
| | | |
| | | result.setOrderCnt(qsUserCnt + jhyUserCnt); |
| | | result.setTotalOrderCnt(qsAllCnt + jhyAllCnt); |
| | | |
| | | result.setTotalBuyCnt(allCnt); |
| | | result.setScore(score); |
| | | return result; |
| | | } |
| | | |
| | | private BigDecimal totalData(List<Map<String, Object>> data) { |
| | | Map<String, BigDecimal> type = new HashMap<>(); |
| | | type.put("金属", BigDecimal.valueOf(0.02)); |
| | | type.put("纸类", BigDecimal.valueOf(1.5)); |
| | | type.put("塑料", BigDecimal.valueOf(0.61)); |
| | | type.put("衣服", BigDecimal.valueOf(1.63)); |
| | | |
| | | if (CollUtil.isEmpty(data)) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | for (Map<String, Object> map : data) { |
| | | String title = (String) map.get("title"); |
| | | BigDecimal value = type.get(title); |
| | | if (value == null) { |
| | | continue; |
| | | } |
| | | |
| | | BigDecimal weight = new BigDecimal(map.get("weight").toString()); |
| | | total = total.add(weight.multiply(value)); |
| | | } |
| | | |
| | | return total; |
| | | } |
| | | } |