From aa3278f2caecd6d204eb89ac87f0011ba8e2f054 Mon Sep 17 00:00:00 2001 From: syruan <321359594@qq.com> Date: Mon, 25 Nov 2024 17:43:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E8=B5=84=E8=A3=85=E5=A4=87=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E7=AD=9B=E9=80=89=E3=80=81=E8=A3=85=E5=A4=87=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=9E=B6=E9=80=BB=E8=BE=91=E3=80=81=E8=8D=89=E7=A8=BF?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/constant/MaterialConstants.java | 3 + .../bonus/common/biz/domain/BmFileInfo.java | 4 +- .../bonus/common/biz/enums/MaStatusEnum.java | 19 +- .../device/controller/DevInfoController.java | 24 +- .../bonus/material/device/domain/DevInfo.java | 58 +++-- .../material/device/domain/vo/DevInfoVo.java | 22 +- .../material/device/mapper/DevInfoMapper.java | 22 +- .../device/service/DevInfoService.java | 12 +- .../service/impl/DevInfoServiceImpl.java | 238 +++++++++++++++--- .../service/impl/MaTypeInfoServiceImpl.java | 2 + .../bootstrap-material_mall_local.yml | 4 + .../material/device/BmFileInfoMapper.xml | 44 ++-- .../mapper/material/device/DevInfoMapper.xml | 138 ++++++++-- .../mapper/material/home/MaTypeInfoMapper.xml | 3 +- 14 files changed, 451 insertions(+), 142 deletions(-) diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/MaterialConstants.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/MaterialConstants.java index a747522..09a59e8 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/MaterialConstants.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/MaterialConstants.java @@ -59,4 +59,7 @@ public class MaterialConstants { public static final String OUTER_PROTOCAL = "2"; //外部单位协议 + /** 文件类型:设备附件 */ + public static final Integer MATERIAL_FILE_TYPE_CODE = 17; + } diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/BmFileInfo.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/BmFileInfo.java index d81abed..bc305b9 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/BmFileInfo.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/BmFileInfo.java @@ -42,12 +42,12 @@ public class BmFileInfo extends BaseEntity { /** 文件名称 */ @Excel(name = "文件名称") @ApiModelProperty(value = "文件名称") - private String name; + private String fileName; /** 文件路径 */ @Excel(name = "文件路径") @ApiModelProperty(value = "文件路径") - private String url; + private String fileUrl; /** 文件类型, 参考数据字典 bm_file_type */ @Excel(name = "文件类型") diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/enums/MaStatusEnum.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/enums/MaStatusEnum.java index c414173..b8c4b3b 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/enums/MaStatusEnum.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/enums/MaStatusEnum.java @@ -9,20 +9,11 @@ import lombok.Getter; @Getter public enum MaStatusEnum { - /** 待上架 */ - TO_BE_LISTED (15, "待上架"), - /** 待租 */ - ON_HIRE(16, "待租"), - /** 在租 */ - UNDER_RENT(17, "在租"), - /** 下架 */ - DELIST(18,"下架"), - /** 自有 */ - SELF_OWNED(43,"自有"), - /** 待审批 */ - PENDING_APPROVAL(331,"待审批"), - /** 上架驳回 */ - LISTING_REJECTED(332,"上架驳回"); + TO_BE_LISTED(0, "草稿"), + ON_HIRE(1, "下架"), + LISTING(2, "上架"), + UNDER_RENT(3,"在租"), + OWN(4,"自有"); private final Integer code; private final String name; diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/controller/DevInfoController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/controller/DevInfoController.java index 78ef868..aa1ad12 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/controller/DevInfoController.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/controller/DevInfoController.java @@ -14,10 +14,13 @@ 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 org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; import java.util.List; import static com.bonus.common.core.web.page.TableSupport.PAGE_NUM; @@ -30,6 +33,7 @@ import static com.bonus.common.core.web.page.TableSupport.PAGE_SIZE; */ @RestController @RequestMapping("/dev") +@Validated @Api(value = "设备信息",tags = "设备管理") public class DevInfoController extends BaseController { @@ -43,6 +47,7 @@ public class DevInfoController extends BaseController { @ApiOperation(value = "装备列表") @PostMapping("/list") public AjaxResult list(@RequestBody DevInfoVo devInfo) { + devInfo.setLevel("4"); List list = devInfoService.selectDevInfoList(devInfo); Integer pageIndex = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1); Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10); @@ -108,7 +113,7 @@ public class DevInfoController extends BaseController { @ApiOperation(value = "上下架(批量)") @PostMapping("updateUpDown") public AjaxResult updateUp(@RequestBody DevInfo devInfo) { - return toAjax(devInfoService.updateUpDown(devInfo)); + return devInfoService.updateUpDown(devInfo); } /** @@ -117,8 +122,8 @@ public class DevInfoController extends BaseController { // @RequiresPermissions("equip:info:edit") @ApiOperation(value = "修改装备信息") @PutMapping - public AjaxResult edit(@RequestBody DevInfo devInfo) { - return toAjax(devInfoService.updateDevInfo(devInfo)); + public AjaxResult edit(@RequestBody @NotNull @Valid DevInfo devInfo) { + return devInfoService.updateDevInfo(devInfo); } /** @@ -158,8 +163,17 @@ public class DevInfoController extends BaseController { //@RequiresPermissions("equip:info:add") @ApiOperation(value = "新增装备--含附件上传") @PostMapping - public AjaxResult add(@RequestBody DevInfo devInfo) { - return toAjax(devInfoService.insertDevInfo(devInfo)); + public AjaxResult add(@RequestBody @NotNull @Valid DevInfo devInfo) { + return devInfoService.insertDevInfo(devInfo); + } + + /** + * 设备信息录入--保存草稿--不校验必填 + */ + @ApiOperation(value = "设备信息录入--保存草稿--不校验必填") + @PostMapping("/insertDraft") + public AjaxResult insertDraft(@NotNull @RequestBody DevInfo devInfo) { + return devInfoService.insertDraft(devInfo); } /** diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/DevInfo.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/DevInfo.java index 782cff4..f29ebad 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/DevInfo.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/DevInfo.java @@ -1,14 +1,16 @@ package com.bonus.material.device.domain; import com.bonus.common.biz.domain.BmFileInfo; -import com.bonus.common.biz.domain.SysFileInfo; import com.bonus.common.core.annotation.Excel; import com.bonus.common.core.web.domain.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import lombok.experimental.Accessors; +import javax.validation.constraints.*; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -21,6 +23,7 @@ import java.util.List; @EqualsAndHashCode(callSuper = false) @Data @ToString +@Accessors(chain = true) public class DevInfo extends BaseEntity { private static final long serialVersionUID = 429270031714225761L; @@ -29,27 +32,39 @@ public class DevInfo extends BaseEntity { @Excel(name = "设备id") @ApiModelProperty(value = "设备id") private Long maId; - /** 设备id */ - @ApiModelProperty(value = "设备id") + + /** 设备id数组 */ + @ApiModelProperty(value = "设备id数组") private List maIds; - /** 系统编码 */ - @Excel(name = "系统编码") - @ApiModelProperty(value = "系统编码") + /** 设备编码 */ + @Excel(name = "设备编码") + @ApiModelProperty(value = "设备编码") + @NotBlank private String code; @ApiModelProperty(value = "装备名称") + @NotBlank private String deviceName; @ApiModelProperty(value = "整机装备重量") + @NotBlank private String deviceWeight; + @Excel(name = "设备数量") + @ApiModelProperty(value = "设备数量") + @NotNull(message = "设备数量不能为空") + @Min(value = 1, message = "设备数量不能小于1") + private Integer deviceCount; + @ApiModelProperty(value = "单位") + @NotBlank(message = "单位不能为空") private String unitName; /** 类型id */ @Excel(name = "类型id") @ApiModelProperty(value = "类型id") + @NotNull private Long typeId; @ApiModelProperty(value = "装备类别") @@ -58,7 +73,7 @@ public class DevInfo extends BaseEntity { /** 设备状态(自有,待上架,上架,在租,下架)考虑数据字典 */ @Excel(name = "设备状态(自有,待上架,上架,在租,下架)考虑数据字典") @ApiModelProperty(value = "设备状态(自有,待上架,上架,在租,下架)考虑数据字典") - private String maStatus; + private Integer maStatus; /** 设备状态(自有,待上架,上架,在租,下架)考虑数据字典 */ @Excel(name = "设备状态(自有,待上架,上架,在租,下架)考虑数据字典") @@ -90,6 +105,7 @@ public class DevInfo extends BaseEntity { /** 设备品牌 */ @Excel(name = "设备品牌") @ApiModelProperty(value = "设备品牌") + @NotBlank private String brand; /** 设备型号 */ @@ -100,6 +116,8 @@ public class DevInfo extends BaseEntity { /** 出厂日期 */ @Excel(name = "出厂日期") @ApiModelProperty(value = "出厂日期") + @JsonFormat(pattern = "yyyy-MM-dd") + @NotBlank private String productionDate; /** 工作时长 */ @@ -120,6 +138,7 @@ public class DevInfo extends BaseEntity { /** 设备天租价 */ @Excel(name = "设备天租价") @ApiModelProperty(value = "设备天租价") + @NotNull private Float dayLeasePrice; /** 设备主照片 */ @@ -147,9 +166,8 @@ public class DevInfo extends BaseEntity { @ApiModelProperty(value = "gps编号") private String gpsCode; - /** 设备所属公司 */ - @Excel(name = "设备所属公司") - @ApiModelProperty(value = "设备所属公司") + /** 设备所属公司--废弃不用 */ + @ApiModelProperty(value = "设备所属公司--废弃") private Long ownCo; /** 创建人 */ @@ -158,9 +176,12 @@ public class DevInfo extends BaseEntity { private Long creator; @ApiModelProperty(value = "联系人") + @NotBlank private String person; @ApiModelProperty(value = "联系人电话") + @NotBlank + @Size(min = 11, max = 11, message = "手机号长度不能超过11位") private String personPhone; /** 设备规格 */ @@ -184,20 +205,20 @@ public class DevInfo extends BaseEntity { private String isActive; @ApiModelProperty(value = "主展示图") - private List mainFileList = new ArrayList<>(); + @NotEmpty(message = "主展示图不能为空") + private List mainFileList = new ArrayList<>(); @ApiModelProperty(value = "详情页展示图") - private List detailsFileList = new ArrayList<>(); + @NotEmpty(message = "详情页展示图不能为空") + private List detailsFileList = new ArrayList<>(); @ApiModelProperty(value = "检测证明、检验pdf") - private List examinationPdf = new ArrayList<>(); + @NotEmpty(message = "检测证明、检验pdf不能为空") + private List examinationPdf = new ArrayList<>(); @ApiModelProperty(value = "合格证、保险pdf") - private List insurancePdf = new ArrayList<>(); - - /**文件附件 后续废弃 用下面的*/ - @ApiModelProperty(value = "文件附件") - private List fileList; + @NotEmpty(message = "合格证、保险pdf不能为空") + private List insurancePdf = new ArrayList<>(); /**文件附件*/ @ApiModelProperty(value = "文件附件") @@ -207,5 +228,6 @@ public class DevInfo extends BaseEntity { private String city; @ApiModelProperty(value = "公司Id") + @NotBlank(message = "所属公司不能为空") private String companyId; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/vo/DevInfoVo.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/vo/DevInfoVo.java index fbfb2a7..df9412a 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/vo/DevInfoVo.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/vo/DevInfoVo.java @@ -1,7 +1,7 @@ package com.bonus.material.device.domain.vo; -import com.bonus.common.biz.domain.SysFileInfo; import com.bonus.material.device.domain.DevInfo; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -9,6 +9,7 @@ import lombok.ToString; import java.util.List; + /** * @author syruan */ @@ -20,7 +21,6 @@ public class DevInfoVo extends DevInfo { private Integer pageNum; private Integer pageSize; private long parentId; - private Long maId; @ApiModelProperty(value = "下单用户id") private Long orderUser; @@ -60,9 +60,6 @@ public class DevInfoVo extends DevInfo { @ApiModelProperty(value = "搜索数量") private Long searchNum; - @ApiModelProperty(value = "附件集合--只做返回用") - private List fileList; - /**上下架id*/ @ApiModelProperty(value = "上下架id") private int upId; @@ -100,9 +97,6 @@ public class DevInfoVo extends DevInfo { @ApiModelProperty(value = "装备分类级别") private String level; - @ApiModelProperty(value = "装备状态") - private String maStatusStr; - @ApiModelProperty(value = "省份名称") private String provinceStr; @@ -112,10 +106,6 @@ public class DevInfoVo extends DevInfo { @ApiModelProperty(value = "区名称") private String areaStr; - @ApiModelProperty(value = "所属公司id") - private String companyId; - - /* 装备组别 parent */ @ApiModelProperty(value = "装备组别Id") private String groupId; @@ -147,4 +137,12 @@ public class DevInfoVo extends DevInfo { @ApiModelProperty(value = "出租记录信息") private List leaseList; + @ApiModelProperty(value = "开始时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private String startTime; + + @ApiModelProperty(value = "结束时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private String endTime; + } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevInfoMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevInfoMapper.java index 91e4746..3f08f7b 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevInfoMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevInfoMapper.java @@ -24,8 +24,17 @@ public interface DevInfoMapper { */ DevInfoVo selectDevInfoByMaId(Long maId); + Integer getMaStatusByMaId(Long maId); + int getHotSearchCountByMaId(Long maId); + /** + * 判断设备名称是否重复 + * @param deviceName 物资名称 + * @return 条数 + */ + int getDeviceNameCount(String deviceName); + int insertHotSearch(Long maId); int updateHotSearchByMaId(Long maId); @@ -60,6 +69,12 @@ public interface DevInfoMapper { */ int insertDevInfo(DevInfo devInfo); + /** + * 保存草稿 + * @param devInfo 设备信息 + */ + int insertDraft(DevInfo devInfo); + /** * 修改设备信息 * @@ -69,12 +84,13 @@ public interface DevInfoMapper { int updateDevInfo(DevInfo devInfo); /** - * 删除设备信息 + * 删除设备信息 -- 逻辑删除 -- 限制状态删除 * * @param maId 设备信息主键 + * @param statusCode 状态码 * @return 结果 */ - int deleteDevInfoByMaId(Long maId); + int deleteDevInfoByMaId(@Param("maId") Long maId, @Param("statusCode") Integer statusCode); /** * 批量删除设备信息 @@ -108,7 +124,7 @@ public interface DevInfoMapper { */ List selectCompanyList(BmCompanyInfo obj); - int updateUpDown(@Param("maIds") List maIds, @Param("maStatus")String maStatus); + int updateUpDown(@Param("maIds") List maIds, @Param("maStatus") Object maStatus); /** * 查询预约车详情 diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevInfoService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevInfoService.java index 34364a9..a5891cf 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevInfoService.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevInfoService.java @@ -2,6 +2,7 @@ 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.InfoMotionDto; import com.bonus.material.device.domain.vo.DevInfoVo; @@ -41,7 +42,7 @@ public interface DevInfoService { * @param devInfo 设备信息 * @return 结果 */ - int updateDevInfo(DevInfo devInfo); + AjaxResult updateDevInfo(DevInfo devInfo); /** * 批量删除设备信息 @@ -76,7 +77,12 @@ public interface DevInfoService { * @param devInfo 设备信息 * @return 结果 */ - int insertDevInfo(DevInfo devInfo); + AjaxResult insertDevInfo(DevInfo devInfo); + + /** + * 新增装备 -- 保存草稿 -- 不校验 + */ + AjaxResult insertDraft(DevInfo devInfo); Map sumType(); @@ -89,5 +95,5 @@ public interface DevInfoService { */ List selectCompanyList(BmCompanyInfo obj); - int updateUpDown(DevInfo devInfo); + AjaxResult updateUpDown(DevInfo devInfo); } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevInfoServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevInfoServiceImpl.java index 6b6d7a9..ba62591 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevInfoServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevInfoServiceImpl.java @@ -1,10 +1,12 @@ package com.bonus.material.device.service.impl; import cn.hutool.core.collection.CollectionUtil; +import com.bonus.common.biz.constant.MaterialConstants; import com.bonus.common.biz.domain.*; import com.bonus.common.biz.enums.MaStatusEnum; -import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.bean.BeanUtils; +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; @@ -12,12 +14,12 @@ import com.bonus.material.device.domain.dto.InfoMotionDto; import com.bonus.material.device.domain.vo.DevInfoVo; import com.bonus.material.device.mapper.BmFileInfoMapper; import com.bonus.material.device.mapper.DevInfoMapper; -import com.bonus.material.device.mapper.SysFileInfoMapper; import com.bonus.material.device.service.DevInfoService; 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 org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -26,6 +28,8 @@ import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; +import static com.bonus.common.biz.enums.MaStatusEnum.*; + /** * 设备信息Service业务层处理 * @@ -48,9 +52,6 @@ public class DevInfoServiceImpl implements DevInfoService { @Resource private DevInfoMapper devInfoMapper; - @Resource - private SysFileInfoMapper sysFileInfoMapper; - @Resource private BmFileInfoMapper bmFileInfoMapper; @@ -67,12 +68,27 @@ public class DevInfoServiceImpl implements DevInfoService { Long userId = SecurityUtils.getLoginUser().getUserid(); if (devInfoVo != null) { //更新搜索量 - updateHotSearch(maId); - BmFileInfo bmFileInfo = new BmFileInfo(); - bmFileInfo.setModelId(devInfoVo.getMaId()); - bmFileInfo.setTaskType(17); + try { + updateHotSearch(maId); + } catch (Exception e) { + System.err.println("更新设备搜索量失败,不影响主业务流程"); + } + BmFileInfo bmFileInfo = new BmFileInfo().setModelId(devInfoVo.getMaId()).setTaskType(MaterialConstants.MATERIAL_FILE_TYPE_CODE); List fileList = bmFileInfoMapper.selectBmFileInfoList(bmFileInfo); - devInfoVo.setBmFileInfoList(fileList); + if (!CollectionUtils.isEmpty(fileList)) { + fileList.removeIf(Objects::isNull); + fileList.forEach(item -> { + if (item.getFileType().equals(Long.valueOf(MAIN_IMAGES_DICT_VALUE))) { + devInfoVo.getMainFileList().add(item); + } else if (item.getFileType().equals(Long.valueOf(DETAILS_IMAGES_DICT_VALUE))) { + devInfoVo.getDetailsFileList().add(item); + } else if (item.getFileType().equals(Long.valueOf(EXAMINATION_PDF))) { + devInfoVo.getExaminationPdf().add(item); + } else if (item.getFileType().equals(Long.valueOf(INSURANCE_PDF))) { + devInfoVo.getInsurancePdf().add(item); + } + }); + } //根据设备id及用户id去预约表中查询是否已经加入预约车 BookCarInfoDto bookCarInfoDto = devInfoMapper.getBookCar(maId, userId); if (bookCarInfoDto != null) { @@ -158,7 +174,7 @@ public class DevInfoServiceImpl implements DevInfoService { bmFileInfo.setFileType(0L); List mainFileInfoList = bmFileInfoMapper.selectBmFileInfoList(bmFileInfo); if (!CollectionUtils.isEmpty(mainFileInfoList)) { - devInfoVo.setPicUrl(mainFileInfoList.get(0).getUrl()); + devInfoVo.setPicUrl(mainFileInfoList.get(0).getFileUrl()); } } } @@ -168,8 +184,8 @@ public class DevInfoServiceImpl implements DevInfoService { List sysDicList = devInfoMapper.getSysDic(); for (DevInfoVo devInfoVo : list) { for (SysDic sysDic : sysDicList) { - if (devInfoVo.getMaStatus().equals(String.valueOf(sysDic.getId()))) { - devInfoVo.setMaStatusStr(sysDic.getName()); + if (devInfoVo.getMaStatus().equals(sysDic.getId())) { + devInfoVo.setMaStatusName(sysDic.getName()); } } } @@ -197,38 +213,153 @@ public class DevInfoServiceImpl implements DevInfoService { * @return 结果 */ @Override - @Transactional - public int insertDevInfo(DevInfo devInfo) { - devInfo.setCreateTime(new Date()); + @Transactional(rollbackFor = Exception.class) + public AjaxResult insertDevInfo(DevInfo devInfo) { + if (devInfo == null) { + return AjaxResult.error("设备信息不能为空"); + } + try { + if (devInfo.getMaId() != null) { + // 更新设备信息--原本草稿相关内容删除 + int deleted = devInfoMapper.deleteDevInfoByMaId(devInfo.getMaId(), MaStatusEnum.UNDER_RENT.getCode()); + if (deleted == 0) { + return AjaxResult.error("传入设备ID,但设备不存在,请刷新后重试"); + } + // 删除原草稿附件 + BmFileInfo bmFileInfo = new BmFileInfo() + .setFileType(Long.valueOf(MaterialConstants.MATERIAL_FILE_TYPE_CODE)) + .setModelId(devInfo.getMaId()); + bmFileInfoMapper.deleteBmFileInfoByBizInfo(bmFileInfo); + } + } catch (DataAccessException e) { + System.err.println("数据库操作异常: " + e.getMessage()); + throw new ServiceException("数据库操作异常: " + e.getMessage()); + } catch (IllegalArgumentException e) { + System.err.println("非法参数异常: {}" + e.getMessage()); + throw new ServiceException("非法参数异常: " + e.getMessage()); + } + + int deviceNameCount = devInfoMapper.getDeviceNameCount(devInfo.getDeviceName()); + if (deviceNameCount > 0) { + return AjaxResult.error("设备名称已存在,请修改后重试!"); + } + //获取用户信息 Long userId = SecurityUtils.getUserId(); //保存用户信息 - devInfo.setCreator(userId); - devInfo.setCode(String.valueOf(UUID.randomUUID())); - devInfo.setMaStatus("3"); - devInfoMapper.insertDevInfo(devInfo); + devInfo.setCreator(userId).setMaStatus(ON_HIRE.getCode()); + int saveSuccessNum = devInfoMapper.insertDevInfo(devInfo); + if (saveSuccessNum == 0) { + return AjaxResult.error("设备信息SQL保存失败,请修改后重试"); + } + //把文件保存到附件中 + AjaxResult error = uploadFiles(devInfo, userId); + if (error != null) {return error;} + return AjaxResult.success("保存成功"); + } + + /** + * 新增设备--草稿状态 + * + * @param devInfo 设备信息 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult insertDraft(DevInfo devInfo) { + //获取用户信息 + Long userId = SecurityUtils.getUserId(); + //保存用户信息 + devInfo.setCreator(userId).setMaStatus(TO_BE_LISTED.getCode()); + try { + if (devInfo.getMaId() != null) { + devInfoMapper.deleteDevInfoByMaId(devInfo.getMaId(), MaStatusEnum.UNDER_RENT.getCode()); + } + int insertedDraft = devInfoMapper.insertDraft(devInfo); + if (insertedDraft == 0) { + return AjaxResult.error("装备草稿保存失败,请修改后重试"); + } + AjaxResult error = uploadFiles(devInfo, userId); + if (error != null) return error; + } catch (Exception e) { + return AjaxResult.error("装备草稿保存失败,执行异常:" + e.getMessage()); + } + return AjaxResult.success("装备草稿保存成功"); + } + + private AjaxResult uploadFiles(DevInfo devInfo, Long userId) { + if (userId == null) { + return AjaxResult.error("用户信息获取失败,请刷新后重试"); + } + if (devInfo.getMaId() == null) { + return AjaxResult.error("设备ID为空,请携带设备信息上传附件"); + } //把文件保存到附件中 - List fileInfoList = devInfo.getBmFileInfoList(); + List fileInfoList = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(devInfo.getMainFileList())) { + devInfo.getMainFileList().removeIf(Objects::isNull); + devInfo.getMainFileList().forEach(item -> { + item.setTaskType(MaterialConstants.MATERIAL_FILE_TYPE_CODE); + item.setFileType(Long.valueOf(MAIN_IMAGES_DICT_VALUE)); + }); + fileInfoList.addAll(devInfo.getMainFileList()); + } + if (CollectionUtil.isNotEmpty(devInfo.getDetailsFileList())) { + devInfo.getDetailsFileList().removeIf(Objects::isNull); + devInfo.getDetailsFileList().forEach(item -> { + item.setTaskType(MaterialConstants.MATERIAL_FILE_TYPE_CODE); + item.setFileType(Long.valueOf(DETAILS_IMAGES_DICT_VALUE)); + }); + fileInfoList.addAll(devInfo.getDetailsFileList()); + } + if (CollectionUtil.isNotEmpty(devInfo.getInsurancePdf())) { + devInfo.getInsurancePdf().removeIf(Objects::isNull); + devInfo.getInsurancePdf().forEach(item -> { + item.setTaskType(MaterialConstants.MATERIAL_FILE_TYPE_CODE); + item.setFileType(Long.valueOf(INSURANCE_PDF)); + }); + fileInfoList.addAll(devInfo.getInsurancePdf()); + } + if (CollectionUtil.isNotEmpty(devInfo.getExaminationPdf())) { + devInfo.getExaminationPdf().removeIf(Objects::isNull); + devInfo.getExaminationPdf().forEach(item -> { + item.setTaskType(MaterialConstants.MATERIAL_FILE_TYPE_CODE); + item.setFileType(Long.valueOf(EXAMINATION_PDF)); + }); + fileInfoList.addAll(devInfo.getExaminationPdf()); + } + + // 上传处理后的附件列表 if (CollectionUtil.isNotEmpty(fileInfoList)) { + System.out.println("设备附件数量:" + fileInfoList.size()); for (BmFileInfo sysFileInfo : fileInfoList) { sysFileInfo.setModelId(devInfo.getMaId()); sysFileInfo.setCreateBy(String.valueOf(userId)); - bmFileInfoMapper.insertBmFileInfo(sysFileInfo); + } + int fileUploadTotal = bmFileInfoMapper.insertBmFileInfos(fileInfoList); + if (fileUploadTotal == 0) { + return AjaxResult.error("设备附件保存0条,保存失败,请修改后重试"); } } - return 1; + return null; } + /** * 修改设备信息 * * @param devInfo 设备信息 */ @Override - public int updateDevInfo(DevInfo devInfo) { - devInfo.setUpdateTime(DateUtils.getNowDate()); - return devInfoMapper.updateDevInfo(devInfo); + public AjaxResult updateDevInfo(DevInfo devInfo) { + if (devInfo.getMaId() == null) { + return AjaxResult.error("设备ID为空,请携带设备信息修改"); + } + int deviceId = devInfoMapper.getDeviceNameCount(devInfo.getDeviceName()); + if (deviceId > 0 && deviceId != devInfo.getMaId()) { + return AjaxResult.error("设备名称已存在,请修改后重试!"); + } + return devInfoMapper.updateDevInfo(devInfo) > 0 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败"); } /** @@ -250,7 +381,7 @@ public class DevInfoServiceImpl implements DevInfoService { */ @Override public int deleteDevInfoByMaId(Long maId) { - return devInfoMapper.deleteDevInfoByMaId(maId); + return devInfoMapper.deleteDevInfoByMaId(maId, MaStatusEnum.UNDER_RENT.getCode()); } /** @@ -277,14 +408,14 @@ public class DevInfoServiceImpl implements DevInfoService { //获取所有的装备信息 List devInfoList = devInfoMapper.selectDevInfoList(devInfoVo); //获取每种状态列表 - Map> groupedByMaStatus = devInfoList.stream() + Map> groupedByMaStatus = devInfoList.stream() .collect(Collectors.groupingBy(DevInfo::getMaStatus)); //获取所有的key - Set keys = groupedByMaStatus.keySet(); + Set keys = groupedByMaStatus.keySet(); //根据key计算每种状态的数量 - for (String key : keys) { + for (Integer key : keys) { List deviceList = groupedByMaStatus.get(key); - sumTypeMap.put(MaStatusEnum.getNameByCode(Integer.parseInt(key)), deviceList.size()); + sumTypeMap.put(MaStatusEnum.getNameByCode(key), deviceList.size()); } return sumTypeMap; } @@ -302,9 +433,6 @@ public class DevInfoServiceImpl implements DevInfoService { /** * 查询公司列表 - * - * @param obj - * @return */ @Override public List selectCompanyList(BmCompanyInfo obj) { @@ -312,14 +440,42 @@ public class DevInfoServiceImpl implements DevInfoService { } @Override - public int updateUpDown(DevInfo devInfo) { - List maIds = devInfo.getMaIds(); - String maStatus = devInfo.getMaStatus(); - int i = 0; - if (CollectionUtil.isNotEmpty(maIds)) { - i = devInfoMapper.updateUpDown(maIds, maStatus); + public AjaxResult updateUpDown(DevInfo devInfo) { + if (devInfo == null || CollectionUtil.isEmpty(devInfo.getMaIds())) { + return AjaxResult.warn("请选择设备"); } - return i; + if (devInfo.getMaStatus() == null) { + return AjaxResult.warn("请选择设备状态"); + } + devInfo.getMaIds().removeIf(Objects::isNull); + List maIds = devInfo.getMaIds(); + if (CollectionUtil.isNotEmpty(maIds)) { + for (Long maId : maIds) { + Integer oldStatus = devInfoMapper.getMaStatusByMaId(maId); + Integer newStatus = devInfo.getMaStatus(); + switch (oldStatus) { + case 0: + 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;} + return AjaxResult.warn("设备ID:" + maId + "已下架,只能进行上下架操作!"); + case 2: + if (newStatus.equals(ON_HIRE.getCode()) || newStatus.equals(LISTING.getCode())) {continue;} + return AjaxResult.warn("设备ID:" + maId + "设备已上架,只能进行上下架操作!!"); + case 3: + return AjaxResult.warn("设备ID:" + maId + "设备已出租,非法状态修改!!"); + default: + return AjaxResult.warn("设备ID:" + maId + "设备状态异常,请修改后重试"); + } + } + try { + devInfoMapper.updateUpDown(maIds, devInfo.getMaStatus()); + } catch (DataAccessException e) { + throw new ServiceException("批量修改状态时SQL执行异常:" + e.getMessage()); + } + } + return AjaxResult.success("操作成功"); } @Override diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/home/service/impl/MaTypeInfoServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/home/service/impl/MaTypeInfoServiceImpl.java index 61037f9..f9c5eb1 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/home/service/impl/MaTypeInfoServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/home/service/impl/MaTypeInfoServiceImpl.java @@ -14,6 +14,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; @Service @Slf4j diff --git a/bonus-modules/bonus-material-mall/src/main/resources/bootstrap-material_mall_local.yml b/bonus-modules/bonus-material-mall/src/main/resources/bootstrap-material_mall_local.yml index 4ca96bf..8dce47d 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/bootstrap-material_mall_local.yml +++ b/bonus-modules/bonus-material-mall/src/main/resources/bootstrap-material_mall_local.yml @@ -24,3 +24,7 @@ spring: jasypt: encryptor: password: Encrypt + +mybatis: + configuration: + map-underscore-to-camel-case: true \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/BmFileInfoMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/BmFileInfoMapper.xml index 23b27d0..adf345d 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/BmFileInfoMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/BmFileInfoMapper.xml @@ -8,15 +8,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - + + - select id, task_type, task_id, model_id, name, url, file_type, create_by, create_time from bm_file_info + select + id, task_type, task_id, model_id, name, url, file_type, create_by, create_time + from bm_file_info @@ -36,6 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where model_id = #{id} + @@ -46,21 +48,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" task_type, task_id, model_id, - name, - url, + `name`, + url, file_type, create_by, - create_time, + create_time #{taskType}, #{taskId}, #{modelId}, - #{name}, - #{url}, + #{name}, + #{url}, #{fileType}, #{createBy}, - #{createTime}, + now() @@ -68,14 +70,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" INSERT INTO bm_file_info(task_type,task_id,model_id,name,url,file_type,create_by,create_time) VALUES - (#{item.taskType}, + ( + #{item.taskType}, #{item.taskId}, #{item.modelId}, - #{item.name}, - #{item.url}, + #{item.fileName}, + #{item.fileUrl}, #{item.fileType}, #{item.createBy}, - #{item.createTime}) + now() + ) @@ -85,11 +89,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" task_type = #{taskType}, task_id = #{taskId}, model_id = #{modelId}, - name = #{name}, - url = #{url}, + name = #{name}, + url = #{url}, file_type = #{fileType}, create_by = #{createBy}, - create_time = #{createTime}, + update_time = now() where id = #{id} @@ -108,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from bm_file_info - and task_type = #{taskType} + and task_type = #{taskType} and task_id = #{taskId} and model_id = #{modelId} and file_type = #{fileType} diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevInfoMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevInfoMapper.xml index 286a295..e5b96f6 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevInfoMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevInfoMapper.xml @@ -44,22 +44,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select ma_id, code, type_id, ma_status, lease_scope, location, province_id, city_id, area_id, brand, model_name, production_date, working_hours, serial_number, + select ma_id, device_name, device_weight, device_count, code, type_id, ma_status, lease_scope, location, province_id, city_id, area_id, brand, model_name, production_date, working_hours, serial_number, month_lease_price, day_lease_price, pic_url, js_month_price, js_day_price, description, gps_code, own_co, create_time, creator, update_time, person, person_phone, update_by, specification, deposit, is_operator, is_active, update_time, update_by from ma_dev_info - - + + INSERT INTO ma_hot_search (ma_id, search_num) VALUES (#{maId}, 1) @@ -421,6 +426,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" set search_num = search_num + 1 where ma_id = #{maId} + @@ -463,6 +469,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + insert into ma_dev_info + + device_name, + device_weight, + device_count, + code, + type_id, + ma_status, + lease_scope, + location, + province_id, + city_id, + area_id, + brand, + model_name, + production_date, + working_hours, + serial_number, + month_lease_price, + day_lease_price, + pic_url, + js_month_price, + js_day_price, + `description`, + gps_code, + own_co, + create_time, + person, + person_phone, + create_time, + creator, + update_time, + update_by, + specification, + deposit, + is_operator, + is_active, + update_time, + update_by, + + + #{deviceName}, + #{deviceWeight}, + #{deviceCount}, + #{code}, + #{typeId}, + #{maStatus}, + #{leaseScope}, + #{location}, + #{provinceId}, + #{cityId}, + #{areaId}, + #{brand}, + #{modelName}, + #{productionDate}, + #{workingHours}, + #{serialNumber}, + #{monthLeasePrice}, + #{dayLeasePrice}, + #{picUrl}, + #{jsMonthPrice}, + #{jsDayPrice}, + #{description}, + #{gpsCode}, + #{companyId}, + #{person}, + #{personPhone}, + now(), + #{creator}, + now(), + #{update_by}, + #{specification}, + #{deposit}, + #{isOperator}, + 1, + #{updateTime}, + #{updateBy}, + + + + diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/home/MaTypeInfoMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/home/MaTypeInfoMapper.xml index 5bfa3e2..fe14b4d 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/home/MaTypeInfoMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/home/MaTypeInfoMapper.xml @@ -55,7 +55,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"