puzhibing
2023-06-13 7860e5cb6db60aeb82c640651998f8294635df5b
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
package com.dsh.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.common.constant.factory.PageFactory;
import com.dsh.guns.core.log.LogObjectHolder;
import com.dsh.guns.core.util.SinataUtil;
import com.dsh.guns.core.util.ToolUtil;
import com.dsh.guns.modular.system.model.TCarBrand;
import com.dsh.guns.modular.system.model.TCarModel;
import com.dsh.guns.modular.system.service.ITCarBrandService;
import com.dsh.guns.modular.system.service.ITCarModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.net.InetSocketAddress;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 车辆类型管理控制器
 *
 * @author fengshuonan
 * @Date 2020-06-05 14:31:28
 */
@Controller
@RequestMapping("/tCarModel")
public class TCarModelController extends BaseController {
 
    private String PREFIX = "/system/tCarModel/";
 
    @Autowired
    private ITCarModelService tCarModelService;
 
    @Autowired
    private ITCarBrandService tCarBrandService;
 
    /**
     * 跳转到车辆类型管理首页
     */
    @RequestMapping("")
    public String index(Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        return PREFIX + "tCarModel.html";
    }
 
    /**
     * 跳转到添加车辆类型管理
     */
    @RequestMapping("/tCarModel_add")
    public String tCarModelAdd(Model model) {
        List<TCarBrand> brandList = tCarBrandService.list(new QueryWrapper<TCarBrand>().eq("state", 1).orderByDesc("insertTime"));
        model.addAttribute("brandList",brandList);
        model.addAttribute("language",UserExt.getLanguage());
        return PREFIX + "tCarModel_add.html";
    }
 
    /**
     * 跳转到修改车辆类型管理
     */
    @RequestMapping("/tCarModel_update/{tCarModelId}")
    public String tCarModelUpdate(@PathVariable Integer tCarModelId, Model model) {
        TCarModel tCarModel = tCarModelService.getById(tCarModelId);
        model.addAttribute("item",tCarModel);
        LogObjectHolder.me().set(tCarModel);
 
        List<TCarBrand> brandList = tCarBrandService.list(new QueryWrapper<TCarBrand>().eq("state", 1).orderByDesc("insertTime"));
        model.addAttribute("brandList",brandList);
        model.addAttribute("language",UserExt.getLanguage());
        return PREFIX + "tCarModel_edit.html";
    }
 
    /**
     * 获取车辆类型管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String createTime,
                       String name,Integer yy) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(createTime)){
            String[] timeArray = createTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        List<Map<String, Object>> carModelList = tCarModelService.getCarModelList(page, beginTime, endTime, name, yy);
        if(ToolUtil.isEmpty(yy)){
            Integer language = UserExt.getLanguage();
            if(language==2){
                for (Map<String, Object> stringObjectMap : carModelList) {
                    stringObjectMap.put("name",stringObjectMap.get("ename"));
                }
            }else if(language==3){
                for (Map<String, Object> stringObjectMap : carModelList) {
                    stringObjectMap.put("name",stringObjectMap.get("yname"));
                }
            }
        }else {
            if(yy==2){
                for (Map<String, Object> stringObjectMap : carModelList) {
                    stringObjectMap.put("name",stringObjectMap.get("ename"));
                }
            }else if(yy==3){
                for (Map<String, Object> stringObjectMap : carModelList) {
                    stringObjectMap.put("name",stringObjectMap.get("yname"));
                }
            }
        }
 
 
        page.setRecords(carModelList);
        return super.packForBT(page);
    }
 
    /**
     * 新增车辆类型管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TCarModel tCarModel,Integer language) {
        tCarModel.setInsertTime(new Date());
        tCarModel.setState(1);
        tCarModel.setLanguage(language);
        tCarModelService.save(tCarModel);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除车辆类型管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tCarModelId) {
        TCarModel tCarModel = tCarModelService.getById(tCarModelId);
        tCarModel.setState(2);
        tCarModelService.updateById(tCarModel);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改车辆类型管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TCarModel tCarModel,Integer language) {
        tCarModel.setLanguage(language);
        tCarModelService.updateById(tCarModel);
        return SUCCESS_TIP;
    }
 
}