Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.ibeetl.admin.console.web;
 
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
 
import javax.servlet.http.HttpServletResponse;
 
import com.ibeetl.admin.console.service.XzxOrderClockInInfoService;
import com.ibeetl.admin.console.web.query.XzxOrderClockInInfoQuery;
import com.ibeetl.admin.core.entity.XzxOrderClockInInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.beetl.sql.core.engine.PageQuery;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.ibeetl.admin.core.annotation.Function;
import com.ibeetl.admin.core.file.FileItem;
import com.ibeetl.admin.core.file.FileService;
import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.admin.core.util.*;
 
/**
 * XzxOrderClockInInfo 接口
 */
@Controller
public class XzxOrderClockInInfoController{
 
    private final Log log = LogFactory.getLog(this.getClass());
    private static final String MODEL = "/admin/xzxOrderClockInInfo";
 
 
    @Autowired private XzxOrderClockInInfoService xzxOrderClockInInfoService;
    
    @Autowired
    FileService fileService;
    /* 页面 */
 
    @GetMapping(MODEL + "/index.do")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public ModelAndView index() {
        ModelAndView view = new ModelAndView("/admin/xzxOrderClockInInfo/index.html") ;
        view.addObject("search", XzxOrderClockInInfoQuery.class.getName());
        return view;
    }
 
    @GetMapping(MODEL + "/edit.do")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public ModelAndView edit(Long id) {
        ModelAndView view = new ModelAndView("/admin/xzxOrderClockInInfo/edit.html");
        XzxOrderClockInInfo xzxOrderClockInInfo = xzxOrderClockInInfoService.queryById(id);
        view.addObject("xzxOrderClockInInfo", xzxOrderClockInInfo);
        return view;
    }
 
    @GetMapping(MODEL + "/add.do")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public ModelAndView add() {
        ModelAndView view = new ModelAndView("/admin/xzxOrderClockInInfo/add.html");
        return view;
    }
 
    /* ajax json */
 
    @PostMapping(MODEL + "/list.json")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public JsonResult<PageQuery> list(XzxOrderClockInInfoQuery condtion)
    {
        PageQuery page = condtion.getPageQuery();
        xzxOrderClockInInfoService.queryByCondition(page);
        return JsonResult.success(page);
    }
 
    @PostMapping(MODEL + "/add.json")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public JsonResult add(@Validated(ValidateConfig.ADD.class)XzxOrderClockInInfo xzxOrderClockInInfo)
    {
        xzxOrderClockInInfoService.save(xzxOrderClockInInfo);
        return new JsonResult().success();
    }
 
    @PostMapping(MODEL + "/edit.json")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public JsonResult<String> update(@Validated(ValidateConfig.UPDATE.class)  XzxOrderClockInInfo xzxOrderClockInInfo) {
        boolean success = xzxOrderClockInInfoService.update(xzxOrderClockInInfo);
        if (success) {
            return new JsonResult().success();
        } else {
            return JsonResult.failMessage("保存失败");
        }
    }
 
 
   
    @GetMapping(MODEL + "/view.json")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public JsonResult<XzxOrderClockInInfo>queryInfo(Long id) {
        XzxOrderClockInInfo xzxOrderClockInInfo = xzxOrderClockInInfoService.queryById( id);
        return  JsonResult.success(xzxOrderClockInInfo);
    }
 
    @PostMapping(MODEL + "/delete.json")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public JsonResult delete(String ids) {
        if (ids.endsWith(",")) {
            ids = StringUtils.substringBeforeLast(ids, ",");
        }
        List<Long> idList = ConvertUtil.str2longs(ids);
        xzxOrderClockInInfoService.batchDelXzxOrderClockInInfo(idList);
        return new JsonResult().success();
    }
    
    
    @PostMapping(MODEL + "/excel/export.json")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public JsonResult<String> export(HttpServletResponse response,XzxOrderClockInInfoQuery condtion) {
        /**
         * 1)需要用你自己编写一个的excel模板
         * 2)通常excel导出需要关联更多数据,因此xzxOrderClockInInfoService.queryByCondition方法经常不符合需求,需要重写一个为模板导出的查询
         * 3)参考ConsoleDictController来实现模板导入导出
         */
        String excelTemplate ="excelTemplates/admin/xzxOrderClockInInfo/你的excel模板文件名字.xls";
        PageQuery<XzxOrderClockInInfo> page = condtion.getPageQuery();
        //取出全部符合条件的
        page.setPageSize(Integer.MAX_VALUE);
        page.setPageNumber(1);
        page.setTotalRow(Integer.MAX_VALUE);
        //本次导出需要的数据
        List<XzxOrderClockInInfo> list =xzxOrderClockInInfoService.queryByCondition(page).getList();
        try(InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(excelTemplate)) {
            if(is==null) {
                throw new PlatformException("模板资源不存在:"+excelTemplate);
            }
            FileItem item = fileService.createFileTemp("XzxOrderClockInInfo_"+DateUtil.now("yyyyMMddHHmmss")+".xls");
            OutputStream os = item.openOutpuStream();
            Context context = new Context();
            context.putVar("list", list);
            JxlsHelper.getInstance().processTemplate(is, os, context);
            os.close();
            //下载参考FileSystemContorller
            return  JsonResult.success(item.getPath());
        } catch (IOException e) {
            throw new PlatformException(e.getMessage());
        }
        
    }
    
    @PostMapping(MODEL + "/excel/import.do")
    @Function("xzxOrderClockInInfo")
    @ResponseBody
    public JsonResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        if (file.isEmpty()) {
           return JsonResult.fail();
        }
        InputStream ins = file.getInputStream();
        /*解析模板并导入到数据库里,参考DictConsoleContorller,使用jxls reader读取excel数据*/
        ins.close();
        return JsonResult.success();
    }
    
    
 
}