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
162
163
164
165
166
package com.dsh.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.log.LogObjectHolder;
import com.dsh.guns.modular.system.model.TbVoice;
import com.dsh.guns.modular.system.service.ITbVoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
 
import java.util.Date;
import java.util.List;
 
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2022-06-17 14:43:39
 */
@Controller
@RequestMapping("/TVoice")
public class TVoiceController extends BaseController {
 
    private String PREFIX = "/system/tVoice/";
 
    @Autowired
    private ITbVoiceService tbVoiceService;
 
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index(Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        return PREFIX + "tbVoice.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tbVoice_add")
    public String tbVoiceAdd(Model model) {
        model.addAttribute("language1",UserExt.getLanguage());
        return PREFIX + "tbVoice_add.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/tbVoice_update/{tbVoiceId}")
    public String tbVoiceUpdate(@PathVariable Integer tbVoiceId, Model model) {
        TbVoice tbVoice = tbVoiceService.getById(tbVoiceId);
        model.addAttribute("item",tbVoice);
        model.addAttribute("language1",UserExt.getLanguage());
        LogObjectHolder.me().set(tbVoice);
        return PREFIX + "tbVoice_edit.html";
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public List<TbVoice> list(String name , Integer state) {
        return tbVoiceService.getList(name,state);
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Integer language,String url,Integer userType, String name) {
        List<TbVoice> list = tbVoiceService.list(new LambdaQueryWrapper<TbVoice>().eq(TbVoice::getVoiceType, userType).eq(TbVoice::getLanguage,language).ne(TbVoice::getState,3));
        if(list.size()>0){
            return "504";
        }
 
        TbVoice tbVoice = new TbVoice();
        tbVoice.setState(1);
        tbVoice.setCreateTime(new Date());
        tbVoice.setLanguage(language);
        tbVoice.setVoiceType(userType);
        tbVoice.setUrl(url);
//        tbVoice.setInsertTime(new Date());
        tbVoice.setName(name);
//        tbVoice.setPublisher(ShiroKit.getUser().getName());
        tbVoiceService.save(tbVoice);
        return SUCCESS_TIP;
    }
 
//    public static void main(String[] args) {
//        String a ="C:\\fakepath\\998e5510ea7fc3d1733ec901e778988f.jpg";
//        String[] split = a.split("\\.");
//        String s = split[split.length-1];
//        int i = a.lastIndexOf("\\")+1;
//        int i1 = a.lastIndexOf(".");
//        String substring = a.substring(i, i1);
//        System.out.println(substring);
//    }
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer TVoiceId) {
        TbVoice byId = tbVoiceService.getById(TVoiceId);
        byId.setState(3);
        tbVoiceService.updateById(byId);
        return SUCCESS_TIP;
    }
    @RequestMapping(value = "/start")
    @ResponseBody
    public Object start(@RequestParam Integer TVoiceId) {
        TbVoice byId = tbVoiceService.getById(TVoiceId);
        byId.setState(1);
        tbVoiceService.updateById(byId);
        return SUCCESS_TIP;
    }
    @RequestMapping(value = "/stop")
    @ResponseBody
    public Object stop(@RequestParam Integer TVoiceId) {
        TbVoice byId = tbVoiceService.getById(TVoiceId);
        byId.setState(2);
        tbVoiceService.updateById(byId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Integer id,Integer language,String url,Integer userType) {
        List<TbVoice> list = tbVoiceService.list(new LambdaQueryWrapper<TbVoice>().eq(TbVoice::getVoiceType, userType).eq(TbVoice::getLanguage,language).ne(TbVoice::getId, id).ne(TbVoice::getState,3));
        if(list.size()>0){
            return "504";
        }
 
 
        TbVoice byId = tbVoiceService.getById(id);
        byId.setLanguage(language);
        byId.setUrl(url);
        byId.setVoiceType(userType);
        int i = url.lastIndexOf("\\")+1;
        int i1 = url.lastIndexOf(".");
        String substring = url.substring(i, i1);
        byId.setName(substring);
        tbVoiceService.updateById(byId);
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{tbVoiceId}")
    @ResponseBody
    public Object detail(@PathVariable("tbVoiceId") Integer tbVoiceId) {
        return tbVoiceService.getById(tbVoiceId);
    }
}