Browse Source

更新了标本图片库

lwh 1 week ago
parent
commit
257ad142bc

+ 7 - 53
yudao-module-museum/yudao-module-museum-biz/src/main/java/cn/iocoder/yudao/module/museum/controller/admin/museuminfo/MuseumInfoController.java

@@ -34,21 +34,15 @@ public class MuseumInfoController {
     @Resource
     private MuseumInfoService museumInfoService;
 
-    //TODO 判断标本编号是否重复
     @PostMapping("/create")
     @Operation(summary = "新增标本")
     public CommonResult<Integer> createMuseumInfo(@Valid @RequestBody MuseumInfoSaveVO saveVO) {
-        String sampleId = saveVO.getSampleId();
-        String result = museumInfoService.getMuseumInfoBySampleId(sampleId);
-        if (result != null) {
-            return CommonResult.error(200, "标本编号已存在");
-        } else {
             return CommonResult.success(museumInfoService.createMuseumInfo(saveVO));
-        }
     }
     @PutMapping("/update")
     @Operation(summary = "更新标本")
     public CommonResult<Boolean> updateSampleMuseumInfo(@Valid @RequestBody MuseumInfoSaveVO saveVO){
+
         museumInfoService.updateSampleMuseumInfo(saveVO);
         return success(true);
     }
@@ -65,7 +59,6 @@ public class MuseumInfoController {
         return success(true);
     }
 
-    //TODO 需要提供原因,调用更新方法
     @DeleteMapping("/delete")
     @Operation(summary = "删除标本")
     public CommonResult<Boolean> deleteMuseumInfo(@RequestParam("id") Integer id,@RequestParam("reason") String reason){
@@ -81,21 +74,6 @@ public class MuseumInfoController {
       return CommonResult.success(result1);
     }
 
-    @GetMapping("/getSampleId")
-    @Operation(summary = "标本编号查寻")
-    public CommonResult<MuseumInfoRespVO>selectMuseumInfoBySampleId(@RequestParam("sampleId") String sampleId){
-        MuseumInfoDO result = museumInfoService.selectMuseumInfoBySampleId(sampleId);
-        MuseumInfoRespVO result1 = BeanUtils.toBean(result,MuseumInfoRespVO.class);
-        return CommonResult.success(result1);
-    }
-
-    @GetMapping("/getSample")
-    @Operation(summary = "所有标本查寻")
-    public CommonResult<List<MuseumInfoRespVO>>selectMuseumInfo(){
-        List<MuseumInfoDO> result = museumInfoService.selectMuseumInfo();
-        List<MuseumInfoRespVO> result1 = BeanUtils.toBean(result,MuseumInfoRespVO.class);
-        return CommonResult.success(result1);
-    }
 
     @GetMapping("/getSampleType")
     @Operation(summary = "标本类型查寻")
@@ -105,7 +83,7 @@ public class MuseumInfoController {
         return CommonResult.success(result1);
     }
 
-    @GetMapping("/get-import-sample")
+    @GetMapping("/getImportSample")
     @Operation(summary = "获得导入标本模板")
     public void importSample(HttpServletResponse response) throws IOException {
         List<MuseuminfoImportExcelVO> list = Arrays.asList(
@@ -166,11 +144,7 @@ public class MuseumInfoController {
             Integer number =museumInfoService.MuseumInfoBySaveJoin(month,currentYear);
             MuseuminfoMonthSaveVO  re = new MuseuminfoMonthSaveVO();
             re.setMonth(month);
-            if (number == null) {
-                re.setCount(0);
-            }else {
-                re.setCount(number);
-            }
+            re.setCount(number);
             result.add(re);
         }
         return CommonResult.success(result);
@@ -183,7 +157,6 @@ public class MuseumInfoController {
         int currentYear =date.getYear();
         List<MuseuminfoMonthSaveVO> result = new ArrayList<>();
         for (int month = 1 ; month <= 12 ; month++) {
-            //TODO 可以直接使用List<String>.size(),就不用写一个countSampleNumbers来计算list中元素的个数了
             int number = museumInfoService.MuseumInfoBySaveOut(month, currentYear).size();
             MuseuminfoMonthSaveVO re = new MuseuminfoMonthSaveVO();
             re.setMonth(month);
@@ -201,7 +174,7 @@ public class MuseumInfoController {
 
         List<MuseuminfoMonthSaveVO> result = new ArrayList<>();
         for (int month = 1 ; month <= 12 ; month++) {
-            int sample_number = countSampleNumbers(museumInfoService.MuseumInfoBySaveBack(month,currentYear));
+            int sample_number = museumInfoService.MuseumInfoBySaveBack(month,currentYear).size();
             MuseuminfoMonthSaveVO  re = new MuseuminfoMonthSaveVO();
             re.setMonth(month);
             re.setCount(sample_number);
@@ -220,8 +193,8 @@ public class MuseumInfoController {
         for (int year = currentYear; year >= year1; year--) {
 
             Integer number1 = museumInfoService.MuseumInfoYearJoin(year);
-            int sample_number2 = countSampleNumbers(museumInfoService.MuseumInfoYearOutBack(1, year));
-            int sample_number3 = countSampleNumbers(museumInfoService.MuseumInfoYearOutBack(0, year));
+            int sample_number2 = museumInfoService.MuseumInfoYearOutBack(1, year).size();
+            int sample_number3 = museumInfoService.MuseumInfoYearOutBack(0, year).size();
                     Map<Integer,Object> map = new HashMap<>();
 
                     Map<String, Integer> innerMap = new HashMap<>();
@@ -234,26 +207,6 @@ public class MuseumInfoController {
         return CommonResult.success(result);
     }
 
-    /**
-     * 统计样本数量
-     * @param number 包含样本信息的列表
-     * @return 样本数量
-     */
-    private int countSampleNumbers(List<String> number) {
-        if (number == null) {
-            return 0;
-        }
-        int count = 0;
-        for (String numberStr : number) {
-            //消除空格
-            String processedStr = numberStr.replaceAll("\\[|\\]","");
-            // 按逗号分割元素
-            String[] groupElements = processedStr.split(",");
-            count += groupElements.length;
-        }
-        return count;
-    }
-
     @GetMapping("/originCount")
     @Operation(summary = "标本来源计数")
     public CommonResult<List<Map<Integer,Object>>> getOrigin(){
@@ -262,6 +215,7 @@ public class MuseumInfoController {
         LocalDate date = LocalDate.now();
         int currentYear =date.getYear();
         int year1 =currentYear-2;
+        //只展示前两年的数据
         for (int year =currentYear ; year>=year1  ; year--) {
 
             Integer number1 = museumInfoService.MuseumInfoByOrigin(year,1);

+ 0 - 4
yudao-module-museum/yudao-module-museum-biz/src/main/java/cn/iocoder/yudao/module/museum/controller/admin/museuminfo/vo/MuseumInfoSaveVO.java

@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.museum.controller.admin.museuminfo.vo;
 
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
-import org.apache.poi.hpsf.Decimal;
 import org.springframework.format.annotation.DateTimeFormat;
 
 
@@ -10,7 +9,6 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.List;
 
-import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
 
 @Schema(description = "博物馆-标本信息 save VO")
@@ -19,7 +17,6 @@ public class MuseumInfoSaveVO {
 
     @Schema(description = "标本id")
     private Integer id;
-//    private Long id;
 
     @Schema(description = "标本编号")
     private String sampleId;
@@ -55,7 +52,6 @@ public class MuseumInfoSaveVO {
     private String stratum;
 
     @Schema(description = "发现时间")
-//    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
     private LocalDateTime[] findTime;
 

+ 4 - 25
yudao-module-museum/yudao-module-museum-biz/src/main/java/cn/iocoder/yudao/module/museum/dal/mysql/museuminfo/MuseumInfoMapper.java

@@ -18,17 +18,7 @@ import java.util.List;
 
 @Mapper
 public interface MuseumInfoMapper extends BaseMapperX<MuseumInfoDO> {
-    /**
-     * 更新标本
-     */
-    @Update("UPDATE museum_info SET sample_id=#{sampleId}, sample_type=#{sampleType}, "+
-            " place=#{place}, chinese_name=#{chineseName}, english_name=#{englishName}, "+
-            " internation_name=#{internationName}, keep_type=#{keepType}, element=#{element}, " +
-            " local=#{local}, bron_time=#{bronTime}, stratum=#{stratum}, find_time=#{findTime}, " +
-            " size=#{size}, weight=#{weight}, origin=#{origin}, bewrite=#{bewrite}, " +
-            " store=#{store}, store_time=#{storeTime}, way=#{way}, fund_id=#{fundId}, " +
-            " reason=#{reason}, picture=#{picture}, sample_tip=#{sampleTip} WHERE id =#{id}")
-    void updateMuseumInfo(MuseumInfoDO museumInfoDO);
+
     /**
      * 标本出库
      */
@@ -49,22 +39,12 @@ public interface MuseumInfoMapper extends BaseMapperX<MuseumInfoDO> {
      */
     @Select("SELECT * FROM museum_info WHERE id =#{id} AND deleted =0 ")
     MuseumInfoDO selectMuseumInfoById(@Param("id") Integer id);
-
     /**
      * 查询标本编号
      */
-    @Select("SELECT * FROM museum_info WHERE sample_id =#{sampleId} AND deleted =0")
-    String getMuseumInfoBySampleId(@Param("sampleId") String sampleId);
-
-    @Select("SELECT * FROM museum_info WHERE sample_id =#{sampleId} AND deleted =0")
+    @Select("SELECT * FROM museum_info WHERE sample_id =#{sampleId} AND id <>#{id} AND deleted =0")
     MuseumInfoDO selectMuseumInfoBySampleId(@Param("sampleId") String sampleId);
 
-    /**
-     * 查询所有标本
-     */
-    @Select("SELECT * FROM museum_info WHERE deleted =0")
-    List<MuseumInfoDO> selectMuseumInfo();
-
     /**
      * 查询标本类型
      */
@@ -82,7 +62,7 @@ public interface MuseumInfoMapper extends BaseMapperX<MuseumInfoDO> {
     @Select("SELECT" +
             " COUNT(*)"+
             " FROM museum_info " +
-            " WHERE deleted =0 AND store =1"+
+            " WHERE deleted =0"+
             " AND DATE_FORMAT(store_time,'%m') = #{month}"+
             " AND DATE_FORMAT(store_time,'%Y') = #{currentYear}")
     Integer countMuseumInfoBySaveJoin(@Param("month") Integer month,@Param("currentYear") Integer currentYear);
@@ -170,10 +150,9 @@ public interface MuseumInfoMapper extends BaseMapperX<MuseumInfoDO> {
                 .likeIfPresent(MuseumInfoDO::getReason, pageReqVO.getReason())
                 .likeIfPresent(MuseumInfoDO::getSampleTip, pageReqVO.getSampleTip())
                 .orderByDesc(MuseumInfoDO::getId);
-
                 if (pageReqVO.getPicture() != null && !pageReqVO.getPicture().isEmpty()) {
                     String picture = String.valueOf(pageReqVO.getPicture());
-                    queryWrapper.apply("JSON_CONTAINS(secretary_ids, CAST({0} AS JSON))", picture);
+                    queryWrapper.apply("JSON_CONTAINS(picture, CAST({0} AS JSON))", picture);
                 }
         return selectPage(pageReqVO, queryWrapper);
     }

+ 1 - 12
yudao-module-museum/yudao-module-museum-biz/src/main/java/cn/iocoder/yudao/module/museum/service/museuminfo/MuseumInfoService.java

@@ -37,18 +37,7 @@ public interface MuseumInfoService {
     * 查询标本
     * */
    MuseumInfoDO selectMuseumInfo (Integer id);
-   /**
-    * 查询标本编号(String)
-    * */
-   String getMuseumInfoBySampleId(String sampleId);
-   /**
-    * 查询标本编号(DO)
-    * */
-   MuseumInfoDO selectMuseumInfoBySampleId(String sampleId);
-   /**
-    * 查询所有标本
-    */
-   List<MuseumInfoDO> selectMuseumInfo();
+
    /**
    * 查询标本类型
    * */

+ 32 - 29
yudao-module-museum/yudao-module-museum-biz/src/main/java/cn/iocoder/yudao/module/museum/service/museuminfo/MuseumInfoServiceImpl.java

@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.museum.service.museuminfo;
 
 
 import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
@@ -37,6 +38,9 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
    @LogRecord(type = MUSEUM_TYPE, subType = CREATE_SUB_TYPE, bizNo = "{{#sample.id}}",
            success =  CREATE_SUB_TYPE_SUCCESS)
    public Integer createMuseumInfo(MuseumInfoSaveVO saveVO) {
+      if(saveVO.getSampleId() != null){
+         checkoutMuseumInfoForCreateOrUpdate(null,saveVO.getSampleId());
+      }
       MuseumInfoDO sample = BeanUtils.toBean(saveVO, MuseumInfoDO.class);
       if(sample.getStore()==null){
          sample.setStore(1);
@@ -53,6 +57,10 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
            success = UPDATE_SUB_TYPE_SUCCESS)
    @Override
    public void updateSampleMuseumInfo(MuseumInfoSaveVO saveVO) {
+      museumInfoExists(saveVO.getId());
+      if(saveVO.getSampleId() !=null ){
+         checkoutMuseumInfoForCreateOrUpdate(saveVO.getId(),saveVO.getSampleId());
+      }
       MuseumInfoDO sample = BeanUtils.toBean(saveVO,MuseumInfoDO.class);
       museumInfoMapper.updateById(sample);
       LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(sample, MuseumInfoSaveVO.class));
@@ -90,6 +98,7 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
    @LogRecord(type = MUSEUM_TYPE, subType = DELETE_SUB_TYPE, bizNo = "{{#sample.id}}",
            success = DELETE_SUB_TYPE_SUCCESS)
    public void deleteMuseumInfo(Integer id,String reason) {
+      museumInfoExists(id);
       MuseumInfoDO sample = museumInfoMapper.selectMuseumInfoById(id);
       museumInfoMapper.deleteMuseumInfo(id,reason);
       LogRecordContext.putVariable("sample", sample );
@@ -102,27 +111,6 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
       return museumInfoMapper.selectMuseumInfoById(id);
    }
 
-   /**
-    * 查询标本编号(String)
-    */
-   @Override
-   public String getMuseumInfoBySampleId (String sampleId) {
-      return museumInfoMapper.getMuseumInfoBySampleId(sampleId);
-   }
-   /**
-    * 查询标本编号(DO)
-    */
-   @Override
-   public  MuseumInfoDO selectMuseumInfoBySampleId (String sampleId) {
-      return museumInfoMapper.selectMuseumInfoBySampleId(sampleId);
-   }
-   /**
-    * 查询所有标本
-    */
-   @Override
-   public  List<MuseumInfoDO> selectMuseumInfo () {
-      return museumInfoMapper.selectMuseumInfo();
-   }
    /**
     * 查询标本类型
     */
@@ -202,8 +190,12 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
    @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
    public MuseuminfoImportRespVO importSampleList(List<MuseuminfoImportExcelVO> importSamples, boolean isUpdateSupport) {
       // 2. 遍历,逐个创建 or 更新
-      MuseuminfoImportRespVO respVO = MuseuminfoImportRespVO.builder().createSampleIds(new ArrayList<>())
-              .updateSampleIds(new ArrayList<>()).failureSampleIds(new LinkedHashMap<>()).build();
+      MuseuminfoImportRespVO respVO = MuseuminfoImportRespVO
+              .builder()
+              .createSampleIds(new ArrayList<>())
+              .updateSampleIds(new ArrayList<>())
+              .failureSampleIds(new LinkedHashMap<>())
+              .build();
       importSamples.forEach(importSample -> {
          // 2.1.2 校验,判断是否有不符合的原因
          try {
@@ -214,8 +206,7 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
                // 2.2.1 判断如果不存在,在进行插入
                MuseumInfoDO existSample = museumInfoMapper.selectMuseumInfoBySampleId(importSample.getSampleId());
                if (existSample == null) {
-                  //改变模式
-
+                  //改变模式 String->Integer
                   Integer SampleType = transformSampleType(importSample.getSampleTypeC());
                   importSample.setSampleType(SampleType);
                   Integer KeepType = transformKeepType(importSample.getKeepTypeC());
@@ -236,9 +227,9 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
                   return;
                }
 
-               //todo允许更新
+               //todo允许更新,因没写啥判断,更新(有Id时)没再判断了
 //               try {// 2.1.2 校验,判断是否有不符合的原因
-//                  MuseuminfoForCreateOrUpdate(existSample.getId(),importSample.getSampleId() );
+//                  museumInfoForCreateOrUpdate(existSample.getId(),importSample.getSampleId() );
 //               } catch (ServiceException ex) {
 //                  respVO.getFailureSampleIds().put(importSample.getSampleId(), ex.getMessage());
 //               }
@@ -266,6 +257,18 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
       return respVO;
    }
 
+   /**
+    * 检查标本编号是否重复
+    */
+   public void checkoutMuseumInfoForCreateOrUpdate (Integer id, String sampleId) {
+         MuseumInfoDO infoData = museumInfoMapper.selectMuseumInfoBySampleId(sampleId);
+      if (infoData!=null){
+         if(!infoData.getId().equals(id)){
+            throw exception(SAMPLE_ID_EXISTS);
+         }
+      }
+   }
+
    private MuseumInfoDO museumInfoForCreateOrUpdate(Integer id, String sampleId) {
       // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
       return DataPermissionUtils.executeIgnore(() -> {
@@ -276,7 +279,7 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
          return sample;
       });
    }
-      MuseumInfoDO museumInfoExists(Integer id) {
+   private MuseumInfoDO museumInfoExists(Integer id) {
          if (id == null) {
             return null;
          }
@@ -301,7 +304,7 @@ public  class  MuseumInfoServiceImpl implements MuseumInfoService {
          if (id == null) {
             throw exception(SAMPLE_ID_EXISTS);
          }
-         if (!sample.getId().equals(Integer.valueOf(id))) {
+         if (!sample.getId().equals(id)) {
             throw exception(SAMPLE_ID_EXISTS);
          }
       }

+ 0 - 1
yudao-module-museum/yudao-module-museum-biz/src/main/java/cn/iocoder/yudao/module/museum/service/museumpicture/MuseumPictureServiceImpl.java

@@ -66,7 +66,6 @@ public  class MuseumPictureServiceImpl implements MuseumPictureService {
         if (file == null || file.isEmpty()) {
             throw new IllegalArgumentException("上传的文件不能为空");
         }
-
         try (InputStream inputStream = file.getInputStream();
              ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
 

+ 2 - 1
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java

@@ -164,6 +164,7 @@ public interface ErrorCodeConstants {
     ErrorCode NOTIFY_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1_002_028_000, "模板参数({})缺失");
 
     // ========== 博物馆 1-002-029-000 ==========
-    ErrorCode SAMPLE_ID_EXISTS = new ErrorCode(1_002_029_000, "标本已经存在");
+    ErrorCode SAMPLE_ID_EXISTS = new ErrorCode(1_002_029_000, "标本编号已经存在");
     ErrorCode SAMPLE_NOT_EXISTS = new ErrorCode(1_002_029_001, "标本不存在");
+
 }