Commit 5e903f55 by zhangtw

审批调整

parent bfec1bf4
...@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
...@@ -31,6 +32,22 @@ public class KeyDmBorrowServiceImpl { ...@@ -31,6 +32,22 @@ public class KeyDmBorrowServiceImpl {
private final String namespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmBorrow."; private final String namespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmBorrow.";
private final String detailNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmBorrowDetail."; private final String detailNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmBorrowDetail.";
private final String materialNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmMaterialLog."; private final String materialNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmMaterialLog.";
private final String userNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmUser.";
private Map<String, String> userMap;
// 把用户的id和名做成字典
@PostConstruct
public void initUserMap() {
List<Map<String,Object>> userList = commonService.findList(userNamespace + "getUserMap", null);
// 此时commonService已被注入,非null
userMap = new HashMap<>();
for (Map<String, Object> user : userList) {
String userId = String.valueOf(user.get("Id")); // 转为String,避免类型问题
String userName = (String) user.get("name");
if (userId != null && userName != null) { // 空值防御
userMap.put(userId, userName);
}
}
}
@ApiOperation(value = "领用申请列表", desc = "分页查询") @ApiOperation(value = "领用申请列表", desc = "分页查询")
public Page<Map<String, Object>> selectList(Map<String, Object> map) { public Page<Map<String, Object>> selectList(Map<String, Object> map) {
if (map == null) map = new HashMap<>(); if (map == null) map = new HashMap<>();
...@@ -82,14 +99,17 @@ public class KeyDmBorrowServiceImpl { ...@@ -82,14 +99,17 @@ public class KeyDmBorrowServiceImpl {
throw new CustomException("日期格式错误,支持格式:2025-12-26 或 2025-12-26T16:00:00.000Z"); throw new CustomException("日期格式错误,支持格式:2025-12-26 或 2025-12-26T16:00:00.000Z");
} }
} }
initUserMap();
map.put("approver_name",userMap.get(map.get("approver_id")));
map.put("expected_return_date", expected_return_date); map.put("expected_return_date", expected_return_date);
if (id == null || String.valueOf(id).trim().isEmpty()) { if (id == null || String.valueOf(id).trim().isEmpty()) {
map.put("application_no","borrow"); map.put("id", UUID.randomUUID().toString());
map.put("applicant_id",user.get("id")); map.put("applicant_id",user.get("id"));
map.put("applicant_name", user.get("name")); map.put("applicant_name", user.get("name"));
map.put("department_id", user.get("company_id")); map.put("department_id", user.get("company_id"));
map.put("department_name", user.get("company_name")); map.put("department_name", user.get("company_name"));
map.put("approval_status", 0); map.put("approval_status", 0);
map.put("issue_status", 0); map.put("issue_status", 0);
map.put("order_no", 0); map.put("order_no", 0);
...@@ -98,7 +118,6 @@ public class KeyDmBorrowServiceImpl { ...@@ -98,7 +118,6 @@ public class KeyDmBorrowServiceImpl {
// insert details if any // insert details if any
if (details != null) { if (details != null) {
for (Map<String, Object> d : details) { for (Map<String, Object> d : details) {
d.put("id",UUID.randomUUID().toString());
d.put("application_id", map.get("id")); d.put("application_id", map.get("id"));
commonService.insert( detailNamespace + "insertDetail", d); commonService.insert( detailNamespace + "insertDetail", d);
} }
......
...@@ -51,7 +51,7 @@ public class KeyDmInboundServiceImpl { ...@@ -51,7 +51,7 @@ public class KeyDmInboundServiceImpl {
private final String userNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmUser."; private final String userNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmUser.";
private Map<String, String> userMap; private Map<String, String> userMap;
// 把用户的id和名做成字典
@PostConstruct @PostConstruct
public void initUserMap() { public void initUserMap() {
List<Map<String,Object>> userList = commonService.findList(userNamespace + "getUserMap", null); List<Map<String,Object>> userList = commonService.findList(userNamespace + "getUserMap", null);
......
...@@ -65,34 +65,118 @@ ...@@ -65,34 +65,118 @@
<insert id="insert" parameterType="map"> <insert id="insert" parameterType="map">
INSERT INTO jl_key_dm_borrow_application( INSERT INTO jl_key_dm_borrow_application(
id,application_no,applicant_id,applicant_name,department_id,department_name,borrow_purpose,expected_return_date, id,application_no,applicant_id,applicant_name,department_id,department_name,borrow_purpose,expected_return_date,approver_id,approver_name,
approval_status,issue_status,is_used,create_by,create_time,order_no approval_status,issue_status,is_used,create_by,create_time,order_no
) VALUES ( ) VALUES (
#{id},CONCAT('borrow', REPLACE(UUID(),'-','')),#{applicant_id},#{applicant_name},#{department_id},#{department_name},#{borrow_purpose},#{expected_return_date}, #{id},CONCAT('borrow', REPLACE(UUID(),'-','')),#{applicant_id},#{applicant_name},#{department_id},#{department_name},#{borrow_purpose},#{expected_return_date},#{approver_id},#{approver_name}
#{approval_status},#{issue_status},1,#{_user.id},NOW(),#{order_no} #{approval_status},#{issue_status},1,#{_user.id},NOW(),#{order_no}
) )
</insert> </insert>
<update id="update" parameterType="map"> <update id="update" parameterType="map">
UPDATE jl_key_dm_borrow_application UPDATE jl_key_dm_borrow_application
SET borrow_purpose = #{borrow_purpose}, expected_return_date = #{expected_return_date}, update_by = #{_user.id}, update_time = NOW() <set>
<!-- 借用用途:非空时更新 -->
<if test="borrow_purpose != null">
borrow_purpose = #{borrow_purpose},
</if>
<!-- 审批人ID:非空时更新 -->
<if test="approver_id != null">
approver_id = #{approver_id},
</if>
<!-- 审批人名称:非空时更新 -->
<if test="approver_name != null">
approver_name = #{approver_name},
</if>
<!-- 预计归还日期:非空时更新(日期类型只需判断null) -->
<if test="expected_return_date != null">
expected_return_date = #{expected_return_date},
</if>
<!-- 更新人:强制更新(无需判断,确保操作痕迹) -->
update_by = #{_user.id},
<!-- 更新时间:强制更新(数据库自动生成) -->
update_time = NOW()
</set>
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<update id="submit" parameterType="map"> <update id="submit" parameterType="map">
UPDATE jl_key_dm_borrow_application SET approver_id = #{approver_id}, approver_name = #{approver_name}, approval_status = 1, submit_time = NOW(), update_by = #{_user.id}, update_time = NOW() WHERE id = #{id} UPDATE jl_key_dm_borrow_application
<set>
<!-- 审批人ID:非空才更新 -->
<if test="approver_id != null and approver_id != ''">
approver_id = #{approver_id},
</if>
<!-- 审批人名称:非空才更新 -->
<if test="approver_name != null and approver_name != ''">
approver_name = #{approver_name},
</if>
<!-- 审批状态:提交时强制设为1,无需判断 -->
approval_status = 1,
<!-- 提交时间:强制更新为当前时间 -->
submit_time = NOW(),
<!-- 更新人:强制记录 -->
update_by = #{_user.id},
<!-- 更新时间:强制更新 -->
update_time = NOW()
</set>
WHERE id = #{id}
</update> </update>
<update id="revoke" parameterType="map"> <update id="revoke" parameterType="map">
UPDATE jl_key_dm_borrow_application SET approval_status = 0, update_by = #{_user.id}, update_time = NOW() WHERE id = #{id} AND approval_status = 1 UPDATE jl_key_dm_borrow_application
<set>
<!-- 审批状态:撤销时强制设为0 -->
approval_status = 0,
<!-- 更新人:强制记录 -->
update_by = #{_user.id},
<!-- 更新时间:强制更新 -->
update_time = NOW()
</set>
WHERE id = #{id}
AND approval_status = 1 <!-- 仅能撤销“待审批”状态的申请 -->
</update> </update>
<update id="approve" parameterType="map"> <update id="approve" parameterType="map">
UPDATE jl_key_dm_borrow_application SET approval_status = 9, approval_time = NOW(), issue_time = NOW(), issue_status = 1, update_by = #{_user.id}, update_time = NOW() WHERE id = #{id} UPDATE jl_key_dm_borrow_application
<set>
<!-- 审批意见:非空才更新 -->
<if test="comment != null and comment != ''">
approval_opinion = #{comment},
</if>
<!-- 审批状态:通过时强制设为9 -->
approval_status = 9,
<!-- 审批时间:强制更新为当前时间 -->
approval_time = NOW(),
<!-- 发放时间:强制更新为当前时间 -->
issue_time = NOW(),
<!-- 发放状态:通过时强制设为1 -->
issue_status = 1,
<!-- 更新人:强制记录 -->
update_by = #{_user.id},
<!-- 更新时间:强制更新 -->
update_time = NOW()
</set>
WHERE id = #{id}
</update> </update>
<update id="reject" parameterType="map"> <update id="reject" parameterType="map">
UPDATE jl_key_dm_borrow_application SET approval_status = -1, approval_time = NOW(), approval_opinion = #{comment}, update_by = #{_user.id}, update_time = NOW() WHERE id = #{id} UPDATE jl_key_dm_borrow_application
<set>
<!-- 审批状态:驳回时强制设为-1 -->
approval_status = -1,
<!-- 审批时间:强制更新为当前时间 -->
approval_time = NOW(),
<!-- 审批意见(approval_opinion):复用comment,非空才更新 -->
<if test="comment != null and comment != ''">
approval_opinion = #{comment},
</if>
<!-- 更新人:强制记录 -->
update_by = #{_user.id},
<!-- 更新时间:强制更新 -->
update_time = NOW()
</set>
WHERE id = #{id}
</update> </update>
<!-- 删除所有明细 --> <!-- 删除所有明细 -->
......
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
</insert> </insert>
<select id="selectDetailsByApplicationId" parameterType="map" resultType="map"> <select id="selectDetailsByApplicationId" parameterType="map" resultType="map">
SELECT bd.*,m.category_id SELECT bd.*,m.category_id,(COALESCE(i.total_quantity,0) - COALESCE(i.borrowed_quantity) - COALESCE(i.damaged_quantity)) as available_quantity
FROM jl_key_dm_borrow_application_detail as bd FROM jl_key_dm_borrow_application_detail as bd
left join jl_key_dm_material as m left join jl_key_dm_material as m
on m.id = bd.material_id on m.id = bd.material_id
left join jl_key_dm_inventory as i
on bd.material_id = i.material_id
WHERE bd.application_id = #{id} AND bd.is_used = 1 ORDER BY bd.create_time ASC WHERE bd.application_id = #{id} AND bd.is_used = 1 ORDER BY bd.create_time ASC
</select> </select>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论