毕业设计|基于 Springboot 实现药房管理系统
最编程
2024-04-27 12:10:12
...
package cn.tedu.drug.controller;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.core.JsonProcessingException;
import cn.tedu.drug.controller.exception.FileContentTypeException;
import cn.tedu.drug.controller.exception.FileEmptyException;
import cn.tedu.drug.controller.exception.FileIOException;
import cn.tedu.drug.controller.exception.FileIllegalStateException;
import cn.tedu.drug.controller.exception.FileSizeException;
import cn.tedu.drug.entity.Customer;
import cn.tedu.drug.entity.CustomerTime;
import cn.tedu.drug.entity.domain.PaginationVO;
import cn.tedu.drug.service.ICustomerService;
import cn.tedu.drug.util.ResponseResult;
@RestController //相当于配置文件(Controller,ResponseBody)
@RequestMapping("/customer")
public class CustomerController extends BaseController {
@Autowired //自动装配
private ICustomerService customerService;
/**
* 注册用户
* @param user
* @return 返回成功
*/
@RequestMapping("/reg")
public ResponseResult<Void> reg(Customer customer) {
customerService.reg(customer);
return new ResponseResult<Void>(SUCCESS);
}
/**
* 登录
* @param username
* @param password
* @return
*/
@PostMapping("/login")
public ResponseResult<Customer> login(String phone,String password,HttpSession session) {
Customer customer = customerService.getloginCustomer(phone, password);
session.setAttribute( "user", customer );
session.setAttribute( "uid", customer.getUid());
session.setAttribute( "username", customer.getUsername() );
return new ResponseResult<Customer>(SUCCESS,customer);
}
/**
* 查询客户数据,多条件查询
* @param drugCategory
* @return
* @throws JsonProcessingException
*/
@RequestMapping("/selectCustomer")
public ResponseResult<PaginationVO<Customer>> selectCustomer
(String username,String gender,String address,String pageNoStr,String pageSizeStr) throws JsonProcessingException {
//获取参数
long pageNo = 1; //如果没有传数据,默认为第一页
if( pageNoStr != null && pageNoStr.trim().length()>0 ){
pageNo = Long.parseLong(pageNoStr);
}
int pageSize = 1; //如果没有传数据,默认为10条数据
if( pageSizeStr != null && pageSizeStr.trim().length()>0 ){
pageSize = Integer.parseInt(pageSizeStr);
}
long beginNo = (pageNo-1)*pageSize;
Map<String ,Object> map = new HashMap<String ,Object>();
map.put("beginNo", beginNo);
map.put("pageSize", pageSize);
map.put("username", username);
map.put("gender", gender);
map.put("address", address);
PaginationVO<Customer> vo = customerService.getSelectCustomer(map);
return new ResponseResult<PaginationVO<Customer>>(SUCCESS,vo);
}
/**
* 删除客户数据
* @param uid
* @param session
* @return
*/
@RequestMapping("/deleteCustomer")
public ResponseResult<Void> deleteCustomer(Integer uid,HttpSession session){
String username = (String) session.getAttribute("username");
customerService.getdeleteId(uid, username);
return new ResponseResult<Void>(SUCCESS);
}
/**
* 修改客户数据
*/
@RequestMapping("/updateCustomer")
public ResponseResult<Void> updateCustomer(Customer customer,HttpSession session){
String username = (String) session.getAttribute("username");
customerService.getupdateCustomer(customer, username);
return new ResponseResult<Void>(SUCCESS);
}
/**
* 展示个人信息
*/
@RequestMapping("/getfindByUid")
public ResponseResult<Customer> getfindByUid(Integer uid){
Customer customer = customerService.getfindByUid(uid);
return new ResponseResult<Customer>(SUCCESS,customer);
}
/**
* 修改密码
*/
@RequestMapping("/getfindByUidPassword")
public ResponseResult<Void> getfindByUidPassword(Integer uid,HttpSession session,String oldPassword,String newPassword){
String username = (String) session.getAttribute("username");
customerService.getfindByUidPassword(uid, username, oldPassword, newPassword);
return new ResponseResult<Void>(SUCCESS);
}
/**
* 上传头像
* @param request
* @param file
* @return MultipartFile file
*/
@RequestMapping("/change_avatar")
public ResponseResult<String> changeAvatar(HttpServletRequest request,@RequestParam("file") MultipartFile file){
if(file.isEmpty()) {
throw new FileEmptyException("上传头像错误!上传文件不能为空!");
}
if(!UPLOAD_CONTENT_TYPE.contains(file.getContentType())) {
throw new FileContentTypeException("上传头像错误!不支持所选的文件类型!");
}
if(file.getSize()>UPLOAD_MAX_SIZE) {
throw new FileSizeException("上传文件过大!请选择小于"+UPLOAD_MAX_SIZE+"的文件!");
}
String parentPath = request.getServletContext().getRealPath(UPLOAD_DIR);
File parent = new File(parentPath);
if(!parent.exists()) {
parent.mkdirs();
}
String originalFilename = file.getOriginalFilename();
//使用系统纳秒值给头像命名
//String prefic = System.nanoTime()+"";
//使用uid+username为头像文件命名,新头像会将旧头像替换
HttpSession session = request.getSession();
String prefic = session.getAttribute("uid").toString()+session.getAttribute("username").toString();
int beginIndex = originalFilename.lastIndexOf(".");
String suffix = "";
if(beginIndex > 0) {
suffix = originalFilename.substring(beginIndex);
}
String filename = prefic+suffix;
File dest = new File(parent,filename);
try {
file.transferTo(dest);
} catch (IllegalStateException e) {
e.printStackTrace();
throw new FileIllegalStateException("上传头像错误!存储头像文件时状态异常!");
} catch (IOException e) {
e.printStackTrace();
throw new FileIOException("上传头像错误!读写文件时出现错误!");
}
Integer uid = getUidFromSession(session);
String avatar = "/"+UPLOAD_DIR+"/"+filename;
customerService.changeAvatar(avatar,uid);
return new ResponseResult<String>(SUCCESS,avatar);
}
/**
* 查询客户的数量
*/
@RequestMapping("/selectIdCount")
public ResponseResult<Long> selectIdCount(){
Long count = customerService.getselectIdCount();
return new ResponseResult<Long>(SUCCESS,count);
}
/**
* 图表展示,客户流量,输入年份,展示该年每一个月的客户注册量
* @param createdTime
* @return
*/
@RequestMapping("/selectYearTime")
public ResponseResult<List<CustomerTime>> selectYearTime(String createdTime){
String str = createdTime.substring(0, createdTime.indexOf("-"));
Map<String,Object> map = new HashMap<String,Object>();
map.put("createdTime", str);
List<CustomerTime> customerTimeList = customerService.getselectYearMonth(map);
return new ResponseResult<List<CustomerTime>>(SUCCESS,customerTimeList);
}
}
推荐阅读
-
基于springboot实现的迪迈手机商城设计系统项目【项目源码+论文阐述】。
-
速递邮件拾取管理系统|基于 SpringBoot 的速递堆栈系统设计与实施 (I)
-
基于 Java、SpringBoot、Vue、Python 爬虫、Hadoop 大数据旅行推荐管理系统
-
基于 SpringBoot 的精品体育场馆预订活动管理系统的设计和实施--座位选择
-
基于 Java、SpringBoot 和 HTML 的实验室预约管理系统设计
-
为药房设计和实施基于 SpringBoot 的药物管理系统
-
毕业设计|基于 Springboot 实现药房管理系统
-
springboot 摄影器材租赁系统设计与实现 341w5 [独家源码] 如何选择高质量的计算机毕业设计
-
Springboot + Vue 项目 - 基于 Java + MySQL 的在线文档管理系统(含源代码 + 演示视频 + LW)
-
基于springboot实现智能推荐卫生健康系统项目【项目源代码+论文说明书】计算机毕业设计-系统设计思路