package com.ruoyi.finance.service.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.basicData.domain.TCorps; import com.ruoyi.basicData.domain.TFees; import com.ruoyi.basicData.mapper.TCorpsMapper; import com.ruoyi.basicData.mapper.TFeesMapper; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.finance.domain.TFee; import com.ruoyi.finance.domain.TFeeDo; import com.ruoyi.finance.domain.TWareHouseFees; import com.ruoyi.finance.mapper.TFeeDoMapper; import com.ruoyi.finance.mapper.TFeeMapper; import com.ruoyi.finance.service.ITFeeService; import com.ruoyi.warehouseBusiness.domain.*; import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper; import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper; import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper; import com.ruoyi.warehouseBusiness.service.impl.BillnoSerialServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.*; /** * 财务数据主Service业务层处理 * * @author ruoyi * @date 2021-01-18 */ @Service public class TFeeServiceImpl implements ITFeeService { @Autowired private TFeeMapper tFeeMapper; @Autowired private TFeeDoMapper tFeeDoMapper; @Autowired private BillnoSerialServiceImpl billnoSerialServiceImpl; @Autowired private BillnoDelMapper billnoDelMapper; @Autowired private TCorpsMapper tCorpsMapper; @Autowired private TFeesMapper tFeesMapper; @Autowired private TWarehouseBillsMapper tWarehouseBillsMapper; @Autowired private TWarehousebillsfeesMapper tWarehousebillsfeesMapper; /** * 查询财务数据主 * * @param fId 财务数据主ID * @return 财务数据主 */ @Override public Map selectTFeeById(Long fId) { Map map = new HashMap<>(); // 客户表 List corpsId = new ArrayList<>(); // 费用 List feesId = new ArrayList<>(); TFee tFee=tFeeMapper.selectTFeeById(fId); if (StringUtils.isNotNull(tFee.getfCorpid())) { corpsId.add(tFee.getfCorpid()); } corpsId.add(tFee.getfCorpid()); // 查询从表数据 TFeeDo tFeeDo = new TFeeDo(); tFeeDo.setfPid(fId); List tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo); List> feeDoList=new ArrayList<>(); if (StringUtils.isNotEmpty(tFeeDoList)) { for (TFeeDo fees : tFeeDoList) { Map map1 = new HashMap<>(); feesId.add(fees.getfFeeid()); // 查询主表 TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fees.getfSrcpid()); // 费用名称 TFees tFees= tFeesMapper.selectTFeesById(fees.getfFeeid()); map1.put("fId",fees.getfId()); map1.put("fSrcid",fees.getfSrcid()); map1.put("fSrcpid",fees.getfSrcpid()); map1.put("fMblno",tWarehousebills.getfMblno()); map1.put("fBscorpno",tWarehousebills.getfBscorpno()); map1.put("fProductName",tWarehousebills.getfProductName()); map1.put("fBsdate",tWarehousebills.getfBsdate()); map1.put("fFeeid",fees.getfFeeid()); map1.put("fFeeName",tFees.getfName()); map1.put("fSrcdc",fees.getfSrcdc()); map1.put("fAmt",fees.getfAmt()); if(tWarehousebills.getfBilltype().equals("SJRK")){ map1.put("fBilltype","入库"); } else if(tWarehousebills.getfBilltype().equals("SJCK")){ map1.put("fBilltype","出库"); } else if(tWarehousebills.getfBilltype().equals("CKDB")){ map1.put("fBilltype","调拨"); } else if(tWarehousebills.getfBilltype().equals("HQZY")){ map1.put("fBilltype","货权转移"); } feeDoList.add(map1); } } List corpsList = new ArrayList<>(); List corpsIdList = StringUtils.integerDeduplication(corpsId); for (Long corpId : corpsIdList) { TCorps corps = tCorpsMapper.selectTCorpsById(corpId); if (StringUtils.isNotNull(corps)) { corpsList.add(corps); } } List feesList = new ArrayList<>(); List longList = StringUtils.integerDeduplication(feesId); for (Long fees : longList) { TFees tFees = tFeesMapper.selectTFeesById(fees); if (StringUtils.isNotNull(tFees)) { feesList.add(tFees); } } map.put("tFee",tFee); map.put("corps",corpsList); map.put("feesList", feesList); map.put("feeDoList",feeDoList); return map; } /** * 查询财务数据主列表 * * @param tFee 财务数据主 * @return 财务数据主 */ @Override public List selectTFeeList(TFee tFee) { return tFeeMapper.selectTFeeList(tFee); } @Override public List> selectTFeeList1(TFee tFee) { return tFeeMapper.selectTFeeList1(tFee); } /** * 新增财务数据主 * * @param tFee 财务数据主 * @return 结果 */ @Override public int insertTFee(TFee tFee) { tFee.setCreateTime(DateUtils.getNowDate()); return tFeeMapper.insertTFee(tFee); } /** * 新增对账 、收费、 * @param tfee * @param tfeeDo * @param loginUser * @param fBilltype * @return */ @Override public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) { Long fPid = null; TFee tFee = JSONArray.parseObject(tfee, TFee.class); if (StringUtils.isNull(tFee.getfId())) { // 如果是新数据 tFee.setCreateBy(loginUser.getUser().getUserName()); tFee.setfBilltype(fBilltype); // 业务编码 Date time = new Date(); String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time); tFee.setfBillno(billNo); tFeeMapper.insertTFee(tFee); fPid = tFee.getfId(); } else { fPid = tFee.getfId(); tFee.setUpdateBy(loginUser.getUser().getUserName()); tFee.setUpdateTime(new Date()); tFeeMapper.updateTFee(tFee); // 删除从表 tFeeDoMapper.deleteByFPid(fPid); } // 财务从表 if (StringUtils.isNotNull(tfeeDo)) { JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo); List tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class); for (TFeeDo tFeeDo : tFeeDoList) { tFeeDo.setfPid(fPid); tFeeDo.setCreateBy(loginUser.getUser().getUserName()); tFeeDo.setCreateTime(new Date()); tFeeDoMapper.insertTFeeDo(tFeeDo); } } return AjaxResult.success(); } /** * 修改财务数据主 * * @param tFee 财务数据主 * @return 结果 */ @Override public int updateTFee(TFee tFee) { tFee.setUpdateTime(DateUtils.getNowDate()); return tFeeMapper.updateTFee(tFee); } /** * 批量删除财务数据主 * * @param fIds 需要删除的财务数据主ID * @return 结果 */ @Override public int deleteTFeeByIds(Long[] fIds) { // 取出业务编号、 放入 billno_del for (Long id : fIds) { // 1、查询主表信息 TFee tFee = tFeeMapper.selectTFeeById(id); // 2、业务编号、客存编号 放入 billno_del BillnoDel billnoDel = new BillnoDel(); billnoDel.setBillType(tFee.getfBilltype()); billnoDel.setBillNo(tFee.getfBillno()); billnoDelMapper.insertBillnoDel(billnoDel); } return tFeeMapper.deleteTFeeByIds(fIds); } /** * 删除财务数据主信息 * * @param fId 财务数据主ID * @return 结果 */ @Override public int deleteTFeeById(Long fId) { return tFeeMapper.deleteTFeeById(fId); } @Override public List> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) { List> maps =new ArrayList>(); Map map = new HashMap<>(); map.put("tWareHouseFees", tWareHouseFees); List> mapList = tFeeMapper.warehouseBillsFeesList(map); if (mapList != null && mapList.size() > 0) { String fAmtdr = null; // 金额 String fAmt = null; // 结算 for (Map m : mapList) { for (String k : m.keySet()) { if (k.equals("fAmtdr")) { fAmtdr = m.get(k).toString(); } if (k.equals("fAmt")) { fAmt = m.get(k).toString(); } } BigDecimal result = calculation1(fAmtdr, fAmt); m.put("fAmtdr",result); m.put("fAmt",result); maps.add(m); } } return maps; } public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) { BigDecimal num1 = new BigDecimal(fTotalgross); BigDecimal num2 = new BigDecimal(fGrossweightblc); BigDecimal result = num1.subtract(num2); return result.setScale(2, BigDecimal.ROUND_HALF_UP); } @Override public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) { // 更新 主表、从表 TFee tFee = JSONArray.parseObject(tfee, TFee.class); tFee.setUpdateBy(loginUser.getUser().getUserName()); tFee.setUpdateTime(new Date()); tFeeMapper.updateTFee(tFee); // 删除从表 tFeeDoMapper.deleteByFPid(tFee.getfId()); // 财务从表 if (StringUtils.isNotNull(tfeeDo)) { JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo); List tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class); for (TFeeDo tFeeDo : tFeeDoList) { tFeeDo.setfPid(tFee.getfId()); tFeeDo.setCreateBy(loginUser.getUser().getUserName()); tFeeDo.setCreateTime(new Date()); tFeeDoMapper.insertTFeeDo(tFeeDo); } } // 更新费用明细 updateBillsFees(tFee.getfId(),fBilltype); // 审批流程 return null; } public void updateBillsFees(Long fid,String billsType){ // 查询从表数据 TFee tFee=tFeeMapper.selectTFeeById(fid); TFeeDo tFeeDo = new TFeeDo(); tFeeDo.setfPid(fid); List tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo); // 更新费用明细 for (TFeeDo tFeeDo1 : tFeeDoList ){ // 查询仓库费用明细表数据 TWarehousebillsfees tWarehousebillsfees=new TWarehousebillsfees(); tWarehousebillsfees.setfId(tFeeDo1.getfSrcid()); if(billsType.equals("DZ")){ tWarehousebillsfees.setfStatementNo(tFee.getfBillno()); tWarehousebillsfees.setfAccamountDate(tFee.getfAccbilldate()); } else { tWarehousebillsfees.setfStlamountNo(tFee.getfBillno()); // tWarehousebillsfees.setfStlamount(); tWarehousebillsfees.setfStlamountDate(tFee.getfAccbilldate()); } } } }