应急救援物资--录入物资时,若本部门已存在相同物资则合并物资

main
15036302109 4 months ago
parent a0c596a28d
commit 9488c8660c

@ -7,6 +7,8 @@ import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ehsRisk.domain.EhsRisk;
import com.ruoyi.materialClass.domain.MaterialClassMaster;
@ -126,6 +128,30 @@ public class EhsMaterialController extends BaseController
return toAjax(ehsMaterialService.save(ehsMaterial));
}
/**
* ,
*/
@PostMapping("/checkRepeat")
public AjaxResult checkRepeat(@RequestBody EhsMaterial ehsMaterial)
{
ehsMaterial.setDeptId(SecurityUtils.getDeptId());
List<EhsMaterial> list = ehsMaterialService.checkMaterialRepeat(ehsMaterial);
if (list != null && list.size() > 0) {
// 说明有重复的,返回响应码209
return new AjaxResult(HttpStatus.DATA_REPEAT, "有重复数据");
}
// 不重复则插入
return toAjax(ehsMaterialService.save(ehsMaterial));
}
/**
*
*/
@PostMapping("/merge")
public AjaxResult mergeMaterial(@RequestBody EhsMaterial ehsMaterial) {
return toAjax(ehsMaterialService.mergeMaterial(ehsMaterial));
}
/**
*
*/

@ -27,6 +27,11 @@ public class HttpStatus
*/
public static final int NO_CONTENT = 204;
/**
*
*/
public static final int DATA_REPEAT = 209;
/**
*
*/

@ -28,4 +28,9 @@ public interface EhsMaterialMapper extends BaseMapper<EhsMaterial> {
*/
public List<EhsMaterial> selectEhsMaterialList(EhsMaterial ehsMaterial);
public List<EhsMaterial> selectEhsMateriallExportList(EhsMaterial ehsMaterial);
/**
* ,
*/
List<EhsMaterial> checkMaterialRepeat(EhsMaterial ehsMaterial);
}

@ -30,4 +30,16 @@ public interface IEhsMaterialService extends IService<EhsMaterial> {
public List<EhsMaterial> selectEhsMaterialList(EhsMaterial ehsMaterial);
public String importMaterial(List<EhsMaterial> list,String classType, Boolean isUpdateSupport);
public List<EhsMaterial> selectEhsMateriallExportList(EhsMaterial ehsMaterial);
/**
* ,
*/
List<EhsMaterial> checkMaterialRepeat(EhsMaterial ehsMaterial);
/**
*
* @param ehsMaterial
* @return
*/
boolean mergeMaterial(EhsMaterial ehsMaterial);
}

@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.BeanValidators;
import com.ruoyi.ehsMaterialDetail.domain.EhsMaterialDetail;
import com.ruoyi.ehsMaterialDetail.service.IEhsMaterialDetailService;
import com.ruoyi.ehsRisk.domain.EhsRisk;
import com.ruoyi.materialClass.domain.MaterialClassMaster;
import com.ruoyi.materialClass.domain.MaterialClassSub;
@ -14,6 +16,9 @@ import com.ruoyi.materialClass.mapper.MaterialClassSubMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -21,6 +26,7 @@ import java.util.stream.Collectors;
import com.ruoyi.ehsMaterial.mapper.EhsMaterialMapper;
import com.ruoyi.ehsMaterial.domain.EhsMaterial;
import com.ruoyi.ehsMaterial.service.IEhsMaterialService;
import org.springframework.transaction.annotation.Transactional;
import javax.validation.Validator;
@ -38,6 +44,8 @@ public class EhsMaterialServiceImpl extends ServiceImpl<EhsMaterialMapper, EhsMa
@Autowired
private MaterialClassSubMapper materialClassSubMapper;
@Autowired
private IEhsMaterialDetailService ehsMaterialDetailService;
@Autowired
protected Validator validator;
/**
*
@ -75,6 +83,39 @@ public class EhsMaterialServiceImpl extends ServiceImpl<EhsMaterialMapper, EhsMa
return ehsMaterialMapper.selectEhsMateriallExportList(ehsMaterial);
}
/**
* ,
*/
@Override
public List<EhsMaterial> checkMaterialRepeat(EhsMaterial ehsMaterial) {
return ehsMaterialMapper.checkMaterialRepeat(ehsMaterial);
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean mergeMaterial(EhsMaterial ehsMaterial) {
ehsMaterial.setDeptId(SecurityUtils.getDeptId());
// 1.先根据部门,物资的一级、二级、三级分类查询数据库,取出数量最多的那条重复物资,与前端传来的数量相加
List<EhsMaterial> ehsMaterials = ehsMaterialMapper.checkMaterialRepeat(ehsMaterial);
EhsMaterial databaseMaterial = ehsMaterials.get(0);
Integer materialQuantity = 0;
if (StringUtils.isNotBlank(databaseMaterial.getMaterialQuantity())) {
materialQuantity = Integer.valueOf(databaseMaterial.getMaterialQuantity()) + Integer.valueOf(ehsMaterial.getMaterialQuantity());
}
// 2.数量相加后更新数据库中该物资的数量
databaseMaterial.setMaterialQuantity(materialQuantity.toString());
boolean b = this.updateById(databaseMaterial);
// 3.插入出入库明细,合并算入库
EhsMaterialDetail ehsMaterialDetail = new EhsMaterialDetail();
ehsMaterialDetail.setMaterialId(databaseMaterial.getMaterialId());
ehsMaterialDetail.setOutboundQuantity(ehsMaterial.getMaterialQuantity());
ehsMaterialDetail.setOutboundTime(new Date());
ehsMaterialDetail.setOutboundUserId(SecurityUtils.getUserId());
ehsMaterialDetail.setOperateType(1);
ehsMaterialDetail.setInventory(new BigDecimal(materialQuantity));
return ehsMaterialDetailService.save(ehsMaterialDetail);
}
private LambdaQueryWrapper<EhsMaterial> buildQueryWrapper(EhsMaterial query) {
Map<String, Object> params = query.getParams();
LambdaQueryWrapper<EhsMaterial> lqw = Wrappers.lambdaQuery();

@ -88,6 +88,16 @@ FROM
<if test="classNameKey != null and classNameKey != ''"> and m2.class_name_sub like concat('%', #{classNameKey}, '%')</if>
</where>
</select>
<select id="checkMaterialRepeat" parameterType="EhsMaterial" resultMap="EhsMaterialResult">
select * from ehs_material
<where>
dept_id = #{deptId}
and class_first = #{classFirst}
and class_second = #{classSecond}
and material_name = #{materialName}
</where>
order by material_quantity desc
</select>
<select id="selectEhsMaterialByMaterialId" parameterType="Long" resultMap="EhsMaterialResult">
<include refid="selectEhsMaterialVo"/>
where m.material_id = #{materialId}
@ -95,5 +105,4 @@ FROM
</mapper>
Loading…
Cancel
Save