|
|
@@ -3,27 +3,42 @@
|
|
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
<mapper namespace="com.ruoyi.base.mapper.AgriculturalTasksMapper">
|
|
|
-
|
|
|
+
|
|
|
<resultMap type="AgriculturalTasks" id="AgriculturalTasksResult">
|
|
|
- <result property="id" column="id" />
|
|
|
- <result property="plotId" column="plot_id" />
|
|
|
- <result property="farmId" column="farm_id" />
|
|
|
- <result property="fieldName" column="field_name" />
|
|
|
- <result property="growCrops" column="grow_crops" />
|
|
|
- <result property="taskName" column="task_name" />
|
|
|
- <result property="taskImages" column="task_images" />
|
|
|
- <result property="typeName" column="type_name" />
|
|
|
- <result property="taskStatus" column="task_status" />
|
|
|
- <result property="executeTime" column="execute_time" />
|
|
|
- <result property="assigneeId" column="assignee_id" />
|
|
|
- <result property="assigneeName" column="assignee_name" />
|
|
|
- <result property="remark" column="remark" />
|
|
|
- <result property="completionTime" column="completion_time" />
|
|
|
- <result property="completionDesc" column="completion_desc" />
|
|
|
- <result property="createBy" column="create_by" />
|
|
|
- <result property="createTime" column="create_time" />
|
|
|
- <result property="updateTime" column="update_time" />
|
|
|
- <result property="updateBy" column="update_by" />
|
|
|
+ <result property="id" column="id"/>
|
|
|
+ <result property="plotId" column="plot_id"/>
|
|
|
+ <result property="farmId" column="farm_id"/>
|
|
|
+ <result property="taskName" column="task_name"/>
|
|
|
+ <result property="taskImages" column="task_images"/>
|
|
|
+ <result property="typeName" column="type_name"/>
|
|
|
+ <result property="taskStatus" column="task_status"/>
|
|
|
+ <result property="executeTime" column="execute_time"/>
|
|
|
+ <result property="assigneeId" column="assignee_id"/>
|
|
|
+ <result property="assigneeName" column="assignee_name"/>
|
|
|
+ <result property="remark" column="remark"/>
|
|
|
+ <result property="practicalBegintime" column="practical_begintime"/>
|
|
|
+ <result property="completionTime" column="completion_time"/>
|
|
|
+ <result property="completionDesc" column="completion_desc"/>
|
|
|
+ <result property="createBy" column="create_by"/>
|
|
|
+ <result property="createTime" column="create_time"/>
|
|
|
+ <result property="updateTime" column="update_time"/>
|
|
|
+ <result property="updateBy" column="update_by"/>
|
|
|
+ <result property="deptName" column="dept_name"/>
|
|
|
+ <result property="fieldName" column="field_name"/>
|
|
|
+ <result property="growCrops" column="grow_crops"/>
|
|
|
+ <result property="imageCount" column="image_count"/>
|
|
|
+ <result property="plannedCompletetime" column="planned_completetime"/>
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <resultMap type="AgriculturalTasksStatistics" id="AgriculturalTasksStatisticsResult">
|
|
|
+ <result property="taskCount" column="task_count"/>
|
|
|
+ <result property="completedCount" column="completed_count"/>
|
|
|
+ <result property="pendingCount" column="pending_count"/>
|
|
|
+ <result property="overdueCount" column="overdue_count"/>
|
|
|
+ <result property="completionRate" column="completion_rate"/>
|
|
|
+ <result property="onTimeRate" column="on_time_rate"/>
|
|
|
+ <result property="avgCompletionDuration" column="avg_completion_duration"/>
|
|
|
+
|
|
|
</resultMap>
|
|
|
|
|
|
<sql id="selectAgriculturalTasksVo">
|
|
|
@@ -31,28 +46,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
</sql>
|
|
|
|
|
|
<select id="selectAgriculturalTasksList" parameterType="AgriculturalTasks" resultMap="AgriculturalTasksResult">
|
|
|
- <include refid="selectAgriculturalTasksVo"/>
|
|
|
- <where>
|
|
|
- <if test="plotId != null "> and plot_id = #{plotId}</if>
|
|
|
- <if test="farmId != null "> and farm_id = #{farmId}</if>
|
|
|
- <if test="fieldName != null and fieldName != ''"> and field_name like concat('%', #{fieldName}, '%')</if>
|
|
|
- <if test="growCrops != null and growCrops != ''"> and grow_crops = #{growCrops}</if>
|
|
|
- <if test="taskName != null and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
|
|
|
- <if test="taskImages != null and taskImages != ''"> and task_images = #{taskImages}</if>
|
|
|
- <if test="typeName != null and typeName != ''"> and type_name like concat('%', #{typeName}, '%')</if>
|
|
|
- <if test="taskStatus != null and taskStatus != ''"> and task_status = #{taskStatus}</if>
|
|
|
- <if test="executeTime != null "> and execute_time = #{executeTime}</if>
|
|
|
- <if test="assigneeId != null "> and assignee_id = #{assigneeId}</if>
|
|
|
- <if test="completionTime != null "> and completion_time = #{completionTime}</if>
|
|
|
- <if test="completionDesc != null and completionDesc != ''"> and completion_desc = #{completionDesc}</if>
|
|
|
- <if test="createBy != null "> and create_by = #{createBy}</if>
|
|
|
+ select at1.*,sd.dept_name,su.nick_name,
|
|
|
+ CASE
|
|
|
+ WHEN task_images = '' THEN 0
|
|
|
+ ELSE LENGTH(task_images) - LENGTH(REPLACE(task_images, ',', '')) + 1
|
|
|
+ END AS image_count
|
|
|
+ from agricultural_tasks at1
|
|
|
+ left join sys_dept sd on at1.farm_id = sd.dept_id
|
|
|
+ left join sys_user su on at1.assignee_id = su.user_id
|
|
|
+
|
|
|
+
|
|
|
+ <where>
|
|
|
+ <if test="plotId != null ">and at1.plot_id = #{plotId}</if>
|
|
|
+ <if test="taskName != null and taskName != ''">and at1.task_name like concat('%', #{taskName}, '%')</if>
|
|
|
+ <if test="assigneeName != null and assigneeName != ''">and at1.assignee_name like concat('%',
|
|
|
+ #{assigneeName}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="taskImages != null and taskImages != ''">and at1.task_images = #{taskImages}</if>
|
|
|
+ <if test="typeName != null and typeName != ''">and at1.type_name = #{typeName}</if>
|
|
|
+ <if test="taskStatus != null and taskStatus != ''">and at1.task_status = #{taskStatus}</if>
|
|
|
+ <if test="executeTime != null ">and at1.execute_time = #{executeTime}</if>
|
|
|
+ <if test="assigneeId != null ">and at1.assignee_id = #{assigneeId}</if>
|
|
|
+ <if test="completionTime != null ">and at1.completion_time = #{completionTime}</if>
|
|
|
+ <if test="completionDesc != null and completionDesc != ''">and at1.completion_desc = #{completionDesc}</if>
|
|
|
+ <if test="createBy != null ">and at1.create_by = #{createBy}</if>
|
|
|
+ <if test="deptIdList != null and deptIdList.size() != 0">and at1.farm_id in (<foreach
|
|
|
+ collection="deptIdList" item="deptId" separator=",">#{deptId}</foreach>)
|
|
|
+ </if>
|
|
|
+ <if test="fieldIdList != null and fieldIdList.size() != 0">and at1.plot_id in (<foreach
|
|
|
+ collection="fieldIdList" item="deptId" separator=",">#{deptId}</foreach>)
|
|
|
+ </if>
|
|
|
+ <if test="params.beginExecuteTime != null and params.beginExecuteTime != '' and params.endExecuteTime != null and params.endExecuteTime != ''">
|
|
|
+ and at1.execute_time between #{params.beginExecuteTime} and #{params.endExecuteTime}
|
|
|
+ </if>
|
|
|
+ <if test="params.beginCompletionTime != null and params.beginCompletionTime != '' and params.endCompletionTime != null and params.endCompletionTime != ''">
|
|
|
+ and at1.completion_time between #{params.beginCompletionTime} and #{params.endCompletionTime}
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <if test="params.beginPlannedCompleteTime != null and params.beginPlannedCompleteTime != '' and params.endPlannedCompleteTime != null and params.endPlannedCompleteTime != ''">
|
|
|
+ and at1.planned_completetime between #{params.beginPlannedCompleteTime} and #{params.endPlannedCompleteTime}
|
|
|
+ </if>
|
|
|
+
|
|
|
</where>
|
|
|
ORDER BY create_time DESC
|
|
|
</select>
|
|
|
-
|
|
|
+
|
|
|
<select id="selectAgriculturalTasksById" parameterType="Long" resultMap="AgriculturalTasksResult">
|
|
|
- <include refid="selectAgriculturalTasksVo"/>
|
|
|
- where id = #{id}
|
|
|
+ select at1.*,sd.dept_name
|
|
|
+ from agricultural_tasks at1
|
|
|
+ left join sys_dept sd on at1.farm_id = sd.dept_id
|
|
|
+ where at1.id = #{id}
|
|
|
</select>
|
|
|
<select id="countStatusTypeTasks" resultType="java.lang.Integer" parameterType="AgriculturalTasks">
|
|
|
select count(*) from agricultural_tasks
|
|
|
@@ -62,6 +105,97 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
<if test="assigneeId != null "> and assignee_id = #{assigneeId}</if>
|
|
|
</where>
|
|
|
</select>
|
|
|
+ <select id="selectAgriculturalTaskStatistics" resultMap="AgriculturalTasksStatisticsResult">
|
|
|
+
|
|
|
+ SELECT
|
|
|
+
|
|
|
+ COUNT(*) AS task_count,
|
|
|
+
|
|
|
+ SUM(CASE WHEN task_status = 1 THEN 1 ELSE 0 END) AS completed_count,
|
|
|
+
|
|
|
+ SUM(CASE WHEN task_status = 0 THEN 1 ELSE 0 END) AS pending_count,
|
|
|
+
|
|
|
+ SUM(
|
|
|
+ CASE
|
|
|
+ WHEN (task_status = 1 AND completion_time > planned_completetime)
|
|
|
+ OR (task_status = 0 AND planned_completetime < NOW())
|
|
|
+ THEN 1
|
|
|
+ ELSE 0
|
|
|
+ END
|
|
|
+ ) AS overdue_count,
|
|
|
+
|
|
|
+ IFNULL(
|
|
|
+ SUM(CASE WHEN task_status = 1 THEN 1 ELSE 0 END) /
|
|
|
+ NULLIF(COUNT(*), 0),
|
|
|
+ 0
|
|
|
+ ) AS completion_rate,
|
|
|
+
|
|
|
+ IFNULL(
|
|
|
+ SUM(CASE WHEN task_status = 1 AND completion_time <= planned_completetime THEN 1 ELSE 0 END) /
|
|
|
+ NULLIF(SUM(CASE WHEN task_status = 1 AND planned_completetime IS NOT NULL THEN 1 ELSE 0 END), 0),
|
|
|
+ 0
|
|
|
+ ) AS on_time_rate,
|
|
|
+
|
|
|
+ ROUND(
|
|
|
+ AVG(
|
|
|
+ CASE
|
|
|
+ WHEN practical_begintime IS NOT NULL THEN TIMESTAMPDIFF(DAY, practical_begintime, completion_time)
|
|
|
+ WHEN planned_completetime IS NOT NULL THEN TIMESTAMPDIFF(DAY, execute_time, completion_time)
|
|
|
+ ELSE NULL
|
|
|
+ END
|
|
|
+ ),
|
|
|
+ 1
|
|
|
+ ) AS avg_completion_duration
|
|
|
+ FROM agricultural_tasks
|
|
|
+ <where>
|
|
|
+ <if test="deptIdList != null and deptIdList.size() != 0">and farm_id in (<foreach
|
|
|
+ collection="deptIdList" item="deptId" separator=",">#{deptId}</foreach>)
|
|
|
+ </if>
|
|
|
+ <if test="fieldIdList != null and fieldIdList.size() != 0">and plot_id in (<foreach
|
|
|
+ collection="fieldIdList" item="deptId" separator=",">#{deptId}</foreach>)
|
|
|
+ </if>
|
|
|
+ <if test="growCrops != null and growCrops != ''">grow_crops= #{growCrops}</if>
|
|
|
+ <if test="typeName != null and typeName != ''">and type_name = #{typeName}</if>
|
|
|
+ <if test="assigneeName != null and assigneeName != ''">and assignee_name like concat('%',
|
|
|
+ #{assigneeName}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''">
|
|
|
+ and create_time between #{params.beginCreateTime} and #{params.endCreateTime}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+
|
|
|
+ </select>
|
|
|
+ <select id="selectAgriculturalTasksOverdueList" resultMap="AgriculturalTasksResult">
|
|
|
+ SELECT *
|
|
|
+ FROM agricultural_tasks
|
|
|
+ WHERE
|
|
|
+
|
|
|
+ (task_status = 0 AND planned_completetime < NOW()) -- 逾期未完成
|
|
|
+ AND planned_completetime IS NOT NULL;
|
|
|
+
|
|
|
+ </select>
|
|
|
+ <select id="selectAgriculturalTasksByCreateTime" parameterType="AgriculturalTasks" resultType="java.util.Map">
|
|
|
+ WITH RECURSIVE date_series AS (
|
|
|
+ SELECT #{params.beginCreateTime} AS date
|
|
|
+ UNION ALL
|
|
|
+ SELECT DATE_ADD(date, INTERVAL 1 DAY)
|
|
|
+ FROM date_series
|
|
|
+ WHERE date < #{params.endCreateTime}
|
|
|
+ )
|
|
|
+ SELECT
|
|
|
+ ds.date,
|
|
|
+ COALESCE(task_counts.value, 0) AS value
|
|
|
+ FROM date_series ds
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ DATE_FORMAT(create_time, '%Y-%m-%d') AS date,
|
|
|
+ COUNT(*) AS value
|
|
|
+ FROM agricultural_tasks
|
|
|
+ WHERE create_time BETWEEN #{params.beginCreateTime} AND #{params.endCreateTime}
|
|
|
+ GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')
|
|
|
+ ) task_counts ON ds.date = task_counts.date
|
|
|
+ ORDER BY ds.date
|
|
|
+ </select>
|
|
|
|
|
|
<insert id="insertAgriculturalTasks" parameterType="AgriculturalTasks" useGeneratedKeys="true" keyProperty="id">
|
|
|
insert into agricultural_tasks
|
|
|
@@ -75,10 +209,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
<if test="typeName != null and typeName != ''">type_name,</if>
|
|
|
<if test="taskStatus != null">task_status,</if>
|
|
|
<if test="executeTime != null">execute_time,</if>
|
|
|
+ <if test="plannedCompletetime != null">planned_completetime,</if>
|
|
|
<if test="assigneeId != null">assignee_id,</if>
|
|
|
<if test="assigneeName != null">assignee_name,</if>
|
|
|
<if test="remark != null">remark,</if>
|
|
|
<if test="completionTime != null">completion_time,</if>
|
|
|
+ <if test="practicalBegintime != null">practical_begintime,</if>
|
|
|
<if test="completionDesc != null">completion_desc,</if>
|
|
|
<if test="createBy != null">create_by,</if>
|
|
|
<if test="createTime != null">create_time,</if>
|
|
|
@@ -95,10 +231,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
<if test="typeName != null and typeName != ''">#{typeName},</if>
|
|
|
<if test="taskStatus != null">#{taskStatus},</if>
|
|
|
<if test="executeTime != null">#{executeTime},</if>
|
|
|
+ <if test="plannedCompletetime != null">#{plannedCompletetime},</if>
|
|
|
<if test="assigneeId != null">#{assigneeId},</if>
|
|
|
<if test="assigneeName != null">#{assigneeName},</if>
|
|
|
<if test="remark != null">#{remark},</if>
|
|
|
<if test="completionTime != null">#{completionTime},</if>
|
|
|
+ <if test="practicalBegintime != null">#{practicalBegintime},</if>
|
|
|
<if test="completionDesc != null">#{completionDesc},</if>
|
|
|
<if test="createBy != null">#{createBy},</if>
|
|
|
<if test="createTime != null">#{createTime},</if>
|
|
|
@@ -137,9 +275,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
</delete>
|
|
|
|
|
|
<delete id="deleteAgriculturalTasksByIds" parameterType="String">
|
|
|
- delete from agricultural_tasks where id in
|
|
|
+ delete from agricultural_tasks where id in
|
|
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
|
|
#{id}
|
|
|
</foreach>
|
|
|
</delete>
|
|
|
-</mapper>
|
|
|
+</mapper>
|