Java project: logistics express management system (java + SSM + jsp + MySQL)

java project logistics express management

The main functions of this system are :

Front end company home page 、 policy 、 News Consulting 、 Contact address 、 Leave a message online 、 Place an order online , Query express logistics information, etc ,

The main functions of the background are : Menu management 、 Role management 、 User management 、 News management 、 Log management 、 message management 、 Order management, etc .

 

 

 

 

Front desk login registration control layer :

/**
* Front desk login registration control layer
*/
@Controller
@RequestMapping("/home/index")
public class HomeLoginController {
@Autowired
private HomeUserService homeUserService;
/**
* Go to the login page
* @return
*/
@RequestMapping(value="/login",method= RequestMethod.GET)
public String login(){
return "home/login";
}
/**
* The user login
* @param mobile
* @param password
* @return
*/
@RequestMapping(value="/login",method= RequestMethod.POST)
@ResponseBody
public Result<Boolean> login(@RequestParam("mobile")String mobile,@RequestParam("password")String password) {
// Verify whether the entered mobile phone number is legal
String checkPhone = "^1[3|4|5|7|8]\\d{9}$";
Pattern r = Pattern.compile(checkPhone);
Matcher m = r.matcher(mobile);
if (!m.matches()) {
return Result.error(CodeMsg.HOMEUSER_MOBILE_ERROR);
}
HomeUser byMobile = homeUserService.findByMobile(mobile);
if (byMobile == null){
return Result.error(CodeMsg.HOMEUSER_NO_EXIST);
}
if (byMobile.getStatus() == 0){
return Result.error(CodeMsg.HOMEUSER_STATUS_ERROR);
}
if (!byMobile.getPassword().equals(password)){
return Result.error(CodeMsg.HOMEUSER_PASSWORD_ERROR);
}
SessionUtil.set(SessionConstant.SESSION_HOME_USER_LOGIN_KEY, byMobile);
return Result.success(true);
}
/**
* Go to the registration page
* @return
*/
@RequestMapping(value="/register",method= RequestMethod.GET)
public String register(){
return "home/register";
}
/**
* User registration
* @param homeUser
* @param code
* @return
*/
@RequestMapping(value="/register",method= RequestMethod.POST)
@ResponseBody
public Result<Boolean> register(HomeUser homeUser, @RequestParam("reCode") String code) {
// Verify whether the entered mobile phone number is legal
String checkPhone = "^1[3|4|5|7|8]\\d{9}$";
Pattern r = Pattern.compile(checkPhone);
Matcher m = r.matcher(homeUser.getMobile());
if (!m.matches()) {
return Result.error(CodeMsg.HOMEUSER_MOBILE_ERROR);
}
if (!StringUtil.emailFormat(homeUser.getEmail())) {
return Result.error(CodeMsg.COMMON_EMAIL_FORMAET_ERROR);
}
if (code == null) {
return Result.error(CodeMsg.HOMEUSER_CODE_ERROR);
}
if (code.length() != 4) {
return Result.error(CodeMsg.HOMEUSER_CODE_LENGTH_ERROR);
}
Object attr = SessionUtil.get(SessionConstant.HOME_USER_REGISTER_CODE);
if (attr == null) {
return Result.error(CodeMsg.CODE_NOT_EMPTY);
}
if (!code.equalsIgnoreCase(attr.toString())) {
return Result.error(CodeMsg.CPACHA_ERROR);
}
// Judge whether the mobile phone number is registered
if(homeUserService.isExistMobile(homeUser.getMobile(),0L)){
return Result.error(CodeMsg.HOMEUSER_MOBILE_EXIST);
}
if (homeUserService.save(homeUser) == null) {
return Result.error(CodeMsg.HOMEUSER_ADD_ERROR);
}
SessionUtil.set(SessionConstant.HOME_USER_REGISTER_CODE, null);
return Result.success(true);
}
/**
* Jump to forgot password
* @return
*/
@RequestMapping(value="/forget",method= RequestMethod.GET)
public String forget(){
return "home/forget_password";
}
/**
* Change Password
* @param homeUser
* @param code
* @return
*/
@RequestMapping(value="/forget",method= RequestMethod.POST)
@ResponseBody
public Result<Boolean> forget(HomeUser homeUser, @RequestParam("reCode") String code) {
// Verify whether the entered mobile phone number is legal
String checkPhone = "^1[3|4|5|7|8]\\d{9}$";
Pattern r = Pattern.compile(checkPhone);
Matcher m = r.matcher(homeUser.getMobile());
if (!m.matches()) {
return Result.error(CodeMsg.HOMEUSER_MOBILE_ERROR);
}
if (!StringUtil.emailFormat(homeUser.getEmail())) {
return Result.error(CodeMsg.COMMON_EMAIL_FORMAET_ERROR);
}
if (code == null) {
return Result.error(CodeMsg.HOMEUSER_CODE_ERROR);
}
if (code.length() != 4) {
return Result.error(CodeMsg.HOMEUSER_CODE_LENGTH_ERROR);
}
Object attr = SessionUtil.get(SessionConstant.HOME_USER_FORGET_PASSWORD_CODE);
if (attr == null) {
return Result.error(CodeMsg.CODE_NOT_EMPTY);
}
if (!code.equalsIgnoreCase(attr.toString())) {
return Result.error(CodeMsg.CPACHA_ERROR);
}
// Judge whether the mobile phone number is registered
HomeUser byMobile = homeUserService.findByMobile(homeUser.getMobile());
if (byMobile == null) {
return Result.error(CodeMsg.HOMEUSER_NO_EXIST);
}
if (!byMobile.getEmail().equals(homeUser.getEmail())){
return Result.error(CodeMsg.CODE_NOT_ERROR);
}
byMobile.setPassword(homeUser.getPassword());
if (homeUserService.save(byMobile) == null) {
return Result.error(CodeMsg.HOMEUSER_FORGET_ERROR);
}
SessionUtil.set(SessionConstant.HOME_USER_FORGET_PASSWORD_CODE, null);
return Result.success(true);
}
/**
* sign out
* @return
*/
@RequestMapping(value = "logout", method = RequestMethod.POST)
@ResponseBody
public Result<Boolean> logout() {
HttpSession session = SessionUtil.getSession();
HomeUser homeUser = SessionUtil.getHomeUser();
if (homeUser != null) {
session.removeAttribute(SessionConstant.SESSION_HOME_USER_LOGIN_KEY);
}
return Result.success(true);
}
}

The background administrator manages the controller :

/**
* The background administrator manages the controller
* @author yy
*
*/
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private OperaterLogService operaterLogService;
/**
* Administrator list page
* @param model
* @param user
* @param pageBean
* @return
*/
@RequestMapping(value="/list")
public String list(Model model,User user,PageBean<User> pageBean){
model.addAttribute("title", " Admin list ");
model.addAttribute("username", user.getUsername());
model.addAttribute("pageBean", userService.findList(pageBean,user.getUsername(), UserRoleTypeEnum.ADMIN));
return "admin/user/list";
}
/**
* New administrator page
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("roles", roleService.findAllByRoleType(UserRoleTypeEnum.ADMIN));
return "admin/user/add";
}
/**
* Administrator adds form submission processing
* @param user
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(User user){
// Use the unified verification entity method to verify whether it is legal
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(user.getRole() == null || user.getRole().getId() == null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
// Determine whether the administrator name exists
if(userService.isExistUsername(user.getUsername(), 0L)){
return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
}
user.setUserType(UserRoleTypeEnum.ADMIN);
// This means that everything is qualified , Add database
if(userService.save(user) == null){
return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
}
operaterLogService.add(" Add Administrator , Administrator name :" + user.getUsername());
return Result.success(true);
}
/**
* Administrator edit page
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("roles", roleService.findAllByRoleType(UserRoleTypeEnum.ADMIN));
model.addAttribute("user", userService.find(id));
return "admin/user/edit";
}
/**
* Edit administrator information form submission processing
* @param user
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(User user){
// Use the unified verification entity method to verify whether it is legal
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(user.getRole() == null || user.getRole().getId() == null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
if(user.getId() == null || user.getId().longValue() <= 0){
return Result.error(CodeMsg.ADMIN_USE_NO_EXIST);
}
if(userService.isExistUsername(user.getUsername(), user.getId())){
return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
}
// This means that everything is qualified , Save the database
User findById = userService.find(user.getId());
// The specified fields of the submitted administrator information are copied to the existing user In the object , This method overwrites the contents of the new field
BeanUtils.copyProperties(user, findById, "id","createTime","updateTime","userType");
if(userService.save(findById) == null){
return Result.error(CodeMsg.ADMIN_USE_EDIT_ERROR);
}
operaterLogService.add(" Editor administrator , Administrator name :" + user.getUsername());
return Result.success(true);
}
/**
* Delete Administrator
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
try {
userService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR);
}
operaterLogService.add(" Delete Administrator , Administrators ID:" + id);
return Result.success(true);
}
}

Background role management controller :

/**
* Background role management controller
* @author yy
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
private Logger log = LoggerFactory.getLogger(RoleController.class);
@Autowired
private MenuService menuService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private RoleService roleService;
/**
* Paging search role list
* @param model
* @param role
* @param pageBean
* @return
*/
@RequestMapping(value="/list")
public String list(Model model,Role role,PageBean<Role> pageBean){
model.addAttribute("title", " Character list ");
model.addAttribute("name", role.getName());
model.addAttribute("pageBean", roleService.findByName(role, pageBean));
return "admin/role/list";
}
/**
* Role add page
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("roleTypes", UserRoleTypeEnum.values());
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
return "admin/role/add";
}
/**
* Role add form submission processing
* @param role
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(Role role){
Role top1ByRoleType = roleService.findTop1ByRoleTypeAndRoleTypeNot(role.getRoleType());
if (top1ByRoleType != null){
return Result.error(CodeMsg.ADMIN_ROLE_EXIST);
}
// Use the unified verification entity method to verify whether it is legal
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(roleService.save(role) == null){
return Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR);
}
log.info(" Adding roles 【"+role+"】");
operaterLogService.add(" Adding roles 【"+role.getName()+"】");
return Result.success(true);
}
/**
* Role edit page
* @param id
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(@RequestParam(name="id",required=true)Long id,Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
Role role = roleService.find(id);
model.addAttribute("role", role);
model.addAttribute("authorities",JSONArray.toJSON(role.getAuthorities()).toString());
model.addAttribute("roleTypes", UserRoleTypeEnum.values());
return "admin/role/edit";
}
/**
* Role modification form submission processing
* @param request
* @param role
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Role role){
// Use the unified verification entity method to verify whether it is legal
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
Role existRole = roleService.find(role.getId());
if(existRole == null){
return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
}
existRole.setName(role.getName());
existRole.setRemark(role.getRemark());
existRole.setStatus(role.getStatus());
existRole.setAuthorities(role.getAuthorities());
if(roleService.save(existRole) == null){
return Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR);
}
log.info(" Edit role 【"+role+"】");
operaterLogService.add(" Edit role 【"+role.getName()+"】");
return Result.success(true);
}
/**
* Delete the role
* @param request
* @param id
* @return
*/
@RequestMapping(value="delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
try {
roleService.delete(id);
} catch (Exception e) {
// TODO: handle exception
return Result.error(CodeMsg.ADMIN_ROLE_DELETE_ERROR);
}
log.info(" Edit role ID【"+id+"】");
operaterLogService.add(" Delete the role ID【"+id+"】");
return Result.success(true);
}
}
copyright:author[qq_ one billion three hundred and thirty-four million six hundr],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201270507243946.html