| | |
| | | package com.panzhihua.shop_backstage.api; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.common.constants.FtpConstants; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.model.dtos.shop.ComShopGoodsDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | |
| | | import com.panzhihua.common.model.vos.shop.ComShopOrderSearchVO; |
| | | import com.panzhihua.common.model.vos.shop.ShopStoreVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.utlis.ClazzUtils; |
| | | import com.panzhihua.common.utlis.SFTPUtil; |
| | | import com.panzhihua.common.validated.PageGroup; |
| | | import com.panzhihua.common.interfaces.ShopOperLog; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * @ClasssName GoodsApi 商品API |
| | |
| | | |
| | | @Resource |
| | | private CommunityService communityService; |
| | | // FTP 登录用户名 |
| | | @Value("${ftp.username}") |
| | | private String userName; |
| | | // FTP 登录密码 |
| | | @Value("${ftp.password}") |
| | | private String password; |
| | | // FTP 服务器地址IP地址 |
| | | @Value("${ftp.host}") |
| | | private String host; |
| | | // FTP 端口 |
| | | @Value("${ftp.port}") |
| | | private int port; |
| | | @Value("${ftp.url}") |
| | | private String url; |
| | | |
| | | @ApiOperation(value = "商品分页搜索", response = ComShopGoodsVO.class) |
| | | @PostMapping("/page") |
| | | public R search(@RequestBody @Validated(PageGroup.class) ComShopGoodsDTO comShopGoodsDTO){ |
| | | R<ShopStoreVO> storeInfoR = communityService.getUserStoreInfo(getUserId()); |
| | | ShopStoreVO shopStoreVO = storeInfoR.getData(); |
| | | if(shopStoreVO==null){ |
| | | return R.fail("用户无关联店铺"); |
| | | if(R.isOk(storeInfoR)) { |
| | | ShopStoreVO shopStoreVO = JSONObject.parseObject(JSONObject.toJSONString(storeInfoR.getData()), ShopStoreVO.class); |
| | | if (shopStoreVO == null) { |
| | | return R.fail("用户无关联店铺"); |
| | | } |
| | | comShopGoodsDTO.setStoreId(shopStoreVO.getId()); |
| | | ClazzUtils.setIfStringIsEmpty(comShopGoodsDTO); |
| | | return communityService.pageShopGoods(comShopGoodsDTO); |
| | | }else{ |
| | | return R.fail(); |
| | | } |
| | | comShopGoodsDTO.setStoreId(shopStoreVO.getId()); |
| | | return communityService.pageShopGoods(comShopGoodsDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "添加商品") |
| | |
| | | @PostMapping("/add") |
| | | public R search(@RequestBody AddShopGoodsVO addShopGoodsVO){ |
| | | R<ShopStoreVO> storeInofR = communityService.getUserStoreInfo(getUserId()); |
| | | ShopStoreVO shopStoreVO = storeInofR.getData(); |
| | | addShopGoodsVO.setStoreId(shopStoreVO.getId()); |
| | | addShopGoodsVO.setName(shopStoreVO.getName()); |
| | | return communityService.saveShopGoods(addShopGoodsVO); |
| | | |
| | | if(R.isOk(storeInofR)) { |
| | | ShopStoreVO shopStoreVO = JSONObject.parseObject(JSONObject.toJSONString(storeInofR.getData()), ShopStoreVO.class); |
| | | if (shopStoreVO == null) { |
| | | return R.fail("用户无关联店铺"); |
| | | } |
| | | addShopGoodsVO.setStoreId(shopStoreVO.getId()); |
| | | addShopGoodsVO.setName(shopStoreVO.getName()); |
| | | return communityService.saveShopGoods(addShopGoodsVO); |
| | | }else{ |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "编辑商品") |
| | |
| | | return communityService.deleteShopGoods(id); |
| | | } |
| | | |
| | | @ApiOperation(value = "上传图片") |
| | | @PostMapping(value = "uploadimage", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImage(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | String name = file.getOriginalFilename(); |
| | | List<String> formateList = Arrays.asList( |
| | | "avi", "flv", "mpg", "mpeg", "mpe", "m1v", "m2v", "mpv2", "mp2v", "dat", "ts", "tp", "tpr", "pva", "pss", "mp4", "m4v", |
| | | "m4p", "m4b", "3gp", "3gpp", "3g2", "3gp2", "ogg", "mov", "qt", "amr", "rm", "ram", "rmvb", "rpm"); |
| | | String nameStr = name.split("\\.")[1]; |
| | | if (formateList.contains(nameStr)) { |
| | | name = UUID.randomUUID().toString().replaceAll("-", "") + ".mp4"; |
| | | } else { |
| | | name = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg"; |
| | | } |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | InputStream is = file.getInputStream(); |
| | | sftp.uploadMore(FtpConstants.FTPFILEPATH_IDCARD, name, is); |
| | | sftp.logout(); |
| | | return R.ok(url + "/idcard/" + name); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | |
| | | } |
| | | } |