控制器
package com. xuecheng. manage_user. controller ;
import com. xuecheng. api. nuoyun. UserControllerApi ;
import com. xuecheng. framework. domain. nuoyun. User ;
import com. xuecheng. framework. domain. nuoyun. ext. UserNode ;
import com. xuecheng. manage_user. service. UserService ;
import org. springframework. beans. factory. annotation. Autowired ;
import org. springframework. web. bind. annotation. * ;
@RestController
@RequestMapping ( "/nuoyun" )
public class UserController implements UserControllerApi {
@Autowired
UserService userService;
@Override
@GetMapping ( "/User/list/{openid}/{type}" )
public String findUserList ( @PathVariable ( "openid" ) String openid, @PathVariable ( "type" ) String type) {
return userService. findUserList ( openid, type) ;
}
@Override
public UserNode addUser ( User user) {
return null ;
}
}
service层
package com. xuecheng. manage_user. service ;
import com. xuecheng. framework. domain. nuoyun. User ;
import com. xuecheng. manage_user. dao. UserRepository ;
import org. springframework. beans. factory. annotation. Autowired ;
import org. springframework. stereotype. Service ;
import java. util. List ;
@Service
public class UserService {
@Autowired
UserRepository userRepository;
public String findUserList ( String openid, String type) {
List < User > userList = userRepository. findByOpenidAndType ( openid, type) ;
if ( userList == null || userList. size ( ) <= 0 ) {
User user = new User ( ) ;
user. setOpenid ( openid) ;
user. setType ( "1" ) ;
user. setRegIp ( "171.11.1.228" ) ;
user. setRegTime ( "20200228" ) ;
user. setPhoto ( "1.jpg" ) ;
user. setAuthStatus ( "1" ) ;
user. setAuthTime ( "20200228" ) ;
user. setRegTime ( "20200228" ) ;
user. setWaiterId ( "2" ) ;
user. setMasterType ( "2" ) ;
user. setClientType ( "2" ) ;
user. setRoomLimit ( "2" ) ;
user. setCreateArea ( "2" ) ;
user. setSalesman ( "2" ) ;
user. setIsWebrtc ( "2" ) ;
user. setCdnSwitch ( "2" ) ;
user. setPushExtime ( "20200228" ) ;
user. setConcurrencyLimit ( "1" ) ;
userRepository. save ( user) ;
return user. getId ( ) ;
}
return userList. get ( 0 ) . getId ( ) ;
}
}
dao层
package com. xuecheng. manage_user. dao ;
import com. xuecheng. framework. domain. nuoyun. User ;
import org. springframework. data. jpa. repository. JpaRepository ;
import java. util. List ;
public interface UserRepository extends JpaRepository < User , String > {
List < User > findByOpenidAndType ( String openid, String type) ;
}
模型
package com. xuecheng. framework. domain. nuoyun ;
import lombok. Data ;
import lombok. ToString ;
import javax. persistence. * ;
import java. io. Serializable ;
@Data
@ToString
@Entity
@Table ( name= "ny_user" )
public class User implements Serializable {
private static final long serialVersionUID = - 916357110051689499L ;
@Id
@GeneratedValue ( strategy = GenerationType . IDENTITY)
@Column ( length = 32 )
private String id;
private String openid;
private String unionid;
@Column ( name= "first_name" )
private String firstName;
@Column ( name= "wechat_name" )
private String wechatName;
private String name;
private String type;
@Column ( name= "reg_ip" )
private String regIp;
@Column ( name= "reg_time" )
private String regTime;
private String photo;
@Column ( name= "auth_status" )
private String authStatus;
@Column ( name= "auth_time" )
private String authTime;
@Column ( name= "waiter_id" )
private String waiterId;
@Column ( name= "master_type" )
private String masterType;
@Column ( name= "client_type" )
private String clientType;
@Column ( name= "room_limit" )
private String roomLimit;
@Column ( name= "create_area" )
private String createArea;
@Column ( name= "salesman" )
private String salesman;
@Column ( name= "is_webrtc" )
private String isWebrtc;
@Column ( name= "cdn_switch" )
private String cdnSwitch;
@Column ( name= "push_extime" )
private String pushExtime;
@Column ( name= "concurrency_limit" )
private String concurrencyLimit;
}
package com. xuecheng. framework. domain. nuoyun. ext ;
import com. xuecheng. framework. domain. nuoyun. User ;
import lombok. Data ;
import lombok. ToString ;
import java. util. List ;
@Data
@ToString
public class UserNode extends User {
List < UserNode > children;
}