ShopApi.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. package com.caimei.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.dto.ShopInfoDto;
  5. import com.caimei.model.dto.ShopSaveDto;
  6. import com.caimei.model.po.ShopInfoPo;
  7. import com.caimei.model.vo.*;
  8. import com.caimei.service.ShopService;
  9. import com.github.pagehelper.PageInfo;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiImplicitParam;
  12. import io.swagger.annotations.ApiImplicitParams;
  13. import io.swagger.annotations.ApiOperation;
  14. import lombok.RequiredArgsConstructor;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import java.util.Map;
  22. /**
  23. * 供应商API
  24. *
  25. * @author : Aslee
  26. * @date : 2021/5/11
  27. */
  28. @Api(tags = "供应商API")
  29. @Slf4j
  30. @RestController
  31. @RequiredArgsConstructor
  32. @RequestMapping("/shop")
  33. public class ShopApi {
  34. private final ShopService shopService;
  35. /**
  36. * 供应商列表
  37. */
  38. @ApiOperation("供应商列表")
  39. @ApiImplicitParams({
  40. @ApiImplicitParam(name = "shopName", required = false, value = "供应商名称"),
  41. @ApiImplicitParam(name = "shopType", required = false, value = "供应商类型:1品牌方,2代理商"),
  42. @ApiImplicitParam(name = "brandId", required = false, value = "所属品牌id"),
  43. @ApiImplicitParam(name = "mobile", required = false, value = "手机号"),
  44. @ApiImplicitParam(name = "linkMan", required = false, value = "联系人"),
  45. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  46. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  47. })
  48. @GetMapping("/list")
  49. public ResponseJson<PageInfo<ShopListVo>> getShopList(String shopName, Integer shopType, Integer brandId, String mobile, String linkMan,
  50. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  51. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  52. return shopService.getShopList(shopName, shopType, brandId, mobile, linkMan, pageNum, pageSize);
  53. }
  54. /**
  55. * 获取供应商回显数据
  56. *
  57. * @param authUserId 供应商用户id
  58. * @return ShopFormVo
  59. */
  60. @ApiOperation("供应商回显数据")
  61. @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id")
  62. @GetMapping("/form/data")
  63. public ResponseJson<ShopFormVo> getShopFormData(Integer authUserId) {
  64. return shopService.getShopFormData(authUserId);
  65. }
  66. /**
  67. * 添加供应商
  68. *
  69. * @param params {
  70. * authUserId 供应商用户id
  71. * shopType 供应商类型:1代理商,2品牌方
  72. * shopName 供应商名称
  73. * mobile 手机号
  74. * linkMan 联系人
  75. * shopStatus 供应商状态:0停用 1启用
  76. * createBy 创建人用户id
  77. * shopInfo [
  78. * {
  79. * brandId 品牌id
  80. * countryId 产地国家id
  81. * brandAuthLogo 品牌授权logo
  82. * securityLink 官网认证链接
  83. * statementType 代理声明类型:1弹窗 2链接 3图片 4文件(.doc .ppt .pdf)
  84. * statementContent 声明弹窗内容
  85. * statementLink 声明链接
  86. * statementImage 声明图片
  87. * statementFileId 声明文件id
  88. * }
  89. * ]
  90. * }
  91. */
  92. @ApiOperation("添加/编辑供应商")
  93. @ApiImplicitParam(name = "params", value = "authUserId:供应商用户id;", required = true)
  94. @PostMapping("/save")
  95. public ResponseJson saveShop(@RequestBody String params) {
  96. JSONObject paramsMap = JSONObject.parseObject(params);
  97. Integer authUserId = paramsMap.getInteger("authUserId");
  98. Integer shopType = paramsMap.getInteger("shopType");
  99. if (null == shopType) {
  100. return ResponseJson.error("请选择供应商类型", null);
  101. }
  102. String shopName = paramsMap.getString("shopName");
  103. String mobile = paramsMap.getString("mobile");
  104. if (StringUtils.isBlank(mobile)) {
  105. return ResponseJson.error("参数异常,请输入手机号");
  106. }
  107. String linkMan = paramsMap.getString("linkMan");
  108. if (StringUtils.isBlank(mobile)) {
  109. return ResponseJson.error("参数异常,请输入联系人");
  110. }
  111. Integer shopStatus = paramsMap.getInteger("shopStatus");
  112. if (null == shopStatus) {
  113. return ResponseJson.error("参数异常,请输入供应商状态");
  114. }
  115. Integer createBy = paramsMap.getInteger("createBy");
  116. List<Map<String, Object>> shopInfoData = (List<Map<String, Object>>) paramsMap.get("shopInfo");
  117. if (null == shopInfoData || shopInfoData.size() <= 0) {
  118. return ResponseJson.error("参数异常,请输入供应商信息");
  119. }
  120. List<ShopInfoDto> shopInfoList = new ArrayList<>();
  121. for (Map<String, Object> infoMap : shopInfoData) {
  122. Integer brandId = (Integer) infoMap.get("brandId");
  123. Integer countryId = (Integer) infoMap.get("countryId");
  124. String brandAuthLogo = (String) infoMap.get("brandAuthLogo");
  125. String securityLink = (String) infoMap.get("securityLink");
  126. Integer statementType = (Integer) infoMap.get("statementType");
  127. String statementContent = (String) infoMap.get("statementContent");
  128. String statementLink = (String) infoMap.get("statementLink");
  129. String statementImage = (String) infoMap.get("statementImage");
  130. Integer statementFileId = (Integer) infoMap.get("statementFileId");
  131. if (null == brandId || null == countryId || StringUtils.isEmpty(brandAuthLogo) || null == statementType) {
  132. return ResponseJson.error("参数异常,供应商信息数据异常");
  133. }
  134. ShopInfoDto shopInfo = new ShopInfoDto();
  135. shopInfo.setBrandId(brandId);
  136. shopInfo.setCountryId(countryId);
  137. shopInfo.setBrandAuthLogo(brandAuthLogo);
  138. shopInfo.setSecurityLink(securityLink);
  139. shopInfo.setStatementType(statementType);
  140. shopInfo.setStatementContent(statementContent);
  141. shopInfo.setStatementLink(statementLink);
  142. shopInfo.setStatementImage(statementImage);
  143. shopInfo.setStatementFileId(statementFileId);
  144. shopInfoList.add(shopInfo);
  145. }
  146. return shopService.saveShop(authUserId, shopType, shopName, mobile, linkMan, shopStatus, createBy, shopInfoList);
  147. }
  148. /**
  149. * 更新供应商状态
  150. */
  151. @ApiOperation("更新供应商状态")
  152. @ApiImplicitParam(name = "params", value = "authUserId:供应商用户id;status:供应商状态:0停用 1启用", required = true)
  153. @PostMapping("/update/status")
  154. public ResponseJson updateShopStatus(@RequestBody Map<String,Integer> params) {
  155. Integer authUserId = params.get("authUserId");
  156. Integer status = params.get("status");
  157. return shopService.updateShopStatus(authUserId, status);
  158. }
  159. /**
  160. * 重置密码
  161. */
  162. @ApiOperation("重置密码")
  163. @ApiImplicitParam(name = "params", value = "authUserId:供应商用户id", required = true)
  164. @PostMapping("/reset/password")
  165. public ResponseJson resetShopPassword(@RequestBody Map<String,Integer> params) {
  166. Integer authUserId = params.get("authUserId");
  167. return shopService.resetShopPassword(authUserId);
  168. }
  169. /**
  170. * 代理声明文件上传
  171. *
  172. * @param authUserId:供应商用户id
  173. * @param brandId:品牌id
  174. * @param file:代理声明文件
  175. * @return Integer
  176. */
  177. @ApiOperation("代理声明文件上传")
  178. @ApiImplicitParams({
  179. @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"),
  180. @ApiImplicitParam(name = "brandId", required = false, value = "品牌id"),
  181. @ApiImplicitParam(name = "file", required = false, value = "代理声明文件"),
  182. })
  183. @PostMapping("/upload/file")
  184. public ResponseJson<FileVo> uploadFile(Integer authUserId, Integer brandId, MultipartFile file) {
  185. return shopService.uploadFile(authUserId, brandId, file);
  186. }
  187. /**
  188. * 品牌列表
  189. *
  190. * @param type 1品牌方可用品牌列表,2代理商可用品牌列表,3供应商可用品牌列表
  191. * @return AuthVo
  192. */
  193. @ApiOperation("品牌列表")
  194. @ApiImplicitParams({
  195. @ApiImplicitParam(name = "type", value = "1品牌方品牌列表,2代理商品牌列表,3供应商可用品牌列表", required = true),
  196. @ApiImplicitParam(name = "authUserId", value = "供应商用户id", required = false)
  197. })
  198. @GetMapping("/brand/list")
  199. public ResponseJson<List<BrandVo>> getBrandList(Integer type, Integer authUserId) {
  200. return shopService.getBrandList(type, authUserId);
  201. }
  202. /**
  203. * 产地国家列表
  204. */
  205. @ApiOperation("产地国家列表")
  206. @GetMapping("/country/list")
  207. public ResponseJson<List<CountryVo>> getCountryList(){
  208. return shopService.getCountryList();
  209. }
  210. }