diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/BaseAddress.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/BaseAddress.java new file mode 100644 index 0000000..28080fb --- /dev/null +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/BaseAddress.java @@ -0,0 +1,56 @@ +package com.bonus.common.biz.domain; + +import com.bonus.common.core.annotation.Excel; +import com.bonus.common.core.web.domain.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * @author bonus + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class BaseAddress extends BaseEntity { + + @Excel(name = "id") + private Long id; + + @Excel(name = "平台id") + private Long platformId; + + @Excel(name = "编码") + private String code; + + @Excel(name = "父级编码") + private String parentCode; + + @Excel(name = "地区名称") + private String name; + + @Excel(name = "纬度") + private Double latitude; + + @Excel(name = "经度") + private Double longitude; + + @Excel(name = "等级") + private Integer level; + + @Excel(name = "区域划分") + private Integer region; + + @Excel(name = "状态") + private Integer status; + + @Excel(name = "创建时间") + private LocalDateTime created; + + @Excel(name = "修改时间") + private LocalDateTime modified; + + @Excel(name = "状态") + private Integer yn; + +} diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/UserCollect.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/UserCollect.java new file mode 100644 index 0000000..2170e87 --- /dev/null +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/UserCollect.java @@ -0,0 +1,45 @@ +package com.bonus.common.biz.domain; + +import com.bonus.common.core.annotation.Excel; +import com.bonus.common.core.web.domain.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +/** + * 我的收藏 +对象 ma_user_collect + * + * @author xsheng + * @date 2023-12-02 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@ToString +@ApiModel("我的收藏") +public class UserCollect extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 用户id */ + @Excel(name = "用户id") + @ApiModelProperty(value = "用户id", required = true) + private Long userId; + + /** 设备id */ + @Excel(name = "设备id") + @ApiModelProperty(value = "设备id", required = true) + private Long maId; + + /** 收藏时间 */ + @Excel(name = "收藏时间") + @ApiModelProperty(value = "收藏时间", required = true) + private String time; + + private Boolean isCollect; +} 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 new file mode 100644 index 0000000..c414173 --- /dev/null +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/enums/MaStatusEnum.java @@ -0,0 +1,61 @@ +package com.bonus.common.biz.enums; + +import lombok.Getter; + +/** + * @author bonus + */ + +@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,"上架驳回"); + + private final Integer code; + private final String name; + + MaStatusEnum(Integer code, String name) { + this.code = code; + this.name = name; + } + + /** + * 根据code获取name + * @param code + * @return + */ + public static String getNameByCode(int code) { + MaStatusEnum[] maStatusEnums = values(); + for (MaStatusEnum maStatusEnum : maStatusEnums) { + if (maStatusEnum.getCode() == code) { + return maStatusEnum.getName(); + } + } + return null; + } + + public static Integer getCodeByName(String msg) { + MaStatusEnum[] maStatusEnums = values(); + for (MaStatusEnum maStatusEnum : maStatusEnums) { + if (maStatusEnum.getName() == msg) { + return maStatusEnum.getCode(); + } + } + return null; + } + + +} 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 919153f..1571d2c 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 @@ -156,8 +156,9 @@ public class DevInfo extends BaseEntity { private String isActive; /**文件附件*/ + @ApiModelProperty(value = "文件附件") private List fileList; - /**城市*/ - private String city; + @ApiModelProperty(value = "城市") + private String city; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/TypeInfo.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/TypeInfo.java new file mode 100644 index 0000000..8ebc718 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/domain/TypeInfo.java @@ -0,0 +1,70 @@ +package com.bonus.material.device.domain; + +import com.bonus.common.core.annotation.Excel; +import com.bonus.common.core.web.domain.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.ArrayList; +import java.util.List; + +/** + * 设备类型对象 ma_type_info + * + * @author syruan + */ +@EqualsAndHashCode(callSuper = false) +@Data +@ToString +@ApiModel("设备类型对象") +public class TypeInfo extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** 类型id */ + @Excel(name = "类型id") + @ApiModelProperty(value = "类型id", required = true) + private Long typeId; + + /** 父级id */ + @Excel(name = "父级id") + @ApiModelProperty(value = "父级id", required = true) + private Long parentId; + + /** 类型名称 */ + @Excel(name = "类型名称") + @ApiModelProperty(value = "类型名称", required = true) + private String typeName; + + /** 计量单位 */ + @Excel(name = "计量单位") + @ApiModelProperty(value = "计量单位", required = true) + private String unitName; + + /** 层级 */ + @Excel(name = "层级") + @ApiModelProperty(value = "层级", required = true) + private String level; + + /** 排序 */ + @Excel(name = "排序") + @ApiModelProperty(value = "排序", required = true) + private String sort; + + /** 是否删除 */ + @Excel(name = "是否删除") + @ApiModelProperty(value = "是否删除", required = true) + private String delFlag; + + /** 父部门名称 */ + @ApiModelProperty(value = "父部门名称", required = true) + private String parentName; + + /** 子部门 */ + @ApiModelProperty(value = "子部门", required = true) + private List children = new ArrayList(); + +} 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 4f7528d..bf454fd 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 @@ -1,8 +1,10 @@ package com.bonus.material.device.mapper; +import com.bonus.common.biz.domain.BaseAddress; import com.bonus.common.biz.domain.SysDic; import com.bonus.common.biz.domain.SysFile; +import com.bonus.common.biz.domain.UserCollect; import com.bonus.material.device.domain.DevInfo; import com.bonus.material.device.domain.vo.DevInfoVo; @@ -46,7 +48,7 @@ public interface DevInfoMapper { */ List selectDevInfoList(DevInfo devInfo); - List selectUserCollectByUserId(Long userId); + List selectUserCollectByUserId(Long userId); List selectDevInfoHotList(DevInfo devInfo); @@ -91,7 +93,7 @@ public interface DevInfoMapper { SysDic getSysDicById(Integer id); -// public List getBaseAddress(); + List getBaseAddress(); String getBaseAddressById(Integer id); diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/SysFileInfoMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/SysFileInfoMapper.java new file mode 100644 index 0000000..df76938 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/SysFileInfoMapper.java @@ -0,0 +1,26 @@ +package com.bonus.material.device.mapper; + + + +import com.bonus.common.biz.domain.SysFileInfo; +import com.bonus.material.device.domain.TypeInfo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @author syruan + */ +@Mapper +public interface SysFileInfoMapper { + + //根据设备id查询 + List selectByMaId(Long maId); + + void insertFileInfo(SysFileInfo fileInfo); + +// BmCompanyInfo getBmCompanyInfo(@Param("companyName") String companyName); + + TypeInfo getTypeInfo(@Param("deviceName") String deviceName); +} 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 new file mode 100644 index 0000000..67d27e6 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevInfoService.java @@ -0,0 +1,81 @@ +package com.bonus.material.device.service; + + +import com.bonus.material.device.domain.DevInfo; +import com.bonus.material.device.domain.vo.DevInfoVo; + +import java.util.List; +import java.util.Map; + +/** + * 设备信息Service接口 + * + * @author syruan + */ +public interface DevInfoService { + /** + * 查询设备信息 + * + * @param maId 设备信息主键 + * @return 设备信息 + */ + public DevInfoVo selectDevInfoByMaId(Long maId); + + /** + * 查询设备信息列表 + * + * @param devInfo 设备信息 + * @return 设备信息集合 + */ + public List selectDevInfoList(DevInfoVo devInfo); + + List selectUserCollectList(DevInfoVo devInfo); + + public List selectDevInfoHotList(DevInfoVo devInfo); + + /** + * 新增设备信息 + * + * @param devInfo 设备信息 + * @return 结果 + */ + public int insertDevInfo(DevInfo devInfo); + + /** + * 修改设备信息 + * + * @param devInfo 设备信息 + * @return 结果 + */ + public int updateDevInfo(DevInfo devInfo); + + /** + * 批量删除设备信息 + * + * @param maIds 需要删除的设备信息主键集合 + * @return 结果 + */ + public int deleteDevInfoByMaIds(Long[] maIds); + + /** + * 删除设备信息信息 + * + * @param maId 设备信息主键 + * @return 结果 + */ + public int deleteDevInfoByMaId(Long maId); + + /** + * 设备信息录入 + * @param inforMationDto + * @return + + int insertInforMationDto(InforMationDto inforMationDto);*/ + + + public Map sumType(); + + List selectDevInfoLists(DevInfoVo devInfo); + + void insertOutType(String 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 new file mode 100644 index 0000000..db7d518 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevInfoServiceImpl.java @@ -0,0 +1,336 @@ +package com.bonus.material.device.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.bonus.common.biz.domain.*; +import com.bonus.common.biz.enums.MaStatusEnum; +import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.device.domain.DevInfo; +import com.bonus.material.device.domain.TypeInfo; +import com.bonus.material.device.domain.vo.DevInfoVo; +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.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + + + +/** + * 设备信息Service业务层处理 + * + * @author syruan + */ +@Service +public class DevInfoServiceImpl implements DevInfoService { + private final Integer ASPECT_PICTURE = 20; + private final Integer EXAMINATION_PDF = 28; + private final Integer INSURANCE_PDF = 29; + + @Resource + private DevInfoMapper devInfoMapper; + + @Resource + private SysFileInfoMapper sysFileInfoMapper; + + /** + * 查询设备信息 + * + * @param maId 设备信息主键 + * @return 设备信息 + */ + @Override + public DevInfoVo selectDevInfoByMaId(Long maId) { + DevInfoVo devInfoVo = devInfoMapper.selectDevInfoByMaId(maId); + //更新搜索量 + updateHotSearch(maId); + try { + List files = devInfoMapper.getFilesByMaId(maId); + if (!CollectionUtils.isEmpty(files) && files.get(0) != null) { + List picList = new ArrayList<>(); + for (SysFile file : files) { + if (file.getDicId().equals(ASPECT_PICTURE)) { + picList.add(file.getUrl()); + } + if (file.getDicId().equals(EXAMINATION_PDF)) { + devInfoVo.setExaminationPdf(file.getUrl()); + } + if (file.getDicId().equals(INSURANCE_PDF)) { + devInfoVo.setInsurancePdf(file.getUrl()); + } + } + String[] pictureArray = null; + if (!CollectionUtils.isEmpty(picList)) { + pictureArray = picList.toArray(new String[0]); + } + devInfoVo.setPictures(pictureArray); + } + Long companyUpNum = devInfoMapper.getCompanyUpNum(devInfoVo.getOwnCo()); + devInfoVo.setCompanyUpNum(companyUpNum); + + SysDic sysDic = devInfoMapper.getSysDicById(Integer.parseInt(devInfoVo.getMaStatus())); + devInfoVo.setMaStatusStr(sysDic.getName()); + + List addressList = devInfoMapper.getBaseAddress(); + for (BaseAddress address : addressList) { + if (devInfoVo.getProvinceId().equals(Integer.valueOf(address.getCode()))) { + devInfoVo.setProvinceStr(address.getName()); + } + if (devInfoVo.getCityId().equals(Integer.valueOf(address.getCode()))) { + devInfoVo.setCityStr(address.getName()); + } + if (devInfoVo.getAreaId().equals(Integer.valueOf(address.getCode()))) { + devInfoVo.setAreaStr(address.getName()); + } + } + } catch (Exception e) { + System.err.println("fail to get devInfo for files or companyUpNum or maStatusStr" + maId); + } + return devInfoVo; + } + + private void updateHotSearch(Long maId) { + int count = devInfoMapper.getHotSearchCountByMaId(maId); + if (count == 0) { + devInfoMapper.insertHotSearch(maId); + } else { + devInfoMapper.updateHotSearchByMaId(maId); + } + } + + /** + * 查询设备信息列表 + * + * @param devInfo 设备信息 + * @return 设备信息 + */ + @Override + public List selectDevInfoList(DevInfoVo devInfo) { + List list = devInfoMapper.selectDevInfoList(devInfo); + fillInMaStatusStr(list); + fillInCityStr(list); + return list; + } + + /** + * 查询设备收藏列表 + * + * @param devInfo 设备信息 + * @return 设备信息 + */ + @Override + public List selectUserCollectList(DevInfoVo devInfo) { + List result = devInfoMapper.selectDevInfoList(devInfo); + LoginUser user = SecurityUtils.getLoginUser(); + if (Objects.nonNull(user)) { + List userCollectList = devInfoMapper.selectUserCollectByUserId(user.getUserid()); + result = filterUserCollect(result, userCollectList); + } + fillInMaStatusStr(result); + fillInCityStr(result); + return result; + } + + private List filterUserCollect(List list, List userCollectList) { + List result = new ArrayList<>(); + for (DevInfoVo devInfoVo : list) { + for (UserCollect userCollect : userCollectList) { + if (devInfoVo.getMaId().longValue() == userCollect.getMaId().longValue()) { + result.add(devInfoVo); + } + } + } + return result; + } + + + @Override + public List selectDevInfoHotList(DevInfoVo devInfo) { + List hotList = devInfoMapper.selectDevInfoHotList(devInfo); + fillInMaStatusStr(hotList); + fillInCityStr(hotList); + return hotList; + } + + private void fillInMaStatusStr(List list) { + List sysDicList = devInfoMapper.getSysDic(); + for (DevInfoVo devInfoVo : list) { + for (SysDic sysDic : sysDicList) { + if (devInfoVo.getMaStatus().equals(String.valueOf(sysDic.getId()))) { + devInfoVo.setMaStatusStr(sysDic.getName()); + } + } + } + } + + private void fillInCityStr(List list) { + List addressList = devInfoMapper.getBaseAddress(); + for (DevInfoVo devInfoVo : list) { + for (BaseAddress address : addressList) { + if (devInfoVo.getCityId().equals(Integer.valueOf(address.getCode()))) { + devInfoVo.setCityStr(address.getName()); + break; + } + } + } + } + + /** + * 新增设备信息 + * + * @param devInfo 设备信息 + * @return 结果 + */ + @Override + @Transactional + public int insertDevInfo(DevInfo devInfo) { + devInfo.setCreateTime(new Date()); + //获取用户信息 + Long userId = SecurityUtils.getUserId(); + //保存用户信息 + devInfo.setCreator(userId); + devInfo.setCode(String.valueOf(UUID.randomUUID())); + devInfoMapper.insertDevInfo(devInfo); + + //把文件保存到附件中 + List fileInfoList = devInfo.getFileList(); + if (CollectionUtil.isNotEmpty(fileInfoList)){ + for (SysFileInfo sysFileInfo: fileInfoList) { + sysFileInfo.setModelId(Math.toIntExact(devInfo.getMaId())); + sysFileInfo.setCreator(String.valueOf(userId)); + sysFileInfoMapper.insertFileInfo(sysFileInfo); + } + } + return 1; + } + + /** + * 修改设备信息 + * @param devInfo 设备信息 + */ + @Override + public int updateDevInfo(DevInfo devInfo) { + devInfo.setUpdateTime(DateUtils.getNowDate()); + return devInfoMapper.updateDevInfo(devInfo); + } + + /** + * 批量删除设备信息 + * + * @param maIds 需要删除的设备信息主键 + * @return 结果 + */ + @Override + public int deleteDevInfoByMaIds(Long[] maIds) + { + return devInfoMapper.deleteDevInfoByMaIds(maIds); + } + + /** + * 删除设备信息信息 + * + * @param maId 设备信息主键 + * @return 结果 + */ + @Override + public int deleteDevInfoByMaId(Long maId) + { + return devInfoMapper.deleteDevInfoByMaId(maId); + } + + /** + * TODO + * 信息录入 + * @param inforMationDto + * @return + + @Override + public int insertInforMationDto(InforMationDto inforMationDto) { + DevInfo devInfo = new DevInfo(); + BeanUtils.copyProperties(inforMationDto, devInfo); + devInfoMapper.insertDevInfo(devInfo); + return devInfoMapper.insertLon(inforMationDto); + }*/ + + + /** + * 统计装备 + */ + @Override + public Map sumType() { + DevInfoVo devInfoVo = new DevInfoVo(); + Map sumTypeMap = new IdentityHashMap<>(); + //获取所有的装备信息 + List devInfoList = devInfoMapper.selectDevInfoList(devInfoVo); + //获取每种状态列表 + Map> groupedByMaStatus = devInfoList.stream() + .collect(Collectors.groupingBy(DevInfo::getMaStatus)); + //获取所有的key + Set keys = groupedByMaStatus.keySet(); + //根据key计算每种状态的数量 + for (String key : keys) { + List deviceList = groupedByMaStatus.get(key); + sumTypeMap.put(MaStatusEnum.getNameByCode(Integer.parseInt(key)),deviceList.size()); + } + return sumTypeMap; + } + + @Override + public List selectDevInfoLists(DevInfoVo devInfo) { + List list = devInfoMapper.selectDevInfoLists(devInfo); + //获取设备的附件 + for (DevInfoVo devInfoVo: list) { + List fileInfoList = sysFileInfoMapper.selectByMaId(devInfoVo.getMaId()); + devInfoVo.setFileList(fileInfoList); + } + return list; + } + + @Override + public void insertOutType(String devInfo) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + Map map = objectMapper.readValue(devInfo, new TypeReference>() {}); + //获取公司名称 + String companyName = (String) map.get("companyName"); + // TODO 根据公司名称获取公司ID +// BmCompanyInfo bmCompanyInfo = sysFileInfoMapper.getBmCompanyInfo(companyName); + //获取设备类型名称 + String deviceName = (String) map.get("deviceName"); + //根据设备类型名称获取设备类型ID + TypeInfo typeInfo = sysFileInfoMapper.getTypeInfo(deviceName); + //获取日租金 + Long leasePrice = (Long) map.get("leasePrice"); + //设备型号 + String modelName = (String) map.get("modelName"); + //出厂日期 + String outFacTime = (String) map.get("outFacTime"); + DevInfo devInfo1 = new DevInfo(); + devInfo1.setCreateTime(new Date()); + //获取用户信息 + Long userId = SecurityUtils.getUserId(); + //保存用户信息 + devInfo1.setCreator(userId); + devInfo1.setCode(String.valueOf(UUID.randomUUID())); + // TODO +// devInfo1.setOwnCo(Long.valueOf(bmCompanyInfo.getCompanyId())); + devInfo1.setTypeId(typeInfo.getTypeId()); + devInfo1.setJsDayPrice(Float.valueOf(leasePrice)); + devInfo1.setModelName(modelName); + devInfo1.setProductionDate(outFacTime); + devInfoMapper.insertDevInfo(devInfo1); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } +} diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/device/DevInfoMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/device/DevInfoMapper.xml index 4e36700..05f8bea 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/device/DevInfoMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/device/DevInfoMapper.xml @@ -307,17 +307,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{maId} - - - select id, user_id, ma_id, time from ma_user_collect where user_id = #{userId} @@ -351,9 +342,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} - - - +