b5d77a45 康伟

kangwei : 物料类别列表:根据是否药剂赛选集合

1 个父辈 f7392619
......@@ -3,10 +3,7 @@ package com.skua.modules.supplies.controller.web;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -80,11 +77,14 @@ public class EquipmentSparepartTypeController {
if (StringUtils.isNotBlank(itemText)) {
queryWrapper.like("item_text",itemText);
}
if (equipmentSparepartType.isMedicament()) {//查询药剂类别
queryWrapper.eq("is_medicament",equipmentSparepartType.isMedicament());
}
List<EquipmentSparepartType> equipmentSparepartTypeList = equipmentSparepartTypeService.list(queryWrapper);
if (equipmentSparepartType.isMedicament()) {//查询药剂类别
queryWrapper.eq("medicament",equipmentSparepartType.isMedicament());
//药剂的物料分类
List<EquipmentSparepartType> medicamentList = equipmentSparepartTypeService.list(queryWrapper);
equipmentSparepartTypeList = this.equipmentSparepartTypeListByMedicament(equipmentSparepartTypeList , medicamentList );
}
List<EquipmentSparepartTypeVO> voList = new ArrayList<>();
getTree(voList, equipmentSparepartTypeList, null);
result.setSuccess(true);
......@@ -92,6 +92,12 @@ public class EquipmentSparepartTypeController {
return result;
}
/***
* 递归转换为tree结构
* @param voList
* @param entityList
* @param tmp
*/
private void getTree(List<EquipmentSparepartTypeVO> voList, List<EquipmentSparepartType> entityList, EquipmentSparepartTypeVO tmp) {
for (EquipmentSparepartType item : entityList) {
String parentId = item.getParentId();
......@@ -110,6 +116,42 @@ public class EquipmentSparepartTypeController {
}
}
/***
* 拼装 药剂的物料分类
* @param allTypeList
* @param medicamentList
* @return
*/
private List<EquipmentSparepartType> equipmentSparepartTypeListByMedicament(List<EquipmentSparepartType> allTypeList ,List<EquipmentSparepartType> medicamentList ){
Set<EquipmentSparepartType> resultSet = new HashSet<>();
// List<EquipmentSparepartType> dataList = new ArrayList<>();
StringBuffer ancestors = new StringBuffer();
for( EquipmentSparepartType equipmentSparepartType : medicamentList){
ancestors.append(equipmentSparepartType.getAncestors()).append(",");
resultSet.add(equipmentSparepartType );
for( EquipmentSparepartType equipmentSparepartType2 : allTypeList){
// 添加下游数据
if(equipmentSparepartType2.getAncestors().contains( equipmentSparepartType.getAncestors() )){
resultSet.add(equipmentSparepartType2 );
}
}
// 将原始字符串按逗号分隔并放入LinkedHashSet中去重
Set<String> uniqueFruits = new LinkedHashSet<>(Arrays.asList(ancestors.toString().split(",")));
//添加上游数据
for(String id : uniqueFruits){
for( EquipmentSparepartType equipmentSparepartType3 : allTypeList){
if(id.equals( equipmentSparepartType3.getId() )){
resultSet.add(equipmentSparepartType3 ) ;
}
}
}
}
return new ArrayList<>(resultSet);
}
/**
* 添加
*
......@@ -168,6 +210,11 @@ public class EquipmentSparepartTypeController {
try {
equipmentSparepartType.setDelFlag(0);
equipmentSparepartTypeService.saveAndUpdateParent(equipmentSparepartType);
if(StringUtils.isNotEmpty( equipmentSparepartType.getParentId() )){
EquipmentSparepartType parentSparepartType = equipmentSparepartTypeService.getById( equipmentSparepartType.getParentId() );
equipmentSparepartType.setAncestors( parentSparepartType.getAncestors() +","+ equipmentSparepartType.getId()) ;
equipmentSparepartTypeService.updateById( equipmentSparepartType );
}
result.success("添加成功!");
} catch (Exception e) {
e.printStackTrace();
......@@ -192,14 +239,26 @@ public class EquipmentSparepartTypeController {
if (equipmentSparepartTypeEntity == null) {
result.error500("未找到对应实体");
} else {
if(StringUtils.isNotEmpty( equipmentSparepartType.getParentId() )){
EquipmentSparepartType parentSparepartType = equipmentSparepartTypeService.getById( equipmentSparepartType.getParentId() );
equipmentSparepartType.setAncestors( parentSparepartType.getAncestors() +","+ equipmentSparepartType.getId()) ;
// 跟新父节点节点状态
if( parentSparepartType.getIsLeaf()){
parentSparepartType.setIsLeaf(false);
equipmentSparepartTypeService.updateById( parentSparepartType );
}
}
boolean ok = equipmentSparepartTypeService.updateById(equipmentSparepartType);
//批量更改祖籍信息
equipmentSparepartTypeService.updateAncestors(equipmentSparepartTypeEntity.getAncestors(), equipmentSparepartType.getAncestors() );
//更新父级叶子节点状态
String parentId = equipmentSparepartType.getParentId();
/* String parentId = equipmentSparepartType.getParentId();
if(StringUtils.isNotEmpty(parentId)) {
EquipmentSparepartType parentEquipmentSparepartTypeEntity = equipmentSparepartTypeService.getById(parentId);
parentEquipmentSparepartTypeEntity.putIsLeaf(false);
equipmentSparepartTypeService.updateById(parentEquipmentSparepartTypeEntity);
}
}*/
if (ok) {
result.success("修改成功!");
}
......
......@@ -2,6 +2,7 @@ package com.skua.modules.supplies.entity;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableField;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
......@@ -38,6 +39,9 @@ public class EquipmentSparepartType {
@Excel(name = "父ID", width = 15)
@ApiModelProperty(value = "父ID")
private String parentId;
@ApiModelProperty(value = "祖籍信息")
private String ancestors;
/**
* 文本key
*/
......@@ -71,7 +75,8 @@ public class EquipmentSparepartType {
@Excel(name = "是否药剂,1:是 0:不是", width = 15)
@ApiModelProperty(value = "是否药剂,1:是 0:不是")
private boolean isMedicament = false;
private boolean medicament = false;
/**
* 创建人
*/
......@@ -107,6 +112,14 @@ public class EquipmentSparepartType {
@ApiModelProperty(value = "删除状态 0正常 1已删除")
private Integer delFlag;
public boolean getIsLeaf() {
return isLeaf;
}
public void setIsLeaf(boolean isLeaf) {
this.isLeaf = isLeaf;
}
public void putIsLeaf(Boolean isLeaf) {
if (isLeaf != null) {
this.isLeaf = isLeaf;
......
......@@ -2,10 +2,17 @@ package com.skua.modules.supplies.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.skua.modules.supplies.entity.EquipmentSparepartType;
import org.apache.ibatis.annotations.Param;
/**
* 设备物资类型
*/
public interface EquipmentSparepartTypeMapper extends BaseMapper<EquipmentSparepartType> {
/***
* 批量更改祖籍信息
* @param oldAncestors
* @param newAncestors
*/
public void updateAncestors(@Param("oldAncestors") String oldAncestors,@Param("newAncestors") String newAncestors);
}
......
......@@ -2,4 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.skua.modules.supplies.mapper.EquipmentSparepartTypeMapper">
<!-- 批量更改祖籍信息 -->
<update id="updateAncestors">
update equipment_sparepart_type set ancestors = REPLACE(ancestors,#{oldAncestors}, #{newAncestors});
</update>
</mapper>
\ No newline at end of file
......
......@@ -27,4 +27,10 @@ public interface IEquipmentSparepartTypeService extends IService<EquipmentSparep
*/
void saveAndUpdateParent(EquipmentSparepartType equipmentSparepartType);
/***
* 批量更改祖籍信息
* @param oldAncestors
* @param newAncestors
*/
void updateAncestors(String oldAncestors, String newAncestors);
}
......
......@@ -63,4 +63,13 @@ public class EquipmentSparepartTypeServiceImpl extends ServiceImpl<EquipmentSpar
}
}
/***
* 批量更改祖籍信息
* @param oldAncestors
* @param newAncestors
*/
public void updateAncestors(String oldAncestors, String newAncestors){
this.baseMapper.updateAncestors(oldAncestors, newAncestors);
}
}
......
......@@ -5,7 +5,9 @@ import java.util.List;
import com.skua.modules.supplies.entity.EquipmentSparepartType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* @author sonin
......@@ -22,6 +24,7 @@ public class EquipmentSparepartTypeVO {
private String itemValue;
private Boolean medicament = false;
private String remark;
private Integer sort;
......@@ -37,8 +40,9 @@ public class EquipmentSparepartTypeVO {
this.itemValue = entity.getItemValue();
this.remark = entity.getRemark();
this.sort = entity.getSort();
this.isLeaf = entity.isLeaf();
if (!entity.isLeaf()) {
this.isLeaf = entity.getIsLeaf();
this.medicament = entity.isMedicament();
if (!entity.getIsLeaf()) {
this.children = new ArrayList<>();
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!