yujian
2019-04-22 b6c37e4bc38db88a360d0f2c6099183f9bb75bdc
fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/HomeNavbarServiceImpl.java
@@ -2,28 +2,27 @@
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.yeshi.utils.tencentcloud.COSManager;
import com.yeshi.fanli.dao.mybatis.homemodule.HomeNavbarMapper;
import com.yeshi.fanli.dao.mybatis.homemodule.SuperHomeNavbarMapper;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar;
import com.yeshi.fanli.entity.bus.homemodule.SuperHomeNavbar;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.exception.ActivityException;
import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar.NavbarTypeEnum;
import com.yeshi.fanli.entity.bus.homemodule.SwiperBanner;
import com.yeshi.fanli.exception.homemodule.HomeNavbarException;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.goods.GoodsClassService;
import com.yeshi.fanli.service.inter.homemodule.HomeNavbarService;
import com.yeshi.fanli.service.inter.homemodule.SwiperBannerService;
import com.yeshi.fanli.util.StringUtil;
@@ -31,17 +30,21 @@
public class HomeNavbarServiceImpl implements HomeNavbarService {
   
   @Resource
   private BusinessSystemService businessSystemService;
   @Resource
   private HomeNavbarMapper homeNavbarMapper;
   @Resource
   private SuperHomeNavbarMapper superHomeNavbarMapper;
   
   @Resource
   private GoodsClassService goodsClassService;
   @Resource
   private SwiperBannerService swiperBannerService;
   @Override
   @Transactional
   public int deleteBatchByPrimaryKey(List<Long> list) {
      superHomeNavbarMapper.deleteBatchByNavbarIds(list);
      if (list == null || list.size() == 0) {
         return 0;
      }
      for (Long id: list) {
         HomeNavbar homeNavbar = homeNavbarMapper.selectByPrimaryKey(id);
         if (homeNavbar !=null) {
@@ -52,7 +55,6 @@
            }
         }
      }
      return homeNavbarMapper.deleteBatchByPrimaryKey(list);
   }
@@ -64,6 +66,34 @@
      String name = record.getName();
      if (name == null || name.trim().length() == 0) {
         throw new HomeNavbarException(1, "导航名称不能为空");
      }
      String startTime_str = record.getStartTime_str();
      if (record.isTimeTask() && (startTime_str == null || startTime_str.length() == 0)) {
         throw new HomeNavbarException(1, "控制时间不能为空");
      }
      NavbarTypeEnum type = record.getType();
      if (NavbarTypeEnum.category.equals(type)) {
         Long classId = record.getClassId();
         if (classId == null) {
            throw new HomeNavbarException(1, "请选择分类");
         }
         record.setUrl(null);
      } else if(NavbarTypeEnum.weex.equals(type) || NavbarTypeEnum.web.equals(type)) {
         String url = record.getUrl();
         if (url == null || url.trim().length() == 0) {
            throw new HomeNavbarException(1, "请输入URl链接");
         }
      } else {
         throw new HomeNavbarException(1, "类型的值不正确");
      }
      Long swiperBannerId = record.getSwiperBannerId();
      if (swiperBannerId != null && swiperBannerId == 0) {
         record.setSwiperBannerId(null);
      }
      
      // 时间转换
@@ -149,7 +179,7 @@
    * web段时间转换
    * @param record
    */
   public void conversionTime(HomeNavbar record) throws ActivityException, Exception {
   public void conversionTime(HomeNavbar record) throws HomeNavbarException, Exception {
      // 是否时间控制
      if(!record.isTimeTask()) {
         record.setStartTime(null);
@@ -160,7 +190,7 @@
         
         if ((startTime_str == null|| startTime_str.trim().length() == 0) 
               && (endTime_str == null || endTime_str.trim().length() == 0)) {
            throw new ActivityException(1, "请输入控制时间");
            throw new HomeNavbarException(1, "请输入控制时间");
         } else {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            if (startTime_str != null && startTime_str.trim().length() > 0) {
@@ -206,76 +236,7 @@
      homeNavbarMapper.updateByPrimaryKeySelective(resultObj);
   }
   @Override
   public List<HomeNavbar> listQueryAndBusinessSystem(long start, int count, String key) {
      List<HomeNavbar> listObj = homeNavbarMapper.listQuery(start, count, key);
      if (listObj == null || listObj.size() == 0) {
         return null;
      }
      List<BusinessSystem> systemList = businessSystemService.getBusinessSystems();
      List<Long> listId = new ArrayList<Long>();
      for (HomeNavbar homeNavbar: listObj) {
         listId.add(homeNavbar.getId());
      }
      List<SuperHomeNavbar> listSuper = superHomeNavbarMapper.listByNavbarIds(listId);
      if (listSuper == null || listSuper.size() == 0) {
         for (HomeNavbar homeNavbar: listObj) {
            homeNavbar.setSystemList(systemList);
         }
      } else {
         for (HomeNavbar homeNavbar: listObj) {
            Long id = homeNavbar.getId();
            List<BusinessSystem> newList = new ArrayList<BusinessSystem>();
            // 是否有关联系统选项
            for (BusinessSystem dsystem : systemList) {
               BusinessSystem newsystem = new BusinessSystem();
               try {
                  PropertyUtils.copyProperties(newsystem, dsystem);
               } catch (Exception e) {
                  e.printStackTrace();
               }
               if (listSuper != null && listSuper.size() > 0) {
                  Long systemId = newsystem.getId();
                  for (SuperHomeNavbar superHomeNavbar : listSuper) {
                     HomeNavbar navbar = superHomeNavbar.getHomeNavbar();
                     BusinessSystem system = superHomeNavbar.getSystem();
                     // 当前专题 、当前系统
                     if (navbar != null && system != null && id == navbar.getId()
                           && systemId == system.getId()) {
                        newsystem.setCheck(1);
                        break;
                     }
                  }
               }
               if (newsystem.getCheck() != 1) {
                  newsystem.setCheck(0);
               }
               newList.add(newsystem);
            }
            homeNavbar.setSystemList(newList);
         }
      }
      return listObj;
   }
   
   @Override
@@ -311,6 +272,25 @@
               homeNavbar.setEndTime_str(sdf.format(endTime));
            }
         }
         Long classId = homeNavbar.getClassId();
         if (classId != null) {
            GoodsClass goodsClass = goodsClassService.selectByPrimaryKey(classId);
            if(goodsClass != null) {
               homeNavbar.setClassName(goodsClass.getName());
            }
         }
         Long swiperBannerId = homeNavbar.getSwiperBannerId();
         if (swiperBannerId != null) {
            SwiperBanner swiperBanner = swiperBannerService.selectByPrimaryKey(swiperBannerId);
            if(swiperBanner != null) {
               homeNavbar.setSwiperName(swiperBanner.getTitle());
            }
         } else {
            // 初始化
            homeNavbar.setSwiperBannerId(0L);
         }
      }
      return listObj;
   }
@@ -321,7 +301,8 @@
   }
   @Override
   public List<HomeNavbar> listQueryEffective() {
   @Cacheable(value = "configCache", key = "'listQueryEffectiveNavbar'")
   public List<HomeNavbar> listQueryEffectiveNavbar() {
      return homeNavbarMapper.listQueryEffective();
   }