AuthApi.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. package com.caimei.controller.admin.auth;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.annotation.CurrentUser;
  4. import com.caimei.model.ResponseJson;
  5. import com.caimei.model.po.CmBrandAuthPo;
  6. import com.caimei.model.po.SysUser;
  7. import com.caimei.model.vo.AuthFormVo;
  8. import com.caimei.model.vo.AuthVo;
  9. import com.caimei.service.auth.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.apache.commons.lang3.StringUtils;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import java.math.BigDecimal;
  21. import java.text.ParseException;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Date;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * 供应商API
  28. *
  29. * @author : Aslee
  30. * @date : 2021/5/11
  31. */
  32. @Api(tags = "认证机构API")
  33. @Slf4j
  34. @RestController
  35. @RequiredArgsConstructor
  36. @RequestMapping("/auth")
  37. public class AuthApi {
  38. private final AuthService authService;
  39. /**
  40. * 授权列表
  41. */
  42. @ApiOperation("授权列表")
  43. @ApiImplicitParams({
  44. @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1授权列表,2授权审核列表,3供应商审核列表,4授权牌物流列表"),
  45. @ApiImplicitParam(name = "authParty", required = false, value = "授权机构"),
  46. @ApiImplicitParam(name = "mobile", required = false, value = "机构用户手机号"),
  47. @ApiImplicitParam(name = "status", required = false, value = "上线状态:0已下线,1已上线,2待上线"),
  48. @ApiImplicitParam(name = "auditStatus", required = false, value = "审核状态:0审核未通过,1审核通过,2待审核"),
  49. @ApiImplicitParam(name = "lowerAuditStatus", required = false, value = "商品信息审核状态:0未完成审核,1已完成审核"),
  50. @ApiImplicitParam(name = "shopAuditStatus", required = false, value = "供应商审核状态:0未审核,1已审核"),
  51. @ApiImplicitParam(name = "sendStatus", required = false, value = "寄送状态:0未寄送,1已寄送"),
  52. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  53. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  54. })
  55. @GetMapping("/list")
  56. public ResponseJson<PageInfo<AuthVo>> getAuthList(@CurrentUser SysUser sysUser, Integer listType, String authParty, String mobile,
  57. Integer status, Integer auditStatus, Integer lowerAuditStatus,
  58. Integer shopAuditStatus, Integer sendStatus,
  59. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  60. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  61. if (null == sysUser) {
  62. return ResponseJson.error("用户信息异常", null);
  63. }
  64. // 获取供应商用户id
  65. Integer userIdentity = sysUser.getUserIdentity();
  66. Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  67. if (null == authUserId) {
  68. return ResponseJson.error("供应商用户id不能为空", null);
  69. }
  70. return authService.getAuthList(listType, authUserId, authParty, mobile, status, auditStatus, lowerAuditStatus, shopAuditStatus, sendStatus, pageNum, pageSize);
  71. }
  72. @ApiOperation("机构下拉框列表")
  73. @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id")
  74. @GetMapping("/select")
  75. public ResponseJson<List<AuthVo>> getAuthSelectList(@CurrentUser SysUser sysUser) {
  76. if (null == sysUser) {
  77. return ResponseJson.error("用户信息异常", null);
  78. }
  79. // 获取供应商用户id
  80. Integer userIdentity = sysUser.getUserIdentity();
  81. Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  82. if (null == authUserId) {
  83. return ResponseJson.error("供应商用户id不能为空", null);
  84. }
  85. return authService.getAuthSelectList(authUserId);
  86. }
  87. /**
  88. * 更新授权状态
  89. */
  90. @ApiOperation("更新授权状态")
  91. @ApiImplicitParam(name = "params", value = "authId:授权id;status:授权状态:0停用 1启用;", required = true)
  92. @PostMapping("/update/status")
  93. public ResponseJson updateAuthStatus(@RequestBody Map<String, Integer> params) {
  94. Integer authId = params.get("authId");
  95. Integer status = params.get("status");
  96. return authService.updateAuthStatus(authId, status);
  97. }
  98. /**
  99. * 删除授权
  100. */
  101. @ApiOperation("删除授权")
  102. @ApiImplicitParam(name = "params", value = "authId:授权id", required = true)
  103. @PostMapping("/delete")
  104. public ResponseJson deleteAuth(@RequestBody Map<String, Integer> params) {
  105. Integer authId = params.get("authId");
  106. return authService.deleteAuth(authId);
  107. }
  108. /**
  109. * 授权机构回显数据
  110. */
  111. @ApiOperation("授权机构回显数据")
  112. @ApiImplicitParam(name = "authId", required = true, value = "机构用户id")
  113. @GetMapping("/form/data")
  114. public ResponseJson<AuthFormVo> getAuthFormData(Integer authId) {
  115. return authService.getAuthFormData(authId);
  116. }
  117. /**
  118. * 添加/编辑授权
  119. */
  120. @ApiOperation("添加/编辑授权")
  121. @ApiImplicitParam(name = "params", value = "authId:授权id;authParty:授权机构;provinceId;cityId;" +
  122. "townId;address;lngAndLat;mobile;userMobile:对应机构用户手机号;" +
  123. "firstClubType:一级分类为医美=1,生美=2,项目公司=3,个人=4,其他=5;" +
  124. "secondClubType:医美的二级分类为诊所=1、门诊=2、医院=3,其他=4。生美二级分类,美容院=5,养生馆=6,其他=7;" +
  125. "medicalLicenseImage:医疗许可证图;empNum:员工人数;" +
  126. "logo;customFlag:是否需要自定义属性:0否,1是;remarks:店铺备注;createBy:创建人id;source:1供应商保存,2机构保存" +
  127. "linkMan:运营联系人;linkMobile:运营联系人手机号", required = true)
  128. @PostMapping("/save")
  129. public ResponseJson saveAuth(@CurrentUser SysUser sysUser, @RequestBody String params) throws ParseException {
  130. if (null == sysUser) {
  131. return ResponseJson.error("用户信息异常", null);
  132. }
  133. // 获取供应商用户id
  134. Integer userIdentity = sysUser.getUserIdentity();
  135. Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  136. if (null == authUserId) {
  137. return ResponseJson.error("供应商用户id不能为空", null);
  138. }
  139. JSONObject paramsMap = JSONObject.parseObject(params);
  140. Integer authId = paramsMap.getInteger("authId");
  141. Integer provinceId = paramsMap.getInteger("provinceId");
  142. Integer cityId = paramsMap.getInteger("cityId");
  143. Integer townId = paramsMap.getInteger("townId");
  144. String address = paramsMap.getString("address");
  145. String lngAndLat = paramsMap.getString("lngAndLat");
  146. String mobile = paramsMap.getString("mobile");
  147. String userMobile = paramsMap.getString("userMobile");
  148. String linkMan = paramsMap.getString("linkMan");
  149. String linkMobile = paramsMap.getString("linkMobile");
  150. Integer firstClubType = paramsMap.getInteger("firstClubType");
  151. Integer secondClubType = paramsMap.getInteger("secondClubType");
  152. String medicalLicenseImage = paramsMap.getString("medicalLicenseImage");
  153. Integer empNum = paramsMap.getInteger("empNum");
  154. String logo = paramsMap.getString("logo");
  155. String authCode = paramsMap.getString("authCode");
  156. String authDateStr = paramsMap.getString("authDate");
  157. SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
  158. Date authDate = null;
  159. if (StringUtils.isNotEmpty(authDateStr)) {
  160. authDate = format.parse(authDateStr);
  161. }
  162. Integer authImageType = paramsMap.getInteger("authImageType");
  163. String authImageLogo = paramsMap.getString("authImageLogo");
  164. String authImage = paramsMap.getString("authImage");
  165. Integer customFlag = paramsMap.getInteger("customFlag");
  166. String remarks = paramsMap.getString("remarks");
  167. List<String> bannerList = (List<String>) paramsMap.get("bannerList");
  168. String authParty = paramsMap.getString("authParty");
  169. Integer createBy = paramsMap.getInteger("createBy");
  170. Integer source = paramsMap.getInteger("source");
  171. if (null == source) {
  172. // 默认供应商保存
  173. source = 1;
  174. }
  175. /*
  176. 组装授权数据
  177. */
  178. CmBrandAuthPo auth = new CmBrandAuthPo();
  179. auth.setId(authId);
  180. auth.setAuthUserId(authUserId);
  181. auth.setAuthParty(authParty);
  182. auth.setProvinceId(provinceId);
  183. auth.setCityId(cityId);
  184. auth.setTownId(townId);
  185. auth.setAddress(address);
  186. auth.setCustomFlag(customFlag);
  187. auth.setRemarks(remarks);
  188. if (StringUtils.isEmpty(lngAndLat)) {
  189. return ResponseJson.error("参数异常,经纬度不能为空");
  190. }
  191. String[] split = lngAndLat.split(",");
  192. auth.setLng(new BigDecimal(split[0]));
  193. auth.setLat(new BigDecimal(split[1]));
  194. auth.setMobile(mobile);
  195. auth.setUserMobile(userMobile);
  196. auth.setLinkMan(linkMan);
  197. auth.setLinkMobile(linkMobile);
  198. auth.setFirstClubType(firstClubType);
  199. auth.setSecondClubType(secondClubType);
  200. auth.setMedicalLicenseImage(medicalLicenseImage);
  201. auth.setEmpNum(empNum);
  202. auth.setLogo(logo);
  203. auth.setAuthCode(authCode);
  204. auth.setAuthDate(authDate);
  205. auth.setAuthImageLogo(authImageLogo);
  206. auth.setAuthImage(authImage);
  207. auth.setAuthImageType(authImageType);
  208. auth.setCreateBy(createBy);
  209. auth.setCreateSource(1);
  210. return authService.saveAuth(auth, bannerList, false, source);
  211. }
  212. /**
  213. * 审核品牌授权
  214. */
  215. @ApiOperation("审核品牌授权")
  216. @ApiImplicitParam(name = "params", value = "authId:授权id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;" +
  217. "invalidReason:审核不通过原因;auditBy:审核人用户id;source:来源:1管理员审核,2供应商审核", required = true)
  218. @PostMapping("/audit")
  219. public ResponseJson auditAuth(@RequestBody String params) {
  220. JSONObject paramsMap = JSONObject.parseObject(params);
  221. Integer authId = paramsMap.getInteger("authId");
  222. Integer auditStatus = paramsMap.getInteger("auditStatus");
  223. String invalidReason = paramsMap.getString("invalidReason");
  224. Integer auditBy = paramsMap.getInteger("auditBy");
  225. Integer source = paramsMap.getInteger("source");
  226. return authService.auditAuth(authId, auditStatus, invalidReason, auditBy, source);
  227. }
  228. @ApiOperation("excel导入")
  229. @ApiImplicitParams({
  230. @ApiImplicitParam(name = "createBy", required = true, value = "创建人用户id"),
  231. @ApiImplicitParam(name = "file", required = true, value = "机构excel表格"),
  232. })
  233. @PostMapping("/import/excel")
  234. public ResponseJson importDataByExcel(@CurrentUser SysUser sysUser, MultipartFile file, Integer createBy) {
  235. if (null == sysUser) {
  236. return ResponseJson.error("用户信息异常", null);
  237. }
  238. // 获取供应商用户id
  239. Integer userIdentity = sysUser.getUserIdentity();
  240. Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  241. if (null == authUserId) {
  242. return ResponseJson.error("供应商用户id不能为空", null);
  243. }
  244. if (null == createBy) {
  245. return ResponseJson.error("参数异常,请输入创建人id");
  246. }
  247. if (null == file) {
  248. return ResponseJson.error("参数异常,请选择文件");
  249. }
  250. return authService.importDataByExcel(file, authUserId, createBy);
  251. }
  252. @ApiOperation("ldm门店图/备注导入")
  253. @GetMapping("/ldm/image/import")
  254. public ResponseJson importLdmImage(@CurrentUser SysUser sysUser) {
  255. if (null == sysUser) {
  256. return ResponseJson.error("用户信息异常", null);
  257. }
  258. // 获取供应商用户id
  259. Integer userIdentity = sysUser.getUserIdentity();
  260. Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  261. if (null == authUserId) {
  262. return ResponseJson.error("供应商用户id不能为空", null);
  263. }
  264. return authService.importLdmImage(authUserId);
  265. }
  266. @ApiOperation("更改查看标记")
  267. @ApiImplicitParam(name = "authId", required = true, value = "授权机构id")
  268. @PostMapping("/check")
  269. public ResponseJson checkAuth(Integer authId) {
  270. return authService.checkAuth(authId);
  271. }
  272. @ApiOperation("勾选明星机构")
  273. @ApiImplicitParams({
  274. @ApiImplicitParam(name = "authId", required = true, value = "授权机构id"),
  275. @ApiImplicitParam(name = "starFlag", required = true, value = "明星机构标识:0不是,1是")
  276. })
  277. @PostMapping("/star")
  278. public ResponseJson starAuth(Integer authId, Integer starFlag) {
  279. if (null == authId) {
  280. return ResponseJson.error("机构id不能为空");
  281. }
  282. if (null == starFlag) {
  283. return ResponseJson.error("明星机构标识不能为空");
  284. }
  285. return authService.starAuth(authId, starFlag);
  286. }
  287. }