瑞利声电固定资产管理系统
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package zbooksoft.fams.controller;
 
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruili.wcp.data.entity.management.User;
import com.ruili.wcp.web.model.AjaxResponse;
import com.ruili.wcp.web.model.ErrorInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import zbooksoft.fams.common.BusinessException;
import zbooksoft.fams.service.LabelService;
 
/**
 * 标签管理页面与接口:模板设计、批量打印、打印记录
 * @author ycq
 * @date 2026-10-16
 */
@Controller
@RequestMapping("/fams/label")
public class LabelController {
 
    private static final String JSON_UTF8 = "application/json; charset=utf-8";
 
    private final ObjectMapper objectMapper = new ObjectMapper();
 
    @Autowired
    private LabelService labelService;
 
    /**
     * 标签模板设计器页面
     * @param templateId 模板ID
     * @return 设计器视图
     */
    @RequestMapping(value = "/design", method = RequestMethod.GET)
    @RequiresUser
    public ModelAndView design(@RequestParam Long templateId) throws JsonProcessingException {
        ModelAndView mv = new ModelAndView("fams/label/design");
        mv.addObject("templateId", String.valueOf(templateId));
        mv.addObject("fieldsJson", objectMapper.writeValueAsString(LabelService.LABEL_FIELDS));
        return mv;
    }
 
    /**
     * 批量打印页面,选中的资产ID由列表页通过params.ids传入
     * @return 打印视图
     */
    @RequestMapping(value = "/print", method = RequestMethod.GET)
    @RequiresUser
    public ModelAndView print() throws JsonProcessingException {
        ModelAndView mv = new ModelAndView("fams/label/print");
        mv.addObject("fieldsJson", objectMapper.writeValueAsString(LabelService.LABEL_FIELDS));
        return mv;
    }
 
    /**
     * 查单个模板
     * @param templateId 模板ID
     * @return 模板数据
     */
    @RequestMapping(value = "/template", method = RequestMethod.GET, produces = JSON_UTF8)
    @ResponseBody
    @RequiresUser
    public Object template(@RequestParam Long templateId) {
        try {
            return new AjaxResponse(labelService.getTemplate(templateId));
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 查启用的标签模板
     * @return 模板列表
     */
    @RequestMapping(value = "/templates", method = RequestMethod.GET, produces = JSON_UTF8)
    @ResponseBody
    @RequiresUser
    public Object templates() {
        return new AjaxResponse(labelService.listEnabledTemplates());
    }
 
    /**
     * 保存模板布局
     * @param templateId 模板ID
     * @param layoutJson 布局JSON
     * @return 保存结果
     */
    @RequestMapping(value = "/saveLayout", method = RequestMethod.POST, produces = JSON_UTF8)
    @ResponseBody
    @RequiresUser
    public Object saveLayout(@RequestParam Long templateId, @RequestParam String layoutJson) {
        try {
            labelService.saveLayout(templateId, layoutJson);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 查要打印标签的资产数据
     * @param ids 逗号分隔的资产ID
     * @return 资产数据
     */
    @RequestMapping(value = "/printData", method = RequestMethod.POST, produces = JSON_UTF8)
    @ResponseBody
    @RequiresUser
    public Object printData(@RequestParam String ids) {
        try {
            return new AjaxResponse(labelService.loadPrintAssets(ids));
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 记录标签已打印
     * @param ids 逗号分隔的资产ID
     * @param templateId 使用的模板ID
     * @return 记录条数
     */
    @RequestMapping(value = "/printed", method = RequestMethod.POST, produces = JSON_UTF8)
    @ResponseBody
    @RequiresUser
    public Object printed(@RequestParam String ids, @RequestParam Long templateId) {
        try {
            User user = (User) SecurityUtils.getSubject().getSession().getAttribute("user");
            return new AjaxResponse(labelService.recordPrint(ids, templateId, user == null ? null : user.getUserId(),
                    user == null ? "" : user.getTrueName()));
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    private static AjaxResponse fail(BusinessException e) {
        return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
    }
}