xiaoyong931011
2023-08-16 46dba54a3ce059624df67c97a29e2cc5c25fdc76
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package cc.mrbird.febs.dapp.controller;
 
 
import cc.mrbird.febs.common.annotation.ControllerEndpoint;
import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.utils.OssUtils;
import cc.mrbird.febs.dapp.dto.AddMallGoodsDto;
import cc.mrbird.febs.dapp.dto.HlmBasicPerkDto;
import cc.mrbird.febs.dapp.dto.MallGoodsUpdateDto;
import cc.mrbird.febs.dapp.dto.MallOrderInfoDto;
import cc.mrbird.febs.dapp.entity.MallGoods;
import cc.mrbird.febs.dapp.entity.MallGoodsCategory;
import cc.mrbird.febs.dapp.entity.MallOrderInfo;
import cc.mrbird.febs.dapp.entity.PlatformBanner;
import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum;
import cc.mrbird.febs.dapp.service.IAdminMallGoodsService;
import cc.mrbird.febs.dapp.vo.AdminMallGoodsCategoryTreeVo;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;
 
import javax.imageio.ImageIO;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/admin/goods")
public class AdminMallGoodsController extends BaseController {
 
    private final IAdminMallGoodsService adminMallGoodsService;
 
    /**
     * 商品分类-选择
     */
    @GetMapping("categorys/tree")
    @ControllerEndpoint(exceptionMessage = "获取分类失败")
    public List<AdminMallGoodsCategoryTreeVo> getParentCategorys(){
        return adminMallGoodsService.getParentCategorys();
    }
 
    /**
     * 商品分类列表
     * @param mallGoodsCategory
     * @param request
     * @return
     */
    @GetMapping("categoryList")
    public FebsResponse getCategoryList(MallGoodsCategory mallGoodsCategory, QueryRequest request) {
        Map<String, Object> data = getDataTable(adminMallGoodsService.getCategoryList(mallGoodsCategory, request));
        return new FebsResponse().success().data(data);
    }
 
    /**
     * 商品分类-新增
     */
    @PostMapping("addCategory")
    @ControllerEndpoint(operation = " 商品分类-新增", exceptionMessage = "操作失败")
    public FebsResponse addCategory(@Valid MallGoodsCategory mallGoodsCategory) {
        return adminMallGoodsService.addCategory(mallGoodsCategory);
    }
 
    /**
     * 商品分类-编辑
     */
    @PostMapping("updateCategory")
    @ControllerEndpoint(operation = " 商品分类-编辑", exceptionMessage = "操作失败")
    public FebsResponse updateCategory(@Valid MallGoodsCategory mallGoodsCategory) {
        return adminMallGoodsService.updateCategory(mallGoodsCategory);
    }
 
    /**
     * 商品分类-删除
     */
    @GetMapping("delCategary/{id}")
    @ControllerEndpoint(operation = " 商品分类-删除", exceptionMessage = "操作失败")
    public FebsResponse delCategary(@NotNull(message = "{required}") @PathVariable Long id) {
        return adminMallGoodsService.delCategary(id);
    }
 
    /**
     *  图片上传
     * @return
     */
    @PostMapping(value = "/uploadFileBase64")
    @ControllerEndpoint(operation = "图片上传", exceptionMessage = "上传失败")
    public Map<String,Object> uploadFileBase64(@RequestBody @Validated MultipartFile file) {
        if (file.isEmpty()) {
            new FebsResponse().message("上传文件为空");
        }
        String base64EncoderImg = "";
        BASE64Encoder base64Encoder =new BASE64Encoder();
        List<String> imageFuffixStr = StrUtil.splitTrim(file.getOriginalFilename(), ".");
        String imageFuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        if("jpg".equals(imageFuffixStr.get(1))){
            try {
                //输出到BufferedImage
                BufferedImage bufferedImage = Thumbnails.of(file.getInputStream())
                        // 图片大小(长宽)压缩比例 从0-1,1表示原图
                        .scale(1f)
                        // 图片质量压缩比例 从0-1,越接近1质量越好
                        .outputQuality(0.5f)
                        .asBufferedImage();
                //对内存中的图片文件进行Base64处理
                ByteArrayOutputStream newBaos = new ByteArrayOutputStream();//io流
                ImageIO.write(bufferedImage, "jpg", newBaos);//写入流中
                byte[] bytes = newBaos.toByteArray();//转换成字节
                base64EncoderImg = base64Encoder.encode(bytes);
//            base64EncoderImg = URLEncoder.encode(new BASE64Encoder().encode(bytes), "UTF-8");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else{
            try {
                base64EncoderImg = base64Encoder.encode(file.getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //文件加密
//        String imageFuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
//      String imageFuffix = ".png";
        String imageNames = System.currentTimeMillis() + IdUtil.simpleUUID() + imageFuffix;
        String imageName = "uploadeFile/" + imageNames;
        OssUtils.uploadFileWithBase64(base64EncoderImg, imageName);
        String bucket_name ="https://excoin.oss-cn-hangzhou.aliyuncs.com";
        String url = bucket_name + "/" + imageName;
 
        Map<String,Object> map = new HashMap<String,Object>();
        Map<String,Object> map2 = new HashMap<String,Object>();
        map.put("code",0);//0表示成功,1失败
        map.put("msg","上传成功");//提示消息
        map.put("data",map2);
        map2.put("src",url);//图片url
        map2.put("title",imageNames);//图片名称,这个会显示在输入框里
        return map;
    }
    /**
     * 商品列表
     * @param mallGoods
     * @param request
     * @return
     */
    @GetMapping("goodsList")
    public FebsResponse getGoodsList(MallGoods mallGoods, QueryRequest request) {
        Map<String, Object> data = getDataTable(adminMallGoodsService.getCategoryListInPage(mallGoods, request));
        return new FebsResponse().success().data(data);
    }
    /**
     * 商品-新增
     */
    @PostMapping("addMallGoods")
    @ControllerEndpoint(operation = " 商品-新增", exceptionMessage = "新增失败")
    public FebsResponse addMallGoods(@RequestBody @Valid AddMallGoodsDto addMallGoodsDto) {
        return adminMallGoodsService.addMallGoods(addMallGoodsDto);
    }
    /**
     * 商品-上架
     */
    @GetMapping("upMallGoods/{id}")
    @ControllerEndpoint(operation = " 商品-上架", exceptionMessage = "上架失败")
    public FebsResponse upMallGoods(@NotNull(message = "{required}") @PathVariable Long id) {
        return adminMallGoodsService.upMallGoods(id);
    }
    /**
     * 商品-下架
     */
    @GetMapping("downMallGoods/{id}")
    @ControllerEndpoint(operation = " 商品-下架", exceptionMessage = "下架失败")
    public FebsResponse downMallGoods(@NotNull(message = "{required}") @PathVariable Long id) {
        return adminMallGoodsService.downMallGoods(id);
    }
    /**
     * 商品-删除
     */
    @GetMapping("delMallGoods/{id}")
    @ControllerEndpoint(operation = " 商品-删除", exceptionMessage = "删除失败")
    public FebsResponse delMallGoods(@NotNull(message = "{required}") @PathVariable Long id) {
        return adminMallGoodsService.delMallGoods(id);
    }
    /**
     * 商品-编辑
     */
    @PostMapping("updateMallGoods")
    @ControllerEndpoint(operation = "商品-编辑", exceptionMessage = "操作失败")
    public FebsResponse updateMallGoods(@RequestBody @Valid MallGoodsUpdateDto mallGoodsUpdateDto) {
        return adminMallGoodsService.updateMallGoods(mallGoodsUpdateDto);
    }
    /**
     * 订单列表
     *
     * @param mallOrderInfo
     * @param request
     * @return
     */
    @GetMapping("orderList")
    public FebsResponse getOrderList(MallOrderInfoDto mallOrderInfo, QueryRequest request) {
        Map<String, Object> data = getDataTable(adminMallGoodsService.getOrderListInPage(mallOrderInfo, request));
        return new FebsResponse().success().data(data);
    }
    /**
     * 订单列表-资金流水
     */
    @GetMapping("/orderMoneyFlow")
    public FebsResponse orderMoneyFlow(QueryRequest request, MallOrderInfo mallOrderInfo, Integer parentId) {
        if (parentId == null) {
            ViewAdminMallGoodsController.idOrderMoneyFlow = 0;
        }
        mallOrderInfo.setId(ViewAdminMallGoodsController.idOrderMoneyFlow);
        Map<String, Object> dataTable = getDataTable(adminMallGoodsService.orderMoneyFlow(request, mallOrderInfo));
        return new FebsResponse().success().data(dataTable);
    }
 
    @GetMapping(value = "/findDicByType/{type}")
    public FebsResponse findDicByType(@PathVariable("type") String type) {
        return new FebsResponse().success().data(adminMallGoodsService.findDataDicByType(type));
    }
 
    @PostMapping(value = "/bonusSystemSetting")
    public FebsResponse bonusSystemSetting(@RequestBody Map<String, Object> map) {
        adminMallGoodsService.bonusSystemSetting(map);
        return new FebsResponse().success().message("设置成功");
    }
 
    @PostMapping(value = "/hlmBasicPerk")
    public FebsResponse hlmBasicPerk(HlmBasicPerkDto hlmBasicPerkDto) {
        adminMallGoodsService.hlmBasicPerk(hlmBasicPerkDto);
        return new FebsResponse().success();
    }
 
 
 
    /**
     * 轮播图---列表
     */
    @GetMapping("platformBanner")
    public FebsResponse platformBanner(PlatformBanner platformBannerEntity, QueryRequest request) {
        Map<String, Object> data = getDataTable(adminMallGoodsService.findPlatformBannerInPage(platformBannerEntity, request));
        return new FebsResponse().success().data(data);
    }
 
    /**
     * 轮播图---确认
     * @return
     */
    @PostMapping("platformBannerConfirm")
    @ControllerEndpoint(operation = "轮播图---确认", exceptionMessage = "设置失败")
    public FebsResponse platformBannerConfirm(@Valid PlatformBanner platformBannerEntity) {
        return adminMallGoodsService.platformBannerConfirm(platformBannerEntity);
    }
 
    /**
     * 轮播图---删除
     * @return
     */
    @GetMapping("platformBannerDelete/{id}")
    @ControllerEndpoint(operation = "轮播图---删除", exceptionMessage = "删除失败")
    public FebsResponse platformBannerDelete(@NotNull(message = "{required}") @PathVariable Long id) {
        return adminMallGoodsService.platformBannerDelete(id);
    }
 
    /**
     * 轮播图---新增
     */
    @PostMapping("platformBannerAdds")
    @ControllerEndpoint(operation = "轮播图---新增", exceptionMessage = "新增失败")
    public FebsResponse platformBannerAdds(@Valid PlatformBanner platformBannerEntity) {
        adminMallGoodsService.platformBannerAdd(platformBannerEntity);
        return new FebsResponse().success();
    }
 
 
 
}