From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 18 一月 2020 12:06:27 +0800
Subject: [PATCH] 用户注册信息

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialCardServiceImpl.java |  266 +++++++++++++++++++++++++++++++++++------------------
 1 files changed, 175 insertions(+), 91 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialCardServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialCardServiceImpl.java
index c5c7160..da79d8d 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialCardServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialCardServiceImpl.java
@@ -1,22 +1,27 @@
 package com.yeshi.fanli.service.impl.homemodule;
 
-import java.util.ArrayList;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
+import java.util.UUID;
 
 import javax.annotation.Resource;
-import javax.transaction.Transactional;
 
-import org.apache.commons.beanutils.PropertyUtils;
 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.homemodule.SpecialCardMapper;
-import com.yeshi.fanli.dao.mybatis.homemodule.SuperSpecialCardMapper;
 import com.yeshi.fanli.entity.bus.homemodule.SpecialCard;
-import com.yeshi.fanli.entity.bus.homemodule.SuperSpecialCard;
-import com.yeshi.fanli.entity.system.BusinessSystem;
+import com.yeshi.fanli.entity.bus.homemodule.SpecialPlace;
+import com.yeshi.fanli.exception.homemodule.SpecialCardException;
 import com.yeshi.fanli.service.inter.config.BusinessSystemService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialCardService;
+import com.yeshi.fanli.service.inter.homemodule.SpecialPlaceService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialService;
+import com.yeshi.fanli.util.FilePathEnum;
 
 
 @Service
@@ -32,117 +37,188 @@
 	private SpecialService specialService;
 	
 	@Resource
-	private SuperSpecialCardMapper superSpecialCardMapper;
+	private  SpecialPlaceService specialPlaceService;
+	
 	
 	@Override
-	public int deleteByPrimaryKey(Long id) {
-		return specialCardMapper.deleteByPrimaryKey(id);
+	public void saveObject(MultipartFile file, SpecialCard record) throws SpecialCardException, Exception{
+		
+		String name = record.getName();
+		if (name == null || name.trim().length() == 0) {
+			throw new SpecialCardException(1, "鍚嶇О涓嶈兘涓虹┖");
+		}
+		
+		Long placeId = record.getPlaceId();
+		if (placeId == null || placeId == 0) {
+			throw new SpecialCardException(1, "浣跨敤浣嶇疆涓嶈兘涓虹┖");
+		}
+		
+		// 鏃堕棿浠诲姟鎺у埗
+		conversionTime(record);
+		
+		
+		// 鍥剧墖涓婁紶
+		String picture = null;
+		if (file != null) {
+			picture = uploadPicture(file);
+		}
+		
+		Integer state = record.getState();
+		if (state == null) {
+			record.setState(0);
+		}
+		
+		Long id = record.getId();
+		if (id == null) {
+			record.setBottomPicture(picture);
+			
+			record.setCreatetime(new Date());
+			record.setUpdatetime(new Date());
+			specialCardMapper.insert(record);
+		} else {
+			// 淇敼
+			SpecialCard resultObj = specialCardMapper.selectByPrimaryKey(id);
+			if (resultObj == null) {
+				throw new SpecialCardException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
+			}
+			
+			// 鍒犻櫎鍥剧墖
+			Boolean delPicture = record.getDelPicture();
+			if (delPicture != null && delPicture) {
+				removePicture(resultObj.getBottomPicture());
+				resultObj.setBottomPicture(null);
+			}
+			
+			if (picture != null && picture.trim().length() > 0) {
+				// 鍒犻櫎鑰佸浘
+				removePicture(resultObj.getBottomPicture());
+				// 瀛樺偍鏂板浘
+				record.setBottomPicture(picture);
+			} else {
+				record.setBottomPicture(resultObj.getBottomPicture());
+			}
+			
+			record.setCreatetime(resultObj.getCreatetime());
+			record.setUpdatetime(new Date());
+			specialCardMapper.updateByPrimaryKey(record);
+		}
+	}
+	
+	/**
+	 * web娈垫椂闂磋浆鎹�
+	 * @param record
+	 */
+	public void conversionTime(SpecialCard record) throws SpecialCardException, 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 SpecialCardException(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));
+				}
+			}
+		}
+	}
+	
+	
+	/**
+	 * 涓婁紶鍥剧墖
+	 * @param file
+	 * @return
+	 * @throws Exception
+	 */
+	public String uploadPicture(MultipartFile file) throws Exception {
+		
+		// 鏂囦欢瑙f瀽 
+		InputStream inputStream = file.getInputStream();
+		String contentType = file.getContentType();
+		String type = contentType.substring(contentType.indexOf("/") + 1);
+	
+		// 鏂囦欢璺緞
+		String filePath=FilePathEnum.specialCard.getPath() +UUID.randomUUID().toString().replace("-", "") + "." + type;
+		// 鎵ц涓婁紶
+		String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
+		
+		return fileLink;
 	}
 
-	@Override
-	public int insert(SpecialCard record) {
-		return specialCardMapper.insert(record);
-	}
-
-	@Override
-	public int insertSelective(SpecialCard record) {
-		return specialCardMapper.insertSelective(record);
-	}
-
-	@Override
-	public SpecialCard selectByPrimaryKey(Long id) {
-		return specialCardMapper.selectByPrimaryKey(id);
-	}
-
-	@Override
-	public int updateByPrimaryKeySelective(SpecialCard record) {
-		return specialCardMapper.updateByPrimaryKeySelective(record);
-	}
-
-	@Override
-	public int updateByPrimaryKey(SpecialCard record) {
-		return specialCardMapper.updateByPrimaryKey(record);
+	/**
+	 * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱
+	 * @param record
+	 * @throws Exception
+	 */
+	public void removePicture(String picture) throws Exception {
+		if (picture != null && picture.trim().length() > 0) {
+			COSManager.getInstance().deleteFile(picture);
+		}
 	}
 
 	
 	@Override
-	@Transactional
+	@Transactional(rollbackFor=Exception.class)
 	public int deleteBatchByPrimaryKey(List<Long> list) throws Exception{
-		
 		specialService.deleteBatchByCardID(list);
-		superSpecialCardMapper.deleteBatchByCardId(list);
-		
 		return specialCardMapper.deleteBatchByPrimaryKey(list);
 	}
 	
 	@Override
 	public List<SpecialCard> listQuery(long start, int count, String key, Integer sort) {
 		
-		List<SpecialCard> listObj = specialCardMapper.listQuery(start, count, key, sort);
+		List<SpecialCard> listObj = specialCardMapper.listQuery(start, count, key);
 		if (listObj == null || listObj.size() == 0) {
 			return null;
 		}
 		
-		List<BusinessSystem> systemList = businessSystemService.getBusinessSystems();
-		
-		List<Long> listCardId = new ArrayList<Long>();
 		for (SpecialCard specialCard: listObj) {
-			listCardId.add(specialCard.getId());
-		}
-		
-		List<SuperSpecialCard> listSuper = superSpecialCardMapper.listByCardIDs(listCardId);
-		
-		if (listSuper == null || listSuper.size() == 0) {
+			long totalSpecial= specialService.countlistQueryByCard(specialCard.getId(), null, null);
+			specialCard.setTotalSpecial(totalSpecial);
 			
-			for (SpecialCard specialCard: listObj) {
-				specialCard.setSystemList(systemList);
-			}
-			
-		} else {
-			for (SpecialCard specialCard: listObj) {
+			Date startTime = specialCard.getStartTime();
+			Date endTime = specialCard.getEndTime();
+			if (startTime == null && endTime == null) {
+				specialCard.setTimeTask(false);
+				specialCard.setStartTime_str("");
+				specialCard.setEndTime_str("");
+			} else {
+				specialCard.setTimeTask(true);
 				
-				Long id = specialCard.getId();
-				
-				List<BusinessSystem> newList = new ArrayList<BusinessSystem>();
-				// 鏄惁鏈夊叧鑱旂郴缁熼�夐」
-				for (BusinessSystem dsystem : systemList) {
-					
-					BusinessSystem newsystem = new BusinessSystem();
-					
-					try {
-						PropertyUtils.copyProperties(newsystem, dsystem);
-					} catch (Exception e) {
-						e.printStackTrace();
-					}
-					
-					
-					
-					if (listSuper != null && listSuper.size() > 0) {
-						
-						Long systemId = newsystem.getId();
-						
-						for (SuperSpecialCard superSpecialCard : listSuper) {
-							SpecialCard special = superSpecialCard.getSpecialCard();
-							BusinessSystem system = superSpecialCard.getSystem();
-							
-							// 褰撳墠涓撻 銆佸綋鍓嶇郴缁�
-							if (special != null && system != null && id == special.getId() 
-									&& systemId == system.getId()) {
-								newsystem.setCheck(1);
-								break;
-							}
-						}
-					}
-					
-					if (newsystem.getCheck() != 1) {
-						newsystem.setCheck(0);
-					}
-					
-					newList.add(newsystem);
+				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
+				if (startTime == null) {
+					specialCard.setStartTime_str("");
+				} else {
+					specialCard.setStartTime_str(sdf.format(startTime));
 				}
 				
-				specialCard.setSystemList(newList);
+				if (endTime == null) {
+					specialCard.setEndTime_str("");
+				} else {
+					specialCard.setEndTime_str(sdf.format(endTime));
+				}
 			}
+			
+			Long placeId = specialCard.getPlaceId();
+			if (placeId != null) {
+				SpecialPlace specialPlace = specialPlaceService.selectByPrimaryKey(placeId);
+				if (specialPlace != null) {
+					specialCard.setPlaceName(specialPlace.getName());
+				}
+			}
+			
 		}
 		
 		return listObj;
@@ -152,5 +228,13 @@
 	public long countlistQuery(String key) {
 		return specialCardMapper.countlistQuery(key);
 	}
+	
+	@Override
+	public String getbottomPicture(String placeKey) {
+		return specialCardMapper.getbottomPicture(placeKey);
+	}
+	
+	
+	
 
 }

--
Gitblit v1.8.0