| | |
| | | import com.moon.server.entity.all.ResponseMsg; |
| | | import com.moon.server.entity.all.StaticData; |
| | | import com.moon.server.entity.ctrl.PubEntity; |
| | | import com.moon.server.entity.ctrl.RegisterEntity; |
| | | import com.moon.server.entity.data.MetaEntity; |
| | | import com.moon.server.entity.data.MetaPubEntity; |
| | | import com.moon.server.entity.data.PublishEntity; |
| | | import com.moon.server.helper.RestHelper; |
| | | import com.moon.server.helper.StringHelper; |
| | | import com.moon.server.mapper.data.PublishMapper; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.lang.reflect.Field; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 数据发布 |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | | public class PublishService implements PublishMapper { |
| | | @Value("${sys.exportServer}") |
| | | private String exportServer; |
| | | |
| | | @Value("${sys.iisHost}") |
| | | private String iisHost; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | PublishMapper publishMapper; |
| | | |
| | | @Autowired |
| | | FmeService fmeService; |
| | | |
| | | private final static Log log = LogFactory.getLog(PublishService.class); |
| | | |
| | | @Override |
| | | public Integer selectCount(String name) { |
| | | public Integer selectCount(String name, String dircode, String type) { |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | dircode = StringHelper.getRightLike(dircode); |
| | | |
| | | return publishMapper.selectCount(name); |
| | | return publishMapper.selectCount(name, dircode, type); |
| | | } |
| | | |
| | | @Override |
| | | public List<PublishEntity> selectByPage(String name, Integer limit, Integer offset) { |
| | | public List<PublishEntity> selectByPage(String name, String dircode, String type, Integer limit, Integer offset) { |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | dircode = StringHelper.getRightLike(dircode); |
| | | |
| | | return publishMapper.selectByPage(name, limit, offset); |
| | | return publishMapper.selectByPage(name, dircode, type, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<MetaEntity> selectMetasByPubid(Integer pubid) { |
| | | return publishMapper.selectMetasByPubid(pubid); |
| | | } |
| | | |
| | | @Override |
| | | public List<PublishEntity> selectRaster() { |
| | | return publishMapper.selectRaster(); |
| | | } |
| | | |
| | | @Override |
| | | public PublishEntity selectByLayerId(Integer layerId) { |
| | | return publishMapper.selectByLayerId(layerId); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectCodesForDir(String dircode, Integer isDom) { |
| | | return publishMapper.selectCodesForDir(dircode, isDom); |
| | | } |
| | | |
| | | @Override |
| | | public Integer insert(PublishEntity entity) { |
| | | return publishMapper.insert(entity); |
| | | } |
| | |
| | | @Override |
| | | public Integer insertPubDown(Integer pubid, Integer downid, Integer createUser) { |
| | | return publishMapper.insertPubDown(pubid, downid, createUser); |
| | | } |
| | | |
| | | @Override |
| | | public Integer insertMetaPub(MetaPubEntity mp) { |
| | | return publishMapper.insertMetaPub(mp); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return publishMapper.selectMetasByPage(depcode, dircode, verid, types, name, limit, offset); |
| | | } |
| | | |
| | | /** |
| | | * 发送发布请求 |
| | | */ |
| | | public long postForPub(PubEntity entity, String method, HttpServletRequest req) { |
| | | Map<String, Object> map = getMapData(entity); |
| | | |
| | |
| | | return 0; |
| | | } |
| | | |
| | | if (msg.getCount() > 0) { |
| | | serverRegister(msg.getResult(), req); |
| | | } |
| | | |
| | | return msg.getCount(); |
| | | } |
| | | |
| | | /** |
| | | * 获取Map数据 |
| | | */ |
| | | private Map<String, Object> getMapData(PubEntity entity) { |
| | | Map<String, Object> map = new HashMap<>(3); |
| | | |
| | |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 服务注册 |
| | | */ |
| | | private void serverRegister(String ids, HttpServletRequest req) { |
| | | List<PublishEntity> list = selectByIds(ids); |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | public long postForPub(PubEntity entity, String method) { |
| | | Map<String, Object> map = getMapData(entity); |
| | | |
| | | String str = RestHelper.postForRest(exportServer + method, map); |
| | | if (StringHelper.isEmpty(str)) { |
| | | return 0; |
| | | } |
| | | |
| | | for (PublishEntity entity : list) { |
| | | String url = entity.getUrl().replace("{host}", iisHost); |
| | | String type = getServerType(entity); |
| | | |
| | | RegisterEntity reg = fmeService.serverRegister(entity.getName(), url, type, req); |
| | | if (null == reg || StringHelper.isEmpty(reg.getSerialnum())) { |
| | | continue; |
| | | } |
| | | |
| | | fmeService.serverApply(reg.getSerialnum(), entity.getId(), req); |
| | | |
| | | entity.setRegid(reg.getHashid()); |
| | | update(entity); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取服务类型 |
| | | */ |
| | | private String getServerType(PublishEntity entity) { |
| | | switch (entity.getType()) { |
| | | case "DOM": |
| | | return "TMS服务"; |
| | | case "DEM": |
| | | return "三维地形服务"; |
| | | case "mpt": |
| | | return "三维场景服务"; |
| | | default: |
| | | return "三维模型服务"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除多条 |
| | | */ |
| | | public Integer deletes(List<Integer> idList, HttpServletRequest req) { |
| | | String ids = StringHelper.join(idList, ","); |
| | | |
| | | deleteRes(ids, req); |
| | | |
| | | return deletes(ids); |
| | | } |
| | | |
| | | /** |
| | | * 删除资源 |
| | | */ |
| | | private void deleteRes(String ids, HttpServletRequest req) { |
| | | List<PublishEntity> list = selectByIds(ids); |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | ResponseMsg<String> msg = JSON.parseObject(str, ResponseMsg.class); |
| | | if (msg == null || msg.getCode() != StaticData.TWO_HUNDRED) { |
| | | return 0; |
| | | } |
| | | |
| | | for (PublishEntity entity : list) { |
| | | if (StringHelper.isEmpty(entity.getRegid())) { |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | fmeService.deleteRes(entity.getRegid(), req); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | return msg.getCount(); |
| | | } |
| | | } |