AuthTemplateApi.java 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package com.caimei.controller.admin.auth;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.vo.TemplateVo;
  5. import com.caimei.service.auth.AuthTemplateService;
  6. import com.github.pagehelper.PageInfo;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiImplicitParam;
  9. import io.swagger.annotations.ApiImplicitParams;
  10. import io.swagger.annotations.ApiOperation;
  11. import lombok.RequiredArgsConstructor;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.web.bind.annotation.*;
  15. /**
  16. * 授权牌模板API
  17. * @author Aslee
  18. * @date 2022/7/6
  19. */
  20. @Api(tags = "授权牌模板API")
  21. @Slf4j
  22. @RestController
  23. @RequiredArgsConstructor
  24. @RequestMapping("/auth/template")
  25. public class AuthTemplateApi {
  26. private final AuthTemplateService authTemplateService;
  27. @ApiOperation("授权牌模板列表")
  28. @ApiImplicitParams({
  29. @ApiImplicitParam(name = "listType", required = true, value = "列表类型:1管理员列表,2供应商列表"),
  30. @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"),
  31. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  32. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  33. })
  34. @GetMapping("/list")
  35. public ResponseJson<PageInfo<TemplateVo>> getTemplateList(Integer listType, Integer authUserId,
  36. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  37. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  38. return authTemplateService.getTemplateList(listType, authUserId, pageNum, pageSize);
  39. }
  40. @ApiOperation("授权牌模板表单")
  41. @ApiImplicitParams({
  42. @ApiImplicitParam(name = "templateId", required = false, value = "模板id"),
  43. @ApiImplicitParam(name = "authId", required = false, value = "机构id"),
  44. @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"),
  45. @ApiImplicitParam(name = "authFlag", required = false, value = "是否作为机构授权牌模板:1是0否"),
  46. @ApiImplicitParam(name = "status", required = false, value = "启用状态:0停用,1启用")
  47. })
  48. @GetMapping("/form/data")
  49. public ResponseJson<TemplateVo> getTemplateFormData(Integer templateId, Integer authId, Integer authUserId, Integer authFlag, Integer status) {
  50. if (null == templateId && null == authId && null == authUserId) {
  51. return ResponseJson.error("参数异常", null);
  52. }
  53. return authTemplateService.getTemplateFormData(templateId, authId, authUserId, authFlag, status);
  54. }
  55. @ApiOperation("添加/编辑授权模板")
  56. @ApiImplicitParam(name = "params", required = true, value = "templateId:模板id;templateImage:模板图片;" +
  57. "authUserId:供应商用户id;status:状态:1启用,0停用;qrPosition:二维码位置;qrSize:二维码尺寸;" +
  58. "logoSize:logo尺寸;authFlag:1设置为机构授权牌模板;productFlag:1设置为设备授权牌模板")
  59. @PostMapping("/save")
  60. public ResponseJson saveTemplate(@RequestBody String params){
  61. JSONObject parseObject = JSONObject.parseObject(params);
  62. Integer templateId = parseObject.getInteger("templateId");
  63. String templateImage = parseObject.getString("templateImage");
  64. Integer authUserId = parseObject.getInteger("authUserId");
  65. Integer status = parseObject.getInteger("status");
  66. String qrPosition = parseObject.getString("qrPosition");
  67. Integer qrSize = parseObject.getInteger("qrSize");
  68. String logoSize = parseObject.getString("logoSize");
  69. Integer authFlag = parseObject.getInteger("authFlag");
  70. Integer productFlag = parseObject.getInteger("productFlag");
  71. if (null != templateId) {
  72. if ((null != authFlag || null != productFlag) && null == authUserId) {
  73. return ResponseJson.error("供应商用户id不能为空");
  74. }
  75. } else {
  76. if (StringUtils.isEmpty(templateImage)) {
  77. return ResponseJson.error("模板图片不能为空");
  78. }
  79. }
  80. return authTemplateService.saveTemplate(templateId, templateImage, authUserId, status, qrPosition, qrSize, logoSize, authFlag, productFlag);
  81. }
  82. }