diff --git a/ruoyi-basetyre/pom.xml b/ruoyi-basetyre/pom.xml index 64ae43e..fd7afa7 100644 --- a/ruoyi-basetyre/pom.xml +++ b/ruoyi-basetyre/pom.xml @@ -27,6 +27,10 @@ 1.6.2 compile + + com.ruoyi + ruoyi-system + \ No newline at end of file diff --git a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/controller/BaseTyreController.java b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/controller/BaseTyreController.java index 208d7a2..e2ef282 100644 --- a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/controller/BaseTyreController.java +++ b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/controller/BaseTyreController.java @@ -7,12 +7,14 @@ import com.ruoyi.common.annotation.Log; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -43,6 +45,14 @@ public class BaseTyreController extends BaseController return getDataTable(list); } + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) + { + ExcelUtil util = new ExcelUtil(BaseTyre.class); + util.importTemplateExcel(response, "轮胎数据"); + } + + /** * 导出轮胎基础列表 */ @@ -55,6 +65,16 @@ public class BaseTyreController extends BaseController ExcelUtil util = new ExcelUtil(BaseTyre.class); util.exportExcel(response, list, "轮胎基础数据"); } + @Log(title = "轮胎管理", businessType = BusinessType.IMPORT) + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception + { + ExcelUtil util = new ExcelUtil(BaseTyre.class); + List baseTyreList = util.importExcel(file.getInputStream()); + String operName = getUsername(); + String message = baseTyreService.importTyre(baseTyreList, updateSupport, operName); + return success(message); + } /** * 获取轮胎基础详细信息 diff --git a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/domain/BaseTyre.java b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/domain/BaseTyre.java index 5049c6d..86a2497 100644 --- a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/domain/BaseTyre.java +++ b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/domain/BaseTyre.java @@ -150,19 +150,19 @@ public class BaseTyre extends BaseEntity private String produceFactory; /** 车辆ID */ - @Excel(name = "车辆ID") + private String carId; /** 车牌号 */ - @Excel(name = "车牌号") + private String carLicense; /** 轮位(拼四段式1-1-1-21)第一轴左侧外,总第21个胎 */ - @Excel(name = "轮位", readConverterExp = "拼=四段式1-1-1-21") +// @Excel(name = "轮位", readConverterExp = "拼=四段式1-1-1-21") private String tyrePosition; /** 当前轮胎传感器ID */ - @Excel(name = "当前轮胎传感器ID") +// @Excel(name = "当前轮胎传感器ID") private String sensorId; /** 当前花纹深度 */ @@ -170,36 +170,36 @@ public class BaseTyre extends BaseEntity private BigDecimal currentTextureDepth; /** 状态 */ - @Excel(name = "状态") +// @Excel(name = "状态") private Long state; /** 是否删除 */ - @Excel(name = "是否删除") +// @Excel(name = "是否删除") private Long isDelete; /** 创建者ID */ - @Excel(name = "创建者ID") +// @Excel(name = "创建者ID") private String createId; /** 创建者姓名 */ - @Excel(name = "创建者姓名") +// @Excel(name = "创建者姓名") private String createName; /** 修改时间 */ @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "修改时间", width = 30, dateFormat = "yyyy-MM-dd") +// @Excel(name = "修改时间", width = 30, dateFormat = "yyyy-MM-dd") private Date modifyTime; /** 修改者ID */ - @Excel(name = "修改者ID") +// @Excel(name = "修改者ID") private String modifyId; /** 修改者账号 */ - @Excel(name = "修改者账号") +// @Excel(name = "修改者账号") private String modifyBy; /** 编辑者姓名 */ - @Excel(name = "编辑者姓名") +// @Excel(name = "编辑者姓名") private String modifyName; public void setId(String id) diff --git a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/mapper/BaseTyreMapper.java b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/mapper/BaseTyreMapper.java index 8cb5d75..4cacfa0 100644 --- a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/mapper/BaseTyreMapper.java +++ b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/mapper/BaseTyreMapper.java @@ -48,6 +48,8 @@ public interface BaseTyreMapper */ public int updateBaseTyre(BaseTyre baseTyre); + public int updateBaseTyreByouterTireNumber(BaseTyre baseTyre); + /** * 删除轮胎基础 * diff --git a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/service/IBaseTyreService.java b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/service/IBaseTyreService.java index 707b8a6..7cdf8e7 100644 --- a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/service/IBaseTyreService.java +++ b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/service/IBaseTyreService.java @@ -47,6 +47,8 @@ public interface IBaseTyreService */ public int updateBaseTyre(BaseTyre baseTyre); + public int updateBaseTyreByouterTireNumber(BaseTyre baseTyre); + /** * 批量删除轮胎基础 * @@ -74,4 +76,6 @@ public interface IBaseTyreService AjaxResult getTyreLife(String outerTireNumber); String checkBaseTyreUnique(BaseTyre baseTyre); + + String importTyre(List baseTyreList, boolean isUpdateSupport, String operName); } diff --git a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/service/impl/BaseTyreServiceImpl.java b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/service/impl/BaseTyreServiceImpl.java index 7422f91..70639d5 100644 --- a/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/service/impl/BaseTyreServiceImpl.java +++ b/ruoyi-basetyre/src/main/java/com/ruoyi/basetyre/service/impl/BaseTyreServiceImpl.java @@ -17,10 +17,16 @@ import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.bean.BeanValidators; +import com.ruoyi.system.service.ISysConfigService; +import com.ruoyi.system.service.impl.SysUserServiceImpl; import org.apache.ibatis.session.SqlSessionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +35,7 @@ import com.ruoyi.basetyre.domain.BaseTyre; import com.ruoyi.basetyre.service.IBaseTyreService; import javax.annotation.Resource; +import javax.validation.Validator; /** * 轮胎基础Service业务层处理 @@ -39,6 +46,8 @@ import javax.annotation.Resource; @Service public class BaseTyreServiceImpl implements IBaseTyreService { + + private static final Logger log = LoggerFactory.getLogger(BaseTyreServiceImpl.class); @Autowired private BaseTyreMapper baseTyreMapper; @Resource @@ -48,6 +57,12 @@ public class BaseTyreServiceImpl implements IBaseTyreService @Autowired private BaseDeviceMapper baseDeviceMapper; + @Autowired + private ISysConfigService configService; + + @Autowired + protected Validator validator; + /** * 查询轮胎基础 * @@ -108,6 +123,15 @@ public class BaseTyreServiceImpl implements IBaseTyreService return baseTyreMapper.updateBaseTyre(baseTyre); } + @Override + public int updateBaseTyreByouterTireNumber(BaseTyre baseTyre) { + LoginUser loginUser=SecurityUtils.getLoginUser(); + baseTyre.setModifyTime(DateUtils.getNowDate()); + baseTyre.setModifyBy(loginUser.getUserId().toString()); + baseTyre.setModifyName(loginUser.getUsername()); + return baseTyreMapper.updateBaseTyreByouterTireNumber(baseTyre); + } + /** * 批量删除轮胎基础 * @@ -313,6 +337,66 @@ public class BaseTyreServiceImpl implements IBaseTyreService } return UserConstants.UNIQUE; } + + @Override + public String importTyre(List baseTyreList, boolean isUpdateSupport, String operName) { + + if (StringUtils.isNull(baseTyreList) || baseTyreList.size() == 0) + { + throw new ServiceException("导入用户数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + for (BaseTyre baseTyre : baseTyreList) + { + try + { + // 验证是否存在这个轮胎 + BaseTyre u = baseTyreMapper.getTyreInfoById(baseTyre.getOuterTireNumber()); + if (StringUtils.isNull(u)) + { + BeanValidators.validateWithException(validator, baseTyre); + + this.insertBaseTyre(baseTyre); + successNum++; + successMsg.append("
" + successNum + "、轮胎 " + baseTyre.getOuterTireNumber() + " 导入成功"); + } + else if (isUpdateSupport) + { + BeanValidators.validateWithException(validator, baseTyre); + this.updateBaseTyre(baseTyre); + + successNum++; + successMsg.append("
" + successNum + "、轮胎 " + baseTyre.getOuterTireNumber() + " 更新成功"); + } + else + { + failureNum++; + failureMsg.append("
" + failureNum + "、轮胎 " + baseTyre.getOuterTireNumber() + " 已存在"); + } + } + catch (Exception e) + { + failureNum++; + String msg = "
" + failureNum + "、账号 " + baseTyre.getOuterTireNumber() + " 导入失败:"; + 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 BaseTyre getTyreInfoById(String outerTireNumber) { return baseTyreMapper.getTyreInfoById(outerTireNumber); diff --git a/ruoyi-basetyre/src/main/resources/mapper/basetyre/BaseTyreMapper.xml b/ruoyi-basetyre/src/main/resources/mapper/basetyre/BaseTyreMapper.xml index ae1bb72..a30ae63 100644 --- a/ruoyi-basetyre/src/main/resources/mapper/basetyre/BaseTyreMapper.xml +++ b/ruoyi-basetyre/src/main/resources/mapper/basetyre/BaseTyreMapper.xml @@ -119,7 +119,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"