TWarehouseAgreementServiceImpl.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. package com.ruoyi.warehouseBusiness.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.ruoyi.common.core.domain.AjaxResult;
  6. import com.ruoyi.common.core.domain.model.LoginUser;
  7. import com.ruoyi.common.utils.DateUtils;
  8. import com.ruoyi.common.utils.StringUtils;
  9. import com.ruoyi.warehouseBusiness.domain.BillnoDel;
  10. import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreement;
  11. import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreementitems;
  12. import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
  13. import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
  14. import com.ruoyi.warehouseBusiness.mapper.TWarehouseAgreementMapper;
  15. import com.ruoyi.warehouseBusiness.mapper.TWarehouseAgreementitemsMapper;
  16. import com.ruoyi.warehouseBusiness.service.ITWarehouseAgreementService;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.math.BigDecimal;
  20. import java.util.Date;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * 仓储费Service业务层处理
  25. *
  26. * @author ruoyi
  27. * @date 2020-12-11
  28. */
  29. @Service
  30. public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementService {
  31. @Autowired
  32. private TWarehouseAgreementMapper tWarehouseAgreementMapper;
  33. @Autowired
  34. private TWarehouseAgreementitemsMapper tWarehouseAgreementitemsMapper;
  35. @Autowired
  36. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  37. @Autowired
  38. private BillnoDelMapper billnoDelMapper;
  39. /**
  40. * 查询仓储费
  41. *
  42. * @param fId 仓储费ID
  43. * @return 仓储费
  44. */
  45. @Override
  46. public TWarehouseAgreement selectTWarehouseAgreementById(Long fId) {
  47. return tWarehouseAgreementMapper.selectTWarehouseAgreementById(fId);
  48. }
  49. /**
  50. * 查询仓储费列表
  51. *
  52. * @param tWarehouseAgreement 仓储费
  53. * @return 仓储费
  54. */
  55. @Override
  56. public List<Map<String, Object>> selectTWarehouseAgreementList1(TWarehouseAgreement tWarehouseAgreement) {
  57. return tWarehouseAgreementMapper.selectTWarehouseAgreementList1(tWarehouseAgreement);
  58. }
  59. /**
  60. * 查询仓储费列表
  61. *
  62. * @param tWarehouseAgreement 仓储费
  63. * @return 仓储费
  64. */
  65. @Override
  66. public List<TWarehouseAgreement> selectTWarehouseAgreementList(TWarehouseAgreement tWarehouseAgreement) {
  67. return tWarehouseAgreementMapper.selectTWarehouseAgreementList(tWarehouseAgreement);
  68. }
  69. /**
  70. * 新增
  71. * @param agreement
  72. * @param agreementitems
  73. * @param loginUser
  74. * @return
  75. */
  76. @Override
  77. public AjaxResult insertTWarehouseAgreement(String agreement, String agreementitems, LoginUser loginUser) {
  78. Long fPid = null;
  79. TWarehouseAgreement tWarehouseAgreement = JSONArray.parseObject(agreement, TWarehouseAgreement.class);
  80. if(StringUtils.isNull(tWarehouseAgreement.getfId())){
  81. // 如果是新数据
  82. tWarehouseAgreement.setCreateBy(loginUser.getUser().getUserName());
  83. // 业务编码
  84. String billNo = billnoSerialServiceImpl.getBillNo("WA", new Date());
  85. tWarehouseAgreement.setfBillno(billNo);
  86. tWarehouseAgreementMapper.insertTWarehouseAgreement(tWarehouseAgreement);
  87. fPid = tWarehouseAgreement.getfId();
  88. }else{
  89. fPid = tWarehouseAgreement.getfId();
  90. tWarehouseAgreement.setUpdateBy(loginUser.getUser().getUserName());
  91. tWarehouseAgreement.setUpdateTime(new Date());
  92. tWarehouseAgreementMapper.updateTWarehouseAgreement(tWarehouseAgreement);
  93. tWarehouseAgreementitemsMapper.deleteByFPid(fPid);
  94. }
  95. // 从表添加
  96. if (StringUtils.isNotNull(agreementitems)) {
  97. JSONArray jsonDrArray = JSONArray.parseArray(agreementitems);
  98. List<TWarehouseAgreementitems> tWarehouseAgreementitemsList = JSONObject.parseArray(jsonDrArray.toJSONString(), TWarehouseAgreementitems.class);
  99. for (TWarehouseAgreementitems tWarehouseAgreementitems : tWarehouseAgreementitemsList) {
  100. tWarehouseAgreementitems.setfPid(fPid);
  101. tWarehouseAgreementitems.setCreateBy(loginUser.getUser().getUserName());
  102. tWarehouseAgreementitems.setCreateTime(new Date());
  103. tWarehouseAgreementitemsMapper.insertTWarehouseAgreementitems(tWarehouseAgreementitems);
  104. }
  105. }
  106. return AjaxResult.success();
  107. }
  108. /**
  109. * 修改仓储费
  110. *
  111. * @param tWarehouseAgreement 仓储费
  112. * @return 结果
  113. */
  114. @Override
  115. public int updateTWarehouseAgreement(TWarehouseAgreement tWarehouseAgreement) {
  116. tWarehouseAgreement.setUpdateTime(DateUtils.getNowDate());
  117. return tWarehouseAgreementMapper.updateTWarehouseAgreement(tWarehouseAgreement);
  118. }
  119. /**
  120. * 批量删除仓储费
  121. *
  122. * @param fIds 需要删除的仓储费ID
  123. * @return 结果
  124. */
  125. @Override
  126. public int deleteTWarehouseAgreementByIds(Long[] fIds) {
  127. // 取出业务编号、 放入 billno_del
  128. for(Long id:fIds){
  129. // 1、查询主表信息
  130. TWarehouseAgreement tWarehouseAgreement = tWarehouseAgreementMapper.selectTWarehouseAgreementById(id);
  131. // 2、业务编号、客存编号 放入 billno_del
  132. BillnoDel billnoDel =new BillnoDel();
  133. billnoDel.setBillType("WA");
  134. billnoDel.setBillNo(tWarehouseAgreement.getfBillno());
  135. billnoDelMapper.insertBillnoDel(billnoDel);
  136. }
  137. return tWarehouseAgreementMapper.deleteTWarehouseAgreementByIds(fIds);
  138. }
  139. /**
  140. * 删除仓储费信息
  141. *
  142. * @param fId 仓储费ID
  143. * @return 结果
  144. */
  145. @Override
  146. public int deleteTWarehouseAgreementById(Long fId) {
  147. return tWarehouseAgreementMapper.deleteTWarehouseAgreementById(fId);
  148. }
  149. /**
  150. * 计算存储费用
  151. * @author shanxin
  152. * @param fCorpid 出库客户Id
  153. * @param fGoodsid 物资类型Id
  154. * @param days 时长天数
  155. * @param feeUnitid 计价单位
  156. * @param itemNums 数量
  157. * @return
  158. */
  159. public BigDecimal getCarryingCost(Long fCorpid,
  160. Long fGoodsid,
  161. Long days,
  162. Long feeUnitid,
  163. Long itemNums) {
  164. if (null == fCorpid ||
  165. null == fGoodsid ||
  166. null == days ||
  167. null == feeUnitid ||
  168. null == itemNums) {
  169. return null;
  170. }
  171. List<TWarehouseAgreementitems> itemList =
  172. this.tWarehouseAgreementitemsMapper.getItemsBytWarehouseAgreementMsg(fCorpid,fGoodsid,feeUnitid);
  173. if (CollUtil.isEmpty(itemList)) {
  174. return null;
  175. }
  176. BigDecimal money = new BigDecimal(0);
  177. Long dayLength = 0L;
  178. for (TWarehouseAgreementitems tWarehouseAgreementitems : itemList) {
  179. if (days < 1) break;
  180. dayLength = tWarehouseAgreementitems.getfEndays() - tWarehouseAgreementitems.getfFromdays() + 1L;
  181. if (days >= dayLength) {
  182. money = money.add(this.getCalculate(itemNums,tWarehouseAgreementitems.getfPrice(),dayLength));
  183. days -= dayLength;
  184. } else {
  185. money = money.add(this.getCalculate(itemNums,feeUnitid,days));
  186. }
  187. }
  188. return money;
  189. }
  190. /**
  191. * 数量 * 单价 * 天数
  192. * @param itemNums 数量
  193. * @param unitPrice 单价
  194. * @param dateLength 天数
  195. * @return
  196. */
  197. public BigDecimal getCalculate (Long itemNums,Long unitPrice,Long dateLength) {
  198. BigDecimal money = new BigDecimal(0);
  199. BigDecimal itemNumsBig = new BigDecimal(itemNums);
  200. BigDecimal unitPriceBig = new BigDecimal(unitPrice);
  201. BigDecimal bigDaysBig = new BigDecimal(dateLength);
  202. money = itemNumsBig.multiply(unitPriceBig).multiply(bigDaysBig);
  203. return money;
  204. }
  205. }