package com.ycl.controller.dingding; import com.ycl.api.CommonResult; import com.ycl.bo.AdminUserDetails; import com.ycl.common.dingding.DingCommon; import com.ycl.controller.BaseController; import com.ycl.entity.dingding.DingUserInfo; import com.ycl.service.auth.AuthService; import com.ycl.service.ding.BookRemarkService; import com.ycl.service.ding.DingService; import com.ycl.vo.AddressBookVO; import com.ycl.vo.NewAddressBookVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController @RequestMapping("/ding") @Api(tags = "钉钉") public class DingController extends BaseController { @Autowired private DingCommon dingCommon; @Value("${jwt.tokenHead}") private String tokenHead; /** * DING 免登 * 根据临时授权码和access_token获取用户信息 * * @author cjx */ @Autowired private AuthService authService; @Autowired private DingService dingService; @Autowired private BookRemarkService bookRemarkService; @ApiOperation(value = "根据钉钉授权码获取token") @GetMapping("/dingLogin") public CommonResult dingLogin(@RequestParam String code) { HashMap map = new HashMap<>(); //获取用户信息 DingUserInfo dingUser = dingCommon.getDingUserInfo(code); //按ding登录 String token = authService.dingLogin(dingUser); map.put("token", token); map.put("tokenHead", tokenHead); map.put("accountId", dingUser.getAccountId()); return CommonResult.success(map); } @ApiOperation(value = "通讯录") @GetMapping("/addressBook") public CommonResult> getAddressBook() { AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return CommonResult.success(dingService.getAddressBook(user.getUserId())); } @ApiOperation(value = "通讯录递归") @GetMapping("/addressBookById") public CommonResult> getAddressBook(@RequestParam("id") Long id) { AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return CommonResult.success(dingService.getAddressBookByParentId(id, user.getUserId())); } @ApiOperation(value = "通讯录递归") @GetMapping("/getDddressBook") public CommonResult getNewAddressBook(@RequestParam("id") Long id) { AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return CommonResult.success(dingService.getAddressBookById(id, user.getUserId())); } @ApiOperation(value = "修改通讯录备注") @PutMapping("/remark") public CommonResult updateRemark(@RequestParam("userId") Long userId, @RequestParam("remark") String remark) { AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return CommonResult.success(bookRemarkService.updateRemark(user, userId, remark)); } }