package com.caimei.controller.admin.auth; import com.alibaba.fastjson.JSONObject; import com.caimei.annotation.CurrentUser; import com.caimei.model.ResponseJson; import com.caimei.model.po.CmBrandAuthPo; import com.caimei.model.po.SysUser; import com.caimei.model.vo.AuthFormVo; import com.caimei.model.vo.AuthVo; import com.caimei.service.auth.AuthService; 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 org.springframework.web.multipart.MultipartFile; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; /** * 供应商API * * @author : Aslee * @date : 2021/5/11 */ @Api(tags = "认证机构API") @Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/auth") public class AuthApi { private final AuthService authService; /** * 授权列表 */ @ApiOperation("授权列表") @ApiImplicitParams({ @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1授权列表,2授权审核列表,3供应商审核列表,4授权牌物流列表"), @ApiImplicitParam(name = "authParty", required = false, value = "授权机构"), @ApiImplicitParam(name = "mobile", required = false, value = "机构用户手机号"), @ApiImplicitParam(name = "status", required = false, value = "上线状态:0已下线,1已上线,2待上线"), @ApiImplicitParam(name = "auditStatus", required = false, value = "审核状态:0审核未通过,1审核通过,2待审核"), @ApiImplicitParam(name = "lowerAuditStatus", required = false, value = "商品信息审核状态:0未完成审核,1已完成审核"), @ApiImplicitParam(name = "shopAuditStatus", required = false, value = "供应商审核状态:0未审核,1已审核"), @ApiImplicitParam(name = "sendStatus", required = false, value = "寄送状态:0未寄送,1已寄送"), @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"), @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条") }) @GetMapping("/list") public ResponseJson> getAuthList(@CurrentUser SysUser sysUser, Integer listType, String authParty, String mobile, Integer status, Integer auditStatus, Integer lowerAuditStatus, Integer shopAuditStatus, Integer sendStatus, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { if (null == sysUser) { return ResponseJson.error("用户信息异常", null); } // 获取供应商用户id Integer userIdentity = sysUser.getUserIdentity(); Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null; if (null == authUserId) { return ResponseJson.error("供应商用户id不能为空", null); } return authService.getAuthList(listType, authUserId, authParty, mobile, status, auditStatus, lowerAuditStatus, shopAuditStatus, sendStatus, pageNum, pageSize); } @ApiOperation("机构下拉框列表") @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id") @GetMapping("/select") public ResponseJson> getAuthSelectList(@CurrentUser SysUser sysUser) { if (null == sysUser) { return ResponseJson.error("用户信息异常", null); } // 获取供应商用户id Integer userIdentity = sysUser.getUserIdentity(); Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null; if (null == authUserId) { return ResponseJson.error("供应商用户id不能为空", null); } return authService.getAuthSelectList(authUserId); } /** * 更新授权状态 */ @ApiOperation("更新授权状态") @ApiImplicitParam(name = "params", value = "authId:授权id;status:授权状态:0停用 1启用;", required = true) @PostMapping("/update/status") public ResponseJson updateAuthStatus(@RequestBody Map params) { Integer authId = params.get("authId"); Integer status = params.get("status"); return authService.updateAuthStatus(authId, status); } /** * 删除授权 */ @ApiOperation("删除授权") @ApiImplicitParam(name = "params", value = "authId:授权id", required = true) @PostMapping("/delete") public ResponseJson deleteAuth(@RequestBody Map params) { Integer authId = params.get("authId"); return authService.deleteAuth(authId); } /** * 授权机构回显数据 */ @ApiOperation("授权机构回显数据") @ApiImplicitParam(name = "authId", required = true, value = "机构用户id") @GetMapping("/form/data") public ResponseJson getAuthFormData(Integer authId) { return authService.getAuthFormData(authId); } /** * 添加/编辑授权 */ @ApiOperation("添加/编辑授权") @ApiImplicitParam(name = "params", value = "authId:授权id;authParty:授权机构;provinceId;cityId;" + "townId;address;lngAndLat;mobile;userMobile:对应机构用户手机号;" + "firstClubType:一级分类为医美=1,生美=2,项目公司=3,个人=4,其他=5;" + "secondClubType:医美的二级分类为诊所=1、门诊=2、医院=3,其他=4。生美二级分类,美容院=5,养生馆=6,其他=7;" + "medicalLicenseImage:医疗许可证图;empNum:员工人数;" + "logo;customFlag:是否需要自定义属性:0否,1是;remarks:店铺备注;createBy:创建人id;source:1供应商保存,2机构保存" + "linkMan:运营联系人;linkMobile:运营联系人手机号", required = true) @PostMapping("/save") public ResponseJson saveAuth(@CurrentUser SysUser sysUser, @RequestBody String params) throws ParseException { if (null == sysUser) { return ResponseJson.error("用户信息异常", null); } // 获取供应商用户id Integer userIdentity = sysUser.getUserIdentity(); Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null; if (null == authUserId) { return ResponseJson.error("供应商用户id不能为空", null); } JSONObject paramsMap = JSONObject.parseObject(params); Integer authId = paramsMap.getInteger("authId"); Integer provinceId = paramsMap.getInteger("provinceId"); Integer cityId = paramsMap.getInteger("cityId"); Integer townId = paramsMap.getInteger("townId"); String address = paramsMap.getString("address"); String lngAndLat = paramsMap.getString("lngAndLat"); String mobile = paramsMap.getString("mobile"); String userMobile = paramsMap.getString("userMobile"); String linkMan = paramsMap.getString("linkMan"); String linkMobile = paramsMap.getString("linkMobile"); Integer firstClubType = paramsMap.getInteger("firstClubType"); Integer secondClubType = paramsMap.getInteger("secondClubType"); String medicalLicenseImage = paramsMap.getString("medicalLicenseImage"); Integer empNum = paramsMap.getInteger("empNum"); String logo = paramsMap.getString("logo"); String authCode = paramsMap.getString("authCode"); String authDateStr = paramsMap.getString("authDate"); SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd"); Date authDate = null; if (StringUtils.isNotEmpty(authDateStr)) { authDate = format.parse(authDateStr); } Integer authImageType = paramsMap.getInteger("authImageType"); String authImageLogo = paramsMap.getString("authImageLogo"); String authImage = paramsMap.getString("authImage"); Integer customFlag = paramsMap.getInteger("customFlag"); String remarks = paramsMap.getString("remarks"); List bannerList = (List) paramsMap.get("bannerList"); String authParty = paramsMap.getString("authParty"); Integer createBy = paramsMap.getInteger("createBy"); Integer source = paramsMap.getInteger("source"); if (null == source) { // 默认供应商保存 source = 1; } /* 组装授权数据 */ CmBrandAuthPo auth = new CmBrandAuthPo(); auth.setId(authId); auth.setAuthUserId(authUserId); auth.setAuthParty(authParty); auth.setProvinceId(provinceId); auth.setCityId(cityId); auth.setTownId(townId); auth.setAddress(address); auth.setCustomFlag(customFlag); auth.setRemarks(remarks); if (StringUtils.isEmpty(lngAndLat)) { return ResponseJson.error("参数异常,经纬度不能为空"); } String[] split = lngAndLat.split(","); auth.setLng(new BigDecimal(split[0])); auth.setLat(new BigDecimal(split[1])); auth.setMobile(mobile); auth.setUserMobile(userMobile); auth.setLinkMan(linkMan); auth.setLinkMobile(linkMobile); auth.setFirstClubType(firstClubType); auth.setSecondClubType(secondClubType); auth.setMedicalLicenseImage(medicalLicenseImage); auth.setEmpNum(empNum); auth.setLogo(logo); auth.setAuthCode(authCode); auth.setAuthDate(authDate); auth.setAuthImageLogo(authImageLogo); auth.setAuthImage(authImage); auth.setAuthImageType(authImageType); auth.setCreateBy(createBy); auth.setCreateSource(1); return authService.saveAuth(auth, bannerList, false, source); } /** * 审核品牌授权 */ @ApiOperation("审核品牌授权") @ApiImplicitParam(name = "params", value = "authId:授权id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;" + "invalidReason:审核不通过原因;auditBy:审核人用户id;source:来源:1管理员审核,2供应商审核", required = true) @PostMapping("/audit") public ResponseJson auditAuth(@RequestBody String params) { JSONObject paramsMap = JSONObject.parseObject(params); Integer authId = paramsMap.getInteger("authId"); Integer auditStatus = paramsMap.getInteger("auditStatus"); String invalidReason = paramsMap.getString("invalidReason"); Integer auditBy = paramsMap.getInteger("auditBy"); Integer source = paramsMap.getInteger("source"); return authService.auditAuth(authId, auditStatus, invalidReason, auditBy, source); } @ApiOperation("excel导入") @ApiImplicitParams({ @ApiImplicitParam(name = "createBy", required = true, value = "创建人用户id"), @ApiImplicitParam(name = "file", required = true, value = "机构excel表格"), }) @PostMapping("/import/excel") public ResponseJson importDataByExcel(@CurrentUser SysUser sysUser, MultipartFile file, Integer createBy) { if (null == sysUser) { return ResponseJson.error("用户信息异常", null); } // 获取供应商用户id Integer userIdentity = sysUser.getUserIdentity(); Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null; if (null == authUserId) { return ResponseJson.error("供应商用户id不能为空", null); } if (null == createBy) { return ResponseJson.error("参数异常,请输入创建人id"); } if (null == file) { return ResponseJson.error("参数异常,请选择文件"); } return authService.importDataByExcel(file, authUserId, createBy); } @ApiOperation("ldm门店图/备注导入") @GetMapping("/ldm/image/import") public ResponseJson importLdmImage(@CurrentUser SysUser sysUser) { if (null == sysUser) { return ResponseJson.error("用户信息异常", null); } // 获取供应商用户id Integer userIdentity = sysUser.getUserIdentity(); Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null; if (null == authUserId) { return ResponseJson.error("供应商用户id不能为空", null); } return authService.importLdmImage(authUserId); } @ApiOperation("更改查看标记") @ApiImplicitParam(name = "authId", required = true, value = "授权机构id") @PostMapping("/check") public ResponseJson checkAuth(Integer authId) { return authService.checkAuth(authId); } @ApiOperation("勾选明星机构") @ApiImplicitParams({ @ApiImplicitParam(name = "authId", required = true, value = "授权机构id"), @ApiImplicitParam(name = "starFlag", required = true, value = "明星机构标识:0不是,1是") }) @PostMapping("/star") public ResponseJson starAuth(Integer authId, Integer starFlag) { if (null == authId) { return ResponseJson.error("机构id不能为空"); } if (null == starFlag) { return ResponseJson.error("明星机构标识不能为空"); } return authService.starAuth(authId, starFlag); } }