admin
2020-05-16 03f9370b85d930bd232f72721e826b5875f898cb
fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java
@@ -12,6 +12,7 @@
import javax.annotation.Resource;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -26,22 +27,24 @@
import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl;
import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
import com.yeshi.fanli.entity.bus.homemodule.Special;
import com.yeshi.fanli.entity.bus.homemodule.SpecialExtra;
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;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
import com.yeshi.fanli.service.inter.homemodule.SpecialCardService;
import com.yeshi.fanli.service.inter.homemodule.SpecialExtraService;
import com.yeshi.fanli.service.inter.homemodule.SpecialPlaceService;
import com.yeshi.fanli.service.inter.homemodule.SpecialService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.FilePathEnum;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.vo.homemodule.SpecialVO;
import net.sf.json.JSONObject;
@@ -57,6 +60,9 @@
   @Resource
   private SpecialCardService specialCardService;
   @Resource
   private SpecialExtraService specialExtraService;
   @Resource
   private JumpDetailV2Service jumpDetailV2Service;
@@ -76,7 +82,7 @@
   @Override
   public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record,
         String jumpType) throws SpecialException, Exception {
         String jumpType, SpecialExtra extra) throws SpecialException, Exception {
      Long cardId = record.getCardId();
      if (cardId == null) {
@@ -102,11 +108,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 +116,7 @@
      }
      // 时间转换
      conversionTime(record);
      handleTime(record);
      Long state = record.getState();
      if (state == null) {
@@ -155,6 +156,8 @@
         record.setUpdatetime(new Date());
         specialMapper.insert(record);
         extra.setId(record.getId());
         Special s = new Special();
         s.setId(record.getId());
         s.setOrderby(Integer.parseInt(s.getId() + ""));
@@ -219,7 +222,12 @@
         record.setUpdatetime(new Date());
         specialMapper.updateByPrimaryKey(record);
         extra.setId(record.getId());
      }
      // 添加补充信息
      specialExtraService.saveExtraInfo(extra);
   }
   /**
@@ -227,30 +235,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, "起始时间不能小于结束时间");
      }
   }
@@ -386,60 +388,84 @@
   }
   @Override
   public List<Special> listQueryByCard(long start, int count, Long card, String key, Integer sex) {
   public List<SpecialVO> listQueryByCard(long start, int count, Long card, String key, Integer sex) {
      List<Special> list = specialMapper.listQueryByCard(start, count, card, key, sex);
      if (list == null || list.size() == 0) {
         return list;
      if (list == null) {
         return null;
      }
      // 跳转链接
       List<SpecialVO> listvo = new ArrayList<SpecialVO>();
      for (Special special : list) {
         Date startTime = special.getStartTime();
         Date endTime = special.getEndTime();
         if (startTime == null && endTime == null) {
            special.setTimeTask(false);
            special.setStartTime_str("");
            special.setEndTime_str("");
         SpecialVO specialVO = new SpecialVO();
         try {
            PropertyUtils.copyProperties(specialVO, special);
         } catch (Exception e) {
            e.printStackTrace();
            continue;
         }
         if (specialVO.getState() != null && specialVO.getState().longValue() == 0) {
            specialVO.setState(1L);
         } else {
            special.setTimeTask(true);
            specialVO.setState(0L);
         }
         Date startTime = specialVO.getStartTime();
         Date endTime = specialVO.getEndTime();
         if (startTime == null && endTime == null) {
            specialVO.setStartTime_str("");
            specialVO.setEndTime_str("");
         } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
            if (startTime == null) {
               special.setStartTime_str("");
               specialVO.setStartTime_str("");
            } else {
               special.setStartTime_str(sdf.format(startTime));
               specialVO.setStartTime_str(sdf.format(startTime));
            }
            if (endTime == null) {
               special.setEndTime_str("");
               specialVO.setEndTime_str("");
            } else {
               special.setEndTime_str(sdf.format(endTime));
               specialVO.setEndTime_str(sdf.format(endTime));
            }
         }
         String params = special.getParams();
         String params = specialVO.getParams();
         if (StringUtil.isNullOrEmpty(params)) {
            special.setParams("");
            specialVO.setParams("");
         }
         String remark = special.getRemark();
         String remark = specialVO.getRemark();
         if (StringUtil.isNullOrEmpty(remark)) {
            special.setRemark("");
            specialVO.setRemark("");
         }
         JumpDetailV2 jumpDetail = special.getJumpDetail();
         JumpDetailV2 jumpDetail = specialVO.getJumpDetail();
         if (jumpDetail == null) {
            // 默认未选择
            JumpDetailV2 jumpDetailV2 = new JumpDetailV2();
            jumpDetailV2.setName("-未选择-");
            jumpDetailV2.setType("default");
            special.setJumpDetail(jumpDetailV2);
            specialVO.setJumpDetail(jumpDetailV2);
         }
         // 补充信息
         SpecialExtra extra = specialExtraService.selectByPrimaryKey(specialVO.getId());
         if (extra == null) {
            specialVO.setNeedSpin(false);
            specialVO.setComment("");
         } else {
            specialVO.setNeedSpin(extra.getNeedSpin());
            if (StringUtil.isNullOrEmpty(extra.getComment())) {
               specialVO.setComment("");
            } else {
               specialVO.setComment(extra.getComment());
            }
         }
         listvo.add(specialVO);
      }
      return list;
      return listvo;
   }
   @Override
@@ -744,6 +770,7 @@
      Special updateObj = new Special();
      updateObj.setId(id);
      updateObj.setState(state);
      updateObj.setJumpLogin(resultObj.isJumpLogin());
      specialMapper.updateByPrimaryKeySelective(updateObj);
   }