admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/HomeNavbarServiceImpl.java
@@ -20,9 +20,11 @@
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.exception.homemodule.SpecialException;
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.FilePathEnum;
import com.yeshi.fanli.util.StringUtil;
@@ -68,12 +70,6 @@
         throw new HomeNavbarException(1, "导航名称不能为空");
      }
      
      String startTime_str = record.getStartTime_str();
      if (record.isTimeTask() && (startTime_str == null || startTime_str.length() == 0)) {
         throw new HomeNavbarException(1, "控制时间不能为空");
      }
      Integer sex = null;
      NavbarTypeEnum type = record.getType();
      if (NavbarTypeEnum.category.equals(type)) {
@@ -107,7 +103,7 @@
      }
      
      // 时间转换
      conversionTime(record);
      handleTime(record);
      
      // 图片上传
      String picture = null;
@@ -182,7 +178,7 @@
      String type = contentType.substring(contentType.indexOf("/") + 1);
   
      // 文件路径
      String filePath="/img/HomeNavbar/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
      String filePath= FilePathEnum.homeNavbar.getPath() +UUID.randomUUID().toString().replace("-", "") + "." + type;
      // 执行上传
      String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
      
@@ -200,37 +196,33 @@
      }
   }
   
   /**
    * web段时间转换
    *
    * @param record
    */
   public void conversionTime(HomeNavbar record) throws HomeNavbarException, Exception {
      // 是否时间控制
      if(!record.isTimeTask()) {
         record.setStartTime(null);
         record.setEndTime(null);
      } else {
         String startTime_str = record.getStartTime_str();
         String endTime_str = record.getEndTime_str();
         if ((startTime_str == null|| startTime_str.trim().length() == 0)
               && (endTime_str == null || endTime_str.trim().length() == 0)) {
            throw new HomeNavbarException(1, "请输入控制时间");
         } else {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            if (startTime_str != null && startTime_str.trim().length() > 0) {
               startTime_str = startTime_str.replaceAll("T", " ");
               record.setStartTime(format.parse(startTime_str));
            }
            if (endTime_str != null && endTime_str.trim().length() > 0) {
               endTime_str = endTime_str.replaceAll("T", " ");
               record.setEndTime(format.parse(endTime_str));
            }
         }
   private void handleTime(HomeNavbar record) throws SpecialException, Exception {
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
      String startTime_str = record.getStartTime_str();
      if (!StringUtil.isNullOrEmpty(startTime_str)) {
         startTime_str = startTime_str.replaceAll("T", " ");
         record.setStartTime(format.parse(startTime_str));
      }
      String endTime_str = record.getEndTime_str();
      if (!StringUtil.isNullOrEmpty(endTime_str)) {
         endTime_str = endTime_str.replaceAll("T", " ");
         record.setEndTime(format.parse(endTime_str));
      }
      if (record.getEndTime() != null && record.getStartTime() != null
            && record.getStartTime().getTime() > record.getEndTime().getTime()) {
         throw new SpecialException(1, "起始时间不能小于结束时间");
      }
   }
   
   @Override
   public void updateOrder(Long id, Integer moveType, Integer sex) throws HomeNavbarException, Exception{
@@ -298,30 +290,21 @@
         return null;
      }
      
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
      for (HomeNavbar homeNavbar: listObj) {
         Date startTime = homeNavbar.getStartTime();
         Date endTime = homeNavbar.getEndTime();
         if (startTime == null && endTime == null) {
            homeNavbar.setTimeTask(false);
         if (startTime == null) {
            homeNavbar.setStartTime_str("");
         } else {
            homeNavbar.setStartTime_str(sdf.format(startTime));
         }
         Date endTime = homeNavbar.getEndTime();
         if (endTime == null) {
            homeNavbar.setEndTime_str("");
         } else {
            homeNavbar.setTimeTask(true);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
            if (startTime == null) {
               homeNavbar.setStartTime_str("");
            } else {
               homeNavbar.setStartTime_str(sdf.format(startTime));
            }
            if (endTime == null) {
               homeNavbar.setEndTime_str("");
            } else {
               homeNavbar.setEndTime_str(sdf.format(endTime));
            }
            homeNavbar.setEndTime_str(sdf.format(endTime));
         }
         
         Long classId = homeNavbar.getClassId();
@@ -376,4 +359,29 @@
      return homeNavbarMapper.getEffectiveByClassId(classId);
   }
   @Override
   public void switchState(Long id) throws HomeNavbarException {
      if (id == null) {
         throw new HomeNavbarException(1, "请传递正确参数");
      }
      HomeNavbar resultObj = homeNavbarMapper.selectByPrimaryKey(id);
      if (resultObj == null) {
         throw new HomeNavbarException(1, "此内容已不存在");
      }
      Integer state = resultObj.getState();
      if (state == null || state == 0) {
         state = 1;
      } else {
         state = 0;
      }
      HomeNavbar updateObj = new HomeNavbar();
      updateObj.setId(id);
      updateObj.setState(state);
      homeNavbarMapper.updateByPrimaryKeySelective(updateObj);
   }
}