1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
package com.landtool.lanbase.modules.sys.controller;
 
import java.io.File;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.landtool.lanbase.common.utils.*;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
 
import com.landtool.lanbase.modules.org.entity.OrgUser;
import com.landtool.lanbase.modules.sys.entity.PubNews;
import com.landtool.lanbase.modules.sys.service.PubNewsService;
 
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
import com.landtool.lanbase.common.annotation.LogAction;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * @author zimao.guo
 * @Description: TODO(${comments})
 * @date 2018-04-17 15:04:58
 */
@RestController
@RequestMapping("/sys/pubnews")
public class PubNewsController extends AbstractController{
 
    @Autowired
    private PubNewsService pubNewsService;
 
    @Autowired
    private SysTemPropertyConfig sysProps;
    /**
     * 列表
     */
    @LogAction("平台管理,资讯发布,资讯发布查询,查询")
    @RequestMapping(value ="/list", method ={RequestMethod.POST, RequestMethod.GET})
//    @RequiresPermissions("sys:pubnews:list")
    @RequiresPermissions(value = {"sys:pubnews:list","sys:pubnews:edit"}, logical = Logical.OR)
    @ApiOperation(
            value = "资讯发布列表",
            notes = ""
            )
    public Result list(@ApiParam(name="params",value="",required=true)@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
         List<PubNews> pubNewsList = pubNewsService.queryList(query);
        int total = pubNewsService.queryTotal(query);
        
        PageUtils pageUtil = new PageUtils(pubNewsList, total, query.getLimit(), query.getPage());
        
        return Result.ok().put("page", pageUtil);
    }
    
    /**
     * 删除
     */
    @LogAction("平台管理,资讯发布,资讯发布删除,删除")
    @PostMapping("/delete")
    @RequiresPermissions("sys:pubnews:edit")
    @ApiOperation(
            value = "删除资讯发布信息",
            notes = ""
            )
    public Result delete(@ApiParam(name="newsids",value="newsids",required=true)@RequestBody Integer[] newsids){
        pubNewsService.deleteBatch(newsids);
        
        return Result.ok();
    }
    
    /**
     * 信息
     */
    @GetMapping("/info/{newsid}")
    @RequiresPermissions("sys:pubnews:edit")
    @ApiOperation(
            value = "资讯发布信息",
            notes = ""
            )
    public Result info(@ApiParam(name="newsid",value="newsid",required=true)@PathVariable("newsid") String newsid){
        PubNews info = pubNewsService.queryObject(Integer.parseInt(newsid));
        return Result.ok().put("info", info);
    }
    
    /**
     * 保存
     */
    @LogAction("平台管理,资讯发布,资讯发布新增,新增")
    @PostMapping("/save")
    @RequiresPermissions("sys:pubnews:edit")
    @ApiOperation(
            value = "保存资讯发布信息",
            notes = ""
            )
    public Result save(@ApiParam(name="资讯发布对象",value="传入json格式",required=true)@RequestBody PubNews pubnews){
        if(pubnews.getTitle() == null || pubnews.getTitle().length() == 0){
            return Result.error("保存失败,存在特殊字符,请重新输入!");
        }
        OrgUser orgUser = (OrgUser) SecurityUtils.getSubject().getPrincipal();
        Timestamp time = new Timestamp(new Date().getTime());
        pubnews.setCreateuser(Integer.parseInt(orgUser.getUserid().toString()));
        pubnews.setCreatedate(time);
        pubnews.setLasteditdate(time);
        pubNewsService.save(pubnews);
        //保存完后获取对应newsid
        int newsid = pubNewsService.queryPubNewsWithSEQ();
        return Result.ok().put("newsid",newsid);
    }
    
    /**
     * 修改
     */
    @LogAction("平台管理,资讯发布,资讯发布修改,修改")
    @PostMapping("/update")
    @RequiresPermissions("sys:pubnews:edit")
    @ApiOperation(
            value = "修改资讯发布信息",
            notes = ""
            )
    public Result update(@ApiParam(name="资讯发布对象",value="传入json格式",required=true)@RequestBody PubNews pubnews){
        if(pubnews.getTitle() == null || pubnews.getTitle().length() == 0){
            return Result.error("保存失败,存在特殊字符,请重新输入!");
        }
        Timestamp time = new Timestamp(new Date().getTime());
        pubnews.setLasteditdate(time);
        pubNewsService.update(pubnews);
        return Result.ok();
    }
 
    @RequestMapping("/uploadueditorfile")
    public ResponseEntity<Map<String, Object>> uploadueditorfile(
            @RequestParam(value = "upfile", required = false) MultipartFile file,
            HttpServletRequest request) {//value的名字一定要叫upfile,这是ueditor写好的参数名称
        String fileName = file.getOriginalFilename();
        String[] types = fileName.split("\\.");
        String type = types[types.length - 1];
        String root = sysProps.getUploadPath().replace("/","\\");
        String LinShiUrl=root+"\\ueditor";
        String suffix= FileUtils.getSuffix(file.getOriginalFilename());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String timePath = sdf.format(new Date().getTime());
        timePath = timePath.replace("-", "");
        String newFileName= AttachmentUtils.newFileName(suffix,LinShiUrl,timePath);
        File newFile=new File(newFileName);
        //临时文件处理
        try {
            file.transferTo(newFile);
        }catch (Exception e){
            e.printStackTrace();
        }
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("state", "SUCCESS");// UEDITOR的规则:不为SUCCESS则显示state的内容
        result.put("url",sysProps.getUploadUeditorPath() + FileUtils.removePrefix(newFile.getAbsolutePath(),root).replace("\\", "/"));
        result.put("title", file.getOriginalFilename());
        result.put("original", file.getOriginalFilename());
        result.put("size", file.getSize());
        result.put("type", type);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.TEXT_PLAIN);
        return new ResponseEntity<Map<String,Object>>(result,headers, HttpStatus.OK);
    }
 
}