123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- package com.ruoyi.warehouseBusiness.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- 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.warehouseBusiness.domain.BillnoDel;
- import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreement;
- import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreementitems;
- import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
- import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
- import com.ruoyi.warehouseBusiness.mapper.TWarehouseAgreementMapper;
- import com.ruoyi.warehouseBusiness.mapper.TWarehouseAgreementitemsMapper;
- import com.ruoyi.warehouseBusiness.service.ITWarehouseAgreementService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- /**
- * 仓储费Service业务层处理
- *
- * @author ruoyi
- * @date 2020-12-11
- */
- @Service
- public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementService {
- @Autowired
- private TWarehouseAgreementMapper tWarehouseAgreementMapper;
- @Autowired
- private TWarehouseAgreementitemsMapper tWarehouseAgreementitemsMapper;
- @Autowired
- private BillnoSerialServiceImpl billnoSerialServiceImpl;
- @Autowired
- private BillnoDelMapper billnoDelMapper;
- /**
- * 查询仓储费
- *
- * @param fId 仓储费ID
- * @return 仓储费
- */
- @Override
- public TWarehouseAgreement selectTWarehouseAgreementById(Long fId) {
- return tWarehouseAgreementMapper.selectTWarehouseAgreementById(fId);
- }
- /**
- * 查询仓储费列表
- *
- * @param tWarehouseAgreement 仓储费
- * @return 仓储费
- */
- @Override
- public List<Map<String, Object>> selectTWarehouseAgreementList1(TWarehouseAgreement tWarehouseAgreement) {
- return tWarehouseAgreementMapper.selectTWarehouseAgreementList1(tWarehouseAgreement);
- }
- /**
- * 查询仓储费列表
- *
- * @param tWarehouseAgreement 仓储费
- * @return 仓储费
- */
- @Override
- public List<TWarehouseAgreement> selectTWarehouseAgreementList(TWarehouseAgreement tWarehouseAgreement) {
- return tWarehouseAgreementMapper.selectTWarehouseAgreementList(tWarehouseAgreement);
- }
- /**
- * 新增
- * @param agreement
- * @param agreementitems
- * @param loginUser
- * @return
- */
- @Override
- public AjaxResult insertTWarehouseAgreement(String agreement, String agreementitems, LoginUser loginUser) {
- Long fPid = null;
- TWarehouseAgreement tWarehouseAgreement = JSONArray.parseObject(agreement, TWarehouseAgreement.class);
- if(StringUtils.isNull(tWarehouseAgreement.getfId())){
- // 如果是新数据
- tWarehouseAgreement.setCreateBy(loginUser.getUser().getUserName());
- // 业务编码
- String billNo = billnoSerialServiceImpl.getBillNo("WA", new Date());
- tWarehouseAgreement.setfBillno(billNo);
- tWarehouseAgreementMapper.insertTWarehouseAgreement(tWarehouseAgreement);
- fPid = tWarehouseAgreement.getfId();
- }else{
- fPid = tWarehouseAgreement.getfId();
- tWarehouseAgreement.setUpdateBy(loginUser.getUser().getUserName());
- tWarehouseAgreement.setUpdateTime(new Date());
- tWarehouseAgreementMapper.updateTWarehouseAgreement(tWarehouseAgreement);
- tWarehouseAgreementitemsMapper.deleteByFPid(fPid);
- }
- // 从表添加
- if (StringUtils.isNotNull(agreementitems)) {
- JSONArray jsonDrArray = JSONArray.parseArray(agreementitems);
- List<TWarehouseAgreementitems> tWarehouseAgreementitemsList = JSONObject.parseArray(jsonDrArray.toJSONString(), TWarehouseAgreementitems.class);
- for (TWarehouseAgreementitems tWarehouseAgreementitems : tWarehouseAgreementitemsList) {
- tWarehouseAgreementitems.setfPid(fPid);
- tWarehouseAgreementitems.setCreateBy(loginUser.getUser().getUserName());
- tWarehouseAgreementitems.setCreateTime(new Date());
- tWarehouseAgreementitemsMapper.insertTWarehouseAgreementitems(tWarehouseAgreementitems);
- }
- }
- return AjaxResult.success();
- }
- /**
- * 修改仓储费
- *
- * @param tWarehouseAgreement 仓储费
- * @return 结果
- */
- @Override
- public int updateTWarehouseAgreement(TWarehouseAgreement tWarehouseAgreement) {
- tWarehouseAgreement.setUpdateTime(DateUtils.getNowDate());
- return tWarehouseAgreementMapper.updateTWarehouseAgreement(tWarehouseAgreement);
- }
- /**
- * 批量删除仓储费
- *
- * @param fIds 需要删除的仓储费ID
- * @return 结果
- */
- @Override
- public int deleteTWarehouseAgreementByIds(Long[] fIds) {
- // 取出业务编号、 放入 billno_del
- for(Long id:fIds){
- // 1、查询主表信息
- TWarehouseAgreement tWarehouseAgreement = tWarehouseAgreementMapper.selectTWarehouseAgreementById(id);
- // 2、业务编号、客存编号 放入 billno_del
- BillnoDel billnoDel =new BillnoDel();
- billnoDel.setBillType("WA");
- billnoDel.setBillNo(tWarehouseAgreement.getfBillno());
- billnoDelMapper.insertBillnoDel(billnoDel);
- }
- return tWarehouseAgreementMapper.deleteTWarehouseAgreementByIds(fIds);
- }
- /**
- * 删除仓储费信息
- *
- * @param fId 仓储费ID
- * @return 结果
- */
- @Override
- public int deleteTWarehouseAgreementById(Long fId) {
- return tWarehouseAgreementMapper.deleteTWarehouseAgreementById(fId);
- }
- /**
- * 计算存储费用
- * @author shanxin
- * @param fCorpid 出库客户Id
- * @param fGoodsid 物资类型Id
- * @param days 时长天数
- * @param feeUnitid 计价单位
- * @param itemNums 数量
- * @return
- */
- public BigDecimal getCarryingCost(Long fCorpid,
- Long fGoodsid,
- Long days,
- Long feeUnitid,
- Long itemNums) {
- if (null == fCorpid ||
- null == fGoodsid ||
- null == days ||
- null == feeUnitid ||
- null == itemNums) {
- return null;
- }
- List<TWarehouseAgreementitems> itemList =
- this.tWarehouseAgreementitemsMapper.getItemsBytWarehouseAgreementMsg(fCorpid,fGoodsid,feeUnitid);
- if (CollUtil.isEmpty(itemList)) {
- return null;
- }
- BigDecimal money = new BigDecimal(0);
- Long dayLength = 0L;
- for (TWarehouseAgreementitems tWarehouseAgreementitems : itemList) {
- if (days < 1) break;
- dayLength = tWarehouseAgreementitems.getfEndays() - tWarehouseAgreementitems.getfFromdays() + 1L;
- if (days >= dayLength) {
- money = money.add(this.getCalculate(itemNums,tWarehouseAgreementitems.getfPrice(),dayLength));
- days -= dayLength;
- } else {
- money = money.add(this.getCalculate(itemNums,feeUnitid,days));
- }
- }
- return money;
- }
- /**
- * 数量 * 单价 * 天数
- * @param itemNums 数量
- * @param unitPrice 单价
- * @param dateLength 天数
- * @return
- */
- public BigDecimal getCalculate (Long itemNums,Long unitPrice,Long dateLength) {
- BigDecimal money = new BigDecimal(0);
- BigDecimal itemNumsBig = new BigDecimal(itemNums);
- BigDecimal unitPriceBig = new BigDecimal(unitPrice);
- BigDecimal bigDaysBig = new BigDecimal(dateLength);
- money = itemNumsBig.multiply(unitPriceBig).multiply(bigDaysBig);
- return money;
- }
- }
|