diff --git a/adc-da-slrs/src/main/java/com/adc/da/slrs/sarLawsInformation/entity/SarLawsInformation.java b/adc-da-slrs/src/main/java/com/adc/da/slrs/sarLawsInformation/entity/SarLawsInformation.java index f18b8cec..edd27b26 100644 --- a/adc-da-slrs/src/main/java/com/adc/da/slrs/sarLawsInformation/entity/SarLawsInformation.java +++ b/adc-da-slrs/src/main/java/com/adc/da/slrs/sarLawsInformation/entity/SarLawsInformation.java @@ -122,17 +122,23 @@ public class SarLawsInformation extends BasePage implements Serializable { private String informationFileName; /** - * 可查看者,若设置为空则仅有上传人和审批人可以查看,若设置人员后,仅有可查看者可查看文件信息。 + * 可查看者,若设置为空则所有用户均可查看,若设置人员后,仅有可查看者可以查看文件信息。 */ @TableField(value = "VIEWABLE_BY") private String viewableBy; /** - * 可下载者,若设置为空则所有用户均可下载,若设置人员后,仅有可下载者可以下载文件信息。 + * 可下载者,若设置为空则仅有上传人和审批人可以查看,若设置人员后,仅有可下载者可下载文件信息。 */ @TableField(value = "DOWNLOADABLE_BY") private String downloadableBy; + /** + * 创建人和审批人 + */ + @TableField + private String createAndApproveBy; + /** * 树节点ID */ @@ -179,6 +185,12 @@ public class SarLawsInformation extends BasePage implements Serializable { @TableField(exist = false) private String sortMode = "asc"; + /** + * 收藏ID + */ + @TableField(exist = false) + private String collectId; + @TableField(exist = false) private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/adc-da-slrs/src/main/java/com/adc/da/slrs/sarLawsInformation/service/impl/SarLawsInformationServiceImpl.java b/adc-da-slrs/src/main/java/com/adc/da/slrs/sarLawsInformation/service/impl/SarLawsInformationServiceImpl.java index 8eb3d9d3..92207144 100644 --- a/adc-da-slrs/src/main/java/com/adc/da/slrs/sarLawsInformation/service/impl/SarLawsInformationServiceImpl.java +++ b/adc-da-slrs/src/main/java/com/adc/da/slrs/sarLawsInformation/service/impl/SarLawsInformationServiceImpl.java @@ -2,9 +2,15 @@ package com.adc.da.slrs.sarLawsInformation.service.impl; import com.adc.da.att.entity.AttFileEO; import com.adc.da.att.service.IAttFileEOService; +import com.adc.da.person.entity.TsPersonCollect; +import com.adc.da.person.service.IPersonCollectEOService; import com.adc.da.slrs.sarLawsInformationCenterTree.entity.SarLawsInformationCenterTree; import com.adc.da.slrs.sarLawsInformationCenterTree.service.SarLawsInformationCenterTreeService; +import com.adc.da.slrs.sarUpdLog.entity.SarUpdLog; +import com.adc.da.slrs.sarUpdLog.service.ISarUpdLogService; import com.adc.da.slrs.tsDictionaryType.service.ITsDicTypeService; +import com.adc.da.util.LoginUserUtil; +import com.adc.da.util.UUIDUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -15,9 +21,10 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; /** * @author tjzdw @@ -34,23 +41,16 @@ public class SarLawsInformationServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(TsPersonCollect::getCollectResId, sarLawsInformation.getId()); + wrapper.eq(TsPersonCollect::getValidFlag, 0); + List list = collectEOService.list(); + if (list.size() > 0) { + sarLawsInformation.setCollectId(list.get(0).getId()); + } return sarLawsInformation; } @@ -81,7 +89,12 @@ public class SarLawsInformationServiceImpl extends ServiceImpl sarLawsInformationList = this.baseMapper.queryByPage(page); + for (SarLawsInformation sarLawsInformation : sarLawsInformationList) { + convertCodeToName(sarLawsInformation); + } + return sarLawsInformationList; } @Override @@ -114,10 +127,120 @@ public class SarLawsInformationServiceImpl extends ServiceImpl compareResult = compareSarLawsInformation(oldLawsInformation, lawsInformation); + if (compareResult.size() > 0) { + int update = this.baseMapper.updateById(lawsInformation); + // 添加修改记录 + SarUpdLog sarUpdLogEO = new SarUpdLog(); + sarUpdLogEO.setId(UUIDUtils.randomUUID20()); + sarUpdLogEO.setSarId(oldLawsInformation.getId()); + sarUpdLogEO.setSarType("LAWS_INFORMATION"); + sarUpdLogEO.setCreationTime(new Date()); + sarUpdLogEO.setCreationUser(LoginUserUtil.getUserId()); + sarUpdLogEO.setContent(oldLawsInformation.getName() + "," + String.join(",",compareResult)); + updLogService.save(sarUpdLogEO); + } return true; } + + public void convertCodeToName(SarLawsInformation sarLawsInformation) { + List firstTypeList = new ArrayList<>(); + for (String type : sarLawsInformation.getFirstType().split(",")) { + if (StringUtils.isNotBlank(type)) { + firstTypeList.add(dicTypeService.getDicTypeNameByDicCode(type)); + } + } + sarLawsInformation.setFirstTypeName(String.join(",",firstTypeList)); + List secondTypeList = new ArrayList<>(); + for (String type : sarLawsInformation.getSecondType().split(",")) { + if (StringUtils.isNotBlank(type)) { + secondTypeList.add(dicTypeService.getDicTypeNameByDicCode(type)); + } + } + sarLawsInformation.setSecondTypeName(String.join(",",secondTypeList)); + List thirdTypeList = new ArrayList<>(); + for (String type : sarLawsInformation.getThirdType().split(",")) { + if (StringUtils.isNotBlank(type)) { + thirdTypeList.add(dicTypeService.getDicTypeNameByDicCode(type)); + } + } + sarLawsInformation.setThirdTypeName(String.join(",",thirdTypeList)); + List fourthTypeList = new ArrayList<>(); + for (String type : sarLawsInformation.getFourthType().split(",")) { + if (StringUtils.isNotBlank(type)) { + fourthTypeList.add(dicTypeService.getDicTypeNameByDicCode(type)); + } + } + sarLawsInformation.setFirstTypeName(String.join(",",fourthTypeList)); + } + + /** + * 比较两个SarLawsInformation 对象 + * @param oldInfo 数据库中存储的对象 + * @param newInfo 更新后的对象 + * @return 差异 + */ + public List compareSarLawsInformation(SarLawsInformation oldInfo, SarLawsInformation newInfo) { + List changes = new ArrayList<>(); + // 不需要比较的字段 + String[] ignoreFields = {"id","firstTypeName","secondTypeName","thirdTypeName","fourthTypeName","uploadTime", + "informationFileName","createAndApproveBy","treeNodeId","treeNodeName","validFlag","createTime", + "modifyTime","sortField","sortMode","collectId","serialVersionUID"}; + List ignoreFieldList = Arrays.asList(ignoreFields); + // 获取SarLawsInformation类的所有字段 + Field[] fields = SarLawsInformation.class.getDeclaredFields(); + for (Field field : fields) { + if (!ignoreFieldList.contains(field.getName())) { + try { + field.setAccessible(true); + String oldValue = String.valueOf(field.get(oldInfo)); + String newValue = String.valueOf(field.get(newInfo)); + if (!Objects.equals(oldValue, newValue)) { + if ("firstType".equals(field.getName()) || "secondType".equals(field.getName()) || "thirdType".equals(field.getName()) || + "fourthType".equals(field.getName())) { + List typeNameList = new ArrayList<>(); + if (StringUtils.isNotBlank(newValue)) { + for (String type : newValue.split(",")) { + if (StringUtils.isNotBlank(type)) { + typeNameList.add(dicTypeService.getDicTypeNameByDicCode(type)); + } + } + } + // 获取资料类型名称 + String fieldName = field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); + Method method = SarLawsInformation.class.getMethod("get" + fieldName + "Name"); + Object oldTypeName = method.invoke(oldInfo); + changes.add("\"" + field.getName() + "\"由\"" + oldTypeName + "\"\"改为\"\"" + String.join(",",typeNameList) + "\""); + } else if ("informationFile".equals(field.getName())) { + List fileNameList = new ArrayList<>(); + if (StringUtils.isNotBlank(newValue)) { + String[] split = newValue.split(","); + for (String attId : split) { + AttFileEO fileInfo = attFileEOService.getFileInfo(attId); + fileNameList.add(fileInfo.getOldFileName()); + } + } + // 获取资料类型名称 + String fieldName = field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); + Method method = SarLawsInformation.class.getMethod("get" + fieldName + "Name"); + Object oldTypeName = method.invoke(oldInfo); + changes.add(field.getName() + "由\"" + oldTypeName + "\"\"改为\"\"" + String.join(",",fileNameList) + "\""); + } + else { + changes.add("\"" + field.getName() + "\"由\"" + oldValue + "\"\"改为\"\"" + newValue + "\""); + } + } + } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { + // 处理异常 + e.printStackTrace(); + } + } + } + return changes; + } } diff --git a/adc-da-slrs/src/main/resources/mybatis/mapper/sarLawsInformation/SarLawsInformationMapper.xml b/adc-da-slrs/src/main/resources/mybatis/mapper/sarLawsInformation/SarLawsInformationMapper.xml index 6cc59f52..e73d9012 100644 --- a/adc-da-slrs/src/main/resources/mybatis/mapper/sarLawsInformation/SarLawsInformationMapper.xml +++ b/adc-da-slrs/src/main/resources/mybatis/mapper/sarLawsInformation/SarLawsInformationMapper.xml @@ -31,13 +31,9 @@ ID, FIRST_TYPE, - (select DIC_TYPE_NAME from ts_dictype where DIC_ID = (SELECT ID FROM `ts_dictionary` where DICTIONARY_CODE = "firstMaterialType") and DIC_TYPE_CODE = FIRST_TYPE) firstTypeName, SECOND_TYPE, - (select DIC_TYPE_NAME from ts_dictype where DIC_ID = (SELECT ID FROM `ts_dictionary` where DICTIONARY_CODE = "secondMaterialType") and DIC_TYPE_CODE = SECOND_TYPE) secondTypeName, THIRD_TYPE, - (select DIC_TYPE_NAME from ts_dictype where DIC_ID = (SELECT ID FROM `ts_dictionary` where DICTIONARY_CODE = "thirdMaterialType") and DIC_TYPE_CODE = THIRD_TYPE) thirdTypeName, FOURTH_TYPE, - (select DIC_TYPE_NAME from ts_dictype where DIC_ID = (SELECT ID FROM `ts_dictionary` where DICTIONARY_CODE = "fourthMaterialType") and DIC_TYPE_CODE = FOURTH_TYPE) fourthTypeName, `NAME`, DEPARTMENT,AUTHOR,UPLOAD_TIME, `DESCRIPTION`,INFORMATION_FILE,VIEWABLE_BY, @@ -46,10 +42,10 @@ - and FIRST_TYPE = #{firstType} + and FIRST_TYPE like concat('%',#{firstType},'%') - and SECOND_TYPE = #{secondType} + and SECOND_TYPE like concat('%',#{secondType},'%') and `NAME` like concat('%',#{name},'%')