|
@@ -6,22 +6,36 @@ import com.github.pagehelper.PageInfo;
|
|
|
import com.hssx.cloudmodel.constant.Constant;
|
|
|
import com.hssx.cloudmodel.entity.Mould;
|
|
|
import com.hssx.cloudmodel.entity.MouldEquipment;
|
|
|
+import com.hssx.cloudmodel.entity.Part;
|
|
|
import com.hssx.cloudmodel.entity.User;
|
|
|
import com.hssx.cloudmodel.entity.vo.MouldEquipmentVO;
|
|
|
+import com.hssx.cloudmodel.entity.vo.UserVO;
|
|
|
import com.hssx.cloudmodel.mapper.MouldEquipmentMapper;
|
|
|
import com.hssx.cloudmodel.mapper.MouldMapper;
|
|
|
+import com.hssx.cloudmodel.mapper.UserMapper;
|
|
|
import com.hssx.cloudmodel.service.MouldEquipmentService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.hssx.cloudmodel.util.HttpRespMsg;
|
|
|
import com.hssx.cloudmodel.util.PageUtil;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -37,6 +51,8 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
|
|
|
MouldEquipmentMapper mouldEquipmentMapper;
|
|
|
@Resource
|
|
|
MouldMapper mouldMapper;
|
|
|
+ @Resource
|
|
|
+ UserMapper userMapper;
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg addAndUpdateMouldEquipment(MouldEquipment mouldEquipment, User user) {
|
|
@@ -85,12 +101,12 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg getList(User user, PageUtil page,Integer companyId,String keyName) {
|
|
|
+ public HttpRespMsg getList(User user, PageUtil page, Integer companyId, String keyName) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
if (user != null) {
|
|
|
if (Constant.SYS_PARENT_ID == user.getParentId()) {
|
|
|
PageHelper.startPage(page.getPageNum(), page.getPageSize());
|
|
|
- List<MouldEquipmentVO> mouldEquipments = mouldEquipmentMapper.getList(companyId,keyName);
|
|
|
+ List<MouldEquipmentVO> mouldEquipments = mouldEquipmentMapper.getList(companyId, keyName);
|
|
|
PageInfo<MouldEquipmentVO> pageInfo = new PageInfo<>(mouldEquipments);
|
|
|
msg.data = pageInfo;
|
|
|
} else {
|
|
@@ -103,21 +119,112 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
|
|
|
@Override
|
|
|
public HttpRespMsg getListByCompanyId(MouldEquipmentVO mouldEquipmentVO) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
- List<Integer> ides = new ArrayList<>();
|
|
|
- List<Mould> moulds = mouldMapper.selectList(new QueryWrapper<Mould>().eq("company_id", mouldEquipmentVO.getBelongCompanyId()));
|
|
|
- if(null == mouldEquipmentVO.getMouldId()){
|
|
|
- mouldEquipmentVO.setMouldId(-1);
|
|
|
- }
|
|
|
- for (Mould mould : moulds) {
|
|
|
- if(mould.getId() != mouldEquipmentVO.getMouldId()){
|
|
|
- ides.add(mould.getEquipmentId());
|
|
|
+ List<Integer> mouldsEquipmentIds = mouldMapper.selectList(new QueryWrapper<Mould>().eq("company_id", mouldEquipmentVO.getBelongCompanyId()).isNotNull("equipment_id")).stream().map(Mould::getEquipmentId).collect(Collectors.toList());
|
|
|
+ mouldsEquipmentIds.add(-1);
|
|
|
+ List<Integer> equipmentIds = mouldEquipmentMapper.selectList(new QueryWrapper<MouldEquipment>().eq("belong_company_id", mouldEquipmentVO.getBelongCompanyId())).stream().map(MouldEquipment::getId).collect(Collectors.toList());
|
|
|
+ equipmentIds.add(-1);
|
|
|
+ equipmentIds.removeAll(mouldsEquipmentIds);//把已经使用的设备剔除
|
|
|
+ List<MouldEquipmentVO> list = mouldEquipmentMapper.getListByCompanyId(mouldEquipmentVO.getBelongCompanyId(), equipmentIds);
|
|
|
+ msg.data = list;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg MouldEquipmentAlarm() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg importMouldEquipmentExcel(MultipartFile file, UserVO userVO) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
+ if (user != null) {
|
|
|
+ List<MouldEquipment> mouldEquipments = mouldEquipmentMapper.selectList(new QueryWrapper<MouldEquipment>());
|
|
|
+ try {
|
|
|
+ File f = null;
|
|
|
+ if ("".equals(file) || file.getSize() <= 0) {
|
|
|
+ file = null;
|
|
|
+ } else {
|
|
|
+ //获取输入流
|
|
|
+ InputStream ins = file.getInputStream();
|
|
|
+ //新建一个文件
|
|
|
+ f = new File(file.getOriginalFilename());
|
|
|
+ //输入流转file
|
|
|
+ inputStreamToFile(ins, f);
|
|
|
+ }
|
|
|
+ //根据文件创建工作簿
|
|
|
+ XSSFWorkbook wookbook = new XSSFWorkbook(f);
|
|
|
+ XSSFSheet sheet = wookbook.getSheetAt(0);
|
|
|
+ int s = sheet.getLastRowNum();
|
|
|
+ // 遍历当前sheet中的所有行,第一行是数据对应的字段,不是数据,
|
|
|
+ // 故从第二行开始遍历拿数据(如果有标题的话,则从第三行开始拿数据)
|
|
|
+ for (int j = 1; j < sheet.getLastRowNum() + 1; j++) {
|
|
|
+ XSSFRow row = sheet.getRow(j);
|
|
|
+ //新建云模盒对象
|
|
|
+ MouldEquipment mouldEquipment = new MouldEquipment();
|
|
|
+ // 遍历所有的列,下面的10是excle表格里共有10列即对应了10个字段
|
|
|
+ for (int y = 0; y < 3; y++) {
|
|
|
+ XSSFCell cell = row.getCell(y);
|
|
|
+ cell.setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ //取出当前列的值
|
|
|
+ String value = cell.getStringCellValue();
|
|
|
+ //判断第几列插入数据,后面就是从列中取数据往对象里放,然后插入到数据库里
|
|
|
+ if (value == null && "".equals(value)) {
|
|
|
+ log.error("数据不可为空");
|
|
|
+ msg.setError("数据不可为空");
|
|
|
+ return msg;
|
|
|
+ } else if (y == 0) {
|
|
|
+ //云模编号
|
|
|
+ for (MouldEquipment p : mouldEquipments) {
|
|
|
+ if (value.equals(p.getEquipmentNo())) {
|
|
|
+ msg.setError("第" + j + "行的云模盒编号:" + value + "已被占用,请修改后重新上传");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mouldEquipment.setEquipmentNo(value);
|
|
|
+ } else if (y == 1) {
|
|
|
+ //使用年限
|
|
|
+ mouldEquipment.setUseLife(Integer.parseInt(value));
|
|
|
+ } else if (y == 2) {
|
|
|
+ //代理商
|
|
|
+ mouldEquipment.setAgent(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mouldEquipmentMapper.insert(mouldEquipment);
|
|
|
+ }
|
|
|
+ //用完后删除临时文件
|
|
|
+ if (!f.isDirectory()) {
|
|
|
+ f.delete();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ msg.setError(e.getMessage());
|
|
|
+ return msg;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ msg.setError("用户不存在或者未登录");
|
|
|
}
|
|
|
- if (ides.size() == 0) {
|
|
|
- ides.add(-1);
|
|
|
- }
|
|
|
- List<MouldEquipmentVO> list = mouldEquipmentMapper.getListByCompanyId(mouldEquipmentVO.getBelongCompanyId(), ides);
|
|
|
- msg.data = list;
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输入流转file
|
|
|
+ *
|
|
|
+ * @param ins
|
|
|
+ * @param file
|
|
|
+ */
|
|
|
+ public static void inputStreamToFile(InputStream ins, File file) {
|
|
|
+ try {
|
|
|
+ OutputStream os = new FileOutputStream(file);
|
|
|
+ int bytesRead = 0;
|
|
|
+ byte[] buffer = new byte[8192];
|
|
|
+ while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
|
|
|
+ os.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ os.close();
|
|
|
+ ins.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|