admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
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,12 +103,22 @@
      }
      
      // 时间转换
      conversionTime(record);
      handleTime(record);
      
      // 图片上传
      String picture = null;
      if (file != null) {
         picture = uploadPicture(file);
      }
      Boolean isDefault = record.getIsDefault();
      if (isDefault == null) {
         record.setIsDefault(false);
      }
      Boolean isFixed = record.getIsFixed();
      if (isFixed == null) {
         record.setIsFixed(false);
      }
      
      Long id = record.getId();
@@ -172,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();
      
@@ -190,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{
@@ -245,26 +247,29 @@
      
      HomeNavbar changeObj = null;
      if (GoodsClass.SEX_ALL == sex || GoodsClass.SEX_DEFAULT == sex) {
         changeObj = homeNavbarMapper.getDefaultChangeOrder(moveType,  resultObj.getOrderby());
         Integer orderby = resultObj.getOrderby();
         changeObj = homeNavbarMapper.getDefaultChangeOrder(moveType, orderby);
         if (changeObj == null ) {
            throw new HomeNavbarException(1, "已经在最边缘,无可交换的位置");
         }
         resultObj.setOrderby(changeObj.getOrderby());
         changeObj.setOrderby(resultObj.getOrderby());
         changeObj.setOrderby(orderby);
      } else if (GoodsClass.SEX_MAN == sex) {
         changeObj = homeNavbarMapper.getManChangeOrder(moveType,  resultObj.getOrderMan());
         Integer orderMan = resultObj.getOrderMan();
         changeObj = homeNavbarMapper.getManChangeOrder(moveType, orderMan);
         if (changeObj == null ) {
            throw new HomeNavbarException(1, "已经在最边缘,无可交换的位置");
         }
         resultObj.setOrderMan(changeObj.getOrderMan());
         changeObj.setOrderMan( resultObj.getOrderMan());
         changeObj.setOrderMan(orderMan);
      } else if (GoodsClass.SEX_WOMAN == sex) {
         changeObj = homeNavbarMapper.getWomanChangeOrder(moveType,  resultObj.getOrderWoman());
         Integer orderWoman = resultObj.getOrderWoman();
         changeObj = homeNavbarMapper.getWomanChangeOrder(moveType, orderWoman);
         if (changeObj == null ) {
            throw new HomeNavbarException(1, "已经在最边缘,无可交换的位置");
         }
         resultObj.setOrderWoman(changeObj.getOrderWoman());
         changeObj.setOrderWoman( resultObj.getOrderWoman());
         changeObj.setOrderWoman(orderWoman);
      }
      
      if (changeObj == null ) {
@@ -285,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();
@@ -363,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);
   }
}