| | |
| | | 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.cache.annotation.Cacheable;
|
| | | 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.HomeNavbarMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.homemodule.SuperHomeNavbarMapper;
|
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.SuperHomeNavbar;
|
| | | import com.yeshi.fanli.entity.system.System;
|
| | | import com.yeshi.fanli.service.inter.config.SystemService;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar.NavbarTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.SwiperBanner;
|
| | | import com.yeshi.fanli.exception.homemodule.HomeNavbarException;
|
| | | import com.yeshi.fanli.service.inter.goods.GoodsClassService;
|
| | | import com.yeshi.fanli.service.inter.homemodule.HomeNavbarService;
|
| | | import com.yeshi.fanli.service.inter.homemodule.SwiperBannerService;
|
| | | import com.yeshi.fanli.util.FilePathEnum;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | |
|
| | | @Service
|
| | | public class HomeNavbarServiceImpl implements HomeNavbarService {
|
| | |
|
| | | @Resource
|
| | | private SystemService systemService;
|
| | | @Resource
|
| | | private HomeNavbarMapper homeNavbarMapper;
|
| | | @Resource
|
| | | private SuperHomeNavbarMapper superHomeNavbarMapper;
|
| | |
|
| | |
|
| | | @Override
|
| | | public int deleteByPrimaryKey(Long id) {
|
| | | return homeNavbarMapper.deleteByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int insert(HomeNavbar record) {
|
| | | return homeNavbarMapper.insert(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int insertSelective(HomeNavbar record) {
|
| | | return homeNavbarMapper.insertSelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public HomeNavbar selectByPrimaryKey(Long id) {
|
| | | return homeNavbarMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKeySelective(HomeNavbar record) {
|
| | | return homeNavbarMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKey(HomeNavbar record) {
|
| | | return homeNavbarMapper.updateByPrimaryKey(record);
|
| | | }
|
| | | @Resource
|
| | | private GoodsClassService goodsClassService;
|
| | | |
| | | @Resource
|
| | | private SwiperBannerService swiperBannerService;
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public int deleteBatchByPrimaryKey(List<Long> list) {
|
| | | superHomeNavbarMapper.deleteBatchByNavbarIds(list);
|
| | | if (list == null || list.size() == 0) {
|
| | | return 0;
|
| | | }
|
| | | |
| | | for (Long id: list) {
|
| | | HomeNavbar homeNavbar = homeNavbarMapper.selectByPrimaryKey(id);
|
| | | if (homeNavbar !=null) {
|
| | | // 删除已存在图片 /
|
| | | String picture = homeNavbar.getPicture();
|
| | | if (!StringUtil.isNullOrEmpty(picture)) {
|
| | | COSManager.getInstance().deleteFile(picture);
|
| | | }
|
| | | }
|
| | | }
|
| | | return homeNavbarMapper.deleteBatchByPrimaryKey(list);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getMaxOrder() {
|
| | | return homeNavbarMapper.getMaxOrder();
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public List<HomeNavbar> getChangeOrder(Long id, Integer type, Integer order) {
|
| | | return homeNavbarMapper.getChangeOrder(id, type, order);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<HomeNavbar> listQuery(long start, int count, String key) {
|
| | | public void saveObject(MultipartFile file, HomeNavbar record) throws HomeNavbarException, Exception{
|
| | |
|
| | | List<HomeNavbar> listObj = homeNavbarMapper.listQuery(start, count, key);
|
| | | String name = record.getName();
|
| | | if (name == null || name.trim().length() == 0) {
|
| | | throw new HomeNavbarException(1, "导航名称不能为空");
|
| | | }
|
| | | |
| | | String startTime_str = record.getStartTime_str();
|
| | | if (record.isTimeTask() && (startTime_str == null || startTime_str.length() == 0)) {
|
| | | throw new HomeNavbarException(1, "控制时间不能为空");
|
| | | }
|
| | | |
| | | |
| | | Integer sex = null;
|
| | | NavbarTypeEnum type = record.getType();
|
| | | if (NavbarTypeEnum.category.equals(type)) {
|
| | | Long classId = record.getClassId();
|
| | | if (classId == null) {
|
| | | throw new HomeNavbarException(1, "请选择分类");
|
| | | }
|
| | | |
| | | GoodsClass goodsClass = goodsClassService.getGoodsClass(record.getClassId());
|
| | | if (goodsClass == null) {
|
| | | throw new HomeNavbarException(1, "分类不存在");
|
| | | }
|
| | | sex = goodsClass.getSex();
|
| | | if (sex == null) {
|
| | | throw new HomeNavbarException(1, "分类未指定适用版本");
|
| | | }
|
| | | record.setUrl(null);
|
| | | } else if(NavbarTypeEnum.weex.equals(type) || NavbarTypeEnum.web.equals(type)) {
|
| | | String url = record.getUrl();
|
| | | if (url == null || url.trim().length() == 0) {
|
| | | throw new HomeNavbarException(1, "请输入URl链接");
|
| | | }
|
| | | } else {
|
| | | throw new HomeNavbarException(1, "类型的值不正确");
|
| | | }
|
| | | |
| | | |
| | | Long swiperBannerId = record.getSwiperBannerId();
|
| | | if (swiperBannerId != null && swiperBannerId == 0) {
|
| | | record.setSwiperBannerId(null);
|
| | | }
|
| | | |
| | | // 时间转换
|
| | | conversionTime(record);
|
| | | |
| | | // 图片上传
|
| | | String picture = null;
|
| | | if (file != null) {
|
| | | picture = uploadPicture(file);
|
| | | }
|
| | | |
| | | Boolean isDefault = record.getIsDefault();
|
| | | if (isDefault == null) {
|
| | | record.setIsDefault(false);
|
| | | }
|
| | | |
| | | Boolean isFixed = record.getIsFixed();
|
| | | if (isFixed == null) {
|
| | | record.setIsFixed(false);
|
| | | }
|
| | | |
| | | Long id = record.getId();
|
| | | if (id == null) {
|
| | | record.setPicture(picture);
|
| | | record.setCreatetime(new Date());
|
| | | record.setUpdatetime(new Date());
|
| | | |
| | | Integer state = record.getState();
|
| | | if (state == null) {
|
| | | record.setState(0);
|
| | | }
|
| | | |
| | | record.setOrderby(homeNavbarMapper.getDefaultMaxOrder() + 1);
|
| | | record.setOrderMan(homeNavbarMapper.getManMaxOrder() + 1);
|
| | | record.setOrderWoman(homeNavbarMapper.getWomanMaxOrder() + 1);
|
| | | |
| | | record.setIsFixed(false);//目前无固定项
|
| | | homeNavbarMapper.insert(record);
|
| | | } else {
|
| | | // 修改
|
| | | HomeNavbar resultObj = homeNavbarMapper.selectByPrimaryKey(id);
|
| | | if (resultObj == null) {
|
| | | throw new HomeNavbarException(1, "修改内容已不存在");
|
| | | }
|
| | | |
| | | if (picture != null && picture.trim().length() > 0) {
|
| | | // 删除老图
|
| | | removePicture(resultObj.getPicture());
|
| | | // 存储新图
|
| | | record.setPicture(picture);
|
| | | } else {
|
| | | record.setPicture(resultObj.getPicture());
|
| | | }
|
| | | |
| | | record.setOrderby(resultObj.getOrderby());
|
| | | record.setOrderMan(resultObj.getOrderMan());
|
| | | record.setOrderWoman(resultObj.getOrderWoman());
|
| | | record.setCreatetime(resultObj.getCreatetime());
|
| | | record.setUpdatetime(new Date());
|
| | | record.setIsFixed(false);//目前无固定项
|
| | | homeNavbarMapper.updateByPrimaryKey(record);
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 上传图片
|
| | | * @param file
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | public String uploadPicture(MultipartFile file) throws Exception {
|
| | | // 文件解析 |
| | | InputStream inputStream = file.getInputStream();
|
| | | String contentType = file.getContentType();
|
| | | String type = contentType.substring(contentType.indexOf("/") + 1);
|
| | | |
| | | // 文件路径
|
| | | String filePath= FilePathEnum.homeNavbar.getPath() +UUID.randomUUID().toString().replace("-", "") + "." + type;
|
| | | // 执行上传
|
| | | String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
|
| | | |
| | | return fileLink;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除图片-不更新数据库
|
| | | * @param record
|
| | | * @throws Exception
|
| | | */
|
| | | public void removePicture(String picture) throws Exception {
|
| | | if (picture != null && picture.trim().length() > 0) {
|
| | | COSManager.getInstance().deleteFile(picture);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * web段时间转换
|
| | | * @param record
|
| | | */
|
| | | public void conversionTime(HomeNavbar record) throws HomeNavbarException, 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));
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | @Override
|
| | | public void updateOrder(Long id, Integer moveType, Integer sex) throws HomeNavbarException, Exception{
|
| | |
|
| | | if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
|
| | | throw new HomeNavbarException(1, "传递的类型不正确");
|
| | | }
|
| | | |
| | | if (id == null) {
|
| | | throw new HomeNavbarException(1, "ID不能为空");
|
| | | }
|
| | | |
| | | |
| | | HomeNavbar resultObj = homeNavbarMapper.selectByPrimaryKey(id);
|
| | | if (resultObj == null) {
|
| | | throw new HomeNavbarException(1, "操作数据已不存在");
|
| | | }
|
| | | |
| | | if (sex == null) {
|
| | | sex = GoodsClass.SEX_DEFAULT;
|
| | | }
|
| | | |
| | | HomeNavbar changeObj = null;
|
| | | if (GoodsClass.SEX_ALL == sex || GoodsClass.SEX_DEFAULT == sex) {
|
| | | Integer orderby = resultObj.getOrderby();
|
| | | changeObj = homeNavbarMapper.getDefaultChangeOrder(moveType, orderby);
|
| | | if (changeObj == null ) {
|
| | | throw new HomeNavbarException(1, "已经在最边缘,无可交换的位置");
|
| | | }
|
| | | resultObj.setOrderby(changeObj.getOrderby());
|
| | | changeObj.setOrderby(orderby);
|
| | | } else if (GoodsClass.SEX_MAN == sex) {
|
| | | Integer orderMan = resultObj.getOrderMan();
|
| | | changeObj = homeNavbarMapper.getManChangeOrder(moveType, orderMan);
|
| | | if (changeObj == null ) {
|
| | | throw new HomeNavbarException(1, "已经在最边缘,无可交换的位置");
|
| | | }
|
| | | resultObj.setOrderMan(changeObj.getOrderMan());
|
| | | changeObj.setOrderMan(orderMan);
|
| | | } else if (GoodsClass.SEX_WOMAN == sex) {
|
| | | Integer orderWoman = resultObj.getOrderWoman();
|
| | | changeObj = homeNavbarMapper.getWomanChangeOrder(moveType, orderWoman);
|
| | | if (changeObj == null ) {
|
| | | throw new HomeNavbarException(1, "已经在最边缘,无可交换的位置");
|
| | | }
|
| | | resultObj.setOrderWoman(changeObj.getOrderWoman());
|
| | | changeObj.setOrderWoman(orderWoman);
|
| | | }
|
| | | |
| | | if (changeObj == null ) {
|
| | | throw new HomeNavbarException(1, "无可交换的位置");
|
| | | }
|
| | | |
| | | homeNavbarMapper.updateByPrimaryKeySelective(changeObj);
|
| | | homeNavbarMapper.updateByPrimaryKeySelective(resultObj);
|
| | | }
|
| | |
|
| | |
|
| | | |
| | | @Override
|
| | | public List<HomeNavbar> listQuery(long start, int count, String key, Integer sex) {
|
| | | |
| | | List<HomeNavbar> listObj = homeNavbarMapper.listQuery(start, count, key, sex);
|
| | | if (listObj == null || listObj.size() == 0) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | List<System> systemList = systemService.getSystems();
|
| | | |
| | | List<Long> listId = new ArrayList<Long>();
|
| | | for (HomeNavbar homeNavbar: listObj) {
|
| | | listId.add(homeNavbar.getId());
|
| | | }
|
| | | List<SuperHomeNavbar> listSuper = superHomeNavbarMapper.listByNavbarIds(listId);
|
| | | |
| | | if (listSuper == null || listSuper.size() == 0) {
|
| | | |
| | | for (HomeNavbar homeNavbar: listObj) {
|
| | | homeNavbar.setSystemList(systemList);
|
| | | }
|
| | | |
| | | } else {
|
| | | for (HomeNavbar homeNavbar: listObj) {
|
| | |
|
| | | Long id = homeNavbar.getId();
|
| | | List<System> newList = new ArrayList<System>();
|
| | | Date startTime = homeNavbar.getStartTime();
|
| | | Date endTime = homeNavbar.getEndTime();
|
| | | |
| | | if (startTime == null && endTime == null) {
|
| | | homeNavbar.setTimeTask(false);
|
| | | homeNavbar.setStartTime_str("");
|
| | | homeNavbar.setEndTime_str("");
|
| | | } else {
|
| | | homeNavbar.setTimeTask(true);
|
| | |
|
| | | // 是否有关联系统选项
|
| | | for (System dsystem : systemList) {
|
| | | |
| | | System newsystem = new System();
|
| | | try {
|
| | | PropertyUtils.copyProperties(newsystem, dsystem);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | if (listSuper != null && listSuper.size() > 0) {
|
| | | Long systemId = newsystem.getId();
|
| | | |
| | | for (SuperHomeNavbar superHomeNavbar : listSuper) {
|
| | | HomeNavbar navbar = superHomeNavbar.getHomeNavbar();
|
| | | System system = superHomeNavbar.getSystem();
|
| | | |
| | | // 当前专题 、当前系统
|
| | | if (navbar != null && system != null && id == navbar.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) {
|
| | | homeNavbar.setStartTime_str("");
|
| | | } else {
|
| | | homeNavbar.setStartTime_str(sdf.format(startTime));
|
| | | }
|
| | |
|
| | | homeNavbar.setSystemList(newList);
|
| | | if (endTime == null) {
|
| | | homeNavbar.setEndTime_str("");
|
| | | } else {
|
| | | homeNavbar.setEndTime_str(sdf.format(endTime));
|
| | | }
|
| | | }
|
| | | |
| | | Long classId = homeNavbar.getClassId();
|
| | | if (classId != null) {
|
| | | GoodsClass goodsClass = goodsClassService.selectByPrimaryKey(classId);
|
| | | if(goodsClass != null) {
|
| | | homeNavbar.setClassName(goodsClass.getName());
|
| | | }
|
| | | }
|
| | | |
| | | Long swiperBannerId = homeNavbar.getSwiperBannerId();
|
| | | if (swiperBannerId != null) {
|
| | | SwiperBanner swiperBanner = swiperBannerService.selectByPrimaryKey(swiperBannerId);
|
| | | if(swiperBanner != null) {
|
| | | homeNavbar.setSwiperName(swiperBanner.getTitle());
|
| | | }
|
| | | } else {
|
| | | // 初始化
|
| | | homeNavbar.setSwiperBannerId(0L);
|
| | | }
|
| | | }
|
| | | |
| | | return listObj;
|
| | | }
|
| | | |
| | | @Override
|
| | | public long countlistQuery(String key, Integer sex) {
|
| | | return homeNavbarMapper.countListQuery(key, sex);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countlistQuery(String key) {
|
| | | return homeNavbarMapper.countListQuery(key);
|
| | | @Cacheable(value = "configCache", key = "'listQueryEffectiveNavbar'")
|
| | | public List<HomeNavbar> listQueryEffectiveNavbar() {
|
| | | return homeNavbarMapper.listQueryEffective();
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | @Cacheable(value = "configCache", key = "'listQueryDefaultNavbar-'+#sex")
|
| | | public List<HomeNavbar> listQueryDefaultNavbar(Integer sex) {
|
| | | return homeNavbarMapper.listQueryDefaultNavbar(sex);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | @Cacheable(value = "configCache", key = "'listQueryFixedNavbar'")
|
| | | public List<HomeNavbar> listQueryFixedNavbar() {
|
| | | return homeNavbarMapper.listQueryFixedNavbar();
|
| | | }
|
| | |
|
| | |
|
| | | |
| | | |
| | | @Override
|
| | | public HomeNavbar getEffectiveByClassId(Long classId) {
|
| | | return homeNavbarMapper.getEffectiveByClassId(classId);
|
| | | }
|
| | |
|
| | | }
|