瑞利声电固定资产管理系统
ycq
2026-10-16 dbbadb021c2fc171466cc82bd9a7a82cc47165f5
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package zbooksoft.fams.dao;
 
import com.ruili.wcp.common.IdGenerater;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
 
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
/**
 * 标签模板、标签打印记录与标签所需资产数据的数据访问
 * @author ycq
 * @date 2026-10-16
 */
@Repository
public class LabelDao {
 
    /** 标签上可展示的资产字段 */
    private static final String CARD_LABEL_COLUMNS = "ID, ASSET_NO, ASSET_NAME, SPEC_MODEL, CATEGORY_NAME, DEVICE_TYPE, BRAND, FACTORY_NO, UNIT, "
            + "ORIGINAL_VALUE, PURCHASE_DATE, SUPPLIER, ASSET_STATE, USE_DEPT_NAME, USER_NAME, LOCATION_NAME, START_USE_DATE, "
            + "WARRANTY_EXPIRE_DATE, NEXT_MAINTAIN_DATE, VERIFY_EXPIRE_DATE, INSPECT_ORG, CERT_NO, SAFETY_USER_NAME, RISK_LEVEL, "
            + "PRINT_STATE, LAST_PRINT_TIME, REMARK";
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    /**
     * 按主键查标签模板
     * @param id 模板ID
     * @return 模板行,不存在返回null
     */
    public Map<String, Object> findTemplate(Long id) {
        List<Map<String, Object>> rows = jdbcTemplate.queryForList(
                "select ID, TEMPLATE_NAME, LABEL_WIDTH, LABEL_HEIGHT, LAYOUT_JSON, IS_DEFAULT, ENABLE_STATE from BUS_LABEL_TEMPLATE where ID = ?", id);
        return rows.isEmpty() ? null : rows.get(0);
    }
 
    /**
     * 查启用的标签模板,默认模板排前
     * @return 模板列表
     */
    public List<Map<String, Object>> findEnabledTemplates() {
        return jdbcTemplate.queryForList("select ID, TEMPLATE_NAME, LABEL_WIDTH, LABEL_HEIGHT, LAYOUT_JSON, IS_DEFAULT from BUS_LABEL_TEMPLATE "
                + "where ifnull(ENABLE_STATE, '启用') = '启用' order by case when IS_DEFAULT = '是' then 0 else 1 end, SORT_NO, CREATE_TIME");
    }
 
    /**
     * 取消除指定模板外所有模板的默认标记
     * @param id 保留默认的模板ID
     */
    public void clearDefaultExcept(Long id) {
        jdbcTemplate.update("update BUS_LABEL_TEMPLATE set IS_DEFAULT = '否' where ID <> ? and IS_DEFAULT = '是'", id);
    }
 
    /**
     * 保存模板布局
     * @param id 模板ID
     * @param layoutJson 布局JSON
     */
    public void updateTemplateLayout(Long id, String layoutJson) {
        jdbcTemplate.update("update BUS_LABEL_TEMPLATE set LAYOUT_JSON = ?, MODIFY_TIME = now() where ID = ?", layoutJson, id);
    }
 
    /**
     * 按ID批量查标签所需的资产数据,按资产编号排序
     * @param ids 资产ID列表
     * @return 资产行
     */
    public List<Map<String, Object>> findCardsForLabel(List<Long> ids) {
        if (ids.isEmpty()) {
            return Collections.emptyList();
        }
        String placeholders = String.join(",", Collections.nCopies(ids.size(), "?"));
        return jdbcTemplate.queryForList("select " + CARD_LABEL_COLUMNS + " from BUS_ASSET_CARD where ID in (" + placeholders + ") order by ASSET_NO",
                ids.toArray());
    }
 
    /**
     * 写一条标签打印记录
     * @param row 打印记录字段(大写列名)
     */
    public void insertPrintLog(Map<String, Object> row) {
        jdbcTemplate.update("insert into BUS_LABEL_PRINT_LOG (ID, ASSET_ID, ASSET_NO, ASSET_NAME, TEMPLATE_ID, TEMPLATE_NAME, "
                        + "PRINT_USER_ID, PRINT_USER_NAME, PRINT_TIME, CREATE_USER_ID, CREATE_USER_NAME, CREATE_TIME, MODIFY_TIME) "
                        + "values (?, ?, ?, ?, ?, ?, ?, ?, now(), ?, ?, now(), now())",
                IdGenerater.getId(), row.get("ASSET_ID"), row.get("ASSET_NO"), row.get("ASSET_NAME"), row.get("TEMPLATE_ID"),
                row.get("TEMPLATE_NAME"), row.get("PRINT_USER_ID"), row.get("PRINT_USER_NAME"), row.get("PRINT_USER_ID"), row.get("PRINT_USER_NAME"));
    }
 
    /**
     * 标记资产标签已打印
     * @param ids 资产ID列表
     */
    public void markPrinted(List<Long> ids) {
        if (ids.isEmpty()) {
            return;
        }
        String placeholders = String.join(",", Collections.nCopies(ids.size(), "?"));
        jdbcTemplate.update("update BUS_ASSET_CARD set PRINT_STATE = 1, LAST_PRINT_TIME = now() where ID in (" + placeholders + ")", ids.toArray());
    }
}