TVoyageServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. package com.ruoyi.shipping.service.impl;
  2. import java.util.*;
  3. import java.util.stream.Collectors;
  4. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  5. import com.ruoyi.common.constant.UserConstants;
  6. import com.ruoyi.common.utils.DateUtils;
  7. import com.ruoyi.common.utils.SecurityUtils;
  8. import com.ruoyi.common.utils.StringUtils;
  9. import com.ruoyi.shipping.mapper.TCtnpriceItemsMapper;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import com.ruoyi.shipping.mapper.TVoyageMapper;
  14. import com.ruoyi.shipping.domain.TVoyage;
  15. import com.ruoyi.shipping.service.ITVoyageService;
  16. /**
  17. * 航次Service业务层处理
  18. *
  19. * @author ruoyi
  20. * @date 2021-04-02
  21. */
  22. @Service
  23. public class TVoyageServiceImpl implements ITVoyageService
  24. {
  25. @Autowired
  26. private TVoyageMapper tVoyageMapper;
  27. @Autowired
  28. private TCtnpriceItemsMapper tCtnpriceItemsMapper;
  29. /**
  30. * 查询航次
  31. *
  32. * @param fId 航次ID
  33. * @return 航次
  34. */
  35. @Override
  36. public TVoyage selectTVoyageById(Long fId)
  37. {
  38. return tVoyageMapper.selectTVoyageById(fId);
  39. }
  40. /**
  41. * 查询航次列表
  42. *
  43. * @param tVoyage 航次
  44. * @return 航次
  45. */
  46. @Override
  47. public List<TVoyage> selectTVoyageList(TVoyage tVoyage)
  48. {
  49. return tVoyageMapper.selectTVoyageList(tVoyage);
  50. }
  51. @Override
  52. public List<TVoyage> freightList(TVoyage tVoyage) {
  53. List<TVoyage> tVoyages = new ArrayList<>();
  54. tVoyages = tVoyageMapper.selectTVoyageListNew(tVoyage);
  55. tVoyages = tVoyages.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TVoyage -> TVoyage.getfPortofloadid() + ";"+ TVoyage.getfDistinationid()+ ";"+ TVoyage.getfPortoftransshipment()))), ArrayList::new));
  56. if (CollectionUtils.isNotEmpty(tVoyages)){
  57. for (TVoyage voyage : tVoyages) {
  58. voyage.setTwenty(tCtnpriceItemsMapper.selectMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "20GP"));
  59. voyage.setFortyHc(tCtnpriceItemsMapper.selectMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40HC"));
  60. voyage.setFortyRh(tCtnpriceItemsMapper.selectMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40RH"));
  61. TVoyage yage = new TVoyage();
  62. yage.setfPortofloadid(voyage.getfPortofloadid());
  63. yage.setfDistinationid(voyage.getfDistinationid());
  64. if (voyage.getfPortoftransshipment() != null){
  65. yage.setfPortoftransshipment(voyage.getfPortoftransshipment());
  66. }else {
  67. yage.setEmpty(1L);
  68. }
  69. List<TVoyage> freightselect = this.freightselect(yage);
  70. if (CollectionUtils.isNotEmpty(freightselect)){
  71. voyage.setFreight(freightselect);
  72. }
  73. }
  74. }
  75. return tVoyages;
  76. }
  77. @Override
  78. public List<TVoyage> freightselect(TVoyage tVoyage) {
  79. List<TVoyage> tVoyages = tVoyageMapper.selectTVoyageListNew(tVoyage);
  80. List<TVoyage> tVoyagesList = new ArrayList<>();
  81. Long fPortoftransshipment = null;
  82. if (CollectionUtils.isNotEmpty(tVoyages)){
  83. for (TVoyage voyage : tVoyages) {
  84. if (voyage.getfPortoftransshipment()!= null){
  85. fPortoftransshipment = voyage.getfPortoftransshipment();
  86. }
  87. List<String> list = tCtnpriceItemsMapper.selectPriceMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "20GP",fPortoftransshipment);
  88. List<String> money = tCtnpriceItemsMapper.selectPriceMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40HC",fPortoftransshipment);
  89. List<String> priceMoney = tCtnpriceItemsMapper.selectPriceMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40RH",fPortoftransshipment);
  90. if (CollectionUtils.isNotEmpty(list)){
  91. for (String s : list) {
  92. if (CollectionUtils.isNotEmpty(money)){
  93. for (String m : money) {
  94. if (CollectionUtils.isNotEmpty(priceMoney)){
  95. for (String p : priceMoney) {
  96. TVoyage yage = new TVoyage();
  97. BeanUtils.copyProperties(voyage,yage);
  98. yage.setTwenty(s);
  99. yage.setFortyHc(m);
  100. yage.setFortyRh(p);
  101. tVoyagesList.add(yage);
  102. }
  103. }else {
  104. TVoyage yage = new TVoyage();
  105. BeanUtils.copyProperties(voyage,yage);
  106. yage.setTwenty(s);
  107. yage.setFortyHc(m);
  108. yage.setFortyRh("0");
  109. tVoyagesList.add(yage);
  110. }
  111. }
  112. }else {
  113. if (CollectionUtils.isNotEmpty(priceMoney)){
  114. for (String p : priceMoney) {
  115. TVoyage yage = new TVoyage();
  116. BeanUtils.copyProperties(voyage,yage);
  117. yage.setTwenty(s);
  118. yage.setFortyHc("0");
  119. yage.setFortyRh(p);
  120. tVoyagesList.add(yage);
  121. }
  122. }else {
  123. TVoyage yage = new TVoyage();
  124. BeanUtils.copyProperties(voyage,yage);
  125. yage.setTwenty(s);
  126. yage.setFortyHc("0");
  127. yage.setFortyRh("0");
  128. tVoyagesList.add(yage);
  129. }
  130. }
  131. }
  132. }else {
  133. if (CollectionUtils.isNotEmpty(money)){
  134. for (String m : money) {
  135. if (CollectionUtils.isNotEmpty(priceMoney)){
  136. for (String p : priceMoney) {
  137. TVoyage yage = new TVoyage();
  138. BeanUtils.copyProperties(voyage,yage);
  139. yage.setTwenty("0");
  140. yage.setFortyHc(m);
  141. yage.setFortyRh(p);
  142. tVoyagesList.add(yage);
  143. }
  144. }else {
  145. TVoyage yage = new TVoyage();
  146. BeanUtils.copyProperties(voyage,yage);
  147. yage.setTwenty("0");
  148. yage.setFortyHc(m);
  149. yage.setFortyRh("0");
  150. tVoyagesList.add(yage);
  151. }
  152. }
  153. }else {
  154. if (CollectionUtils.isNotEmpty(priceMoney)){
  155. for (String p : priceMoney) {
  156. TVoyage yage = new TVoyage();
  157. BeanUtils.copyProperties(voyage,yage);
  158. yage.setTwenty("0");
  159. yage.setFortyHc("0");
  160. yage.setFortyRh(p);
  161. tVoyagesList.add(yage);
  162. }
  163. }else {
  164. TVoyage yage = new TVoyage();
  165. BeanUtils.copyProperties(voyage,yage);
  166. yage.setTwenty("0");
  167. yage.setFortyHc("0");
  168. yage.setFortyRh("0");
  169. tVoyagesList.add(yage);
  170. }
  171. }
  172. }
  173. }
  174. }
  175. return tVoyagesList;
  176. }
  177. /**
  178. * 新增航次
  179. *
  180. * @param tVoyage 航次
  181. * @return 结果
  182. */
  183. @Override
  184. public int insertTVoyage(TVoyage tVoyage)
  185. {
  186. tVoyage.setCreateTime(DateUtils.getNowDate());
  187. tVoyage.setCreateBy(SecurityUtils.getUsername());
  188. if (tVoyage.getfDays()==null){
  189. long dateDay = DateUtils.getDateDay(tVoyage.getfEta(),tVoyage.getfEtd());
  190. tVoyage.setfDays(dateDay);
  191. }
  192. return tVoyageMapper.insertTVoyage(tVoyage);
  193. }
  194. /**
  195. * 修改航次
  196. *
  197. * @param tVoyage 航次
  198. * @return 结果
  199. */
  200. @Override
  201. public int updateTVoyage(TVoyage tVoyage)
  202. {
  203. tVoyage.setUpdateTime(DateUtils.getNowDate());
  204. tVoyage.setUpdateBy(SecurityUtils.getUsername());
  205. if (tVoyage.getfDays()==null){
  206. long dateDay = DateUtils.getDateDay(tVoyage.getfEta(), tVoyage.getfEtd());
  207. tVoyage.setfDays(dateDay);
  208. }
  209. return tVoyageMapper.updateTVoyage(tVoyage);
  210. }
  211. /**
  212. * 批量删除航次
  213. *
  214. * @param fIds 需要删除的航次ID
  215. * @return 结果
  216. */
  217. @Override
  218. public int deleteTVoyageByIds(Long[] fIds)
  219. {
  220. return tVoyageMapper.deleteTVoyageByIds(fIds);
  221. }
  222. /**
  223. * 删除航次信息
  224. *
  225. * @param fId 航次ID
  226. * @return 结果
  227. */
  228. @Override
  229. public int deleteTVoyageById(Long fId)
  230. {
  231. return tVoyageMapper.deleteTVoyageById(fId);
  232. }
  233. @Override
  234. public String selectTVoyagefNo(TVoyage tVoyage) {
  235. TVoyage voyage = tVoyageMapper.selectTVoyagefNo(tVoyage);
  236. if (StringUtils.isNotNull(voyage) && !voyage.getfId().equals(voyage.getfId())) {
  237. return UserConstants.NOT_UNIQUE;
  238. }
  239. return UserConstants.UNIQUE;
  240. }
  241. @Override
  242. public List<Map<String, Object>> selectTVoyagefNumber(TVoyage tVoyage) {
  243. return tVoyageMapper.selectTVoyagefNumber(tVoyage);
  244. }
  245. @Override
  246. public List<TVoyage> selectMessage(TVoyage tVoyage) {
  247. return tVoyageMapper.selectMessage(tVoyage);
  248. }
  249. }