From b641f43ec17b5d41e2ecc076ad51c1f19987dc6b Mon Sep 17 00:00:00 2001 From: duhl <1558016038@qq.com> Date: Fri, 27 Mar 2020 11:14:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=9B=9B=E6=AC=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tyre/BaseCarbrandController.java | 49 ++++++++++--- .../templates/tyre/carbrand/carbrand.html | 22 ++++++ .../tyre/service/IBaseCarbrandService.java | 4 +- .../service/impl/BaseCarbrandServiceImpl.java | 68 ++++++++++++++++++- 4 files changed, 131 insertions(+), 12 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tyre/BaseCarbrandController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tyre/BaseCarbrandController.java index 84f2844..ff871c7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tyre/BaseCarbrandController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tyre/BaseCarbrandController.java @@ -26,6 +26,7 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; /** * 品牌Controller @@ -66,7 +67,7 @@ public class BaseCarbrandController extends BaseController * 导出品牌列表 */ @RequiresPermissions("tyre:carbrand:export") - @Log(title = "品牌", businessType = BusinessType.EXPORT) + @Log(title = "车辆车牌", businessType = BusinessType.EXPORT) @PostMapping("/export") @ResponseBody public AjaxResult export(BaseCarbrand baseCarbrand) @@ -77,7 +78,37 @@ public class BaseCarbrandController extends BaseController } /** - * 新增品牌 + * 导出车牌信息 + * @param file + * @param updateSupport + * @return + * @throws Exception + */ + @Log(title = "车辆车牌", businessType = BusinessType.IMPORT) + @RequiresPermissions("tyre:carbrand:import") + @PostMapping("/importData") + @ResponseBody + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception + { + ExcelUtil util = new ExcelUtil(BaseCarbrand.class); + List brandList = util.importExcel(file.getInputStream()); + String operName = ShiroUtils.getSysUser().getLoginName(); + String message = baseCarbrandService.importBrand(brandList, updateSupport, operName); + return AjaxResult.success(message); + } + + @RequiresPermissions("tyre:carbrand:view") + @GetMapping("/importTemplate") + @ResponseBody + public AjaxResult importTemplate() + { + ExcelUtil util = new ExcelUtil(BaseCarbrand.class); + return util.importTemplateExcel("车牌数据"); + } + + + /** + * 新增车辆车牌 */ @GetMapping("/add") public String add() @@ -86,10 +117,10 @@ public class BaseCarbrandController extends BaseController } /** - * 新增保存品牌 + * 新增保存车辆车牌 */ @RequiresPermissions("tyre:carbrand:add") - @Log(title = "品牌", businessType = BusinessType.INSERT) + @Log(title = "车辆车牌", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(BaseCarbrand baseCarbrand) @@ -108,7 +139,7 @@ public class BaseCarbrandController extends BaseController } /** - * 修改品牌 + * 修改车辆车牌 */ @GetMapping("/edit/{objid}") public String edit(@PathVariable("objid") Long objid, ModelMap mmap) @@ -119,10 +150,10 @@ public class BaseCarbrandController extends BaseController } /** - * 修改保存品牌 + * 修改保存车辆车牌 */ @RequiresPermissions("tyre:carbrand:edit") - @Log(title = "品牌", businessType = BusinessType.UPDATE) + @Log(title = "车辆车牌", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(BaseCarbrand baseCarbrand) @@ -141,10 +172,10 @@ public class BaseCarbrandController extends BaseController } /** - * 删除品牌 + * 删除车辆车牌 */ @RequiresPermissions("tyre:carbrand:remove") - @Log(title = "品牌", businessType = BusinessType.DELETE) + @Log(title = "车辆车牌", businessType = BusinessType.DELETE) @PostMapping( "/remove") @ResponseBody public AjaxResult remove(String ids) diff --git a/ruoyi-admin/src/main/resources/templates/tyre/carbrand/carbrand.html b/ruoyi-admin/src/main/resources/templates/tyre/carbrand/carbrand.html index c737526..1320965 100644 --- a/ruoyi-admin/src/main/resources/templates/tyre/carbrand/carbrand.html +++ b/ruoyi-admin/src/main/resources/templates/tyre/carbrand/carbrand.html @@ -47,6 +47,9 @@ 删除 + + 导入 + 导出 @@ -69,6 +72,10 @@ updateUrl: prefix + "/edit/{id}", removeUrl: prefix + "/remove", exportUrl: prefix + "/export", + importUrl: prefix + "/importData", + importTemplateUrl: prefix + "/importTemplate", + sortName: "recordtime", + sortOrder: "desc", modalName: "车牌", columns: [{ checkbox: true @@ -118,4 +125,19 @@ }); + + \ No newline at end of file diff --git a/ruoyi-tyre/src/main/java/com/ruoyi/tyre/service/IBaseCarbrandService.java b/ruoyi-tyre/src/main/java/com/ruoyi/tyre/service/IBaseCarbrandService.java index ac51ab9..ed76508 100644 --- a/ruoyi-tyre/src/main/java/com/ruoyi/tyre/service/IBaseCarbrandService.java +++ b/ruoyi-tyre/src/main/java/com/ruoyi/tyre/service/IBaseCarbrandService.java @@ -64,5 +64,7 @@ public interface IBaseCarbrandService * @param branno * @return */ - String checkBrannoUnique(BaseCarbrand branno); + public String checkBrannoUnique(BaseCarbrand branno); + + public String importBrand(List brandList, boolean updateSupport, String operName); } diff --git a/ruoyi-tyre/src/main/java/com/ruoyi/tyre/service/impl/BaseCarbrandServiceImpl.java b/ruoyi-tyre/src/main/java/com/ruoyi/tyre/service/impl/BaseCarbrandServiceImpl.java index 311960b..26d9466 100644 --- a/ruoyi-tyre/src/main/java/com/ruoyi/tyre/service/impl/BaseCarbrandServiceImpl.java +++ b/ruoyi-tyre/src/main/java/com/ruoyi/tyre/service/impl/BaseCarbrandServiceImpl.java @@ -4,8 +4,11 @@ import java.util.List; import com.ruoyi.common.constant.TyreConstants; import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.system.domain.SysPost; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.tyre.mapper.BaseCarbrandMapper; @@ -22,6 +25,8 @@ import com.ruoyi.common.core.text.Convert; @Service public class BaseCarbrandServiceImpl implements IBaseCarbrandService { + + private static final Logger log = LoggerFactory.getLogger(BaseCarbrandServiceImpl.class); @Autowired private BaseCarbrandMapper baseCarbrandMapper; @@ -105,7 +110,7 @@ public class BaseCarbrandServiceImpl implements IBaseCarbrandService /** * 删除车牌信息 - * + * * @param objid 车牌ID * @return 结果 */ @@ -113,4 +118,63 @@ public class BaseCarbrandServiceImpl implements IBaseCarbrandService { return baseCarbrandMapper.deleteBaseCarbrandById(objid); } + + @Override + public String importBrand(List brandList, boolean updateSupport, String operName) + { + if (StringUtils.isNull(brandList) || brandList.size() == 0) + { + throw new BusinessException("导入车牌数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + for (BaseCarbrand brand : brandList) + { + try + { + // 验证是否存在这个车牌 + BaseCarbrand baseCarbrand = baseCarbrandMapper.checkBrannoUnique(brand.getBranno()); + if (StringUtils.isNull(baseCarbrand)) + { + + brand.setRecorderid(operName); + this.insertBaseCarbrand(brand); + successNum++; + successMsg.append("
" + successNum + "、车牌号 " + brand.getBranno() + " 导入成功"); + } + else if (updateSupport) + { + brand.setRecorderid(operName); + this.updateBaseCarbrand(brand); + successNum++; + successMsg.append("
" + successNum + "、车牌号 " + brand.getBranno() + " 更新成功"); + } + else + { + failureNum++; + failureMsg.append("
" + failureNum + "、车牌号 " + brand.getBranno() + " 已存在"); + } + } + catch (Exception e) + { + failureNum++; + String msg = "
" + failureNum + "、车牌号 " + brand.getBranno() + " 导入失败:"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) + { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new BusinessException(failureMsg.toString()); + } + else + { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } } +