admin
2021-04-25 36aafca8d6c1964bb755fe2ae030b163b6d0f92b
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
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import net.sf.json.JSONObject;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.ShareContent;
import com.yeshi.buwan.service.imp.ShareService;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.web.tag.PageEntity;
 
@Controller
@RequestMapping("admin/new/api/share")
public class ShareController {
 
    @Resource
    private ShareService shareService;
    @Resource
    private SystemService systemService;
    
    @RequestMapping("shareList")
    public void shareList(String key,int pageIndex,PrintWriter out) {
 
        key = StringUtil.isNullOrEmpty(key) ? "" : key;
        pageIndex = pageIndex <= 0 ? 1 : pageIndex;
 
        List<ShareContent> list = shareService.getShareContentList(key, pageIndex);
        long count = shareService.getShareContentListCount(key);
        PageEntity page = new PageEntity();
        Map<String, String> map = new HashMap<String, String>();
        map.put("key", key);
        page.setParams(map);
        page.setPageIndex(pageIndex);
        page.setPageSize(Constant.pageCount);
        page.setTotalCount((int) count);
        JSONObject json=new JSONObject();
        json.put("code", "0");
        json.put("pageEntity", page);
        Gson gson =new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        json.put("shareList", gson.toJson(list));
        out.print(json);
        
        return;
    }
    
    @RequestMapping("addShare")
    public void addShare(String shareContent,String detailSystem,String shareUrl,PrintWriter out) {
 
        ShareContent sc = new ShareContent();
        sc.setShareContent(shareContent);
        sc.setShareUrl(shareUrl);
        sc.setDetailSystem(new DetailSystem(detailSystem));
        sc.setCreatetime(System.currentTimeMillis() + "");
        shareService.addShareContent(sc);
        out.print("yes");
        return ;
    }
    
    @RequestMapping("updateShare")
    public void updateShare(String id,String shareContent,String shareUrl,PrintWriter out) {
 
        ShareContent sc = shareService.getShareContentById(id);
        sc.setShareContent(shareContent);
        sc.setShareUrl(shareUrl);
        shareService.updateShareContent(sc);
        out.print("yes");
        return ;
    }
    
    @RequestMapping("getShare")
    public void getShare(String id,PrintWriter out) {
        ShareContent sc = shareService.getShareContentById(id);
        Gson gson =new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        JSONObject json =new JSONObject();
        json.put("code", "0");
        json.put("share", gson.toJson(sc));
        out.print(json);
        return ;
    }
    
    @RequestMapping("deleteShare")
    public void deleteShare(String ids,PrintWriter out) {
        if(ids == null || "".equals(ids.trim())){
            out.print("no");
            return;
        }
        String[] idArr = ids.split(",");
        for (String id : idArr) {
            System.out.println("id=="+id);
            shareService.deleteShareContent(new ShareContent(id));
        }
        out.print("yes");
        return ;
    }
    
}