package com.fdkankan.agent.controller; import com.auth0.jwt.JWT; import com.fdkankan.agent.entity.Agent; import com.fdkankan.agent.entity.AgentNotice; import com.fdkankan.agent.service.IAgentNoticeService; import com.fdkankan.agent.service.IAgentService; import com.fdkankan.agent.vo.AgentNoticeVo; import com.fdkankan.agent.vo.AgentVo; import com.fdkankan.common.response.ResultData; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.LinkedHashMap; import java.util.List; @RestController @RequestMapping("/api/agent") public class AgentController { @Autowired IAgentService agentService; @Autowired IAgentNoticeService agentNoticeService; /** * 获取代理商信息 * @return */ @PostMapping(value = "/detail") public ResultData detail(HttpServletRequest request ) throws Exception { String userName = JWT.decode( request.getHeader("token")).getClaim("userName").asString(); String agentId = userName.split(":")[1]; LinkedHashMap queryMap = new LinkedHashMap<>(); queryMap.put("agent_id = "+agentId ,"and"); queryMap.put("rec_status = A" ,"and"); Agent one = agentService.getOne(queryMap); AgentVo agentDto = new AgentVo(); BeanUtils.copyProperties(one, agentDto); return ResultData.ok(agentDto); } /** * 获取代理商公告 * @return */ @PostMapping(value = "/notice") public ResultData notice(HttpServletRequest request ) throws Exception { AgentNoticeVo agentNoticeVo = new AgentNoticeVo(); LinkedHashMap queryMap = new LinkedHashMap<>(); queryMap.put("rec_status = A" ,"and"); List notices = agentNoticeService.getList(queryMap, 1, 1, "create_time desc"); if (notices != null && notices.size() > 0){ BeanUtils.copyProperties(notices.get(0), agentNoticeVo); } return ResultData.ok(agentNoticeVo); } }