package com.ruoyi.basicData.service.impl; import com.ruoyi.basicData.domain.TFees; import com.ruoyi.basicData.domain.TGoods; import com.ruoyi.basicData.mapper.TFeesMapper; import com.ruoyi.basicData.service.ITFeesService; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees; import com.ruoyi.warehouseBusiness.domain.TWarehousebillsitems; import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.util.*; /** * 费用信息Service业务层处理 * * @author ruoyi * @date 2020-12-11 */ @Service public class TFeesServiceImpl implements ITFeesService { @Autowired private TFeesMapper tFeesMapper; @Autowired private TWarehousebillsfeesMapper tWarehousebillsfeesMapper; /** * 查询费用信息 * * @param fId 费用信息ID * @return 费用信息 */ @Override public TFees selectTFeesById(Long fId) { return tFeesMapper.selectTFeesById(fId); } /** * 查询费用信息列表 * * @param tFees 费用信息 * @return 费用信息 */ @Override public List selectTFeesList(TFees tFees) { return tFeesMapper.selectTFeesList(tFees); } /** * 新增费用信息 * * @param tFees 费用信息 * @return 结果 */ @Override public int insertTFees(TFees tFees) { tFees.setCreateTime(DateUtils.getNowDate()); return tFeesMapper.insertTFees(tFees); } /** * 修改费用信息 * * @param tFees 费用信息 * @return 结果 */ @Override @Transactional public AjaxResult updateTFees(TFees tFees) { /* String modify = tFeesMapper.selectTFeesModify(tFees); if ("F".equals(modify)) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return AjaxResult.error("该费用不允许修改数据"); }*/ tFees.setUpdateTime(DateUtils.getNowDate()); tFeesMapper.updateTFees(tFees); return AjaxResult.success(); } /** * 批量删除费用信息 * * @param fIds 需要删除的费用信息ID * @return 结果 */ @Override @Transactional public AjaxResult deleteTFeesByIds(Long[] fIds) { // return tFeesMapper.deleteTFeesByIds(fIds); int i = 1; for(Long id:fIds){ TFees tFees = new TFees(); tFees.setfId(id); String modify = tFeesMapper.selectTFeesModify(tFees); if ("F".equals(modify)) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return AjaxResult.error("费用第" + i + "行为不允许修改数据"); } TWarehousebillsfees tWarehousebillsfees =new TWarehousebillsfees(); tWarehousebillsfees.setfFeeid(id); List TWarehousebillsfeesList =tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(tWarehousebillsfees); if(TWarehousebillsfeesList!=null && !TWarehousebillsfeesList.isEmpty()){ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return AjaxResult.error("费用第" + i + "行不可删除"); } tFeesMapper.deleteTFeesById(id); i++; } return AjaxResult.success(); } /** * 删除费用信息信息 * * @param fId 费用信息ID * @return 结果 */ @Override public int deleteTFeesById(Long fId) { return tFeesMapper.deleteTFeesById(fId); } @Override public String checkUFNoUnique(TFees tFees) { TFees tFees1= tFeesMapper.checkFNoUnique(tFees.getfNo()); if (StringUtils.isNotNull(tFees1) && tFees1.getfId()!=tFees.getfId()) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; } @Override public String checkUFNnameUnique(TFees tFees) { TFees tFees1 = tFeesMapper.checkUFNnameUnique(tFees.getfName()); if (StringUtils.isNotNull(tFees1) && tFees1.getfId()!=tFees.getfId()) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; } /** * 获取费用统计 * * @param tFees 费用信息 * @return 费用统计 */ @Override public Map getFeeStatistics(TFees tFees) { List dimensions = Arrays.asList("product", "应收", "已收", "利润"); List> source = new ArrayList<>(); for (int i = -5; i <= 0; i++) { tFees.getParams().put("beginDate", DateUtils.beginOfOffsetMonth(i) + " 00:00:00"); tFees.getParams().put("endDate", DateUtils.endOfOffsetMonth(i) + " 23:59:59"); Map feeMap = tFeesMapper.getFeeStatistics(tFees); Map temp = new HashMap<>(); temp.put("product", DateUtils.offsetFormatMonth(i, "yyyy-MM")); temp.put("应收", feeMap.get("receivable")); temp.put("已收", feeMap.get("received")); temp.put("利润", feeMap.get("profit")); source.add(temp); } return new HashMap() {{ this.put("dimensions", dimensions); this.put("source", source); }}; } /** * 获取费用统计 * * @param tFees 费用信息 * @return 费用统计 */ @Override public Map getArrearsStatistics(TFees tFees) { List key = new ArrayList<>(); List value = new ArrayList<>(); List> statisticsList = tFeesMapper.getArrearsStatistics(tFees); for (Map statisticsMap : statisticsList) { String name = statisticsMap.get("name"); key.add(name.length() > 6 ? name.substring(0,6) : name); value.add(statisticsMap.get("receivable")); } return new HashMap() {{ this.put("key", key); this.put("value", value); }}; } }