package com.ruoyi.cwgl.service.impl; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import javax.annotation.Resource; import com.ruoyi.common.utils.RandomUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.cwgl.domain.EstimatedReceivableBill; import com.ruoyi.cwgl.mapper.EstimatedReceivableLogMapper; import com.ruoyi.cwgl.service.IEstimatedReceivableLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.stereotype.Service; import org.springframework.scheduling.annotation.Async; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.annotation.DataSource; import com.ruoyi.common.enums.DataSourceType; import com.ruoyi.common.core.service.BaseService; import com.ruoyi.cwgl.mapper.EstimatedReceivableMapper; import com.ruoyi.cwgl.domain.EstimatedReceivable; import com.ruoyi.cwgl.service.IEstimatedReceivableService; import com.ruoyi.common.core.text.Convert; /** * 预估应收管理Service业务层处理 * * @author ruoyi * @date 2025-08-07 */ @Service @Transactional(rollbackFor = Exception.class) public class EstimatedReceivableServiceImpl extends BaseService implements IEstimatedReceivableService { protected final Logger logger = LoggerFactory.getLogger(getClass()); @Resource private EstimatedReceivableMapper estimatedReceivableMapper; @Autowired private IEstimatedReceivableLogService logService; /** * 查询预估应收管理 * * @param id 预估应收管理ID * @return 预估应收管理 */ @DataSource(DataSourceType.SLAVE) @Override public EstimatedReceivable selectEstimatedReceivableById(Integer id) { return estimatedReceivableMapper.selectEstimatedReceivableById(id); } /** * 查询预估应收管理 记录数 * * @param estimatedReceivable 预估应收管理 * @return 预估应收管理集合 */ @DataSource(DataSourceType.SLAVE) @Override public int selectEstimatedReceivableCount(EstimatedReceivable estimatedReceivable) { return estimatedReceivableMapper.selectEstimatedReceivableCount(estimatedReceivable); } /** * 查询预估应收管理列表 * * @param estimatedReceivable 预估应收管理 * @return 预估应收管理 */ @DataSource(DataSourceType.SLAVE) @Override public List selectEstimatedReceivableList(EstimatedReceivable estimatedReceivable) { return estimatedReceivableMapper.selectEstimatedReceivableList(estimatedReceivable); } /** * 查询预估应收管理列表 异步 导出 * * @param estimatedReceivable 预估应收管理 * @param exportKey 导出功能的唯一标识 * @return 预估应收管理集合 */ @DataSource(DataSourceType.SLAVE) @Async @Override public void export(EstimatedReceivable estimatedReceivable,String exportKey) { super.export(EstimatedReceivable.class,exportKey,"estimatedReceivableData",(pageNum)->{ PageUtils.startPage(pageNum, Constants.EXPORT_PATE_SIZE); return selectEstimatedReceivableList(estimatedReceivable); }); } /** * 新增预估应收管理 * * @param estimatedReceivable 预估应收管理 * @return 结果 */ @Override public int insertEstimatedReceivable(EstimatedReceivable estimatedReceivable) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd"); Date nowDate = DateUtils.getNowDate(); String datePart = dateFormat.format(nowDate); estimatedReceivable.setCreateTime(nowDate); estimatedReceivable.setFeeSystemNo("YF"+datePart+ RandomUtils.random(5)); estimatedReceivable.setFeeType(0); return estimatedReceivableMapper.insertEstimatedReceivable(estimatedReceivable); } /** * 新增预估应收管理[批量] * * @param estimatedReceivables 预估应收管理 * @return 结果 */ @Override public int insertEstimatedReceivableBatch(List estimatedReceivables) { int rows = estimatedReceivableMapper.insertEstimatedReceivableBatch(estimatedReceivables); return rows; } /** * 修改预估应收管理 * * @param estimatedReceivable 预估应收管理 * @return 结果 */ @Override public int updateEstimatedReceivable(EstimatedReceivable estimatedReceivable) { Integer id = estimatedReceivable.getId(); EstimatedReceivable estimatedReceivable1 = estimatedReceivableMapper.selectEstimatedReceivableById(id); if (estimatedReceivable1.getRelatedBillStatus().equals(2)||estimatedReceivable1.getRelatedBillStatus().equals(3)){ throw new ServiceException("结算中或已结算无法修改"); } estimatedReceivable.setUpdateTime(DateUtils.getNowDate()); String username = SecurityUtils.getUsername(); logService.insertEstimatedReceivableLog("修改应收",estimatedReceivable.getId(),username); return estimatedReceivableMapper.updateEstimatedReceivable(estimatedReceivable); } /** * 修改预估应收管理[批量] * * @param estimatedReceivables 预估应收管理 * @return 结果 */ @Override public int updateEstimatedReceivableBatch(List estimatedReceivables){ return estimatedReceivableMapper.updateEstimatedReceivableBatch(estimatedReceivables); } /** * 删除预估应收管理对象 * * @param ids 需要删除的数据ID * @return 结果 */ @Override public int deleteEstimatedReceivableByIds(String ids) { return deleteEstimatedReceivableByIds(Convert.toIntArray(ids)); } /** * 删除预估应收管理对象 * * * @param ids 需要删除的数据ID * @return 结果 */ @Override public int deleteEstimatedReceivableByIds(Integer[] ids) { return estimatedReceivableMapper.deleteEstimatedReceivableByIds(ids); } /** * 删除预估应收管理信息 * * @param id 预估应收管理ID * @return 结果 */ @Override public int deleteEstimatedReceivableById(Integer id) { return estimatedReceivableMapper.deleteEstimatedReceivableById(id); } @Override public int confirm(Integer id) { EstimatedReceivable estimatedReceivable = estimatedReceivableMapper.selectEstimatedReceivableById(id); if (estimatedReceivable==null){ throw new ServiceException("数据不存在"); } if (estimatedReceivable.getIsConfirmed().equals(2)) { throw new ServiceException("该数据已作废"); } if (estimatedReceivable.getIsConfirmed().equals(1)) { throw new ServiceException("无需重复确认"); } String username = SecurityUtils.getUsername(); logService.insertEstimatedReceivableLog("确认应收",id,username); estimatedReceivable.setIsConfirmed(1); estimatedReceivable.setConfirmBy(username); estimatedReceivable.setConfirmTime(new Date()); return estimatedReceivableMapper.updateEstimatedReceivable(estimatedReceivable); } @Override public int cancel(Integer id) { EstimatedReceivable estimatedReceivable = estimatedReceivableMapper.selectEstimatedReceivableById(id); if (estimatedReceivable==null){ throw new ServiceException("数据不存在"); } if (estimatedReceivable.getIsConfirmed().equals(2)) { throw new ServiceException("该数据已作废"); } if (estimatedReceivable.getIsConfirmed().equals(0)) { throw new ServiceException("无需重复取消"); } String username = SecurityUtils.getUsername(); logService.insertEstimatedReceivableLog("取消应收",id,username); estimatedReceivable.setIsConfirmed(0); return estimatedReceivableMapper.updateEstimatedReceivable(estimatedReceivable); } @Override public int invalid(Integer id) { EstimatedReceivable estimatedReceivable = estimatedReceivableMapper.selectEstimatedReceivableById(id); if (estimatedReceivable==null){ throw new ServiceException("数据不存在"); } if (estimatedReceivable.getIsConfirmed().equals(2)) { throw new ServiceException("无需重复作废"); } String username = SecurityUtils.getUsername(); logService.insertEstimatedReceivableLog("作废应收",id,username); estimatedReceivable.setIsConfirmed(2); return estimatedReceivableMapper.updateEstimatedReceivable(estimatedReceivable); } }