源码获取:关注文末gongzhonghao,输入014领取下载链接
开发工具:IDEA,数据库mysql
技术:springboot+mybatis
系统主要分两个角色,客户和员工
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 reg(Customer customer) {customerService.reg(customer);return new ResponseResult(SUCCESS);}/*** 登录* @param username* @param password* @return*/@PostMapping("/login")public ResponseResult 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(SUCCESS,customer);}/*** 查询客户数据,多条件查询* @param drugCategory* @return* @throws JsonProcessingException */@RequestMapping("/selectCustomer")public ResponseResult> 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 map = new HashMap();map.put("beginNo", beginNo);map.put("pageSize", pageSize);map.put("username", username);map.put("gender", gender);map.put("address", address);PaginationVO vo = customerService.getSelectCustomer(map);return new ResponseResult>(SUCCESS,vo);}/*** 删除客户数据* @param uid* @param session* @return*/@RequestMapping("/deleteCustomer")public ResponseResult deleteCustomer(Integer uid,HttpSession session){String username = (String) session.getAttribute("username");customerService.getdeleteId(uid, username);return new ResponseResult(SUCCESS);}/*** 修改客户数据*/@RequestMapping("/updateCustomer")public ResponseResult updateCustomer(Customer customer,HttpSession session){String username = (String) session.getAttribute("username");customerService.getupdateCustomer(customer, username);return new ResponseResult(SUCCESS);}/*** 展示个人信息*/@RequestMapping("/getfindByUid")public ResponseResult getfindByUid(Integer uid){Customer customer = customerService.getfindByUid(uid);return new ResponseResult(SUCCESS,customer);}/*** 修改密码*/@RequestMapping("/getfindByUidPassword")public ResponseResult getfindByUidPassword(Integer uid,HttpSession session,String oldPassword,String newPassword){String username = (String) session.getAttribute("username");customerService.getfindByUidPassword(uid, username, oldPassword, newPassword);return new ResponseResult(SUCCESS);}/*** 上传头像* @param request* @param file* @return MultipartFile file*/@RequestMapping("/change_avatar")public ResponseResult 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(SUCCESS,avatar);}/*** 查询客户的数量*/@RequestMapping("/selectIdCount")public ResponseResult selectIdCount(){Long count = customerService.getselectIdCount();return new ResponseResult(SUCCESS,count);}/*** 图表展示,客户流量,输入年份,展示该年每一个月的客户注册量* @param createdTime* @return*/@RequestMapping("/selectYearTime")public ResponseResult> selectYearTime(String createdTime){String str = createdTime.substring(0, createdTime.indexOf("-"));Map map = new HashMap();map.put("createdTime", str);List customerTimeList = customerService.getselectYearMonth(map);return new ResponseResult>(SUCCESS,customerTimeList);}}
package cn.tedu.drug.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import cn.tedu.drug.entity.Drug;
import cn.tedu.drug.entity.DrugANDDrugCategory;
import cn.tedu.drug.entity.DrugCategory;
import cn.tedu.drug.entity.domain.PaginationVO;
import cn.tedu.drug.service.IDrugCategoryService;
import cn.tedu.drug.service.IDrugService;
import cn.tedu.drug.util.ResponseResult;
@RestController
@RequestMapping(“/drug”)
public class DrugController extends BaseController{
@Autowired //自动装配
private IDrugService drugService;
@Autowired //自动装配
private IDrugCategoryService drugCategoryService;
/*** 添加数据。药品类别信息* @param user* @return 返回成功*/
@RequestMapping("/addDrug")
public ResponseResult addDrug(Drug drug,HttpSession session) {String username = (String) session.getAttribute("username");drugService.addDrug(drug, username);return new ResponseResult(SUCCESS);
}/*** 为添加药品时,药品类别选择所设计* @return*/
@RequestMapping("/selectDrugCategory")
public ResponseResult> selectDrugCategory(){List list = drugCategoryService.getfindByCategoryIdCategoryName();return new ResponseResult>(SUCCESS,list);
}/*** 查询药品数据(关联查询)药品类别表,后期改为多条件查询* @param drugCategory* @return* @throws JsonProcessingException */
@RequestMapping("/selectDrug")
public ResponseResult> selectDrug(String drugName,String unit,String origin,Integer categoryId,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 map = new HashMap();map.put("drugName", drugName);map.put("unit", unit);map.put("origin", origin);map.put("beginNo", beginNo);map.put("categoryId", categoryId);map.put("pageSize", pageSize);PaginationVO vo = drugService.getselectDrug(map);return new ResponseResult>(SUCCESS,vo);
}/*** 根据uid查询药品全部数据* @param uid* @return*/
@RequestMapping("/findId")
public ResponseResult getfindId(Integer id){Drug data = drugService.getfindId(id);return new ResponseResult(SUCCESS,data);
};/*** 修改药品数据* @param drug* @param session* @return*/
@RequestMapping("/updateIdDrug")
public ResponseResult updateIdDrug(Drug drug,HttpSession session) {String username = (String) session.getAttribute("username");drugService.getupdateIdDrug(drug, username);return new ResponseResult(SUCCESS);
}/*** 根据id删除药品数据* @param id* @param session* @return*/
@RequestMapping("/deleteIdDrug")
public ResponseResult deleteIdDrug(String id,HttpSession session) {String[] ids = id.split(",");String username = (String) session.getAttribute("username");drugService.getdeleteIdDrug(ids, username);return new ResponseResult(SUCCESS);
}/*** 查询药品的数量*/
@RequestMapping("/selectIdCount")
public ResponseResult selectIdCount(){Long count = drugService.getselectIdCount();return new ResponseResult(SUCCESS,count);
}
}