| package com.xzx.gc.system.service;  | 
|   | 
| import cn.hutool.core.date.DateUtil;  | 
| import com.github.pagehelper.PageHelper;  | 
| import com.github.pagehelper.PageInfo;  | 
| import com.xzx.gc.entity.CityPartner;  | 
| import com.xzx.gc.entity.CoreUser;  | 
| import com.xzx.gc.model.JsonResult;  | 
| import com.xzx.gc.model.admin.BannerModel;  | 
| import com.xzx.gc.system.mapper.BannerMapper;  | 
| import com.xzx.gc.util.SessionUtil;  | 
| import lombok.extern.slf4j.Slf4j;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.stereotype.Service;  | 
| import org.springframework.transaction.annotation.Transactional;  | 
|   | 
| import java.util.HashMap;  | 
| import java.util.List;  | 
| import java.util.Map;  | 
|   | 
| @Slf4j  | 
| @Transactional  | 
| @Service  | 
| public class BannerService {  | 
|       | 
|     @Autowired  | 
|     private BannerMapper bannerMapper;  | 
|       | 
|     @Autowired  | 
|     private SessionUtil sessionUtil;  | 
|   | 
|     @Autowired  | 
|     private CityPartnerService cityPartnerService;  | 
|       | 
|     /**  | 
|      * 查询  | 
|      *  | 
|      * @param bannerModel  | 
|      * @return  | 
|      */  | 
|     public Map<String, Object> queryBannerApiList(BannerModel bannerModel) {  | 
|         Map<String, Object> map = new HashMap<>();  | 
|         PageHelper.startPage(bannerModel.getPage(), bannerModel.getLimit());  | 
|         List<BannerModel> bannerModels = bannerMapper.queryBannerList(bannerModel);  | 
|         PageInfo<BannerModel> pageInfo = new PageInfo<>(bannerModels);  | 
|         map.put("data", bannerModels);  | 
|         map.put("count", pageInfo.getTotal());  | 
|         map.put("code", 0);  | 
|         return map;  | 
|     }  | 
|   | 
|     /**  | 
|      * 添加  | 
|      *  | 
|      * @param bannerModel  | 
|      * @return  | 
|      */  | 
|     public JsonResult insertBannerApi(BannerModel bannerModel) {  | 
|         CoreUser user = sessionUtil.getCurrentUser();  | 
|         CityPartner partner = cityPartnerService.queryById(user.getId());  | 
|         if (null != partner) {  | 
|             bannerModel.setPartnerId(user.getId() + "");  | 
|         } else {  | 
|             if (null != bannerModel.getCityId() && !"".equals(bannerModel.getCityId())) {  | 
|                 partner = cityPartnerService.queryCityPartnerByCityId(bannerModel.getCityId());  | 
|                 if (null != partner) {  | 
|                     bannerModel.setPartnerId(partner.getId() + "");  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         bannerModel.setCreateTime(DateUtil.now());  | 
|         if (bannerMapper.insertBanner(bannerModel) > 0) {  | 
|             return JsonResult.success();  | 
|         } else {  | 
|             return JsonResult.failMessage("保存失败");  | 
|         }  | 
|     }  | 
|   | 
|     /**  | 
|      * 更新  | 
|      *  | 
|      * @param bannerModel  | 
|      * @return  | 
|      */  | 
|     public int updateBannerApi(BannerModel bannerModel) {  | 
|         return bannerMapper.updateBanner(bannerModel);  | 
|     }  | 
|   | 
|     /**  | 
|      * 删除  | 
|      *  | 
|      * @param id  | 
|      * @return  | 
|      */  | 
|     public int delBannerApi(String id) {  | 
|         return bannerMapper.delBanner(id);  | 
|     }  | 
|       | 
| }  |