Przeglądaj źródła

处理isc_materials

车车 4 miesięcy temu
rodzic
commit
8f9e7d6c8e

+ 113 - 95
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/controller/admin/materials/MaterialsController.java

@@ -1,95 +1,113 @@
-package cn.iocoder.yudao.module.iscs.controller.admin.materials;
-
-import org.springframework.web.bind.annotation.*;
-import jakarta.annotation.Resource;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.security.access.prepost.PreAuthorize;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.Operation;
-
-import jakarta.validation.constraints.*;
-import jakarta.validation.*;
-import jakarta.servlet.http.*;
-import java.util.*;
-import java.io.IOException;
-
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.pojo.CommonResult;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
-
-import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
-
-import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
-import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
-
-import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.*;
-import cn.iocoder.yudao.module.iscs.dal.dataobject.materials.MaterialsDO;
-import cn.iocoder.yudao.module.iscs.service.materials.MaterialsService;
-
-@Tag(name = "管理后台 - 物资")
-@RestController
-@RequestMapping("/iscs/materials")
-@Validated
-public class MaterialsController {
-
-    @Resource
-    private MaterialsService materialsService;
-
-    @PostMapping("/insertMaterials")
-    @Operation(summary = "创建物资")
-    @PreAuthorize("@ss.hasPermission('iscs:materials:create')")
-    public CommonResult<Long> insertMaterials(@Valid @RequestBody MaterialsSaveReqVO createReqVO) {
-        return success(materialsService.createMaterials(createReqVO));
-    }
-
-    @PutMapping("/updateMaterials")
-    @Operation(summary = "更新物资")
-    @PreAuthorize("@ss.hasPermission('iscs:materials:update')")
-    public CommonResult<Boolean> updateMaterials(@Valid @RequestBody MaterialsSaveReqVO updateReqVO) {
-        materialsService.updateMaterials(updateReqVO);
-        return success(true);
-    }
-
-    @DeleteMapping("/deleteMaterialsList")
-    @Parameter(name = "ids", description = "编号", required = true)
-    @Operation(summary = "批量删除物资")
-                @PreAuthorize("@ss.hasPermission('iscs:materials:delete')")
-    public CommonResult<Boolean> deleteMaterialsList(@RequestParam("ids") List<Long> ids) {
-        materialsService.deleteMaterialsListByIds(ids);
-        return success(true);
-    }
-
-    @GetMapping("/selectMaterialsById")
-    @Operation(summary = "获得物资")
-    @Parameter(name = "id", description = "编号", required = true, example = "1024")
-    @PreAuthorize("@ss.hasPermission('iscs:materials:query')")
-    public CommonResult<MaterialsRespVO> selectMaterialsById(@RequestParam("id") Long id) {
-        MaterialsDO materials = materialsService.getMaterials(id);
-        return success(BeanUtils.toBean(materials, MaterialsRespVO.class));
-    }
-
-    @GetMapping("/getMaterialsPage")
-    @Operation(summary = "获得物资分页")
-    @PreAuthorize("@ss.hasPermission('iscs:materials:query')")
-    public CommonResult<PageResult<MaterialsRespVO>> getMaterialsPage(@Valid MaterialsPageReqVO pageReqVO) {
-        PageResult<MaterialsDO> pageResult = materialsService.getMaterialsPage(pageReqVO);
-        return success(BeanUtils.toBean(pageResult, MaterialsRespVO.class));
-    }
-
-    @GetMapping("/exportMaterialsExcel")
-    @Operation(summary = "导出物资 Excel")
-    @PreAuthorize("@ss.hasPermission('iscs:materials:export')")
-    @ApiAccessLog(operateType = EXPORT)
-    public void exportMaterialsExcel(@Valid MaterialsPageReqVO pageReqVO,
-              HttpServletResponse response) throws IOException {
-        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
-        List<MaterialsDO> list = materialsService.getMaterialsPage(pageReqVO).getList();
-        // 导出 Excel
-        ExcelUtils.write(response, "物资.xls", "数据", MaterialsRespVO.class,
-                        BeanUtils.toBean(list, MaterialsRespVO.class));
-    }
-
-}
+package cn.iocoder.yudao.module.iscs.controller.admin.materials;
+
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialBindingVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsPageReqVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsRespVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsSaveReqVO;
+import cn.iocoder.yudao.module.iscs.service.materials.MaterialsService;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.List;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.UPDATE;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+@Tag(name = "管理后台 - 物资")
+@RestController
+@RequestMapping("/iscs/materials")
+@Validated
+public class MaterialsController {
+
+    @Resource
+    private MaterialsService materialsService;
+
+    @PostMapping("/insertMaterials")
+    @Operation(summary = "创建物资")
+    @PreAuthorize("@ss.hasPermission('iscs:materials:create')")
+    public CommonResult<Long> insertMaterials(@Valid @RequestBody MaterialsSaveReqVO createReqVO) {
+        return success(materialsService.createMaterials(createReqVO));
+    }
+
+    @PutMapping("/updateMaterials")
+    @Operation(summary = "更新物资")
+    @PreAuthorize("@ss.hasPermission('iscs:materials:update')")
+    public CommonResult<Boolean> updateMaterials(@Valid @RequestBody MaterialsSaveReqVO updateReqVO) {
+        materialsService.updateMaterials(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/deleteMaterialsList")
+    @Parameter(name = "ids", description = "编号", required = true)
+    @Operation(summary = "批量删除物资")
+                @PreAuthorize("@ss.hasPermission('iscs:materials:delete')")
+    public CommonResult<Boolean> deleteMaterialsList(@RequestParam("ids") List<Long> ids) {
+        materialsService.deleteMaterialsListByIds(ids);
+        return success(true);
+    }
+
+    @GetMapping("/selectMaterialsById")
+    @Operation(summary = "获得物资")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('iscs:materials:query')")
+    public CommonResult<MaterialsRespVO> selectMaterialsById(@RequestParam("id") Long id) {
+        MaterialsRespVO materials = materialsService.getMaterials(id);
+        return success(materials);
+    }
+
+    @GetMapping("/getMaterialsPage")
+    @Operation(summary = "获得物资分页")
+    @PreAuthorize("@ss.hasPermission('iscs:materials:query')")
+    public CommonResult<PageResult<MaterialsRespVO>> getMaterialsPage(@Valid MaterialsPageReqVO pageReqVO) throws JsonProcessingException {
+        PageResult<MaterialsRespVO> pageResult = materialsService.getMaterialsPage(pageReqVO);
+        return success(pageResult);
+    }
+
+    @GetMapping("/exportMaterialsExcel")
+    @Operation(summary = "导出物资 Excel")
+    @PreAuthorize("@ss.hasPermission('iscs:materials:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportMaterialsExcel(@Valid MaterialsPageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<MaterialsRespVO> list = materialsService.getMaterialsPage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "物资.xls", "数据", MaterialsRespVO.class, list);
+    }
+
+    @Operation(summary = "绑定物资-物资柜绑定物资")
+    @PreAuthorize("@ss.hasPermi('iscs:materials:binding')")
+    @ApiAccessLog(operateType = UPDATE)
+    @PostMapping("/updateMaterialsBinding")
+    public CommonResult<Boolean> updateMaterialsBinding(@RequestBody @Parameter(name = "vo", description = "修改数据类,放到body") MaterialBindingVO vo) {
+        return CommonResult.success(materialsService.updateMaterialsBinding(vo));
+    }
+
+    @Operation(summary = "查询异常还错柜子的物资")
+    @Parameters({
+            @Parameter(name = "vo", description = "实体参数")
+    })
+    @PreAuthorize("@ss.hasPermi('iscs:materials:list')")
+    @GetMapping("/getExMaterials")
+    public CommonResult<List<MaterialsRespVO>> getExMaterials(MaterialBindingVO vo) {
+        List<MaterialsRespVO> result = materialsService.getExMaterials(vo);
+        return CommonResult.success(result);
+    }
+
+}

+ 25 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/controller/admin/materials/vo/MaterialBindingVO.java

@@ -0,0 +1,25 @@
+package cn.iocoder.yudao.module.iscs.controller.admin.materials.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 物资对象 is_materials
+ *
+ * @author cgj
+ * @date 2024-11-08
+ */
+@Data
+public class MaterialBindingVO
+{
+    private static final long serialVersionUID = 1L;
+
+    @Schema(description = "物资柜ID")
+    private Long materialsCabinetId;
+
+    @Schema(description = "物资ID")
+    private List<Long> materialsIds;
+
+}

+ 17 - 8
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/controller/admin/materials/vo/MaterialsPageReqVO.java

@@ -6,7 +6,6 @@ import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.time.LocalDate;
-import java.time.LocalDateTime;
 
 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 
@@ -51,10 +50,6 @@ public class MaterialsPageReqVO extends PageParam {
     @Schema(description = "供应商")
     private String supplier;
 
-    @Schema(description = "启用时间")
-    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
-    private LocalDateTime[] startTime;
-
     @Schema(description = "属性数组,JSON 格式 [{propertId: , valueId: }, {propertId: , valueId: }]")
     private String properties;
 
@@ -67,8 +62,22 @@ public class MaterialsPageReqVO extends PageParam {
     @Schema(description = "物资状态(字典material_info_status)", example = "2")
     private String status;
 
-    @Schema(description = "创建时间")
-    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
-    private LocalDateTime[] createTime;
+    @Schema(description = "开始时间")
+    private String startTime;
+
+    @Schema(description = "结束时间")
+    private String endTime;
+
+    @Schema(description = "有效期-开始时间")
+    private String startExpirationDate;
+
+    @Schema(description = "有效期-结束时间")
+    private String endExpirationDate;
+
+    @Schema(description = "规格项")
+    private String propertyId;
+
+    @Schema(description = "规格值")
+    private String recordId;
 
 }

+ 22 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/controller/admin/materials/vo/MaterialsRespVO.java

@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.iscs.controller.admin.materials.vo;
 
 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
+import com.baomidou.mybatisplus.annotation.TableField;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
@@ -89,4 +90,25 @@ public class MaterialsRespVO {
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
+    @Schema(description = "物资类型图标")
+    @TableField(exist = false)
+    private String materialsTypeIcon;
+
+    @Schema(description = "物资类型缩略图")
+    @TableField(exist = false)
+    private String materialsTypePicture;
+
+    @Schema(description = "物资规格属性项")
+    @TableField(exist = false)
+    private String propertyIds;
+
+    @Schema(description = "物资规格")
+    private String propertiesValue;
+
+    @Schema(description = "物资规格种类")
+    private String propertiesProperty;
+
+    @Schema(description = "物资柜Name")
+    private String cabinetName;
+
 }

+ 31 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/controller/admin/materials/vo/PropertyVO.java

@@ -0,0 +1,31 @@
+package cn.iocoder.yudao.module.iscs.controller.admin.materials.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 物资对象 is_materials
+ *
+ * @author cgj
+ * @date 2024-11-08
+ */
+@Data
+public class PropertyVO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+
+    @Schema(description = "propertyId")
+    private String propertyId;
+
+    @Schema(description = "propertyName")
+    private String propertyName;
+
+    @Schema(description = "recordId")
+    private String recordId;
+
+    @Schema(description = "valueName")
+    private String valueName;
+
+}

+ 15 - 7
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/dal/mysql/materials/MaterialsMapper.java

@@ -1,13 +1,16 @@
 package cn.iocoder.yudao.module.iscs.dal.mysql.materials;
 
-import java.util.*;
-
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsPageReqVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsRespVO;
 import cn.iocoder.yudao.module.iscs.dal.dataobject.materials.MaterialsDO;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.Mapper;
-import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.*;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 物资 Mapper
@@ -31,13 +34,18 @@ public interface MaterialsMapper extends BaseMapperX<MaterialsDO> {
                 .betweenIfPresent(MaterialsDO::getExpirationDate, reqVO.getExpirationDate())
                 .eqIfPresent(MaterialsDO::getMaterialsRfid, reqVO.getMaterialsRfid())
                 .eqIfPresent(MaterialsDO::getSupplier, reqVO.getSupplier())
-                .betweenIfPresent(MaterialsDO::getStartTime, reqVO.getStartTime())
+                // .betweenIfPresent(MaterialsDO::getStartTime, reqVO.getStartTime())
                 .eqIfPresent(MaterialsDO::getProperties, reqVO.getProperties())
                 .eqIfPresent(MaterialsDO::getRemark, reqVO.getRemark())
                 .eqIfPresent(MaterialsDO::getLoanState, reqVO.getLoanState())
                 .eqIfPresent(MaterialsDO::getStatus, reqVO.getStatus())
-                .betweenIfPresent(MaterialsDO::getCreateTime, reqVO.getCreateTime())
+                // .betweenIfPresent(MaterialsDO::getCreateTime, reqVO.getCreateTime())
                 .orderByDesc(MaterialsDO::getId));
     }
 
-}
+    Page<MaterialsRespVO> getIsMaterialsPage(Page<MaterialsDO> page, @Param(value = "vo") MaterialsPageReqVO vo);
+
+    List<MaterialsRespVO> getExMaterials(@Param(value = "materialsIds") List<Long> materialsIds);
+
+
+}

+ 71 - 63
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/materials/MaterialsService.java

@@ -1,63 +1,71 @@
-package cn.iocoder.yudao.module.iscs.service.materials;
-
-import java.util.*;
-import jakarta.validation.*;
-import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.*;
-import cn.iocoder.yudao.module.iscs.dal.dataobject.materials.MaterialsDO;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
-import com.baomidou.mybatisplus.extension.service.IService;
-
-/**
- * 物资 Service 接口
- *
- * @author 芋道源码
- */
-public interface MaterialsService extends IService<MaterialsDO> {
-
-    /**
-     * 创建物资
-     *
-     * @param createReqVO 创建信息
-     * @return 编号
-     */
-    Long createMaterials(@Valid MaterialsSaveReqVO createReqVO);
-
-    /**
-     * 更新物资
-     *
-     * @param updateReqVO 更新信息
-     */
-    void updateMaterials(@Valid MaterialsSaveReqVO updateReqVO);
-
-    /**
-     * 删除物资
-     *
-     * @param id 编号
-     */
-    void deleteMaterials(Long id);
-
-    /**
-    * 批量删除物资
-    *
-    * @param ids 编号
-    */
-    void deleteMaterialsListByIds(List<Long> ids);
-
-    /**
-     * 获得物资
-     *
-     * @param id 编号
-     * @return 物资
-     */
-    MaterialsDO getMaterials(Long id);
-
-    /**
-     * 获得物资分页
-     *
-     * @param pageReqVO 分页查询
-     * @return 物资分页
-     */
-    PageResult<MaterialsDO> getMaterialsPage(MaterialsPageReqVO pageReqVO);
-
-}
+package cn.iocoder.yudao.module.iscs.service.materials;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialBindingVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsPageReqVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsRespVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsSaveReqVO;
+import cn.iocoder.yudao.module.iscs.dal.dataobject.materials.MaterialsDO;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import jakarta.validation.Valid;
+
+import java.util.List;
+
+/**
+ * 物资 Service 接口
+ *
+ * @author 芋道源码
+ */
+public interface MaterialsService extends IService<MaterialsDO> {
+
+    /**
+     * 创建物资
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createMaterials(@Valid MaterialsSaveReqVO createReqVO);
+
+    /**
+     * 更新物资
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateMaterials(@Valid MaterialsSaveReqVO updateReqVO);
+
+    /**
+     * 删除物资
+     *
+     * @param id 编号
+     */
+    void deleteMaterials(Long id);
+
+    /**
+    * 批量删除物资
+    *
+    * @param ids 编号
+    */
+    void deleteMaterialsListByIds(List<Long> ids);
+
+    /**
+     * 获得物资
+     *
+     * @param id 编号
+     * @return 物资
+     */
+    MaterialsRespVO getMaterials(Long id);
+
+    /**
+     * 获得物资分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 物资分页
+     */
+    PageResult<MaterialsRespVO> getMaterialsPage(MaterialsPageReqVO pageReqVO) throws JsonProcessingException;
+
+    Boolean updateMaterialsBinding(MaterialBindingVO dto);
+
+    List<MaterialsRespVO> getExMaterials(MaterialBindingVO vo);
+
+}

+ 108 - 6
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/materials/MaterialsServiceImpl.java

@@ -1,18 +1,32 @@
 package cn.iocoder.yudao.module.iscs.service.materials;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsPageReqVO;
-import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsSaveReqVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.*;
+import cn.iocoder.yudao.module.iscs.dal.dataobject.exceptionmisplace.ExceptionMisplaceDO;
 import cn.iocoder.yudao.module.iscs.dal.dataobject.materials.MaterialsDO;
+import cn.iocoder.yudao.module.iscs.dal.dataobject.materialstype.MaterialsTypeDO;
 import cn.iocoder.yudao.module.iscs.dal.mysql.materials.MaterialsMapper;
+import cn.iocoder.yudao.module.iscs.service.exceptionmisplace.ExceptionMisplaceService;
+import cn.iocoder.yudao.module.iscs.service.materialstype.MaterialsTypeService;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import jakarta.annotation.Resource;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 物资 Service 实现类
@@ -25,9 +39,24 @@ public class MaterialsServiceImpl extends ServiceImpl<MaterialsMapper, Materials
 
     @Resource
     private MaterialsMapper materialsMapper;
+    @Lazy
+    @Resource
+    private MaterialsTypeService materialsTypeService;
+    @Autowired
+    private ExceptionMisplaceService exceptionMisplaceService;
 
     @Override
     public Long createMaterials(MaterialsSaveReqVO createReqVO) {
+        // 2.检查rfid重复
+        if (StringUtils.isNotBlank(createReqVO.getMaterialsRfid())) {
+            List<MaterialsDO> rfidList = list(Wrappers.<MaterialsDO>lambdaQuery()
+                    .eq(MaterialsDO::getMaterialsRfid, createReqVO.getMaterialsRfid()));
+            Assert.isTrue(rfidList.isEmpty(), "该RFID已被使用!");
+        }
+        // 3.如果设置了物资柜信息,把loan_state变更
+        if (createReqVO.getMaterialsCabinetId() == null || createReqVO.getMaterialsCabinetId() == 0) {
+            createReqVO.setLoanState("0");
+        }
         // 插入
         MaterialsDO materials = BeanUtils.toBean(createReqVO, MaterialsDO.class);
         materialsMapper.insert(materials);
@@ -38,6 +67,19 @@ public class MaterialsServiceImpl extends ServiceImpl<MaterialsMapper, Materials
 
     @Override
     public void updateMaterials(MaterialsSaveReqVO updateReqVO) {
+        // 2.检查rfid重复
+        if (StringUtils.isNotBlank(updateReqVO.getMaterialsRfid())) {
+            List<MaterialsDO> rfidList = list(Wrappers.<MaterialsDO>lambdaQuery()
+                    .eq(MaterialsDO::getMaterialsRfid, updateReqVO.getMaterialsRfid())
+                    .ne(MaterialsDO::getId, updateReqVO.getId()));
+            Assert.isTrue(rfidList.isEmpty(), "该RFID已被使用!");
+        }
+        // 3.如果设置了物资柜信息,把loan_state变更
+        if (updateReqVO.getMaterialsCabinetId() == null || updateReqVO.getMaterialsCabinetId() == 0) {
+            updateReqVO.setLoanState("0");
+        } else {
+            updateReqVO.setLoanState("1");
+        }
         // 校验存在
         validateMaterialsExists(updateReqVO.getId());
         // 更新
@@ -75,13 +117,73 @@ public class MaterialsServiceImpl extends ServiceImpl<MaterialsMapper, Materials
     }
 
     @Override
-    public MaterialsDO getMaterials(Long id) {
-        return materialsMapper.selectById(id);
+    public MaterialsRespVO getMaterials(Long id) {
+        MaterialsDO materialsDO = materialsMapper.selectById(id);
+        MaterialsRespVO bean = BeanUtils.toBean(materialsDO, MaterialsRespVO.class);
+        if (bean != null && bean.getMaterialsTypeId() != null) {
+            MaterialsTypeDO materialsType = materialsTypeService.getById(bean.getMaterialsTypeId());
+            if (materialsType != null) {
+                bean.setMaterialsTypeIcon(materialsType.getMaterialsTypeIcon());
+                bean.setMaterialsTypePicture(materialsType.getMaterialsTypePicture());
+                bean.setPropertyIds(materialsType.getPropertyIds());
+            }
+        }
+        return bean;
+    }
+
+    @Override
+    public PageResult<MaterialsRespVO> getMaterialsPage(MaterialsPageReqVO pageReqVO) throws JsonProcessingException {
+        if (StringUtils.isNotBlank(pageReqVO.getPropertyId())) {
+            pageReqVO.setPropertyId('"' + "propertyId" + '"' + ":" + '"' + pageReqVO.getPropertyId() + '"');
+        }
+        if (StringUtils.isNotBlank(pageReqVO.getRecordId())) {
+            pageReqVO.setRecordId('"' + "recordId" + '"' + ":" + '"' + pageReqVO.getRecordId() + '"');
+        }
+        Page<MaterialsDO> page = new Page<MaterialsDO>().setCurrent(pageReqVO.getPageNo()).setSize(pageReqVO.getPageSize());
+        Page<MaterialsRespVO> pageResult = materialsMapper.getIsMaterialsPage(page, pageReqVO);
+        // 解析规格属性
+        if (!pageResult.getRecords().isEmpty()) {
+            ObjectMapper objectMapper = new ObjectMapper();
+            for (MaterialsRespVO record : pageResult.getRecords()) {
+                if (StringUtils.isNotBlank(record.getProperties())) {
+                    List<PropertyVO> propertyVOS = objectMapper.readValue(record.getProperties(), new TypeReference<List<PropertyVO>>() {});
+                    String propertiesValue = propertyVOS.stream().map(PropertyVO::getValueName).collect(Collectors.joining(","));
+                    record.setPropertiesValue(propertiesValue);
+                    String propertiesProperty = propertyVOS.stream().map(PropertyVO::getPropertyName).collect(Collectors.joining(","));
+                    record.setPropertiesProperty(propertiesProperty);
+                }
+            }
+        }
+        PageResult<MaterialsRespVO> respVOPageResult = new PageResult<>();
+        respVOPageResult.setList(pageResult.getRecords());
+        respVOPageResult.setTotal(pageResult.getTotal());
+        return respVOPageResult;
+    }
+
+    @Override
+    public Boolean updateMaterialsBinding(MaterialBindingVO dto) {
+        // 1.断言开道,bug闪开
+        Assert.notNull(dto.getMaterialsCabinetId(), "物资柜信息不可为空!");
+        Assert.isFalse(dto.getMaterialsIds().isEmpty(), "请选择物资!");
+        // 2.开始更新啊
+        return update(Wrappers.<MaterialsDO>lambdaUpdate()
+                .in(MaterialsDO::getId, dto.getMaterialsIds())
+                .set(MaterialsDO::getMaterialsCabinetId, dto.getMaterialsCabinetId()));
     }
 
     @Override
-    public PageResult<MaterialsDO> getMaterialsPage(MaterialsPageReqVO pageReqVO) {
-        return materialsMapper.selectPage(pageReqVO);
+    public List<MaterialsRespVO> getExMaterials(MaterialBindingVO vo) {
+        // 查询异常未处理的归还物资
+        List<ExceptionMisplaceDO> exMaterials = exceptionMisplaceService.list(Wrappers.<ExceptionMisplaceDO>lambdaQuery()
+                .eq(ExceptionMisplaceDO::getStatus, "0")
+                .eq(vo.getMaterialsCabinetId() != null, ExceptionMisplaceDO::getRestitutionToId, vo.getMaterialsCabinetId()));
+        // 吧当前柜子的异常数据返回给前端
+        List<MaterialsRespVO> materialsPageVOS = new ArrayList<>();
+        if (!exMaterials.isEmpty()) {
+            List<Long> materialsIds = exMaterials.stream().map(ExceptionMisplaceDO::getMaterialsId).collect(Collectors.toList());
+            materialsPageVOS = materialsMapper.getExMaterials(materialsIds);
+        }
+        return materialsPageVOS;
     }
 
 }

+ 81 - 1
yudao-module-iscs/src/main/resources/mapper/MaterialsMapper.xml

@@ -9,4 +9,84 @@
         文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
      -->
 
-</mapper>
+    <select id="getIsMaterialsPage"
+            resultType="cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsRespVO">
+        SELECT
+        m.*,
+        t.materials_type_name,
+        c.cabinet_name,
+        t.materials_type_icon,
+        t.materials_type_picture
+        FROM
+        isc_materials m
+        LEFT JOIN isc_materials_type t ON t.id = m.materials_type_id
+        LEFT JOIN isc_materials_cabinet c ON c.id = m.materials_cabinet_id
+        <where>
+            <if test="vo.materialsCode != null and vo.materialsCode.trim != ''">
+                and m.materials_code like concat('%',#{vo.materialsCode},'%')
+            </if>
+            <if test="vo.materialsName != null and vo.materialsName.trim != ''">
+                and m.materials_name like concat('%',#{vo.materialsName},'%')
+            </if>
+            <if test="vo.loanState != null and vo.loanState.trim != ''">
+                and m.loan_state = #{vo.loanState}
+            </if>
+            <if test="vo.status != null and vo.status.trim != ''">
+                and m.status = #{vo.status}
+            </if>
+            <if test="vo.materialsCabinetId != null and vo.materialsCabinetId > 0">
+                and m.materials_cabinet_id = #{vo.materialsCabinetId}
+            </if>
+            <if test="vo.materialsCabinetId != null and vo.materialsCabinetId == 0">
+                and (m.materials_cabinet_id is null || m.materials_cabinet_id = 0)
+            </if>
+            <if test="vo.materialsTypeId != null">
+                and m.materials_type_id = #{vo.materialsTypeId}
+            </if>
+            <if test="vo.startTime != null and vo.startTime.trim != ''">
+                and m.create_time &gt;= #{vo.startTime}
+            </if>
+            <if test="vo.endTime != null and vo.endTime.trim != ''">
+                and m.create_time &lt;= #{vo.endTime}
+            </if>
+            <if test="vo.startExpirationDate != null and vo.startExpirationDate.trim != ''">
+                and m.expiration_date &gt;= #{vo.startExpirationDate}
+            </if>
+            <if test="vo.endExpirationDate != null and vo.endExpirationDate.trim != ''">
+                and m.expiration_date &lt;= #{vo.endExpirationDate}
+            </if>
+            <if test="vo.supplier != null and vo.supplier.trim != ''">
+                and m.supplier like concat('%',#{vo.supplier},'%')
+            </if>
+            <if test="vo.materialsRfid != null and vo.materialsRfid.trim != ''">
+                and m.materials_rfid like concat('%',#{vo.materialsRfid},'%')
+            </if>
+            <if test="vo.propertyId != null and vo.propertyId.trim != ''">
+                and m.properties like concat('%',#{vo.propertyId},'%')
+            </if>
+            <if test="vo.recordId != null and vo.recordId.trim != ''">
+                and m.properties like concat('%',#{vo.recordId},'%')
+            </if>
+        </where>
+        ORDER BY m.id DESC
+    </select>
+    <select id="getExMaterials"
+            resultType="cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.MaterialsRespVO">
+        SELECT
+        m.*,
+        t.materials_type_name,
+        c.cabinet_name,
+        t.materials_type_icon,
+        t.materials_type_picture
+        FROM
+        isc_materials m
+        LEFT JOIN isc_materials_type t ON t.id = m.materials_type_id
+        LEFT JOIN isc_materials_cabinet c ON c.id = m.materials_cabinet_id
+        <where>
+            m.materials_id in
+            <foreach collection="materialsIds" index="index" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </where>
+    </select>
+</mapper>