123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package com.kcim.service.impl;
- 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.kcim.common.constants.NumberConstant;
- import com.kcim.common.exception.CostException;
- import com.kcim.common.util.BeanUtil;
- import com.kcim.common.util.PageUtils;
- import com.kcim.common.util.UserContext;
- import com.kcim.dao.mapper.CostOtherPaymentsMapper;
- import com.kcim.dao.model.CostOtherPayments;
- import com.kcim.dao.model.dto.CostOtherPaymentsEditDto;
- import com.kcim.vo.CostOtherPaymentsSaveDto;
- import com.kcim.vo.CostOtherPaymentsVO;
- import com.kcim.service.CostOtherPaymentsService;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.List;
- import java.util.Objects;
- @Service("costOtherPaymentsService")
- public class CostOtherPaymentsServiceImpl extends ServiceImpl<CostOtherPaymentsMapper, CostOtherPayments> implements CostOtherPaymentsService {
- /**
- * 分压查询全院其他收支设置
- *
- * @param current
- * @param pageSize
- * @param name
- * @param hospId
- * @return
- */
- @Override
- public PageUtils queryList(Integer current, Integer pageSize, String name, Long hospId) {
- Page<CostOtherPayments> costOtherPaymentsPage = new Page<>(current, pageSize);
- Page<CostOtherPayments> pages = this.page(costOtherPaymentsPage, new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId));
- List<CostOtherPayments> records = pages.getRecords();
- List<CostOtherPaymentsVO> costOtherPaymentsVOList = BeanUtil.convertList(records, CostOtherPaymentsVO.class);
- PageUtils pageUtils = new PageUtils(pages);
- for (CostOtherPaymentsVO vo : costOtherPaymentsVOList) {
- if(vo.getPaymentsType().equals(NumberConstant.ONE)){
- vo.setPaymentsTypeName("收入");
- } else if (vo.getPaymentsType().equals(NumberConstant.TWO)) {
- vo.setPaymentsTypeName("支出");
- }else {
- vo.setPaymentsTypeName("未知");
- }
- }
- pageUtils.setList(costOtherPaymentsVOList);
- return pageUtils;
- }
- /**
- * 根据Id获取对应的数据
- *
- * @param id
- * @return
- */
- @Override
- public CostOtherPaymentsVO getByParamsId(Long id) {
- CostOtherPayments costOtherPayments = this.getById(id);
- if (Objects.isNull(costOtherPayments)){
- return null;
- }
- CostOtherPaymentsVO costOtherPaymentsVO = BeanUtil.convertObj(costOtherPayments, CostOtherPaymentsVO.class);
- return costOtherPaymentsVO;
- }
- /**
- * @param costOtherPaymentsSaveDto
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void addOtherPayment(CostOtherPaymentsSaveDto costOtherPaymentsSaveDto) {
- Long hospId = UserContext.getHospId();
- CostOtherPayments otherPayments = this.getOne(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId)
- .eq(CostOtherPayments::getPaymentsName,costOtherPaymentsSaveDto.getPaymentsName())
- .eq(CostOtherPayments::getPaymentsType,costOtherPaymentsSaveDto.getPaymentsType()));
- if (Objects.nonNull(otherPayments)){
- throw new CostException(500,"数据已存在");
- }
- CostOtherPayments costOtherPayments = BeanUtil.convertObj(costOtherPaymentsSaveDto, CostOtherPayments.class);
- costOtherPayments.setHospId(hospId);
- costOtherPayments.setCreateTime(System.currentTimeMillis());
- this.save(costOtherPayments);
- }
- /**
- * 修改全院其他收支设置
- *
- * @param costOtherPaymentsEditDto
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void updateOtherPaymentById(CostOtherPaymentsEditDto costOtherPaymentsEditDto) {
- Long hospId = UserContext.getHospId();
- Long id = costOtherPaymentsEditDto.getId();
- CostOtherPayments otherPayments = this.getOne(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId)
- .eq(CostOtherPayments::getId,id));
- if (Objects.isNull(otherPayments)){
- throw new CostException(500,"原始数据不存在");
- }
- this.removeById(id);
- CostOtherPayments otherPaymentResponse = this.getOne(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId)
- .eq(CostOtherPayments::getPaymentsName,costOtherPaymentsEditDto.getPaymentsName())
- .eq(CostOtherPayments::getPaymentsType,costOtherPaymentsEditDto.getPaymentsType()));
- if (Objects.nonNull(otherPaymentResponse)){
- throw new CostException(500,"修改后的数据已存在");
- }
- CostOtherPayments costOtherPayments = BeanUtil.convertObj(costOtherPaymentsEditDto, CostOtherPayments.class);
- costOtherPayments.setCreateTime(System.currentTimeMillis());
- costOtherPayments.setId(null);
- costOtherPayments.setHospId(hospId);
- this.save(costOtherPayments);
- }
- /**
- * 查询全院收支设置数据
- *
- * @param hospId
- * @return
- */
- @Override
- public List<CostOtherPaymentsVO> getAll(Long hospId) {
- List<CostOtherPayments> costOtherPaymentsList = this.list(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId));
- return BeanUtil.convertList(costOtherPaymentsList, CostOtherPaymentsVO.class);
- }
- /**
- * 删除全院其他收支设置数据
- *
- * @param idList 收支设置的Id集合
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void deleteByIds(List<Long> idList) {
- this.removeByIds(idList);
- }
- }
|