Browse Source

操作日志

yurk 2 năm trước cách đây
mục cha
commit
63a82ba210

+ 19 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/config/PropertyMsg.java

@@ -0,0 +1,19 @@
+package com.management.platform.config;
+
+import java.lang.annotation.*;
+
+/**
+ *  属性信息注解,仅仅可以用于域声明
+ */
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+public @interface PropertyMsg {
+    /**
+     * 提示语,用于标记哪个字段发生变更
+     *
+     * @return 提示语
+     */
+    String value();
+}

+ 3 - 3
src/main/java/com/management/platform/controller/ExpenseTypeController.java

@@ -11,11 +11,11 @@ import org.springframework.web.bind.annotation.RestController;
  * </p>
  *
  * @author Seyason
- * @since 2022-07-28
+ * @since 2022-08-18
  */
 @RestController
-@RequestMapping("/expense-type")
-public class ExpenseTypeController {
+@RequestMapping("/operation-record")
+public class OperationRecordController {
 
 }
 

+ 53 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/OperationRecord.java

@@ -0,0 +1,53 @@
+package com.management.platform.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-08-18
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class OperationRecord extends Model<OperationRecord> {
+
+    private static final long serialVersionUID=1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @TableField("company_id")
+    private Integer companyId;
+
+    @TableField("module_name")
+    private String moduleName;
+
+    @TableField("operator_name")
+    private String operatorName;
+
+    @TableField("operation_time")
+    private LocalDateTime operationTime;
+
+    @TableField("content")
+    private String content;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 6 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/Project.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.management.platform.config.PropertyMsg;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -39,6 +40,7 @@ public class Project extends Model<Project> {
     /**
      * 项目名称
      */
+    @PropertyMsg("项目名称")
     @TableField("project_name")
     private String projectName;
 
@@ -51,6 +53,7 @@ public class Project extends Model<Project> {
     /**
      * 项目编码
      */
+    @PropertyMsg("项目编号")
     @TableField("project_code")
     private String projectCode;
 
@@ -63,6 +66,7 @@ public class Project extends Model<Project> {
     /**
      * 计划开始日期
      */
+    @PropertyMsg("计划开始日期")
     @TableField("plan_start_date")
     @JsonFormat(pattern = "yyyy-MM-dd")
     @DateTimeFormat(pattern = "yyyy-MM-dd")
@@ -71,6 +75,7 @@ public class Project extends Model<Project> {
     /**
      * 计划结束日期
      */
+    @PropertyMsg("计划结束日期")
     @TableField("plan_end_date")
     @JsonFormat(pattern = "yyyy-MM-dd")
     @DateTimeFormat(pattern = "yyyy-MM-dd")
@@ -86,6 +91,7 @@ public class Project extends Model<Project> {
     /**
      * 0-全部,1-正常,2-紧急,3-重要,4-重要且紧急 5-低风险 6-中风险 7-高风险
      */
+    @PropertyMsg("项目级别")
     @TableField("level")
     private Integer level;
 

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/OperationRecordMapper.java

@@ -0,0 +1,16 @@
+package com.management.platform.mapper;
+
+import com.management.platform.entity.OperationRecord;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-08-18
+ */
+public interface OperationRecordMapper extends BaseMapper<OperationRecord> {
+
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/OperationRecordService.java

@@ -0,0 +1,16 @@
+package com.management.platform.service;
+
+import com.management.platform.entity.OperationRecord;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-08-18
+ */
+public interface OperationRecordService extends IService<OperationRecord> {
+
+}

+ 20 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/OperationRecordServiceImpl.java

@@ -0,0 +1,20 @@
+package com.management.platform.service.impl;
+
+import com.management.platform.entity.OperationRecord;
+import com.management.platform.mapper.OperationRecordMapper;
+import com.management.platform.service.OperationRecordService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-08-18
+ */
+@Service
+public class OperationRecordServiceImpl extends ServiceImpl<OperationRecordMapper, OperationRecord> implements OperationRecordService {
+
+}

+ 22 - 8
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -10,10 +10,7 @@ import com.management.platform.entity.*;
 import com.management.platform.entity.vo.*;
 import com.management.platform.mapper.*;
 import com.management.platform.service.*;
-import com.management.platform.util.ExcelUtil;
-import com.management.platform.util.HttpRespMsg;
-import com.management.platform.util.ListUtil;
-import com.management.platform.util.WorkDayCalculateUtils;
+import com.management.platform.util.*;
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFRow;
@@ -153,6 +150,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
     UserCustomMapper userCustomMapper;
     @Resource
     SubUserCustomMapper subUserCustomMapper;
+    @Resource
+    OperationRecordService operationRecordService;
 
 
     @Resource
@@ -522,6 +521,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                 }
             }
         } else {
+            Project oldProject = projectMapper.selectById(id);
             isNew = false;
             //修改项目
             //检查项目编号不能重复
@@ -671,6 +671,20 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                     financeProjectsMapper.update(fp, new QueryWrapper<FinanceProjects>().eq("project_id", p.getId()));
                 }
             }
+            Project newProject = projectMapper.selectById(id);
+            String path = Project.class.getClassLoader().getResource("/").getPath();
+            BeanChangeUtil<Project> beanChangeUtil=new BeanChangeUtil();
+            String content = beanChangeUtil.contrastObj(oldProject, newProject);
+            OperationRecord operationRecord =new OperationRecord();
+            operationRecord.setOperatorName(user.getName());
+            operationRecord.setOperationTime(LocalDateTime.now());
+            operationRecord.setCompanyId(companyId);
+            operationRecord.setContent(content);
+            operationRecord.setModuleName("项目管理");
+            if(!StringUtils.isEmpty(content.trim())){
+                System.out.println(operationRecord);
+                operationRecordService.save(operationRecord);
+            }
         }
         if (httpRespMsg.code.equals("ok")) {
             //编辑关系
@@ -2940,8 +2954,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                         endDateCell = row.getCell(8+i+k+c);
                         amountCell = row.getCell(9+i+k+c);
                         if(company.getId()==936){
-                            warrantyEndDateCell=row.getCell(10+i+k+c);
-                            warrantyStartDateCell=row.getCell(11+i+k+c);
+                            warrantyStartDateCell=row.getCell(10+i+k+c);
+                            warrantyEndDateCell=row.getCell(11+i+k+c);
                             projectCategorySubCell=row.getCell(12+i+k+c);
                             regionCell=row.getCell(13+i+k+c);
                             buCell=row.getCell(14+i+k+c);
@@ -2976,8 +2990,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                         endDateCell = row.getCell(9+i+k+c);
                         amountCell = row.getCell(10+i+k+c);
                         if(company.getId()==936){
-                            warrantyEndDateCell=row.getCell(11+i+k+c);
-                            warrantyStartDateCell=row.getCell(12+i+k+c);
+                            warrantyStartDateCell=row.getCell(11+i+k+c);
+                            warrantyEndDateCell=row.getCell(12+i+k+c);
                             projectCategorySubCell=row.getCell(13+i+k+c);
                             regionCell=row.getCell(14+i+k+c);
                             buCell=row.getCell(15+i+k+c);

+ 107 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/BeanChangeUtil.java

@@ -0,0 +1,107 @@
+package com.management.platform.util;
+
+import com.management.platform.config.PropertyMsg;
+import com.management.platform.service.OperationRecordService;
+
+import javax.annotation.Resource;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Objects;
+
+public class BeanChangeUtil<T> {
+
+    @Resource
+    private OperationRecordService operationRecordService;
+
+    public String contrastObj(Object oldBean, Object newBean) {
+        /*// 创建字符串拼接对象
+        StringBuilder str = new StringBuilder();
+        // 转换为传入的泛型T
+        T pojo1 = (T) oldBean;
+        T pojo2 = (T) newBean;
+        // 通过反射获取类的Class对象
+        Class clazz = pojo1.getClass();
+        // 获取类型及字段属性
+        Field[] fields = clazz.getDeclaredFields();
+        return jdk8Before(fields, pojo1, pojo2, str,clazz);*/
+//        return jdk8OrAfter(fields, pojo1, pojo2, str,clazz);
+        Field[] fields = newBean.getClass().getDeclaredFields();
+        StringBuilder builder = new StringBuilder();
+        for(Field field : fields) {
+            field.setAccessible(true);
+            if (field.isAnnotationPresent(PropertyMsg.class)) {
+                try {
+                    Object newValue = field.get(newBean);
+                    Object oldValue = field.get(oldBean);
+                    if(!Objects.equals(newValue, oldValue)) {
+                        builder.append(field.getAnnotation(PropertyMsg.class).value()); //获取字段名称
+                        builder.append(":[更改前:");
+                        builder.append(oldValue);
+                        builder.append(",更改后:");
+                        builder.append(newValue);
+                        builder.append("]\n");
+                    }
+                } catch (Exception e) {
+                    System.out.println(e);
+                }
+            }
+        }
+        return builder.toString();
+    }
+
+    // jdk8 普通循环方式
+    public String jdk8Before(Field[] fields,T pojo1,T pojo2,StringBuilder str,Class clazz){
+        int i = 1;
+        try {
+            for (Field field : fields) {
+                if(field.isAnnotationPresent(PropertyMsg.class)){
+                    field.setAccessible(true);//关闭字段的安全检测
+                    PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz);
+                    // 获取对应属性值
+                    Method getMethod = pd.getReadMethod();
+                    Object o1 = getMethod.invoke(pojo1);
+                    Object o2 = getMethod.invoke(pojo2);
+                    if (o1 == null || o2 == null) {
+                        continue;
+                    }
+                    if (!o1.toString().equals(o2.toString())) {
+                        str.append(i + "、" + field.getAnnotation(PropertyMsg.class).value() + ":" + "修改前=>" + o1 + ",修改后=>" + o2 + "\n");
+                        i++;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return str.toString();
+    }
+
+    // lambda表达式,表达式内部的变量都是final修饰,需要传入需要传入final类型的数组
+    public String jdk8OrAfter(Field[] fields, T pojo1, T pojo2, StringBuilder str, Class clazz){
+        final int[] i = {1};
+        Arrays.asList(fields).forEach(f -> {
+            if(f.isAnnotationPresent(PropertyMsg.class)){
+                try {
+                    PropertyDescriptor pd = new PropertyDescriptor(f.getName(), clazz);
+                    // 获取对应属性值
+                    Method getMethod = pd.getReadMethod();
+                    Object o1 = getMethod.invoke(pojo1);
+                    Object o2 = getMethod.invoke(pojo2);
+                    if (o1 == null || o2 == null) {
+                        return;
+                    }
+                    if (!o1.toString().equals(o2.toString())) {
+                        str.append(i[0] + "、" + f.getAnnotation(PropertyMsg.class).value() + ":" + "修改前=>" + o1 + "\t修改后=>" + o2 + "\n");
+                        i[0]++;
+                    }
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        });
+        return str.toString();
+    }
+}

+ 20 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/OperationRecordMapper.xml

@@ -0,0 +1,20 @@
+<?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.management.platform.mapper.OperationRecordMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.management.platform.entity.OperationRecord">
+        <id column="id" property="id" />
+        <result column="company_id" property="companyId" />
+        <result column="module_name" property="moduleName" />
+        <result column="operator_name" property="operatorName" />
+        <result column="operation_time" property="operationTime" />
+        <result column="content" property="content" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, company_id, module_name, operator_name, operation_time, content
+    </sql>
+
+</mapper>