Commit 78b344865fc0471703637f1b2184b5c0179a3d99
1 parent
86c6675b1f
Exists in
master
and in
6 other branches
操作日志
Showing 3 changed files with 128 additions and 3 deletions
platform-dal/src/main/java/com/lyms/platform/pojo/OperateLogModel.java
View file @
78b3448
| ... | ... | @@ -47,6 +47,16 @@ |
| 47 | 47 | //操作备注 |
| 48 | 48 | private String operateRemark; |
| 49 | 49 | |
| 50 | + private String modifyContent; | |
| 51 | + | |
| 52 | + public String getModifyContent() { | |
| 53 | + return modifyContent; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public void setModifyContent(String modifyContent) { | |
| 57 | + this.modifyContent = modifyContent; | |
| 58 | + } | |
| 59 | + | |
| 50 | 60 | public String getId() { |
| 51 | 61 | return id; |
| 52 | 62 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BabyBookbuildingFacade.java
View file @
78b3448
| ... | ... | @@ -609,7 +609,7 @@ |
| 609 | 609 | patient.setPid(pm.getId()); |
| 610 | 610 | patient.setCreated(new Date()); |
| 611 | 611 | patients = yunBookbuildingService.addPregnantBookbuilding(patient); |
| 612 | - operateLogFacade.addOptLog(userId,Integer.valueOf(patients.getHospitalId()),patients,"",OptActionEnums.ADD.getId(),"儿童建档时候添加孕妇建档"); | |
| 612 | + operateLogFacade.addOptLog(userId,Integer.valueOf(patients.getHospitalId()),patients,null,OptActionEnums.ADD.getId(),"儿童建档时候添加孕妇建档"); | |
| 613 | 613 | } |
| 614 | 614 | } |
| 615 | 615 | |
| ... | ... | @@ -636,7 +636,7 @@ |
| 636 | 636 | patient.setCreated(new Date()); |
| 637 | 637 | patients = yunBookbuildingService.addPregnantBookbuilding(patient); |
| 638 | 638 | |
| 639 | - operateLogFacade.addOptLog(userId,Integer.valueOf(patients.getHospitalId()),patients,"",OptActionEnums.ADD.getId(),"儿童建档时候添加孕妇建档"); | |
| 639 | + operateLogFacade.addOptLog(userId,Integer.valueOf(patients.getHospitalId()),patients,null,OptActionEnums.ADD.getId(),"儿童建档时候添加孕妇建档"); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | |
| ... | ... | @@ -672,7 +672,7 @@ |
| 672 | 672 | // String hospitalName = organizationService.getOrganization(Integer.valueOf(request.getHospitalId())).getName(); |
| 673 | 673 | model = babyBookbuildingService.addBabyBookbuilding(model); |
| 674 | 674 | |
| 675 | - operateLogFacade.addOptLog(userId,Integer.valueOf(request.getHospitalId()),model,"",OptActionEnums.ADD.getId(),"儿童建档"); | |
| 675 | + operateLogFacade.addOptLog(userId,Integer.valueOf(request.getHospitalId()),model,null,OptActionEnums.ADD.getId(),"儿童建档"); | |
| 676 | 676 | |
| 677 | 677 | if (model == null || model.getId() == null) { |
| 678 | 678 | br.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/OperateLogFacade.java
View file @
78b3448
| ... | ... | @@ -7,12 +7,21 @@ |
| 7 | 7 | import com.lyms.platform.permission.model.UsersQuery; |
| 8 | 8 | import com.lyms.platform.permission.service.UsersService; |
| 9 | 9 | import com.lyms.platform.pojo.OperateLogModel; |
| 10 | +import org.apache.commons.beanutils.PropertyUtils; | |
| 10 | 11 | import org.apache.commons.collections.CollectionUtils; |
| 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | 13 | import org.springframework.stereotype.Component; |
| 14 | +import org.springframework.util.StringUtils; | |
| 13 | 15 | |
| 16 | +import java.beans.BeanInfo; | |
| 17 | +import java.beans.Introspector; | |
| 18 | +import java.beans.PropertyDescriptor; | |
| 19 | +import java.text.DateFormat; | |
| 20 | +import java.text.SimpleDateFormat; | |
| 21 | +import java.util.ArrayList; | |
| 14 | 22 | import java.util.Date; |
| 15 | 23 | import java.util.List; |
| 24 | +import java.util.Map; | |
| 16 | 25 | |
| 17 | 26 | |
| 18 | 27 | /** |
| ... | ... | @@ -52,6 +61,11 @@ |
| 52 | 61 | model.setOperateBeforeContent(JsonUtil.array2JsonString(operateBeforeContent)); |
| 53 | 62 | model.setOperateRemark(operateRemark); |
| 54 | 63 | |
| 64 | + if (operateBeforeContent != null && operateBeforeContent != null ) | |
| 65 | + { | |
| 66 | + model.setModifyContent(JsonUtil.array2JsonString(getChangeItems(operateAfterContent, operateBeforeContent))); | |
| 67 | + } | |
| 68 | + | |
| 55 | 69 | model.setOperateHospitalId(hospitalId); |
| 56 | 70 | |
| 57 | 71 | model.setCreated(new Date()); |
| ... | ... | @@ -59,5 +73,106 @@ |
| 59 | 73 | operateLogService.addOptLog(model); |
| 60 | 74 | } |
| 61 | 75 | |
| 76 | + | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * 获取更新操作的change item | |
| 80 | + * @param oldObj | |
| 81 | + * @param newObj | |
| 82 | + * @return | |
| 83 | + */ | |
| 84 | + public static List<ChangeItem> getChangeItems(Object oldObj, Object newObj) { | |
| 85 | + Class cl = oldObj.getClass(); | |
| 86 | + List<ChangeItem> changeItems = new ArrayList<ChangeItem>(); | |
| 87 | + try { | |
| 88 | + BeanInfo beanInfo = Introspector.getBeanInfo(cl, Object.class); | |
| 89 | + | |
| 90 | + for (PropertyDescriptor propertyDescriptor : beanInfo | |
| 91 | + .getPropertyDescriptors()) { | |
| 92 | + String field = propertyDescriptor.getName(); | |
| 93 | + //获取字段旧值 | |
| 94 | + String oldProp = getValue(PropertyUtils.getProperty(oldObj, | |
| 95 | + field)); | |
| 96 | + //获取字段新值 | |
| 97 | + String newProp = getValue(PropertyUtils.getProperty(newObj, | |
| 98 | + field)); | |
| 99 | + | |
| 100 | + //对比新旧值 | |
| 101 | + if (!oldProp.equals(newProp)) { | |
| 102 | + ChangeItem changeItem = new ChangeItem(); | |
| 103 | + changeItem.setField(field); | |
| 104 | + changeItem.setNewValue(newProp); | |
| 105 | + changeItem.setOldValue(oldProp); | |
| 106 | + changeItems.add(changeItem); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + } catch (Exception e) { | |
| 110 | + } | |
| 111 | + return changeItems; | |
| 112 | + } | |
| 113 | + | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * 不同类型转字符串的处理 | |
| 117 | + * @param obj | |
| 118 | + * @return | |
| 119 | + */ | |
| 120 | + public static String getValue(Object obj) { | |
| 121 | + if (obj != null) { | |
| 122 | + if (obj instanceof Date) { | |
| 123 | + return formatDateW3C((Date) obj); | |
| 124 | + } else { | |
| 125 | + return obj.toString(); | |
| 126 | + } | |
| 127 | + } else { | |
| 128 | + return ""; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * 将date类型转为字符串形式 | |
| 134 | + * @param date | |
| 135 | + * @return | |
| 136 | + */ | |
| 137 | + public static String formatDateW3C(Date date) { | |
| 138 | + DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); | |
| 139 | + String text = df.format(date); | |
| 140 | + String result = text.substring(0, 22) + ":" + text.substring(22); | |
| 141 | + return result; | |
| 142 | + } | |
| 143 | + | |
| 144 | +} | |
| 145 | + | |
| 146 | +class ChangeItem { | |
| 147 | + | |
| 148 | + private String field; | |
| 149 | + | |
| 150 | + private String oldValue; | |
| 151 | + | |
| 152 | + private String newValue; | |
| 153 | + | |
| 154 | + public String getOldValue() { | |
| 155 | + return oldValue; | |
| 156 | + } | |
| 157 | + | |
| 158 | + public void setOldValue(String oldValue) { | |
| 159 | + this.oldValue = oldValue; | |
| 160 | + } | |
| 161 | + | |
| 162 | + public String getNewValue() { | |
| 163 | + return newValue; | |
| 164 | + } | |
| 165 | + | |
| 166 | + public void setNewValue(String newValue) { | |
| 167 | + this.newValue = newValue; | |
| 168 | + } | |
| 169 | + | |
| 170 | + public String getField() { | |
| 171 | + return field; | |
| 172 | + } | |
| 173 | + | |
| 174 | + public void setField(String field) { | |
| 175 | + this.field = field; | |
| 176 | + } | |
| 62 | 177 | } |