| package com.zt.modules.sys.service; | 
|   | 
| import cn.hutool.core.convert.Convert; | 
| import com.zt.common.service.BaseService; | 
| import com.zt.core.context.UserContext; | 
| import com.zt.modules.sys.dao.SysMapDao; | 
| import com.zt.modules.sys.dto.MapDto; | 
| import com.zt.modules.sys.model.SysMap; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.springframework.stereotype.Service; | 
|   | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.stream.Collectors; | 
|   | 
| /** | 
|  * SYS_POST_USER | 
|  * | 
|  * @author zt generator | 
|  * @since 1.0.0 2020-06-11 | 
|  */ | 
| @Service | 
| public class SysMapService extends BaseService<SysMapDao, SysMap> { | 
|   | 
|     /** | 
|      * 根据用户ID,获取岗位ID列表 | 
|      */ | 
|   | 
|     public List<MapDto> getMapsDto(Long mainId, String type) { | 
|         return baseDao.getMapsDto(mainId, type); | 
|     } | 
|   | 
|     public List<SysMap> getMaps(Long mainId, String type) { | 
|         return baseDao.getList(mainId, type); | 
|     } | 
|   | 
|     public List<Long> getIdList(Long mainId, String type) { | 
|         List<SysMap> maps = this.getMaps(mainId, type); | 
|         return maps.stream().map(map -> map.getSubId()).collect(Collectors.toList()); | 
|     } | 
|   | 
|     public String getIds(Long mainId, String type) { | 
|         List<SysMap> maps = this.getMaps(mainId, type); | 
|         String result = maps.stream().map(map -> map.getSubId().toString()).collect(Collectors.joining(",")); | 
|         return result; | 
|     } | 
|   | 
|     public void saveOrUpdate(String type, Long mainId, String subIds) { | 
|         baseDao.deleteByMainId(mainId, type); | 
|         if (!StringUtils.isBlank(subIds)) { | 
|             String[] subIdList = subIds.split(","); | 
|             for (String subId : subIdList) { | 
|                 SysMap sysMap = new SysMap(); | 
|                 sysMap.setType(type); | 
|                 sysMap.setMainId(mainId); | 
|                 sysMap.setSubId(Convert.toLong(subId)); | 
|                 sysMap.setIsDelete(0); | 
|                 sysMap.setUpdateDate(new Date()); | 
|                 sysMap.setCreateDate(new Date()); | 
|   | 
|                 sysMap.setUpdater(0L); | 
|                 sysMap.setCreator(0L); | 
|                 baseDao.insert(sysMap); | 
|             } | 
|         } | 
|     } | 
|   | 
|     public void saveOrUpdate(String type, Long mainId, List<Long> subIdList) { | 
|         baseDao.deleteByMainId(mainId, type); | 
|         for (Long subId : subIdList) { | 
|             SysMap sysMap = new SysMap(); | 
|             sysMap.setType(type); | 
|             sysMap.setMainId(mainId); | 
|             sysMap.setSubId(subId); | 
|             sysMap.setIsDelete(0); | 
|             sysMap.setUpdateDate(new Date()); | 
|             sysMap.setCreateDate(new Date()); | 
|   | 
|             sysMap.setUpdater(0L); | 
|             sysMap.setCreator(0L); | 
|             baseDao.insert(sysMap); | 
|         } | 
|     } | 
|   | 
|     public void insertData(String type, Long mainId, String subIds) { | 
|         String[] splitIds = subIds.split(","); | 
|         for (String id : splitIds) { | 
|             Integer num = baseDao.checkItemNum(type, mainId, id); | 
|             if (num>0) | 
|                 continue; | 
|             SysMap sysMap = new SysMap(); | 
|             sysMap.setType(type); | 
|             sysMap.setMainId(mainId); | 
|             sysMap.setSubId(Long.parseLong(id)); | 
|             sysMap.setIsDelete(0); | 
|             sysMap.setUpdateDate(new Date()); | 
|             sysMap.setCreateDate(new Date()); | 
|   | 
|             Long userId = UserContext.getUser().getId(); | 
|             sysMap.setUpdater(userId); | 
|             sysMap.setCreator(userId); | 
|             baseDao.insert(sysMap); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 根据岗位id,删除岗位用户关系 | 
|      * | 
|      * @param postId | 
|      *            岗位id | 
|      */ | 
| //    @Transactional(rollbackFor = Exception.class) | 
| //    public void deleteByPostId(Long postId) { | 
| //        baseDao.delete(new QueryWrapper<SysPostUser>().lambda().eq(SysPostUser::getPostId, postId)); | 
| //    } | 
| } |