| @@ -89,6 +89,12 @@ public class ServiceController extends BaseController { | |||||
| return genericsSuccess(serviceService.getServiceVersion(id)); | return genericsSuccess(serviceService.getServiceVersion(id)); | ||||
| } | } | ||||
| @GetMapping("serviceVersionCompare") | |||||
| @ApiOperation("服务版本版本对比") | |||||
| public GenericsAjaxResult<Map<String, Object>> serviceVersionCompare(@RequestParam("id1") Long id1, @RequestParam("id2") Long id2) throws IllegalAccessException { | |||||
| return genericsSuccess(serviceService.serviceVersionCompare(id1, id2)); | |||||
| } | |||||
| @GetMapping("/serviceVersionList/{id}") | @GetMapping("/serviceVersionList/{id}") | ||||
| @ApiOperation("查询服务版本列表") | @ApiOperation("查询服务版本列表") | ||||
| public GenericsAjaxResult<List<ServiceVersion>> serviceVersionList(@PathVariable("id") Long id) { | public GenericsAjaxResult<List<ServiceVersion>> serviceVersionList(@PathVariable("id") Long id) { | ||||
| @@ -28,6 +28,8 @@ public interface ServiceService { | |||||
| ServiceVersionVo getServiceVersion(Long id); | ServiceVersionVo getServiceVersion(Long id); | ||||
| Map<String, Object> serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException; | |||||
| String deleteService(Long id); | String deleteService(Long id); | ||||
| String deleteServiceVersion(Long id); | String deleteServiceVersion(Long id); | ||||
| @@ -7,6 +7,7 @@ import com.ruoyi.platform.constant.Constant; | |||||
| import com.ruoyi.platform.domain.ServiceVersion; | import com.ruoyi.platform.domain.ServiceVersion; | ||||
| import com.ruoyi.platform.mapper.ServiceDao; | import com.ruoyi.platform.mapper.ServiceDao; | ||||
| import com.ruoyi.platform.service.ServiceService; | import com.ruoyi.platform.service.ServiceService; | ||||
| import com.ruoyi.platform.utils.ConvertUtil; | |||||
| import com.ruoyi.platform.utils.HttpUtils; | import com.ruoyi.platform.utils.HttpUtils; | ||||
| import com.ruoyi.platform.utils.JacksonUtil; | import com.ruoyi.platform.utils.JacksonUtil; | ||||
| import com.ruoyi.platform.vo.serviceVos.ServiceCodeConfigVo; | import com.ruoyi.platform.vo.serviceVos.ServiceCodeConfigVo; | ||||
| @@ -157,6 +158,28 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| return serviceVersionVo; | return serviceVersionVo; | ||||
| } | } | ||||
| @Override | |||||
| public Map<String, Object> serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException { | |||||
| HashMap<String, Object> result = new HashMap<>(); | |||||
| ServiceVersion serviceVersion1 = serviceDao.getServiceVersionById(id1); | |||||
| ServiceVersion serviceVersion2 = serviceDao.getServiceVersionById(id2); | |||||
| com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(serviceVersion1.getServiceId()); | |||||
| ServiceVersionVo serviceVersionVo1 = getServiceVersionVo(serviceVersion1); | |||||
| ServiceVersionVo serviceVersionVo2 = getServiceVersionVo(serviceVersion1); | |||||
| serviceVersionVo1.setServiceName(service.getServiceName()); | |||||
| serviceVersionVo2.setServiceName(service.getServiceName()); | |||||
| Map<String, String> compareMap = ConvertUtil.compareObjects(serviceVersion1, serviceVersion2); | |||||
| result.put("version1", serviceVersionVo1); | |||||
| result.put("version2", serviceVersionVo2); | |||||
| result.put("differences", compareMap); | |||||
| return result; | |||||
| } | |||||
| @Override | @Override | ||||
| public String deleteService(Long id) { | public String deleteService(Long id) { | ||||
| com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(id); | com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(id); | ||||
| @@ -158,5 +158,29 @@ public class ConvertUtil { | |||||
| } | } | ||||
| return sb.toString(); | return sb.toString(); | ||||
| } | } | ||||
| public static Map<String, String> compareObjects(Object obj1, Object obj2) throws IllegalAccessException { | |||||
| Map<String, String> differences = new HashMap<>(); | |||||
| // Get the class of the first object | |||||
| Class<?> clazz = obj1.getClass(); | |||||
| // Iterate over all fields of the class | |||||
| for (Field field : clazz.getDeclaredFields()) { | |||||
| // Set the fields to be accessible | |||||
| field.setAccessible(true); | |||||
| // Get the field value from both objects | |||||
| Object value1 = field.get(obj1); | |||||
| Object value2 = field.get(obj2); | |||||
| // Compare the field values | |||||
| if ((value1 !=null && !value1.equals(value2)) || (value2 !=null && !value2.equals(value1))) { | |||||
| differences.put(field.getName(), "Field " + field.getName() + " differs: " + value1 + " vs " + value2); | |||||
| } | |||||
| } | |||||
| return differences; | |||||
| } | |||||
| } | } | ||||