85 changed files with 6593 additions and 924 deletions
@ -0,0 +1,98 @@ |
|||
package com.zc.business.controller; |
|||
|
|||
import java.util.List; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.PutMapping; |
|||
import org.springframework.web.bind.annotation.DeleteMapping; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import com.ruoyi.common.annotation.Log; |
|||
import com.ruoyi.common.core.controller.BaseController; |
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.ruoyi.common.enums.BusinessType; |
|||
import com.zc.business.domain.DcEventImportant; |
|||
import com.zc.business.service.IDcEventImportantService; |
|||
import com.ruoyi.common.utils.poi.ExcelUtil; |
|||
import com.ruoyi.common.core.page.TableDataInfo; |
|||
|
|||
/** |
|||
* 事件侧重要素Controller |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-11 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/business/eventImportant") |
|||
public class DcEventImportantController extends BaseController |
|||
{ |
|||
@Autowired |
|||
private IDcEventImportantService dcEventImportantService; |
|||
|
|||
/** |
|||
* 查询事件侧重要素列表 |
|||
*/ |
|||
@GetMapping("/list") |
|||
public TableDataInfo list(DcEventImportant dcEventImportant) |
|||
{ |
|||
startPage(); |
|||
List<DcEventImportant> list = dcEventImportantService.selectDcEventImportantList(dcEventImportant); |
|||
return getDataTable(list); |
|||
} |
|||
|
|||
/** |
|||
* 导出事件侧重要素列表 |
|||
*/ |
|||
@Log(title = "事件侧重要素", businessType = BusinessType.EXPORT) |
|||
@PostMapping("/export") |
|||
public void export(HttpServletResponse response, DcEventImportant dcEventImportant) |
|||
{ |
|||
List<DcEventImportant> list = dcEventImportantService.selectDcEventImportantList(dcEventImportant); |
|||
ExcelUtil<DcEventImportant> util = new ExcelUtil<>(DcEventImportant.class); |
|||
util.exportExcel(response, list, "事件侧重要素数据"); |
|||
} |
|||
|
|||
/** |
|||
* 获取事件侧重要素详细信息 |
|||
*/ |
|||
@GetMapping(value = "/{id}") |
|||
public AjaxResult getInfo(@PathVariable("id") String id) |
|||
{ |
|||
return AjaxResult.success(dcEventImportantService.selectDcEventImportantByEventId(id)); |
|||
} |
|||
|
|||
/** |
|||
* 新增事件侧重要素 |
|||
*/ |
|||
@Log(title = "事件侧重要素", businessType = BusinessType.INSERT) |
|||
@PostMapping |
|||
public AjaxResult add(@RequestBody DcEventImportant dcEventImportant) |
|||
{ |
|||
return toAjax(dcEventImportantService.insertDcEventImportant(dcEventImportant)); |
|||
} |
|||
|
|||
/** |
|||
* 修改事件侧重要素 |
|||
*/ |
|||
@Log(title = "事件侧重要素", businessType = BusinessType.UPDATE) |
|||
@PutMapping |
|||
public AjaxResult edit(@RequestBody DcEventImportant dcEventImportant) |
|||
{ |
|||
return toAjax(dcEventImportantService.updateDcEventImportant(dcEventImportant)); |
|||
} |
|||
|
|||
/** |
|||
* 删除事件侧重要素 |
|||
*/ |
|||
@Log(title = "事件侧重要素", businessType = BusinessType.DELETE) |
|||
@DeleteMapping("/{ids}") |
|||
public AjaxResult remove(@PathVariable String[] ids) |
|||
{ |
|||
return toAjax(dcEventImportantService.deleteDcEventImportantByEventIds(ids)); |
|||
} |
|||
} |
@ -0,0 +1,174 @@ |
|||
package com.zc.business.controller; |
|||
|
|||
import java.io.*; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
|
|||
import com.zc.business.utils.PoiUtil; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.poi.xwpf.usermodel.XWPFDocument; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.PutMapping; |
|||
import org.springframework.web.bind.annotation.DeleteMapping; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import com.ruoyi.common.annotation.Log; |
|||
import com.ruoyi.common.core.controller.BaseController; |
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.ruoyi.common.enums.BusinessType; |
|||
import com.zc.business.domain.DcEventImportantFile; |
|||
import com.zc.business.service.IDcEventImportantFileService; |
|||
import com.ruoyi.common.utils.poi.ExcelUtil; |
|||
import com.ruoyi.common.core.page.TableDataInfo; |
|||
|
|||
/** |
|||
* 重要事件文件内容Controller |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-12 |
|||
*/ |
|||
@Api(tags = "重要事件文件内容") |
|||
@RestController |
|||
@RequestMapping("/business/eventImportantFile") |
|||
public class DcEventImportantFileController extends BaseController |
|||
{ |
|||
@Autowired |
|||
private IDcEventImportantFileService dcEventImportantFileService; |
|||
|
|||
/** |
|||
* 分页查询重要事件文件内容 |
|||
*/ |
|||
@ApiOperation("分页查询重要事件文件内容") |
|||
@GetMapping("/page") |
|||
public TableDataInfo page(DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
startPage(); |
|||
List<DcEventImportantFile> list = dcEventImportantFileService.selectDcEventImportantFileList(dcEventImportantFile); |
|||
return getDataTable(list); |
|||
} |
|||
|
|||
/** |
|||
* 无分页查询重要事件文件内容列表 |
|||
*/ |
|||
@ApiOperation("无分页查询重要事件文件内容列表") |
|||
@GetMapping("/list") |
|||
public List<DcEventImportantFile> list(DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
return dcEventImportantFileService.selectDcEventImportantFileList(dcEventImportantFile); |
|||
} |
|||
|
|||
/** |
|||
* 导出重要事件文件内容列表 |
|||
*/ |
|||
@Log(title = "重要事件文件内容", businessType = BusinessType.EXPORT) |
|||
@PostMapping("/export") |
|||
public void export(HttpServletResponse response, DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
List<DcEventImportantFile> list = dcEventImportantFileService.selectDcEventImportantFileList(dcEventImportantFile); |
|||
ExcelUtil<DcEventImportantFile> util = new ExcelUtil<>(DcEventImportantFile.class); |
|||
util.exportExcel(response, list, "重要事件文件内容数据"); |
|||
} |
|||
|
|||
/** |
|||
* 下载重要事件文件 |
|||
*/ |
|||
@ApiOperation("下载重要事件文件") |
|||
@Log(title = "下载重要事件文件", businessType = BusinessType.EXPORT) |
|||
@PostMapping("/download") |
|||
public void download(HttpServletResponse response, DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wordTemplate/importantTemplate.docx"); |
|||
|
|||
XWPFDocument document = null; |
|||
try { |
|||
|
|||
|
|||
//获取docx解析对象
|
|||
document = new XWPFDocument(inputStream); |
|||
Map<String,Object> textMap = new HashMap<>(); |
|||
textMap.put("${fromDept}",dcEventImportantFile.getFromDept()); |
|||
textMap.put("${createTime}",dcEventImportantFile.getCreateTime()); |
|||
textMap.put("${title}",dcEventImportantFile.getTitle()); |
|||
textMap.put("${toDept}",dcEventImportantFile.getToDept()); |
|||
textMap.put("${content}",dcEventImportantFile.getContent()); |
|||
textMap.put("${createName}",dcEventImportantFile.getCreateName()); |
|||
textMap.put("${phoneNumber}",dcEventImportantFile.getPhoneNumber()); |
|||
textMap.put("${issued}",dcEventImportantFile.getIssued()); |
|||
|
|||
//解析替换文本段落对象
|
|||
PoiUtil.changeText(document, textMap); |
|||
|
|||
document.write(response.getOutputStream()); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
}finally { |
|||
if (inputStream != null) { |
|||
try { |
|||
inputStream.close(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 获取重要事件文件内容详细信息 |
|||
*/ |
|||
@ApiOperation("获取重要事件文件内容详细信息") |
|||
@GetMapping(value = "/{id}") |
|||
public AjaxResult getInfo(@PathVariable("id") String id) |
|||
{ |
|||
return AjaxResult.success(dcEventImportantFileService.selectDcEventImportantFileByEventId(id)); |
|||
} |
|||
|
|||
/** |
|||
* 新增重要事件文件内容 |
|||
*/ |
|||
@ApiOperation("新增重要事件文件内容") |
|||
@Log(title = "重要事件文件内容", businessType = BusinessType.INSERT) |
|||
@PostMapping |
|||
public AjaxResult add(@RequestBody DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
return toAjax(dcEventImportantFileService.insertDcEventImportantFile(dcEventImportantFile)); |
|||
} |
|||
|
|||
/** |
|||
* 修改重要事件文件内容 |
|||
*/ |
|||
@ApiOperation("修改重要事件文件内容") |
|||
@Log(title = "重要事件文件内容", businessType = BusinessType.UPDATE) |
|||
@PutMapping |
|||
public AjaxResult edit(@RequestBody DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
return toAjax(dcEventImportantFileService.updateDcEventImportantFile(dcEventImportantFile)); |
|||
} |
|||
|
|||
/** |
|||
* 删除重要事件文件内容 |
|||
*/ |
|||
@ApiOperation("删除重要事件文件内容") |
|||
@Log(title = "重要事件文件内容", businessType = BusinessType.DELETE) |
|||
@DeleteMapping("/{ids}") |
|||
public AjaxResult remove(@PathVariable String[] ids) |
|||
{ |
|||
return toAjax(dcEventImportantFileService.deleteDcEventImportantFileByEventIds(ids)); |
|||
} |
|||
|
|||
/** |
|||
* 获取重要事件状态 |
|||
*/ |
|||
@ApiOperation("获取重要事件状态") |
|||
@GetMapping("/getImportantFileStatus/{eventId}") |
|||
public AjaxResult getImportantFileStatus(@PathVariable("eventId") String eventId){ |
|||
return dcEventImportantFileService.getImportantFileStatus(eventId); |
|||
} |
|||
} |
@ -0,0 +1,103 @@ |
|||
package com.zc.business.controller; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.ruoyi.common.core.controller.BaseController; |
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.zc.business.domain.DcWarning; |
|||
import com.zc.business.service.IMsmService; |
|||
import com.zc.business.utils.HttpUtil; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.omg.CORBA.INTERNAL; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.lang.reflect.Array; |
|||
import java.rmi.MarshalledObject; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
|
|||
/** |
|||
* 王思祥 |
|||
* 推送业务 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/business/sms") |
|||
public class MsmController extends BaseController { |
|||
@Autowired |
|||
private IMsmService msmService; |
|||
|
|||
/** |
|||
* 短信推送业务,阿里云短信业务 |
|||
*/ |
|||
@PostMapping("/push") |
|||
public Boolean alibabaCloudSms(@RequestBody HashMap map) |
|||
{ |
|||
String type = map.get("type").toString(); |
|||
if (map==null|| StringUtils.isBlank(map.get("phone").toString())){ |
|||
return false; |
|||
} |
|||
String string = map.get("phone").toString(); |
|||
return msmService.send(string); |
|||
} |
|||
|
|||
//调用微信推送
|
|||
@PostMapping("/wenXinPush") |
|||
public AjaxResult commandAndDispatch(@RequestBody HashMap map){ |
|||
return AjaxResult.success(msmService.wenXinSend("wx9ee0e3babfd8d2af","de2ecb80b30d63135918ba3ae6ffb711")); |
|||
} |
|||
//整合推送
|
|||
@PostMapping("/pushAll") |
|||
public AjaxResult pushAll(@RequestBody HashMap map) |
|||
{ |
|||
if (map == null || StringUtils.isBlank(map.get("type").toString())) { |
|||
return AjaxResult.error("参数错误"); |
|||
} |
|||
ArrayList<String> array = (ArrayList<String>) map.get("type"); |
|||
Boolean send = null; |
|||
Integer data = null; |
|||
String weiXin = "微信推送失败"; // 初始化为成功状态
|
|||
String message = "短信推送失败"; // 初始化为失败状态
|
|||
for (String type : array) { |
|||
if ("1".equals(type)) { //短信
|
|||
if (map == null || StringUtils.isBlank(map.get("phone").toString())) { |
|||
return AjaxResult.error("手机号为空"); |
|||
} |
|||
String string = map.get("phone").toString(); |
|||
send = msmService.send(string); |
|||
continue; |
|||
} |
|||
if ("2".equals(type)) { //微信
|
|||
JSONArray objects = msmService.wenXinSend("wx9ee0e3babfd8d2af", "de2ecb80b30d63135918ba3ae6ffb711"); |
|||
data = (Integer) objects.get(0); |
|||
continue; |
|||
} |
|||
} |
|||
if (send==null){ |
|||
message=null; |
|||
}else if (send){ |
|||
message = "短信推送成功"; // 如果 send 为 true,则短信推送成功
|
|||
} |
|||
if (data==null){ |
|||
weiXin=null; |
|||
}else if (data==0){ |
|||
weiXin = "微信推送成功"; // 如果所有 dateValue 都为0,则微信推送成功
|
|||
} |
|||
if (message!=null&&"短信推送成功".equals(message) &&weiXin!=null&&"微信推送成功".equals(weiXin)) { |
|||
return AjaxResult.success(message +","+ weiXin); |
|||
} else if (message==null&&weiXin!=null&&"微信推送成功".equals(weiXin)){ |
|||
return AjaxResult.success(weiXin); |
|||
}else if (message!=null&&"短信推送成功".equals(message)&&weiXin==null){ |
|||
return AjaxResult.success(message); |
|||
}else if (message!=null&&"短信推送失败".equals(message)&&weiXin==null){ |
|||
return AjaxResult.error(message); |
|||
}else if (message==null&&"微信推送失败".equals(weiXin)){ |
|||
return AjaxResult.error(weiXin); |
|||
}else { |
|||
return AjaxResult.error(message +","+ weiXin); |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,95 @@ |
|||
package com.zc.business.controller; |
|||
|
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import org.apache.http.HttpEntity; |
|||
import org.apache.http.HttpResponse; |
|||
import org.apache.http.client.HttpClient; |
|||
import org.apache.http.client.methods.CloseableHttpResponse; |
|||
import org.apache.http.client.methods.HttpGet; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClients; |
|||
import org.apache.http.util.EntityUtils; |
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
import java.net.URLEncoder; |
|||
/** |
|||
* @author 王思祥 |
|||
* @ClassName DcWarningPush 微博推送 |
|||
*/ |
|||
|
|||
public class WeiboAuthUtil { |
|||
//1.登录传入重定向的url,用户授权后返回授权的code,2.使用code取得认证权限token 3.调用接口参数
|
|||
//1.登录获取用户的回调code
|
|||
private static final String APP_KEY = "你的App Key"; |
|||
private static final String AUTH_URL = "https://api.weibo.com/oauth2/authorize"; |
|||
private static final String APP_SECRET = "你的App Secret"; |
|||
private static final String REDIRECT_URI = "你的回调URL"; |
|||
//获取授权后的code
|
|||
public String tokenCode(){ |
|||
String url="https://api.weibo.com/oauth2/authorize?client_id="+APP_KEY+"&redirect_uri="+AUTH_URL; |
|||
String token=null; |
|||
try { |
|||
URL urlGet = new URL(url); //创建链接
|
|||
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection(); |
|||
http.setRequestMethod("GET"); |
|||
http.setDoInput(true); //打开获取返回数据
|
|||
http.connect(); //发送链接
|
|||
InputStream is = http.getInputStream(); //
|
|||
int size = is.available(); |
|||
byte[] jsonBytes = new byte[size]; |
|||
is.read(jsonBytes); |
|||
token = new String(jsonBytes, "UTF-8"); |
|||
System.err.println(token); |
|||
JSONObject jsonObject = JSONObject.parseObject(token); |
|||
is.close(); |
|||
return jsonObject.get("code").toString(); |
|||
}catch (Exception e){ |
|||
e.printStackTrace(); |
|||
} |
|||
return ""; |
|||
} |
|||
//获取toke
|
|||
public String token(String code)throws IOException { |
|||
HttpClient httpClient = HttpClients.createDefault(); |
|||
String tokenUrl = REDIRECT_URI + "?client_id=" + APP_KEY |
|||
+ "&client_secret=" + APP_SECRET |
|||
+ "&grant_type=authorization_code" |
|||
+ "&code=" + code |
|||
+ "&redirect_uri=" + URLEncoder.encode(REDIRECT_URI, "UTF-8"); |
|||
HttpGet httpGet = new HttpGet(tokenUrl); |
|||
HttpResponse response = httpClient.execute(httpGet); |
|||
HttpEntity entity = response.getEntity(); |
|||
if (entity != null) { |
|||
String responseBody = EntityUtils.toString(entity, "UTF-8"); |
|||
org.json.JSONObject jsonObject = new org.json.JSONObject(responseBody); |
|||
return jsonObject.optString("access_token"); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
//执行调用推送api
|
|||
public static void main(String[] args) throws Exception { |
|||
WeiboAuthUtil weiboAuthUtil = new WeiboAuthUtil(); |
|||
String code = weiboAuthUtil.tokenCode(); |
|||
String accessToken = weiboAuthUtil.token(code);//认证后的code放入,获取token
|
|||
// 创建HttpClient实例
|
|||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|||
// 构建请求URL,这里以获取用户信息为例
|
|||
String url = "https://api.weibo.com/2/users/show.json?access_token=" + accessToken + "&uid=用户UID"; |
|||
// 创建HttpGet请求
|
|||
HttpGet httpGet = new HttpGet(url); |
|||
// 执行请求并获取响应
|
|||
try (CloseableHttpResponse response = httpClient.execute(httpGet)) { |
|||
HttpEntity entity = response.getEntity(); |
|||
if (entity != null) { |
|||
// 读取响应内容
|
|||
String responseString = EntityUtils.toString(entity, "UTF-8"); |
|||
System.out.println(responseString); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,79 @@ |
|||
package com.zc.business.domain; |
|||
|
|||
import org.apache.commons.lang3.builder.ToStringBuilder; |
|||
import org.apache.commons.lang3.builder.ToStringStyle; |
|||
import com.ruoyi.common.annotation.Excel; |
|||
import com.ruoyi.common.core.domain.BaseEntity; |
|||
|
|||
/** |
|||
* 调度信息记录对象 dc_dispatch_resource |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-15 |
|||
*/ |
|||
public class DcDispatchResource extends BaseEntity |
|||
{ |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** $column.columnComment */ |
|||
private Long id; |
|||
|
|||
/** 1-人员2-车辆 */ |
|||
@Excel(name = "1-人员 2-车辆") |
|||
private Integer dispatchType; |
|||
|
|||
/** $column.columnComment */ |
|||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") |
|||
private Long resourceId; |
|||
|
|||
/** $column.columnComment */ |
|||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") |
|||
private Long dispatchId; |
|||
|
|||
public void setId(Long id) |
|||
{ |
|||
this.id = id; |
|||
} |
|||
|
|||
public Long getId() |
|||
{ |
|||
return id; |
|||
} |
|||
public void setDispatchType(Integer dispatchType) |
|||
{ |
|||
this.dispatchType = dispatchType; |
|||
} |
|||
|
|||
public Integer getDispatchType() |
|||
{ |
|||
return dispatchType; |
|||
} |
|||
public void setResourceId(Long resourceId) |
|||
{ |
|||
this.resourceId = resourceId; |
|||
} |
|||
|
|||
public Long getResourceId() |
|||
{ |
|||
return resourceId; |
|||
} |
|||
public void setDispatchId(Long dispatchId) |
|||
{ |
|||
this.dispatchId = dispatchId; |
|||
} |
|||
|
|||
public Long getDispatchId() |
|||
{ |
|||
return dispatchId; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
|||
.append("id", getId()) |
|||
.append("dispatchType", getDispatchType()) |
|||
.append("resourceId", getResourceId()) |
|||
.append("dispatchId", getDispatchId()) |
|||
.toString(); |
|||
} |
|||
} |
@ -0,0 +1,183 @@ |
|||
package com.zc.business.domain; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Description 事件侧重要素 |
|||
* |
|||
* @author liuwenge |
|||
* @date 2024/4/11 18:28 |
|||
*/ |
|||
@ApiModel("事件侧重要素") |
|||
public class DcEventImportant |
|||
{ |
|||
|
|||
@ApiModelProperty(value = "事件id") |
|||
private String id; |
|||
|
|||
@ApiModelProperty(value = "事件id") |
|||
private String eventId; |
|||
|
|||
@ApiModelProperty(value = "车型及车牌号") |
|||
private String plateNumber; |
|||
|
|||
@ApiModelProperty(value = "分流点名称及桩号") |
|||
private String diversionPoint; |
|||
|
|||
@ApiModelProperty(value = "目前进度") |
|||
private String currentProgress; |
|||
|
|||
@ApiModelProperty(value = "已采取措施") |
|||
private String takeSteps; |
|||
|
|||
@ApiModelProperty(value = "是否启动预案") |
|||
private Integer planStatus; |
|||
|
|||
@ApiModelProperty(value = "交警是否到达") |
|||
private Integer trafficPoliceStatus; |
|||
|
|||
@ApiModelProperty(value = "医疗是否到达") |
|||
private Integer medicalStatus; |
|||
|
|||
@ApiModelProperty(value = "消防是否到达") |
|||
private Integer fireStatus; |
|||
|
|||
@ApiModelProperty(value = "是否做好情报板提示工作") |
|||
private Integer boardStatus; |
|||
|
|||
@ApiModelProperty(value = "是否有危化品泄漏") |
|||
private Integer chemicalsStatus; |
|||
|
|||
@ApiModelProperty(value = "预案等级") |
|||
private String planLevel; |
|||
|
|||
@ApiModelProperty(value = "危化品名称") |
|||
private String chemicalsName; |
|||
|
|||
@ApiModelProperty(value = "危化品泄露程度") |
|||
private String leakageLevel; |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getEventId() { |
|||
return eventId; |
|||
} |
|||
|
|||
public void setEventId(String eventId) { |
|||
this.eventId = eventId; |
|||
} |
|||
|
|||
public String getPlateNumber() { |
|||
return plateNumber; |
|||
} |
|||
|
|||
public void setPlateNumber(String plateNumber) { |
|||
this.plateNumber = plateNumber; |
|||
} |
|||
|
|||
public String getDiversionPoint() { |
|||
return diversionPoint; |
|||
} |
|||
|
|||
public void setDiversionPoint(String diversionPoint) { |
|||
this.diversionPoint = diversionPoint; |
|||
} |
|||
|
|||
public String getCurrentProgress() { |
|||
return currentProgress; |
|||
} |
|||
|
|||
public void setCurrentProgress(String currentProgress) { |
|||
this.currentProgress = currentProgress; |
|||
} |
|||
|
|||
public String getTakeSteps() { |
|||
return takeSteps; |
|||
} |
|||
|
|||
public void setTakeSteps(String takeSteps) { |
|||
this.takeSteps = takeSteps; |
|||
} |
|||
|
|||
public Integer getPlanStatus() { |
|||
return planStatus; |
|||
} |
|||
|
|||
public void setPlanStatus(Integer planStatus) { |
|||
this.planStatus = planStatus; |
|||
} |
|||
|
|||
public Integer getTrafficPoliceStatus() { |
|||
return trafficPoliceStatus; |
|||
} |
|||
|
|||
public void setTrafficPoliceStatus(Integer trafficPoliceStatus) { |
|||
this.trafficPoliceStatus = trafficPoliceStatus; |
|||
} |
|||
|
|||
public Integer getMedicalStatus() { |
|||
return medicalStatus; |
|||
} |
|||
|
|||
public void setMedicalStatus(Integer medicalStatus) { |
|||
this.medicalStatus = medicalStatus; |
|||
} |
|||
|
|||
public Integer getFireStatus() { |
|||
return fireStatus; |
|||
} |
|||
|
|||
public void setFireStatus(Integer fireStatus) { |
|||
this.fireStatus = fireStatus; |
|||
} |
|||
|
|||
public Integer getBoardStatus() { |
|||
return boardStatus; |
|||
} |
|||
|
|||
public void setBoardStatus(Integer boardStatus) { |
|||
this.boardStatus = boardStatus; |
|||
} |
|||
|
|||
public Integer getChemicalsStatus() { |
|||
return chemicalsStatus; |
|||
} |
|||
|
|||
public void setChemicalsStatus(Integer chemicalsStatus) { |
|||
this.chemicalsStatus = chemicalsStatus; |
|||
} |
|||
|
|||
public String getPlanLevel() { |
|||
return planLevel; |
|||
} |
|||
|
|||
public void setPlanLevel(String planLevel) { |
|||
this.planLevel = planLevel; |
|||
} |
|||
|
|||
public String getChemicalsName() { |
|||
return chemicalsName; |
|||
} |
|||
|
|||
public void setChemicalsName(String chemicalsName) { |
|||
this.chemicalsName = chemicalsName; |
|||
} |
|||
|
|||
public String getLeakageLevel() { |
|||
return leakageLevel; |
|||
} |
|||
|
|||
public void setLeakageLevel(String leakageLevel) { |
|||
this.leakageLevel = leakageLevel; |
|||
} |
|||
} |
@ -0,0 +1,173 @@ |
|||
package com.zc.business.domain; |
|||
|
|||
import org.apache.commons.lang3.builder.ToStringBuilder; |
|||
import org.apache.commons.lang3.builder.ToStringStyle; |
|||
import com.ruoyi.common.annotation.Excel; |
|||
import com.ruoyi.common.core.domain.BaseEntity; |
|||
|
|||
/** |
|||
* 重要事件文件内容对象 dc_event_important_file |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-12 |
|||
*/ |
|||
public class DcEventImportantFile |
|||
{ |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
private Long id; |
|||
|
|||
/** 事件id */ |
|||
private String eventId; |
|||
|
|||
/** 报送单位 */ |
|||
@Excel(name = "报送单位") |
|||
private String fromDept; |
|||
|
|||
/** 报送时间 */ |
|||
@Excel(name = "报送时间") |
|||
private String createTime; |
|||
|
|||
/** 标题 */ |
|||
@Excel(name = "标题") |
|||
private String title; |
|||
|
|||
/** 发至单位 */ |
|||
@Excel(name = "发至单位") |
|||
private String toDept; |
|||
|
|||
/** 内容 */ |
|||
@Excel(name = "内容") |
|||
private String content; |
|||
|
|||
/** 填报人 */ |
|||
@Excel(name = "填报人") |
|||
private String createName; |
|||
|
|||
/** 联系电话 */ |
|||
@Excel(name = "联系电话") |
|||
private String phoneNumber; |
|||
|
|||
/** 签发人 */ |
|||
@Excel(name = "签发人") |
|||
private String issued; |
|||
|
|||
/** 类型 1:初报,2续报,3终报 */ |
|||
@Excel(name = "类型 1:初报,2续报,3终报") |
|||
private String type; |
|||
|
|||
public Long getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(Long id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public void setEventId(String eventId) |
|||
{ |
|||
this.eventId = eventId; |
|||
} |
|||
|
|||
public String getEventId() |
|||
{ |
|||
return eventId; |
|||
} |
|||
public void setFromDept(String fromDept) |
|||
{ |
|||
this.fromDept = fromDept; |
|||
} |
|||
|
|||
public String getFromDept() |
|||
{ |
|||
return fromDept; |
|||
} |
|||
|
|||
public String getCreateTime() { |
|||
return createTime; |
|||
} |
|||
|
|||
public void setCreateTime(String createTime) { |
|||
this.createTime = createTime; |
|||
} |
|||
|
|||
public void setTitle(String title) |
|||
{ |
|||
this.title = title; |
|||
} |
|||
|
|||
public String getTitle() |
|||
{ |
|||
return title; |
|||
} |
|||
public void setToDept(String toDept) |
|||
{ |
|||
this.toDept = toDept; |
|||
} |
|||
|
|||
public String getToDept() |
|||
{ |
|||
return toDept; |
|||
} |
|||
public void setContent(String content) |
|||
{ |
|||
this.content = content; |
|||
} |
|||
|
|||
public String getContent() |
|||
{ |
|||
return content; |
|||
} |
|||
public void setCreateName(String createName) |
|||
{ |
|||
this.createName = createName; |
|||
} |
|||
|
|||
public String getCreateName() |
|||
{ |
|||
return createName; |
|||
} |
|||
public void setPhoneNumber(String phoneNumber) |
|||
{ |
|||
this.phoneNumber = phoneNumber; |
|||
} |
|||
|
|||
public String getPhoneNumber() |
|||
{ |
|||
return phoneNumber; |
|||
} |
|||
public void setIssued(String issued) |
|||
{ |
|||
this.issued = issued; |
|||
} |
|||
|
|||
public String getIssued() |
|||
{ |
|||
return issued; |
|||
} |
|||
public void setType(String type) |
|||
{ |
|||
this.type = type; |
|||
} |
|||
|
|||
public String getType() |
|||
{ |
|||
return type; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
|||
.append("eventId", getEventId()) |
|||
.append("fromDept", getFromDept()) |
|||
.append("createTime", getCreateTime()) |
|||
.append("title", getTitle()) |
|||
.append("toDept", getToDept()) |
|||
.append("content", getContent()) |
|||
.append("createName", getCreateName()) |
|||
.append("phoneNumber", getPhoneNumber()) |
|||
.append("issued", getIssued()) |
|||
.append("type", getType()) |
|||
.toString(); |
|||
} |
|||
} |
@ -0,0 +1,71 @@ |
|||
package com.zc.business.mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.zc.business.domain.DcEventImportantFile; |
|||
|
|||
/** |
|||
* 重要事件文件内容Mapper接口 |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-12 |
|||
*/ |
|||
public interface DcEventImportantFileMapper |
|||
{ |
|||
/** |
|||
* 查询重要事件文件内容 |
|||
* |
|||
* @param id 重要事件文件内容主键 |
|||
* @return 重要事件文件内容 |
|||
*/ |
|||
public DcEventImportantFile selectDcEventImportantFileByEventId(String id); |
|||
|
|||
/** |
|||
* 查询重要事件文件内容列表 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 重要事件文件内容集合 |
|||
*/ |
|||
List<DcEventImportantFile> selectDcEventImportantFileList(DcEventImportantFile dcEventImportantFile); |
|||
|
|||
/** |
|||
* 新增重要事件文件内容 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 结果 |
|||
*/ |
|||
int insertDcEventImportantFile(DcEventImportantFile dcEventImportantFile); |
|||
|
|||
/** |
|||
* 修改重要事件文件内容 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 结果 |
|||
*/ |
|||
int updateDcEventImportantFile(DcEventImportantFile dcEventImportantFile); |
|||
|
|||
/** |
|||
* 删除重要事件文件内容 |
|||
* |
|||
* @param id 重要事件文件内容主键 |
|||
* @return 结果 |
|||
*/ |
|||
int deleteDcEventImportantFileByEventId(String id); |
|||
|
|||
/** |
|||
* 批量删除重要事件文件内容 |
|||
* |
|||
* @param ids 需要删除的数据主键集合 |
|||
* @return 结果 |
|||
*/ |
|||
int deleteDcEventImportantFileByEventIds(String[] ids); |
|||
|
|||
/** |
|||
* 获取重要事件状态 |
|||
* |
|||
* @param eventId 事件id |
|||
* @return 结果 |
|||
*/ |
|||
int getImportantFileStatus(String eventId); |
|||
} |
@ -0,0 +1,61 @@ |
|||
package com.zc.business.mapper; |
|||
|
|||
import java.util.List; |
|||
import com.zc.business.domain.DcEventImportant; |
|||
|
|||
/** |
|||
* 事件侧重要素Mapper接口 |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-11 |
|||
*/ |
|||
public interface DcEventImportantMapper |
|||
{ |
|||
/** |
|||
* 查询事件侧重要素 |
|||
* |
|||
* @param id 事件侧重要素主键 |
|||
* @return 事件侧重要素 |
|||
*/ |
|||
public DcEventImportant selectDcEventImportantByEventId(String id); |
|||
|
|||
/** |
|||
* 查询事件侧重要素列表 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 事件侧重要素集合 |
|||
*/ |
|||
List<DcEventImportant> selectDcEventImportantList(DcEventImportant dcEventImportant); |
|||
|
|||
/** |
|||
* 新增事件侧重要素 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 结果 |
|||
*/ |
|||
int insertDcEventImportant(DcEventImportant dcEventImportant); |
|||
|
|||
/** |
|||
* 修改事件侧重要素 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 结果 |
|||
*/ |
|||
int updateDcEventImportant(DcEventImportant dcEventImportant); |
|||
|
|||
/** |
|||
* 删除事件侧重要素 |
|||
* |
|||
* @param id 事件侧重要素主键 |
|||
* @return 结果 |
|||
*/ |
|||
int deleteDcEventImportantByEventId(String id); |
|||
|
|||
/** |
|||
* 批量删除事件侧重要素 |
|||
* |
|||
* @param ids 需要删除的数据主键集合 |
|||
* @return 结果 |
|||
*/ |
|||
int deleteDcEventImportantByEventIds(String[] ids); |
|||
} |
@ -0,0 +1,71 @@ |
|||
package com.zc.business.service; |
|||
|
|||
import java.util.List; |
|||
|
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.zc.business.domain.DcEventImportantFile; |
|||
|
|||
/** |
|||
* 重要事件文件内容Service接口 |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-12 |
|||
*/ |
|||
public interface IDcEventImportantFileService |
|||
{ |
|||
/** |
|||
* 查询重要事件文件内容 |
|||
* |
|||
* @param id 重要事件文件内容主键 |
|||
* @return 重要事件文件内容 |
|||
*/ |
|||
public DcEventImportantFile selectDcEventImportantFileByEventId(String id); |
|||
|
|||
/** |
|||
* 查询重要事件文件内容列表 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 重要事件文件内容集合 |
|||
*/ |
|||
List<DcEventImportantFile> selectDcEventImportantFileList(DcEventImportantFile dcEventImportantFile); |
|||
|
|||
/** |
|||
* 新增重要事件文件内容 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 结果 |
|||
*/ |
|||
int insertDcEventImportantFile(DcEventImportantFile dcEventImportantFile); |
|||
|
|||
/** |
|||
* 修改重要事件文件内容 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 结果 |
|||
*/ |
|||
int updateDcEventImportantFile(DcEventImportantFile dcEventImportantFile); |
|||
|
|||
/** |
|||
* 批量删除重要事件文件内容 |
|||
* |
|||
* @param ids 需要删除的重要事件文件内容主键集合 |
|||
* @return 结果 |
|||
*/ |
|||
int deleteDcEventImportantFileByEventIds(String[] ids); |
|||
|
|||
/** |
|||
* 删除重要事件文件内容信息 |
|||
* |
|||
* @param id 重要事件文件内容主键 |
|||
* @return 结果 |
|||
*/ |
|||
int deleteDcEventImportantFileByEventId(String id); |
|||
|
|||
/** |
|||
* 获取重要事件状态 |
|||
* |
|||
* @param eventId 事件id |
|||
* @return 结果 |
|||
*/ |
|||
AjaxResult getImportantFileStatus(String eventId); |
|||
} |
@ -0,0 +1,61 @@ |
|||
package com.zc.business.service; |
|||
|
|||
import java.util.List; |
|||
import com.zc.business.domain.DcEventImportant; |
|||
|
|||
/** |
|||
* 事件侧重要素Service接口 |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-11 |
|||
*/ |
|||
public interface IDcEventImportantService |
|||
{ |
|||
/** |
|||
* 查询事件侧重要素 |
|||
* |
|||
* @param id 事件侧重要素主键 |
|||
* @return 事件侧重要素 |
|||
*/ |
|||
public DcEventImportant selectDcEventImportantByEventId(String id); |
|||
|
|||
/** |
|||
* 查询事件侧重要素列表 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 事件侧重要素集合 |
|||
*/ |
|||
List<DcEventImportant> selectDcEventImportantList(DcEventImportant dcEventImportant); |
|||
|
|||
/** |
|||
* 新增事件侧重要素 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 结果 |
|||
*/ |
|||
int insertDcEventImportant(DcEventImportant dcEventImportant); |
|||
|
|||
/** |
|||
* 修改事件侧重要素 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 结果 |
|||
*/ |
|||
int updateDcEventImportant(DcEventImportant dcEventImportant); |
|||
|
|||
/** |
|||
* 批量删除事件侧重要素 |
|||
* |
|||
* @param ids 需要删除的事件侧重要素主键集合 |
|||
* @return 结果 |
|||
*/ |
|||
int deleteDcEventImportantByEventIds(String[] ids); |
|||
|
|||
/** |
|||
* 删除事件侧重要素信息 |
|||
* |
|||
* @param id 事件侧重要素主键 |
|||
* @return 结果 |
|||
*/ |
|||
int deleteDcEventImportantByEventId(String id); |
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.zc.business.service; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
|
|||
public interface IMsmService { |
|||
/** |
|||
* 发送短信 |
|||
* |
|||
* @param phone 手机号 |
|||
* @return |
|||
*/ |
|||
public boolean send(String phone); |
|||
/** |
|||
* 微信推送 |
|||
* |
|||
* @return |
|||
*/ |
|||
JSONArray wenXinSend(String appId, String appSecret); |
|||
|
|||
} |
@ -0,0 +1,135 @@ |
|||
package com.zc.business.service.impl; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.ruoyi.common.utils.DateUtils; |
|||
import com.ruoyi.common.utils.SecurityUtils; |
|||
import com.zc.business.domain.DcEventProcess; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import com.zc.business.mapper.DcEventImportantFileMapper; |
|||
import com.zc.business.domain.DcEventImportantFile; |
|||
import com.zc.business.service.IDcEventImportantFileService; |
|||
|
|||
/** |
|||
* 重要事件文件内容Service业务层处理 |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-12 |
|||
*/ |
|||
@Service |
|||
public class DcEventImportantFileServiceImpl implements IDcEventImportantFileService |
|||
{ |
|||
@Autowired |
|||
private DcEventImportantFileMapper dcEventImportantFileMapper; |
|||
@Autowired |
|||
private DcEventProcessServiceImpl dcEventProcessService; |
|||
|
|||
/** |
|||
* 查询重要事件文件内容 |
|||
* |
|||
* @param id 重要事件文件内容主键 |
|||
* @return 重要事件文件内容 |
|||
*/ |
|||
@Override |
|||
public DcEventImportantFile selectDcEventImportantFileByEventId(String id) |
|||
{ |
|||
return dcEventImportantFileMapper.selectDcEventImportantFileByEventId(id); |
|||
} |
|||
|
|||
/** |
|||
* 查询重要事件文件内容列表 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 重要事件文件内容 |
|||
*/ |
|||
@Override |
|||
public List<DcEventImportantFile> selectDcEventImportantFileList(DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
return dcEventImportantFileMapper.selectDcEventImportantFileList(dcEventImportantFile); |
|||
} |
|||
|
|||
/** |
|||
* 新增重要事件文件内容 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int insertDcEventImportantFile(DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
int i = dcEventImportantFileMapper.insertDcEventImportantFile(dcEventImportantFile); |
|||
if (i > 0){ |
|||
DcEventProcess dcEventProcess = new DcEventProcess(); |
|||
dcEventProcess.setEventId(dcEventImportantFile.getEventId()); |
|||
dcEventProcess.setOperationTime(new Date()); |
|||
dcEventProcess.setOperator(SecurityUtils.getUserId().toString()); |
|||
dcEventProcess.setSource(1); |
|||
dcEventProcess.setProcessType(4); |
|||
dcEventProcess.setProcessId(dcEventImportantFile.getId()); |
|||
String context = "重要事件"; |
|||
if ("1".equals(dcEventImportantFile.getType())){ |
|||
context = "重要事件初报"; |
|||
} else if ("2".equals(dcEventImportantFile.getType())){ |
|||
context = "重要事件续报"; |
|||
} else if ("3".equals(dcEventImportantFile.getType())){ |
|||
context = "重要事件终报"; |
|||
} |
|||
dcEventProcess.setContext(context); |
|||
dcEventProcessService.insertDcEventProcess(dcEventProcess); |
|||
|
|||
} |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 修改重要事件文件内容 |
|||
* |
|||
* @param dcEventImportantFile 重要事件文件内容 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int updateDcEventImportantFile(DcEventImportantFile dcEventImportantFile) |
|||
{ |
|||
return dcEventImportantFileMapper.updateDcEventImportantFile(dcEventImportantFile); |
|||
} |
|||
|
|||
/** |
|||
* 批量删除重要事件文件内容 |
|||
* |
|||
* @param ids 需要删除的重要事件文件内容主键 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int deleteDcEventImportantFileByEventIds(String[] ids) |
|||
{ |
|||
return dcEventImportantFileMapper.deleteDcEventImportantFileByEventIds(ids); |
|||
} |
|||
|
|||
/** |
|||
* 删除重要事件文件内容信息 |
|||
* |
|||
* @param id 重要事件文件内容主键 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int deleteDcEventImportantFileByEventId(String id) |
|||
{ |
|||
return dcEventImportantFileMapper.deleteDcEventImportantFileByEventId(id); |
|||
} |
|||
|
|||
/** |
|||
* 获取重要事件状态 |
|||
* |
|||
* @param eventId 事件id |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public AjaxResult getImportantFileStatus(String eventId){ |
|||
int num = dcEventImportantFileMapper.getImportantFileStatus(eventId); |
|||
return AjaxResult.success(num); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,93 @@ |
|||
package com.zc.business.service.impl; |
|||
|
|||
import java.util.List; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import com.zc.business.mapper.DcEventImportantMapper; |
|||
import com.zc.business.domain.DcEventImportant; |
|||
import com.zc.business.service.IDcEventImportantService; |
|||
|
|||
/** |
|||
* 事件侧重要素Service业务层处理 |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-04-11 |
|||
*/ |
|||
@Service |
|||
public class DcEventImportantServiceImpl implements IDcEventImportantService |
|||
{ |
|||
@Autowired |
|||
private DcEventImportantMapper dcEventImportantMapper; |
|||
|
|||
/** |
|||
* 查询事件侧重要素 |
|||
* |
|||
* @param id 事件侧重要素主键 |
|||
* @return 事件侧重要素 |
|||
*/ |
|||
@Override |
|||
public DcEventImportant selectDcEventImportantByEventId(String id) |
|||
{ |
|||
return dcEventImportantMapper.selectDcEventImportantByEventId(id); |
|||
} |
|||
|
|||
/** |
|||
* 查询事件侧重要素列表 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 事件侧重要素 |
|||
*/ |
|||
@Override |
|||
public List<DcEventImportant> selectDcEventImportantList(DcEventImportant dcEventImportant) |
|||
{ |
|||
return dcEventImportantMapper.selectDcEventImportantList(dcEventImportant); |
|||
} |
|||
|
|||
/** |
|||
* 新增事件侧重要素 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int insertDcEventImportant(DcEventImportant dcEventImportant) |
|||
{ |
|||
return dcEventImportantMapper.insertDcEventImportant(dcEventImportant); |
|||
} |
|||
|
|||
/** |
|||
* 修改事件侧重要素 |
|||
* |
|||
* @param dcEventImportant 事件侧重要素 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int updateDcEventImportant(DcEventImportant dcEventImportant) |
|||
{ |
|||
return dcEventImportantMapper.updateDcEventImportant(dcEventImportant); |
|||
} |
|||
|
|||
/** |
|||
* 批量删除事件侧重要素 |
|||
* |
|||
* @param ids 需要删除的事件侧重要素主键 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int deleteDcEventImportantByEventIds(String[] ids) |
|||
{ |
|||
return dcEventImportantMapper.deleteDcEventImportantByEventIds(ids); |
|||
} |
|||
|
|||
/** |
|||
* 删除事件侧重要素信息 |
|||
* |
|||
* @param id 事件侧重要素主键 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int deleteDcEventImportantByEventId(String id) |
|||
{ |
|||
return dcEventImportantMapper.deleteDcEventImportantByEventId(id); |
|||
} |
|||
} |
@ -0,0 +1,200 @@ |
|||
package com.zc.business.service.impl; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.aliyuncs.DefaultAcsClient; |
|||
import com.aliyuncs.IAcsClient; |
|||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; |
|||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; |
|||
import com.aliyuncs.profile.DefaultProfile; |
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.ruoyi.common.core.redis.RedisCache; |
|||
import com.ruoyi.common.utils.spring.SpringUtils; |
|||
import com.zc.business.service.IMsmService; |
|||
import com.zc.business.utils.HttpUtil; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.json.JSONObject; |
|||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.io.InputStream; |
|||
|
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Random; |
|||
import java.util.concurrent.CountDownLatch; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.concurrent.Executors; |
|||
import java.util.concurrent.ThreadPoolExecutor; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* 短信业务实现类 |
|||
*/ |
|||
@Service |
|||
public class MsmServiceImpl implements IMsmService { |
|||
private static final String WEIXINTUISONTOKEN = "weixintuisontoken";//redis策略缓存的key
|
|||
|
|||
/** |
|||
* 发送短信 |
|||
* |
|||
* @param phone 手机号 |
|||
* @return |
|||
*/ |
|||
public boolean send(String phone) { |
|||
//地域节点、阿里云的id、秘钥
|
|||
DefaultProfile profile = DefaultProfile.getProfile("cn-qingdao", |
|||
"LTAI5tENd3j1tP5t2fF4fxaX", "i86Yenj13XRd2aeZMtybpKxsqI1VRU"); |
|||
IAcsClient client = new DefaultAcsClient(profile); |
|||
SendSmsRequest request = new SendSmsRequest(); |
|||
request.setSysRegionId("cn-qingdao");//地域节点
|
|||
request.putQueryParameter("PhoneNumbers", phone); //手机号,要填绑定测试的手机号码
|
|||
request.putQueryParameter("SignName", "阿里云短信测试"); //阿里云签名名称
|
|||
request.putQueryParameter("TemplateCode", "SMS_154950909"); //阿里云模板code
|
|||
String code = String.format("%04d", new Random().nextInt(10000));//验证码
|
|||
HashMap<Object, Object> map = new HashMap<>(); |
|||
map.put("code", code); //参数加入到map
|
|||
JSONObject json = new JSONObject(map); //map参数转为JSON传入到模板即可
|
|||
request.putQueryParameter("TemplateParam", json); |
|||
try { |
|||
SendSmsResponse response = client.getAcsResponse(request); |
|||
if (response != null && response.getCode() != null && response.getCode().equals("OK")) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
//测试短信推送
|
|||
// public static void main(String[] args) {
|
|||
// MsmServiceImpl msmService = new MsmServiceImpl();
|
|||
// boolean send = msmService.send("19806114248");
|
|||
// System.out.println(send);
|
|||
// }
|
|||
//微信推送
|
|||
@Override |
|||
public JSONArray wenXinSend(String appId, String appSecret) { |
|||
MsmServiceImpl msmService = new MsmServiceImpl(); |
|||
return msmService.sendTemp(appId, appSecret); |
|||
} |
|||
|
|||
//获取微信token
|
|||
public static com.alibaba.fastjson.JSONObject getAccessToken(String appId, String appSecret) { |
|||
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret; |
|||
String accessToken = null; |
|||
com.alibaba.fastjson.JSONObject jsonObj = null; |
|||
try { |
|||
URL urlGet = new URL(url); |
|||
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection(); |
|||
http.setRequestMethod("GET"); // 必须是get方式请求
|
|||
http.setDoInput(true); |
|||
http.connect(); |
|||
InputStream is = http.getInputStream(); |
|||
int size = is.available(); |
|||
byte[] jsonBytes = new byte[size]; |
|||
is.read(jsonBytes); |
|||
accessToken = new String(jsonBytes, "UTF-8"); |
|||
System.err.println(accessToken); |
|||
jsonObj = com.alibaba.fastjson.JSONObject.parseObject(accessToken); |
|||
is.close(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return jsonObj; |
|||
} |
|||
|
|||
//执行微信推送
|
|||
public JSONArray sendTemp(String appId, String appSecret) { |
|||
JSONArray objects = new JSONArray(); |
|||
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(100); |
|||
MsmServiceImpl msmService = new MsmServiceImpl(); |
|||
RedisCache redisCache = SpringUtils.getBean(RedisCache.class); |
|||
String accessToken = redisCache.getCacheObject(WEIXINTUISONTOKEN); |
|||
if (StringUtils.isBlank(accessToken)) { |
|||
accessToken = msmService.getAccessToken(appId, appSecret).getString("access_token");//获取到了access_token
|
|||
String expiresIn = msmService.getAccessToken(appId, appSecret).getString("expires_in");//token有效秒数
|
|||
redisCache.setCacheObject(WEIXINTUISONTOKEN, accessToken, Integer.parseInt(expiresIn), TimeUnit.SECONDS);//把token存入到redis中,并设置过期时间(时间来自于微信接口返回)
|
|||
} |
|||
JSONArray userListOpenid = msmService.getUserListOpenid(accessToken); |
|||
CountDownLatch latch = new CountDownLatch(userListOpenid.size()); |
|||
for (Object openid : userListOpenid) { |
|||
String token = accessToken; |
|||
executor.execute(() -> { |
|||
// 封装要发送的json
|
|||
Map<String, Object> map = new HashMap(); |
|||
map.put("template_id", "D_yBiN7aDl2pw3bhSqU_Fbi0D8BHXL0qeBjhusWVO68");//模板消息id
|
|||
map.put("touser", openid.toString());//这里的openid是全部关注公众号的openid
|
|||
// 封装data
|
|||
com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject(); |
|||
com.alibaba.fastjson.JSONObject name = new com.alibaba.fastjson.JSONObject(); |
|||
name.put("value", "做一个身体和心灵都勇敢的人,趁着身体未老,心灵还透明。晚安!"); |
|||
data.put("name", name); |
|||
com.alibaba.fastjson.JSONObject weather = new com.alibaba.fastjson.JSONObject(); |
|||
weather.put("value", "阴天 19°c"); |
|||
data.put("weather", weather); |
|||
com.alibaba.fastjson.JSONObject birthday = new com.alibaba.fastjson.JSONObject(); |
|||
birthday.put("value", "53 天"); |
|||
data.put("birthday", birthday); |
|||
map.put("data", data); |
|||
String r = HttpUtil.getJsonData(com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(map)), |
|||
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token); //发送模板消息
|
|||
System.out.println("-->" + r); |
|||
try { |
|||
JSONObject jsonObject = new JSONObject(r); |
|||
Object errcode = jsonObject.get("errcode"); |
|||
objects.add(errcode); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
latch.countDown(); |
|||
} |
|||
}); |
|||
} |
|||
try { |
|||
latch.await(); // 等待所有线程执行完毕
|
|||
} catch (InterruptedException e) { |
|||
Thread.currentThread().interrupt(); |
|||
} finally { |
|||
executor.shutdown(); |
|||
} |
|||
return objects; |
|||
//map.put("url","https://www.vipkes.cn");//用户点击模板消息,要跳转的地址
|
|||
// 封装miniprogram 跳转小程序用,不跳不要填
|
|||
// Map<String, String> mapA = new HashMap<>();
|
|||
// mapA.put("appid", ""); //小程序appid
|
|||
// mapA.put("pagepath", ""); //小程序页面pagepath
|
|||
// map.put("miniprogram", mapA);
|
|||
} |
|||
|
|||
//获取微信公众号全部关注人的openid
|
|||
public static JSONArray getUserListOpenid(String accessToken) { |
|||
String url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken; |
|||
; |
|||
com.alibaba.fastjson.JSONObject jsonObj = null; |
|||
try { |
|||
URL urlGet = new URL(url); |
|||
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection(); |
|||
http.setRequestMethod("GET"); // 必须是get方式请求
|
|||
http.setDoInput(true); |
|||
http.connect(); |
|||
InputStream is = http.getInputStream(); |
|||
int size = is.available(); |
|||
byte[] jsonBytes = new byte[size]; |
|||
is.read(jsonBytes); |
|||
String userOpenid = new String(jsonBytes, "UTF-8"); |
|||
jsonObj = com.alibaba.fastjson.JSONObject.parseObject(userOpenid); |
|||
is.close(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
com.alibaba.fastjson.JSONObject data = jsonObj.getJSONObject("data"); |
|||
return data.getJSONArray("openid"); |
|||
} |
|||
} |
@ -0,0 +1,83 @@ |
|||
package com.zc.business.utils; |
|||
|
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
|
|||
import java.io.BufferedReader; |
|||
import java.io.InputStream; |
|||
import java.io.InputStreamReader; |
|||
import java.io.OutputStreamWriter; |
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
|
|||
public class HttpUtil { |
|||
|
|||
public static String getJsonData(JSONObject jsonParam, String urls) { |
|||
StringBuffer sb = new StringBuffer(); |
|||
try { |
|||
// 创建url资源
|
|||
URL url = new URL(urls); |
|||
// 建立http连接
|
|||
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
|||
// 设置允许输出
|
|||
conn.setDoOutput(true); |
|||
// 设置允许输入
|
|||
conn.setDoInput(true); |
|||
// 设置不用缓存
|
|||
conn.setUseCaches(false); |
|||
// 设置传递方式
|
|||
conn.setRequestMethod("POST"); |
|||
// 设置维持长连接
|
|||
conn.setRequestProperty("Connection", "Keep-Alive"); |
|||
// 设置文件字符集:
|
|||
conn.setRequestProperty("Charset", "UTF-8"); |
|||
// 转换为字节数组
|
|||
byte[] data = (jsonParam.toString()).getBytes(); |
|||
// 设置文件长度
|
|||
conn.setRequestProperty("Content-Length", String.valueOf(data.length)); |
|||
// 设置文件类型:
|
|||
conn.setRequestProperty("contentType", "application/json"); |
|||
// 开始连接请求
|
|||
conn.connect(); |
|||
//OutputStream out = new DataOutputStream(conn.getOutputStream()) ;
|
|||
//防止消息乱码
|
|||
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8"); |
|||
// 写入请求的字符串
|
|||
out.write(jsonParam.toString()); |
|||
out.flush(); |
|||
out.close(); |
|||
|
|||
System.out.println(conn.getResponseCode()); |
|||
|
|||
// 请求返回的状态
|
|||
if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) { |
|||
System.out.println("连接成功"); |
|||
// 请求返回的数据
|
|||
InputStream in1 = conn.getInputStream(); |
|||
try { |
|||
String readLine = new String(); |
|||
BufferedReader responseReader = new BufferedReader(new InputStreamReader(in1, "UTF-8")); |
|||
while ((readLine = responseReader.readLine()) != null) { |
|||
sb.append(readLine).append("\n"); |
|||
} |
|||
responseReader.close(); |
|||
System.out.println(sb.toString()); |
|||
|
|||
} catch (Exception e1) { |
|||
e1.printStackTrace(); |
|||
} |
|||
} else { |
|||
System.out.println("error++"); |
|||
|
|||
} |
|||
|
|||
} catch (Exception e) { |
|||
|
|||
} |
|||
|
|||
return sb.toString(); |
|||
|
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,82 @@ |
|||
package com.zc.business.utils.diff; |
|||
|
|||
import com.zc.business.utils.diff.algorithm.AlgorithmModule; |
|||
import com.zc.business.utils.diff.algorithm.array.SimilarArrayComparator; |
|||
import com.zc.business.utils.diff.algorithm.array.SimpleArrayComparator; |
|||
import com.zc.business.utils.diff.algorithm.nulls.DefaultNullComparator; |
|||
import com.zc.business.utils.diff.algorithm.object.LeftJoinObjectComparator; |
|||
import com.zc.business.utils.diff.algorithm.object.SimpleObjectComparator; |
|||
import com.zc.business.utils.diff.algorithm.other.DefaultOtherComparator; |
|||
import com.zc.business.utils.diff.algorithm.primitive.DefaultPrimitiveComparator; |
|||
|
|||
/** |
|||
* 算法模型枚举类:提供一些默认实现的算法模型 |
|||
* @Author JingWei |
|||
* @create 2022/3/2 |
|||
*/ |
|||
public enum AlgorithmEnum { |
|||
|
|||
/** |
|||
* 默认的比较算法模型 |
|||
*/ |
|||
DEFAULT(defaultAlgorithmModule()), |
|||
|
|||
/** |
|||
* 数组比较采用Simple,对象比较采用Simple |
|||
*/ |
|||
SIMPLE_ARRAY_AND_SIMPLE_OBJECT(simpleAndSimpleAlgorithmModule()), |
|||
|
|||
/** |
|||
* 数组比较采用Simple,对象比较采用LeftJoin |
|||
*/ |
|||
SIMPLE_ARRAY_AND_LEFTJOIN_OBJECT(simpleAndLeftJoinAlgorithmModule()), |
|||
|
|||
/** |
|||
* 数组比较采用Similar,对象比较采用LeftJoin |
|||
*/ |
|||
SIMLAR_ARRAY_AND_LEFTJOIN_OBJECT(similarAndLeftJoinAlgorithmModule()), |
|||
|
|||
/** |
|||
* 数组比较采用Similar,对象比较采用Simple |
|||
*/ |
|||
MOST_COMMONLY_USED(similarAndSimpleAlgorithmModule()); |
|||
|
|||
final private AlgorithmModule algorithmModule; |
|||
|
|||
AlgorithmEnum(AlgorithmModule algorithmModule) { |
|||
this.algorithmModule = algorithmModule; |
|||
} |
|||
|
|||
|
|||
public AlgorithmModule getAlgorithmModule() { |
|||
return algorithmModule; |
|||
} |
|||
|
|||
private static AlgorithmModule defaultAlgorithmModule() { |
|||
return new AlgorithmModule(new SimpleObjectComparator(), new SimilarArrayComparator(), |
|||
new DefaultPrimitiveComparator(), new DefaultNullComparator(), new DefaultOtherComparator()); |
|||
|
|||
} |
|||
|
|||
private static AlgorithmModule simpleAndSimpleAlgorithmModule() { |
|||
return new AlgorithmModule(new SimpleObjectComparator(), new SimpleArrayComparator(), |
|||
new DefaultPrimitiveComparator(), new DefaultNullComparator(), new DefaultOtherComparator()); |
|||
} |
|||
|
|||
|
|||
private static AlgorithmModule simpleAndLeftJoinAlgorithmModule() { |
|||
return new AlgorithmModule(new LeftJoinObjectComparator(), new SimpleArrayComparator(), |
|||
new DefaultPrimitiveComparator(), new DefaultNullComparator(), new DefaultOtherComparator()); |
|||
} |
|||
|
|||
private static AlgorithmModule similarAndLeftJoinAlgorithmModule() { |
|||
return new AlgorithmModule(new LeftJoinObjectComparator(), new SimilarArrayComparator(), |
|||
new DefaultPrimitiveComparator(), new DefaultNullComparator(), new DefaultOtherComparator()); |
|||
} |
|||
|
|||
private static AlgorithmModule similarAndSimpleAlgorithmModule() { |
|||
return new AlgorithmModule(new SimpleObjectComparator(), new SimilarArrayComparator(), |
|||
new DefaultPrimitiveComparator(), new DefaultNullComparator(), new DefaultOtherComparator()); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,208 @@ |
|||
package com.zc.business.utils.diff; |
|||
|
|||
import com.google.gson.JsonElement; |
|||
import com.google.gson.JsonParser; |
|||
import com.zc.business.utils.diff.algorithm.AlgorithmModule; |
|||
import com.zc.business.utils.diff.algorithm.array.ArrayComparator; |
|||
import com.zc.business.utils.diff.algorithm.array.SimilarArrayComparator; |
|||
import com.zc.business.utils.diff.algorithm.nulls.DefaultNullComparator; |
|||
import com.zc.business.utils.diff.algorithm.nulls.NullComparator; |
|||
import com.zc.business.utils.diff.algorithm.object.ObjectComparator; |
|||
import com.zc.business.utils.diff.algorithm.object.SimpleObjectComparator; |
|||
import com.zc.business.utils.diff.algorithm.other.DefaultOtherComparator; |
|||
import com.zc.business.utils.diff.algorithm.other.OtherComparator; |
|||
import com.zc.business.utils.diff.algorithm.primitive.DefaultPrimitiveComparator; |
|||
import com.zc.business.utils.diff.algorithm.primitive.PrimitiveComparator; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
import com.zc.business.utils.diff.model.Result; |
|||
import com.zc.business.utils.diff.model.ResultConvertUtil; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* DIFF入口,用于比较两个Json字符串 |
|||
* @Author JingWei |
|||
* @create 2022/2/25 |
|||
*/ |
|||
public class Diff { |
|||
/** |
|||
* 算法模型。根据传入的算法模型使用该算法模型进行diff比较。 |
|||
*/ |
|||
private AlgorithmEnum algorithmEnum; |
|||
/** |
|||
* 特殊路径集合。当前路径符合特殊路径且特殊路径下比较结果相同,会在返回结果中做额外标识标识。 |
|||
*/ |
|||
private List<String> specialPath; |
|||
/** |
|||
* 噪音字段集合。如果当前路径符合噪音字段路径,则不会比较。 |
|||
*/ |
|||
private List<String> noisePahList; |
|||
/** |
|||
* 以下为5种可以自定义的比较器,条件是algorithmEnum为空(如果algorithmEnum有值,直接使用algorithmEnum对应算法模型,比较器不生效) |
|||
*/ |
|||
private ObjectComparator objectComparator; |
|||
private ArrayComparator arrayComparator; |
|||
private PrimitiveComparator primitiveComparator; |
|||
private NullComparator nullComparator; |
|||
private OtherComparator otherComparator; |
|||
|
|||
|
|||
/** |
|||
* @param a 要比较的第一个JsonElement |
|||
* @param b 要比较的第二个JsonElement |
|||
* @return 用来展示的diff结果 |
|||
*/ |
|||
public List<Result> diffElement(JsonElement a, JsonElement b) { |
|||
DiffContext diffContext; |
|||
//用噪音路径和自定义路径构造路径模型
|
|||
PathModule pathModule = new PathModule(noisePahList, specialPath); |
|||
//如果有算法模型直接使用算法模型
|
|||
if(algorithmEnum != null){ |
|||
diffContext = algorithmEnum.getAlgorithmModule().diffElement(a, b, pathModule); |
|||
}//如果也没有比较器,直接用默认算法模型
|
|||
else if(objectComparator == null && arrayComparator == null && primitiveComparator == null && nullComparator == null && otherComparator == null){ |
|||
diffContext = AlgorithmEnum.DEFAULT.getAlgorithmModule().diffElement(a, b, pathModule); |
|||
}//如果有比较器,为空的比较器用默认替换,然后构造算法模型,
|
|||
else { |
|||
constrcutDefaultComparator(); |
|||
diffContext = new AlgorithmModule(objectComparator, arrayComparator, primitiveComparator, nullComparator, otherComparator).diffElement(a, b, pathModule); |
|||
} |
|||
return ResultConvertUtil.constructResult(diffContext); |
|||
} |
|||
|
|||
/** |
|||
* @param strA 要比较的第一个字符串 |
|||
* @param strB 要比较的第二个字符串 |
|||
* @return 用来展示的diff结果 |
|||
*/ |
|||
public List<Result> diff(String strA, String strB) { |
|||
return diffElement(new JsonParser().parse(strA), new JsonParser().parse(strB)); |
|||
} |
|||
|
|||
public Diff() { |
|||
} |
|||
|
|||
/** |
|||
* 没有初始的比较器替换成默认的 |
|||
*/ |
|||
private void constrcutDefaultComparator() { |
|||
//如果没有初始化算法,则采用默认的算法。
|
|||
if(objectComparator == null){ |
|||
objectComparator = defaultObjectComparator(); |
|||
} |
|||
if(arrayComparator == null){ |
|||
arrayComparator = defaultArrayComparator(); |
|||
} |
|||
if(primitiveComparator == null){ |
|||
primitiveComparator = defaultPrimitiveComparator(); |
|||
} |
|||
if(nullComparator == null){ |
|||
nullComparator = defaultNullComparator(); |
|||
} |
|||
if(otherComparator == null){ |
|||
otherComparator = defaultOtherComparator(); |
|||
} |
|||
} |
|||
|
|||
private ObjectComparator defaultObjectComparator() { |
|||
return new SimpleObjectComparator(); |
|||
} |
|||
|
|||
private ArrayComparator defaultArrayComparator() { |
|||
return new SimilarArrayComparator(); |
|||
} |
|||
|
|||
private PrimitiveComparator defaultPrimitiveComparator() { |
|||
return new DefaultPrimitiveComparator(); |
|||
} |
|||
|
|||
private NullComparator defaultNullComparator() { |
|||
return new DefaultNullComparator(); |
|||
} |
|||
|
|||
private OtherComparator defaultOtherComparator() { |
|||
return new DefaultOtherComparator(); |
|||
} |
|||
|
|||
/** |
|||
* 选择算法模型 |
|||
* @param algorithmEnum 算法模型枚举类 |
|||
* @return 对象本身 |
|||
*/ |
|||
public Diff withAlgorithmEnum(AlgorithmEnum algorithmEnum){ |
|||
this.algorithmEnum = algorithmEnum; |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 设置自定义路径 |
|||
* @param specialPath 自定义路径列表 |
|||
* @return 对象本身 |
|||
*/ |
|||
public Diff withSpecialPath(List<String> specialPath){ |
|||
this.specialPath = specialPath; |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 设置噪音路径 |
|||
* @param noisePahList 噪音路径列表 |
|||
* @return 对象本身 |
|||
*/ |
|||
public Diff withNoisePahList(List<String> noisePahList){ |
|||
this.noisePahList = noisePahList; |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 自定义对象比较器 |
|||
* @param objectComparator 对象比较器 |
|||
* @return 对象本身 |
|||
*/ |
|||
public Diff withObjectComparator(ObjectComparator objectComparator) { |
|||
this.objectComparator = objectComparator; |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 自定义数组比较器 |
|||
* @param arrayComparator 数组比较器 |
|||
* @return 对象本身 |
|||
*/ |
|||
public Diff withArrayComparator(ArrayComparator arrayComparator) { |
|||
this.arrayComparator = arrayComparator; |
|||
return this; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 自定义基本类型比较器 |
|||
* @param primitiveComparator 基本类型比较器 |
|||
* @return 对象本身 |
|||
*/ |
|||
public Diff withPrimitiveAlgorithm(PrimitiveComparator primitiveComparator) { |
|||
this.primitiveComparator = primitiveComparator; |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 自定义空类型比较器 |
|||
* @param nullComparator 空类型比较器 |
|||
* @return 对象本身 |
|||
*/ |
|||
public Diff withNullComparator(NullComparator nullComparator) { |
|||
this.nullComparator = nullComparator; |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 自定义其他类型比较器 |
|||
* @param otherComparator 其他类型比较器 |
|||
* @return 对象本身 |
|||
*/ |
|||
public Diff withOtheComparator(OtherComparator otherComparator) { |
|||
this.otherComparator = otherComparator; |
|||
return this; |
|||
} |
|||
} |
@ -0,0 +1,49 @@ |
|||
package com.zc.business.utils.diff.algorithm; |
|||
|
|||
import com.google.gson.JsonElement; |
|||
import com.zc.business.utils.diff.model.Constants; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
import com.zc.business.utils.diff.model.SingleNodeDifference; |
|||
|
|||
/** |
|||
* 数组和对象比较的公有方法抽象类 |
|||
* @Author JingWei |
|||
* @create 2022/3/1 |
|||
*/ |
|||
public abstract class AbstractObjectAndArray { |
|||
protected AlgorithmModule algorithmModule; |
|||
|
|||
/** |
|||
* diff算法比较核心方法,比较2个JsonElement的入口。 |
|||
* @param a 比较的第一个JsonElement |
|||
* @param b 比较的第二个JsonElement |
|||
* @param pathModule 路径模型 |
|||
* @return 不同的比较结果 |
|||
*/ |
|||
public DiffContext diffElement(JsonElement a, JsonElement b, PathModule pathModule) { |
|||
return algorithmModule.diffElement(a, b, pathModule); |
|||
} |
|||
|
|||
/** |
|||
* 构造算法模型,比如使用对象和数组类型算法比较时,内部会用到其他类型的算法。 |
|||
* @param algorithmModule 算法模型 |
|||
*/ |
|||
public void constructAlgorithmModule(AlgorithmModule algorithmModule) { |
|||
this.algorithmModule = algorithmModule; |
|||
} |
|||
|
|||
/** |
|||
* 如果下层diff结果不同,会把下层diff结果加入到上层diff结果中去。 |
|||
* @param parentResult 上层结果 |
|||
* @param childResult 下层结果 |
|||
*/ |
|||
public void parentContextAddChildContext(DiffContext parentResult, DiffContext childResult) { |
|||
if(childResult.isSame() == Constants.DIFFERENT) { |
|||
for (SingleNodeDifference singleNodeDifference : childResult.getDiffResultModels()) { |
|||
parentResult.getDiffResultModels().add(singleNodeDifference); |
|||
} |
|||
parentResult.setSame(false); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,34 @@ |
|||
package com.zc.business.utils.diff.algorithm; |
|||
|
|||
import com.google.gson.JsonElement; |
|||
|
|||
/** |
|||
* 基本类型和其它类型比较的公有方法抽象类 |
|||
* @Author JingWei |
|||
* @create 2022/1/11 |
|||
*/ |
|||
public abstract class AbstractPrimitiveAndOther { |
|||
/** |
|||
* 将比较的元素转换成String类型方便结果展示 |
|||
* @param element 元素 |
|||
* @return 元素转换成的字符串 |
|||
*/ |
|||
protected static String jsonElement2Str(JsonElement element){ |
|||
//该对象不存在的情况
|
|||
if(element == null){ |
|||
return null; |
|||
} else if (element.isJsonObject()) { |
|||
return "{省略内部字段}"; |
|||
} else if (element.isJsonArray()) { |
|||
return "[省略内部元素]"; |
|||
} else if (element.isJsonPrimitive()) { |
|||
return element.getAsJsonPrimitive().getAsString(); |
|||
} else if (element.isJsonNull()) { |
|||
return "null"; |
|||
}else{ |
|||
throw new RuntimeException("异常"); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,66 @@ |
|||
package com.zc.business.utils.diff.algorithm; |
|||
|
|||
import com.google.gson.JsonArray; |
|||
import com.google.gson.JsonElement; |
|||
import com.google.gson.JsonNull; |
|||
import com.google.gson.JsonObject; |
|||
import com.google.gson.JsonPrimitive; |
|||
import com.zc.business.utils.diff.algorithm.array.ArrayComparator; |
|||
import com.zc.business.utils.diff.algorithm.nulls.NullComparator; |
|||
import com.zc.business.utils.diff.algorithm.object.ObjectComparator; |
|||
import com.zc.business.utils.diff.algorithm.other.OtherComparator; |
|||
import com.zc.business.utils.diff.algorithm.primitive.PrimitiveComparator; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
/** |
|||
* 算法模型 |
|||
* 算法模型包含5种比较器,对象、数组、基本类型、空类型、其他类型比较器。 |
|||
* 当2个JsonElement的子类同时为对象、数组、基本类型、空类型,使用前4种比较器。当2个JsonElement的子类类型不相同时,使用其它类型比较器。 |
|||
* @Author JingWei |
|||
* @create 2022/1/13 |
|||
*/ |
|||
public class AlgorithmModule{ |
|||
protected ObjectComparator objectAlgorithm; |
|||
protected ArrayComparator arrayAlgorithm; |
|||
protected PrimitiveComparator primitiveComparator; |
|||
protected NullComparator nullComparator; |
|||
protected OtherComparator otherComparator; |
|||
|
|||
public AlgorithmModule(ObjectComparator objectAlgorithm, ArrayComparator arrayAlgorithm, |
|||
PrimitiveComparator primitiveComparator, NullComparator nullComparator, OtherComparator otherComparator) { |
|||
this.arrayAlgorithm = arrayAlgorithm; |
|||
this.objectAlgorithm = objectAlgorithm; |
|||
this.primitiveComparator = primitiveComparator; |
|||
this.nullComparator = nullComparator; |
|||
this.otherComparator = otherComparator; |
|||
objectAlgorithm.constructAlgorithmModule(this); |
|||
arrayAlgorithm.constructAlgorithmModule(this); |
|||
} |
|||
|
|||
/** |
|||
* 判断要比较的两个JsonElement的类型,并根据类型调用对应的算法进行比较 |
|||
* @param a 要比较的第一个元素 |
|||
* @param b 要比较的第二个元素 |
|||
* @param pathModule 路径模型 |
|||
* @return 返回比较结果 |
|||
*/ |
|||
public DiffContext diffElement(JsonElement a, JsonElement b, PathModule pathModule) { |
|||
if (a instanceof JsonObject && b instanceof JsonObject) { |
|||
return objectAlgorithm.diff( (JsonObject) a, (JsonObject) b, pathModule); |
|||
} else if (a instanceof JsonArray && b instanceof JsonArray) { |
|||
return arrayAlgorithm.diffArray((JsonArray) a, (JsonArray) b, pathModule); |
|||
} else if (a instanceof JsonPrimitive && b instanceof JsonPrimitive) { |
|||
return primitiveComparator.diff((JsonPrimitive) a, (JsonPrimitive) b, pathModule); |
|||
} else if (a instanceof JsonNull && b instanceof JsonNull) { |
|||
return nullComparator.diff((JsonNull) a, (JsonNull) b, pathModule); |
|||
} else { |
|||
return otherComparator.diff(a, b, pathModule); |
|||
} |
|||
} |
|||
|
|||
public ArrayComparator getArrayAlgorithm() { |
|||
return arrayAlgorithm; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
package com.zc.business.utils.diff.algorithm; |
|||
|
|||
/** |
|||
* 比较器最顶层的接口,逻辑意义 |
|||
* @Author JingWei |
|||
* @create 2022/3/2 |
|||
*/ |
|||
public interface Comparator { |
|||
} |
@ -0,0 +1,22 @@ |
|||
package com.zc.business.utils.diff.algorithm.array; |
|||
|
|||
import com.zc.business.utils.diff.algorithm.AbstractObjectAndArray; |
|||
|
|||
/** |
|||
* 数组比较的公有方法抽象类 |
|||
* @Author JingWei |
|||
* @create 2022/3/1 |
|||
*/ |
|||
public abstract class AbstractArray extends AbstractObjectAndArray implements ArrayComparator { |
|||
/** |
|||
* 数组索引号加一个中括号表示数组路径 |
|||
* @param i 数组元素的索引号 |
|||
* @return 索引号增加中括号 |
|||
*/ |
|||
protected String constructArrayPath(Integer i){ |
|||
if(i == null || i < 0 ){ |
|||
throw new RuntimeException("数组索引号入参为空或者为负。 入参:" + i); |
|||
} |
|||
return "[" + i + "]"; |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
package com.zc.business.utils.diff.algorithm.array; |
|||
|
|||
import com.google.gson.JsonArray; |
|||
import com.google.gson.JsonElement; |
|||
import com.zc.business.utils.diff.algorithm.AlgorithmModule; |
|||
import com.zc.business.utils.diff.algorithm.Comparator; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
|
|||
/** |
|||
* 数组类型比较器接口,用于2个JsonElement均为数组时对2个元素进行比较。 |
|||
* @Author JingWei |
|||
* @create 2022/2/23 |
|||
*/ |
|||
public interface ArrayComparator extends Comparator { |
|||
/** |
|||
* 对两个JsonArray进行比较的方法 |
|||
* @param a 要比较的第一个JsonArray |
|||
* @param b 要比较的第二个JsonArray |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不相等的结果 |
|||
*/ |
|||
DiffContext diffArray(JsonArray a, JsonArray b, PathModule pathModule) ; |
|||
|
|||
/** |
|||
* 对象内部包含其他非数组类型,对这些类型比较需要使用JsonElement比较方法 |
|||
* @param a 要比较的第一个JsonElement |
|||
* @param b 要比较的第一个JsonElement |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不相等的结果 |
|||
*/ |
|||
DiffContext diffElement(JsonElement a, JsonElement b, PathModule pathModule); |
|||
|
|||
/** |
|||
* 构造算法模型,数组中元素比较需要使用到其他非数组算法 |
|||
* @param algorithmModule 算法模型:包含对象、数组、基本类型、空类型、其他类型算法 |
|||
*/ |
|||
void constructAlgorithmModule(AlgorithmModule algorithmModule); |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,252 @@ |
|||
package com.zc.business.utils.diff.algorithm.array; |
|||
|
|||
import com.google.gson.JsonArray; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
import com.zc.business.utils.diff.model.SingleNodeDifference; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
import java.util.Objects; |
|||
|
|||
/** |
|||
* 相似度数组算法比较器:当数组进行比较找不到相等元素时,通过算法优先找最接近的元素进行匹配 |
|||
* |
|||
* 举例: |
|||
*"[{\"a\":7,\"b\":5,\"c\":6},{\"a\":6,\"b\":2,\"c\":3}]"和 |
|||
*"[{\"a\":1,\"b\":2,\"c\":3},{\"a\":4,\"b\":5,\"c\":6},{\"a\":7,\"b\":8,\"c\":9}]"比较 |
|||
* 数组一中第一个元素依次和数组二中元素比较,分别有3组不同,1组不同,2组不同 |
|||
* 数组一中第二个元素依次和数组二中元素比较,分别有1组不同,3组不同,3组不同 |
|||
* 一、得到相似矩阵如下 |
|||
* 3 1 2 |
|||
* 1 3 3 |
|||
* 二、遍历矩阵所有元素,找到值最小的元素,并且行和列的其他元素不能再被使用。行和列即为要比较的2个元素在各自数组中的索引号 |
|||
* 第一次找到1,第二次找到另外一个1. |
|||
* 三、遍历矩阵中未使用所有列,列索引号为多余的元素在数组中的位置。 |
|||
* 只有第三列可以使用 ,第二组中第3个元素为新增元素。 |
|||
* |
|||
* @Author JingWei |
|||
* @create 2022/2/24 |
|||
*/ |
|||
public class SimilarArrayComparator extends AbstractArray { |
|||
/** |
|||
* USEABLE表示当前位置可以使用 |
|||
*/ |
|||
private final boolean USEABLE = false; |
|||
|
|||
/** |
|||
* USED表示当前位置已经被使用过 |
|||
*/ |
|||
private final boolean USED = true; |
|||
|
|||
|
|||
/** |
|||
* @param a 要比较的第一个数组 |
|||
* @param b 要比较的第二个数组 |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不相等的结果 |
|||
*/ |
|||
@Override |
|||
public DiffContext diffArray(JsonArray a, JsonArray b, PathModule pathModule) { |
|||
DiffContext diffContext; |
|||
//a数组长度小于等于b,直接使用diff数组比较算法
|
|||
if(a.size() <= b.size()){ |
|||
diffContext = diff(a, b, pathModule); |
|||
} |
|||
//当a数组长度大于b时,需要交换pathModule中a和b路径, 并交换数组a和b,再使用diff数组比较算法
|
|||
else { |
|||
exchangeLeftAndRightPath(pathModule); |
|||
diffContext = diff(b, a, pathModule); |
|||
exchangeLeftAndRightPath(pathModule); |
|||
exchangeResult(diffContext); |
|||
} |
|||
return diffContext; |
|||
} |
|||
|
|||
/** |
|||
* 交换返回结果中每一个路径和结果 |
|||
* @param diffContext 返回结果 |
|||
*/ |
|||
private void exchangeResult(DiffContext diffContext) { |
|||
List<SingleNodeDifference> singleNodeDifferences = diffContext.getDiffResultModels(); |
|||
for(SingleNodeDifference singleNodeDifference : singleNodeDifferences){ |
|||
exchangePathAndResult(singleNodeDifference); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 交换返回结果中的路径和结果 |
|||
* @param singleNodeDifference 返回结果 |
|||
*/ |
|||
private void exchangePathAndResult(SingleNodeDifference singleNodeDifference) { |
|||
String tempStringA = singleNodeDifference.getLeftPath(); |
|||
Object tempLeft = singleNodeDifference.getLeft(); |
|||
singleNodeDifference.setLeftPath(singleNodeDifference.getRightPath()); |
|||
singleNodeDifference.setRightPath(tempStringA); |
|||
singleNodeDifference.setLeft(singleNodeDifference.getRight()); |
|||
singleNodeDifference.setRight(tempLeft); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 将路径模型中a和b的路径交换 |
|||
* @param pathModule 路径模型 |
|||
*/ |
|||
private void exchangeLeftAndRightPath(PathModule pathModule) { |
|||
LinkedList<String> tempA = pathModule.getLeftPath(); |
|||
pathModule.setLeftPath(pathModule.getRightPath()); |
|||
pathModule.setRightPath(tempA); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 数组比较核心算法,支持数组a长度小于b长度时使用 |
|||
*/ |
|||
DiffContext diff(JsonArray a, JsonArray b, PathModule pathModule ) { |
|||
int rowlength = a.size(); |
|||
int linelength = b.size(); |
|||
//a数组中m个元素,与b数组中n个元素比较,共比较m*n次,所有比较结果会得组成一个矩阵,矩阵中的数字用来存储比较结果。
|
|||
int [][] similarMatrix = new int[rowlength][linelength]; |
|||
//创建一个行和列数组 用来判断当前行和列是否被使用过
|
|||
boolean []row = new boolean[rowlength]; |
|||
boolean []line = new boolean[linelength]; |
|||
for (int i = 0; i < rowlength; i++) { |
|||
pathModule.addLeftPath(constructArrayPath(i)); |
|||
//a数组中m个元素,与b数组中n个元素比较,比较结果生成一个m*n的矩阵
|
|||
constructSimilarMatrix(a, b, i, pathModule, similarMatrix, row, line); |
|||
pathModule.removeLastLeftPath(); |
|||
} |
|||
return obtainDiffResult(a, b, pathModule, row, line, similarMatrix); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 通过相似度矩阵,获取比较结果。 第一步在矩阵找到最小的数字,即找到最接近的几对结果。 第二步找剩余未使用的列数,即多余的元素 |
|||
*/ |
|||
private DiffContext obtainDiffResult(JsonArray a, JsonArray b, PathModule pathModule, boolean[] row, boolean[] line, int[][] similarMatrix) { |
|||
DiffContext arrayDiffContext = new DiffContext(); |
|||
//找到a和b都有的结果,并且是最接近的几对结果
|
|||
obtainModifyDiffResult(a,b,pathModule,row,line,similarMatrix, arrayDiffContext); |
|||
//a没有b有的结果,即新增的结果
|
|||
obtainAddDiffResult(b,pathModule,line, arrayDiffContext); |
|||
|
|||
return arrayDiffContext; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 得到新增的结果。由于b数组长度大于a,会有几个元素多余。在选出a和b最接近的几对元素后,剩下的几个元素被认为是新增的。 |
|||
*/ |
|||
private void obtainAddDiffResult(JsonArray b, PathModule pathModule, boolean[] line, DiffContext arrayDiffContext) { |
|||
for (int j = 0; j < line.length; j++) { |
|||
if (line[j] == USED) { |
|||
continue; |
|||
} |
|||
DiffContext addOrDeleteDiffContext = constructAddContext(b, j, pathModule); |
|||
parentContextAddChildContext(arrayDiffContext, addOrDeleteDiffContext); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 从m*n的矩阵中选出最接近的几组结果,矩阵中的数字越小,说明2个元素比较时结果相差越少 |
|||
*/ |
|||
private void obtainModifyDiffResult(JsonArray a, JsonArray b, PathModule pathModule, boolean[] row, boolean[] line, int[][] similarMatrix, DiffContext arrayDiffContext) { |
|||
int counts = 0; |
|||
//找到还未使用行的数量(行数小于列数)
|
|||
for (boolean value : row) { |
|||
if (Objects.equals(USEABLE, value)) { |
|||
counts++; |
|||
} |
|||
} |
|||
//不同结果对数等于未使用的行数
|
|||
for (int n = 0; n < counts; n++) { |
|||
int bestLineIndex = 0; |
|||
int bestRowIndex = 0; |
|||
int minDiffPair = Integer.MAX_VALUE; |
|||
//遍历矩阵中所有元素,找最小的数字,矩阵中的数字越小,说明2个元素比较时结果相差越少
|
|||
for (int i = 0; i < row.length; i++) { |
|||
for (int j = 0; j < line.length; j++) { |
|||
//如果行或列被使用,跳过该行
|
|||
if (row[i] == USED || line[j] == USED) { |
|||
continue; |
|||
} |
|||
//如果当前元素数字更小,那么把当前行和列保存下来,数字更新为当前最优结果
|
|||
if (similarMatrix[i][j] < minDiffPair) { |
|||
bestRowIndex = i; |
|||
bestLineIndex = j; |
|||
minDiffPair = similarMatrix[i][j]; |
|||
} |
|||
} |
|||
} |
|||
//将找到的最优结果添加到返回结果中
|
|||
DiffContext modifyDiffContext = constructModifyContext(a, b, bestRowIndex, bestLineIndex, pathModule); |
|||
row[bestRowIndex] = USED; |
|||
line[bestLineIndex] = USED; |
|||
parentContextAddChildContext(arrayDiffContext, modifyDiffContext); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 此时a数组没有该元素,b数组有元素,结果为新增 |
|||
* @param b 数组 |
|||
* @param index 索引号 |
|||
* @param pathModule 路径模型 |
|||
* @return 生成的不同结果 |
|||
*/ |
|||
private DiffContext constructAddContext(JsonArray b, int index, PathModule pathModule) { |
|||
pathModule.addAllpath(constructArrayPath(index)); |
|||
DiffContext diffContext = diffElement(null, b.get(index), pathModule); |
|||
pathModule.removeAllLastPath(); |
|||
return diffContext; |
|||
} |
|||
|
|||
/** |
|||
* 返回两个数组对应索引号元素比较结果 |
|||
* @param a 数组a |
|||
* @param b 数组b |
|||
* @param i 数组a中元素的索引号 |
|||
* @param bestLineIndex 数组b中元素的索引号,即找到的和a中元素接接近的元素索引号。 |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不同的结果 |
|||
*/ |
|||
private DiffContext constructModifyContext(JsonArray a, JsonArray b, int i, int bestLineIndex, PathModule pathModule) { |
|||
pathModule.addLeftPath(constructArrayPath(i)); |
|||
pathModule.addRightPath(constructArrayPath(bestLineIndex)); |
|||
DiffContext diffContext = diffElement(a.get(i), b.get(bestLineIndex), pathModule); |
|||
pathModule.removeAllLastPath(); |
|||
return diffContext; |
|||
} |
|||
|
|||
/** |
|||
* 用数组a的一个元素与数组b中所有元素分别比较,会得到n次比较结果,结果为不相等的结果对数,在矩阵中更新n次结果。 |
|||
*/ |
|||
private void constructSimilarMatrix(JsonArray arrayA, JsonArray arrayB, int rowIndex, PathModule pathModule, int [][]similarArray, boolean[] row, boolean[] line) { |
|||
if(rowIndex < 0 || rowIndex >= arrayB.size()){ |
|||
throw new RuntimeException("索引号入参超出数组长度。 索引号:" + rowIndex +" 数组B:" + arrayB); |
|||
} |
|||
|
|||
for (int j = 0; j < arrayB.size(); j++) { |
|||
if (line[j] == USEABLE) { |
|||
pathModule.addRightPath(constructArrayPath(j)); |
|||
DiffContext diffContext = diffElement(arrayA.get(rowIndex), arrayB.get(j), pathModule); |
|||
pathModule.removeLastRightPath(); |
|||
if (diffContext.isSame()) { |
|||
row[rowIndex] = USED; |
|||
line[j] = USED; |
|||
return; |
|||
} else if(existSpecialPath(diffContext.getSpecialPathResult())){ |
|||
similarArray[rowIndex][j] = 0 ; |
|||
} else { |
|||
similarArray[rowIndex][j] = diffContext.getDiffResultModels().size(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 判断比较结果是否有特殊路径 |
|||
*/ |
|||
private boolean existSpecialPath(LinkedList<String> specialPathResult) { |
|||
return specialPathResult != null && !specialPathResult.isEmpty(); |
|||
} |
|||
} |
@ -0,0 +1,62 @@ |
|||
package com.zc.business.utils.diff.algorithm.array; |
|||
|
|||
import com.google.gson.JsonArray; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
/** |
|||
* 简单数组比较器:数组对比时按照索引号顺序依次进行比较 |
|||
* 例:[A,B,C] 与 [C,B,A]比较时,依次找索引号为0、为1、为2进行比较,相同结果对为<A,C> <B,B> <C,A>,不同结果<A,C> <C,A>会加入到返回结果中。 |
|||
* @Author JingWei |
|||
* @create 2022/1/14 |
|||
*/ |
|||
public class SimpleArrayComparator extends AbstractArray { |
|||
/** |
|||
* 对两个JsonArray进行比较的方法。 |
|||
* @param a 要比较的第一个数组 |
|||
* @param b 要比较的第二个数组 |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不相等的比较结果 |
|||
*/ |
|||
@Override |
|||
public DiffContext diffArray(JsonArray a, JsonArray b, PathModule pathModule) { |
|||
DiffContext arrayDiffContext = new DiffContext(); |
|||
int maxLength = Math.max(a.size(), b.size()); |
|||
//根据数组a和b长度的大的值进行遍历
|
|||
for (int i = 0; i < maxLength; i++) { |
|||
pathModule.addAllpath(constructArrayPath(i)); |
|||
DiffContext diffContext = generateDiffResult(a,b,i,pathModule); |
|||
parentContextAddChildContext(arrayDiffContext, diffContext); |
|||
} |
|||
return arrayDiffContext; |
|||
} |
|||
|
|||
/** |
|||
* 生成比较结果,分以下3种情况考虑 |
|||
* i < a.size() && i < b.size() |
|||
* a.size() <= i |
|||
* b.size() <= i |
|||
* @param a 数组a |
|||
* @param b 数组b |
|||
* @param i 数组a和b中正在比较的元素索引号 |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不相等的比较结果 |
|||
*/ |
|||
private DiffContext generateDiffResult(JsonArray a, JsonArray b, int i, PathModule pathModule) { |
|||
if(i >= a.size() && i >= b.size()){ |
|||
throw new RuntimeException("数组索引号入参超过数组长度。 索引号:" + i + " 数组a:" + a + "数组b:" + b); |
|||
} |
|||
DiffContext diffContext; |
|||
if(i < a.size() && i < b.size()){ |
|||
diffContext = diffElement(a.get(i), b.get(i), pathModule); |
|||
}else if (i >= a.size()){ |
|||
diffContext = diffElement(null, b.get(i), pathModule); |
|||
}else{ |
|||
diffContext = diffElement(a.get(i), null, pathModule); |
|||
} |
|||
return diffContext; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -0,0 +1,27 @@ |
|||
package com.zc.business.utils.diff.algorithm.nulls; |
|||
|
|||
import com.google.gson.JsonNull; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
/** |
|||
* 当要比较的两个JsonElement都为空类型时,默认实现的算法比较器 |
|||
* @Author JingWei |
|||
* @create 2022/1/10 |
|||
*/ |
|||
public class DefaultNullComparator implements NullComparator { |
|||
|
|||
/** |
|||
* 当要比较的两个JsonElement是空类型时,默认比较方法 |
|||
* @param a 第一个空类型 |
|||
* @param b 第二个空类型 |
|||
* @param pathModule 路径模型 |
|||
* @return 返回结果 |
|||
*/ |
|||
@Override |
|||
public DiffContext diff(JsonNull a, JsonNull b, PathModule pathModule){ |
|||
return new DiffContext(); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,25 @@ |
|||
package com.zc.business.utils.diff.algorithm.nulls; |
|||
|
|||
import com.google.gson.JsonNull; |
|||
import com.zc.business.utils.diff.algorithm.Comparator; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
/** |
|||
* 空类型比较器接口,用于2个JsonElement均为JsonNull时对2个元素进行比较。 |
|||
* @Author JingWei |
|||
* @create 2022/2/23 |
|||
*/ |
|||
public interface NullComparator extends Comparator { |
|||
|
|||
/** |
|||
* 对两个JsonNull进行比较时,需要实现此方法。 |
|||
* @param a 要比较的第一个JsonNull |
|||
* @param b 要比较的第二个JsonNull |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不同的比较结果 |
|||
*/ |
|||
DiffContext diff(JsonNull a, JsonNull b, PathModule pathModule); |
|||
|
|||
|
|||
} |
@ -0,0 +1,128 @@ |
|||
package com.zc.business.utils.diff.algorithm.object; |
|||
|
|||
import com.google.common.base.Joiner; |
|||
import com.google.gson.JsonObject; |
|||
import com.zc.business.utils.diff.algorithm.AbstractObjectAndArray; |
|||
import com.zc.business.utils.diff.model.Constants; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
import java.util.Set; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 对象比较的一些公有方法抽象类 |
|||
* @Author JingWei |
|||
* @create 2022/2/24 |
|||
*/ |
|||
public abstract class AbstractObject extends AbstractObjectAndArray implements ObjectComparator { |
|||
|
|||
/** |
|||
* 对两个对象进行比较:遍历keySet中的所有key, 在a和b对象中找对应的value值进行比较 |
|||
* @param a 要比较的第一个对象 |
|||
* @param b 要比较的第二个对象 |
|||
* @param keySet key的集合 |
|||
* @param pathModule 路径模型 |
|||
* @return 不同的比较结果 |
|||
*/ |
|||
protected DiffContext diffValueByKey(JsonObject a, JsonObject b, Set<String> keySet, PathModule pathModule) { |
|||
DiffContext objectDiffContext = new DiffContext(); |
|||
LinkedList<String> specialPathResult = new LinkedList<>(); |
|||
for (String key : keySet) { |
|||
//更新a和b当前路径
|
|||
pathModule.addAllpath(key); |
|||
//如果对象当前路径在噪音路径集合中,直接跳过比较
|
|||
if (!needDiff(pathModule.getNoisePahList(), pathModule.getLeftPath())) { |
|||
pathModule.removeAllLastPath(); |
|||
continue; |
|||
} |
|||
//生成比较结果
|
|||
DiffContext diffContext = diffElement(a.get(key), b.get(key), pathModule); |
|||
parentContextAddChildContext(objectDiffContext, diffContext); |
|||
//特殊路径处理
|
|||
specialPathHandle(diffContext.isSame(), specialPathResult, pathModule); |
|||
pathModule.removeAllLastPath(); |
|||
|
|||
} |
|||
objectDiffContext.setSpecialPathResult(specialPathResult); |
|||
return objectDiffContext; |
|||
} |
|||
|
|||
/** |
|||
* 如果比较的路径为特殊路径并且比较相等,特殊路径会被标识,添加到返回结果中。 |
|||
* @param isSame 比较结果是否相等 |
|||
* @param specialPathResult 返回的特殊路径结果 |
|||
* @param pathModule 路径模型 |
|||
*/ |
|||
private void specialPathHandle(boolean isSame,LinkedList<String> specialPathResult, PathModule pathModule) { |
|||
//如果比较结果不等,直接返回。
|
|||
if (!isSame){ |
|||
return; |
|||
} |
|||
//如果存在特殊路径,将特殊路径加入到集合中
|
|||
String specialPath = getSpecialPath(pathModule); |
|||
if( existPath(specialPath)){ |
|||
specialPathResult.add(specialPath); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 校验路径是否存在,即路径是否为空 |
|||
* @param specialPath 特殊路径 |
|||
* @return 特殊路径是否为空 |
|||
*/ |
|||
private boolean existPath(String specialPath) { |
|||
return specialPath != null; |
|||
} |
|||
|
|||
/** |
|||
* 判断当前路径是否在特殊路径集合中,如果在,则返回特殊路径。 |
|||
* @param pathModule 路径模型 |
|||
* @return 返回的特殊路径字符串 |
|||
*/ |
|||
protected String getSpecialPath(PathModule pathModule) { |
|||
if(pathModule == null || pathModule.getSpecialPath() == null || pathModule.getSpecialPath().isEmpty()){ |
|||
return null; |
|||
} |
|||
String currentPath = listJoin(pathModule.getLeftPath()); |
|||
if(pathModule.getSpecialPath().contains(currentPath)){ |
|||
return currentPath; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 判断当前字段是否需要diff,如果在噪音字段集合中,则不需要diff,返回false。 |
|||
* @param noisePahList 噪音路径列表 |
|||
* @param pathList 当前路径 |
|||
* @return 当前路径是否在噪音路径中 |
|||
*/ |
|||
protected boolean needDiff(List<String> noisePahList, LinkedList<String> pathList) { |
|||
if(noisePahList == null || pathList == null || noisePahList.isEmpty() || pathList.isEmpty()){ |
|||
return true; |
|||
} |
|||
String path = listJoin(pathList); |
|||
if(noisePahList.contains(path)){ |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* 将path路径列表改为字符串 |
|||
* @param path 当前路径 |
|||
* @return 当前路径字符串 |
|||
*/ |
|||
protected String listJoin(LinkedList<String> path) { |
|||
if(path == null){ |
|||
throw new RuntimeException("当前路径不能为空"); |
|||
} |
|||
List<String> collect = path.stream().filter(e -> e.charAt(0) != '[').collect(Collectors.toList()); |
|||
return Joiner.on(Constants.MERGE_PATH).join(collect); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,30 @@ |
|||
package com.zc.business.utils.diff.algorithm.object; |
|||
|
|||
import com.google.gson.JsonObject; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
/** |
|||
* 左匹配对象比较器:当对两个JsonObject进行比较时,只对第一个对象中keySet中存在keyValue值进行比较。 |
|||
* |
|||
* 举例: |
|||
* {"a":1,"b":2,"c":3}和{"a":1,"b":4,"c":3,"d":4}进行比较 |
|||
* 只会比较第一个对象中有的字段,即比较第一个对象中有的"a","b","c"3个字段,第二个对象中的"d"字段没有被比较 |
|||
* |
|||
* @Author JingWei |
|||
* @create 2022/2/18 |
|||
*/ |
|||
public class LeftJoinObjectComparator extends AbstractObject { |
|||
/** |
|||
* @param a 要比较的第一个JsonObject |
|||
* @param b 要比较的第二个JsonObject |
|||
* @param pathModule 路径模型 |
|||
* @return 不同的比较结果 |
|||
*/ |
|||
@Override |
|||
public DiffContext diff(JsonObject a, JsonObject b, PathModule pathModule){ |
|||
//用a的keySet作为遍历集合。
|
|||
return diffValueByKey(a, b, a.keySet(), pathModule); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package com.zc.business.utils.diff.algorithm.object; |
|||
|
|||
import com.google.gson.JsonElement; |
|||
import com.google.gson.JsonObject; |
|||
import com.zc.business.utils.diff.algorithm.AlgorithmModule; |
|||
import com.zc.business.utils.diff.algorithm.Comparator; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
/** |
|||
* 对象类型比较器接口,用于2个JsonElement均为JsonObject时对2个元素进行比较。 |
|||
* @Author JingWei |
|||
* @create 2022/2/23 |
|||
*/ |
|||
public interface ObjectComparator extends Comparator { |
|||
|
|||
/** |
|||
* 对两个JsonObject进行比较时,需要实现此方法。 |
|||
* @param a 要比较的第一个JsonObject |
|||
* @param b 要比较的第二个JsonObject |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不同的比较结果 |
|||
*/ |
|||
DiffContext diff(JsonObject a, JsonObject b, PathModule pathModule); |
|||
|
|||
/** |
|||
* 对象内部包含其他非JsonObject类型,对这些类型比较需要使用JsonElement比较方法 |
|||
* @param a 元素a |
|||
* @param b 元素b |
|||
* @param pathModule 路径模型 |
|||
* @return 返回不同的比较结果 |
|||
*/ |
|||
DiffContext diffElement(JsonElement a, JsonElement b, PathModule pathModule); |
|||
|
|||
/** |
|||
* 构造算法模型,对象比较时,内部元素比较需要使用到其他非数组算法 |
|||
* @param algorithmModule 算法模型:包含对象、数组、基本类型、空类型、其他类型算法 |
|||
*/ |
|||
void constructAlgorithmModule(AlgorithmModule algorithmModule); |
|||
} |
@ -0,0 +1,33 @@ |
|||
package com.zc.business.utils.diff.algorithm.object; |
|||
|
|||
import com.google.common.collect.Sets; |
|||
import com.google.gson.JsonObject; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* 简单对象比较器:当对两个JsonObject进行比较时,两个对象所有keySet中key对应的Value都会被比较。 |
|||
* 举例: |
|||
* {"b":2,"c":3}和{"a":1,"d":4}进行比较 |
|||
* 会比较两个对象中所有的字段,即比较两个对象中并集"a","b","c","d"4个字段 |
|||
* @Author JingWei |
|||
* @create 2022/2/16 |
|||
*/ |
|||
public class SimpleObjectComparator extends AbstractObject { |
|||
/** |
|||
* @param a 要比较的第一个JsonObject |
|||
* @param b 要比较的第二个JsonObject |
|||
* @param pathModule 路径模型 |
|||
* @return 不同的比较结果 |
|||
*/ |
|||
@Override |
|||
public DiffContext diff(JsonObject a, JsonObject b, PathModule pathModule) { |
|||
Set<String> unionSet = Sets.union(a.keySet(), b.keySet()); |
|||
//用a和b的keySet的并集作为遍历集合。
|
|||
return diffValueByKey(a, b, unionSet, pathModule); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package com.zc.business.utils.diff.algorithm.other; |
|||
|
|||
import com.google.common.base.Joiner; |
|||
import com.google.gson.JsonElement; |
|||
import com.zc.business.utils.diff.algorithm.AbstractPrimitiveAndOther; |
|||
import com.zc.business.utils.diff.model.Constants; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
import com.zc.business.utils.diff.model.SingleNodeDifference; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 当要比较的两个JsonElement的不同时为对象、组数、空、基本类型时,默认实现的比较器。 |
|||
* @Author JingWei |
|||
* @create 2022/1/10 |
|||
*/ |
|||
public class DefaultOtherComparator extends AbstractPrimitiveAndOther implements OtherComparator { |
|||
|
|||
/** |
|||
* @param a 要比较的第一个JsonElement |
|||
* @param b 要比较的第二个JsonElement |
|||
* @param pathModule 路径模型 |
|||
* @return 不同的比较结果 |
|||
*/ |
|||
@Override |
|||
public DiffContext diff(JsonElement a, JsonElement b, PathModule pathModule){ |
|||
//比较结果一定会不同,因为要比较的a和b类型不同才会调用该方法。
|
|||
DiffContext otherDiffContext = new DiffContext(Constants.DIFFERENT); |
|||
List<SingleNodeDifference> singleNodeDifferences = new ArrayList<>(); |
|||
singleNodeDifferences.add(new SingleNodeDifference(Joiner.on(Constants.MERGE_PATH).join(pathModule.getLeftPath()), Joiner.on(Constants.MERGE_PATH).join(pathModule.getRightPath()), jsonElement2Str(a), jsonElement2Str(b))); |
|||
otherDiffContext.setDiffResultModels(singleNodeDifferences); |
|||
return otherDiffContext; |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.zc.business.utils.diff.algorithm.other; |
|||
|
|||
import com.google.gson.JsonElement; |
|||
import com.zc.business.utils.diff.algorithm.Comparator; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
/** |
|||
* 其他类型比较器接口,用于2个JsonElement不同时为对象、数组、空、基本类型时对2个元素进行比较。 |
|||
* |
|||
* 举例:第一个要比较类型为对象类型,第二个要比较类型为数组类型。 |
|||
* @Author JingWei |
|||
* @create 2022/2/23 |
|||
*/ |
|||
public interface OtherComparator extends Comparator { |
|||
/** |
|||
* 对两个JsonElement进行比较并且两个JsonElement的类型不相等时,需要实现此方法。 |
|||
* @param a 要比较的第一个JsonElement |
|||
* @param b 要比较的第二个JsonElement |
|||
* @return 不同的比较结果 |
|||
*/ |
|||
DiffContext diff(JsonElement a, JsonElement b, PathModule pathModule); |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package com.zc.business.utils.diff.algorithm.primitive; |
|||
|
|||
import com.google.common.base.Joiner; |
|||
import com.google.gson.JsonPrimitive; |
|||
import com.zc.business.utils.diff.algorithm.AbstractPrimitiveAndOther; |
|||
import com.zc.business.utils.diff.model.Constants; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
import com.zc.business.utils.diff.model.SingleNodeDifference; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 当要比较的两个JsonElement是基本类型时,默认实现的比较器。 |
|||
* @Author JingWei |
|||
* @create 2022/1/10 |
|||
*/ |
|||
public class DefaultPrimitiveComparator extends AbstractPrimitiveAndOther implements PrimitiveComparator { |
|||
/** |
|||
* @param a 要比较的第一个JsonPrimitive |
|||
* @param b 要比较的第二个JsonPrimitive |
|||
* @param pathModule 路径模型 |
|||
* @return 不同的比较结果 |
|||
*/ |
|||
@Override |
|||
public DiffContext diff(JsonPrimitive a, JsonPrimitive b, PathModule pathModule){ |
|||
DiffContext primitiveDiffContext = new DiffContext(); |
|||
//如果a和b不相等,返回a和b的比较结果。
|
|||
if(Constants.DIFFERENT == a.equals(b)) { |
|||
List<SingleNodeDifference> singleNodeDifferences = new ArrayList<>(); |
|||
singleNodeDifferences.add(new SingleNodeDifference(Joiner.on(Constants.MERGE_PATH).join(pathModule.getLeftPath()), Joiner.on(Constants.MERGE_PATH).join(pathModule.getRightPath()), jsonElement2Str(a), jsonElement2Str(b))); |
|||
primitiveDiffContext.setDiffResultModels(singleNodeDifferences); |
|||
primitiveDiffContext.setSame(Constants.DIFFERENT); |
|||
} |
|||
return primitiveDiffContext; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.zc.business.utils.diff.algorithm.primitive; |
|||
|
|||
import com.google.gson.JsonPrimitive; |
|||
import com.zc.business.utils.diff.algorithm.Comparator; |
|||
import com.zc.business.utils.diff.model.DiffContext; |
|||
import com.zc.business.utils.diff.model.PathModule; |
|||
|
|||
/** |
|||
* 基本类型比较器接口,用于2个JsonElement均为基本类型的时对2个元素进行比较。 |
|||
* @Author JingWei |
|||
* @create 2022/2/23 |
|||
*/ |
|||
public interface PrimitiveComparator extends Comparator { |
|||
/** |
|||
* 对两个基本类型进行比较时,需要实现此方法。 |
|||
* @param a 要比较的第一个JsonPrimitive |
|||
* @param b 要比较的第二个JsonPrimitive |
|||
* @param pathModule 路径模型 |
|||
* @return 不同的比较结果 |
|||
*/ |
|||
DiffContext diff(JsonPrimitive a, JsonPrimitive b, PathModule pathModule); |
|||
|
|||
} |
@ -0,0 +1,20 @@ |
|||
package com.zc.business.utils.diff.model; |
|||
|
|||
|
|||
/** |
|||
* 常量 |
|||
* @Author JingWei |
|||
* @create 2022/3/2 |
|||
*/ |
|||
public class Constants { |
|||
/** |
|||
* 描述比较结果不同 |
|||
*/ |
|||
public static final boolean DIFFERENT = false; |
|||
/** |
|||
* 描述比较结果相同 |
|||
*/ |
|||
public static final boolean SAME = true; |
|||
public static final String SPLIT_PATH = "\\."; |
|||
public static final String MERGE_PATH = "."; |
|||
} |
@ -0,0 +1,61 @@ |
|||
package com.zc.business.utils.diff.model; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* diff比较上下文 |
|||
* @Author JingWei |
|||
* @create 2022/3/2 |
|||
*/ |
|||
public class DiffContext { |
|||
/** |
|||
* 比较结果是否相同 |
|||
*/ |
|||
private boolean isSame; |
|||
|
|||
/** |
|||
* 比较结果不同时,存储所有不同的结果对 |
|||
*/ |
|||
private List<SingleNodeDifference> singleNodeDifferences; |
|||
|
|||
/** |
|||
* 比较结果中,出现了特殊路径下值相等的情况,会存储该特殊路径。 |
|||
*/ |
|||
private LinkedList<String> specialPathResult; |
|||
|
|||
public DiffContext(boolean isSame) { |
|||
this.isSame = isSame; |
|||
this.singleNodeDifferences = new ArrayList<>(); |
|||
} |
|||
|
|||
public boolean isSame() { |
|||
return isSame; |
|||
} |
|||
|
|||
public void setSame(boolean same) { |
|||
isSame = same; |
|||
} |
|||
|
|||
public List<SingleNodeDifference> getDiffResultModels() { |
|||
return singleNodeDifferences; |
|||
} |
|||
|
|||
public void setDiffResultModels(List<SingleNodeDifference> singleNodeDifferences) { |
|||
this.singleNodeDifferences = singleNodeDifferences; |
|||
} |
|||
|
|||
public DiffContext() { |
|||
this.isSame = true; |
|||
this.singleNodeDifferences = new ArrayList<>(); |
|||
} |
|||
|
|||
public LinkedList<String> getSpecialPathResult() { |
|||
return specialPathResult; |
|||
} |
|||
|
|||
public void setSpecialPathResult(LinkedList<String> specialPathResult) { |
|||
this.specialPathResult = specialPathResult; |
|||
} |
|||
} |
@ -0,0 +1,122 @@ |
|||
package com.zc.business.utils.diff.model; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 路径模型 |
|||
* A和B比较时,实时更新当前正在进行比较的元素路径。 |
|||
* |
|||
* @Author JingWei |
|||
* @create 2022/2/15 |
|||
*/ |
|||
public class PathModule { |
|||
/** |
|||
* 对象A当前遍历到的路径 |
|||
*/ |
|||
private LinkedList<String> leftPath; |
|||
/** |
|||
* 对象B当前遍历到的路径 |
|||
*/ |
|||
private LinkedList<String> rightPath; |
|||
/** |
|||
* 特殊路径集合。当前路径符合特殊路径且特殊路径下比较结果相同,会在返回结果中做额外标识标识。 |
|||
*/ |
|||
private List<String> specialPath; |
|||
/** |
|||
* 噪音字段集合。如果当前路径符合噪音字段路径,则不会比较。 |
|||
*/ |
|||
private List<String> noisePahList; |
|||
|
|||
public PathModule() { |
|||
this.leftPath = new LinkedList<>(); |
|||
this.rightPath = new LinkedList<>(); |
|||
} |
|||
|
|||
public PathModule(List<String> noisePahList) { |
|||
this.leftPath = new LinkedList<>(); |
|||
this.rightPath = new LinkedList<>(); |
|||
this.noisePahList = noisePahList; |
|||
} |
|||
|
|||
public PathModule(List<String> noisePahList, List<String> specialPath) { |
|||
this.leftPath = new LinkedList<>(); |
|||
this.rightPath = new LinkedList<>(); |
|||
this.noisePahList = noisePahList; |
|||
this.specialPath = specialPath; |
|||
} |
|||
|
|||
public List<String> getNoisePahList() { |
|||
return noisePahList; |
|||
} |
|||
|
|||
public void setNoisePahList(List<String> noisePahList) { |
|||
this.noisePahList = noisePahList; |
|||
} |
|||
|
|||
public List<String> getSpecialPath() { |
|||
return specialPath; |
|||
} |
|||
|
|||
public void setSpecialPath(LinkedList<String> specialPath) { |
|||
this.specialPath = specialPath; |
|||
} |
|||
|
|||
public LinkedList<String> getLeftPath() { |
|||
return leftPath; |
|||
} |
|||
|
|||
public void setLeftPath(LinkedList<String> leftPath) { |
|||
this.leftPath = leftPath; |
|||
} |
|||
|
|||
public LinkedList<String> getRightPath() { |
|||
return rightPath; |
|||
} |
|||
|
|||
public void setRightPath(LinkedList<String> rightPath) { |
|||
this.rightPath = rightPath; |
|||
} |
|||
|
|||
/** |
|||
* 同时在A和B路径列表最后加上一个Path路径 |
|||
*/ |
|||
public void addAllpath(String lastPath) { |
|||
leftPath.add(lastPath); |
|||
rightPath.add(lastPath); |
|||
} |
|||
|
|||
public void addLeftPath(String lastPath) { |
|||
leftPath.add(lastPath); |
|||
} |
|||
|
|||
public void addRightPath(String lastPath) { |
|||
rightPath.add(lastPath); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 同时移除A和B路径列表中最后的一个路径 |
|||
*/ |
|||
public void removeAllLastPath() { |
|||
leftPath.removeLast(); |
|||
rightPath.removeLast(); |
|||
} |
|||
|
|||
/** |
|||
* 移除A路径列表中最后的一个路径 |
|||
*/ |
|||
public void removeLastLeftPath() { |
|||
leftPath.removeLast(); |
|||
} |
|||
|
|||
/** |
|||
* 移除B路径列表中最后的一个路径 |
|||
*/ |
|||
public void removeLastRightPath() { |
|||
rightPath.removeLast(); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -0,0 +1,71 @@ |
|||
package com.zc.business.utils.diff.model; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* diff比较最终结果 |
|||
* @Author JingWei |
|||
* @create 2022/3/2 |
|||
*/ |
|||
public class Result implements Serializable { |
|||
/** |
|||
* 第一个对象路径 |
|||
*/ |
|||
private String leftPath; |
|||
/** |
|||
* 第二个对象路径 |
|||
*/ |
|||
private String rightPath; |
|||
/** |
|||
* 第一个对象值 |
|||
*/ |
|||
private Object left; |
|||
/** |
|||
* 第二个对象值 |
|||
*/ |
|||
private Object right; |
|||
/** |
|||
* 比较结果 |
|||
*/ |
|||
private String diffType; |
|||
|
|||
public String getLeftPath() { |
|||
return leftPath; |
|||
} |
|||
|
|||
public String getRightPath() { |
|||
return rightPath; |
|||
} |
|||
|
|||
public void setLeftPath(String leftPath) { |
|||
this.leftPath = leftPath; |
|||
} |
|||
|
|||
public void setRightPath(String rightPath) { |
|||
this.rightPath = rightPath; |
|||
} |
|||
|
|||
public Object getLeft() { |
|||
return left; |
|||
} |
|||
|
|||
public void setLeft(Object left) { |
|||
this.left = left; |
|||
} |
|||
|
|||
public Object getRight() { |
|||
return right; |
|||
} |
|||
|
|||
public void setRight(Object right) { |
|||
this.right = right; |
|||
} |
|||
|
|||
public String getDiffType() { |
|||
return diffType; |
|||
} |
|||
|
|||
public void setDiffType(String diffType) { |
|||
this.diffType = diffType; |
|||
} |
|||
} |
@ -0,0 +1,66 @@ |
|||
package com.zc.business.utils.diff.model; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Objects; |
|||
|
|||
/** |
|||
* 结果转换工具:将diff上下文转换成diff最终结果 |
|||
* @Author JingWei |
|||
* @create 2022/2/25 |
|||
*/ |
|||
public class ResultConvertUtil { |
|||
public static final String OBJECT_NULL = null; |
|||
//diff结果类型分为修改、新增、删除
|
|||
public static final String TYPE_MODIFY = "MODIFY"; |
|||
public static final String TYPE_ADD = "ADD"; |
|||
public static final String TYPE_DELETE = "DELETE"; |
|||
|
|||
/** |
|||
* 将diff上下文转换成diff最终结果 |
|||
* @param diffContext diff比较的直接结果 |
|||
* @return diff展示的结果 |
|||
*/ |
|||
public static ArrayList<Result> constructResult(DiffContext diffContext) { |
|||
ArrayList<Result> list = new ArrayList<>(); |
|||
for (SingleNodeDifference resultModel : diffContext.getDiffResultModels()) { |
|||
Result printModel = convert(resultModel); |
|||
boolean leftAndRightBothNull = (Objects.equals(OBJECT_NULL,resultModel.getLeft())) |
|||
&& Objects.equals(OBJECT_NULL,resultModel.getRight()) ; |
|||
//判断两个对象是否同时为空
|
|||
if (leftAndRightBothNull) { |
|||
printModel.setDiffType(TYPE_MODIFY); |
|||
} |
|||
//这种情况为对象A中keySet没这个key,或者A数组长度小于B 数组中没这个元素。
|
|||
else if (Objects.equals(OBJECT_NULL,resultModel.getLeft()) ) { |
|||
printModel.setDiffType(TYPE_ADD); |
|||
printModel.setLeftPath(null); |
|||
} |
|||
//这种情况为对象B中keySet没这个key,或者B数组长度小于A 数组中没这个元素。
|
|||
else if (Objects.equals(OBJECT_NULL,resultModel.getRight()) ) { |
|||
printModel.setDiffType(TYPE_DELETE); |
|||
printModel.setRightPath(null); |
|||
} |
|||
//其他情况
|
|||
else { |
|||
printModel.setDiffType(TYPE_MODIFY); |
|||
} |
|||
list.add(printModel); |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 数据模型转换,增加类型字段。 |
|||
* @param resultModel 比较结果 |
|||
* @return 展示模型 |
|||
*/ |
|||
private static Result convert(SingleNodeDifference resultModel) { |
|||
Result printModel = new Result(); |
|||
printModel.setLeft(resultModel.getLeft()); |
|||
printModel.setRight(resultModel.getRight()); |
|||
printModel.setLeftPath(resultModel.getLeftPath()); |
|||
printModel.setRightPath(resultModel.getRightPath()); |
|||
return printModel; |
|||
} |
|||
} |
@ -0,0 +1,69 @@ |
|||
package com.zc.business.utils.diff.model; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 单对元素比较结果 |
|||
* @Author JingWei |
|||
* @create 2022/3/2 |
|||
*/ |
|||
public class SingleNodeDifference implements Serializable { |
|||
/** |
|||
* 第一个对象路径 |
|||
*/ |
|||
private String leftPath; |
|||
/** |
|||
* 第二个对象路径 |
|||
*/ |
|||
private String rightPath; |
|||
/** |
|||
* 第一个对象值 |
|||
*/ |
|||
private Object left; |
|||
/** |
|||
* 第二个对象值 |
|||
*/ |
|||
private Object right; |
|||
/** |
|||
* 比较结果 |
|||
*/ |
|||
|
|||
public SingleNodeDifference(String leftPath, String rightPath, Object left, Object right) { |
|||
this.leftPath = leftPath; |
|||
this.rightPath = rightPath; |
|||
this.left = left; |
|||
this.right = right; |
|||
} |
|||
|
|||
public String getLeftPath() { |
|||
return leftPath; |
|||
} |
|||
|
|||
public void setLeftPath(String leftPath) { |
|||
this.leftPath = leftPath; |
|||
} |
|||
|
|||
public String getRightPath() { |
|||
return rightPath; |
|||
} |
|||
|
|||
public void setRightPath(String rightPath) { |
|||
this.rightPath = rightPath; |
|||
} |
|||
|
|||
public Object getLeft() { |
|||
return left; |
|||
} |
|||
|
|||
public void setLeft(Object left) { |
|||
this.left = left; |
|||
} |
|||
|
|||
public Object getRight() { |
|||
return right; |
|||
} |
|||
|
|||
public void setRight(Object right) { |
|||
this.right = right; |
|||
} |
|||
} |
@ -0,0 +1,106 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.zc.business.mapper.DcEventImportantFileMapper"> |
|||
|
|||
<resultMap type="DcEventImportantFile" id="DcEventImportantFileResult"> |
|||
<result property="id" column="id" /> |
|||
<result property="eventId" column="event_id" /> |
|||
<result property="fromDept" column="from_dept" /> |
|||
<result property="createTime" column="create_time" /> |
|||
<result property="title" column="title" /> |
|||
<result property="toDept" column="to_dept" /> |
|||
<result property="content" column="content" /> |
|||
<result property="createName" column="create_name" /> |
|||
<result property="phoneNumber" column="phone_number" /> |
|||
<result property="issued" column="issued" /> |
|||
<result property="type" column="type" /> |
|||
</resultMap> |
|||
|
|||
<sql id="selectDcEventImportantFileVo"> |
|||
select id,event_id, from_dept, create_time, title, to_dept, content, create_name, phone_number, issued, type from dc_event_important_file |
|||
</sql> |
|||
|
|||
<select id="selectDcEventImportantFileList" parameterType="DcEventImportantFile" resultMap="DcEventImportantFileResult"> |
|||
<include refid="selectDcEventImportantFileVo"/> |
|||
<where> |
|||
<if test="eventId != null and fromDept != ''"> and event_id = #{eventId}</if> |
|||
<if test="fromDept != null and fromDept != ''"> and from_dept = #{fromDept}</if> |
|||
<if test="title != null and title != ''"> and title = #{title}</if> |
|||
<if test="toDept != null and toDept != ''"> and to_dept = #{toDept}</if> |
|||
<if test="content != null and content != ''"> and content = #{content}</if> |
|||
<if test="createName != null and createName != ''"> and create_name like concat('%', #{createName}, '%')</if> |
|||
<if test="phoneNumber != null and phoneNumber != ''"> and phone_number = #{phoneNumber}</if> |
|||
<if test="issued != null and issued != ''"> and issued = #{issued}</if> |
|||
<if test="type != null and type != ''"> and type = #{type}</if> |
|||
</where> |
|||
</select> |
|||
|
|||
<select id="selectDcEventImportantFileByEventId" parameterType="String" resultMap="DcEventImportantFileResult"> |
|||
<include refid="selectDcEventImportantFileVo"/> |
|||
where id = #{id} |
|||
</select> |
|||
<select id="getImportantFileStatus" resultType="java.lang.Integer"> |
|||
SELECT IFNULL(max(type),0) type |
|||
FROM `dc_event_important_file` |
|||
where event_id = #{eventId} |
|||
</select> |
|||
|
|||
<insert id="insertDcEventImportantFile" parameterType="DcEventImportantFile" useGeneratedKeys="true" keyProperty="id"> |
|||
insert into dc_event_important_file |
|||
<trim prefix="(" suffix=")" suffixOverrides=","> |
|||
<if test="eventId != null">event_id,</if> |
|||
<if test="fromDept != null">from_dept,</if> |
|||
<if test="createTime != null">create_time,</if> |
|||
<if test="title != null">title,</if> |
|||
<if test="toDept != null">to_dept,</if> |
|||
<if test="content != null">content,</if> |
|||
<if test="createName != null">create_name,</if> |
|||
<if test="phoneNumber != null">phone_number,</if> |
|||
<if test="issued != null">issued,</if> |
|||
<if test="type != null">type,</if> |
|||
</trim> |
|||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|||
<if test="eventId != null">#{eventId},</if> |
|||
<if test="fromDept != null">#{fromDept},</if> |
|||
<if test="createTime != null">#{createTime},</if> |
|||
<if test="title != null">#{title},</if> |
|||
<if test="toDept != null">#{toDept},</if> |
|||
<if test="content != null">#{content},</if> |
|||
<if test="createName != null">#{createName},</if> |
|||
<if test="phoneNumber != null">#{phoneNumber},</if> |
|||
<if test="issued != null">#{issued},</if> |
|||
<if test="type != null">#{type},</if> |
|||
</trim> |
|||
</insert> |
|||
|
|||
<update id="updateDcEventImportantFile" parameterType="DcEventImportantFile"> |
|||
update dc_event_important_file |
|||
<trim prefix="SET" suffixOverrides=","> |
|||
<if test="eventId != null">event_id = #{eventId},</if> |
|||
<if test="fromDept != null">from_dept = #{fromDept},</if> |
|||
<if test="fromDept != null">from_dept = #{fromDept},</if> |
|||
<if test="createTime != null">create_time = #{createTime},</if> |
|||
<if test="title != null">title = #{title},</if> |
|||
<if test="toDept != null">to_dept = #{toDept},</if> |
|||
<if test="content != null">content = #{content},</if> |
|||
<if test="createName != null">create_name = #{createName},</if> |
|||
<if test="phoneNumber != null">phone_number = #{phoneNumber},</if> |
|||
<if test="issued != null">issued = #{issued},</if> |
|||
<if test="type != null">type = #{type},</if> |
|||
</trim> |
|||
where id = #{id} |
|||
</update> |
|||
|
|||
<delete id="deleteDcEventImportantFileByEventId" parameterType="String"> |
|||
delete from dc_event_important_file where id = #{id} |
|||
</delete> |
|||
|
|||
<delete id="deleteDcEventImportantFileByEventIds" parameterType="String"> |
|||
delete from dc_event_important_file where id in |
|||
<foreach item="id" collection="array" open="(" separator="," close=")"> |
|||
#{id} |
|||
</foreach> |
|||
</delete> |
|||
</mapper> |
@ -0,0 +1,121 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.zc.business.mapper.DcEventImportantMapper"> |
|||
|
|||
<resultMap type="DcEventImportant" id="DcEventImportantResult"> |
|||
<result property="id" column="id" /> |
|||
<result property="eventId" column="event_id" /> |
|||
<result property="plateNumber" column="plate_number" /> |
|||
<result property="diversionPoint" column="diversion_point" /> |
|||
<result property="currentProgress" column="current_progress" /> |
|||
<result property="takeSteps" column="take_steps" /> |
|||
<result property="planStatus" column="plan_status" /> |
|||
<result property="trafficPoliceStatus" column="traffic_police_status" /> |
|||
<result property="medicalStatus" column="medical_status" /> |
|||
<result property="fireStatus" column="fire_status" /> |
|||
<result property="boardStatus" column="board_status" /> |
|||
<result property="chemicalsStatus" column="chemicals_status" /> |
|||
<result property="planLevel" column="plan_level" /> |
|||
<result property="chemicalsName" column="chemicals_name" /> |
|||
<result property="leakageLevel" column="leakage_level" /> |
|||
</resultMap> |
|||
|
|||
<sql id="selectDcEventImportantVo"> |
|||
select id, event_id, plate_number, diversion_point, current_progress, take_steps, plan_status, traffic_police_status, medical_status, fire_status, board_status, chemicals_status, plan_level, chemicals_name, leakage_level from dc_event_important |
|||
</sql> |
|||
|
|||
<select id="selectDcEventImportantList" parameterType="DcEventImportant" resultMap="DcEventImportantResult"> |
|||
<include refid="selectDcEventImportantVo"/> |
|||
<where> |
|||
<if test="eventId != null and eventId != ''"> and event_id = #{eventId}</if> |
|||
<if test="plateNumber != null and plateNumber != ''"> and plate_number = #{plateNumber}</if> |
|||
<if test="diversionPoint != null and diversionPoint != ''"> and diversion_point = #{diversionPoint}</if> |
|||
<if test="currentProgress != null and currentProgress != ''"> and current_progress = #{currentProgress}</if> |
|||
<if test="takeSteps != null and takeSteps != ''"> and take_steps = #{takeSteps}</if> |
|||
<if test="planStatus != null "> and plan_status = #{planStatus}</if> |
|||
<if test="trafficPoliceStatus != null "> and traffic_police_status = #{trafficPoliceStatus}</if> |
|||
<if test="medicalStatus != null "> and medical_status = #{medicalStatus}</if> |
|||
<if test="fireStatus != null "> and fire_status = #{fireStatus}</if> |
|||
<if test="boardStatus != null "> and board_status = #{boardStatus}</if> |
|||
<if test="chemicalsStatus != null "> and chemicals_status = #{chemicalsStatus}</if> |
|||
<if test="planLevel != null and planLevel != ''"> and plan_level = #{planLevel}</if> |
|||
<if test="chemicalsName != null and chemicalsName != ''"> and chemicals_name like concat('%', #{chemicalsName}, '%')</if> |
|||
<if test="leakageLevel != null and leakageLevel != ''"> and leakage_level = #{leakageLevel}</if> |
|||
</where> |
|||
</select> |
|||
|
|||
<select id="selectDcEventImportantByEventId" parameterType="String" resultMap="DcEventImportantResult"> |
|||
<include refid="selectDcEventImportantVo"/> |
|||
where event_id = #{eventId} |
|||
</select> |
|||
|
|||
<insert id="insertDcEventImportant" parameterType="DcEventImportant"> |
|||
insert into dc_event_important |
|||
<trim prefix="(" suffix=")" suffixOverrides=","> |
|||
<if test="eventId != null">event_id,</if> |
|||
<if test="plateNumber != null">plate_number,</if> |
|||
<if test="diversionPoint != null">diversion_point,</if> |
|||
<if test="currentProgress != null">current_progress,</if> |
|||
<if test="takeSteps != null">take_steps,</if> |
|||
<if test="planStatus != null">plan_status,</if> |
|||
<if test="trafficPoliceStatus != null">traffic_police_status,</if> |
|||
<if test="medicalStatus != null">medical_status,</if> |
|||
<if test="fireStatus != null">fire_status,</if> |
|||
<if test="boardStatus != null">board_status,</if> |
|||
<if test="chemicalsStatus != null">chemicals_status,</if> |
|||
<if test="planLevel != null">plan_level,</if> |
|||
<if test="chemicalsName != null">chemicals_name,</if> |
|||
<if test="leakageLevel != null">leakage_level,</if> |
|||
</trim> |
|||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|||
<if test="eventId != null">#{eventId},</if> |
|||
<if test="plateNumber != null">#{plateNumber},</if> |
|||
<if test="diversionPoint != null">#{diversionPoint},</if> |
|||
<if test="currentProgress != null">#{currentProgress},</if> |
|||
<if test="takeSteps != null">#{takeSteps},</if> |
|||
<if test="planStatus != null">#{planStatus},</if> |
|||
<if test="trafficPoliceStatus != null">#{trafficPoliceStatus},</if> |
|||
<if test="medicalStatus != null">#{medicalStatus},</if> |
|||
<if test="fireStatus != null">#{fireStatus},</if> |
|||
<if test="boardStatus != null">#{boardStatus},</if> |
|||
<if test="chemicalsStatus != null">#{chemicalsStatus},</if> |
|||
<if test="planLevel != null">#{planLevel},</if> |
|||
<if test="chemicalsName != null">#{chemicalsName},</if> |
|||
<if test="leakageLevel != null">#{leakageLevel},</if> |
|||
</trim> |
|||
</insert> |
|||
|
|||
<update id="updateDcEventImportant" parameterType="DcEventImportant"> |
|||
update dc_event_important |
|||
<trim prefix="SET" suffixOverrides=","> |
|||
<if test="eventId != null">event_id = #{eventId},</if> |
|||
<if test="plateNumber != null">plate_number = #{plateNumber},</if> |
|||
<if test="diversionPoint != null">diversion_point = #{diversionPoint},</if> |
|||
<if test="currentProgress != null">current_progress = #{currentProgress},</if> |
|||
<if test="takeSteps != null">take_steps = #{takeSteps},</if> |
|||
<if test="planStatus != null">plan_status = #{planStatus},</if> |
|||
<if test="trafficPoliceStatus != null">traffic_police_status = #{trafficPoliceStatus},</if> |
|||
<if test="medicalStatus != null">medical_status = #{medicalStatus},</if> |
|||
<if test="fireStatus != null">fire_status = #{fireStatus},</if> |
|||
<if test="boardStatus != null">board_status = #{boardStatus},</if> |
|||
<if test="chemicalsStatus != null">chemicals_status = #{chemicalsStatus},</if> |
|||
<if test="planLevel != null">plan_level = #{planLevel},</if> |
|||
<if test="chemicalsName != null">chemicals_name = #{chemicalsName},</if> |
|||
<if test="leakageLevel != null">leakage_level = #{leakageLevel},</if> |
|||
</trim> |
|||
where id = #{id} |
|||
</update> |
|||
|
|||
<delete id="deleteDcEventImportantByEventId" parameterType="String"> |
|||
delete from dc_event_important where id = #{id} |
|||
</delete> |
|||
|
|||
<delete id="deleteDcEventImportantByEventIds" parameterType="String"> |
|||
delete from dc_event_important where id in |
|||
<foreach item="id" collection="array" open="(" separator="," close=")"> |
|||
#{id} |
|||
</foreach> |
|||
</delete> |
|||
</mapper> |
File diff suppressed because it is too large
Binary file not shown.
Loading…
Reference in new issue