xuhy
2023-03-06 3bcf6a65dfb9813dff2986c9cc03b638742ce64e
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
package com.stylefeng.guns.modular.system.controller.general;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.system.model.TAppUser;
import com.stylefeng.guns.modular.system.model.TSystemConfig;
import com.stylefeng.guns.modular.system.model.User;
import com.stylefeng.guns.modular.system.service.ITSystemConfigService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.TBranchOffice;
import com.stylefeng.guns.modular.system.service.ITBranchOfficeService;
 
import java.util.Objects;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-02-21 11:17:18
 */
@Controller
@RequestMapping("/tBranchOffice")
public class TBranchOfficeController extends BaseController {
 
    private String PREFIX = "/system/tBranchOffice/";
 
    @Autowired
    private ITBranchOfficeService tBranchOfficeService;
    @Autowired
    private ITSystemConfigService tSystemConfigService;
 
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tBranchOffice.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tBranchOffice_add")
    public String tBranchOfficeAdd() {
        return PREFIX + "tBranchOffice_add.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/tBranchOffice_update/{tBranchOfficeId}")
    public String tBranchOfficeUpdate(@PathVariable Integer tBranchOfficeId, Model model) {
        TBranchOffice tBranchOffice = tBranchOfficeService.selectById(tBranchOfficeId);
        model.addAttribute("item",tBranchOffice);
        LogObjectHolder.me().set(tBranchOffice);
        return PREFIX + "tBranchOffice_edit.html";
    }
 
    /**
     * 跳转到详情
     */
    @RequestMapping("/tBranchOfficeDetail")
    public String tBranchOfficeDetail(Integer tBranchOfficeId, Model model) {
        tBranchOfficeService.tBranchOfficeDetail(tBranchOfficeId,model);
        TSystemConfig tSystemConfig = tSystemConfigService.selectOne(new EntityWrapper<TSystemConfig>().eq("type", 3));
        JSONObject jsonObject = JSONObject.parseObject(tSystemConfig.getContent());
        model.addAttribute("num2",jsonObject.getInteger("num2"));
        model.addAttribute("num3",jsonObject.getInteger("num3"));
        return PREFIX + "tBranchOfficeDetail.html";
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String branchOfficeName,String principal,String principalPhone,Integer operatingBusiness ,Integer status) {
        EntityWrapper<TBranchOffice> wrapper = new EntityWrapper<>();
        // 分公司名称
        if(StringUtils.hasLength(branchOfficeName)){
            wrapper.like("branchOfficeName",branchOfficeName);
        }
        // 负责人
        if(StringUtils.hasLength(principal)){
            wrapper.like("principal",principal);
        }
        // 负责人电话
        if(StringUtils.hasLength(principalPhone)){
            wrapper.like("principalPhone",principalPhone);
        }
        // 经营业务
        if(Objects.nonNull(operatingBusiness)){
            wrapper.eq("operatingBusiness",operatingBusiness);
        }
        // 状态
        if(Objects.nonNull(status)){
            wrapper.eq("status",status);
        }
        // 判断代理商 分公司
        Integer roleType = Objects.requireNonNull(ShiroKit.getUser()).getRoleType();
        Integer objectId = Objects.requireNonNull(ShiroKit.getUser()).getObjectId();
        if(2 == roleType){
            // 分公司
            wrapper.eq("id",objectId);
        }
        if(3 == roleType){
            // 代理商
            wrapper.eq("agentId",objectId);
        }
        return tBranchOfficeService.selectList(wrapper);
    }
 
    /**
     * 启用分公司
     */
    @RequestMapping(value = "/start")
    @ResponseBody
    public Object start(Integer id) {
        TBranchOffice tBranchOffice = tBranchOfficeService.selectById(id);
        tBranchOffice.setStatus(1);
        tBranchOfficeService.updateById(tBranchOffice);
        return SUCCESS_TIP;
    }
 
    /**
     * 冻结分公司
     */
    @RequestMapping(value = "/stop")
    @ResponseBody
    public Object updateStatus(Integer id) {
        TBranchOffice tBranchOffice = tBranchOfficeService.selectById(id);
        tBranchOffice.setStatus(2);
        tBranchOfficeService.updateById(tBranchOffice);
        return SUCCESS_TIP;
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list-back")
    @ResponseBody
    public Object listBack(String condition) {
        return tBranchOfficeService.selectList(null);
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TBranchOffice tBranchOffice) {
        tBranchOfficeService.insert(tBranchOffice);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tBranchOfficeId) {
        tBranchOfficeService.deleteById(tBranchOfficeId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TBranchOffice tBranchOffice) {
        tBranchOfficeService.updateById(tBranchOffice);
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{tBranchOfficeId}")
    @ResponseBody
    public Object detail(@PathVariable("tBranchOfficeId") Integer tBranchOfficeId) {
        return tBranchOfficeService.selectById(tBranchOfficeId);
    }
}