xuhy
2024-12-11 5be07b1a021f596b003eac001f4cb77416ae6c7b
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
package com.ruoyi.web.controller.api;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.dto.AllertTitleDto;
import com.ruoyi.system.dto.RegionDto;
import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.query.CityQueryDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.nio.file.LinkOption;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
 
@RestController
@RequestMapping("/web")
public class WebController {
 
 
    @Resource
    private TIndexMenuService indexMenuService;
    @Resource
    private TRegionService regionService;
 
    @Autowired
    private TokenService tokenService;
    @Resource
    private TUserChangeService changeService;
    @Resource
    private TUserChangeDetailService changeDetailService;
    @Resource
    private TAppUserService appUserService;
 
    @ApiOperation(value = "获取地区树状图",tags = "web端偏好设置")
    @PostMapping(value = "/region/tree")
    public R<List<RegionDto>> regionTree() {
 
       List<RegionDto> regionDtos = regionService.regionTree();
 
 
        return R.ok(regionDtos);
    }
 
 
 
    @ApiOperation(value = "通过cityCodes查职称分类",tags = "web端偏好设置")
    @PostMapping(value = "/title/tree")
    public R<List<AllertTitleDto>> list(@Validated @RequestBody CityQueryDto cityQueryDto) {
        String[] split = cityQueryDto.getStrings().split(",");
        cityQueryDto.getCityCode().addAll(Arrays.asList(split));
        List<AllertTitleDto> allertTitleDtos =  indexMenuService.allert(cityQueryDto.getCityCode());
        return R.ok(allertTitleDtos);
    }
 
    @ApiOperation(value = "设置偏好设置",tags = "web端偏好设置")
    @PostMapping(value = "/title/set")
    public R<List<AllertTitleDto>> set(@RequestBody List<TUserChangeDetail> userChangeDetails) {
        Long userId = tokenService.getLoginUser().getUserId();
        TAppUser byId = appUserService.getById(userId);
        if(Objects.nonNull(byId)){
            byId.setIsSetPreference(1);
            appUserService.updateById(byId);
        }
 
        //保存一次变更记录
 
        TUserChange tUserChange = new TUserChange();
        tUserChange.setUserId(userId);
        changeService.save(tUserChange);
 
 
        //保存变更细节
        for (TUserChangeDetail userChangeDetail : userChangeDetails) {
            userChangeDetail.setChangeId(tUserChange.getId());
        }
        changeDetailService.saveBatch(userChangeDetails);
 
 
        return R.ok();
    }
 
}