diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Dim.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Dim.java new file mode 100644 index 0000000..1c78bc4 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Dim.java @@ -0,0 +1,17 @@ +package com.jd.logistics.cloud.data.domain; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 14:38 + */ +@Data +public class Dim implements Serializable{ + private static final long serialVersionUID = 8657041672009519925L; + private long id; + private String name; +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimService.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimService.java new file mode 100644 index 0000000..f72e876 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimService.java @@ -0,0 +1,19 @@ +package com.jd.logistics.cloud.data.service; + +import com.jd.logistics.cloud.data.domain.Dim; +import com.jd.logistics.cloud.data.domain.DimQuery; +import com.jd.logistics.cloud.data.domain.GenericRes; + +import java.util.List; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 14:39 + */ +public interface DimService { + List getWarehouses(); + + List getDateCycles(); + +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimServiceImpl.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimServiceImpl.java new file mode 100644 index 0000000..5a3764a --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimServiceImpl.java @@ -0,0 +1,31 @@ +package com.jd.logistics.cloud.data.service; + +import com.jd.logistics.cloud.data.domain.Dim; +import com.jd.logistics.cloud.data.domain.DimQuery; +import com.jd.logistics.cloud.data.domain.GenericRes; +import com.jd.logistics.cloud.data.repository.DimRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 14:40 + */ +@Service +public class DimServiceImpl implements DimService { + @Autowired + DimRepository dimRepository; + @Override + public List getWarehouses() { + return dimRepository.getWarehouses(); + } + + @Override + public List getDateCycles() { + return dimRepository.getDateCycles(); + } + +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/UserServiceImpl.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/UserServiceImpl.java new file mode 100644 index 0000000..63006cc --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/UserServiceImpl.java @@ -0,0 +1,36 @@ +package com.jd.logistics.cloud.data.service; + +import com.jd.logistics.cloud.data.domain.User; +import com.jd.logistics.cloud.data.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 9:13 + */ +@Service +public class UserServiceImpl implements UserService { + @Autowired + UserRepository userRepository; + @Override + public User getUserByName(String username) { + return userRepository.getByName(username); + } + + @Override + public boolean checkPwd(String username, String pwd) { + return pwd.equals(userRepository.getByName(username).getPassword()) ? true: false; + } + + @Override + public boolean checkUser(String username) { + return null == getUserByName(username) ? false: true; + } + + @Override + public User getUserById(long id) { + return userRepository.getById(id); + } +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimApi.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimApi.java new file mode 100644 index 0000000..98e41eb --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimApi.java @@ -0,0 +1,33 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.domain.Dim; +import com.jd.logistics.cloud.data.domain.Function; +import com.jd.logistics.cloud.data.domain.GenericRes; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.validation.Valid; +import java.util.List; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 14:41 + */ +@RequestMapping(value="/api/dim") +public interface DimApi { + + @RequestMapping(value = "/warehouse", + produces = {"application/json"}, + method = RequestMethod.GET) + List getWarehouses(); + + @RequestMapping(value = "/datecycle", + produces = {"application/json"}, + method = RequestMethod.GET) + List getDateCycles(); + +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimRestController.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimRestController.java new file mode 100644 index 0000000..f8d1b62 --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimRestController.java @@ -0,0 +1,29 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.domain.Dim; +import com.jd.logistics.cloud.data.domain.GenericRes; +import com.jd.logistics.cloud.data.service.DimService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 14:43 + */ +@RestController +public class DimRestController implements DimApi{ + @Autowired + DimService dimService; + @Override + public List getWarehouses() { + return dimService.getWarehouses(); + } + + @Override + public List getDateCycles() { + return dimService.getDateCycles(); + } +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/FuncApi.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/FuncApi.java new file mode 100644 index 0000000..91a1cf7 --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/FuncApi.java @@ -0,0 +1,37 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.domain.Function; +import com.jd.logistics.cloud.data.domain.User; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.swing.text.html.parser.Entity; +import javax.validation.Valid; +import java.util.List; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 10:14 + */ +@RequestMapping(value="/api/func") +public interface FuncApi { + + @RequestMapping(value = "/{type}", + produces = { "application/json" }, + method = RequestMethod.GET) + List getFuncByType(@PathVariable("type") int type); + + @RequestMapping(value = "", + produces = { "application/json" }, + method = RequestMethod.GET) + List getFunc(); + + @RequestMapping(value = "", + produces = { "application/json" }, + method = RequestMethod.PUT) + ResponseEntity updateFuncType(@Valid @RequestBody List functionList); +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/UserApi.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/UserApi.java new file mode 100644 index 0000000..70f3c1f --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/UserApi.java @@ -0,0 +1,29 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.domain.User; +import io.swagger.annotations.Api; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.validation.Valid; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 9:14 + */ +@RequestMapping(value="/api/user") +public interface UserApi { + @RequestMapping(value = "/login", + produces = { "application/json" }, + method = RequestMethod.POST) + ResponseEntity login(@Valid @RequestBody User user); + + @RequestMapping(value = "/{id}", + produces = { "application/json" }, + method = RequestMethod.GET) + User user(@PathVariable("id") long id); +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/UserRestController.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/UserRestController.java new file mode 100644 index 0000000..feca9d6 --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/UserRestController.java @@ -0,0 +1,41 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.commons.validation.Errors; +import com.jd.logistics.cloud.data.domain.User; +import com.jd.logistics.cloud.data.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 9:14 + */ +@RestController +public class UserRestController implements UserApi { + @Autowired + UserService userService; + @Override + public ResponseEntity login(@RequestBody User user) { + Errors.Builder errorsBuilder = new Errors.Builder(); + if(!userService.checkUser(user.getUsername())) { + errorsBuilder.addFieldError("username", "账户不存在,请重新输入!"); + return new ResponseEntity<>(errorsBuilder.build(), HttpStatus.OK); + } + if(!userService.checkPwd(user.getUsername(), user.getPassword())) { + errorsBuilder.addFieldError("password", "密码不正确!"); + return new ResponseEntity<>(errorsBuilder.build(), HttpStatus.OK); + } + + return new ResponseEntity<>(HttpStatus.OK); + } + + @Override + public User user(@PathVariable("id") long id) { + return userService.getUserById(id); + } +}