luo
2023-12-25 23c4967b4cb8dbce8277f830f7152d315c5a4a57
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
package com.stylefeng.guns.modular.code.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.system.dto.Host;
import com.stylefeng.guns.modular.system.dto.THouseResource;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.IAppUserService;
import com.stylefeng.guns.modular.system.service.IHouseResourceService;
import com.stylefeng.guns.modular.system.service.IHouseTypeService;
import com.stylefeng.guns.modular.system.service.IHousingDemandService;
import com.stylefeng.guns.modular.system.util.RedisUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.warpper.req.AddHouseReq;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.bouncycastle.cms.PasswordRecipient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
@Controller
@RequestMapping("/base/house")
public class HouseController {
    @Autowired
    private IHouseTypeService houseTypeService;
 
 
    @Autowired
    private IHouseResourceService houseResourceService;
 
    @Autowired
    private IHousingDemandService demandService;
 
    @Autowired
    private IAppUserService appUserService;
 
    @Autowired
    private RedisUtil redisUtil;
 
 
    @ResponseBody
    @GetMapping("/data")
    @ApiOperation(value = "统计", tags = {"后台-主页"})
    public List<Integer> data(){
 
        Date date = new Date(); // 假设这是您的java.util.Date对象
 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String formattedDate = sdf.format(date);
 
        LocalDate today = LocalDate.now();
 
        List<Integer> data = new ArrayList<>();
        //总房源
        Integer one = houseResourceService.selectCount(new EntityWrapper<HouseResource>().eq("is_delete", 0));
        data.add(one);
        //总出租房源
        Integer two = houseResourceService.selectCount(new EntityWrapper<HouseResource>().eq("is_delete", 0).eq("data_type",1));
        data.add(two);
        //总卖房源
        Integer three = houseResourceService.selectCount(new EntityWrapper<HouseResource>().eq("is_delete", 0).eq("data_type",2));
        data.add(three);
        //总求买房
        Integer four = demandService.selectCount(new EntityWrapper<HousingDemand>().eq("is_delete", 0).eq("data_type",2));
        data.add(four);
        //总求租房
        Integer five = demandService.selectCount(new EntityWrapper<HousingDemand>().eq("is_delete", 0).eq("data_type",1));
        data.add(five);
        //总中介
        Integer six = appUserService.selectCount(new EntityWrapper<AppUser>().eq("user_type",3).ne("status",3));
        data.add(six);
        //总房东
        Integer seven = appUserService.selectCount(new EntityWrapper<AppUser>().eq("user_type",3).ne("status",2));
        data.add(seven);
        //总用户
        Integer eight = appUserService.selectCount(new EntityWrapper<AppUser>().ne("status",2));
        data.add(eight);
        //今日新增中介
        Integer nine = appUserService.selectCount(new EntityWrapper<AppUser>()
                .eq("user_type", 3)
                .ne("status", 3)
                .like("changeTime", formattedDate));
        data.add(nine);
        //今日新增房东
        Integer ten = appUserService.selectCount(new EntityWrapper<AppUser>()
                .eq("user_type",2)
                .ne("status",3)
                .like("changeTime", formattedDate));
        data.add(ten);
        //今日新增用户
        Integer eleven = appUserService.selectCount(new EntityWrapper<AppUser>().ne("status",3).like("insert_time", formattedDate));
        data.add(eleven);
        //今日新增房源出租
        Integer twelve = houseResourceService.selectCount(new EntityWrapper<HouseResource>().eq("is_delete", 0).ne("type",1).eq("data_type",1).like("auth_time", formattedDate));
        data.add(twelve);
        //今日卖房源
        Integer thirteen = houseResourceService.selectCount(new EntityWrapper<HouseResource>().eq("is_delete", 0).ne("type",1).eq("data_type",2).like("auth_time", formattedDate));
        data.add(thirteen);
        //今日求租房
        Integer fourteen = demandService.selectCount(new EntityWrapper<HousingDemand>().eq("is_delete", 0).ne("type",1).eq("data_type",1).like("insert_time", formattedDate));
        data.add(fourteen);
        //今日求买房
        Integer fifteen = demandService.selectCount(new EntityWrapper<HousingDemand>().eq("is_delete", 0).ne("type",1).eq("data_type",2).like("insert_time", formattedDate));
        data.add(fifteen);
 
        return data;
    }
 
 
    @ResponseBody
    @PostMapping("/addHouse/add")
    @ApiOperation(value = "发布房源", tags = {"后台-房源管理"})
    public ResultUtil addHouse(@RequestBody AddHouseReq req){
        return houseResourceService.addHouse(req);
    }
 
 
    @ResponseBody
    @GetMapping("/getHouseType")
    @ApiOperation(value = "获取房源类型", tags = {"后台-房源管理"})
    public ResultUtil<List<HouseType>> getHouseType(){
        List<HouseType> houseTypes = houseTypeService.selectList(null);
        return ResultUtil.success(houseTypes);
    }
 
    @ResponseBody
    @GetMapping("/getHouseTypeList")
    @ApiOperation(value = "获取房源类型列表", tags = {"后台-房源管理"})
    public Object getHouseTypeList(@RequestParam int pageNum,@RequestParam int pageSize){
 
        PageHelper.startPage(pageNum,pageSize);
        List<HouseType> houseTypes = houseTypeService.list();
        PageInfo<HouseType> info=new PageInfo<>(houseTypes);
        System.err.println(info);
        return info;
    }
 
 
 
    @ResponseBody
    @PostMapping("/addHouseType")
    @ApiOperation(value = "增加房源类型", tags = {"后台-房源管理"})
    public ResultUtil addHouseType(@RequestBody HouseType houseType){
        houseType.setInsertTime(new Date());
        houseType.setCreateBy(Objects.requireNonNull(ShiroKit.getUser()).id);
        houseTypeService.insert(houseType);
 
        return ResultUtil.success("增加成功");
    }
 
    @ResponseBody
    @DeleteMapping("/deleteHouseType")
    @ApiOperation(value = "删除房源类型", tags = {"后台-房源管理"})
    public ResultUtil deleteHouseType(Integer id){
        houseTypeService.deleteById(id);
        return ResultUtil.success("删除成功");
    }
 
    @ResponseBody
    @GetMapping("/pre/edit")
    @ApiOperation(value = "编辑房源前", tags = {"后台-房源管理"})
    public AddHouseReq preEdit(Integer id){
        HouseResource houseResource = houseResourceService.selectById(id);
        AddHouseReq addHouseReq = new AddHouseReq();
        BeanUtils.copyProperties(houseResource,addHouseReq);
        addHouseReq.setTime(houseResource.getLeaseTime());
        return addHouseReq;
    }
 
 
    @ResponseBody
    @GetMapping("/auth/setting")
    @ApiOperation(value = "房源审核设置", tags = {"后台-房源审核设置"})
    public ResultUtil setting(){
        String tt = redisUtil.getValue("HouseAuthSetting");
        if (tt.equals("null")){
            tt = "0";
        }
        return ResultUtil.success(tt);
    }
 
    @ResponseBody
    @PutMapping("/auth/setting/update")
    @ApiOperation(value = "房源审核设置修改", tags = {"后台-房源审核设置"})
    public ResultUtil settingUpdate(Integer num){
        redisUtil.setStrValue("HouseAuthSetting", String.valueOf(num));
        return ResultUtil.success("保存成功");
    }
 
 
    @ResponseBody
    @PutMapping("/edit")
    @ApiOperation(value = "编辑房源", tags = {"后台-房源管理"})
    public ResultUtil edit(@RequestBody AddHouseReq req){
        return houseResourceService.editHouse(req);
    }
 
 
    @ResponseBody
    @GetMapping("/list")
    @ApiOperation(value = "列表", tags = {"后台-房源管理"},response = THouseResource.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "cellName", value = "小区名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "dataType", value = "房屋类型(1=出租,2=卖房)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "isManage", value = "1后台2房东3中介", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "姓名", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "saleAmount", value = "售卖金额区间'-'分隔", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态1=正常,2=冻结", dataType = "Integer", paramType = "query")
    })
    public PageInfo<THouseResource> list(@RequestParam int pageNum,
                                         @RequestParam int  pageSize,
                                         String cellName,
                                         Integer dataType,
                                         Integer isManage,
                                         String name,
                                         String saleAmount,
                                         Integer status){
 
 
        PageHelper.startPage(pageNum,pageSize);
        List<THouseResource> houseResources =houseResourceService.list(cellName,dataType,isManage,name,saleAmount,status);
        PageInfo<THouseResource> info=new PageInfo<>(houseResources);
        System.err.println(info);
        return  info;
    }
 
 
    @ResponseBody
    @GetMapping("/au/list")
    @ApiOperation(value = "审核列表", tags = {"后台-房源管理"},response = THouseResource.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "cellName", value = "小区名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "dataType", value = "房屋类型(1=出租,2=卖房)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "isManage", value = "1后台2房东3中介", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "姓名", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "saleAmount", value = "售卖金额区间'-'分隔", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "面积", dataType = "Integer", paramType = "query")
    })
    public PageInfo<THouseResource> auList(@RequestParam int pageNum,
                                         @RequestParam int  pageSize,
                                         String cellName,
                                         Integer dataType,
                                         Integer isManage,
                                         String name,
                                         String saleAmount,
                                         Integer id,String size){
 
 
        PageHelper.startPage(pageNum,pageSize);
        List<THouseResource> houseResources =houseResourceService.aulist(id,cellName,dataType,isManage,name,saleAmount,size);
        PageInfo<THouseResource> info=new PageInfo<>(houseResources);
        System.err.println(info);
        return  info;
    }
 
 
    @ResponseBody
    @PutMapping("/change")
    @ApiOperation(value = "(0=下架,1=上架,2=删除,3通过审核,4拒绝审核)", tags = {"后台-房源管理"})
    public ResultUtil change(String ids,Integer status,String reason){
        String[] split = ids.split(",");
        for (String id : split) {
        HouseResource houseResource = houseResourceService.selectById(Integer.valueOf(id));
 
        if (status==0||status==1){
            houseResource.setStatus(status);
        }else if (status==2){
            houseResource.setIsDelete(1);
        }else if (status ==3){
            houseResource.setAuthTime(new Date());
            houseResource.setAuthStatus(2);
        }else if (status == 4){
            houseResource.setAuthTime(new Date());
            houseResource.setReason(reason);
            houseResource.setAuthStatus(3);
        }
        houseResourceService.updateById(houseResource);
 
        }
        return ResultUtil.success("操作成功");
 
 
    }
 
 
 
 
 
}