package com.caimei.controller.admin.auth; import com.alibaba.fastjson.JSONObject; import com.caimei.model.ResponseJson; import com.caimei.model.vo.TemplateVo; import com.caimei.service.auth.AuthTemplateService; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.*; /** * 授权牌模板API * @author Aslee * @date 2022/7/6 */ @Api(tags = "授权牌模板API") @Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/auth/template") public class AuthTemplateApi { private final AuthTemplateService authTemplateService; @ApiOperation("授权牌模板列表") @ApiImplicitParams({ @ApiImplicitParam(name = "listType", required = true, value = "列表类型:1管理员列表,2供应商列表"), @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"), @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"), @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条") }) @GetMapping("/list") public ResponseJson> getTemplateList(Integer listType, Integer authUserId, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { return authTemplateService.getTemplateList(listType, authUserId, pageNum, pageSize); } @ApiOperation("授权牌模板表单") @ApiImplicitParams({ @ApiImplicitParam(name = "templateId", required = false, value = "模板id"), @ApiImplicitParam(name = "authId", required = false, value = "机构id"), @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"), @ApiImplicitParam(name = "authFlag", required = false, value = "是否作为机构授权牌模板:1是0否"), @ApiImplicitParam(name = "status", required = false, value = "启用状态:0停用,1启用") }) @GetMapping("/form/data") public ResponseJson getTemplateFormData(Integer templateId, Integer authId, Integer authUserId, Integer authFlag, Integer status) { if (null == templateId && null == authId && null == authUserId) { return ResponseJson.error("参数异常", null); } return authTemplateService.getTemplateFormData(templateId, authId, authUserId, authFlag, status); } @ApiOperation("添加/编辑授权模板") @ApiImplicitParam(name = "params", required = true, value = "templateId:模板id;templateImage:模板图片;" + "authUserId:供应商用户id;status:状态:1启用,0停用;qrPosition:二维码位置;qrSize:二维码尺寸;" + "logoSize:logo尺寸;authFlag:1设置为机构授权牌模板;productFlag:1设置为设备授权牌模板") @PostMapping("/save") public ResponseJson saveTemplate(@RequestBody String params){ JSONObject parseObject = JSONObject.parseObject(params); Integer templateId = parseObject.getInteger("templateId"); String templateImage = parseObject.getString("templateImage"); Integer authUserId = parseObject.getInteger("authUserId"); Integer status = parseObject.getInteger("status"); String qrPosition = parseObject.getString("qrPosition"); Integer qrSize = parseObject.getInteger("qrSize"); String logoSize = parseObject.getString("logoSize"); Integer authFlag = parseObject.getInteger("authFlag"); Integer productFlag = parseObject.getInteger("productFlag"); if (null != templateId) { if ((null != authFlag || null != productFlag) && null == authUserId) { return ResponseJson.error("供应商用户id不能为空"); } } else { if (StringUtils.isEmpty(templateImage)) { return ResponseJson.error("模板图片不能为空"); } } return authTemplateService.saveTemplate(templateId, templateImage, authUserId, status, qrPosition, qrSize, logoSize, authFlag, productFlag); } }