实现对比报表整份删除与最小操作日志
按独立删除权限在同一事务清理全部版本并同步保留删除日志,复用报表锁且不影响来源测试。平台日志清理保留报表删除记录,新增 V13 删除权限。
| | |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import javax.sql.DataSource; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.jdbc.support.GeneratedKeyHolder; |
| | |
| | | throw new ServiceException("对比报表不存在"); |
| | | } |
| | | |
| | | /** 仅在业务事务和报表锁内调用;物理清理全部版本,同步保留最小操作日志。 */ |
| | | public void delete(long id, long operatorId, String operatorName) |
| | | { |
| | | String name = jdbc.queryForObject("select report_name from t_compare_report where report_id=?", String.class, id); |
| | | jdbc.update("delete from t_compare_report_version where report_id=?", id); |
| | | jdbc.update("delete from t_compare_report where report_id=?", id); |
| | | // 不走异步 @Log,日志失败必须回滚删除;只保留身份,不读取或记录测量快照。 |
| | | jdbc.update("insert into sys_oper_log(title,business_type,method,request_method,operator_type,oper_name,oper_url,oper_param,status,oper_time) values(?,3,?,'DELETE',1,?,?,?,0,?)", |
| | | "对比报表删除", "compare-report.delete", operatorName, "/system/compare-report/" + id, |
| | | JSON.toJSONString(Map.of("reportId", id, "reportName", name, "operatorId", operatorId)), new Timestamp(System.currentTimeMillis())); |
| | | } |
| | | |
| | | /** 只追加版本并更新列表名称;业务事务保证两步同时成功。 */ |
| | | public void append(long id, int versionNo, String name, String snapshot, long operatorId, String operatorName, String summary) |
| | | { |
| | |
| | | return JSON.parseObject(current.snapshotJson()); |
| | | } |
| | | |
| | | /** 授权用户删除整份报表及全部版本,不影响来源测试;删除与最小日志同成同败。 */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delete(long id, long operatorId, String operatorName) |
| | | { |
| | | // 与版本追加共用身份锁,避免删除期间再写入孤立版本;重复删除不另记日志。 |
| | | reports.lock(id); |
| | | reports.delete(id, operatorId, operatorName); |
| | | } |
| | | |
| | | private void validateSettings(CompareReportRequest.Settings settings) |
| | | { |
| | | Set<String> metrics = Set.of("voltage", "current", "temperature", "positiveVoltage", "negativeVoltage"); |
| | |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | @GetMapping("/{id}") |
| | | public AjaxResult get(@PathVariable long id) { return success(service.get(id)); } |
| | | |
| | | /** 删除权限独立于创建人;业务事务同步记录删除,不使用异步操作日志切面。 */ |
| | | @PreAuthorize("@ss.hasPermi('system:compare-report:remove')") |
| | | @DeleteMapping("/{id}") |
| | | public AjaxResult delete(@PathVariable long id) |
| | | { |
| | | service.delete(id, getUserId(), getUsername()); |
| | | return success(); |
| | | } |
| | | |
| | | /** 授权查看全部历史版本摘要,不限制创建人。 */ |
| | | @PreAuthorize("@ss.hasPermi('system:compare-report:query')") |
| | | @GetMapping("/{id}/versions") |
| New file |
| | |
| | | -- 删除整份报表及全部版本按独立动作授权,不限制创建人。 |
| | | INSERT INTO sys_menu(menu_name,parent_id,order_num,path,menu_type,visible,status,perms,create_by,create_time) |
| | | SELECT '删除',parent_id,4,'#','F','0','0','system:compare-report:remove','system',UTC_TIMESTAMP(3) |
| | | FROM sys_menu WHERE perms='system:compare-report:query'; |
| | |
| | | <foreach collection="array" item="operId" open="(" separator="," close=")"> |
| | | #{operId} |
| | | </foreach> |
| | | <!-- 报表删除只保留这一份最小追溯记录,平台日志清理也不能移除。 --> |
| | | and (method is null or method <> 'compare-report.delete') |
| | | </delete> |
| | | |
| | | <select id="selectOperLogById" parameterType="Long" resultMap="SysOperLogResult"> |
| | |
| | | </select> |
| | | |
| | | <update id="cleanOperLog"> |
| | | truncate table sys_oper_log |
| | | delete from sys_oper_log where method is null or method <> 'compare-report.delete' |
| | | </update> |
| | | |
| | | </mapper> |
| | | </mapper> |