xuhy
2023-08-11 1ec67d10e570856dd15160507dd823ea1b19863e
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
package com.stylefeng.guns.modular.system.controller.specialTrain;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.ErrorTip;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.modular.system.model.TCompany;
import com.stylefeng.guns.modular.system.service.ITCompanyService;
import com.stylefeng.guns.modular.system.service.IUserService;
import org.springframework.stereotype.Controller;
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.TDispatch;
import com.stylefeng.guns.modular.system.service.ITDispatchService;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 调度管理控制器
 *
 * @author fengshuonan
 * @Date 2020-09-01 16:00:16
 */
@Controller
@RequestMapping("/tDispatch")
public class TDispatchController extends BaseController {
 
    private String PREFIX = "/system/tDispatch/";
 
    @Autowired
    private ITDispatchService tDispatchService;
 
    @Autowired
    private ITCompanyService tCompanyService;
 
    @Autowired
    private IUserService userService;
 
    /**
     * 跳转到调度管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tDispatch.html";
    }
 
    /**
     * 跳转到添加调度管理
     */
    @RequestMapping("/tDispatch_add")
    public String tDispatchAdd(Model model) {
        model.addAttribute("roleType",ShiroKit.getUser().getRoleType());
 
        List<TCompany> companyList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 2)
                .eq("isCross", 1)
                .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
        model.addAttribute("companyList",companyList);
 
        if (2 == ShiroKit.getUser().getRoleType()){
            List<TCompany> franchiseeList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 3)
                    .eq("superiorId",ShiroKit.getUser().getObjectId()));
            model.addAttribute("franchiseeList",franchiseeList);
        }else{
            model.addAttribute("franchiseeList",null);
        }
        return PREFIX + "tDispatch_add.html";
    }
 
    /**
     * 根据分公司ID获取加盟商
     * @param oneId
     * @return
     */
    @RequestMapping(value = "/companyChange")
    @ResponseBody
    public Object companyChange(@RequestParam Integer oneId) {
        List<TCompany> list = new ArrayList<>();
        if (SinataUtil.isNotEmpty(oneId)){
            list = tCompanyService.selectList(new EntityWrapper<TCompany>()
                    .eq("type", 3)
                    .eq("isCross", 1)
                    .eq("superiorId", oneId)
                    .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
        }
        return list;
    }
 
    /**
     * 跳转到修改调度管理
     */
    @RequestMapping("/tDispatch_update/{tDispatchId}")
    public String tDispatchUpdate(@PathVariable Integer tDispatchId, Model model) {
        TDispatch tDispatch = tDispatchService.selectById(tDispatchId);
        model.addAttribute("item",tDispatch);
        LogObjectHolder.me().set(tDispatch);
 
        Integer roleType = ShiroKit.getUser().getRoleType();
        model.addAttribute("roleType",roleType);
        if (1 == roleType){
            List<TCompany> companyList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 2)
                    .eq("isCross", 1)
                    .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
            model.addAttribute("companyList",companyList);
 
            List<TCompany> franchiseeList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 3)
                    .eq("superiorId",tDispatch.getCompanyId())
                    .eq("isCross", 1)
                    .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
            model.addAttribute("franchiseeList",franchiseeList);
        }else if (2 == roleType){
            List<TCompany> franchiseeList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 3)
                    .eq("superiorId",ShiroKit.getUser().getObjectId())
                    .eq("isCross", 1)
                    .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
            model.addAttribute("franchiseeList",franchiseeList);
        }
        return PREFIX + "tDispatch_edit.html";
    }
 
    /**
     * 获取调度管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,String name,String companyName,String franchiseeName,String account,Integer state) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)){
            String[] timeArray = insertTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tDispatchService.getDispatchList(page,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),beginTime,endTime,name,companyName,franchiseeName,account,state));
        return super.packForBT(page);
    }
 
    /**
     * 新增调度管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TDispatch tDispatch) {
        //判断账号是否存在
        int count = tDispatchService.selectCount(new EntityWrapper<TDispatch>().eq("account",tDispatch.getAccount()).last(" and FIND_IN_SET(state,'1,2')"));
        if (count > 0){
            return new ErrorTip(500,"账号已存在,请重新输入");
        }
        Integer roleType = ShiroKit.getUser().getRoleType();
        Integer objectId = ShiroKit.getUser().getObjectId();
        if (2 == roleType){
            tDispatch.setCompanyId(objectId);
        }else if (3 == roleType){
            TCompany company = tCompanyService.selectById(objectId);
            tDispatch.setCompanyId(company.getSuperiorId());
            tDispatch.setFranchiseeId(objectId);
        }
        tDispatch.setInsertTime(new Date());
        tDispatch.setInsertUserId(ShiroKit.getUser().getId());
        tDispatch.setInsertUserRole(roleType);
        tDispatch.setState(1);
        if(tDispatch.getCompanyId() == null){
            Integer objectId1 = userService.selectById(ShiroKit.getUser().getId()).getObjectId();
            tDispatch.setCompanyId(objectId1);
        }
        tDispatch.setPassword(ShiroKit.md5(tDispatch.getPassword(), "WL:x9#"));
        tDispatchService.insert(tDispatch);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除调度管理
     * @param tDispatchId
     * @param optType  1=删除  2=冻结  3=解冻
     * @return
     */
    @RequestMapping(value = "/opt")
    @ResponseBody
    public Object delete(@RequestParam Integer tDispatchId,@RequestParam Integer optType) {
        TDispatch dispatch = tDispatchService.selectById(tDispatchId);
        if (1 == optType){
            dispatch.setState(3);
        }else if (2 == optType){
            dispatch.setState(2);
        }else if (3 == optType){
            dispatch.setState(1);
        }
        tDispatchService.updateById(dispatch);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改调度管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TDispatch tDispatch) {
        TDispatch obj = tDispatchService.selectById(tDispatch.getId());
        if (!obj.getAccount().equals(tDispatch.getAccount())){
            //判断账号是否存在
            int count = tDispatchService.selectCount(new EntityWrapper<TDispatch>().eq("account",tDispatch.getAccount()).last(" and FIND_IN_SET(state,'1,2')"));
            if (count > 0){
                return new ErrorTip(500,"账号已存在,请重新输入");
            }
        }
        Integer roleType = ShiroKit.getUser().getRoleType();
        Integer objectId = ShiroKit.getUser().getObjectId();
        if (2 == roleType){
            tDispatch.setCompanyId(objectId);
        }else if (3 == roleType){
            TCompany company = tCompanyService.selectById(objectId);
            tDispatch.setCompanyId(company.getSuperiorId());
            tDispatch.setFranchiseeId(objectId);
        }
        if (SinataUtil.isNotEmpty(tDispatch.getPassword())){
            tDispatch.setPassword(ShiroKit.md5(tDispatch.getPassword(), "WL:x9#"));
        }
        tDispatchService.updateById(tDispatch);
        return SUCCESS_TIP;
    }
 
}