Main.java

package com.hcxy.car;

import org.springframework.boot.SpringApplication;

import com.hcxy.car.spring.config.App;

public class Main {

    public static void main(String[] args) {
SpringApplication.run(App.class, args); } }

Account.java

package com.hcxy.car.bean;

import javax.persistence.*;

import org.apache.ibatis.type.Alias;

import java.io.Serializable;
import java.util.List; @Alias("account")
public class Account implements Serializable {
private static final long serialVersionUID = 7095190807242765977L;
private int aid;
private String username; //帐号
private String password; //密码;
private String salt; //加密密码的盐
private int state; //用户状态,0:创建未认证(比如没有激活,没有输入验证码等等)--等待验证的用户 , 1:正常状态,2:用户被锁定.
private List<Role> roleList;// 一个用户具有多个角色 private List<Permission> permissions; public Integer getUid() {
return aid;
} public void setAid(Integer aid) {
this.aid = aid;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getSalt() {
return salt;
} public void setSalt(String salt) {
this.salt = salt;
} public int getState() {
return state;
} public void setState(int state) {
this.state = state;
} public List<Role> getRoleList() {
return roleList;
} public void setRoleList(List<Role> roleList) {
this.roleList = roleList;
} /**
* 密码盐.
* @return
*/
public String getCredentialsSalt(){
return this.username+this.salt;
}
//重新对盐重新进行了定义,用户名+salt,这样就更加不容易被破解 public List<Permission> getPermissions() {
return permissions;
} public void setPermissions(List<Permission> permissions) {
this.permissions = permissions;
}
}

Package.java

package com.hcxy.car.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import org.apache.ibatis.type.Alias; /*import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;*/ //@Entity @Alias("pack")
public class Package implements Serializable { private static final long serialVersionUID = -8102114779905245955L; // @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
private int pid;// 主键. private String deviceType;// tbox,vin,ipc private String carModel;// 版本号 private String packageVersion;// 文件名 private int state;// 状态:0.已废弃,1.可用,2.暂时不可用 private String description;// 文件,描述 private String updateTime;// 上传时间 private ArrayList<PackageFile> files; public String getDeviceType() {
return deviceType;
} public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
} public String getCarModel() {
return carModel;
} public void setCarModel(String carModel) {
this.carModel = carModel;
} public String getPackageVersion() {
return packageVersion;
} public void setPackageVersion(String packageVersion) {
this.packageVersion = packageVersion;
} public int getState() {
return state;
} public void setState(int state) {
this.state = state;
} public String getDescription() {
return description;
} public void setDescription(String description) {
this.description = description;
} public String getUpdateTime() {
return updateTime;
} public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
} public ArrayList<PackageFile> getFiles() {
return files;
} public void setFiles(ArrayList<PackageFile> files) {
this.files = files;
} public int getPid() {
return pid;
} public void setPid(int pid) {
this.pid = pid;
}
}

PackageFile.java

package com.hcxy.car.bean;

import java.io.Serializable;

import org.apache.ibatis.type.Alias;

@Alias("packFile")
public class PackageFile implements Serializable{ private static final long serialVersionUID = 7388621848904718389L; private int fid;// 主键. private String orignName;// 文件名 private String newName;// 文件名 private String filePath;// 文件路径 private String size;// 文件路径 private String md5;//md5校验值 private Package pack; public String getOrignName() {
return orignName;
} public void setOrignName(String orignName) {
this.orignName = orignName;
} public String getNewName() {
return newName;
} public void setNewName(String newName) {
this.newName = newName;
} public String getFilePath() {
return filePath;
} public void setFilePath(String filePath) {
this.filePath = filePath;
} public String getSize() {
return size;
} public void setSize(String size) {
this.size = size;
} public String getMd5() {
return md5;
} public void setMd5(String md5) {
this.md5 = md5;
} public Package getPack() {
return pack;
} public void setPack(Package pack) {
this.pack = pack;
} public int getFid() {
return fid;
} public void setFid(int fid) {
this.fid = fid;
} }

Permission.java

package com.hcxy.car.bean;

import javax.persistence.*;

import org.apache.ibatis.type.Alias;

import java.io.Serializable;
import java.util.List; @Alias("permission")
public class Permission implements Serializable{
private static final long serialVersionUID = -9057378183567456755L;
private int pid;//主键.
private String pname;//名称.
private String pdescription;//资源类型,[menu|button]
// private String url;//资源路径.
// private String permission; //权限字符串,menu例子:role:*,button例子:role:create,role:update,role:delete,role:view
// private Long parentId; //父编号
// private String parentIds; //父编号列表
// private Boolean available = Boolean.FALSE;
private List<Role> roles; public int getPId() {
return pid;
} public void setId(int pid) {
this.pid = pid;
} public String getPname() {
return pname;
} public void setPname(String pname) {
this.pname = pname;
} public List<Role> getRoles() {
return roles;
} public void setRoles(List<Role> roles) {
this.roles = roles;
} public String getPdescription() {
return pdescription;
} public void setPdescription(String pdescription) {
this.pdescription = pdescription;
}
}

Role.java

package com.hcxy.car.bean;

import javax.persistence.*;

import org.apache.ibatis.type.Alias;

import java.io.Serializable;
import java.util.List; @Alias("role")
public class Role implements Serializable{
private static final long serialVersionUID = -319946799189427159L;
private int rid; // 编号
private String rname; // 角色标识程序中判断使用,如"admin",这个是唯一的:
private String rdescription; // 角色描述,UI界面显示使用
private List<Permission> permissions;
private List<Account> userInfos;// 一个角色对应多个用户 public int getRId() {
return rid;
} public void setId(int rid) {
this.rid = rid;
} public String getRdescription() {
return rdescription;
} public void setRdescription(String rdescription) {
this.rdescription = rdescription;
} public List<Permission> getPermissions() {
return permissions;
} public void setPermissions(List<Permission> permissions) {
this.permissions = permissions;
} public List<Account> getUserInfos() {
return userInfos;
} public void setUserInfos(List<Account> userInfos) {
this.userInfos = userInfos;
} public String getRname() {
return rname;
} public void setRname(String rname) {
this.rname = rname;
}
}

PackageFileLink.java

package com.hcxy.car.bean.pojo;

import org.apache.ibatis.type.Alias;

import com.hcxy.car.bean.Package;
import com.hcxy.car.bean.PackageFile; @Alias("packFileLink") //使用默认的别名
public class PackageFileLink {
private Package pack; private PackageFile file; public Package getPack() {
return pack;
} public void setPack(Package pack) {
this.pack = pack;
} public PackageFile getFile() {
return file;
} public void setFile(PackageFile file) {
this.file = file;
} }

AccountController.java

package com.hcxy.car.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import com.hcxy.car.bean.Account;
import com.hcxy.car.bean.DeviceType;
import com.hcxy.car.bean.Permission;
import com.hcxy.car.service.IAccountService;
import com.hcxy.car.util.CommomUtil; @RestController
@RequestMapping("/account")
public class AccountController extends BaseController{
@Resource(name = "accountService")
IAccountService accountService; @PostMapping("/add")
public @ResponseBody Map<String, Object> adddevice(@RequestBody Map<String, String> reqMap) throws Exception {
String accountname = reqMap.get("username");
String pwd = reqMap.get("password");
Map<String, Object> map = new HashMap<String, Object>();
boolean b = findByName(accountname);
if(b == true) {
map.put("errcode", 1);
map.put("mess", "账号名:" + accountname + ",已存在,请重命名!");
return map;
}
Account ac = new Account();
ac.setUsername(accountname);
ac.setPassword(CommomUtil.password(pwd));
ac.setState(1);
ac.setSalt("");
try {
accountService.addAccount(ac);
} catch (Exception e1) {
e1.printStackTrace();
map.put("errcode", 1);
map.put("mess", "添加失败");
return map;
}
map.put("errcode", 0);
map.put("mess", "添加成功");
return null;
} public Boolean findByName(String name) throws Exception {
boolean b = accountService.findByName(name);
return b;
} @RequestMapping(value = "/all", method = RequestMethod.GET)
public Map<String, Object> all(HttpServletRequest request, HttpServletResponse response) {
Map<String, Object> map = new HashMap<String, Object>();
List<Account> l = null;
try {
l = accountService.findAll();
} catch (Exception e) {
e.printStackTrace();
}
map.put("accounts", l);
return map;
} @RequestMapping(value = "/permissions", method = RequestMethod.POST)
public Map<String, Object> permissions() {
Map<String, Object> map = new HashMap<String, Object>();
List<Permission> l = null;
try {
l = accountService.findAllpermissions();
} catch (Exception e) {
e.printStackTrace();
}
map.put("permissions", l);
return map;
}
}

PackageController.java

package com.hcxy.car.controller;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import com.alibaba.fastjson.JSON;
import com.hcxy.car.bean.Package;
import com.hcxy.car.bean.PackageFile;
import com.hcxy.car.bean.pojo.PackageFileLink;
import com.hcxy.car.service.IPackageService;
import com.hcxy.car.util.CommomUtil; @CrossOrigin
@RestController
@RequestMapping("/package")
public class PackageController extends BaseController { private String UPLOAD_FOLDER; private Logger logger = LoggerFactory.getLogger(PackageController.class); /*
* @Autowired(required=true) //接口只有一个实现类的时候会找到,多个实现类的时候指定子类的类名
* @Qualifier("PackageServiceImpl")
*/
@Resource(name = "packageService")
IPackageService pkService; @RequestMapping(value = "/all", method = RequestMethod.POST)
public Map<String, Object> all(HttpServletRequest request, HttpServletResponse response) {
/*
* User user = UserThreadLocal.get(); if (null == user) { // 未登录状态
* this.cartCookieService.delete(itemId, request, response); } else { // 登录状态
* this.cartService.delete(itemId, user.getId()); } System.out.println("haha");
*/
Map<String, Object> map = new HashMap<String, Object>();
List<Package> l = null;
try {
l = pkService.findAllPackages();
} catch (Exception e) { e.printStackTrace();
}
map.put("total", l.size());
map.put("limit", 100);
map.put("packages", l);
return map;
} // PostMapping = @RequestMapping(value =“/xx”, method = RequestMethod.POST).
//public @ResponseBody ResponseEntity<String> uploadImg(HttpServletRequest request, HttpServletResponse response) {
//return new ResponseEntity<String>("文件为空,请重新上传", HttpStatus.OK);
@PostMapping("/add")
public @ResponseBody Map<String, Object> uploadImg(HttpServletRequest request, HttpServletResponse response) {
// response.setHeader("Access-Control-Allow-Origin", "*");
Map<String, Object> m = new HashMap<String, Object>(); MultipartHttpServletRequest params = ((MultipartHttpServletRequest) request);
List<MultipartFile> filelist = ((MultipartHttpServletRequest) request).getFiles("fileList");
//System.out.println("filelist: " + JSON.toJSONString(filelist, true)); if (filelist.size() == 0) {
logger.error("文件为空");
m.put("errcode", 1);
m.put("mess", "文件为空,请重新上传");
return m;
} String now = CommomUtil.DateFormat();
Package t = new Package();
String version = params.getParameter("fileVersion");
t.setPackageVersion(version);
t.setDescription(params.getParameter("description"));
t.setUpdateTime(now);
int state = Integer.parseInt(params.getParameter("state"));
t.setState(state);
String[] selectedOptions = params.getParameter("selectedOptions").split(",");
t.setDeviceType(selectedOptions[0]);
t.setCarModel(selectedOptions[1]); boolean b = pkService.findByName(selectedOptions[0],selectedOptions[1],version);
if(b == true) {
m.put("errcode", 1);
m.put("mess", selectedOptions[0] + "--" + "selectedOptions[1]" + "--" + version + ",已存在,请重命名!");
return m;
} try {
pkService.addPackage(t);
} catch (Exception e1) {
e1.printStackTrace();
} UPLOAD_FOLDER = request.getSession().getServletContext().getRealPath("/") + "upload\\" +selectedOptions[0]+
"\\" + selectedOptions[1] + "\\"+version + "\\";
File dir = new File(UPLOAD_FOLDER);
if (!dir.exists()) {
dir.mkdirs();
} for (int i = 0; i < filelist.size(); i++) {
if (filelist.get(i) != null) {
MultipartFile file = filelist.get(i);
String filename = file.getOriginalFilename();
String filetype = file.getContentType();
String suffix = filename.substring(filename.lastIndexOf("."));
String defineName = UUID.randomUUID() + "-" + CommomUtil.DateFormat() + suffix; // 重命名
// 获取文件大小
long size = file.getSize();
File serverFile = new File(UPLOAD_FOLDER + defineName);
try {
file.transferTo(serverFile);//会先传到tomcat的临时目录,C:\Users\17M38332\AppData\Local\Temp\tomcat.5717973570587192077.8086\work\Tomcat\localhost\ROOT PackageFile tf = new PackageFile();
tf.setOrignName(filename);
tf.setNewName(defineName);
tf.setFilePath(UPLOAD_FOLDER + defineName);
tf.setSize(Long.toString(size));
tf.setMd5(CommomUtil.md5(serverFile)); pkService.insertfile(tf); PackageFileLink tfl = new PackageFileLink();
tfl.setPack(t);
tfl.setFile(tf);
pkService.saveRelativity(tfl);
} catch (IllegalStateException e) {
e.printStackTrace();
m.put("errcode", 1);
m.put("mess", "上传第" + i + "个文件失败");
return m;
} catch (IOException e) {
e.printStackTrace();
m.put("errcode", 1);
m.put("mess", "上传第" + i + "个文件失败");
return m;
}
}
}
// 调用文件处理类FileUtil,处理文件,将文件写入指定位置
/*
* try { service.uploadFile(fileList[0].getBytes(), filePath, fileName); } catch
* ( Exception e) { // TODO: handle exception }
*/
List<Package> l = findStateEnable(selectedOptions[0],selectedOptions[1],1);
if(l.size() > 1) {
m.put("errcode", 0);
m.put("mess", selectedOptions[0]+"--"+selectedOptions[1]+",有多个启用版本");
}else if(l.size() == 0) {
m.put("errcode", 0);
m.put("mess", selectedOptions[0]+"--"+selectedOptions[1]+",没有启用版本");
}else {
m.put("errcode", 0);
m.put("mess", "添加成功");
}
return m;
} @RequestMapping(value = "/modify", method = RequestMethod.POST)
public Map<String, Object> modifystate(@RequestBody Map<String, String> reqMap) {
/*
* User user = UserThreadLocal.get(); if (null == user) { // 未登录状态
* this.cartCookieService.delete(itemId, request, response); } else { // 登录状态
* this.cartService.delete(itemId, user.getId()); } System.out.println("haha");
*/
int pid = Integer.parseInt(reqMap.get("pid"));
int state = Integer.parseInt(reqMap.get("state"));
String deviceType = reqMap.get("deviceType");
String carModel = reqMap.get("carModel");
try {
pkService.modifyPackageByState(pid, state);
} catch (Exception e) {
e.printStackTrace();
}
Map<String, Object> m = new HashMap<String, Object>();
List<Package> l = findStateEnable(deviceType,carModel,1);
if(l.size() > 1) {
m.put("errcode", 1);
m.put("mess", deviceType+"--"+carModel+",有多个启用版本");
}else if(l.size() == 0) {
m.put("errcode", 1);
m.put("mess", deviceType+"--"+carModel+",没有启用版本");
}else {
m.put("errcode", 0);
m.put("mess", "修改成功");
}
return m;
} public List<Package> findStateEnable(String deviceType,String carModel,int n){
List<Package> l = pkService.findMore(deviceType,carModel,n);
return l;
} //文件下载相关代码
@RequestMapping("/download")
public String downloadFile(HttpServletRequest request, HttpServletResponse response) {
String fileName = "b60bcf72-219d-4e92-88de-ed6b0ad9b0e7-2018-04-23-14-09-14.xls";// 设置文件名,根据业务需要替换成要下载的文件名
if (fileName != null) {
//设置文件路径
/*String realPath = request.getServletContext().getRealPath("//WEB-INF//");*/
String realPath = "D:\\eclipsworksapce1\\upgrade\\src\\main\\webapp\\upload\\tbox\\456789\\";
File file = new File(realPath , fileName);
if (file.exists()) {
response.setContentType("application/force-download");//
response.setHeader("content-type", "application/octet-stream");
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);// 设置文件名
byte[] buffer = new byte[1024];
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
OutputStream os = response.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
System.out.println("success");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
return null;
} @RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(String deviceType,String carModel,int n){
return "ssssssssssssss";
}
}

AccountMapper.java

package com.hcxy.car.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

import com.hcxy.car.bean.Account;
import com.hcxy.car.bean.Permission; @Mapper
public interface AccountMapper {
int addAccount(Account dt);
List<Account> findAll();
int deleteByAccountId(int id); List<Account> findByName(String name); List<Permission> findAllpermissions(); }

PackageFileMapper.java

package com.hcxy.car.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

import com.hcxy.car.bean.PackageFile;

@Mapper
public interface PackageFileMapper { PackageFile selectByPrimaryKeyfile(Long id); List<PackageFile> selectAllTboxFile(); Long deleteByPrimaryKeyfile(Long id); Long insertfile(PackageFile tboxfile); Long insertSelectivefile(PackageFile tboxfile); Long updateByPrimaryKeySelectivefile(PackageFile tboxfile); Long updateByPrimaryKeyfile(PackageFile tboxfile);
}

PackageMapper.java

package com.hcxy.car.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

import com.hcxy.car.bean.Package;
import com.hcxy.car.bean.pojo.PackageFileLink; @Mapper
public interface PackageMapper{ Package tboxselectByPrimaryKey(Long id); List<Package> tboxselectAllTboxFile(); Long tboxdeleteByPrimaryKey(Long id); Long addPackage(Package tbox); Long saveRelativity(PackageFileLink tfl); Long insertSelectivetbox(Package tbox); Long updateByPrimaryKeySelectivetbox(Package tbox); Long updateByPrimaryKeytbox(Package tbox); List<Package> selectAllTboxandFiles();
List<Package> selectAllFiles();//请求所有升级包列表
void modifyPackageByState(int pid,int state);
List<Package> findByName(String devicetype, String carmodel, String version);
List<Package> findMore(String deviceType,String carModel,int n); }

IAccountService.java

package com.hcxy.car.service;

import java.util.List;

import com.hcxy.car.bean.Account;
import com.hcxy.car.bean.Permission; public interface IAccountService extends IBaseService {
boolean findByName(String name); int addAccount(Account dt);
List<Account> findAll();
int deleteByAccountId(int id); List<Permission> findAllpermissions(); }

IPackageService.java

package com.hcxy.car.service;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import com.hcxy.car.bean.Package;
import com.hcxy.car.bean.PackageFile;
import com.hcxy.car.bean.pojo.PackageFileLink; /*@Service
@Transactional*/
public interface IPackageService extends IBaseService {
public void uploadFile(byte[] file, String filePath, String fileName) throws Exception; int addPackage(Package tbox); int insertfile(PackageFile tf); int saveRelativity(PackageFileLink tfl); List<Package> findAllTbox(int pageNum, int pageSize); List<Package> findAllPackages();//请求所有升级包列表 void modifyPackageByState(int pid,int state) throws Exception; boolean findByName(String devicetype,String carmodel,String version); List<Package> findMore(String deviceType,String carModel,int n);
}

AccountServiceImpl.java

package com.hcxy.car.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import com.hcxy.car.bean.Account;
import com.hcxy.car.bean.DeviceType;
import com.hcxy.car.bean.Permission;
import com.hcxy.car.mapper.AccountMapper;
import com.hcxy.car.mapper.CarModelMapper;
import com.hcxy.car.mapper.DeviceTypeMapper;
import com.hcxy.car.service.IAccountService;
import com.hcxy.car.service.IDeviceTypeService; @Service(value = "accountService")
public class AccountServiceImpl implements IAccountService { @Resource(name = "accountMapper")
private AccountMapper accountMapper; @Transactional
public int addAccount(Account dt) {
accountMapper.addAccount(dt);
return 0;
} public List<Account> findAll(){
List<Account> l = null;
try {
l = accountMapper.findAll();
} catch (Exception e) {
e.printStackTrace();
}
return l;
}; @Transactional
public int deleteByAccountId(int id){
accountMapper.deleteByAccountId(id);
return 0;
}; public boolean findByName(String name) {
List<Account> d = accountMapper.findByName(name);
if(d == null || d.size() == 0) {//true有false没有
return false;
}else {
return true;
}
} public List<Permission> findAllpermissions() {
List<Permission> d = accountMapper.findAllpermissions();
return d;
} }

PackageServiceImpl.java

package com.hcxy.car.service.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import com.hcxy.car.bean.Package;
import com.hcxy.car.bean.PackageFile;
import com.hcxy.car.bean.pojo.PackageFileLink;
import com.hcxy.car.mapper.PackageFileMapper;
import com.hcxy.car.mapper.PackageMapper;
import com.hcxy.car.service.IPackageService; @Service(value = "packageService")
public class PackageServiceImpl implements IPackageService{
//@Autowired
@Resource(name = "packageMapper")
private PackageMapper packageMapper;
// @Autowired
@Resource(name = "packageFileMapper")
private PackageFileMapper packageFileMapper; public void uploadFile(byte[] file, String filePath, String fileName) throws Exception { System.out.println("sssssss");
File targetFile = new File(filePath);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
FileOutputStream out = new FileOutputStream(filePath + fileName);
out.write(file);
out.flush();
out.close();
} @Transactional
public int addPackage(Package tbox) {
try {
packageMapper.addPackage(tbox);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
} public List<Package> findALlFiles(int pageNum, int pageSize) {
// packageMapper.selectALlFiles();
return null;
} public List<Package> findAllPackages() {//请求所有升级包列表
return packageMapper.selectAllFiles();
// return null;
} @Transactional
public int insertfile(PackageFile tf) {
packageFileMapper.insertfile(tf);
return 0;
} @Transactional
public int saveRelativity(PackageFileLink tfl) {
packageMapper.saveRelativity(tfl);
return 0;
} public List<Package> findAllTbox(int pageNum, int pageSize) {
// TODO Auto-generated method stub
return null;
} @Transactional
public void modifyPackageByState(int pid,int state) throws Exception {
packageMapper.modifyPackageByState(pid,state);
//throw new Exception();
} public boolean findByName(String devicetype, String carmodel, String version) {
List<Package> p = packageMapper.findByName(devicetype,carmodel,version);
if(null == p || p.size() == 0) {
return false;
}else {
return true;
}
} public List<Package> findMore(String deviceType,String carModel,int n) {
List<Package> l = packageMapper.findMore(deviceType,carModel,n);
return l;
}
}

App.java

package com.hcxy.car.spring.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; //import com.jolbox.bonecp.BoneCPDataSource; @Configuration
@PropertySource(value = {"classpath:jdbc.properties", "classpath:env.properties",
"classpath:httpclient.properties"})
@ComponentScan(basePackages = "com.hcxy.car") //扫描 @Server @Controller @Repository
@MapperScan(value = "com.hcxy.car.mapper")
@ServletComponentScan //不加MyServlet不起作用
//@ImportResource(value = "classpath:dubbo/dubbo-consumer.xml") //ImportResource是import导入
@EnableAutoConfiguration
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
public class App extends SpringBootServletInitializer{ @Value("${jdbc.url}")
private String jdbcUrl; @Value("${jdbc.driverClassName}")
private String jdbcDriverClassName; @Value("${jdbc.username}")
private String jdbcUsername; @Value("${jdbc.password}")
private String jdbcPassword; /*@Bean(destroyMethod = "close")
public DataSource dataSource() {
BoneCPDataSource boneCPDataSource = new BoneCPDataSource();
// 数据库驱动
boneCPDataSource.setDriverClass(jdbcDriverClassName);
// 相应驱动的jdbcUrl
boneCPDataSource.setJdbcUrl(jdbcUrl);
// 数据库的用户名
boneCPDataSource.setUsername(jdbcUsername);
// 数据库的密码
boneCPDataSource.setPassword(jdbcUsername);
// 检查数据库连接池中空闲连接的间隔时间,单位是分,默认值:240,如果要取消则设置为0
boneCPDataSource.setIdleConnectionTestPeriodInMinutes(60);
// 连接池中未使用的链接最大存活时间,单位是分,默认值:60,如果要永远存活设置为0
boneCPDataSource.setIdleMaxAgeInMinutes(30);
// 每个分区最大的连接数
boneCPDataSource.setMaxConnectionsPerPartition(100);
// 每个分区最小的连接数
boneCPDataSource.setMinConnectionsPerPartition(5);
return boneCPDataSource;
}*/ protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(App.class);
} //Tomcat large file upload connection reset
/*@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) (connector) -> {
if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
//-1 means unlimited
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
});
return tomcat;
}*/ }

CORSConfig.java

package com.hcxy.car.spring.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import static org.springframework.web.cors.CorsConfiguration.ALL; /**
* CORS configuration,去掉就不能访问了
*/
@Configuration
public class CORSConfig { @Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(ALL)
.allowedMethods(ALL)
.allowedHeaders(ALL)
.allowCredentials(true);
}
};
} }

DruidDBConfig.java

package com.hcxy.car.spring.config;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import com.alibaba.druid.pool.DruidDataSource; import org.slf4j.Logger; @Configuration
public class DruidDBConfig {
private Logger logger = LoggerFactory.getLogger(DruidDBConfig.class); @Value("${spring.datasource.url}")
private String dbUrl; @Value("${spring.datasource.username}")
private String username; @Value("${spring.datasource.password}")
private String password; @Value("${spring.datasource.driverClassName}")
private String driverClassName; @Value("${spring.datasource.initialSize}")
private int initialSize; @Value("${spring.datasource.minIdle}")
private int minIdle; @Value("${spring.datasource.maxActive}")
private int maxActive; @Value("${spring.datasource.maxWait}")
private int maxWait; @Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
private int timeBetweenEvictionRunsMillis; @Value("${spring.datasource.minEvictableIdleTimeMillis}")
private int minEvictableIdleTimeMillis; @Value("${spring.datasource.validationQuery}")
private String validationQuery; @Value("${spring.datasource.testWhileIdle}")
private boolean testWhileIdle; @Value("${spring.datasource.testOnBorrow}")
private boolean testOnBorrow; @Value("${spring.datasource.testOnReturn}")
private boolean testOnReturn; @Value("${spring.datasource.poolPreparedStatements}")
private boolean poolPreparedStatements; @Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}")
private int maxPoolPreparedStatementPerConnectionSize; @Value("${spring.datasource.filters}")
private String filters; @Value("{spring.datasource.connectionProperties}")
private String connectionProperties; @Bean //声明其为Bean实例
@Primary //在同样的DataSource中,首先使用被标注的DataSource
public DataSource dataSource(){
DruidDataSource datasource = new DruidDataSource(); datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName); //configuration
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
logger.error("druid configuration initialization filter", e);
}
datasource.setConnectionProperties(connectionProperties); return datasource;
}
}

CommomUtil.java

package com.hcxy.car.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash; public class CommomUtil { public static String DateFormat() {
Date d = new Date();
System.out.println(d);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String dateNowStr = sdf.format(d);
return dateNowStr;
} public static String md5(File f) {//得到文件的md5值
String md5 = null;
try {
md5 = DigestUtils.md5Hex(new FileInputStream(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return md5;
} public static String password(String pwd) {//得到文件的md5值
String md5 = null;
//盐
String salt = "hcxyupgrade";
//散列次数
int hashIterations = 1;
SimpleHash simpleHash = new SimpleHash("md5", pwd, salt, hashIterations);
String password_md5 = simpleHash.toString();
return password_md5;
} }

dubbo-consumer.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 提供方应用信息,用于计算依赖关系 -->
<!-- <dubbo:application name="taotao-cart-consumer" /> --> <!-- 这里使用的注册中心是zookeeper -->
<!-- <dubbo:registry address="zookeeper://127.0.0.1:2181" client="zkclient"/> --> <!-- 从注册中心中查找服务 -->
<!-- <dubbo:reference id="userQueryService" interface="com.taotao.sso.query.service.UserQueryService"/> --> </beans>

AccountMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hcxy.car.mapper.AccountMapper" > <resultMap id="BaseResultMap" type="account" >
<id column="aid" property="aid" jdbcType="INTEGER" />
<result column="user_name" property="username" jdbcType="CHAR" />
<result column="state" property="state" jdbcType="CHAR" />
<collection property="permissions" ofType="permission" javaType="ArrayList">
<id property="pid" column="pid" jdbcType="INTEGER"/>
<result property="pname" column="p_name" jdbcType="CHAR"/>
<result property="pdescription" column="pdescription" jdbcType="VARCHAR"/>
</collection>
</resultMap> <resultMap id="permissionsResult" type="permission" >
<id column="pid" property="pid" jdbcType="INTEGER" />
<result column="p_name" property="pname" jdbcType="CHAR" />
<result column="pdescription" property="pdescription" jdbcType="VARCHAR" />
</resultMap> <sql id="Base_Column" >
aid, user_name
</sql> <select id="selectByid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column" />
from t_device_type
where dtid = #{dtid,jdbcType=INTEGER}
</select> <select id="findAll" resultMap="BaseResultMap">
select ac.aid ,ac.user_name ,ac.state ,pe.pid, pe.p_name ,pe.pdescription
from t_account ac
left join t_account_permission ap on ac.aid = ap.account_id
left join t_permission pe on ap.permission_id = pe.pid
</select> <select id="findAllpermissions" resultMap="permissionsResult">
select p.pid,p.p_name,p.pdescription
from t_permission p
</select> <select id="findByName" resultMap="BaseResultMap" parameterType="java.lang.String">
select aid, user_name
from t_account
where t_account.user_name = #{arg0,jdbcType=VARCHAR}
</select> <delete id="deleteByiud" parameterType="java.lang.Integer" >
delete from t_device_type
where dtid = #{arg0,jdbcType=INTEGER}
</delete> <insert id="addAccount" parameterType="account" useGeneratedKeys="true" keyProperty="id">
insert into t_account (user_name, password,state)
values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},#{state,jdbcType=CHAR})
</insert> <!-- <insert id="insertSelectivefile" parameterType="tboxFile" useGeneratedKeys="true" keyProperty="id">
insert into t_tboxfile
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="orignName != null" >
orignName,
</if>
<if test="newName != null" >
newName,
</if>
<if test="filePath != null" >
filePath,
</if>
<if test="size != null" >
size,
</if>
<if test="md5 != null" >
md5,
</if>
<if test="state != null" >
state,
</if>
<if test="updateTime != null" >
updateTime
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="orignName != null" >
#{orignName,jdbcType=VARCHAR},
</if>
<if test="newName != null" >
#{newName,jdbcType=VARCHAR},
</if>
<if test="filePath != null" >
#{filePath,jdbcType=VARCHAR},
</if>
<if test="size != null" >
#{size,jdbcType=VARCHAR},
</if>
<if test="md5 != null" >
#{md5,jdbcType=VARCHAR},
</if>
<if test="state != null" >
#{state,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=VARCHAR},
</if>
</trim>
</insert> --> <update id="updateById" parameterType="account" >
update t_device_type
<set >
<if test="name != null" >
dtname = #{dtname,jdbcType=CHAR},
</if>
<if test="description != null" >
description = #{description,jdbcType=VARCHAR},
</if>
</set>
where dtid = #{dtid,jdbcType=INTEGER}
</update> <update id="update" parameterType="account" >
update t_device_type
set dtname = #{dtname,jdbcType=CHAR},
description = #{description,jdbcType=VARCHAR}
where dtid = #{dtid,jdbcType=INTEGER}
</update> </mapper>

PackageFileMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hcxy.car.mapper.PackageFileMapper" > <resultMap id="BaseResultMap" type="packFile">
<id column="fid" property="fid" jdbcType="INTEGER"/>
<result column="orign_name" property="orignName" jdbcType="VARCHAR" />
<result column="new_name" property="newName" jdbcType="VARCHAR" />
<result column="file_path" property="filePath" jdbcType="VARCHAR" />
<result column="size" property="size" jdbcType="VARCHAR" />
<result column="md5" property="md5" jdbcType="VARCHAR" />
<association property="pack" javaType="pack">
<id property="pid" column="pid" />
<result property="deviceType" column="device_type" />
<result property="carModel" column="car_model" />
<result property="packageVersion" column="package_version" />
<result property="state" column="state" />
<result property="description" column="description" />
<result property="updateTime" column="update_time" />
</association>
</resultMap> <!-- <sql id="File_Base_Column_List" >
fid, orignName, newName,filePath, size, md5,state,updateTime
</sql> <select id="selectByPrimaryKeyfile" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="File_Base_Column_List" />
from t_tboxfile
where fid = #{fid,jdbcType=BIGINT}
</select> --> <!-- <select id="selectAllTboxFile" resultMap="BaseResultMap">
select
<include refid="File_Base_Column_List" />
from t_tboxfile
</select> --> <!-- <delete id="deleteByPrimaryKeyfile" parameterType="java.lang.Integer" >
delete from t_tboxfile
where fid = #{fid,jdbcType=BIGINT}
</delete> --> <insert id="insertfile" parameterType="packFile" useGeneratedKeys="true" keyProperty="fid">
<!-- <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="fid">
SELECT LAST_INSERT_ID()
</selectKey> -->
insert into t_file (orign_name, new_name, file_path, size, md5)
values (#{orignName,jdbcType=VARCHAR}, #{newName,jdbcType=VARCHAR},
#{filePath,jdbcType=VARCHAR},#{size,jdbcType=VARCHAR},#{md5,jdbcType=VARCHAR})
</insert> <!-- <insert id="insertSelectivefile" parameterType="tboxFile" useGeneratedKeys="true" keyProperty="id">
insert into t_tboxfile
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="fid != null" >
fid,
</if>
<if test="orignName != null" >
orignName,
</if>
<if test="newName != null" >
newName,
</if>
<if test="filePath != null" >
filePath,
</if>
<if test="size != null" >
size,
</if>
<if test="md5 != null" >
md5,
</if>
<if test="state != null" >
state,
</if>
<if test="updateTime != null" >
updateTime
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="fid != null" >
#{fid,jdbcType=BIGINT},
</if>
<if test="orignName != null" >
#{orignName,jdbcType=VARCHAR},
</if>
<if test="newName != null" >
#{newName,jdbcType=VARCHAR},
</if>
<if test="filePath != null" >
#{filePath,jdbcType=VARCHAR},
</if>
<if test="size != null" >
#{size,jdbcType=VARCHAR},
</if>
<if test="md5 != null" >
#{md5,jdbcType=VARCHAR},
</if>
<if test="state != null" >
#{state,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=VARCHAR},
</if>
</trim>
</insert> --> <!-- <update id="updateByPrimaryKeySelectivefile" parameterType="tboxFile" >
update t_tboxfile
<set >
<if test="orignName != null" >
orignName = #{orignName,jdbcType=VARCHAR},
</if>
<if test="newName != null" >
newName = #{newName,jdbcType=VARCHAR},
</if>
<if test="filePath != null" >
filePath = #{filePath,jdbcType=VARCHAR},
</if>
<if test="size != null" >
size = #{size,jdbcType=VARCHAR},
</if>
<if test="md5 != null" >
md5 = #{md5,jdbcType=VARCHAR},
</if>
<if test="state != null" >
state = #{state,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
updateTime = #{updateTime,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update> --> <!-- <update id="updateByPrimaryKeyfile" parameterType="tboxFile" >
update t_tboxfile
set orignName = #{orignName,jdbcType=VARCHAR},
newName = #{newName,jdbcType=VARCHAR},
filePath = #{filePath,jdbcType=VARCHAR},
size = #{size,jdbcType=VARCHAR},
md5 = #{md5,jdbcType=VARCHAR},
state = #{state,jdbcType=INTEGER},
updateTime = #{updateTime,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update> -->
</mapper>

PackageMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hcxy.car.mapper.PackageMapper" > <resultMap id="BaseResult" type="pack" >
<id column="pid" property="pid" jdbcType="INTEGER" />
<result column="device_type" property="deviceType" jdbcType="VARCHAR" />
<result column="car_model" property="carModel" jdbcType="VARCHAR" />
<result column="package_version" property="packageVersion" jdbcType="VARCHAR" />
<result column="state" property="state" jdbcType="INTEGER" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="update_time" property="updateTime" jdbcType="VARCHAR" />
<!-- </resultMap>
<resultMap type="pack" id="FilesResult" extends="BaseResult"> -->
<collection property="files" ofType="packFile" javaType="ArrayList">
<id property="fid" column="fid" />
<result property="orignName" column="orignName" />
<result property="newName" column="newName" />
<result property="filePath" column="filePath" />
<result property="size" column="size" />
<result property="md5" column="md5" />
</collection>
</resultMap>
<!-- javaType="ArrayList" select="getPackFiles" -->
<sql id="Base_Column" >
pid, device_type, car_model,package_version, state, description,update_time
</sql>
<!-- 请求所有的升级包列表 -->
<select id="selectAllFiles" resultMap="BaseResult">
select p.pid,
p.device_type,
p.car_model,
p.package_version,
p.state,
p.description,
p.update_time,
f.fid ,
f.orign_name as orignName,
f.new_name as newName,
f.file_path as filePath,
f.size,
f.md5
from t_package p
left join t_package_file pf on pf.package_id=p.pid
left join t_file f on pf.file_id=f.fid where p.state!=2
</select> <select id="tboxselectByPrimaryKey" resultMap="BaseResult" parameterType="java.lang.Integer" >
select
<include refid="Base_Column" />
from t_package
where pid = #{pid,jdbcType=BIGINT}
</select> <select id="findByName" resultMap="BaseResult">
select *
from t_package
where device_type = #{arg0,jdbcType=VARCHAR} and car_model=#{arg1,jdbcType=VARCHAR}
and package_version=#{arg2,jdbcType=VARCHAR}
</select> <select id="findMore" resultMap="BaseResult">
select *
from t_package
where state = #{arg2,jdbcType=VARCHAR} and device_type = #{arg0,jdbcType=INTEGER} and car_model = #{arg1,jdbcType=INTEGER}
</select>
<!--
<select id="tboxselectAllTboxFile" resultMap="BaseResult">
select
<include refid="Base_Column" />
from t_package
</select> --> <!-- 根据tbox表中的id查询tbox和file信息 -->
<select id="selectALlFilesById" parameterType="int" resultMap="BaseResult">
select p.pid,p.device_type,p.car_model,p.package_version,p.state,p.description,p.update_time,
f.fid as fId,f.orign_name as Fo, f.new_name as fn,f.file_path as ff ,f.size as fs,f.md5 as fm
from t_package p left join t_package_file pf on p.pid=pf.package_id left join t_file f on pf.file_id=f.fid where p.pid = #{id} and p.state!=2
</select> <!-- <delete id="tboxdeleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from t_package
where pid = #{pid,jdbcType=BIGINT}
</delete> --> <insert id="addPackage" parameterType="pack" useGeneratedKeys="true" keyProperty="pid"> <!-- keyProperty="pid"是对象的属性id -->
<!-- <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="pid">
SELECT LAST_INSERT_ID()
</selectKey> -->
insert into t_package (device_type, car_model, package_version, state, description,update_time)
values (#{deviceType,jdbcType=VARCHAR}, #{carModel,jdbcType=VARCHAR},
#{packageVersion,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},
#{description,jdbcType=VARCHAR},#{updateTime,jdbcType=VARCHAR})
</insert> <!-- 保存用户和组之间的关系信息 -->
<insert id="saveRelativity" parameterType="com.hcxy.car.bean.pojo.PackageFileLink">
insert into t_package_file(package_id,file_id)
values(#{pack.pid},#{file.fid})
</insert> <!-- <insert id="insertSelectivetbox" parameterType="tbox" useGeneratedKeys="true" keyProperty="id">
insert into t_package
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="pid != null" >
pid,
</if>
<if test="fileType != null" >
fileType,
</if>
<if test="fileVersion != null" >
fileVersion,
</if>
<if test="state != null" >
state,
</if>
<if test="updateTime != null" >
updateTime,
</if>
<if test="description != null" >
description,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="pid != null" >
#{pid,jdbcType=BIGINT},
</if>
<if test="fileType != null" >
#{fileType,jdbcType=VARCHAR},
</if>
<if test="fileVersion != null" >
#{fileVersion,jdbcType=VARCHAR},
</if>
<if test="state != null" >
#{state,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=VARCHAR},
</if>
<if test="description != null" >
#{description,jdbcType=VARCHAR},
</if>
</trim>
</insert> --> <!-- <update id="updateByPrimaryKeySelectivetbox" parameterType="tbox" >
update t_package
<set >
<if test="fileType != null" >
fileType = #{fileType,jdbcType=VARCHAR},
</if>
<if test="fileVersion != null" >
fileVersion = #{fileVersion,jdbcType=VARCHAR},
</if>
<if test="state != null" >
state = #{state,jdbcType=BIGINT},
</if>
<if test="description != null" >
description = #{description,jdbcType=VARCHAR},
</if>
<if test="updateTime != null" >
updateTime = #{updateTime,jdbcType=VARCHAR},
</if>
</set>
where pid = #{pid,jdbcType=BIGINT}
</update> --> <!-- <update id="updateByPrimaryKeytbox" parameterType="tbox" >
update t_package
set fileType = #{fileType,jdbcType=VARCHAR},
fileVersion = #{fileVersion,jdbcType=VARCHAR},
state = #{state,jdbcType=INTEGER},
description = #{description,jdbcType=VARCHAR},
updateTime = #{updateTime,jdbcType=VARCHAR}
where pid = #{pid,jdbcType=BIGINT}
</update> --> <update id="modifyPackageByState">
update t_package
set state = #{arg1}
where pid = #{arg0}
</update>
</mapper>

application.yml

server:
port: 8086
servlet:
path: / spring:
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
http:
multipart:
enabled: true
max-file-size: -1
max-request-size: -1
resolve-lazily: false
file-size-threshold: 0
datasource:
url: jdbc:mysql://127.0.0.1:3306/upgrade?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=true
username: root
password:
# 使用druid数据源,
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.jdbc.Driver
filters: stat,wall,log4j
maxActive: 20
initialSize: 5
maxWait: 60000
minIdle: 5
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
maxPoolPreparedStatementPerConnectionSize: 20
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
jpa:
database: mysql
show-sql: true
hibernate:
#ddl-auto: update
naming:
strategy: org.hibernate.cfg.DefaultComponentSafeNamingStrategy
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
hbm2ddl:
auto: update mybatis:
mapper-locations: classpath:mapper/*.xml
#config-location: classpath:mybatis-config.xml
type-aliases-package: com.hcxy.car.bean #pagehelper
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql logging:
level:
com:
hcxy:
car:
mapper: DEBUG

tbox.sql

DROP TABLE IF EXISTS `t_package`;
--升级包表
CREATE TABLE `t_package` (
`pid` int unsigned not null primary key auto_increment,
`device_type` char(20) NOT NULL,
`car_model` char(20) NOT NULL,
`package_version` varchar(50) NOT NULL,
`state` char(1) NOT NULL,
`update_time` char(20) NOT NULL,
`description` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8; --文件表
DROP TABLE IF EXISTS `t_file`;
CREATE TABLE `t_file` (
`fid` int unsigned not null primary key auto_increment,
`orign_name` varchar(50) NOT NULL,
`new_name` varchar(150) NOT NULL,
`size` varchar(150) DEFAULT "",
`file_path` varchar(255) NOT NULL,
`md5` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ---中间表
DROP TABLE IF EXISTS `t_package_file`;
CREATE TABLE `t_package_file` (
`pfid` int unsigned NOT NULL primary key auto_increment,
`package_id` int unsigned NOT NULL,
`file_id` int unsigned NOT NULL,
CONSTRAINT `FK_package_ID3` FOREIGN KEY (`package_id`) REFERENCES `t_package` (`pid`),
CONSTRAINT `FK_file_ID3` FOREIGN KEY (`file_id`) REFERENCES `t_file` (`fid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; --设备类型表
DROP TABLE IF EXISTS `t_device_type`;
CREATE TABLE `t_device_type` (
`dtid` int unsigned not null primary key auto_increment,
`dtname` char(20) NOT NULL,
`description` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8; --车型表
DROP TABLE IF EXISTS `t_car_model`;
CREATE TABLE `t_car_model` (
`cmid` int unsigned not null primary key auto_increment,
`cname` char(20) NOT NULL,
`device_type_id` int unsigned NOT NULL,
CONSTRAINT `FK_device_type_ID` FOREIGN KEY (`device_type_id`) REFERENCES `t_device_type` (`dtid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; --设备表
DROP TABLE IF EXISTS `t_device`;
CREATE TABLE `t_device` (
`did` int NOT NULL primary key auto_increment,
`device_uuid` varchar(150) NOT NULL,
`device_type` char(20) NOT NULL,
`car_model` char(20),
`package_id` int unsigned,
`is_newset` char(1),
CONSTRAINT `FK_package` FOREIGN KEY (`package_id`) REFERENCES `t_package` (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; --下载记录表
DROP TABLE IF EXISTS `t_download_log`;
CREATE TABLE `t_download_log` (
`dlid` int NOT NULL primary key auto_increment,
`package_id` int unsigned not null,
`device_id` int NOT NULL,
`download_time` char(20),
`is_success` char(1),
CONSTRAINT `FK_package_ID1` FOREIGN KEY (`package_id`) REFERENCES `t_package` (`pid`),
CONSTRAINT `FK_device_ID` FOREIGN KEY (`device_id`) REFERENCES `t_device` (`did`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; --tsp推送记录
DROP TABLE IF EXISTS `t_tsp_push`;
CREATE TABLE `t_tsp_push` (
`tpid` int NOT NULL primary key auto_increment,
`package_id` int unsigned default null,
`date` char(20),
`message_body` text,
`is_success` char(1),
`type` char(20) not null,
CONSTRAINT `FK_package_ID2` FOREIGN KEY (`package_id`) REFERENCES `t_package` (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; --推送和设备中间表
DROP TABLE IF EXISTS `t_push_device`;
CREATE TABLE `t_push_device` (
`pdid` int NOT NULL primary key auto_increment,
`push_id` int NOT NULL,
`device_id` int NOT NULL,
CONSTRAINT `FK_push_ID` FOREIGN KEY (`push_id`) REFERENCES `t_tsp_push` (`tpid`),
CONSTRAINT `FK_device_ID2` FOREIGN KEY (`device_id`) REFERENCES `t_device` (`did`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `t_account`;
CREATE TABLE `t_account` (
`aid` int NOT NULL primary key auto_increment,
`user_name` char(20) NOT NULL,
`password` char(20) NOT NULL,
`sault` char(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `t_role`;
CREATE TABLE `t_role` (
`rid` int NOT NULL primary key auto_increment,
`r_name` char(20) NOT NULL,
`description` varchar(100) default ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `t_permission`;
CREATE TABLE `t_permission` (
`pid` int NOT NULL primary key auto_increment,
`p_name` char(20) NOT NULL,
`description` varchar(100) default ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `t_account_role`;
CREATE TABLE `t_account_role` (
`arid` int NOT NULL primary key auto_increment,
`account_id` int NOT NULL,
`role_id` int NOT NULL,
CONSTRAINT `FK_account_ID` FOREIGN KEY (`account_id`) REFERENCES `t_account` (`aid`),
CONSTRAINT `FK_role_ID2` FOREIGN KEY (`role_id`) REFERENCES `t_role` (`rid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `t_role_permission`;
CREATE TABLE `t_role_permission` (
`rpid` int NOT NULL primary key auto_increment,
`role_id` int NOT NULL,
`permission_id` int NOT NULL,
CONSTRAINT `FK_role_ID` FOREIGN KEY (`role_id`) REFERENCES `t_role` (`rid`),
CONSTRAINT `FK_permission_ID` FOREIGN KEY (`permission_id`) REFERENCES `t_permission` (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; //账号权限表
CREATE TABLE `t_account_permission` (
`apid` int NOT NULL primary key auto_increment,
`account_id` int NOT NULL,
`permission_id` int NOT NULL,
CONSTRAINT `FK_account_ID3` FOREIGN KEY (`account_id`) REFERENCES `t_account` (`aid`),
CONSTRAINT `FK_permission_ID3` FOREIGN KEY (`permission_id`) REFERENCES `t_permission` (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.12.RELEASE</version>
</parent>
<groupId>com.hcxy.car</groupId>
<artifactId>upgrade</artifactId>
<version>1.0.0-SNAPSHOT</version>
<!-- <packaging>war</packaging> -->
<packaging>jar</packaging>
<dependencies>
<!-- 单元测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency> <!-- Mybatis -->
<!-- <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId>
<version>3.2.8</version> </dependency> <dependency> <groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency> <!-- 分页助手 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.7.5</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>0.9.1</version>
</dependency>
<!--支持热启动-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>true</scope>
</dependency>
<!-- 阿里系的Druid数据源: -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.25</version>
</dependency> <!-- Spring Boot的JPA依赖包: -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- 通用Mapper -->
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>mapper</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.0</version>
</dependency>
<!-- MySqlDriver驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 连接池 -->
<!-- <dependency> <groupId>com.jolbox</groupId> <artifactId>bonecp-spring</artifactId>
<version>0.8.0.RELEASE</version> </dependency> --> <!-- httpclient -->
<!-- <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId>
</dependency> --> <!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency> <!-- Apache工具组件 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<!-- <dependency> <groupId>org.springframework.amqp</groupId> <artifactId>spring-rabbit</artifactId>
</dependency> --> <!-- <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId>
<version>2.5.3</version> <exclusions> <exclusion> 排除传递spring依赖 <artifactId>spring</artifactId>
<groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> --> <!-- <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId>
<version>3.3.3</version> </dependency> --> <!-- <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId>
<version>0.1</version> </dependency> -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.39</version>
</dependency>
</dependencies> <build>
<!-- <defaultGoal>compile</defaultGoal> -->
<plugins>
<!-- 资源文件拷贝插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--fork : 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build> </project>

springboot-vue项目后台2的更多相关文章

  1. Linux下 SpringBoot jar项目后台运行、查看、停用

    运行java jar: nohup java -jar **-0.0.1-SNAPSHOT.jar & 查看进程: 采用top或者ps aux命令.一般 如果后台是springboot,jar ...

  2. .gitignore 标准模板 -适用于SpringBoot+Vue项目 -Idea+VSCode开发

    .gitignore 标准模板 -适用于SpringBoot+Vue项目 node_modules/ target/ !.mvn/wrapper/maven-wrapper.jar ### STS # ...

  3. 【占坑】IDEA从github 导入并运行 SpringBoot + VUE项目

    最近工程实践的项目内容是开发一个类似于博客和bbs论坛的系统,在github上找了一个类似的项目可以照着写一写.所以这里先占着坑,等把后端的数据库连接学完了再来填坑. github项目链接:githu ...

  4. linux下部署springboot vue项目

    使用的工具是 XFTP5 XSHELL5 docker pull gmaslowski/jdk 拉取jdk docker images 查询下载的镜像ID (如:390b58b1be42) docke ...

  5. SpringBoot+Vue项目上手

    博客 https://gitee.com/RoadsideParty/White-Jotter-Vue?_from=gitee_search UI框架 https://at-ui.github.io/ ...

  6. 使用vue+elementUI+springboot创建基础后台增删改查的管理页面--(1)

    目前这家公司前端用的是vue框架,由于在之前的公司很少涉及到前端内容,对其的了解也只是会使用js和jquery,所以..慢慢来吧. 在此之前需要先了解vue的大致语法和规则,可先前往官方文档进行学习h ...

  7. springboot部署多个vue项目

    在springboot下部署多个vue项目,只需要将vue打包成静态文件后,将其放在resources的静态文件夹下即可. 如下图:static目录下有三个vue的静态文件夹,分别为运营后台(admi ...

  8. SpringBoot + Vue + nginx项目部署(零基础带你部署)

    一.环境.工具 jdk1.8 maven spring-boot idea VSVode vue 百度网盘(vue+springboot+nginx源码): 链接:https://pan.baidu. ...

  9. docker 运行jenkins及vue项目与springboot项目(二.docker运行jenkins为自动打包运行做准备)

    docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...

  10. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑

    (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...

随机推荐

  1. gcc使用备忘

    本文为原创文章,转载请指明该文链接 Options Controling the kind of Output -x language 明确说明输入文件的编码语言,没有该选项的话, gcc 会根据输入 ...

  2. PHPWord使用方法

    官方文档  github地址 一.安装 直接使用composer安装,链接地址 composer require phpoffice/phpword 二.简单使用 require_once 'PhpO ...

  3. Python 双向链表 快速排序

    1.创建链表: from random import randint class DLinkedNode(object): def __init__(self, data=None, pre=None ...

  4. Web Services 概要

    WSDL WSDL 是基于 XML 的用来描述 Web services 以及如何访问它们的一种语言. WSDL 可描述 web service,连同用于 web service 的消息格式和协议的细 ...

  5. Servlet 客户端 HTTP 请求

    当浏览器请求网页时,它会向 Web 服务器发送特定信息,这些信息不能被直接读取,因为这些信息是作为 HTTP 请求的头的一部分进行传输的.您可以查看 HTTP 协议 了解更多相关信息. 以下是来自于浏 ...

  6. Python Socket 网络编程 (客户端的编程)

    Socket 是进程间通信的一种方式,它与其他进程间通信的一个主要不同是:它能实现不同主机间的进程间通信,我们网络上各种各样的服务大多都是基于 Socket 来完成通信的,例如我们每天浏览网页.QQ ...

  7. 【ask】webstorm调试node单个js文件

    The procedure falls into two parts: first we start an application as usual and then connect to it wi ...

  8. hdu 1534(差分约束+spfa求最长路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1534 思路:设s[i]表示工作i的开始时间,v[i]表示需要工作的时间,则完成时间为s[i]+v[i] ...

  9. ios [__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7a97d4c0'报错

    今天接口由get换成post,我去改进行登录但出现了这个错误,首先出错先看能不能与服务器交互,能不能获得数据,其次,获得的数据是不是你想要的,记住,首先出错要想到是自己的问题,还有就是程序崩了要学会自 ...

  10. ApiDoc 和 Swagger 接口文档

    ApiDoc:https://blog.csdn.net/weixin_38682852/article/details/78812244 Swagger git: https://github.co ...