浏览代码

优化点检内容新增删除

LLL 1 年之前
父节点
当前提交
18fd9c292a

+ 36 - 5
jeecg_module_ems/src/main/java/org/jeecg/modules/cmmsSpotcheckContent/controller/CmmsSpotcheckContentController.java

@@ -10,8 +10,14 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.modules.cmmsSpotcheckContent.convert.CmmsSpotcheckContentConvert;
+import org.jeecg.modules.cmmsSpotcheckContent.dto.CmmsSpotcheckContentAddDTO;
 import org.jeecg.modules.cmmsSpotcheckContent.entity.CmmsSpotcheckContent;
 import org.jeecg.modules.cmmsSpotcheckContent.service.ICmmsSpotcheckContentService;
+import org.jeecg.modules.cmmsSpotcheckContentItem.entity.CmmsSpotcheckContentItem;
+import org.jeecg.modules.cmmsSpotcheckContentItem.service.ICmmsSpotcheckContentItemService;
+import org.jeecg.modules.util.AutoCodeUtil;
+import org.jeecg.modules.util.UserConstants;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
@@ -19,6 +25,10 @@ import org.springframework.web.servlet.ModelAndView;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 点检内容
@@ -33,6 +43,10 @@ import java.util.Arrays;
 public class CmmsSpotcheckContentController extends JeecgController<CmmsSpotcheckContent, ICmmsSpotcheckContentService> {
 	@Autowired
 	private ICmmsSpotcheckContentService cmmsSpotcheckContentService;
+	@Autowired
+	private AutoCodeUtil autoCodeUtil;
+	@Autowired
+	private ICmmsSpotcheckContentItemService spotcheckContentItemService;
 
 	 /**
 	  * 如果要修改该点检内容状态为“启用”,那该设备的其他点检项都停掉
@@ -86,17 +100,26 @@ public class CmmsSpotcheckContentController extends JeecgController<CmmsSpotchec
 	}
 
 	/**
-	 *   添加
+	 *   点检内容——新增
 	 *
-	 * @param cmmsSpotcheckContent
+	 * @param dto
 	 * @return
 	 */
-	@AutoLog(value = "点检内容-添加")
-	@ApiOperation(value="点检内容-添加", notes="点检内容-添加")
+	@AutoLog(value = "点检内容——新增")
+	@ApiOperation(value="点检内容——新增", notes="点检内容——新增——同时新增多个点检项-点检内容")
 	//@RequiresPermissions("org.jeecg.modules:ems_cmms_spotcheck_content:add")
 	@PostMapping(value = "/add")
-	public Result<String> add(@RequestBody CmmsSpotcheckContent cmmsSpotcheckContent) {
+	public Result<String> add(@RequestBody CmmsSpotcheckContentAddDTO dto) {
+		CmmsSpotcheckContent cmmsSpotcheckContent = CmmsSpotcheckContentConvert.INSTANCE.convert(dto);
+		if (cmmsSpotcheckContent.getContentcode() == null || "".equals(cmmsSpotcheckContent.getContentcode())) {
+			cmmsSpotcheckContent.setContentcode(autoCodeUtil.genSerialCode(UserConstants.CMMSSPOTCHECKCONTENT_CODE, null));
+		}
 		cmmsSpotcheckContentService.save(cmmsSpotcheckContent);
+		List<CmmsSpotcheckContentItem> contentItemList = dto.getSpotcheckContentItemList();
+		if (contentItemList != null && contentItemList.size() > 0) {
+			contentItemList.stream().map(i->i.setSpotcheckcontid(cmmsSpotcheckContent.getId())).collect(Collectors.toList());
+			spotcheckContentItemService.saveBatch(contentItemList);
+		}
 		return Result.OK("添加成功!");
 	}
 
@@ -126,6 +149,9 @@ public class CmmsSpotcheckContentController extends JeecgController<CmmsSpotchec
 	//@RequiresPermissions("org.jeecg.modules:ems_cmms_spotcheck_content:delete")
 	@DeleteMapping(value = "/delete")
 	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
+		Map<String, Object> columnMap = new HashMap<>();
+		columnMap.put("spotcheckcontid",id);
+		spotcheckContentItemService.removeByMap(columnMap);
 		cmmsSpotcheckContentService.removeById(id);
 		return Result.OK("删除成功!");
 	}
@@ -141,6 +167,11 @@ public class CmmsSpotcheckContentController extends JeecgController<CmmsSpotchec
 	//@RequiresPermissions("org.jeecg.modules:ems_cmms_spotcheck_content:deleteBatch")
 	@DeleteMapping(value = "/deleteBatch")
 	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
+		for (String id: Arrays.asList(ids.split(","))){
+			Map<String, Object> columnMap = new HashMap<>();
+			columnMap.put("spotcheckcontid",id);
+			spotcheckContentItemService.removeByMap(columnMap);
+		}
 		this.cmmsSpotcheckContentService.removeByIds(Arrays.asList(ids.split(",")));
 		return Result.OK("批量删除成功!");
 	}

+ 2 - 1
jeecg_module_ems/src/main/java/org/jeecg/modules/cmmsSpotcheckContent/convert/CmmsSpotcheckContentConvert.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.cmmsSpotcheckContent.convert;
 
 
+import org.jeecg.modules.cmmsSpotcheckContent.dto.CmmsSpotcheckContentAddDTO;
 import org.jeecg.modules.cmmsSpotcheckContent.entity.CmmsSpotcheckContent;
 import org.mapstruct.Mapper;
 import org.mapstruct.ReportingPolicy;
@@ -14,6 +15,6 @@ public interface CmmsSpotcheckContentConvert {
 
     CmmsSpotcheckContentConvert INSTANCE = Mappers.getMapper(CmmsSpotcheckContentConvert.class);
 
-    CmmsSpotcheckContent convert(CmmsSpotcheckContent cmmsSpotcheckContent, String itemcode, String equipmenttreeid);
+    CmmsSpotcheckContent convert(CmmsSpotcheckContentAddDTO dto);
 
 }

+ 65 - 0
jeecg_module_ems/src/main/java/org/jeecg/modules/cmmsSpotcheckContent/dto/CmmsSpotcheckContentAddDTO.java

@@ -0,0 +1,65 @@
+package org.jeecg.modules.cmmsSpotcheckContent.dto;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.jeecg.common.aspect.annotation.Dict;
+import org.jeecg.modules.cmmsSpotcheckContentItem.entity.CmmsSpotcheckContentItem;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class CmmsSpotcheckContentAddDTO  implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**主键*/
+    @TableId(type = IdType.ASSIGN_ID)
+    @ApiModelProperty(value = "主键")
+    private java.lang.String id;
+    /**点检内容编号*/
+    @Excel(name = "点检内容编号", width = 15)
+    @ApiModelProperty(value = "点检内容编号")
+    private java.lang.String contentcode;
+    /**点检内容名称*/
+    @Excel(name = "点检内容名称", width = 15)
+    @ApiModelProperty(value = "点检内容名称")
+    private java.lang.String contentname;
+    /**设备id*/
+    @Excel(name = "设备id", width = 15, dictTable = "ems_tpm_equipment", dicText = "equipmentname", dicCode = "id")
+    @Dict(dictTable = "ems_tpm_equipment", dicText = "equipmentname", dicCode = "id")
+    @ApiModelProperty(value = "设备id")
+    private java.lang.String equipmentid;
+    /**状态:启用:0、禁用:1*/
+    @Excel(name = "状态:启用:0、禁用:1", width = 15, dicCode = "spotcheck_content_status")
+    @Dict(dicCode = "spotcheck_content_status")
+    @ApiModelProperty(value = "状态:启用:0、禁用:1")
+    private java.lang.String status;
+    /**创建人*/
+    @ApiModelProperty(value = "创建人")
+    private java.lang.String createBy;
+    /**创建日期*/
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建日期")
+    private java.util.Date createTime;
+    /**更新人*/
+    @ApiModelProperty(value = "更新人")
+    private java.lang.String updateBy;
+    /**更新日期*/
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "更新日期")
+    private java.util.Date updateTime;
+    /**所属部门*/
+    @ApiModelProperty(value = "所属部门")
+    private java.lang.String sysOrgCode;
+
+    /**点检内容-点检项集合*/
+    private List<CmmsSpotcheckContentItem> spotcheckContentItemList ;
+}