|
|
@@ -0,0 +1,145 @@
|
|
|
+package com.hr.service.impl;
|
|
|
+
|
|
|
+import com.hr.param.IpInterfaceParam;
|
|
|
+import com.hr.param.SwitchStatusParam;
|
|
|
+import com.hr.repository.domain.IpInterfacePO;
|
|
|
+import com.hr.repository.jpa.IpInterfaceRepository;
|
|
|
+import com.hr.service.IpInterfaceService;
|
|
|
+import com.hr.util.SnowflakeIdWorker;
|
|
|
+import com.hr.vo.IpInterfaceVO;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.*;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 接口表;(ip_interface)表服务接口实现类
|
|
|
+ * @author : http://www.yonsum.com
|
|
|
+ * @date : 2025-10-10
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class IpInterfaceServiceImpl implements IpInterfaceService {
|
|
|
+ @Autowired
|
|
|
+ private IpInterfaceRepository ipInterfaceRepository;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过ID查询单条数据
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 实例对象
|
|
|
+ */
|
|
|
+ public IpInterfaceVO queryById(Long id){
|
|
|
+ IpInterfacePO ipInterfacePO = ipInterfaceRepository.queryById(id);
|
|
|
+ IpInterfaceVO ipInterfaceVO = new IpInterfaceVO();
|
|
|
+ if(ipInterfacePO != null){
|
|
|
+ BeanUtils.copyProperties(ipInterfacePO, ipInterfaceVO);
|
|
|
+ return ipInterfaceVO;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<IpInterfaceVO> paginQuery(IpInterfaceParam interfaceParam, Integer current, Integer size) {
|
|
|
+ IpInterfacePO ipInterfacePO = new IpInterfacePO();
|
|
|
+ BeanUtils.copyProperties(interfaceParam, ipInterfacePO);
|
|
|
+ ExampleMatcher matcher = ExampleMatcher.matchingAll()
|
|
|
+ .withIgnoreNullValues() // 忽略 null 字段
|
|
|
+ .withIgnoreCase();
|
|
|
+ Pageable pageAble = PageRequest.of(current, size);
|
|
|
+ Example<IpInterfacePO> example = Example.of(ipInterfacePO, matcher);
|
|
|
+ Page<IpInterfacePO> page = ipInterfaceRepository.findAll(example, pageAble);
|
|
|
+ List<IpInterfaceVO> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ page.getContent().forEach(item -> {
|
|
|
+ IpInterfaceVO vo = new IpInterfaceVO();
|
|
|
+ BeanUtils.copyProperties(item, vo);
|
|
|
+ resultList.add(vo);
|
|
|
+ });
|
|
|
+ Page<IpInterfaceVO> resultPage = new PageImpl(resultList);
|
|
|
+ BeanUtils.copyProperties(page, resultPage);
|
|
|
+ return resultPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增数据
|
|
|
+ *
|
|
|
+ * @param IpInterfacePO 实例对象
|
|
|
+ * @return 实例对象
|
|
|
+ */
|
|
|
+ public void insert(IpInterfacePO IpInterfacePO){
|
|
|
+ ipInterfaceRepository.save(IpInterfacePO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新数据
|
|
|
+ *
|
|
|
+ * @param IpInterfacePO 实例对象
|
|
|
+ * @return 实例对象
|
|
|
+ */
|
|
|
+ public void update(IpInterfacePO IpInterfacePO){
|
|
|
+ ipInterfaceRepository.save(IpInterfacePO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean switchStatus(SwitchStatusParam switchStatusParam) {
|
|
|
+ IpInterfacePO ipInterfacePO = ipInterfaceRepository.queryById(switchStatusParam.getId());
|
|
|
+ if(ipInterfacePO == null){
|
|
|
+ throw new RuntimeException("接口不存在");
|
|
|
+ }
|
|
|
+ ipInterfacePO.setStatus(switchStatusParam.getStatus());
|
|
|
+ ipInterfaceRepository.save(ipInterfacePO);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveOrUpdate(IpInterfaceParam ipInterfaceParam, String username, Long userid) {
|
|
|
+ IpInterfacePO ipInterfacePO ;
|
|
|
+ if(ipInterfaceParam.getId() == null){
|
|
|
+ ipInterfacePO = ipInterfaceRepository.findByInterfaceName(ipInterfaceParam.getInterfaceName());
|
|
|
+ if(ipInterfacePO != null){
|
|
|
+ throw new RuntimeException("接口名称已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ ipInterfacePO = ipInterfaceRepository.findByInterfaceNo(ipInterfaceParam.getInterfaceNo());
|
|
|
+ if(ipInterfacePO != null){
|
|
|
+ throw new RuntimeException("接口编号已存在");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ ipInterfacePO = ipInterfaceRepository.findByInterfaceName(ipInterfaceParam.getInterfaceName());
|
|
|
+ if(ipInterfaceParam != null && ipInterfacePO.getInterfaceName().equals(ipInterfaceParam.getInterfaceName()) && !ipInterfacePO.getId().equals(ipInterfaceParam.getId())){
|
|
|
+ throw new RuntimeException("接口名称已存在");
|
|
|
+ }
|
|
|
+ ipInterfacePO = ipInterfaceRepository.findByInterfaceNo(ipInterfaceParam.getInterfaceNo());
|
|
|
+ if(ipInterfaceParam != null && ipInterfacePO.getInterfaceNo().equals(ipInterfaceParam.getInterfaceNo()) && !ipInterfacePO.getId().equals(ipInterfaceParam.getId())){
|
|
|
+ throw new RuntimeException("接口编号已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ipInterfacePO = new IpInterfacePO();
|
|
|
+ BeanUtils.copyProperties(ipInterfaceParam, ipInterfacePO);
|
|
|
+ if(ipInterfaceParam.getId() == null){
|
|
|
+ ipInterfacePO.setId(SnowflakeIdWorker.nextId());
|
|
|
+ ipInterfacePO.setAddTime(LocalDateTime.now());
|
|
|
+ ipInterfacePO.setAddUserId(userid);
|
|
|
+ ipInterfacePO.setAddUserName(username);
|
|
|
+ }
|
|
|
+ ipInterfacePO.setUpdateTime(LocalDateTime.now());
|
|
|
+ ipInterfacePO.setUpdateUserId(userid);
|
|
|
+ ipInterfacePO.setUpdateUserName(username);
|
|
|
+ ipInterfaceRepository.save(ipInterfacePO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过主键删除数据
|
|
|
+ *
|
|
|
+ * @param iid 主键
|
|
|
+ * @return 是否成功
|
|
|
+ */
|
|
|
+ public boolean deleteById(Long iid){
|
|
|
+ ipInterfaceRepository.deleteById(iid);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|