| | |
| | | package com.kidgrow.oprationcenter.service.impl; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.constant.ConsumptionConstant; |
| | | import com.kidgrow.common.model.*; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import com.kidgrow.oprationcenter.model.ProductOrderDetail; |
| | | import com.kidgrow.common.utils.DateUtils; |
| | | import com.kidgrow.oprationcenter.feign.DiagnosticService; |
| | | import com.kidgrow.oprationcenter.mapper.ConsumptionRecordMapper; |
| | | import com.kidgrow.oprationcenter.mapper.ProductOrderDetailMapper; |
| | | import com.kidgrow.oprationcenter.model.ConsumptionRecord; |
| | | import com.kidgrow.oprationcenter.model.ProductOrder; |
| | | import com.kidgrow.oprationcenter.model.ProductOrderDetail; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderDetailService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderService; |
| | | import com.kidgrow.oprationcenter.vo.*; |
| | | import com.kidgrow.usercenter.feign.SysDoctorService; |
| | | import com.kidgrow.usercenter.feign.SysHospitalService; |
| | | import com.kidgrow.usercenter.model.SysHospital; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cglib.beans.BeanCopier; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class ProductOrderDetailServiceImpl extends SuperServiceImpl<ProductOrderDetailMapper, ProductOrderDetail> implements IProductOrderDetailService { |
| | | @Autowired |
| | | DiagnosticService diagnosticService; |
| | | @Autowired |
| | | private SysDoctorService sysDoctorService; |
| | | @Autowired |
| | | private SysHospitalService sysHospitalService; |
| | | @Autowired |
| | | private ConsumptionRecordMapper consumptionRecordMapper; |
| | | @Autowired |
| | | private IProductOrderService iProductOrderService; |
| | | /** |
| | | * 列表 |
| | | * @param params |
| | |
| | | List<ProductOrderDetail> list = baseMapper.findList(page, params); |
| | | return PageResult.<ProductOrderDetail>builder().data(list).code(0).count(page.getTotal()).build(); |
| | | } |
| | | /** |
| | | * 获取已购买产品列表 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<ProductOrderJoinDetail> findAllList(Map<String, Object> params){ |
| | | return baseMapper.findAllList(params); |
| | | } |
| | | |
| | | /** |
| | | * 判定医院科室的套餐是否到期 以及到期时间 |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @return |
| | | */ |
| | | public ResultBody<UserProductData> UserProductDetailData(Long hospitalId,Long departmentId) |
| | | { |
| | | UserProductData userProductData=new UserProductData(); |
| | | userProductData.setEnd(true); |
| | | UserProductDetail userProductDetail = this.getUserProductDetail(hospitalId, departmentId); |
| | | if (userProductDetail != null) { |
| | | //合并集合 |
| | | userProductDetail.getProductOrderJoinDetailListShare().addAll(userProductDetail.getProductOrderJoinDetailsListDep()); |
| | | List<ProductOrderJoinDetail> productOrderJoinDetailList = userProductDetail.getProductOrderJoinDetailListShare(); |
| | | if (productOrderJoinDetailList.size() > 0) { |
| | | userProductData.setEnd(false); |
| | | //合并后按id排序并筛除已用完的套餐 |
| | | List<ProductOrderJoinDetail> productOrderJoinDetailsNewList = productOrderJoinDetailList.stream().filter(f -> f.getAilightCount() >= 0).sorted(Comparator.comparing(ProductOrderJoinDetail::getProEndtime).reversed()).collect(Collectors.toList()); |
| | | userProductData.setMaxEndTime(productOrderJoinDetailsNewList.get(0).getProEndtime()); |
| | | } |
| | | } |
| | | return ResultBody.ok().data(userProductData); |
| | | } |
| | | |
| | | /** |
| | | * 获取需要审核的套餐 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageResult all(Map<String, Object> params) { |
| | | Page<ProductOrderDetail> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit")); |
| | | List<ProductOrderDetail> list = baseMapper.findList(page, params); |
| | | List<ProductOrderDetailVo> volist=new ArrayList<>(); |
| | | for (ProductOrderDetail productOrderDetail : list) { |
| | | ProductOrderDetailVo productOrderDetailVo=new ProductOrderDetailVo(); |
| | | BeanCopier beanCopier = BeanCopier.create(ProductOrderDetail.class, ProductOrderDetailVo.class, false); |
| | | beanCopier.copy(productOrderDetail,productOrderDetailVo,null); |
| | | //查询医院 |
| | | if(productOrderDetail.getOrderId()!=null){ |
| | | ProductOrder productOrder = iProductOrderService.getById(productOrderDetail.getOrderId()); |
| | | if(productOrder!=null){ |
| | | productOrderDetailVo.setDepartmentId(productOrder.getDepartmentId()); |
| | | productOrderDetailVo.setDepartmentName(productOrder.getDepartmentName()); |
| | | productOrderDetailVo.setHospitalId(productOrder.getHospitalId()); |
| | | productOrderDetailVo.setHospitalName(productOrder.getHospitalName()); |
| | | } |
| | | volist.add(productOrderDetailVo); |
| | | } |
| | | } |
| | | return PageResult.<ProductOrderDetailVo>builder().data(volist).code(0).count(page.getTotal()).build(); |
| | | } |
| | | |
| | | /** |
| | | * 获取科室试用次数 |
| | | * @param departmentId 科室ID |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int getEnabledCount(Long departmentId) { |
| | | int counts=baseMapper.getEnabledCount(departmentId); |
| | | return counts; |
| | | } |
| | | /** |
| | | * 统计获取数据量 |
| | | * @param datatype |
| | | * 0 试用审核量 |
| | | * 1 套餐总量 |
| | | * 2 未处理用户反馈 |
| | | * 3 未处理数据需求 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int oprationChart(int datatype) { |
| | | return baseMapper.oprationChart(datatype); |
| | | } |
| | | /** |
| | | * 按指定类型统计合同数量 |
| | | * @param params |
| | | * datatype 1 按年 |
| | | * 2 按月 |
| | | * 3 按天 |
| | | * 4 按周 |
| | | * beginTime 查询时间段的开始时间 |
| | | * endTime 结束时间 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<OrderChartVo> productOrderChart(Map<String, Object> params) { |
| | | return baseMapper.productOrderChart(params); |
| | | } |
| | | /** |
| | | * 统计产品的使用数量 |
| | | * @return ccount 是数量 |
| | | * units 是产品名称 |
| | | */ |
| | | @Override |
| | | public List<OrderChartVo> proCountChart() { |
| | | return baseMapper.proCountChart(); |
| | | } |
| | | |
| | | /** |
| | | * 获取诊断列表 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageResult<DiagnosisRecord> findAllDataList(Map<String, Object> params){ |
| | | return diagnosticService.getDiagnosticItemList(params).getData(); |
| | | } |
| | | |
| | | /** |
| | | * 获取统计数据 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | |
| | | @Override |
| | | public PageResult<GroupProductDetail> groupList(Map<String, Object> params) { |
| | | Page<GroupProductDetail> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit")); |
| | | List<GroupProductDetail> list = baseMapper.groupProductDetail(page,params); |
| | | return PageResult.<GroupProductDetail>builder().data(list).code(0).count(page.getTotal()).build(); |
| | | } |
| | | |
| | | /** |
| | | * 根据ProductOrderDetail对象当做查询条件进行查询 |
| | |
| | | public ProductOrderDetail findByObject(ProductOrderDetail productOrderDetail){ |
| | | return baseMapper.findByObject(productOrderDetail); |
| | | } |
| | | /** |
| | | * 修改数据状态 启用 禁用 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody updateEnabled(Map<String, Object> params) { |
| | | Long id = MapUtils.getLong(params, "id"); |
| | | Boolean enabled = MapUtils.getBoolean(params, "enabled"); |
| | | |
| | | ProductOrderDetail productOrder = baseMapper.selectById(id); |
| | | if (productOrder == null) { |
| | | return ResultBody.failed("该数据不存在!"); |
| | | } |
| | | productOrder.setEnabled(enabled); |
| | | productOrder.setUpdateTime(new Date()); |
| | | int i = baseMapper.updateById(productOrder); |
| | | return i > 0 ? ResultBody.ok().data(productOrder).msg("更新成功") : ResultBody.failed("更新失败"); |
| | | } |
| | | |
| | | @Override |
| | | public ResultBody getTypeByUser(SysUser sysUser) { |
| | | List<SysOrganization> organizations = sysUser.getOrganizations(); |
| | | if(organizations.size()>0){ |
| | | SysOrganization sysOrganization = organizations.get(0); |
| | | List<ProductOrderJoinDetail> list=baseMapper.getTypeByUser(sysOrganization.getId()); |
| | | if (list.size()>0) { |
| | | ProductOrderJoinDetail productOrderJoinDetail = list.get(0); |
| | | //查询用户的真实姓名 |
| | | Map<String,Object> selectMap=new HashMap<>(); |
| | | selectMap.put("user_id",sysUser.getId()); |
| | | ResultBody listByMap = sysDoctorService.getListByMap(selectMap); |
| | | List<SysDoctor> sysDoctors = JSON.parseArray(JSON.toJSONString(listByMap.getData()), SysDoctor.class); |
| | | String str=""; |
| | | if(sysDoctors!=null&&sysDoctors.size()>0){ |
| | | str= sysDoctors.get(0).getDoctorName(); |
| | | } |
| | | //查询医院的 logo |
| | | Map<String,Object> map=new HashMap<>(); |
| | | map.put("id",sysOrganization.getId()); |
| | | ResultBody allByMap = sysHospitalService.findAllByMap(map); |
| | | List<SysHospital> hospitals = JSON.parseArray(JSON.toJSONString(allByMap.getData()), SysHospital.class); |
| | | String logo=""; |
| | | if(hospitals.size()>0){ |
| | | logo = hospitals.get(0).getHospitalLogo(); |
| | | } |
| | | Map<String,Object> mapVo=new HashMap<>(); |
| | | mapVo.put("type",productOrderJoinDetail.getProType()); |
| | | mapVo.put("realName",str); |
| | | //剩余时间 |
| | | Date proEndtime = productOrderJoinDetail.getProEndtime(); |
| | | Double surplusDay=DateUtils.getDays(proEndtime, new Date()); |
| | | int surplus = surplusDay.intValue(); |
| | | mapVo.put("surplus",surplus); |
| | | mapVo.put("logo",logo); |
| | | //获取 售后服务工程师********不能从sysOrganization获取,从department获取 |
| | | /* mapVo.put("saleUserName",sysOrganization.getSaleUserName()); |
| | | mapVo.put("saleUserTel",sysOrganization.getSaleUserTel());*/ |
| | | return ResultBody.ok().data(mapVo); |
| | | }else { |
| | | return ResultBody.failed("该用户套餐已经失效"); |
| | | } |
| | | }else { |
| | | return ResultBody.failed("该用户的组织已经失效"); |
| | | } |
| | | } |
| | | /** |
| | | *获取医院的套餐数据 |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public UserProductDetail getUserProductDetail(Long hospitalId, Long departmentId) |
| | | { |
| | | //查询当前医院正在使用的套餐 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("hospitalId", hospitalId); |
| | | List<ProductOrderJoinDetail> productOrderDetailList = this.findAllList(selectMap); |
| | | if (productOrderDetailList.size() > 0) { |
| | | UserProductDetail userProductDetail=new UserProductDetail(); |
| | | //包含共享的数据 |
| | | userProductDetail.setProductOrderJoinDetailListShare(productOrderDetailList.stream().filter(f -> f.getIsShare()).collect(Collectors.toList())); |
| | | //科室私有的数据 |
| | | userProductDetail.setProductOrderJoinDetailsListDep(productOrderDetailList.stream().filter((f -> departmentId.equals(f.getDepartmentId()) && !f.getIsShare())).collect(Collectors.toList())); |
| | | return userProductDetail; |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 统计用户所有套餐剩余 套餐剩余量=(有效期内的医院所有共享+科室私有的套餐的读片量)-预扣费的读片量 |
| | | * |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody biUserNowProduct(Long hospitalId, Long departmentId) { |
| | | if (hospitalId > 0 && departmentId > 0) { |
| | | UserProductDetail userProductDetail=getUserProductDetail(hospitalId,departmentId); |
| | | int userAICount = 0; |
| | | if (userProductDetail!=null) { |
| | | //包含共享的数据 |
| | | List<ProductOrderJoinDetail> productOrderJoinDetailListShare = userProductDetail.getProductOrderJoinDetailListShare(); |
| | | //科室私有的数据 |
| | | List<ProductOrderJoinDetail> productOrderJoinDetailsListDep = userProductDetail.getProductOrderJoinDetailsListDep(); |
| | | //本医院可共享的读片总量 |
| | | int shareCount = productOrderJoinDetailListShare.stream().collect(Collectors.summingInt(ProductOrderJoinDetail::getAilightCount)); |
| | | //本科室私有读片总量 |
| | | int depCount = productOrderJoinDetailsListDep.stream().collect(Collectors.summingInt(ProductOrderJoinDetail::getAilightCount)); |
| | | //可用的总量 |
| | | userAICount = shareCount + depCount; |
| | | //计算预扣费的总量 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("recordType", ConsumptionConstant.BEFORE_DEDUCTION); |
| | | List<ConsumptionRecord> consumptionRecordList = consumptionRecordMapper.findList(selectMap);; |
| | | if (consumptionRecordList.size() > 0) { |
| | | //共享套餐里面的detailid |
| | | List<Long> shareDetailId = productOrderJoinDetailListShare.stream().map(m -> m.getId()).collect(Collectors.toList()); |
| | | //私有套餐里面的detailid |
| | | List<Long> depDetailId = productOrderJoinDetailsListDep.stream().map(m -> m.getId()).collect(Collectors.toList()); |
| | | //共享套餐里面预扣费总数 |
| | | int shareConCount = consumptionRecordList.stream().filter(f -> shareDetailId.contains(f.getProOrderDetailId())).collect(Collectors.summingInt(ConsumptionRecord::getConsumptionCount)); |
| | | //共享套餐里面预扣费总数 |
| | | int depConCount = consumptionRecordList.stream().filter(f -> depDetailId.contains(f.getProOrderDetailId())).collect(Collectors.summingInt(ConsumptionRecord::getConsumptionCount)); |
| | | userAICount -= (shareConCount + depConCount); |
| | | } |
| | | } |
| | | |
| | | return ResultBody.ok().data(userAICount); |
| | | } else { |
| | | return ResultBody.failed("医院和科室数据有误!"); |
| | | } |
| | | } |
| | | } |