JobLibraryFactory
package org.springblade.police.joblibrary.factory;import org.springblade.police.joblibrary.service.ConsumerJobLibraryService;import java.util.HashMap;import java.util.Map;/*** 作业库工厂* @author admin*/public class JobLibraryFactory {/*** 作业库作业类型集合*/private static Map<Integer, ConsumerJobLibraryService> jobLibraryServiceMap = new HashMap<>();/*** 作业类型注册到工厂** @param code* @param jobLibraryService*/public static void register(Integer code, ConsumerJobLibraryService jobLibraryService) {if (null != code && !"".equals(code)) {jobLibraryServiceMap.put(code, jobLibraryService);}}/*** 从工厂获取作业类型方法** @param code* @return*/public static ConsumerJobLibraryService get(Integer code) {return jobLibraryServiceMap.get(code);}}
通用service
package org.springblade.police.joblibrary.service;import com.baomidou.mybatisplus.extension.service.IService;import org.springblade.police.joblibrary.entity.JobLibrary;import org.springblade.police.joblibrary.vo.WebJobLibraryVO;/*** @author admin 自定义作业库接口* 0-空中标注 1-航点地图选点(航点飞行) 2-带状航线 3-绕点飞行 4-全景拍摄 5-建图航拍 6-倾斜摄影 7-航点在线录制*/public interface ConsumerJobLibraryService extends IService<JobLibrary> {/*** 作业处理保存数据到作业管理具体实现** @param jobLibrary 作业库* @param object 前端传值对象* @param webJobLibraryVO 作业库响应vo* @return*/WebJobLibraryVO process(JobLibrary jobLibrary, Object object, WebJobLibraryVO webJobLibraryVO);/*** 根据业务关联id删除各作业类型详情** @param busesId* @return*/boolean deleteJobLibraryByBusesId(Long busesId);/*** 根据业务关联id删除各作业类型详情** @param jobLibrary 作业库* @param object 前端传值对象* @return*/boolean updateJobLibraryByBusesId(JobLibrary jobLibrary, Object object);/*** 根据业务关联id查询各作业类型详情** @param busesId* @return*/Object findJobTypeDetailByBusesId(Long busesId);}
接口实现
package org.springblade.police.joblibrary.service.impl;import com.alibaba.fastjson.JSON;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;import lombok.extern.slf4j.Slf4j;import org.springblade.core.tool.api.R;import org.springblade.police.joblibrary.entity.JobLibrary;import org.springblade.police.joblibrary.entity.enums.JobType;import org.springblade.police.joblibrary.factory.JobLibraryFactory;import org.springblade.police.joblibrary.mapper.JobLibraryMapper;import org.springblade.police.joblibrary.service.ConsumerJobLibraryService;import org.springblade.police.joblibrary.service.IJobLibraryService;import org.springblade.police.joblibrary.vo.WebJobLibraryVO;import org.springblade.police.jobtype.controller.AerialPhotographyController;import org.springblade.police.jobtype.dto.AerialPhotographyDTO;import org.springframework.beans.BeanUtils;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import javax.annotation.PostConstruct;import javax.annotation.Resource;import java.util.Objects;/*** @author lxzn 建图航拍实现类*/@Service@Slf4jpublic class AerialPhotoGraphJobLibraryServiceImpl extends ServiceImpl<JobLibraryMapper, JobLibrary> implements ConsumerJobLibraryService {@Resourceprivate IJobLibraryService jobLibraryService;@Resourceprivate AerialPhotographyController aerialPhotographyController;@PostConstructpublic void init() {JobLibraryFactory.register(JobType.FIVE.getCode(), this);}@Override@Transactional(rollbackFor = Exception.class)public WebJobLibraryVO process(JobLibrary jobLibrary, Object object, WebJobLibraryVO webJobLibraryVO) {AerialPhotographyDTO aerialPhotographyDTO = JSON.parseObject(JSON.toJSONString(object), AerialPhotographyDTO.class);//防止数据错存if (Objects.isNull(aerialPhotographyDTO) || Objects.isNull(aerialPhotographyDTO.getAerialPhotographyLatitudeAndLongitudes())) {log.error("传入的建图航拍基础数据与作业类型不匹配!");return null;}//保存参数到建图航拍R<Long> result = aerialPhotographyController.submit(aerialPhotographyDTO);if (result.getData() == null) {log.error("存储建图航拍基础数据异常,存储数据到作业库失败!");return null;}//作业库 关联建图航拍idjobLibrary.setBusinessId(result.getData());boolean save = jobLibraryService.save(jobLibrary);if (save) {//存储数据到作业库成功BeanUtils.copyProperties(jobLibrary, webJobLibraryVO);} else {log.error("存储建图航拍基础数据异常,存储数据到作业库失败!");return null;}return webJobLibraryVO;}@Override@Transactional(rollbackFor = Exception.class)public boolean deleteJobLibraryByBusesId(Long busesId) {return aerialPhotographyController.remove(String.valueOf(busesId)).isSuccess();}@Override@Transactional(rollbackFor = Exception.class)public boolean updateJobLibraryByBusesId(JobLibrary jobLibrary, Object object) {AerialPhotographyDTO aerialPhotographyDTO = JSON.parseObject(JSON.toJSONString(object), AerialPhotographyDTO.class);//修改参数到建图航拍表Long flag = aerialPhotographyController.submit(aerialPhotographyDTO).getData();if (flag == null) {log.error("修改建图航拍基础数据异常,更新数据到作业库失败!");return false;}//更新作业库boolean update = jobLibraryService.updateById(jobLibrary);if (update) {//修改数据到作业库成功return true;} else {log.error("修改建图航拍基础数据异常,修改数据到作业库失败!");return false;}}@Overridepublic Object findJobTypeDetailByBusesId(Long busesId) {return aerialPhotographyController.detail(String.valueOf(busesId));}}
