yujian
2020-04-24 916f8851ccddff8ff764d950667b5fa86f77d7b2
fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java
@@ -29,7 +29,6 @@
import com.yeshi.fanli.entity.common.JumpDetailV2;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.exception.banner.SwiperPictureException;
import com.yeshi.fanli.exception.homemodule.HomeNavbarException;
import com.yeshi.fanli.exception.homemodule.SpecialException;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.AppVersionService;
@@ -102,11 +101,6 @@
         record.setParams(params.trim());
      }
      String startTime_str = record.getStartTime_str();
      if (record.isTimeTask() && (startTime_str == null || startTime_str.length() == 0)) {
         throw new SpecialException(1, "控制时间不能为空");
      }
      if (!StringUtil.isNullOrEmpty(jumpType)) {
         List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType);
         if (listByType != null && listByType.size() > 0) {
@@ -115,7 +109,7 @@
      }
      // 时间转换
      conversionTime(record);
      handleTime(record);
      Long state = record.getState();
      if (state == null) {
@@ -227,30 +221,24 @@
    * 
    * @param record
    */
   public void conversionTime(Special record) throws SpecialException, 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(Special 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, "起始时间不能小于结束时间");
      }
   }
@@ -269,7 +257,7 @@
      String type = contentType.substring(contentType.indexOf("/") + 1);
      // 文件路径
      String filePath =FilePathEnum.special.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type;
      String filePath = FilePathEnum.special.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type;
      // 执行上传
      String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
@@ -289,7 +277,7 @@
   }
   @Override
   @Transactional(rollbackFor=Exception.class)
   @Transactional(rollbackFor = Exception.class)
   public void updateOrder(Long id, Integer moveType, Integer sex) throws SpecialException {
      if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1)) || sex == null) {
@@ -355,7 +343,7 @@
            COSManager.getInstance().deleteFile(subPicture);
         }
      }
      if (listSpecial != null)
         for (Special special : listSpecial) {
            List<AdActivityVersionControl> versionList = adActivityVersionControlService
@@ -395,17 +383,18 @@
      // 跳转链接
      for (Special special : list) {
         if (special.getState() != null && special.getState().longValue() == 0) {
            special.setState(1L);
         } else {
            special.setState(0L);
         }
         Date startTime = special.getStartTime();
         Date endTime = special.getEndTime();
         if (startTime == null && endTime == null) {
            special.setTimeTask(false);
            special.setStartTime_str("");
            special.setEndTime_str("");
         } else {
            special.setTimeTask(true);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
            if (startTime == null) {
               special.setStartTime_str("");
@@ -555,10 +544,16 @@
                  s.setParams(special.getParams());
               }
            }
            if (s.getJumpDetail() != null) {
               s.getJumpDetail().setNeedLogin(s.isJumpLogin()
                     | (s.getJumpDetail().getNeedLogin() != null && s.getJumpDetail().getNeedLogin()));
            }
         }
      // 数据处理
      handlelist(listArc);
//      handlelist(listArc);
      arcMap.put("list", JsonUtil.getApiCommonGson().toJson(listArc));
      // 首页-活动区域(女王节)
@@ -716,4 +711,30 @@
         }
      }
   }
   @Override
   public void switchState(Long id) throws SpecialException {
      if (id == null) {
         throw new SpecialException(1, "请传递正确参数");
      }
      Special resultObj = specialMapper.selectByPrimaryKey(id);
      if (resultObj == null) {
         throw new SpecialException(1, "此内容已不存在");
      }
      Long state = resultObj.getState();
      if (state == null || state == 0) {
         state = 1L;
      } else {
         state = 0L;
      }
      Special updateObj = new Special();
      updateObj.setId(id);
      updateObj.setState(state);
      updateObj.setJumpLogin(resultObj.isJumpLogin());
      specialMapper.updateByPrimaryKeySelective(updateObj);
   }
}