装备批量导入,导入模版下载,安全证书功能
This commit is contained in:
parent
557aae7778
commit
c94f3d2d0a
|
|
@ -9,19 +9,26 @@ import com.bonus.common.core.utils.poi.ExcelUtil;
|
|||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.device.domain.DevInfo;
|
||||
import com.bonus.material.device.domain.dto.DevInfoImpDto;
|
||||
import com.bonus.material.device.domain.dto.InfoMotionDto;
|
||||
import com.bonus.material.device.domain.vo.DevInfoVo;
|
||||
import com.bonus.material.device.service.DevInfoService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.java.Log;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
|
@ -193,4 +200,33 @@ public class DevInfoController extends BaseController {
|
|||
util.exportExcel(response, list, "设备信息数据");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "装备批量录入")
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
|
||||
String fileName = file.getOriginalFilename();
|
||||
if (fileName != null) {
|
||||
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
long fileSize = file.getSize();
|
||||
if (!fileExtension.equalsIgnoreCase("xls") && !fileExtension.equalsIgnoreCase("xlsx")) {
|
||||
// 文件后缀名不符合要求
|
||||
return error("文件后缀名不符合要求");
|
||||
} else if (fileSize > 10 * 1024 * 1024) {
|
||||
// 文件大小超过10M
|
||||
return error("文件大小超过10M");
|
||||
}
|
||||
}
|
||||
ExcelUtil<DevInfoImpDto> util = new ExcelUtil<DevInfoImpDto>(DevInfoImpDto.class);
|
||||
List<DevInfoImpDto> maPropInfoList = util.importExcel(file.getInputStream());
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
String message = devInfoService.importMaProp(maPropInfoList, updateSupport, userId);
|
||||
return success(message);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "装备模版下载")
|
||||
@PostMapping("/downLoad")
|
||||
public void downLoadExcelFile() throws IOException {
|
||||
HttpServletResponse resp = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
||||
devInfoService.downLoadTemplate(resp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package com.bonus.material.device.controller;
|
||||
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.device.domain.SafeBookInfo;
|
||||
import com.bonus.material.device.service.SafeBookService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/12/4 - 16:24
|
||||
*/
|
||||
public class SafeBookController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private SafeBookService safeBookService;
|
||||
|
||||
@ApiOperation(value = "查询安全证书")
|
||||
@GetMapping("/getSafeBookByMaId")
|
||||
public AjaxResult getSafeBookByMaId(SafeBookInfo safeBookInfo) {
|
||||
startPage();
|
||||
List<SafeBookInfo> list = safeBookService.getSafeBookByMaId(safeBookInfo);
|
||||
return AjaxResult.success(getDataTable(list));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增安全证书")
|
||||
@PostMapping("/addSafeBook")
|
||||
public AjaxResult addSafeBook(SafeBookInfo safeBookInfo) {
|
||||
Integer i = safeBookService.addSafeBook(safeBookInfo);
|
||||
if (i > 0) {
|
||||
return AjaxResult.success("新增成功");
|
||||
} else {
|
||||
return AjaxResult.error("新增失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "删除安全证书")
|
||||
@PostMapping("/delSafeBook")
|
||||
public AjaxResult delSafeBook(SafeBookInfo safeBookInfo) {
|
||||
Integer i = safeBookService.delSafeBook(safeBookInfo);
|
||||
if (i > 0) {
|
||||
return AjaxResult.success("删除成功");
|
||||
} else {
|
||||
return AjaxResult.error("删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -119,7 +119,8 @@ public class DevInfo extends BaseEntity {
|
|||
@Excel(name = "出厂日期")
|
||||
@ApiModelProperty(value = "出厂日期")
|
||||
@NotBlank
|
||||
private String productionDate;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||
private Date productionDate;
|
||||
|
||||
/** 工作时长 */
|
||||
@Excel(name = "工作时长")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package com.bonus.material.device.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/12/4 - 16:22
|
||||
*/
|
||||
@Data
|
||||
public class SafeBookInfo {
|
||||
@ApiModelProperty(value = "主键id")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "证书编号")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "关联装备")
|
||||
private Integer maId;
|
||||
|
||||
@ApiModelProperty(value = "证书附件")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(value = "上传人Id")
|
||||
private Long uploadPerson;
|
||||
|
||||
@ApiModelProperty(value = "上传时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
|
||||
private String startTime;
|
||||
|
||||
private String endTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package com.bonus.material.device.domain.dto;
|
||||
|
||||
import com.bonus.common.core.annotation.Excel;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/12/4 - 13:59
|
||||
*/
|
||||
@Data
|
||||
public class DevInfoImpDto {
|
||||
|
||||
/** 设备编码 */
|
||||
@ApiModelProperty(value = "设备编码")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "装备名称")
|
||||
@Excel(name = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
/** 设备品牌 */
|
||||
@Excel(name = "设备品牌")
|
||||
@ApiModelProperty(value = "设备品牌")
|
||||
private String brand;
|
||||
|
||||
@Excel(name = "出厂日期")
|
||||
@ApiModelProperty(value = "出厂日期")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private Date productionDate;
|
||||
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private Long creator;
|
||||
|
||||
@ApiModelProperty(value = "联系人")
|
||||
@Excel(name = "联系人")
|
||||
private String person;
|
||||
|
||||
@ApiModelProperty(value = "联系电话")
|
||||
@Excel(name = "联系电话")
|
||||
@Size(min = 11, max = 11, message = "手机号长度不能超过11位")
|
||||
private String personPhone;
|
||||
|
||||
@ApiModelProperty(value = "整机装备重量(kg)")
|
||||
@Excel(name = "整机装备重量(kg)")
|
||||
private String deviceWeight;
|
||||
|
||||
@ApiModelProperty(value = "上传人Id")
|
||||
private Long ownId;
|
||||
|
||||
@ApiModelProperty(value = "校验日期")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "校验日期")
|
||||
private Date checkDate;
|
||||
|
||||
@ApiModelProperty(value = "校验周期(月)")
|
||||
@Excel(name = "校验周期(月)")
|
||||
private Integer checkCycle;
|
||||
|
||||
@ApiModelProperty(value = "设备状态")
|
||||
private Integer maStatus;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.bonus.material.device.mapper;
|
||||
|
||||
import com.bonus.material.device.domain.SafeBookInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/12/4 - 16:41
|
||||
*/
|
||||
public interface SafeBookMapper {
|
||||
public List<SafeBookInfo> getSafeBookByMaId(SafeBookInfo safeBookInfo);
|
||||
|
||||
Integer addSafeBook(SafeBookInfo safeBookInfo);
|
||||
|
||||
String selectTaskNumByMonth(@Param("date") Date nowDate);
|
||||
|
||||
Integer delSafeBook(SafeBookInfo safeBookInfo);
|
||||
}
|
||||
|
|
@ -4,9 +4,11 @@ package com.bonus.material.device.service;
|
|||
import com.bonus.common.biz.domain.BmCompanyInfo;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.device.domain.DevInfo;
|
||||
import com.bonus.material.device.domain.dto.DevInfoImpDto;
|
||||
import com.bonus.material.device.domain.dto.InfoMotionDto;
|
||||
import com.bonus.material.device.domain.vo.DevInfoVo;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -97,4 +99,8 @@ public interface DevInfoService {
|
|||
List<BmCompanyInfo> selectCompanyList(BmCompanyInfo obj);
|
||||
|
||||
AjaxResult updateUpDown(DevInfo devInfo);
|
||||
|
||||
String importMaProp(List<DevInfoImpDto> maPropInfoList, boolean updateSupport, Long operName);
|
||||
|
||||
void downLoadTemplate(HttpServletResponse resp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.bonus.material.device.service;
|
||||
|
||||
import com.bonus.material.device.domain.SafeBookInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/12/4 - 16:36
|
||||
*/
|
||||
public interface SafeBookService {
|
||||
|
||||
List<SafeBookInfo> getSafeBookByMaId(SafeBookInfo safeBookInfo);
|
||||
|
||||
Integer addSafeBook(SafeBookInfo safeBookInfo);
|
||||
|
||||
Integer delSafeBook(SafeBookInfo safeBookInfo);
|
||||
}
|
||||
|
|
@ -8,10 +8,12 @@ import com.bonus.common.core.exception.ServiceException;
|
|||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.bean.BeanUtils;
|
||||
import com.bonus.common.core.utils.bean.BeanValidators;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.book.domain.BookCarInfoDto;
|
||||
import com.bonus.material.device.domain.DevInfo;
|
||||
import com.bonus.material.device.domain.dto.DevInfoImpDto;
|
||||
import com.bonus.material.device.domain.dto.InfoMotionDto;
|
||||
import com.bonus.material.device.domain.vo.DevInfoVo;
|
||||
import com.bonus.material.device.domain.vo.DevNameVo;
|
||||
|
|
@ -23,12 +25,19 @@ import com.bonus.system.api.model.LoginUser;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Validator;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -41,6 +50,7 @@ import static com.bonus.common.biz.enums.MaStatusEnum.*;
|
|||
* @author syruan
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DevInfoServiceImpl implements DevInfoService {
|
||||
// 装备主展示图片字典
|
||||
private final Integer MAIN_IMAGES_DICT_VALUE = 0;
|
||||
|
|
@ -60,6 +70,9 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
@Resource
|
||||
private BmFileInfoMapper bmFileInfoMapper;
|
||||
|
||||
@Resource
|
||||
protected Validator validator;
|
||||
|
||||
/**
|
||||
* 查询设备信息
|
||||
*
|
||||
|
|
@ -129,6 +142,7 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
|
||||
/**
|
||||
* 更新设备搜索量
|
||||
*
|
||||
* @param maId
|
||||
*/
|
||||
private void updateHotSearch(Long maId) {
|
||||
|
|
@ -222,6 +236,7 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
|
||||
/**
|
||||
* 提取主图文件地址,方便用于列表页面回显
|
||||
*
|
||||
* @param hotList
|
||||
*/
|
||||
private void extractedFile(List<DevInfoVo> hotList) {
|
||||
|
|
@ -320,7 +335,9 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
}
|
||||
//把文件保存到附件中
|
||||
AjaxResult error = uploadFiles(devInfo, userId);
|
||||
if (error != null) {return error;}
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
return AjaxResult.success("保存成功");
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +364,9 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
return AjaxResult.error("装备草稿保存失败,请修改后重试");
|
||||
}
|
||||
AjaxResult error = uploadFiles(devInfo, userId);
|
||||
if (error != null) {return error;}
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("装备草稿保存失败,执行异常:" + e.getMessage());
|
||||
}
|
||||
|
|
@ -356,6 +375,7 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
|
||||
/**
|
||||
* 物资设备文件处理并上传
|
||||
*
|
||||
* @param devInfo 设备附件对象
|
||||
* @param userId 用户ID
|
||||
* @return 无异常返回null ,报错返回AjaxResult
|
||||
|
|
@ -545,13 +565,19 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
// 根据旧状态和新状态进行状态转换检查
|
||||
switch (dto.getMaStatus()) {
|
||||
case 0:
|
||||
if (newStatus.equals(TO_BE_LISTED.getCode()) || newStatus.equals(ON_HIRE.getCode())) {continue;}
|
||||
if (newStatus.equals(TO_BE_LISTED.getCode()) || newStatus.equals(ON_HIRE.getCode())) {
|
||||
continue;
|
||||
}
|
||||
return AjaxResult.warn("设备ID:" + maId + "是草稿状态,只能进行保存操作:" + newStatus);
|
||||
case 1:
|
||||
if (newStatus.equals(LISTING.getCode()) || newStatus.equals(ON_HIRE.getCode())) {continue;}
|
||||
if (newStatus.equals(LISTING.getCode()) || newStatus.equals(ON_HIRE.getCode())) {
|
||||
continue;
|
||||
}
|
||||
return AjaxResult.warn("设备ID:" + maId + "已下架,只能进行上下架操作!");
|
||||
case 2:
|
||||
if (newStatus.equals(ON_HIRE.getCode()) || newStatus.equals(LISTING.getCode())) {continue;}
|
||||
if (newStatus.equals(ON_HIRE.getCode()) || newStatus.equals(LISTING.getCode())) {
|
||||
continue;
|
||||
}
|
||||
return AjaxResult.warn("设备ID:" + maId + "设备已上架,只能进行上下架操作!!");
|
||||
case 3:
|
||||
return AjaxResult.warn("设备ID:" + maId + "设备已出租,非法状态修改!!");
|
||||
|
|
@ -570,6 +596,71 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
return AjaxResult.success("操作成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String importMaProp(List<DevInfoImpDto> maPropInfoList, boolean updateSupport, Long userId) {
|
||||
if (StringUtils.isNull(maPropInfoList) || maPropInfoList.size() == 0) {
|
||||
throw new ServiceException("导入的数据不能为空!");
|
||||
}
|
||||
int successNum = 0;
|
||||
int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
for (DevInfoImpDto devInfo : maPropInfoList) {
|
||||
try {
|
||||
BeanValidators.validateWithException(validator, devInfo);
|
||||
devInfo.setCreator(userId);
|
||||
devInfo.setOwnId(userId);
|
||||
devInfo.setCode(getString());
|
||||
DevInfo devInfo1 = new DevInfo();
|
||||
BeanUtils.copyProperties(devInfo, devInfo1);
|
||||
devInfo1.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId().toString());
|
||||
devInfo1.setMaStatus(0);
|
||||
devInfoMapper.insertDevInfo(devInfo1);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、资产名称 " + devInfo.getDeviceName() + " 导入成功");
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、资产名称 " + devInfo.getDeviceName() + " 导入失败:";
|
||||
failureMsg.append(msg + e.getMessage());
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
if (failureNum > 0) {
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
} else {
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downLoadTemplate(HttpServletResponse response) {
|
||||
String templateName = "template.xlsx";
|
||||
OutputStream out = null;
|
||||
InputStream input = null;
|
||||
try {
|
||||
input = this.getClass().getClassLoader().getResourceAsStream("template/template.xlsx");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("content-Type", "application/vnd.ms-excel");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + new String((templateName).getBytes(), "iso-8859-1"));
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
out = response.getOutputStream();
|
||||
byte[] buffer = new byte[1024]; // 缓冲区
|
||||
int bytesToRead = -1;
|
||||
// 通过循环将读入内容输出到浏览器中
|
||||
while ((bytesToRead = input.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesToRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertOutType(String devInfo) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
|
@ -589,7 +680,7 @@ public class DevInfoServiceImpl implements DevInfoService {
|
|||
//设备型号
|
||||
String modelName = (String) map.get("modelName");
|
||||
//出厂日期
|
||||
String outFacTime = (String) map.get("outFacTime");
|
||||
Date outFacTime = (Date) map.get("outFacTime");
|
||||
DevInfo devInfo1 = new DevInfo();
|
||||
devInfo1.setCreateTime(new Date());
|
||||
//获取用户信息
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package com.bonus.material.device.service.impl;
|
||||
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.device.domain.SafeBookInfo;
|
||||
import com.bonus.material.device.mapper.SafeBookMapper;
|
||||
import com.bonus.material.device.service.SafeBookService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/12/4 - 16:37
|
||||
*/
|
||||
@Service
|
||||
public class SafeBookServiceImpl implements SafeBookService {
|
||||
|
||||
@Resource
|
||||
private SafeBookMapper safeBookMapper;
|
||||
@Override
|
||||
public List<SafeBookInfo> getSafeBookByMaId(SafeBookInfo safeBookInfo) {
|
||||
return safeBookMapper.getSafeBookByMaId(safeBookInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer addSafeBook(SafeBookInfo safeBookInfo) {
|
||||
safeBookInfo.setCode(getString());
|
||||
safeBookInfo.setUploadPerson(SecurityUtils.getLoginUser().getUserid());
|
||||
return safeBookMapper.addSafeBook(safeBookInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer delSafeBook(SafeBookInfo safeBookInfo) {
|
||||
return safeBookMapper.delSafeBook(safeBookInfo);
|
||||
}
|
||||
|
||||
private String getString() {
|
||||
//根据前台传过来的数据,生成需求编号
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
Date nowDate = DateUtils.getNowDate();
|
||||
String format = dateFormat.format(nowDate);
|
||||
String taskNum = safeBookMapper.selectTaskNumByMonth(nowDate);
|
||||
if (StringUtils.isNotBlank(taskNum)) {
|
||||
// 将字符串转换为整数
|
||||
int num = Integer.parseInt(taskNum);
|
||||
// 执行加一操作
|
||||
num++;
|
||||
// 将结果转换回字符串格式,并确保结果是4位数,不足4位则在前面补0
|
||||
taskNum = String.format("%04d", num);
|
||||
} else {
|
||||
taskNum = "0001";
|
||||
}
|
||||
return format + "-" + taskNum;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="deviceCount != null">device_count,</if>
|
||||
<if test="code != null and code != '' ">code,</if>
|
||||
<if test="typeId != null and typeId != ''">type_id,</if>
|
||||
<if test="maStatus != null and maStatus != ''">ma_status,</if>
|
||||
<if test="maStatus != null">ma_status,</if>
|
||||
<if test="leaseScope != null and leaseScope != ''">lease_scope,</if>
|
||||
<if test="location != null and location != ''" >location,</if>
|
||||
<if test="provinceId != null and provinceId != ''">province_id,</if>
|
||||
|
|
@ -275,7 +275,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="areaId != null and areaId != ''">area_id,</if>
|
||||
<if test="brand != null and brand != ''">brand,</if>
|
||||
<if test="modelName != null and modelName != ''">model_name,</if>
|
||||
<if test="productionDate != null and productionDate != ''">production_date,</if>
|
||||
<if test="productionDate != null">production_date,</if>
|
||||
<if test="workingHours != null and workingHours != ''">working_hours,</if>
|
||||
<if test="serialNumber != null and serialNumber != ''">serial_number,</if>
|
||||
<if test="picUrl != null and picUrl != ''">pic_url,</if>
|
||||
|
|
@ -305,7 +305,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="deviceCount != null">#{deviceCount},</if>
|
||||
<if test="code != null and code != ''">#{code},</if>
|
||||
<if test="typeId != null and typeId != ''">#{typeId},</if>
|
||||
<if test="maStatus != null and maStatus != ''">#{maStatus},</if>
|
||||
<if test="maStatus != null">#{maStatus},</if>
|
||||
<if test="leaseScope != null and leaseScope != ''">#{leaseScope},</if>
|
||||
<if test="location != null and location != ''">#{location},</if>
|
||||
<if test="provinceId != null and provinceId != ''">#{provinceId},</if>
|
||||
|
|
@ -313,7 +313,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="areaId != null and areaId != ''">#{areaId},</if>
|
||||
<if test="brand != null and brand != ''">#{brand},</if>
|
||||
<if test="modelName != null and modelName != ''">#{modelName},</if>
|
||||
<if test="productionDate != null and productionDate != ''">#{productionDate},</if>
|
||||
<if test="productionDate != null">#{productionDate},</if>
|
||||
<if test="workingHours != null and workingHours != ''">#{workingHours},</if>
|
||||
<if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
|
||||
<if test="picUrl != null and picUrl != ''">#{picUrl},</if>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?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.bonus.material.device.mapper.SafeBookMapper">
|
||||
<insert id="addSafeBook">
|
||||
insert into safe_book(code,ma_id,url,upload_person,create_time)
|
||||
values(#{code},#{maId},#{url},#{uploadPerson},now())
|
||||
</insert>
|
||||
|
||||
<delete id="delSafeBook">
|
||||
delete from safe_book where id = #{id}
|
||||
</delete>
|
||||
|
||||
<select id="getSafeBookByMaId" resultType="com.bonus.material.device.domain.SafeBookInfo">
|
||||
select id,code,ma_id,url,upload_person,create_time,update_time from safe_book where ma_id = #{maId}
|
||||
<if test="code != null and code != ''">
|
||||
and code like concat('%',#{code},'%')
|
||||
</if>
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
AND create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectTaskNumByMonth" resultType="java.lang.String">
|
||||
SELECT SUBSTRING(lease_code, - 4) as code
|
||||
FROM safe_book
|
||||
WHERE DATE_FORMAT(create_time, '%y%m') = DATE_FORMAT(#{date}, '%y%m')
|
||||
ORDER BY create_time DESC LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
Binary file not shown.
Loading…
Reference in New Issue