whycrzg
2021-02-19 656bd1b190ed296a7bf63623dc8e9fe2bc9d3098
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
package com.fgkj.services;
 
import com.fgkj.dto.Announce;
import com.fgkj.dto.PageBean;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User_inf;
import com.fgkj.mapper.impl.AnnounceMapper;
import com.fgkj.mapper.impl.User_infMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
@Service
public class AnnounceService {
 
    @Resource
    private AnnounceMapper mapper;
    @Resource
    private User_infMapper userInfMapper;
    
    //发布新公告
    public ServiceModel add(Announce a) {
        ServiceModel model = new ServiceModel();
        Boolean bl= null;
        try {
            bl = mapper.add(a)>0;
        } catch (Exception e) {
            e.printStackTrace();
            model.setMsg("添加失败!");
            return model;
        }
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }
        else{
            model.setMsg("添加失败!");
        }
        return model;
        
    }
    
    //更新公告
    public ServiceModel update(Announce a) {
        ServiceModel model = new ServiceModel();
        Boolean bl=mapper.update(a)>0;
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }
        else{
            model.setMsg("修改失败!");
        }
        return model;    
    }
    
    //删除公告
    public ServiceModel delete(Announce a) {
        ServiceModel model = new ServiceModel();
        Boolean bl=mapper.del(a)>0;
        if(bl){
            model.setCode(1);
            model.setMsg("删除成功!");
        }
        else{
            model.setMsg("删除失败!");
        }
        return model;    
    }
    //根据查询条件查询公告
    public ServiceModel serchByCondition(Announce a){
        ServiceModel model = new ServiceModel();
        //物理分页
        PageBean pageBean = a.getPageBean();
        PageHelper.startPage(pageBean.getPageNum(), pageBean.getPageSize());
        List<Announce> list=mapper.serchByCondition(a);
        PageInfo<Announce> announcePageInfo = new PageInfo<>(list);
        /*for (Object object : list) {
            System.out.println(object);
        }*/
        if(list!=null&&list.size()>0){
            for(int i=0;i<list.size();i++){
                User_inf uinf=new User_inf();
                uinf.setuId(list.get(i).getUsr_id());
                List<User_inf> listU=userInfMapper.serchUname(uinf);
                if(listU!=null){
                    list.get(i).setUsr_name(listU.get(listU.size()-1).getuName());
                }else{
                    list.get(i).setUsr_name("");
                }
            }
        }
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setMsg("查询成功!");
            model.setData(announcePageInfo);
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        //System.out.println(model);        
        return model;
    } 
 
    //0.6公告信息显示
     public ServiceModel searchAll(){
        ServiceModel model = new ServiceModel();
        List<Announce> list=mapper.searchAll();
        if(list!=null&&list.size()>0){
            for(int i=0;i<list.size();i++){
                User_inf uinf=new User_inf();
                uinf.setuId(list.get(i).getUsr_id());
                List<User_inf> listU=userInfMapper.serchUname(uinf);
                if(listU!=null){
                    list.get(i).setUsr_name(listU.get(listU.size()-1).getuName());
                }else{
                    list.get(i).setUsr_name("");
                }
            }
        }
//        for (Object object : list) {
//            System.out.println(object);
//        }
        //System.out.println(list);
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setData(list);
        }
        //System.out.println(model);        
        return model;
    }
     
     //0.6公告信息显示(分页)
     public ServiceModel serchByInfo(Object obj){
        ServiceModel model = new ServiceModel();
         List<Announce> list=mapper.serchByInfo(obj);
         if(list!=null&&list.size()>0){
             for(int i=0;i<list.size();i++){
                 User_inf uinf=new User_inf();
                 uinf.setuId(list.get(i).getUsr_id());
                 List<User_inf> listU=userInfMapper.serchUname(uinf);
                 if(listU!=null){
                     list.get(i).setUsr_name(listU.get(listU.size()-1).getuName());
                 }else{
                     list.get(i).setUsr_name("");
                 }
             }
         }
         for (Object object : list) {
             System.out.println(object);
         }
         //System.out.println(list);
         if(list!=null && list.size()>0){
             model.setCode(1);
             model.setData(list);
         }
           System.out.println(model);        
         return model;
       }
     
}