软件工程项目实训(2021-3-21~2021-4)

继续完成相关数据库与程序底层交接的程序设计工作。

一、本阶段工作进展

1.确定流程
  • 事务状态state
    1
    2
    3
    4
    public static final Integer STATE_READY = 10;                  //准备好可以审批
    public static final Integer STATE_APPROVING = 11; //审批中
    public static final Integer STATE_APPROVE_FAILED = 12; //审批失败
    public static final Integer STATE_END = 13; //审批结束
  • 事务类型kind
    1
    2
    public static final Integer KIND_REIMBURSEMENT_AUDIT = 20;    //报销审计
    public static final Integer KIND_FOLLOW_UP_AUDIT = 21; //跟踪审计
  • 提示信息
    1
    2
    OK("00200","成功"),
    USER_INPUT_ERROR("00400", "用户输入错误");
2. 整理对象属性
1
2
3
4
5
6
7
public class User {
private Long id; //用户id
private String username; //用户名
private String password; //用户密码
private String name; //用户姓名
private Integer post; //用户职务
}
1
2
3
4
5
6
7
8
public class MaterialLog {
private Long id; //材料id
private String name; //材料名称
private String remark; //备注
private Long affairId; //所属的事务
private Date createTime; //创建时间
private Long authorId; //上传用户id
}
1
2
3
4
5
6
7
8
9
10
public class ApprovalLog {
private Long id; //审计操作的log的id
private Long affairId; //所属的事务
private Date createTime; //审批时间
private Boolean isPass; //是否通过
private Boolean isEditSource; //是否修改附件
private Long authorId; //审批人id
private String ip; //审批人ip
private String msg; //审批结论
}
1
2
3
4
5
6
7
8
9
10
11
public class Affair {
private Long id; //事务id
private String name; //事务名
private String remark; //备注
private Integer kind; //事务类型
private Integer state; //审批状态
private Date startTime; //创建时间
private Date endTime; //结束时间
private Long promoterId; //事务发起人id
private Integer approverPost; //当前审批人职务
}
3. 构建修正MySQL数据库相关表单
  • user表
    user表
  • MaterialLog 表
    在这里插入图片描述
    外键
    在这里插入图片描述

  • ApprovalLog 表
    在这里插入图片描述
    外键
    在这里插入图片描述

  • Affair 表
    在这里插入图片描述
    外键
    在这里插入图片描述

    二、实现相关连接

    后端底层 DAO 层通过 mapper 与 MySQL 数据库进行连接。通过 MyBatis 简介明了地实现连接的相关函数。

以下为原始实现,后来修改了,已失效

AffairChangeMapper 实现返回值为 AffairChange 对象,插入新的AffairChange

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?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.shenji.audit.dao.AffairChangeMapper" >
<resultMap id="BaseResultMap" type="com.shenji.audit.model.AffairChange" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="kind" property="kind" jdbcType="INTEGER" />
<result column="date" property="date" jdbcType="DATE" />
<result column="author_id" property="authorId" jdbcType="BIGINT" />
<result column="affair_id" property="affairId" jdbcType="BIGINT" />
<result column="message" property="message" jdbcType="VARCHAR" />
</resultMap>

<insert id="insertOne">
insert into affair_change values (
#{id},
#{kind},
#{date},
#{authorId},
#{affairId},
#{message}
)
</insert>

</mapper>

AffairMapper 实现返回值为 Affair 对象,从数据库按照id查找Affair,插入新的Affair,更新Affair
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?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.shenji.audit.dao.AffairMapper" >
<resultMap id="BaseResultMap" type="com.shenji.audit.model.Affair" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="remark" property="remark" jdbcType="VARCHAR" />
<result column="kind" property="kind" jdbcType="INTEGER" />
<result column="state" property="state" jdbcType="INTEGER" />
<result column="start_time" property="startTime" jdbcType="DATE" />
<result column="end_time" property="endTime" jdbcType="DATE" />
<result column="approver_id" property="approverId" jdbcType="BIGINT" />
<result column="promoter_id" property="promoterId" jdbcType="BIGINT" />
</resultMap>

<select id="getAffairById" resultMap="BaseResultMap">
SELECT *
FROM affair
WHERE id=#{affairId}
</select>

<insert id="insertOne">
insert into affair values (
#{id},
#{name},
#{remark},
#{kind},
#{state},
#{startTime},
#{endTime},
#{approverId},
#{promoterId}
)
</insert>

<update id="updateState" parameterType="com.shenji.audit.model.Affair">
update affair
<set>
<if test="state != null">
state = #{state},
</if>
</set>
where id = #{affairId}
</update>

</mapper>

MaterialMapper 实现返回值为 Material 对象,插入新的Material
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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.shenji.audit.dao.MaterialMapper" >
<resultMap id="BaseResultMap" type="com.shenji.audit.model.Material" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="affair_id" property="affairId" jdbcType="BIGINT" />
<result column="affair_change_id" property="affairChangeId" jdbcType="BIGINT" />
<result column="create_time" property="createTime" jdbcType="DATE" />
<result column="author_id" property="authorId" jdbcType="BIGINT" />
<result column="content_url" property="contentUrl" jdbcType="VARCHAR" />
</resultMap>

<insert id="insertOne">
insert into material values (
#{id},
#{name},
#{affairId},
#{affairChangeId},
#{createTime},
#{authorId},
#{contentUrl}
)
</insert>

</mapper>

ReportMapper 实现返回值为 Report 对象,根据id查找Report,插入新的Report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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.shenji.audit.dao.ReportMapper" >
<resultMap id="BaseResultMap" type="com.shenji.audit.model.Report" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="content_url" property="contentUrl" jdbcType="VARCHAR" />
<result column="affair_id" property="affairId" jdbcType="BIGINT" />
<result column="state" property="state" jdbcType="INTEGER" />
</resultMap>

<select id="selectOne" resultMap="BaseResultMap">
SELECT *
FROM report
WHERE id=#{reportId}
</select>

<insert id="insertOne">
insert into report values (
#{id},
#{name},
#{contentUrl},
#{affairId},
#{state}
)
</insert>

</mapper>

UserMapper 实现返回值为 User 对象,查询所有User
1
2
3
4
5
6
7
8
9
10
11
12
13
<?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.shenji.audit.dao.UserMapper" >
<resultMap id="BaseResultMap" type="com.shenji.audit.model.User" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="username" property="username" jdbcType="VARCHAR" />
<result column="password" property="password" jdbcType="VARCHAR" />
<result column="name" property="name" jdbcType="VARCHAR" />
</resultMap>
<select id="selectAll" resultMap="BaseResultMap">
SELECT * FROM user;
</select>
</mapper>

三、进行相关接口测试

陈神完成相关服务器后端接口,韬测试相关接口

1
http://baixx.site:18080/swagger-ui/#/

接口版本1.0,现已失效

事务接口
获取全部事务 1

在这里插入图片描述

创建跟踪审计 1

在这里插入图片描述
在这里插入图片描述

获取我发起的事务 1

暂时没有id输入,输出了与1相关的项目
在这里插入图片描述

获取待我审批的事务

暂时没有id输入,输出了需要1审批的项目
在这里插入图片描述

创建报销审计 1

暂时没有approveid和promoterid输入,promoterid固定为2???
关于审批的职位12345,需要谁审批?
在这里插入图片描述

创建成功
在这里插入图片描述

审批接口

审批事务

出错Internal Server Error,status500
TestApprove-test02-nopass
在这里插入图片描述

TestApprove-test02-pass
在这里插入图片描述

获取pdf文件

测试
在这里插入图片描述

想要生成这个
在这里插入图片描述

但是乱码了,我下载(成功)看了看损坏了(文件损坏打不开),猜测是中文编码格式乱码了
在这里插入图片描述

上传报告

传空报错
在这里插入图片描述在这里插入图片描述

获取源文件列表 1

获取成功
在这里插入图片描述

测试空的新项目成功
在这里插入图片描述

获取源文件

测试获取审计处新一代物联化信息管理系统建设方案.docx还是乱码了
下载(成功)看了,只有名字乱码了,内容没事,猜测是中文编码格式乱码了
在这里插入图片描述
在这里插入图片描述

测试不存在的文件,不存在的id
在这里插入图片描述

资料接口

获取资料列表

获取空成功
获取相关资料成功
在这里插入图片描述

上传资料

暂时必须手动填id,后期自动生成
在这里插入图片描述

不需要传入上传人id
在这里插入图片描述

填错误id,出错
在这里插入图片描述在这里插入图片描述

删除资料文件

未测试

获取资料文件

成功获取相关资料,下载查看没问题
在这里插入图片描述

尝试获取不存在的文件
在这里插入图片描述
404 not found
在这里插入图片描述

获取资料文件列表 1

成功获取相关资料
在这里插入图片描述
成功获取不存在的id的空

三、下一阶段工作目标

发现用户安全问题,需要token工具类,进行token代码开发和拦截器过滤器开发