AuthApi.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package com.caimei.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.po.CmBrandAuthPo;
  5. import com.caimei.model.vo.AuthFormVo;
  6. import com.caimei.model.vo.AuthVo;
  7. import com.caimei.model.vo.BrandVo;
  8. import com.caimei.model.vo.ShopFormVo;
  9. import com.caimei.service.AuthService;
  10. import com.github.pagehelper.PageInfo;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiImplicitParam;
  13. import io.swagger.annotations.ApiImplicitParams;
  14. import io.swagger.annotations.ApiOperation;
  15. import lombok.RequiredArgsConstructor;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import javax.servlet.http.HttpServletResponse;
  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("/auth")
  33. public class AuthApi {
  34. private final AuthService authService;
  35. /**
  36. * 授权列表
  37. */
  38. @ApiOperation("授权列表")
  39. @ApiImplicitParams({
  40. @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1授权列表,2授权审核列表"),
  41. @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"),
  42. @ApiImplicitParam(name = "authParty", required = false, value = "授权机构"),
  43. @ApiImplicitParam(name = "status", required = false, value = "上线状态:0已下线,1已上线,2待上线"),
  44. @ApiImplicitParam(name = "auditStatus", required = false, value = "审核状态:0审核未通过,1审核通过,2待审核"),
  45. @ApiImplicitParam(name = "lowerAuditStatus", required = false, value = "商品信息审核状态:0未完成审核,1已完成审核"),
  46. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  47. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  48. })
  49. @GetMapping("/list")
  50. public ResponseJson<PageInfo<AuthVo>> getAuthList(Integer listType, Integer authUserId, String authParty, Integer status, Integer auditStatus, Integer lowerAuditStatus,
  51. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  52. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  53. return authService.getAuthList(listType, authUserId, authParty, status, auditStatus, lowerAuditStatus, pageNum, pageSize);
  54. }
  55. /**
  56. * 更新授权状态
  57. */
  58. @ApiOperation("更新授权状态")
  59. @ApiImplicitParam(name = "params", value = "authId:授权id;status:授权状态:0停用 1启用;", required = true)
  60. @PostMapping("/update/status")
  61. public ResponseJson updateAuthStatus(@RequestBody Map<String,Integer> params) {
  62. Integer authId = params.get("authId");
  63. Integer status = params.get("status");
  64. return authService.updateAuthStatus(authId, status);
  65. }
  66. /**
  67. * 删除授权
  68. */
  69. @ApiOperation("删除授权")
  70. @ApiImplicitParam(name = "params", value = "authId:授权id", required = true)
  71. @PostMapping("/delete")
  72. public ResponseJson deleteAuth(@RequestBody Map<String,Integer> params) {
  73. Integer authId = params.get("authId");
  74. return authService.deleteAuth(authId);
  75. }
  76. /**
  77. * 授权机构回显数据
  78. */
  79. @ApiOperation("授权机构回显数据")
  80. @ApiImplicitParam(name = "authId", required = true, value = "机构用户id")
  81. @GetMapping("/form/data")
  82. public ResponseJson<AuthFormVo> getAuthFormData(Integer authId) {
  83. return authService.getAuthFormData(authId);
  84. }
  85. /**
  86. * 添加/编辑授权
  87. */
  88. @ApiOperation("添加/编辑授权")
  89. @ApiImplicitParam(name = "params", value = "authId:授权id;authUserId:供应商用户id;authParty:授权机构;createBy:创建人id", required = true)
  90. @PostMapping("/save")
  91. public ResponseJson saveAuth(@RequestBody String params) {
  92. JSONObject paramsMap = JSONObject.parseObject(params);
  93. Integer authId = paramsMap.getInteger("authId");
  94. Integer authUserId = paramsMap.getInteger("authUserId");
  95. Integer provinceId = paramsMap.getInteger("provinceId");
  96. Integer cityId = paramsMap.getInteger("cityId");
  97. Integer townId = paramsMap.getInteger("townId");
  98. String address = paramsMap.getString("address");
  99. String lonAndLat = paramsMap.getString("lonAndLat");
  100. String mobile = paramsMap.getString("mobile");
  101. String logo = paramsMap.getString("logo");
  102. List<String> bannerList = (List<String>) paramsMap.get("bannerList");
  103. String authParty = paramsMap.getString("authParty");
  104. Integer createBy = paramsMap.getInteger("createBy");
  105. /*
  106. 组装授权数据
  107. */
  108. CmBrandAuthPo auth = new CmBrandAuthPo();
  109. auth.setId(authId);
  110. auth.setAuthUserId(authUserId);
  111. auth.setAuthParty(authParty);
  112. auth.setProvinceId(provinceId);
  113. auth.setCityId(cityId);
  114. auth.setTownId(townId);
  115. auth.setAddress(address);
  116. auth.setLonAndLat(lonAndLat);
  117. auth.setMobile(mobile);
  118. auth.setLogo(logo);
  119. auth.setCreateBy(createBy);
  120. return authService.saveAuth(auth, bannerList, false);
  121. }
  122. /**
  123. * 审核品牌授权
  124. */
  125. @ApiOperation("审核品牌授权")
  126. @ApiImplicitParam(name = "params", value = "authId:授权id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;invalidReason:审核不通过原因;auditBy:审核人用户id", required = true)
  127. @PostMapping("/audit")
  128. public ResponseJson auditAuth(@RequestBody String params) {
  129. JSONObject paramsMap = JSONObject.parseObject(params);
  130. Integer authId = paramsMap.getInteger("authId");
  131. Integer auditStatus = paramsMap.getInteger("auditStatus");
  132. String invalidReason = paramsMap.getString("invalidReason");
  133. Integer auditBy = paramsMap.getInteger("auditBy");
  134. return authService.auditAuth(authId, auditStatus, invalidReason, auditBy);
  135. }
  136. @ApiOperation("excel导入")
  137. @ApiImplicitParams({
  138. @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"),
  139. @ApiImplicitParam(name = "createBy", required = true, value = "创建人用户id"),
  140. @ApiImplicitParam(name = "file", required = true, value = "代理声明文件"),
  141. })
  142. @PostMapping("/import/excel")
  143. public ResponseJson importDataByExcel(MultipartFile file, Integer authUserId, Integer createBy) {
  144. if (null == authUserId) {
  145. return ResponseJson.error("参数异常,请输入供应商id");
  146. }
  147. if (null == createBy) {
  148. return ResponseJson.error("参数异常,请输入创建人id");
  149. }
  150. if (null == file) {
  151. return ResponseJson.error("参数异常,请选择文件");
  152. }
  153. return authService.importDataByExcel(file, authUserId, createBy);
  154. }
  155. @ApiOperation("excel导出")
  156. @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id")
  157. @GetMapping("/export/excel")
  158. public ResponseJson exportDataByExcel(Integer authUserId, HttpServletResponse response) {
  159. if (null == authUserId) {
  160. return ResponseJson.error("参数异常,请输入供应商id");
  161. }
  162. return authService.exportDataByExcel(authUserId, response);
  163. }
  164. }