package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.SoftwareMapper;
|
import com.whyc.pojo.Software;
|
import com.whyc.pojo.User;
|
import com.whyc.util.CommonUtil;
|
import com.whyc.util.UserUtil;
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class SoftwareService {
|
|
@Resource
|
private SoftwareMapper mapper;
|
|
|
public Response upgradeApply(Software software) {
|
software.setCreateTime(new Date());
|
mapper.insert(software);
|
return new Response().setII(1,"申请完成");
|
}
|
|
public Response upload(MultipartFile file, int id) throws IOException {
|
User user = UserUtil.getUser();
|
String fileName = file.getOriginalFilename();
|
//根据id获取软件包信息
|
Software software = mapper.selectById(id);
|
//上传路径定义和http路径定义
|
String rootFile = CommonUtil.getRootFile();
|
//路径为/battery_gwm_file/software/序列号_SN编码_版本号/文件名
|
//String softwareDir = rootFile + "software";
|
String softwareDir = rootFile + "software" + File.separator + software.getSerialNumber() + "_" + software.getSnCode() + "_" + software.getVersion();
|
|
String softwareHttpUrl = softwareDir.substring(softwareDir.lastIndexOf("battery_gwm_file"+ File.separator + "software"));
|
File softwareDirFile = new File(softwareDir);
|
if(!softwareDirFile.exists()){
|
softwareDirFile.mkdirs();
|
}
|
//上传
|
file.transferTo(new File(softwareDir + File.separator + fileName));
|
//更新上传的软件信息
|
Date now = new Date();
|
software.setCreateTime(now);
|
software.setUploadUserId(user.getId());
|
software.setUploadUserName(user.getName());
|
software.setFileUrl(softwareHttpUrl + File.separator +fileName);
|
software.setFileName(fileName);
|
|
mapper.updateById(software);
|
|
return new Response().setII(1,"上传完成");
|
}
|
|
public Response getPage(int pageNum, int pageSize, String snCode, String serialNumber, String materialCode) {
|
PageHelper.startPage(pageNum, pageSize);
|
QueryWrapper<Software> query = Wrappers.query();
|
if (snCode != null && !snCode.equals("")) {
|
query.eq("sn_code", snCode);
|
}
|
if (serialNumber != null && !serialNumber.equals("")) {
|
query.eq("serial_number", serialNumber);
|
}
|
if (materialCode != null && !materialCode.equals("")) {
|
query.eq("material_code", materialCode);
|
}
|
query.orderByDesc("id");
|
List<Software> list = mapper.selectList(query);
|
PageInfo<Software> pageInfo = new PageInfo<>(list);
|
return new Response().set(1, pageInfo);
|
}
|
|
public Response getSnCodeList() {
|
QueryWrapper<Software> query = Wrappers.query();
|
query.select("sn_code");
|
List<String> snCodeList = mapper.selectList(query).stream().map(Software::getSnCode).collect(Collectors.toList());
|
return new Response().set(1, snCodeList);
|
|
}
|
|
public Response getSerialNumberList() {
|
QueryWrapper<Software> query = Wrappers.query();
|
query.select("serial_number");
|
List<String> serialNumberList = mapper.selectList(query).stream().map(Software::getSerialNumber).collect(Collectors.toList());
|
return new Response().set(1, serialNumberList);
|
}
|
|
public Response getMaterialCodeList() {
|
QueryWrapper<Software> query = Wrappers.query();
|
query.select("material_code");
|
List<String> materialCodeList = mapper.selectList(query).stream().map(Software::getMaterialCode).collect(Collectors.toList());
|
return new Response().set(1, materialCodeList);
|
}
|
|
public List<Software> getSendList() {
|
QueryWrapper<Software> query = Wrappers.query();
|
query.eq("mail_st", 0);
|
return mapper.selectList(query);
|
}
|
|
public void updateMailStatus(Integer id) {
|
Software software = new Software();
|
software.setMailSt(1);
|
software.setSendTime(new Date());
|
software.setId(id);
|
mapper.updateById(software);
|
}
|
}
|