zengh
2022-09-14 d79aeb1aefbeff017c27304750f62d629779ed0b
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
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.mechanism.controller;
 
import com.google.zxing.WriterException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
 
import javax.validation.Valid;
 
import org.springblade.common.utils.QRCodeUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.mechanism.entity.Mechanism;
import org.springblade.modules.mechanism.vo.MechanismVO;
import org.springblade.modules.mechanism.service.IMechanismService;
import org.springblade.core.boot.ctrl.BladeController;
import springfox.documentation.annotations.ApiIgnore;
import sun.misc.BASE64Encoder;
 
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
 
/**
 * 控制器
 *
 * @author BladeX
 * @since 2021-11-22
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-mechanism/mechanism")
@Api(value = "", tags = "接口")
public class MechanismController extends BladeController {
 
    private final IMechanismService mechanismService;
 
    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入mechanism")
    public R<Mechanism> detail(Mechanism mechanism) {
        Mechanism detail = mechanismService.getOne(Condition.getQueryWrapper(mechanism));
        return R.data(detail);
    }
 
    /**
     * 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入mechanism")
    public R<IPage<Mechanism>> list(@ApiIgnore @RequestParam Map<String, Object> mechanism, Query query) {
        IPage<Mechanism> pages = mechanismService.page(Condition.getPage(query), Condition.getQueryWrapper(mechanism, Mechanism.class));
        return R.data(pages);
    }
 
    /**
     * 自定义分页
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入mechanism")
    public R<IPage<MechanismVO>> page(MechanismVO mechanism, Query query) {
        IPage<MechanismVO> pages = mechanismService.selectMechanismPage(Condition.getPage(query), mechanism);
        return R.data(pages);
    }
 
    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入mechanism")
    public R save(@Valid @RequestBody Mechanism mechanism) throws IOException, WriterException {
        mechanism.setPitch("-90");
        mechanism.setHeading("0");
        mechanism.setRoll("0");
        mechanism.setGd("0");
        String addressName = URLEncoder.encode(mechanism.getAddressName(), "UTF-8");
        //String url = "http://192.168.0.115:8080/#/mobileLayout/default";
        String url = "https://dev.jxpskj.com:8023/zhjg/#/mobileLayout/default";
        String gotos = URLEncoder.encode("arc", "UTF-8");
        String mechanismname = URLEncoder.encode(mechanism.getMechanismname(), "UTF-8");
        String address = URLEncoder.encode(mechanism.getAddress(), "UTF-8");
        String telephone = URLEncoder.encode(mechanism.getTelephone(), "UTF-8");
        String introduce = URLEncoder.encode(mechanism.getIntroduce(), "UTF-8");
        String jd = URLEncoder.encode(mechanism.getJd(), "UTF-8");
        String x = URLEncoder.encode(mechanism.getX(), "UTF-8");
        String wd = URLEncoder.encode(mechanism.getWd(), "UTF-8");
        String gd = URLEncoder.encode(mechanism.getGd(), "UTF-8");
        String tpurl = URLEncoder.encode(mechanism.getTpurl(), "UTF-8");
        String websiteurl = URLEncoder.encode(mechanism.getWebsiteurl(), "UTF-8");
        String type = URLEncoder.encode(mechanism.getType(), "UTF-8");
        String mtype = URLEncoder.encode(mechanism.getMtype(), "UTF-8");
        String loutype = URLEncoder.encode(mechanism.getLoutype(), "UTF-8");
        String xtype = URLEncoder.encode(mechanism.getXtype(), "UTF-8");
        String heading = URLEncoder.encode(mechanism.getHeading(), "UTF-8");
        String pitch = URLEncoder.encode(mechanism.getPitch(), "UTF-8");
        String roll = URLEncoder.encode(mechanism.getRoll(), "UTF-8");
        String videourl = URLEncoder.encode(mechanism.getVideourl(), "UTF-8");
        String content = url + "?methods=" + gotos + "&mechanismname=" + mechanismname + "&address=" + address +
            "&telephone=" + telephone +
            "&introduce=" + introduce +
            "&jd=" + jd +
            "&x=" + x +
            "&wd=" + wd +
            "&gd=" + gd +
            "&tpurl=" + tpurl +
            "&websiteurl=" + websiteurl +
            "&type=" + type +
            "&mtype=" + mtype +
            "&loutype=" + loutype +
            "&xtype=" + xtype +
            "&heading=" + heading +
            "&pitch=" + pitch +
            "&roll=" + roll +
            "&addressName=" + addressName +
            "&videourl=" + videourl;
        //生成标注二维码
        byte[] qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350);
        String encode = new BASE64Encoder().encode(qrCodeImage);
        //设置二维码
        String a = "data:image/png;base64," + encode;
        mechanism.setCodeurl(a);
        return R.status(mechanismService.save(mechanism));
    }
 
    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入mechanism")
    public R update(@Valid @RequestBody Mechanism mechanism) {
        return R.status(mechanismService.updateById(mechanism));
    }
 
    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入mechanism")
    public R submit(@Valid @RequestBody Mechanism mechanism) {
        return R.status(mechanismService.saveOrUpdate(mechanism));
    }
 
 
    /**
     * 删除
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(mechanismService.removeByIds(Func.toLongList(ids)));
    }
 
 
}