| | |
| | | package com.yeshi.fanli.service.impl.homemodule;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import java.io.InputStream;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.transaction.Transactional;
|
| | |
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.homemodule.SpecialMapper;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.Special;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.SpecialPlace;
|
| | | import com.yeshi.fanli.service.inter.homemodule.SpecialPlaceService;
|
| | | import com.yeshi.fanli.service.inter.homemodule.SpecialService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | |
|
| | | @Service
|
| | |
| | |
|
| | | @Resource
|
| | | private SpecialMapper specialMapper;
|
| | | |
| | | @Resource
|
| | | private SpecialPlaceService specialPlaceService;
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | public int updateByPrimaryKey(Special record) {
|
| | | return specialMapper.updateByPrimaryKey(record);
|
| | | }
|
| | | |
| | | @Override
|
| | | @Transactional
|
| | | public int deleteBatchByPrimaryKey(List<Long> list) throws Exception{
|
| | | |
| | | List<Special> listSpecial = specialMapper.queryByListPrimaryKey(list);
|
| | | for (Special special: listSpecial) {
|
| | | String src = special.getPicture();
|
| | | if (!StringUtil.isNullOrEmpty(src)) {
|
| | | COSManager.getInstance().deleteFile(src);
|
| | | }
|
| | | }
|
| | | |
| | | return specialMapper.deleteBatchByPrimaryKey(list);
|
| | | }
|
| | | |
| | | @Override
|
| | | public int deleteBatchByCardID(List<Long> list) throws Exception{
|
| | | List<Special> listSpecial = specialMapper.queryByListCardID(list);
|
| | | for (Special special: listSpecial) {
|
| | | String src = special.getPicture();
|
| | | if (!StringUtil.isNullOrEmpty(src)) {
|
| | | COSManager.getInstance().deleteFile(src);
|
| | | }
|
| | | }
|
| | | |
| | | return specialMapper.deleteBatchByCardID(list);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<Special> listQueryByCard(long start, int count, Long card, String key){
|
| | | return specialMapper.listQueryByCard(start, count, card, key);
|
| | | }
|
| | | |
| | | @Override
|
| | | public long countlistQueryByCard(Long card, String key) {
|
| | | return specialMapper.countlistQueryByCard(card, key);
|
| | | }
|
| | | |
| | | @Override
|
| | | public List<Special> getOrderByCardID(Long cardId, Integer type, Integer order) {
|
| | | return specialMapper.getOrderByCardID(cardId, type, order);
|
| | | }
|
| | | |
| | | @Override
|
| | | public int getMaxOrderByCard(Long card) {
|
| | | return specialMapper.getMaxOrderByCard(card);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Cacheable(value = "configCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId")
|
| | | public List<Special> listBySystemAndCard(String card, Long systemId) {
|
| | | return specialMapper.listBySystemAndCard(card, systemId);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | @Cacheable(value = "configCache", key = "'listPageBySystemAndCard-'+#start+'-'+#count+'-'+#card+'-'+#systemId")
|
| | | public List<Special> listPageBySystemAndCard(long start, int count, String card, Long systemId) {
|
| | | return specialMapper.listPageBySystemAndCard(start, count, card, systemId);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | @Cacheable(value = "configCache", key = "'getSpecialListCache-'+#card+'-'+#systemId")
|
| | | public JSONObject getSpecialListCache(String card, Long systemId) throws Exception{
|
| | | |
| | | // 两行圆形专题
|
| | | List<Special> arcList = new ArrayList<Special>();
|
| | | // 活动列表
|
| | | List<Special> activityList = new ArrayList<Special>();
|
| | | // 方块部分
|
| | | List<Special> blockList = new ArrayList<Special>();
|
| | | |
| | | |
| | | List<Special> list = specialMapper.listBySystemAndCard(card, systemId);
|
| | | if (list != null && list.size() > 0) {
|
| | | for (Special special : list) {
|
| | | if (Special.SHOWTYPE_ARC.equals(special.getShowType())) {
|
| | | // 两行圆形专题
|
| | | arcList.add(special);
|
| | | } else if (Special.SHOWTYPE_BLOCK.equals(special.getShowType())) {
|
| | | // 方块部分
|
| | | blockList.add(special);
|
| | | } else if (Special.SHOWTYPE_ACTIVITY.equals(special.getShowType())) {
|
| | | // 动态
|
| | | activityList.add(special);
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | JSONObject arcMap = new JSONObject();
|
| | | arcMap.put("list", JsonUtil.getApiCommonGson().toJson(arcList));
|
| | | |
| | | JSONObject activityMap = new JSONObject();
|
| | | activityMap.put("list", JsonUtil.getApiCommonGson().toJson(activityList));
|
| | | |
| | | JSONObject blockJsonMap = new JSONObject();
|
| | | blockJsonMap.put("list", JsonUtil.getApiCommonGson().toJson(blockList));
|
| | | |
| | | // 背景图片
|
| | | List<SpecialPlace> listPlace = specialPlaceService.getList();
|
| | | if (listPlace != null && listPlace.size() > 0) {
|
| | | for (SpecialPlace specialPlace: listPlace) {
|
| | | String bottomPicture = specialPlace.getBottomPicture();
|
| | | if (bottomPicture != null && bottomPicture.trim().length() > 0) {
|
| | | if (Special.SHOWTYPE_ARC.equals(specialPlace.getKey())) {
|
| | | arcMap.put("bottomPicture", bottomPicture);
|
| | | } else if (Special.SHOWTYPE_BLOCK.equals(specialPlace.getKey())) {
|
| | | blockJsonMap.put("bottomPicture", bottomPicture);
|
| | | } else if (Special.SHOWTYPE_ACTIVITY.equals(specialPlace.getKey())) {
|
| | | activityMap.put("bottomPicture", bottomPicture);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | JSONObject rootMap = new JSONObject();
|
| | | rootMap.put("arcArea", arcMap);
|
| | | rootMap.put("activityArea", activityMap);
|
| | | rootMap.put("blockArea", blockJsonMap);
|
| | | |
| | | return rootMap;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public void uploadPicture(MultipartFile file, Special record, Long cardId) throws Exception {
|
| | | |
| | | InputStream inputStream = file.getInputStream();
|
| | | String contentType = file.getContentType();
|
| | | String type = contentType.substring(contentType.indexOf("/") + 1);
|
| | | // 上传文件相对位置
|
| | | String fileUrl="SpecialPic/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
|
| | | |
| | | /* 修改图片时,先删除已存在图片 */
|
| | | if (record != null) { |
| | | String src = record.getPicture();
|
| | | if (!StringUtil.isNullOrEmpty(src)) {
|
| | | COSManager.getInstance().deleteFile(src);
|
| | | }
|
| | | }
|
| | | |
| | | String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
|
| | | |
| | | /* 更新数据库信息 */
|
| | | if (!StringUtil.isNullOrEmpty(uploadFilePath)) {
|
| | | |
| | | if (record != null) {
|
| | | record.setUpdatetime(new Date());
|
| | | record.setPicture(uploadFilePath);
|
| | | updateByPrimaryKeySelective(record);
|
| | | } else {
|
| | | record = new Special();
|
| | | record.setPicture(uploadFilePath);
|
| | | record.setCreatetime(new Date());
|
| | | record.setUpdatetime(new Date());
|
| | | record.setCardId(cardId);
|
| | | record.setState(0L);
|
| | | |
| | | int maxOrder = getMaxOrderByCard(cardId);
|
| | | record.setOrderby(maxOrder + 1);
|
| | | record.setShowType("default");
|
| | | insertSelective(record);
|
| | | }
|
| | | |
| | | }
|
| | | }
|
| | |
|
| | | |
| | | }
|