From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/help/HelpClassServiceImpl.java |  596 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 310 insertions(+), 286 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/help/HelpClassServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/help/HelpClassServiceImpl.java
index df529b8..57ad048 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/help/HelpClassServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/help/HelpClassServiceImpl.java
@@ -1,286 +1,310 @@
-package com.yeshi.fanli.service.impl.help;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
-import javax.annotation.Resource;
-
-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.help.HelpClassMapper;
-import com.yeshi.fanli.entity.AppVersionInfo;
-import com.yeshi.fanli.entity.bus.help.HelpClass;
-import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl;
-import com.yeshi.fanli.entity.bus.homemodule.FloatAD;
-import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
-import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
-import com.yeshi.fanli.exception.banner.SwiperPictureException;
-import com.yeshi.fanli.exception.config.HelpClassException;
-import com.yeshi.fanli.exception.homemodule.FloatADException;
-import com.yeshi.fanli.service.inter.help.HelpClassService;
-import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
-import com.yeshi.fanli.util.StringUtil;
-
-@Service
-public class HelpClassServiceImpl implements HelpClassService {
-
-	@Resource
-	private HelpClassMapper helpClassMapper;
-
-	@Resource
-	private AdActivityVersionControlService adActivityVersionControlService;
-	
-	@Override
-	public int deleteByPrimaryKeyBatch(List<Long> list) {
-		return helpClassMapper.deleteByPrimaryKeyBatch(list);
-	}
-
-	@Override
-	public HelpClass selectByPrimaryKey(Long id) {
-		return helpClassMapper.selectByPrimaryKey(id);
-	}
-	
-	@Override
-	public void save(HelpClass record, MultipartFile file) throws HelpClassException, Exception{
-		if (record == null)
-			throw new HelpClassException(1, "鍙傛暟涓嶈兘涓虹┖");
-		
-		String name = record.getName();
-		if (StringUtil.isNullOrEmpty(name))
-			throw new HelpClassException(1, "鍚嶇О涓嶈兘涓虹┖");
-		
-		try {
-			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
-			String startTime_str = record.getStartTime_str();
-			if (startTime_str != null && startTime_str.trim().length() > 0) {
-				startTime_str = startTime_str.replaceAll("T", " ");
-				record.setStartTime(format.parse(startTime_str));
-			}
-			
-			String endTime_str = record.getEndTime_str();
-			if (endTime_str != null && endTime_str.trim().length() > 0) {
-				endTime_str = endTime_str.replaceAll("T", " ");
-				record.setEndTime(format.parse(endTime_str));
-			}
-		} catch (ParseException e) {
-			e.printStackTrace();
-		}
-		
-		// 鍥剧墖涓婁紶
-		String picture = null;
-		if (file != null) {
-			InputStream inputStream = file.getInputStream();
-			String contentType = file.getContentType();
-			String type = contentType.substring(contentType.indexOf("/") + 1);
-			String filePath ="/img/HelpClass/" + UUID.randomUUID().toString().replace("-", "") + "." + type;
-			picture = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
-		}
-				
-		Integer showState = record.getShowState();
-		if (showState == null)
-			record.setShowState(0);
-		
-		record.setUpdateTime(new Date());
-		if (record.getId() == null) {
-			int maxOrder = helpClassMapper.getMaxOrder();
-			record.setSort(maxOrder + 1);
-			record.setCreateTime(new Date());
-			helpClassMapper.insertSelective(record);
-		} else {
-			// 淇敼
-			HelpClass resultObj = helpClassMapper.selectByPrimaryKey(record.getId());
-			if (resultObj == null)
-				throw new FloatADException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
-			
-			if (picture != null && picture.trim().length() > 0) {
-				String pictureOld = resultObj.getPicture();
-				if (pictureOld != null && pictureOld.trim().length() > 0) {
-					COSManager.getInstance().deleteFile(pictureOld);
-				}
-				// 瀛樺偍鏂板浘
-				record.setPicture(picture);
-			} else {
-				record.setPicture(resultObj.getPicture());
-			}
-			
-			record.setSort(resultObj.getSort());
-			record.setCreateTime(resultObj.getCreateTime());
-			helpClassMapper.updateByPrimaryKey(record);
-		}
-	}
-	
-	
-	@Override
-	public int updateShowState(Long id) throws HelpClassException {
-		
-		if (id == null) {
-			throw new HelpClassException(1, "浼犻�掑弬鏁颁笉鑳戒负绌�");
-		}
-		
-		HelpClass helpClass = helpClassMapper.selectByPrimaryKey(id);
-		if (helpClass == null) {
-			throw new HelpClassException(1, "鏇存柊鏁版嵁宸蹭笉瀛樺湪");
-		}
-		
-		Integer showState = helpClass.getShowState();
-		if (showState == null || showState == 0) {
-			showState = 1;
-		} else {
-			showState = 0;
-		}
-		
-		HelpClass help = new HelpClass();
-		help.setId(id);
-		help.setShowState(showState);
-		help.setUpdateTime(new Date());
-		
-		helpClassMapper.updateByPrimaryKeySelective(help);
-		
-		return showState;
-	}
-	
-	
-	@Override
-	public void updateSort(Integer moveType, Long id) throws HelpClassException {
-		
-		if (id == null || moveType == null) {
-			throw new HelpClassException(1, "浼犻�掑弬鏁颁笉鑳戒负绌�");
-		}
-		
-		HelpClass helpClass = helpClassMapper.selectByPrimaryKey(id);
-		if (helpClass == null) {
-			throw new HelpClassException(1, "鏇存柊鏁版嵁宸蹭笉瀛樺湪");
-		}
-		
-		HelpClass changeObjct = helpClassMapper.getChangeOrder(moveType, helpClass.getSort());
-		
-		if (changeObjct == null) {
-			throw new HelpClassException(1, "宸茬粡鏄渶杈圭紭浣嶇疆");
-		} else {
-			Integer changeSort = changeObjct.getSort();
-			
-			// 浜ゆ崲鎺掑簭搴忓彿
-			changeObjct.setSort(helpClass.getSort());
-			helpClassMapper.updateByPrimaryKeySelective(changeObjct);
-			
-			helpClass.setSort(changeSort);
-			helpClassMapper.updateByPrimaryKeySelective(helpClass);
-		}
-	}
-	
-	@Override
-	public void uploadPic(MultipartFile file, Long id) throws HelpClassException, IOException {
-		
-		if (id == null || file == null) {
-			throw new HelpClassException(1, "浼犻�掑弬鏁颁笉鑳戒负绌�");
-		}
-		
-		HelpClass helpClass = helpClassMapper.selectByPrimaryKey(id);
-		if (helpClass == null) {
-			throw new HelpClassException(1, "鏇存柊鏁版嵁宸蹭笉瀛樺湪");
-		}
-		
-		InputStream inputStream = file.getInputStream();
-		String contentType = file.getContentType();
-		String type = contentType.substring(contentType.indexOf("/") + 1);
-		
-		String filePath ="/img/HelpClass/" + UUID.randomUUID().toString().replace("-", "") + "." + type;
-		
-		/*  淇敼鍥剧墖鏃讹紝鍏堝垹闄ゅ凡瀛樺湪鍥剧墖  */
-		String picture = helpClass.getPicture();
-		if (!StringUtil.isNullOrEmpty(picture)) {
-			COSManager.getInstance().deleteFile(picture);
-		}
-		
-		String fileUrl = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
-		
-		/*  鏇存柊鏁版嵁搴撲俊鎭�  */
-		if (!StringUtil.isNullOrEmpty(fileUrl)) {
-			helpClass.setUpdateTime(new Date());
-			helpClass.setPicture(fileUrl);
-			helpClassMapper.updateByPrimaryKeySelective(helpClass);
-		}
-	}
-	
-	
-	@Override
-	public List<HelpClass> query(int start, int count, String key, Integer state)
-			throws HelpClassException {
-		return helpClassMapper.listQuery(start, count, key, state);
-	}
-
-	@Override
-	public long countQuery(String key, Integer state) {
-		return helpClassMapper.countQuery(key, state);
-	}
-	
-	@Override
-	public List<HelpClass> getClassByState(Integer state) throws HelpClassException {
-		return helpClassMapper.getClassByState(state);
-	}
-	
-	@Override
-	public List<HelpClass> getProvidedClass() throws HelpClassException {
-		return helpClassMapper.getProvidedClass();
-	}
-	
-	
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public void setVersions(Long id, List<Long> versions) throws HelpClassException {
-		HelpClass helpClass = helpClassMapper.selectByPrimaryKey(id);
-		if (helpClass == null) {
-			throw new HelpClassException(1, "姝や俊鎭笉瀛樺湪锛岃鍒锋柊閲嶈瘯");
-		}
-
-		Set<Long> oldSet = new HashSet<>();
-		List<AdActivityVersionControl> versionList = adActivityVersionControlService
-				.listByTypeAndSourceId(AdActivityType.helpClass, id);
-		if (versionList != null) {
-			for (AdActivityVersionControl control : versionList)
-				oldSet.add(control.getVersion().getId());
-		}
-
-		Set<Long> newSet = new HashSet<>();
-		for (Long version : versions) {
-			newSet.add(version);
-		}
-
-		Set<Long> delSet = new HashSet<>();
-		delSet.addAll(oldSet);
-		delSet.removeAll(newSet);
-		for (Long versionId : delSet) {
-			adActivityVersionControlService.deleteBySourceAndVersion(id, AdActivityType.helpClass, versionId);
-		}
-
-		Set<Long> addSet = new HashSet<>();
-		addSet.addAll(newSet);
-		addSet.removeAll(oldSet);
-
-		// 娣诲姞鏄犲皠
-		for (Long versionId : addSet) {
-			AdActivityVersionControl control = new AdActivityVersionControl();
-			control.setCreateTime(new Date());
-			control.setSourceId(id);
-			control.setType(AdActivityType.helpClass);
-			control.setVersion(new AppVersionInfo(versionId));
-			try {
-				adActivityVersionControlService.addVersionControl(control);
-			} catch (Exception e) {
-				throw new HelpClassException(2, e.getMessage());
-			}
-		}
-	}
-
-	
-}
+package com.yeshi.fanli.service.impl.help;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+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.help.HelpClassMapper;
+import com.yeshi.fanli.entity.AppVersionInfo;
+import com.yeshi.fanli.entity.bus.help.HelpClass;
+import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl;
+import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
+import com.yeshi.fanli.exception.config.HelpClassException;
+import com.yeshi.fanli.service.inter.help.HelpClassService;
+import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
+import com.yeshi.fanli.util.FilePathEnum;
+import com.yeshi.fanli.util.StringUtil;
+
+@Service
+public class HelpClassServiceImpl implements HelpClassService {
+
+	@Resource
+	private HelpClassMapper helpClassMapper;
+
+	@Resource
+	private AdActivityVersionControlService adActivityVersionControlService;
+	
+	@Override
+	public int deleteByPrimaryKeyBatch(List<Long> list) {
+		return helpClassMapper.deleteByPrimaryKeyBatch(list);
+	}
+
+	@Override
+	public HelpClass selectByPrimaryKey(Long id) {
+		return helpClassMapper.selectByPrimaryKey(id);
+	}
+	
+	@Override
+	public void save(HelpClass record, MultipartFile file) throws HelpClassException, Exception{
+		if (record == null)
+			throw new HelpClassException(1, "鍙傛暟涓嶈兘涓虹┖");
+		
+		String name = record.getName();
+		if (StringUtil.isNullOrEmpty(name))
+			throw new HelpClassException(1, "鍚嶇О涓嶈兘涓虹┖");
+		
+		try {
+			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+			String startTime_str = record.getStartTime_str();
+			if (startTime_str != null && startTime_str.trim().length() > 0) {
+				startTime_str = startTime_str.replaceAll("T", " ");
+				record.setStartTime(format.parse(startTime_str));
+			}
+			
+			String endTime_str = record.getEndTime_str();
+			if (endTime_str != null && endTime_str.trim().length() > 0) {
+				endTime_str = endTime_str.replaceAll("T", " ");
+				record.setEndTime(format.parse(endTime_str));
+			}
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		
+		// 鍥剧墖涓婁紶
+		String picture = null;
+		if (file != null) {
+			InputStream inputStream = file.getInputStream();
+			String contentType = file.getContentType();
+			String type = contentType.substring(contentType.indexOf("/") + 1);
+			String filePath =FilePathEnum.helpClass.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type;
+			picture = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
+		}
+				
+		Integer showState = record.getShowState();
+		if (showState == null)
+			record.setShowState(0);
+		
+		record.setUpdateTime(new Date());
+		if (record.getId() == null) {
+			int maxOrder = helpClassMapper.getMaxOrder();
+			record.setSort(maxOrder + 1);
+			record.setPicture(picture);
+			record.setCreateTime(new Date());
+			helpClassMapper.insertSelective(record);
+		} else {
+			// 淇敼
+			HelpClass resultObj = helpClassMapper.selectByPrimaryKey(record.getId());
+			if (resultObj == null)
+				throw new HelpClassException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
+			
+			if (picture != null && picture.trim().length() > 0) {
+				String pictureOld = resultObj.getPicture();
+				if (pictureOld != null && pictureOld.trim().length() > 0) {
+					COSManager.getInstance().deleteFile(pictureOld);
+				}
+				// 瀛樺偍鏂板浘
+				record.setPicture(picture);
+			} else {
+				record.setPicture(resultObj.getPicture());
+			}
+			
+			record.setSort(resultObj.getSort());
+			record.setCreateTime(resultObj.getCreateTime());
+			helpClassMapper.updateByPrimaryKey(record);
+		}
+	}
+	
+	
+	@Override
+	public void switchState(Long id) throws HelpClassException {
+		if (id == null) {
+			throw new HelpClassException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		
+		HelpClass resultObj = helpClassMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new HelpClassException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Integer state = resultObj.getShowState();
+		if (state == null || state == 0) {
+			state = 1;
+		} else {
+			state = 0;
+		}
+		
+		HelpClass updateObj = new HelpClass();
+		updateObj.setId(id);
+		updateObj.setShowState(state);
+		helpClassMapper.updateByPrimaryKeySelective(updateObj);
+	}
+	
+	
+	@Override
+	public int updateShowState(Long id) throws HelpClassException {
+		
+		if (id == null) {
+			throw new HelpClassException(1, "浼犻�掑弬鏁颁笉鑳戒负绌�");
+		}
+		
+		HelpClass helpClass = helpClassMapper.selectByPrimaryKey(id);
+		if (helpClass == null) {
+			throw new HelpClassException(1, "鏇存柊鏁版嵁宸蹭笉瀛樺湪");
+		}
+		
+		Integer showState = helpClass.getShowState();
+		if (showState == null || showState == 0) {
+			showState = 1;
+		} else {
+			showState = 0;
+		}
+		
+		HelpClass help = new HelpClass();
+		help.setId(id);
+		help.setShowState(showState);
+		help.setUpdateTime(new Date());
+		
+		helpClassMapper.updateByPrimaryKeySelective(help);
+		
+		return showState;
+	}
+	
+	
+	@Override
+	public void updateSort(Integer moveType, Long id, SystemEnum system) throws HelpClassException {
+		
+		if (id == null || moveType == null) {
+			throw new HelpClassException(1, "浼犻�掑弬鏁颁笉鑳戒负绌�");
+		}
+		
+		HelpClass helpClass = helpClassMapper.selectByPrimaryKey(id);
+		if (helpClass == null) {
+			throw new HelpClassException(1, "鏇存柊鏁版嵁宸蹭笉瀛樺湪");
+		}
+		
+		HelpClass changeObjct = helpClassMapper.getChangeOrder(moveType, helpClass.getSort(),system);
+		
+		if (changeObjct == null) {
+			throw new HelpClassException(1, "宸茬粡鏄渶杈圭紭浣嶇疆");
+		} else {
+			Integer changeSort = changeObjct.getSort();
+			
+			// 浜ゆ崲鎺掑簭搴忓彿
+			changeObjct.setSort(helpClass.getSort());
+			helpClassMapper.updateByPrimaryKeySelective(changeObjct);
+			
+			helpClass.setSort(changeSort);
+			helpClassMapper.updateByPrimaryKeySelective(helpClass);
+		}
+	}
+	
+	@Override
+	public void uploadPic(MultipartFile file, Long id) throws HelpClassException, IOException {
+		
+		if (id == null || file == null) {
+			throw new HelpClassException(1, "浼犻�掑弬鏁颁笉鑳戒负绌�");
+		}
+		
+		HelpClass helpClass = helpClassMapper.selectByPrimaryKey(id);
+		if (helpClass == null) {
+			throw new HelpClassException(1, "鏇存柊鏁版嵁宸蹭笉瀛樺湪");
+		}
+		
+		InputStream inputStream = file.getInputStream();
+		String contentType = file.getContentType();
+		String type = contentType.substring(contentType.indexOf("/") + 1);
+		
+		String filePath =FilePathEnum.helpClass.getPath()+ UUID.randomUUID().toString().replace("-", "") + "." + type;
+		
+		/*  淇敼鍥剧墖鏃讹紝鍏堝垹闄ゅ凡瀛樺湪鍥剧墖  */
+		String picture = helpClass.getPicture();
+		if (!StringUtil.isNullOrEmpty(picture)) {
+			COSManager.getInstance().deleteFile(picture);
+		}
+		
+		String fileUrl = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
+		
+		/*  鏇存柊鏁版嵁搴撲俊鎭�  */
+		if (!StringUtil.isNullOrEmpty(fileUrl)) {
+			helpClass.setUpdateTime(new Date());
+			helpClass.setPicture(fileUrl);
+			helpClassMapper.updateByPrimaryKeySelective(helpClass);
+		}
+	}
+	
+	
+	@Override
+	public List<HelpClass> query(int start, int count, String key, Integer state, SystemEnum system)
+			throws HelpClassException {
+		return helpClassMapper.listQuery(start, count, key, state,system);
+	}
+
+	@Override
+	public long countQuery(String key, Integer state, SystemEnum system) {
+		return helpClassMapper.countQuery(key, state,system);
+	}
+	
+	@Override
+	public List<HelpClass> getClassByState(Integer state, SystemEnum system) throws HelpClassException {
+		return helpClassMapper.getClassByState(state,system);
+	}
+	
+	@Override
+	public List<HelpClass> getProvidedClass(SystemEnum system) throws HelpClassException {
+		return helpClassMapper.getProvidedClass(system);
+	}
+	
+	
+	@Transactional(rollbackFor = Exception.class)
+	@Override
+	public void setVersions(Long id, List<Long> versions) throws HelpClassException {
+		HelpClass helpClass = helpClassMapper.selectByPrimaryKey(id);
+		if (helpClass == null) {
+			throw new HelpClassException(1, "姝や俊鎭笉瀛樺湪锛岃鍒锋柊閲嶈瘯");
+		}
+
+		Set<Long> oldSet = new HashSet<>();
+		List<AdActivityVersionControl> versionList = adActivityVersionControlService
+				.listByTypeAndSourceId(AdActivityType.helpClass, id);
+		if (versionList != null) {
+			for (AdActivityVersionControl control : versionList)
+				oldSet.add(control.getVersion().getId());
+		}
+
+		Set<Long> newSet = new HashSet<>();
+		for (Long version : versions) {
+			newSet.add(version);
+		}
+
+		Set<Long> delSet = new HashSet<>();
+		delSet.addAll(oldSet);
+		delSet.removeAll(newSet);
+		for (Long versionId : delSet) {
+			adActivityVersionControlService.deleteBySourceAndVersion(id, AdActivityType.helpClass, versionId);
+		}
+
+		Set<Long> addSet = new HashSet<>();
+		addSet.addAll(newSet);
+		addSet.removeAll(oldSet);
+
+		// 娣诲姞鏄犲皠
+		for (Long versionId : addSet) {
+			AdActivityVersionControl control = new AdActivityVersionControl();
+			control.setCreateTime(new Date());
+			control.setSourceId(id);
+			control.setType(AdActivityType.helpClass);
+			control.setVersion(new AppVersionInfo(versionId));
+			try {
+				adActivityVersionControlService.addVersionControl(control);
+			} catch (Exception e) {
+				throw new HelpClassException(2, e.getMessage());
+			}
+		}
+	}
+
+	
+}

--
Gitblit v1.8.0