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 selectTVoyageList(TVoyage tVoyage) { return tVoyageMapper.selectTVoyageList(tVoyage); } @Override public List freightList(TVoyage tVoyage) { List 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 freightselect = this.freightselect(yage); if (CollectionUtils.isNotEmpty(freightselect)){ voyage.setFreight(freightselect); } } } return tVoyages; } @Override public List freightselect(TVoyage tVoyage) { List tVoyages = tVoyageMapper.selectTVoyageListNew(tVoyage); List tVoyagesList = new ArrayList<>(); Long fPortoftransshipment = null; if (CollectionUtils.isNotEmpty(tVoyages)){ for (TVoyage voyage : tVoyages) { if (voyage.getfPortoftransshipment()!= null){ fPortoftransshipment = voyage.getfPortoftransshipment(); } List list = tCtnpriceItemsMapper.selectPriceMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "20GP",fPortoftransshipment); List money = tCtnpriceItemsMapper.selectPriceMoney(voyage.getfPortofloadid(), voyage.getfDistinationid(), "40HC",fPortoftransshipment); List 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> selectTVoyagefNumber(TVoyage tVoyage) { return tVoyageMapper.selectTVoyagefNumber(tVoyage); } @Override public List selectMessage(TVoyage tVoyage) { return tVoyageMapper.selectMessage(tVoyage); } }