forked from kidgrow-microservices-platform

zhaoxiaohao
2020-06-24 a8bf44754f50d0b0a65f0f2d4beefc131261e35d
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.kidgrow.oprationcenter.service.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kidgrow.common.model.PageResult;
import com.kidgrow.common.service.impl.SuperServiceImpl;
import com.kidgrow.common.utils.StringUtils;
import com.kidgrow.oprationcenter.mapper.ConsumptionRecordMapper;
import com.kidgrow.oprationcenter.model.ConsumptionRecord;
import com.kidgrow.oprationcenter.service.IConsumptionRecordService;
import com.kidgrow.oprationcenter.service.IProductOrderDetailService;
import com.kidgrow.oprationcenter.vo.ProductOrderJoinDetail;
import com.kidgrow.oprationcenter.vo.UserProductDetail;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 * @Description: <br>
 * @Project: 运营中心<br>
 * @CreateDate: Created in 2020-06-23 15:07:14 <br>
 * @Author: <a href="411269194@kidgrow.com">houruijun</a>
 * @version 1.0
 */
@Slf4j
@Service
public class ConsumptionRecordServiceImpl extends SuperServiceImpl<ConsumptionRecordMapper, ConsumptionRecord> implements IConsumptionRecordService {
    @Autowired
    private IProductOrderDetailService productOrderDetailService;
    /**
     * 列表
     * @param params
     * @return
     */
    @Override
    public PageResult<ConsumptionRecord> findList(Map<String, Object> params){
        Page<ConsumptionRecord> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
        List<ConsumptionRecord> list  =  baseMapper.findList(page, params);
        return PageResult.<ConsumptionRecord>builder().data(list).code(0).count(page.getTotal()).build();
    }
    /**
     * 列表
     * @param params
     * @return
     */
    @Override
    public List<ConsumptionRecord> findAllList(Map<String, Object> params){
        return baseMapper.findList(params);
    }
 
    /**
   * 根据ConsumptionRecord对象当做查询条件进行查询
   * @param consumptionRecord
   * @return ConsumptionRecord
   */
    @Override
    public ConsumptionRecord findByObject(ConsumptionRecord consumptionRecord){
        return baseMapper.findByObject(consumptionRecord);
    }
 
    /**
     *
     * @param hospitalId
     * @param departmentId
     * @return
     */
    public boolean deductionDepartmentProduct(Long hospitalId,Long departmentId)
    {
        UserProductDetail userProductDetail=productOrderDetailService.getUserProductDetail(hospitalId,departmentId);
        //合并集合
        userProductDetail.getProductOrderJoinDetailListShare().addAll(userProductDetail.getProductOrderJoinDetailsListDep());
        List<ProductOrderJoinDetail> productOrderJoinDetailList=userProductDetail.getProductOrderJoinDetailListShare();
        //Collections.sort(productOrderJoinDetailList);
        return false;
    }
    /**
     * 写/更新记录数据
     * @param consumptionRecord
     * @return
     */
    public ConsumptionRecord SaveConsumptionRecord(ConsumptionRecord consumptionRecord)
    {
        if (consumptionRecord != null) {
            this.saveOrUpdate(consumptionRecord);
            return consumptionRecord;
        }
        return null;
    }
    /**
     * 检查该业务是否存在该业务类型
     * @param consumptionRecordList 该业务下的扣费列表
     * @param recordType 记录类型编码 参考ConsumptionConstant里面
     * @return
     */
    public boolean isBeforeDeduction(List<ConsumptionRecord> consumptionRecordList,int recordType)
    {
        if (consumptionRecordList != null) {
            if (consumptionRecordList.size()>0) {
                //过滤预扣费的记录
                return consumptionRecordList.stream().filter(f->f.getRecordType()==recordType).collect(Collectors.toList()).size()==1;
            }
        }
        return false;
    }
 
    /**
     * 获取一个业务关联的扣费记录
     * @param businessId 光片的名称/编号
     * @return
     */
    public List<ConsumptionRecord> GetBusinessConsumptionList(String businessId)
    {
        if (StringUtils.isNotBlank(businessId)) {
            Map<String, Object> params = new HashMap<>();
            params.put("businessId", businessId);
            List<ConsumptionRecord> consumptionRecordList=this.findAllList(params);
            return consumptionRecordList;
        }
        return null;
    }
    /**
     * 获取一个扣费记录
     * @param recordId 扣费记录id
     * @return
     */
    public ConsumptionRecord GetBusinessConsumptionList(Long recordId)
    {
        if (recordId>0) {
            return baseMapper.selectById(recordId);
        }
        return null;
    }
}