123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package com.imed.costaccount.service.impl;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.imed.costaccount.common.exception.CostException;
- import com.imed.costaccount.common.util.BeanUtil;
- import com.imed.costaccount.common.util.DateUtils;
- import com.imed.costaccount.common.util.PageUtils;
- import com.imed.costaccount.enums.DateStyleEnum;
- import com.imed.costaccount.mapper.CostOtherPaymentsDataMapper;
- import com.imed.costaccount.model.CostOtherPaymentsData;
- import com.imed.costaccount.model.dto.CostOtherPaymentsDataEditDto;
- import com.imed.costaccount.model.dto.CostOtherPaymentsDataSaveDto;
- import com.imed.costaccount.model.vo.CostOtherPaymentsDataVO;
- import com.imed.costaccount.service.CostOtherPaymentsDataService;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.Date;
- import java.util.List;
- import java.util.Objects;
- @Service("costOtherPaymentsDataService")
- public class CostOtherPaymentsDataServiceImpl extends ServiceImpl<CostOtherPaymentsDataMapper, CostOtherPaymentsData> implements CostOtherPaymentsDataService {
- /**
- * 分页查询
- *
- * @param current 第几页
- * @param pageSize 每页大小
- * @param dateTime 时间
- * @param hospId 医院Id
- * @return
- */
- @Override
- public PageUtils queryList(Integer current, Integer pageSize, String dateTime, Long hospId) {
- // 先检验当前年月是否存在数据
- int year = 0;
- int month = 0;
- Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
- if (StrUtil.isNotBlank(dateTime)) {
- year = DateUtil.year(date);
- month = DateUtil.month(date) + 1;
- }
- Page<CostOtherPaymentsData> paymentsDataPage = new Page<>(current, pageSize);
- Page<CostOtherPaymentsData> pages = this.page(paymentsDataPage, new QueryWrapper<CostOtherPaymentsData>().lambda()
- .eq(CostOtherPaymentsData::getHospId, hospId)
- .eq(StrUtil.isNotBlank(dateTime),CostOtherPaymentsData::getDateYear,year)
- .eq(StrUtil.isNotBlank(dateTime),CostOtherPaymentsData::getDateMonth,month)
- .orderByDesc(CostOtherPaymentsData::getCreateTime));
- List<CostOtherPaymentsData> records = pages.getRecords();
- List<CostOtherPaymentsDataVO> costOtherPaymentsDataVOList = BeanUtil.convertList(records, CostOtherPaymentsDataVO.class);
- PageUtils pageUtils = new PageUtils(pages);
- pageUtils.setList(costOtherPaymentsDataVOList);
- return pageUtils;
- }
- /**
- * 保存全院其他收支数据
- *
- * @param costOtherPaymentsDataSaveDto 全院其他收支
- * @param hospId 医院的Id
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void addOtherPaymentData(CostOtherPaymentsDataSaveDto costOtherPaymentsDataSaveDto, Long hospId) {
- String dateTime = costOtherPaymentsDataSaveDto.getDateTime();
- // 先检验当前年月是否存在数据
- checkOtherPaymentData(costOtherPaymentsDataSaveDto, hospId, dateTime);
- CostOtherPaymentsData costOtherPaymentsData = BeanUtil.convertObj(costOtherPaymentsDataSaveDto, CostOtherPaymentsData.class);
- int year = 0;
- int month = 0;
- Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
- if (StrUtil.isNotBlank(dateTime)) {
- year = DateUtil.year(date);
- month = DateUtil.month(date) + 1;
- }
- costOtherPaymentsData.setHospId(hospId);
- costOtherPaymentsData.setCreateTime(System.currentTimeMillis());
- costOtherPaymentsData.setDateYear(year);
- costOtherPaymentsData.setDateMonth(month);
- this.save(costOtherPaymentsData);
- }
- // 先检验当前年月是否存在数据
- private void checkOtherPaymentData(CostOtherPaymentsDataSaveDto costOtherPaymentsDataSaveDto, Long hospId, String dateTime) {
- int year = 0;
- int month = 0;
- Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
- if (StrUtil.isNotBlank(dateTime)) {
- year = DateUtil.year(date);
- month = DateUtil.month(date) + 1;
- }
- Integer paymentsType = costOtherPaymentsDataSaveDto.getPaymentsType();
- String paymentsName = costOtherPaymentsDataSaveDto.getPaymentsName();
- CostOtherPaymentsData paymentsData = this.getOne(new QueryWrapper<CostOtherPaymentsData>().lambda()
- .eq(CostOtherPaymentsData::getHospId, hospId)
- .eq(CostOtherPaymentsData::getDateYear, year).eq(CostOtherPaymentsData::getDateMonth, month)
- .eq(CostOtherPaymentsData::getPaymentsType, paymentsType).eq(CostOtherPaymentsData::getPaymentsName, paymentsName));
- if (Objects.nonNull(paymentsData)){
- throw new CostException(500,"当前年月添加的数据已存在");
- }
- }
- /**
- * 修改全院其他收支数据
- *
- * @param costOtherPaymentsDataEditDto
- * @param hospId
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void updateOtherPaymentData(CostOtherPaymentsDataEditDto costOtherPaymentsDataEditDto, Long hospId) {
- String dateTime = costOtherPaymentsDataEditDto.getDateTime();
- int year = 0;
- int month = 0;
- if (StrUtil.isNotBlank(dateTime)) {
- Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
- year = DateUtil.year(date);
- month = DateUtil.month(date) + 1;
- }
- Long id = costOtherPaymentsDataEditDto.getId();
- CostOtherPaymentsData otherPaymentsData = this.getById(id);
- if (Objects.isNull(otherPaymentsData)){
- throw new CostException(500,"全院其他收支数据不存在");
- }
- this.removeById(id);
- CostOtherPaymentsDataSaveDto costOtherPaymentsDataSaveDto = BeanUtil.convertObj(costOtherPaymentsDataEditDto, CostOtherPaymentsDataSaveDto.class);
- // 检验数据
- checkOtherPaymentData(costOtherPaymentsDataSaveDto,hospId,dateTime);
- // 实现数据添加
- CostOtherPaymentsData costOtherPaymentsData = BeanUtil.convertObj(costOtherPaymentsDataSaveDto, CostOtherPaymentsData.class);
- costOtherPaymentsData.setCreateTime(System.currentTimeMillis());
- costOtherPaymentsData.setHospId(hospId);
- costOtherPaymentsData.setDateYear(year);
- costOtherPaymentsData.setDateMonth(month);
- this.save(costOtherPaymentsData);
- }
- }
|