| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.entity.CalculateRecord; |
| | | import com.ycl.platform.mapper.CalculateRecordMapper; |
| | | import com.ycl.platform.service.ICalculateRecordService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ycl.platform.service.CalculateRecordService; |
| | | import com.ycl.system.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.form.CalculateRecordForm; |
| | | import com.ycl.platform.domain.vo.CalculateRecordVO; |
| | | import com.ycl.platform.domain.query.CalculateRecordQuery; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.system.page.PageUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import java.util.ArrayList; |
| | | import java.util.stream.Collectors; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | |
| | | /** |
| | | * 核算记录Service业务层处理 |
| | | * |
| | | * @author ruoyi |
| | | * @date 2024-04-03 |
| | | * 核算记录 服务实现类 |
| | | * |
| | | * @author xp |
| | | * @since 2024-04-23 |
| | | */ |
| | | @Service |
| | | public class CalculateRecordServiceImpl extends ServiceImpl<CalculateRecordMapper, CalculateRecord> implements ICalculateRecordService |
| | | { |
| | | @Autowired |
| | | private CalculateRecordMapper calculateRecordMapper; |
| | | @RequiredArgsConstructor |
| | | public class CalculateRecordServiceImpl extends ServiceImpl<CalculateRecordMapper, CalculateRecord> implements CalculateRecordService { |
| | | |
| | | private final CalculateRecordMapper calculateRecordMapper; |
| | | |
| | | /** |
| | | * 查询核算记录 |
| | | * |
| | | * @param id 核算记录主键 |
| | | * @return 核算记录 |
| | | * 添加 |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public CalculateRecord selectCalculateRecordById(Long id) |
| | | { |
| | | return calculateRecordMapper.selectCalculateRecordById(id); |
| | | public Result add(CalculateRecordForm form) { |
| | | CalculateRecord entity = CalculateRecordForm.getEntityByForm(form, null); |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | } |
| | | |
| | | /** |
| | | * 查询核算记录列表 |
| | | * |
| | | * @param calculateRecord 核算记录 |
| | | * @return 核算记录 |
| | | * 修改 |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<CalculateRecord> selectCalculateRecordList(CalculateRecord calculateRecord) |
| | | { |
| | | return calculateRecordMapper.selectCalculateRecordList(calculateRecord); |
| | | public Result update(CalculateRecordForm form) { |
| | | |
| | | CalculateRecord entity = baseMapper.selectById(form.getId()); |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | Date now = new Date(); |
| | | entity.setUpdateTime(now); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | return Result.ok("修改成功"); |
| | | } |
| | | return Result.error("修改失败"); |
| | | } |
| | | |
| | | /** |
| | | * 新增核算记录 |
| | | * |
| | | * @param calculateRecord 核算记录 |
| | | * @return 结果 |
| | | * 批量删除 |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int insertCalculateRecord(CalculateRecord calculateRecord) |
| | | { |
| | | return calculateRecordMapper.insertCalculateRecord(calculateRecord); |
| | | public Result remove(List<String> ids) { |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | | } |
| | | |
| | | /** |
| | | * 修改核算记录 |
| | | * |
| | | * @param calculateRecord 核算记录 |
| | | * @return 结果 |
| | | * id删除 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int updateCalculateRecord(CalculateRecord calculateRecord) |
| | | { |
| | | return calculateRecordMapper.updateCalculateRecord(calculateRecord); |
| | | public Result removeById(String id) { |
| | | if(baseMapper.deleteById(id) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除核算记录 |
| | | * |
| | | * @param ids 需要删除的核算记录主键 |
| | | * @return 结果 |
| | | * 分页查询 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int deleteCalculateRecordByIds(Long[] ids) |
| | | { |
| | | return calculateRecordMapper.deleteCalculateRecordByIds(ids); |
| | | public Result page(CalculateRecordQuery query) { |
| | | |
| | | IPage<CalculateRecord> page = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .orderByDesc(CalculateRecord::getCreateTime) |
| | | .page(PageUtil.getPage(query, CalculateRecord.class)); |
| | | |
| | | List<CalculateRecordVO> vos = page.getRecords().stream() |
| | | .map( |
| | | entity -> CalculateRecordVO.getVoByEntity(entity, null) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | | * 删除核算记录信息 |
| | | * |
| | | * @param id 核算记录主键 |
| | | * @return 结果 |
| | | * 根据id查找 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int deleteCalculateRecordById(Long id) |
| | | { |
| | | return calculateRecordMapper.deleteCalculateRecordById(id); |
| | | public Result detail(String id) { |
| | | |
| | | CalculateRecord entity = baseMapper.selectById(id); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | CalculateRecordVO vo = CalculateRecordVO.getVoByEntity(entity, null); |
| | | return Result.ok().data(vo); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result all() { |
| | | List<CalculateRecord> entities = baseMapper.selectList(null); |
| | | List<CalculateRecordVO> vos = entities.stream() |
| | | .map( |
| | | entity -> CalculateRecordVO.getVoByEntity(entity, null) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | } |