123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- package com.ruoyi.shipping.service.impl;
- import java.util.*;
- import java.util.stream.Collectors;
- import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
- import com.ruoyi.common.constant.UserConstants;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.SecurityUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.shipping.mapper.TCtnpriceItemsMapper;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.ruoyi.shipping.mapper.TVoyageMapper;
- import com.ruoyi.shipping.domain.TVoyage;
- import com.ruoyi.shipping.service.ITVoyageService;
- /**
- * 航次Service业务层处理
- *
- * @author ruoyi
- * @date 2021-04-02
- */
- @Service
- public class TVoyageServiceImpl implements ITVoyageService
- {
- @Autowired
- private TVoyageMapper tVoyageMapper;
- @Autowired
- private TCtnpriceItemsMapper tCtnpriceItemsMapper;
- /**
- * 查询航次
- *
- * @param fId 航次ID
- * @return 航次
- */
- @Override
- public TVoyage selectTVoyageById(Long fId)
- {
- return tVoyageMapper.selectTVoyageById(fId);
- }
- /**
- * 查询航次列表
- *
- * @param tVoyage 航次
- * @return 航次
- */
- @Override
- public List<TVoyage> selectTVoyageList(TVoyage tVoyage)
- {
- return tVoyageMapper.selectTVoyageList(tVoyage);
- }
- @Override
- public List<TVoyage> freightList(TVoyage tVoyage) {
- List<TVoyage> tVoyages = new ArrayList<>();
- tVoyages = tVoyageMapper.selectTVoyageListNew(tVoyage);
- tVoyages = tVoyages.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TVoyage -> TVoyage.getfPortofloadid() + ";"+ TVoyage.getfDistinationid()+ ";"+ TVoyage.getfPortoftransshipment()))), ArrayList::new));
- if (CollectionUtils.isNotEmpty(tVoyages)){
- for (TVoyage voyage : tVoyages) {
- voyage.setTwenty(tCtnpriceItemsMapper.selectMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "20GP"));
- voyage.setFortyHc(tCtnpriceItemsMapper.selectMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40HC"));
- voyage.setFortyRh(tCtnpriceItemsMapper.selectMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40RH"));
- TVoyage yage = new TVoyage();
- yage.setfPortofloadid(voyage.getfPortofloadid());
- yage.setfDistinationid(voyage.getfDistinationid());
- if (voyage.getfPortoftransshipment() != null){
- yage.setfPortoftransshipment(voyage.getfPortoftransshipment());
- }else {
- yage.setEmpty(1L);
- }
- List<TVoyage> freightselect = this.freightselect(yage);
- if (CollectionUtils.isNotEmpty(freightselect)){
- voyage.setFreight(freightselect);
- }
- }
- }
- return tVoyages;
- }
- @Override
- public List<TVoyage> freightselect(TVoyage tVoyage) {
- List<TVoyage> tVoyages = tVoyageMapper.selectTVoyageListNew(tVoyage);
- List<TVoyage> tVoyagesList = new ArrayList<>();
- Long fPortoftransshipment = null;
- if (CollectionUtils.isNotEmpty(tVoyages)){
- for (TVoyage voyage : tVoyages) {
- if (voyage.getfPortoftransshipment()!= null){
- fPortoftransshipment = voyage.getfPortoftransshipment();
- }
- List<String> list = tCtnpriceItemsMapper.selectPriceMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "20GP",fPortoftransshipment);
- List<String> money = tCtnpriceItemsMapper.selectPriceMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40HC",fPortoftransshipment);
- List<String> priceMoney = tCtnpriceItemsMapper.selectPriceMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40RH",fPortoftransshipment);
- if (CollectionUtils.isNotEmpty(list)){
- for (String s : list) {
- if (CollectionUtils.isNotEmpty(money)){
- for (String m : money) {
- if (CollectionUtils.isNotEmpty(priceMoney)){
- for (String p : priceMoney) {
- TVoyage yage = new TVoyage();
- BeanUtils.copyProperties(voyage,yage);
- yage.setTwenty(s);
- yage.setFortyHc(m);
- yage.setFortyRh(p);
- tVoyagesList.add(yage);
- }
- }else {
- TVoyage yage = new TVoyage();
- BeanUtils.copyProperties(voyage,yage);
- yage.setTwenty(s);
- yage.setFortyHc(m);
- yage.setFortyRh("0");
- tVoyagesList.add(yage);
- }
- }
- }else {
- if (CollectionUtils.isNotEmpty(priceMoney)){
- for (String p : priceMoney) {
- TVoyage yage = new TVoyage();
- BeanUtils.copyProperties(voyage,yage);
- yage.setTwenty(s);
- yage.setFortyHc("0");
- yage.setFortyRh(p);
- tVoyagesList.add(yage);
- }
- }else {
- TVoyage yage = new TVoyage();
- BeanUtils.copyProperties(voyage,yage);
- yage.setTwenty(s);
- yage.setFortyHc("0");
- yage.setFortyRh("0");
- tVoyagesList.add(yage);
- }
- }
- }
- }else {
- if (CollectionUtils.isNotEmpty(money)){
- for (String m : money) {
- if (CollectionUtils.isNotEmpty(priceMoney)){
- for (String p : priceMoney) {
- TVoyage yage = new TVoyage();
- BeanUtils.copyProperties(voyage,yage);
- yage.setTwenty("0");
- yage.setFortyHc(m);
- yage.setFortyRh(p);
- tVoyagesList.add(yage);
- }
- }else {
- TVoyage yage = new TVoyage();
- BeanUtils.copyProperties(voyage,yage);
- yage.setTwenty("0");
- yage.setFortyHc(m);
- yage.setFortyRh("0");
- tVoyagesList.add(yage);
- }
- }
- }else {
- if (CollectionUtils.isNotEmpty(priceMoney)){
- for (String p : priceMoney) {
- TVoyage yage = new TVoyage();
- BeanUtils.copyProperties(voyage,yage);
- yage.setTwenty("0");
- yage.setFortyHc("0");
- yage.setFortyRh(p);
- tVoyagesList.add(yage);
- }
- }else {
- TVoyage yage = new TVoyage();
- BeanUtils.copyProperties(voyage,yage);
- yage.setTwenty("0");
- yage.setFortyHc("0");
- yage.setFortyRh("0");
- tVoyagesList.add(yage);
- }
- }
- }
- }
- }
- return tVoyagesList;
- }
- /**
- * 新增航次
- *
- * @param tVoyage 航次
- * @return 结果
- */
- @Override
- public int insertTVoyage(TVoyage tVoyage)
- {
- tVoyage.setCreateTime(DateUtils.getNowDate());
- tVoyage.setCreateBy(SecurityUtils.getUsername());
- if (tVoyage.getfDays()==null){
- long dateDay = DateUtils.getDateDay(tVoyage.getfEta(),tVoyage.getfEtd());
- tVoyage.setfDays(dateDay);
- }
- return tVoyageMapper.insertTVoyage(tVoyage);
- }
- /**
- * 修改航次
- *
- * @param tVoyage 航次
- * @return 结果
- */
- @Override
- public int updateTVoyage(TVoyage tVoyage)
- {
- tVoyage.setUpdateTime(DateUtils.getNowDate());
- tVoyage.setUpdateBy(SecurityUtils.getUsername());
- if (tVoyage.getfDays()==null){
- long dateDay = DateUtils.getDateDay(tVoyage.getfEta(), tVoyage.getfEtd());
- tVoyage.setfDays(dateDay);
- }
- return tVoyageMapper.updateTVoyage(tVoyage);
- }
- /**
- * 批量删除航次
- *
- * @param fIds 需要删除的航次ID
- * @return 结果
- */
- @Override
- public int deleteTVoyageByIds(Long[] fIds)
- {
- return tVoyageMapper.deleteTVoyageByIds(fIds);
- }
- /**
- * 删除航次信息
- *
- * @param fId 航次ID
- * @return 结果
- */
- @Override
- public int deleteTVoyageById(Long fId)
- {
- return tVoyageMapper.deleteTVoyageById(fId);
- }
- @Override
- public String selectTVoyagefNo(TVoyage tVoyage) {
- TVoyage voyage = tVoyageMapper.selectTVoyagefNo(tVoyage);
- if (StringUtils.isNotNull(voyage) && !voyage.getfId().equals(voyage.getfId())) {
- return UserConstants.NOT_UNIQUE;
- }
- return UserConstants.UNIQUE;
- }
- @Override
- public List<Map<String, Object>> selectTVoyagefNumber(TVoyage tVoyage) {
- return tVoyageMapper.selectTVoyagefNumber(tVoyage);
- }
- @Override
- public List<TVoyage> selectMessage(TVoyage tVoyage) {
- return tVoyageMapper.selectMessage(tVoyage);
- }
- }
|