package cn.besteam.modules.medical.service.impl; import cn.besteam.common.constant.DepartmentEnum; import cn.besteam.modules.medical.dto.MwServicePeriodDTO; import cn.besteam.modules.medical.dto.MwServicePeriodEditDTO; import cn.besteam.modules.medical.dto.RenewOrderRequestVO; import cn.besteam.modules.medical.dto.RenewOrderResponseVO; import cn.besteam.modules.medical.entity.MwServicePeriod; import cn.besteam.modules.medical.entity.MwServicePeriodLog; import cn.besteam.modules.medical.mapper.MwServicePeriodMapper; import cn.besteam.modules.medical.service.IMwServicePeriodLogService; import cn.besteam.modules.medical.service.IMwServicePeriodService; import cn.besteam.modules.medical.vo.MwServicePeriodListDTO; import cn.besteam.modules.shiro.authc.util.EnvUtils; import cn.besteam.modules.system.entity.SysDepartment; import cn.besteam.modules.system.entity.SysDictItem; import cn.besteam.modules.system.service.ISysDepartmentService; import cn.besteam.modules.system.service.ISysDictItemService; import cn.besteam.modules.system.util.NouNouPayUtil; import cn.hutool.poi.excel.ExcelWriter; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.collections.CollectionUtils; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * 服务期限 * @author pzb * @Date 2022/7/13 20:01 */ @Service public class MwServicePeriodServiceImpl extends ServiceImpl implements IMwServicePeriodService { @Autowired private ISysDictItemService sysDictItemService; @Autowired private ISysDepartmentService departmentService; @Autowired private IMwServicePeriodLogService servicePeriodLogService; @Autowired private ISysDictItemService dictItemService; @Autowired private NouNouPayUtil nouNouPayUtil; private List getSearchHospitalIdList(Integer hospitalId) { if (hospitalId == null) { return departmentService.listMyHospital(EnvUtils.getUser().getId()).stream().map(SysDepartment::getId).collect(Collectors.toList()); } else { SysDepartment sysDepartment = departmentService.getById(hospitalId); if (sysDepartment == null) { return new ArrayList<>(); } List childrenList = departmentService.list(new QueryWrapper().lambda().likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())); if (CollectionUtils.isEmpty(childrenList)) { return new ArrayList<>(); } return childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()); } } /** * 获取服务期管理列表 * @param dto * @return */ @Override public List getServicePeriodList(MwServicePeriodDTO dto) { return this.baseMapper.getServicePeriodList(dto); } @Override public MwServicePeriodListDTO getServicePeriodInfo(Integer id) { MwServicePeriod one = this.getOne(new QueryWrapper().lambda().eq(MwServicePeriod::getDepartmentId, id) .eq(MwServicePeriod::getStatus, 1).eq(MwServicePeriod::getDelFlag, 0).orderByDesc(MwServicePeriod::getCreateTime)); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); MwServicePeriodListDTO dto = new MwServicePeriodListDTO(); SysDepartment byId = departmentService.getById(one.getDepartmentId()); if(null != one){ dto.setId(id); dto.setExpireDate(sdf.format(byId.getExpireDate())); dto.setReminderDays(byId.getReminderDays()); dto.setServiceCharge(byId.getServiceCharge()); SysDictItem dictItem = sysDictItemService.getById(byId.getServiceUnit()); dto.setServiceUnit(dictItem.getItemText()); dto.setNote(byId.getNote()); } return dto; } @Override public List getServicePeriodHistoryRecord(Integer id) { return this.baseMapper.getServicePeriodHistoryRecord(id); } @Override public void editServicePeriod(MwServicePeriodEditDTO dto, Integer userId) { String[] split = dto.getIds().split(","); for (String s : split) { MwServicePeriod one = this.getOne(new QueryWrapper().lambda().eq(MwServicePeriod::getDepartmentId, s) .eq(MwServicePeriod::getStatus, 1).eq(MwServicePeriod::getDelFlag, 0).orderByDesc(MwServicePeriod::getCreateTime)); if(null != one){ one.setStatus(0); this.baseMapper.updateById(one); } MwServicePeriod mwServicePeriod = new MwServicePeriod(); BeanUtils.copyProperties(dto, mwServicePeriod); mwServicePeriod.setDepartmentId(Integer.valueOf(s)); mwServicePeriod.setPayStatus(1); mwServicePeriod.setStatus(1); mwServicePeriod.setDelFlag(0); mwServicePeriod.setCreateUserId(userId); mwServicePeriod.setCreateTime(new Date()); //支付为0直接修改数据 SysDepartment department = departmentService.getById(s); department.setReminderDays(dto.getReminderDays()); department.setExpireDate(dto.getExpireDate()); department.setServiceCharge(dto.getServiceCharge()); department.setServiceUnit(dto.getServiceUnit()); department.setNote(dto.getNote()); departmentService.updateById(department); //添加操作日志记录 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if(null == one || department.getExpireDate().getTime() != dto.getExpireDate().getTime()){ // MwServicePeriodLog servicePeriodLog = new MwServicePeriodLog(); // servicePeriodLog.setServicePeriodId(mwServicePeriod.getId()); // servicePeriodLog.setServiceType(1); // servicePeriodLog.setHistoricalData(null == one ? "" : sdf.format(department.getExpireDate())); // servicePeriodLog.setCurrentData(sdf.format(department.getExpireDate())); // servicePeriodLog.setCreateTime(new Date()); servicePeriodLogService.saveLog(Integer.valueOf(s),dto.getServiceCharge(),dto.getExpireDate(),dto.getReminderDays(),dto.getServiceUnit(),dto.getNote(),userId,1); }else{ // if(null == one || department.getServiceCharge() != dto.getServiceCharge()){ // MwServicePeriodLog servicePeriodLog = new MwServicePeriodLog(); // servicePeriodLog.setServicePeriodId(mwServicePeriod.getId()); // servicePeriodLog.setServiceType(2); // servicePeriodLog.setHistoricalData(null == one ? "" : department.getServiceCharge().toString()); // servicePeriodLog.setCurrentData(department.getServiceCharge().toString()); // servicePeriodLog.setCreateTime(new Date()); // servicePeriodLogService.saveLog(Integer.valueOf(s),dto.getServiceCharge(),dto.getExpireDate(),dto.getReminderDays(),dto.getServiceUnit(),dto.getNote(),userId,2); } } } @Override public void exportServicePeriodList(MwServicePeriodDTO dto, HttpServletResponse response) throws Exception { ExcelWriter excelWriter = new ExcelWriter(exportServicePeriodList(dto, "服务期管理"), "服务期管理"); if (excelWriter != null) { response.setContentType("application/octet-stream;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("服务期管理", "UTF-8") + ".xlsx"); excelWriter.flush(response.getOutputStream(), true); excelWriter.close(); } } private XSSFWorkbook exportServicePeriodList(MwServicePeriodDTO dto, String fileName){ List servicePeriodList = this.baseMapper.getServicePeriodList(dto); XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(fileName); XSSFCellStyle cellStyle = createDefaultCellStyle(workbook); XSSFRow row = sheet.createRow(0);//表头 XSSFCell cell = row.createCell(0); cell.setCellStyle(cellStyle); cell.setCellValue("服务期管理"); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); XSSFRow row1 = sheet.createRow(0);//表头 XSSFCell cel2 = row1.createCell(0); cel2.setCellStyle(cellStyle); cel2.setCellValue("所属区域"); XSSFCell cel3 = row1.createCell(1); cel3.setCellStyle(cellStyle); cel3.setCellValue("医院名称"); XSSFCell cel4 = row1.createCell(2); cel4.setCellStyle(cellStyle); cel4.setCellValue("到期时间"); XSSFCell cel5 = row1.createCell(3); cel5.setCellStyle(cellStyle); cel5.setCellValue("是否到期"); XSSFCell cel6 = row1.createCell(4); cel6.setCellStyle(cellStyle); cel6.setCellValue("即将到期"); XSSFCell cel7 = row1.createCell(5); cel7.setCellStyle(cellStyle); cel7.setCellValue("即将到期提醒"); XSSFCell cel8 = row1.createCell(6); cel8.setCellStyle(cellStyle); cel8.setCellValue("服务费"); XSSFCell cel9 = row1.createCell(7); cel9.setCellStyle(cellStyle); cel9.setCellValue("服务单位"); for (int i = 0; i < servicePeriodList.size(); i++) { MwServicePeriodListDTO mwServicePeriodListDTO = servicePeriodList.get(i); XSSFRow row21 = sheet.createRow(i);//表头 row21.setRowStyle(cellStyle); XSSFCell cel21 = row21.createCell(0); cel21.setCellValue(mwServicePeriodListDTO.getDepartment()); XSSFCell cel22 = row21.createCell(1); cel22.setCellValue(mwServicePeriodListDTO.getHospital()); XSSFCell cel23 = row21.createCell(2); cel23.setCellValue(null == mwServicePeriodListDTO.getExpireDate() ? "" : mwServicePeriodListDTO.getExpireDate()); XSSFCell cel24 = row21.createCell(3); cel24.setCellValue(mwServicePeriodListDTO.getIsExpire() == 1 ? "是" : "否"); XSSFCell cel25 = row21.createCell(4); cel25.setCellValue(mwServicePeriodListDTO.getAboutToExpire() == 1 ? "是" : "否"); XSSFCell cel26 = row21.createCell(5); cel26.setCellValue(null == mwServicePeriodListDTO.getReminderDays() ? "" : mwServicePeriodListDTO.getReminderDays().toString()); XSSFCell cel27 = row21.createCell(6); cel27.setCellValue(null == mwServicePeriodListDTO.getServiceCharge() ? "" : mwServicePeriodListDTO.getServiceCharge().toString()); XSSFCell cel28 = row21.createCell(7); cel28.setCellValue(mwServicePeriodListDTO.getServiceUnit()); } return workbook; } private XSSFCellStyle createDefaultCellStyle(XSSFWorkbook workbook) { XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); cellStyle.setAlignment(HorizontalAlignment.CENTER); XSSFFont font = workbook.createFont(); font.setFontName("宋体"); font.setFontHeightInPoints((short) 12); cellStyle.setFont(font); return cellStyle; } @Override public IPage getRenewOrderList(RenewOrderRequestVO vo, Integer pageNo, Integer pageSize) { pageNo = vo.getPageNo(); pageSize = vo.getPageSize(); vo.setHospitalIdList(getSearchHospitalIdList(vo.getDepartmentId())); Page pageParam = new Page<>(pageNo, pageSize); IPage renewOrderList = this.baseMapper.getRenewOrderList(pageParam, vo); return renewOrderList; } @Override public RenewOrderResponseVO getRenewOrderOne(Integer id) { return this.baseMapper.getRenewOrderOne(id); } @Override public void exportRenewOrder(RenewOrderRequestVO vo, HttpServletResponse response) throws Exception { ExcelWriter excelWriter = new ExcelWriter(exportRenewOrder(vo, "续费订单"), "续费订单"); if (excelWriter != null) { response.setContentType("application/octet-stream;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("续费订单", "UTF-8") + ".xlsx"); excelWriter.flush(response.getOutputStream(), true); excelWriter.close(); } } private XSSFWorkbook exportRenewOrder(RenewOrderRequestVO vo, String fileName){ Page pageParam = new Page<>(0, 100000000); IPage renewOrderList = this.baseMapper.getRenewOrderList(pageParam, vo); List records = renewOrderList.getRecords(); XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(fileName); XSSFCellStyle cellStyle = createDefaultCellStyle(workbook); XSSFRow row = sheet.createRow(0);//表头 XSSFCell cell = row.createCell(0); cell.setCellStyle(cellStyle); cell.setCellValue("续费订单"); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10)); XSSFRow row1 = sheet.createRow(1);//表头 XSSFCell cel2 = row1.createCell(0); cel2.setCellStyle(cellStyle); cel2.setCellValue("所属区域"); XSSFCell cel3 = row1.createCell(1); cel3.setCellStyle(cellStyle); cel3.setCellValue("医院名称"); XSSFCell cel4 = row1.createCell(2); cel4.setCellStyle(cellStyle); cel4.setCellValue("订单编号"); XSSFCell cel5 = row1.createCell(3); cel5.setCellStyle(cellStyle); cel5.setCellValue("订单时间"); XSSFCell cel6 = row1.createCell(4); cel6.setCellStyle(cellStyle); cel6.setCellValue("订单状态"); XSSFCell cel7 = row1.createCell(5); cel7.setCellStyle(cellStyle); cel7.setCellValue("订单金额"); XSSFCell cel8 = row1.createCell(6); cel8.setCellStyle(cellStyle); cel8.setCellValue("支付时间"); XSSFCell cel9 = row1.createCell(7); cel9.setCellStyle(cellStyle); cel9.setCellValue("支付方式"); XSSFCell cel10 = row1.createCell(8); cel10.setCellStyle(cellStyle); cel10.setCellValue("支付金额"); XSSFCell cel11 = row1.createCell(9); cel11.setCellStyle(cellStyle); cel11.setCellValue("微信/支付宝订单号"); XSSFCell cel12 = row1.createCell(10); cel12.setCellStyle(cellStyle); cel12.setCellValue("开票状态"); for (int i = 2; i < records.size(); i++) { RenewOrderResponseVO renewOrderResponseVO = records.get(i); XSSFRow row21 = sheet.createRow(i);//表头 row21.setRowStyle(cellStyle); XSSFCell cel21 = row21.createCell(0); cel21.setCellValue(renewOrderResponseVO.getDepartmentName()); XSSFCell cel22 = row21.createCell(1); cel22.setCellValue(renewOrderResponseVO.getHospitalName()); XSSFCell cel23 = row21.createCell(2); cel23.setCellValue(renewOrderResponseVO.getCode()); XSSFCell cel24 = row21.createCell(3); cel24.setCellValue(renewOrderResponseVO.getOrderTime()); XSSFCell cel25 = row21.createCell(4); switch (renewOrderResponseVO.getPayStatus()){ case 0: cel25.setCellValue("待支付"); break; case 1: cel25.setCellValue("已支付"); break; case 2: cel25.setCellValue("支付失败"); break; case 3: cel25.setCellValue("关闭"); break; case 4: cel25.setCellValue("退款中"); break; case 5: cel25.setCellValue("退款成功"); break; case 6: cel25.setCellValue("退款失败"); break; } XSSFCell cel26 = row21.createCell(5); cel26.setCellValue(renewOrderResponseVO.getServiceCharge()); XSSFCell cel27 = row21.createCell(6); cel27.setCellValue(renewOrderResponseVO.getPayTime()); XSSFCell cel28 = row21.createCell(7); cel28.setCellValue(renewOrderResponseVO.getPayType()==null?"":renewOrderResponseVO.getPayType() == 1 ? "微信" : "支付宝"); XSSFCell cel29 = row21.createCell(8); cel29.setCellValue(renewOrderResponseVO.getPayMoney()==null?0:renewOrderResponseVO.getPayMoney()); XSSFCell cel30 = row21.createCell(9); cel30.setCellValue(renewOrderResponseVO.getOrderNumber()); XSSFCell cel31 = row21.createCell(10); if(renewOrderResponseVO.getIsInvoiced()!=null){ switch (renewOrderResponseVO.getIsInvoiced()){ case 0: cel31.setCellValue("未开票"); break; case 1: cel31.setCellValue("已开票"); break; case 2: cel31.setCellValue("开票失败"); break; case 3: cel31.setCellValue("正在开票"); break; } }else{ cel31.setCellValue(""); } } return workbook; } @Override public String getBillingAddress(Integer id) { MwServicePeriod servicePeriod = this.getById(id); SysDepartment department = departmentService.getById(servicePeriod.getDepartmentId()); SysDictItem dictItem = dictItemService.getById(department.getBillingCompany()); String invoiceLinks = nouNouPayUtil.getInvoiceLinks("", servicePeriod.getCode(), dictItem.getItemValue()); return invoiceLinks; } }