package com.caimei.controller.auth; import com.alibaba.fastjson.JSONObject; import com.caimei.model.ResponseJson; import com.caimei.model.dto.ProductSaveDto; import com.caimei.model.vo.ProductFormVo; import com.caimei.model.vo.ProductListVo; import com.caimei.model.vo.ProductTypeListVo; import com.caimei.service.auth.AuthProductService; 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.*; import java.io.IOException; import java.util.List; import java.util.Map; /** * 授权商品API * @author Aslee * @date 2021/5/17 */ @Api(tags = "认证商品API") @Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/auth/product") public class AuthProductApi { private final AuthProductService authProductService; /** * 授权商品列表 */ @ApiOperation("授权商品列表") @ApiImplicitParams({ @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1商品列表,2管理员商品审核列表,3供应商商品审核列表"), @ApiImplicitParam(name = "authId", required = true, value = "授权id"), @ApiImplicitParam(name = "productName", required = false, value = "商品名称"), @ApiImplicitParam(name = "snCode", required = false, value = "商品SN码"), @ApiImplicitParam(name = "status", required = false, value = "上线状态:0下线,1上线,2待上线"), @ApiImplicitParam(name = "auditStatus", required = false, value = "审核状态:0审核未通过,1审核通过,2待审核"), @ApiImplicitParam(name = "shopAuditStatus", required = false, value = "供应商审核状态:0未审核,1已审核"), @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"), @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条") }) @GetMapping("/list") public ResponseJson> getProductList(Integer listType, Integer authId, String productName, String snCode, Integer status, Integer auditStatus, Integer shopAuditStatus, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { return authProductService.getProductList(listType, authId, productName, snCode, status, auditStatus, shopAuditStatus, pageNum, pageSize); } /** * 更新授权商品状态 */ @ApiOperation("更新授权商品状态") @ApiImplicitParam(name = "params", value = "productId:授权商品id;status:上线状态:0已下线,1已上线,2待上线", required = true) @PostMapping("/update/status") public ResponseJson updateProductStatus(@RequestBody Map params) { Integer productId = params.get("productId"); Integer status = params.get("status"); return authProductService.updateProductStatus(productId, status); } /** * 删除授权商品 */ @ApiOperation("删除授权商品") @ApiImplicitParam(name = "params", value = "productId:授权商品id", required = true) @PostMapping("/delete") public ResponseJson deleteProduct(@RequestBody Map params) { Integer productId = params.get("productId"); return authProductService.deleteProduct(productId); } /** * 添加/编辑授权商品 * @param productSaveDto { * productId 授权商品id * authId 授权id * brandId 品牌id * productTypeId 设备分类id * snCode 商品SN码 * productImage 商品图片 * certificateImage 授权牌照 * addQrCodeFlag 是否生成二维码授权牌:0否,1是 * addTemplateType 生成二维码授权牌模板:1左下,2右边,3左边 * purchaseWay 购买渠道 * invoiceImage 发票图片 * status 上线状态:0已下线,1已上线,2待上线 * createBy 创建人id * paramList 商品参数列表 * } */ @ApiOperation("添加/编辑授权商品") @PostMapping("/save") public ResponseJson saveProduct(@RequestBody ProductSaveDto productSaveDto) throws IOException { return authProductService.saveProduct(productSaveDto, false, 1); } /** * 获取授权商品回显数据 * * @param productId 授权商品id * @return ProductFormVo */ @ApiOperation("授权商品回显数据") @ApiImplicitParam(name = "productId", required = true, value = "授权商品id") @GetMapping("/form/data") public ResponseJson getProductFormData(Integer productId) { return authProductService.getProductFormData(productId); } /** * 更新所有商品的水印图片 */ @ApiOperation("更新所有商品的水印图片") @PostMapping("/update/all/watermark") public ResponseJson updateAllWatermark(){ return authProductService.updateAllWaterMark(); } /** * 审核商品 */ @ApiOperation("审核商品") @ApiImplicitParam(name = "params", value = "productId:授权商品id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;" + "invalidReason:审核不通过原因;auditBy:审核人用户id;source:来源:1管理员审核,2供应商审核", required = true) @PostMapping("/audit") public ResponseJson auditProduct(@RequestBody String params) { JSONObject paramsMap = JSONObject.parseObject(params); Integer productId = paramsMap.getInteger("productId"); Integer auditStatus = paramsMap.getInteger("auditStatus"); String invalidReason = paramsMap.getString("invalidReason"); Integer auditBy = paramsMap.getInteger("auditBy"); Integer source = paramsMap.getInteger("source"); return authProductService.auditProduct(productId, auditStatus, invalidReason, auditBy, source); } @ApiOperation("添加/编辑设备分类") @ApiImplicitParam(name = "params", value = "productTypeId:设备分类id;authUserId:供应商用户id;name:设备分类名称;image:图片;createBy:创建人用户id;", required = true) @PostMapping("/type/save") public ResponseJson saveProductType(@RequestBody String params) throws IOException { JSONObject paramsMap = JSONObject.parseObject(params); Integer productTypeId = paramsMap.getInteger("productTypeId"); Integer authUserId = paramsMap.getInteger("authUserId"); String name = paramsMap.getString("name"); String image = paramsMap.getString("image"); Integer createBy = paramsMap.getInteger("createBy"); if (null == authUserId) { return ResponseJson.error("参数异常,供应商用户id不能为空"); } if (StringUtils.isEmpty(name)) { return ResponseJson.error("参数异常,设备分类名称不能为空"); } if (StringUtils.isEmpty(image)) { return ResponseJson.error("参数异常,图片不能为空"); } return authProductService.saveProductType(productTypeId, authUserId, name, image, createBy); } @ApiOperation("删除设备分类") @ApiImplicitParam(name = "params", value = "productTypeId:设备分类id", required = true) @PostMapping("/type/delete") public ResponseJson deleteProductType(@RequestBody Map params) { Integer productTypeId = params.get("productTypeId"); if (null == productTypeId) { return ResponseJson.error("参数异常,设备分类id不能为空"); } return authProductService.deleteProductType(productTypeId); } @ApiOperation("更新设备分类状态") @ApiImplicitParam(name = "params", value = "productTypeId:设备分类id;status:上线状态:0已下线,1已上线,2待上线", required = true) @PostMapping("/type/update/status") public ResponseJson updateProductTypeStatus(@RequestBody Map params) { Integer productTypeId = params.get("productTypeId"); Integer status = params.get("status"); if (productTypeId == null) { return ResponseJson.error("请输入设备分类id"); } if (status == null) { return ResponseJson.error("请输入要更新的状态值"); } else if (status != 0 && status != 1) { return ResponseJson.error("状态值只能为0或1"); } return authProductService.updateProductTypeStatus(productTypeId, status); } @ApiOperation("设备分类列表") @ApiImplicitParams({ @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1设备分类列表,2设备分类审核列表"), @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"), @ApiImplicitParam(name = "name", required = false, value = "设备分类名称"), @ApiImplicitParam(name = "status", required = false, value = "上线状态:0下线,1上线,2待上线"), @ApiImplicitParam(name = "auditStatus", required = false, value = "审核状态:0审核未通过,1审核通过,2待审核"), @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"), @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条") }) @GetMapping("/type/list") public ResponseJson> getProductTypeList(Integer listType, Integer authUserId, String name, Integer status, Integer auditStatus, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { if (null == authUserId) { return ResponseJson.error("参数异常,供应商用户id不能为空", null); } return authProductService.getProductTypeList(listType, authUserId, name, status, auditStatus, pageNum, pageSize); } @ApiOperation("设备分类下拉框列表") @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id") @GetMapping("/type/select") public ResponseJson> getProductTypeSelectList(Integer authUserId) { if (null == authUserId) { return ResponseJson.error("参数异常,供应商用户id不能为空", null); } return authProductService.getProductTypeSelectList(authUserId); } @ApiOperation("审核设备分类") @ApiImplicitParam(name = "params", value = "productTypeId:设备分类id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;invalidReason:审核不通过原因;auditBy:审核人用户id", required = true) @PostMapping("/type/audit") public ResponseJson auditProductType(@RequestBody String params) { JSONObject paramsMap = JSONObject.parseObject(params); Integer productTypeId = paramsMap.getInteger("productTypeId"); Integer auditStatus = paramsMap.getInteger("auditStatus"); String invalidReason = paramsMap.getString("invalidReason"); Integer auditBy = paramsMap.getInteger("auditBy"); if (productTypeId == null) { return ResponseJson.error("请输入商品id"); } if (auditStatus == null) { return ResponseJson.error("请输入审核结果"); } if (auditStatus == 0 && StringUtils.isEmpty(invalidReason)) { return ResponseJson.error("请输入审核不通过的原因"); } if (auditBy == null) { return ResponseJson.error("请输入审核人用户id"); } return authProductService.auditProductType(productTypeId, auditStatus, invalidReason, auditBy); } }